XBee API operation library for mbed
XBeeAPI.h@8:4da2ac03e35e, 2016-03-30 (annotated)
- Committer:
- yangcq88517
- Date:
- Wed Mar 30 19:58:48 2016 +0000
- Revision:
- 8:4da2ac03e35e
- Parent:
- 5:da252d355673
put every thing together and documentation bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangcq88517 | 0:415f4b1b988e | 1 | #ifndef UK_AC_HERTS_SMARTLAB_XBEE_API |
yangcq88517 | 0:415f4b1b988e | 2 | #define UK_AC_HERTS_SMARTLAB_XBEE_API |
yangcq88517 | 0:415f4b1b988e | 3 | |
yangcq88517 | 0:415f4b1b988e | 4 | #include "mbed.h" |
yangcq88517 | 0:415f4b1b988e | 5 | #include "SerialData.h" |
yangcq88517 | 0:415f4b1b988e | 6 | #include "CoreAPI.h" |
yangcq88517 | 0:415f4b1b988e | 7 | |
yangcq88517 | 2:723cccd7659a | 8 | /** XBee API library entry poiont. |
yangcq88517 | 5:da252d355673 | 9 | * Example: |
yangcq88517 | 2:723cccd7659a | 10 | * @code |
yangcq88517 | 5:da252d355673 | 11 | * #include "mbed.h" |
yangcq88517 | 5:da252d355673 | 12 | * #include "XBeeAPI.h" |
yangcq88517 | 2:723cccd7659a | 13 | * |
yangcq88517 | 5:da252d355673 | 14 | * XBeeAPI xbee(p9, p10, true); |
yangcq88517 | 5:da252d355673 | 15 | * Address add(0x0013A200,0x406CABD,0x0456); |
yangcq88517 | 5:da252d355673 | 16 | * XBeeTx16Request tx16(0x00, &add, OptionsBase::DEFAULT, "Hello From XBEE API", 0, 19); |
yangcq88517 | 5:da252d355673 | 17 | * XBeeRx16Indicator rx16(NULL); |
yangcq88517 | 2:723cccd7659a | 18 | * |
yangcq88517 | 5:da252d355673 | 19 | * int main() |
yangcq88517 | 5:da252d355673 | 20 | * { |
yangcq88517 | 2:723cccd7659a | 21 | * xbee.setVerifyChecksum(false); |
yangcq88517 | 2:723cccd7659a | 22 | * |
yangcq88517 | 2:723cccd7659a | 23 | * // option 1 |
yangcq88517 | 2:723cccd7659a | 24 | * while(1) { |
yangcq88517 | 2:723cccd7659a | 25 | * XBeeRx16Indicator * response = xbee.getXBeeRx16(); |
yangcq88517 | 2:723cccd7659a | 26 | * if (response != NULL) { |
yangcq88517 | 2:723cccd7659a | 27 | * tx16.setPayload(response->getReceivedData(), 0, response->getReceivedDataLength()); |
yangcq88517 | 2:723cccd7659a | 28 | * xbee.send(&tx16); |
yangcq88517 | 2:723cccd7659a | 29 | * } |
yangcq88517 | 2:723cccd7659a | 30 | * } |
yangcq88517 | 2:723cccd7659a | 31 | * |
yangcq88517 | 2:723cccd7659a | 32 | * // option 2 |
yangcq88517 | 2:723cccd7659a | 33 | * while(1) { |
yangcq88517 | 2:723cccd7659a | 34 | * |
yangcq88517 | 2:723cccd7659a | 35 | * APIFrame * frame = xbee.getResponse(); |
yangcq88517 | 2:723cccd7659a | 36 | * while(frame != NULL) { |
yangcq88517 | 2:723cccd7659a | 37 | * switch (frame->getFrameType()) { |
yangcq88517 | 2:723cccd7659a | 38 | * case APIFrame::Tx64_Request : |
yangcq88517 | 2:723cccd7659a | 39 | * break; |
yangcq88517 | 2:723cccd7659a | 40 | * case APIFrame::Tx16_Request : |
yangcq88517 | 2:723cccd7659a | 41 | * break; |
yangcq88517 | 2:723cccd7659a | 42 | * case APIFrame::AT_Command: |
yangcq88517 | 2:723cccd7659a | 43 | * break; |
yangcq88517 | 2:723cccd7659a | 44 | * case APIFrame::AT_Command_Queue_Parameter_Value: |
yangcq88517 | 2:723cccd7659a | 45 | * break; |
yangcq88517 | 2:723cccd7659a | 46 | * case APIFrame::ZigBee_Transmit_Request: |
yangcq88517 | 2:723cccd7659a | 47 | * break; |
yangcq88517 | 2:723cccd7659a | 48 | * case APIFrame::Explicit_Addressing_ZigBee_Command_Frame: |
yangcq88517 | 2:723cccd7659a | 49 | * break; |
yangcq88517 | 2:723cccd7659a | 50 | * case APIFrame::Remote_Command_Request : |
yangcq88517 | 2:723cccd7659a | 51 | * break; |
yangcq88517 | 2:723cccd7659a | 52 | * case APIFrame::Create_Source_Route : |
yangcq88517 | 2:723cccd7659a | 53 | * break; |
yangcq88517 | 2:723cccd7659a | 54 | * case APIFrame::Register_Joining_Device: |
yangcq88517 | 2:723cccd7659a | 55 | * break; |
yangcq88517 | 2:723cccd7659a | 56 | * case APIFrame::Rx64_Receive_Packet : |
yangcq88517 | 2:723cccd7659a | 57 | * break; |
yangcq88517 | 2:723cccd7659a | 58 | * case APIFrame::Rx16_Receive_Packet: |
yangcq88517 | 2:723cccd7659a | 59 | * rx16.convert(frame); |
yangcq88517 | 2:723cccd7659a | 60 | * tx16.setPayload(rx16.getReceivedData(), 0, rx16.getReceivedDataLength()); |
yangcq88517 | 2:723cccd7659a | 61 | * xbee.send(&tx16); |
yangcq88517 | 2:723cccd7659a | 62 | * break; |
yangcq88517 | 2:723cccd7659a | 63 | * case APIFrame::Rx64_IO_Data_Sample_Rx_Indicator: |
yangcq88517 | 2:723cccd7659a | 64 | * break; |
yangcq88517 | 2:723cccd7659a | 65 | * case APIFrame::Rx16_IO_Data_Sample_Rx_Indicator : |
yangcq88517 | 2:723cccd7659a | 66 | * xbee.send(&tx16); |
yangcq88517 | 2:723cccd7659a | 67 | * break; |
yangcq88517 | 2:723cccd7659a | 68 | * case APIFrame::AT_Command_Response: |
yangcq88517 | 2:723cccd7659a | 69 | * break; |
yangcq88517 | 2:723cccd7659a | 70 | * case APIFrame::XBee_Transmit_Status : |
yangcq88517 | 2:723cccd7659a | 71 | * break; |
yangcq88517 | 2:723cccd7659a | 72 | * case APIFrame::Modem_Status: |
yangcq88517 | 2:723cccd7659a | 73 | * break; |
yangcq88517 | 2:723cccd7659a | 74 | * case APIFrame::ZigBee_Transmit_Status : |
yangcq88517 | 2:723cccd7659a | 75 | * break; |
yangcq88517 | 2:723cccd7659a | 76 | * case APIFrame::ZigBee_Receive_Packet: |
yangcq88517 | 2:723cccd7659a | 77 | * break; |
yangcq88517 | 2:723cccd7659a | 78 | * case APIFrame::ZigBee_Explicit_Rx_Indicator : |
yangcq88517 | 2:723cccd7659a | 79 | * break; |
yangcq88517 | 2:723cccd7659a | 80 | * case APIFrame::ZigBee_IO_Data_Sample_Rx_Indicator : |
yangcq88517 | 2:723cccd7659a | 81 | * break; |
yangcq88517 | 2:723cccd7659a | 82 | * case APIFrame::XBee_Sensor_Read_Indicato : |
yangcq88517 | 2:723cccd7659a | 83 | * break; |
yangcq88517 | 2:723cccd7659a | 84 | * case APIFrame::Node_Identification_Indicator: |
yangcq88517 | 2:723cccd7659a | 85 | * break; |
yangcq88517 | 2:723cccd7659a | 86 | * case APIFrame::Remote_Command_Response: |
yangcq88517 | 2:723cccd7659a | 87 | * break; |
yangcq88517 | 2:723cccd7659a | 88 | * case APIFrame::Over_the_Air_Firmware_Update_Status : |
yangcq88517 | 2:723cccd7659a | 89 | * break; |
yangcq88517 | 2:723cccd7659a | 90 | * case APIFrame::Route_Record_Indicator : |
yangcq88517 | 2:723cccd7659a | 91 | * break; |
yangcq88517 | 2:723cccd7659a | 92 | * case APIFrame::Device_Authenticated_Indicator: |
yangcq88517 | 2:723cccd7659a | 93 | * break; |
yangcq88517 | 2:723cccd7659a | 94 | * case APIFrame::Many_to_One_Route_Request_Indicator: |
yangcq88517 | 2:723cccd7659a | 95 | * break; |
yangcq88517 | 2:723cccd7659a | 96 | * } |
yangcq88517 | 2:723cccd7659a | 97 | * |
yangcq88517 | 2:723cccd7659a | 98 | * frame = xbee.getResponse(); |
yangcq88517 | 2:723cccd7659a | 99 | * } |
yangcq88517 | 2:723cccd7659a | 100 | * } |
yangcq88517 | 5:da252d355673 | 101 | * } |
yangcq88517 | 5:da252d355673 | 102 | * @endcode |
yangcq88517 | 2:723cccd7659a | 103 | */ |
yangcq88517 | 0:415f4b1b988e | 104 | class XBeeAPI: public CoreAPI |
yangcq88517 | 0:415f4b1b988e | 105 | { |
yangcq88517 | 2:723cccd7659a | 106 | public: |
yangcq88517 | 0:415f4b1b988e | 107 | |
yangcq88517 | 5:da252d355673 | 108 | /** Create a XBeeAPI instance, with baud rate 9600 and no escape. |
yangcq88517 | 2:723cccd7659a | 109 | * |
yangcq88517 | 2:723cccd7659a | 110 | * @param tx data transmission line |
yangcq88517 | 2:723cccd7659a | 111 | * @param rx data receiving line |
yangcq88517 | 2:723cccd7659a | 112 | * |
yangcq88517 | 2:723cccd7659a | 113 | */ |
yangcq88517 | 0:415f4b1b988e | 114 | XBeeAPI(PinName tx, PinName rx); |
yangcq88517 | 0:415f4b1b988e | 115 | |
yangcq88517 | 5:da252d355673 | 116 | /** Create a XBeeAPI instance, with baud rate 9600. |
yangcq88517 | 2:723cccd7659a | 117 | * |
yangcq88517 | 2:723cccd7659a | 118 | * @param tx data transmission line |
yangcq88517 | 2:723cccd7659a | 119 | * @param rx data receiving line |
yangcq88517 | 2:723cccd7659a | 120 | * @param isEscape API escaped operating mode (AP = 2) works similarly to API mode. The only difference is that when working in API escaped mode, some bytes of the API frame specific data must be escaped. |
yangcq88517 | 2:723cccd7659a | 121 | * |
yangcq88517 | 2:723cccd7659a | 122 | */ |
yangcq88517 | 0:415f4b1b988e | 123 | XBeeAPI(PinName tx, PinName rx, bool isEscape); |
yangcq88517 | 0:415f4b1b988e | 124 | |
yangcq88517 | 2:723cccd7659a | 125 | /** Create a XBeeAPI instance. |
yangcq88517 | 2:723cccd7659a | 126 | * |
yangcq88517 | 2:723cccd7659a | 127 | * @param tx data transmission line |
yangcq88517 | 2:723cccd7659a | 128 | * @param rx data receiving line |
yangcq88517 | 2:723cccd7659a | 129 | * @param baudRate baud rate |
yangcq88517 | 2:723cccd7659a | 130 | * @param isEscape API escaped operating mode (AP = 2) works similarly to API mode. The only difference is that when working in API escaped mode, some bytes of the API frame specific data must be escaped. |
yangcq88517 | 2:723cccd7659a | 131 | * |
yangcq88517 | 2:723cccd7659a | 132 | */ |
yangcq88517 | 0:415f4b1b988e | 133 | XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape); |
yangcq88517 | 0:415f4b1b988e | 134 | |
yangcq88517 | 2:723cccd7659a | 135 | /** Create a SerialData instance with other serial interface. |
yangcq88517 | 2:723cccd7659a | 136 | * |
yangcq88517 | 2:723cccd7659a | 137 | * @param serial class that implementes ISerial interface. |
yangcq88517 | 5:da252d355673 | 138 | * @param baudRate baud rate |
yangcq88517 | 2:723cccd7659a | 139 | * @param isEscape API escaped operating mode (AP = 2) works similarly to API mode. The only difference is that when working in API escaped mode, some bytes of the API frame specific data must be escaped. |
yangcq88517 | 2:723cccd7659a | 140 | * |
yangcq88517 | 2:723cccd7659a | 141 | */ |
yangcq88517 | 0:415f4b1b988e | 142 | XBeeAPI(ISerial * serial, bool isEscape); |
yangcq88517 | 0:415f4b1b988e | 143 | }; |
yangcq88517 | 0:415f4b1b988e | 144 | |
yangcq88517 | 0:415f4b1b988e | 145 | #endif |