takashi yamanoue
/
XBee_API_ex3
Xbee API Test 3
> help h or help m <status-in-hex>,. ... Modem status l <cmd>,<val-in-hex>. ... exec <cmd> (AT) at this host. lset fid <val-in-hex>. ... set local frame id. default is 1. lset cmd <val-in-hex>. ... set local command. lset val <val-in-hex>. ... set local command value. q <cmd>,<val-in-hex>. ... set queue parameter value. r <cmd>,<val-in-hex>. ... exec <cmd> (AT)at remote host. rset a16 <val-in-hex>. ... set remote address high. rset a64 <val-in-hex>,<val-in-hex>. ... set remote address low. rset fid <val-in-hex>. ... set remote frame id. default is 1. > l D4,0x05 cmd=D4 val=0x05 apiId=88 object 100008c8:35 01 00 10 88 00 05 FE 04 01 00 FF l OK: > l D4,0x04 cmd=D4 val=0x04 apiId=88 object 100008c8:35 01 00 10 88 00 05 FE 04 01 00 FF l OK: >
LPC1768/api/DNSRequest.h@0:3edcfa3aba71, 2012-07-21 (annotated)
- Committer:
- takashiyamanoue
- Date:
- Sat Jul 21 04:09:54 2012 +0000
- Revision:
- 0:3edcfa3aba71
xbee test 3
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
takashiyamanoue | 0:3edcfa3aba71 | 1 | |
takashiyamanoue | 0:3edcfa3aba71 | 2 | /* |
takashiyamanoue | 0:3edcfa3aba71 | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
takashiyamanoue | 0:3edcfa3aba71 | 4 | |
takashiyamanoue | 0:3edcfa3aba71 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
takashiyamanoue | 0:3edcfa3aba71 | 6 | of this software and associated documentation files (the "Software"), to deal |
takashiyamanoue | 0:3edcfa3aba71 | 7 | in the Software without restriction, including without limitation the rights |
takashiyamanoue | 0:3edcfa3aba71 | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
takashiyamanoue | 0:3edcfa3aba71 | 9 | copies of the Software, and to permit persons to whom the Software is |
takashiyamanoue | 0:3edcfa3aba71 | 10 | furnished to do so, subject to the following conditions: |
takashiyamanoue | 0:3edcfa3aba71 | 11 | |
takashiyamanoue | 0:3edcfa3aba71 | 12 | The above copyright notice and this permission notice shall be included in |
takashiyamanoue | 0:3edcfa3aba71 | 13 | all copies or substantial portions of the Software. |
takashiyamanoue | 0:3edcfa3aba71 | 14 | |
takashiyamanoue | 0:3edcfa3aba71 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
takashiyamanoue | 0:3edcfa3aba71 | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
takashiyamanoue | 0:3edcfa3aba71 | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
takashiyamanoue | 0:3edcfa3aba71 | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
takashiyamanoue | 0:3edcfa3aba71 | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
takashiyamanoue | 0:3edcfa3aba71 | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
takashiyamanoue | 0:3edcfa3aba71 | 21 | THE SOFTWARE. |
takashiyamanoue | 0:3edcfa3aba71 | 22 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 23 | |
takashiyamanoue | 0:3edcfa3aba71 | 24 | /** \file |
takashiyamanoue | 0:3edcfa3aba71 | 25 | DNS Request header file |
takashiyamanoue | 0:3edcfa3aba71 | 26 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 27 | |
takashiyamanoue | 0:3edcfa3aba71 | 28 | #ifndef DNSREQUEST_H |
takashiyamanoue | 0:3edcfa3aba71 | 29 | #define DNSREQUEST_H |
takashiyamanoue | 0:3edcfa3aba71 | 30 | |
takashiyamanoue | 0:3edcfa3aba71 | 31 | #include "core/net.h" |
takashiyamanoue | 0:3edcfa3aba71 | 32 | #include "core/ipaddr.h" |
takashiyamanoue | 0:3edcfa3aba71 | 33 | #include "core/host.h" |
takashiyamanoue | 0:3edcfa3aba71 | 34 | //Essentially it is a safe interface to NetDnsRequest |
takashiyamanoue | 0:3edcfa3aba71 | 35 | |
takashiyamanoue | 0:3edcfa3aba71 | 36 | ///DNS Request error codes |
takashiyamanoue | 0:3edcfa3aba71 | 37 | enum DNSRequestErr |
takashiyamanoue | 0:3edcfa3aba71 | 38 | { |
takashiyamanoue | 0:3edcfa3aba71 | 39 | __DNS_MIN = -0xFFFF, |
takashiyamanoue | 0:3edcfa3aba71 | 40 | DNS_SETUP, ///<DNSRequest not properly configured |
takashiyamanoue | 0:3edcfa3aba71 | 41 | DNS_IF, ///<Interface has problems, does not exist or is not initialized |
takashiyamanoue | 0:3edcfa3aba71 | 42 | DNS_MEM, ///<Not enough mem |
takashiyamanoue | 0:3edcfa3aba71 | 43 | DNS_INUSE, ///<Interface / Port is in use |
takashiyamanoue | 0:3edcfa3aba71 | 44 | DNS_PROCESSING, ///<Request has not completed |
takashiyamanoue | 0:3edcfa3aba71 | 45 | //... |
takashiyamanoue | 0:3edcfa3aba71 | 46 | DNS_OK = 0 ///<Success |
takashiyamanoue | 0:3edcfa3aba71 | 47 | }; |
takashiyamanoue | 0:3edcfa3aba71 | 48 | |
takashiyamanoue | 0:3edcfa3aba71 | 49 | ///DNS Request Result Events |
takashiyamanoue | 0:3edcfa3aba71 | 50 | enum DNSReply |
takashiyamanoue | 0:3edcfa3aba71 | 51 | { |
takashiyamanoue | 0:3edcfa3aba71 | 52 | DNS_PRTCL, |
takashiyamanoue | 0:3edcfa3aba71 | 53 | DNS_NOTFOUND, ///Hostname is unknown |
takashiyamanoue | 0:3edcfa3aba71 | 54 | DNS_ERROR, ///Problem with DNS Service |
takashiyamanoue | 0:3edcfa3aba71 | 55 | //... |
takashiyamanoue | 0:3edcfa3aba71 | 56 | DNS_FOUND, |
takashiyamanoue | 0:3edcfa3aba71 | 57 | }; |
takashiyamanoue | 0:3edcfa3aba71 | 58 | |
takashiyamanoue | 0:3edcfa3aba71 | 59 | class NetDnsRequest; |
takashiyamanoue | 0:3edcfa3aba71 | 60 | enum NetDnsReply; |
takashiyamanoue | 0:3edcfa3aba71 | 61 | |
takashiyamanoue | 0:3edcfa3aba71 | 62 | ///This is a simple DNS Request class |
takashiyamanoue | 0:3edcfa3aba71 | 63 | /** |
takashiyamanoue | 0:3edcfa3aba71 | 64 | This class exposes an API to deal with DNS Requests |
takashiyamanoue | 0:3edcfa3aba71 | 65 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 66 | class DNSRequest |
takashiyamanoue | 0:3edcfa3aba71 | 67 | { |
takashiyamanoue | 0:3edcfa3aba71 | 68 | public: |
takashiyamanoue | 0:3edcfa3aba71 | 69 | ///Creates a new request |
takashiyamanoue | 0:3edcfa3aba71 | 70 | DNSRequest(); |
takashiyamanoue | 0:3edcfa3aba71 | 71 | |
takashiyamanoue | 0:3edcfa3aba71 | 72 | ///Terminates and closes request |
takashiyamanoue | 0:3edcfa3aba71 | 73 | ~DNSRequest(); |
takashiyamanoue | 0:3edcfa3aba71 | 74 | |
takashiyamanoue | 0:3edcfa3aba71 | 75 | ///Resolves an hostname |
takashiyamanoue | 0:3edcfa3aba71 | 76 | /** |
takashiyamanoue | 0:3edcfa3aba71 | 77 | @param hostname : hostname to resolve |
takashiyamanoue | 0:3edcfa3aba71 | 78 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 79 | DNSRequestErr resolve(const char* hostname); |
takashiyamanoue | 0:3edcfa3aba71 | 80 | |
takashiyamanoue | 0:3edcfa3aba71 | 81 | ///Resolves an hostname |
takashiyamanoue | 0:3edcfa3aba71 | 82 | /** |
takashiyamanoue | 0:3edcfa3aba71 | 83 | @param host : hostname to resolve, the result will be stored in the IpAddr field of this object |
takashiyamanoue | 0:3edcfa3aba71 | 84 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 85 | DNSRequestErr resolve(Host* pHost); |
takashiyamanoue | 0:3edcfa3aba71 | 86 | |
takashiyamanoue | 0:3edcfa3aba71 | 87 | ///Setups callback |
takashiyamanoue | 0:3edcfa3aba71 | 88 | /** |
takashiyamanoue | 0:3edcfa3aba71 | 89 | The callback function will be called on result. |
takashiyamanoue | 0:3edcfa3aba71 | 90 | @param pMethod : callback function |
takashiyamanoue | 0:3edcfa3aba71 | 91 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 92 | void setOnReply( void (*pMethod)(DNSReply) ); |
takashiyamanoue | 0:3edcfa3aba71 | 93 | |
takashiyamanoue | 0:3edcfa3aba71 | 94 | class CDummy; |
takashiyamanoue | 0:3edcfa3aba71 | 95 | ///Setups callback |
takashiyamanoue | 0:3edcfa3aba71 | 96 | /** |
takashiyamanoue | 0:3edcfa3aba71 | 97 | The callback function will be called on result. |
takashiyamanoue | 0:3edcfa3aba71 | 98 | @param pItem : instance of class on which to execute the callback method |
takashiyamanoue | 0:3edcfa3aba71 | 99 | @param pMethod : callback method |
takashiyamanoue | 0:3edcfa3aba71 | 100 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 101 | template<class T> |
takashiyamanoue | 0:3edcfa3aba71 | 102 | void setOnReply( T* pItem, void (T::*pMethod)(DNSReply) ) |
takashiyamanoue | 0:3edcfa3aba71 | 103 | { |
takashiyamanoue | 0:3edcfa3aba71 | 104 | m_pCbItem = (CDummy*) pItem; |
takashiyamanoue | 0:3edcfa3aba71 | 105 | m_pCbMeth = (void (CDummy::*)(DNSReply)) pMethod; |
takashiyamanoue | 0:3edcfa3aba71 | 106 | } |
takashiyamanoue | 0:3edcfa3aba71 | 107 | |
takashiyamanoue | 0:3edcfa3aba71 | 108 | ///Gets IP address once it has been resolved |
takashiyamanoue | 0:3edcfa3aba71 | 109 | /** |
takashiyamanoue | 0:3edcfa3aba71 | 110 | @param pIp : pointer to an IpAddr instance in which to store the resolved IP address |
takashiyamanoue | 0:3edcfa3aba71 | 111 | */ |
takashiyamanoue | 0:3edcfa3aba71 | 112 | DNSRequestErr getResult(IpAddr* pIp); |
takashiyamanoue | 0:3edcfa3aba71 | 113 | |
takashiyamanoue | 0:3edcfa3aba71 | 114 | ///Closes DNS Request before completion |
takashiyamanoue | 0:3edcfa3aba71 | 115 | DNSRequestErr close(); |
takashiyamanoue | 0:3edcfa3aba71 | 116 | |
takashiyamanoue | 0:3edcfa3aba71 | 117 | protected: |
takashiyamanoue | 0:3edcfa3aba71 | 118 | void onNetDnsReply(NetDnsReply r); |
takashiyamanoue | 0:3edcfa3aba71 | 119 | DNSRequestErr checkInst(); |
takashiyamanoue | 0:3edcfa3aba71 | 120 | |
takashiyamanoue | 0:3edcfa3aba71 | 121 | private: |
takashiyamanoue | 0:3edcfa3aba71 | 122 | NetDnsRequest* m_pNetDnsRequest; |
takashiyamanoue | 0:3edcfa3aba71 | 123 | |
takashiyamanoue | 0:3edcfa3aba71 | 124 | CDummy* m_pCbItem; |
takashiyamanoue | 0:3edcfa3aba71 | 125 | void (CDummy::*m_pCbMeth)(DNSReply); |
takashiyamanoue | 0:3edcfa3aba71 | 126 | |
takashiyamanoue | 0:3edcfa3aba71 | 127 | void (*m_pCb)(DNSReply); |
takashiyamanoue | 0:3edcfa3aba71 | 128 | |
takashiyamanoue | 0:3edcfa3aba71 | 129 | }; |
takashiyamanoue | 0:3edcfa3aba71 | 130 | |
takashiyamanoue | 0:3edcfa3aba71 | 131 | #endif |