XBee API operation library for mbed for miniprojects

Dependencies:   SmartLabXBeeCore

Fork of SmartLabXBeeAPI2 by CHENGQI YANG

Committer:
yangcq88517
Date:
Thu Oct 22 20:02:33 2015 +0000
Revision:
2:723cccd7659a
Parent:
0:415f4b1b988e
Child:
5:da252d355673
bug fix

Who changed what in which revision?

UserRevisionLine numberNew 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 2:723cccd7659a 9 *Example:
yangcq88517 2:723cccd7659a 10 * @code
yangcq88517 2:723cccd7659a 11 *#include "mbed.h"
yangcq88517 2:723cccd7659a 12 *#include "XBeeAPI.h"
yangcq88517 2:723cccd7659a 13 *
yangcq88517 2:723cccd7659a 14 *XBeeAPI xbee(p9, p10, true);
yangcq88517 2:723cccd7659a 15 *Address add(0x00,0x00,0x1022);
yangcq88517 2:723cccd7659a 16 *XBeeTx16Request tx16(0x00, &add, &OptionsBase::DEFAULT, "Hello From XBEE API", 0, 19);
yangcq88517 2:723cccd7659a 17 *XBeeRx16Indicator rx16(NULL);
yangcq88517 2:723cccd7659a 18 *
yangcq88517 2:723cccd7659a 19 *int main()
yangcq88517 2:723cccd7659a 20 *{
yangcq88517 2:723cccd7659a 21 * xbee.setVerifyChecksum(false);
yangcq88517 2:723cccd7659a 22 * xbee.start();
yangcq88517 2:723cccd7659a 23 *
yangcq88517 2:723cccd7659a 24 * // option 1
yangcq88517 2:723cccd7659a 25 * while(1) {
yangcq88517 2:723cccd7659a 26 * XBeeRx16Indicator * response = xbee.getXBeeRx16();
yangcq88517 2:723cccd7659a 27 * if (response != NULL) {
yangcq88517 2:723cccd7659a 28 * tx16.setPayload(response->getReceivedData(), 0, response->getReceivedDataLength());
yangcq88517 2:723cccd7659a 29 * xbee.send(&tx16);
yangcq88517 2:723cccd7659a 30 * }
yangcq88517 2:723cccd7659a 31 * }
yangcq88517 2:723cccd7659a 32 *
yangcq88517 2:723cccd7659a 33 * // option 2
yangcq88517 2:723cccd7659a 34 * while(1) {
yangcq88517 2:723cccd7659a 35 *
yangcq88517 2:723cccd7659a 36 * APIFrame * frame = xbee.getResponse();
yangcq88517 2:723cccd7659a 37 * while(frame != NULL) {
yangcq88517 2:723cccd7659a 38 * switch (frame->getFrameType()) {
yangcq88517 2:723cccd7659a 39 * case APIFrame::Tx64_Request :
yangcq88517 2:723cccd7659a 40 * break;
yangcq88517 2:723cccd7659a 41 * case APIFrame::Tx16_Request :
yangcq88517 2:723cccd7659a 42 * break;
yangcq88517 2:723cccd7659a 43 * case APIFrame::AT_Command:
yangcq88517 2:723cccd7659a 44 * break;
yangcq88517 2:723cccd7659a 45 * case APIFrame::AT_Command_Queue_Parameter_Value:
yangcq88517 2:723cccd7659a 46 * break;
yangcq88517 2:723cccd7659a 47 * case APIFrame::ZigBee_Transmit_Request:
yangcq88517 2:723cccd7659a 48 * break;
yangcq88517 2:723cccd7659a 49 * case APIFrame::Explicit_Addressing_ZigBee_Command_Frame:
yangcq88517 2:723cccd7659a 50 * break;
yangcq88517 2:723cccd7659a 51 * case APIFrame::Remote_Command_Request :
yangcq88517 2:723cccd7659a 52 * break;
yangcq88517 2:723cccd7659a 53 * case APIFrame::Create_Source_Route :
yangcq88517 2:723cccd7659a 54 * break;
yangcq88517 2:723cccd7659a 55 * case APIFrame::Register_Joining_Device:
yangcq88517 2:723cccd7659a 56 * break;
yangcq88517 2:723cccd7659a 57 * case APIFrame::Rx64_Receive_Packet :
yangcq88517 2:723cccd7659a 58 * break;
yangcq88517 2:723cccd7659a 59 * case APIFrame::Rx16_Receive_Packet:
yangcq88517 2:723cccd7659a 60 * rx16.convert(frame);
yangcq88517 2:723cccd7659a 61 * tx16.setPayload(rx16.getReceivedData(), 0, rx16.getReceivedDataLength());
yangcq88517 2:723cccd7659a 62 * xbee.send(&tx16);
yangcq88517 2:723cccd7659a 63 * break;
yangcq88517 2:723cccd7659a 64 * case APIFrame::Rx64_IO_Data_Sample_Rx_Indicator:
yangcq88517 2:723cccd7659a 65 * break;
yangcq88517 2:723cccd7659a 66 * case APIFrame::Rx16_IO_Data_Sample_Rx_Indicator :
yangcq88517 2:723cccd7659a 67 * xbee.send(&tx16);
yangcq88517 2:723cccd7659a 68 * break;
yangcq88517 2:723cccd7659a 69 * case APIFrame::AT_Command_Response:
yangcq88517 2:723cccd7659a 70 * break;
yangcq88517 2:723cccd7659a 71 * case APIFrame::XBee_Transmit_Status :
yangcq88517 2:723cccd7659a 72 * break;
yangcq88517 2:723cccd7659a 73 * case APIFrame::Modem_Status:
yangcq88517 2:723cccd7659a 74 * break;
yangcq88517 2:723cccd7659a 75 * case APIFrame::ZigBee_Transmit_Status :
yangcq88517 2:723cccd7659a 76 * break;
yangcq88517 2:723cccd7659a 77 * case APIFrame::ZigBee_Receive_Packet:
yangcq88517 2:723cccd7659a 78 * break;
yangcq88517 2:723cccd7659a 79 * case APIFrame::ZigBee_Explicit_Rx_Indicator :
yangcq88517 2:723cccd7659a 80 * break;
yangcq88517 2:723cccd7659a 81 * case APIFrame::ZigBee_IO_Data_Sample_Rx_Indicator :
yangcq88517 2:723cccd7659a 82 * break;
yangcq88517 2:723cccd7659a 83 * case APIFrame::XBee_Sensor_Read_Indicato :
yangcq88517 2:723cccd7659a 84 * break;
yangcq88517 2:723cccd7659a 85 * case APIFrame::Node_Identification_Indicator:
yangcq88517 2:723cccd7659a 86 * break;
yangcq88517 2:723cccd7659a 87 * case APIFrame::Remote_Command_Response:
yangcq88517 2:723cccd7659a 88 * break;
yangcq88517 2:723cccd7659a 89 * case APIFrame::Over_the_Air_Firmware_Update_Status :
yangcq88517 2:723cccd7659a 90 * break;
yangcq88517 2:723cccd7659a 91 * case APIFrame::Route_Record_Indicator :
yangcq88517 2:723cccd7659a 92 * break;
yangcq88517 2:723cccd7659a 93 * case APIFrame::Device_Authenticated_Indicator:
yangcq88517 2:723cccd7659a 94 * break;
yangcq88517 2:723cccd7659a 95 * case APIFrame::Many_to_One_Route_Request_Indicator:
yangcq88517 2:723cccd7659a 96 * break;
yangcq88517 2:723cccd7659a 97 * }
yangcq88517 2:723cccd7659a 98 *
yangcq88517 2:723cccd7659a 99 * frame = xbee.getResponse();
yangcq88517 2:723cccd7659a 100 * }
yangcq88517 2:723cccd7659a 101 * }
yangcq88517 2:723cccd7659a 102 *}
yangcq88517 2:723cccd7659a 103 *@endcode
yangcq88517 2:723cccd7659a 104 */
yangcq88517 0:415f4b1b988e 105 class XBeeAPI: public CoreAPI
yangcq88517 0:415f4b1b988e 106 {
yangcq88517 2:723cccd7659a 107 public:
yangcq88517 0:415f4b1b988e 108
yangcq88517 2:723cccd7659a 109 /** Create a XBeeAPI instance.
yangcq88517 2:723cccd7659a 110 *
yangcq88517 2:723cccd7659a 111 * @param tx data transmission line
yangcq88517 2:723cccd7659a 112 * @param rx data receiving line
yangcq88517 2:723cccd7659a 113 *
yangcq88517 2:723cccd7659a 114 */
yangcq88517 0:415f4b1b988e 115 XBeeAPI(PinName tx, PinName rx);
yangcq88517 0:415f4b1b988e 116
yangcq88517 2:723cccd7659a 117 /** Create a XBeeAPI instance.
yangcq88517 2:723cccd7659a 118 *
yangcq88517 2:723cccd7659a 119 * @param tx data transmission line
yangcq88517 2:723cccd7659a 120 * @param rx data receiving line
yangcq88517 2:723cccd7659a 121 * @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 122 *
yangcq88517 2:723cccd7659a 123 */
yangcq88517 0:415f4b1b988e 124 XBeeAPI(PinName tx, PinName rx, bool isEscape);
yangcq88517 0:415f4b1b988e 125
yangcq88517 2:723cccd7659a 126 /** Create a XBeeAPI instance.
yangcq88517 2:723cccd7659a 127 *
yangcq88517 2:723cccd7659a 128 * @param tx data transmission line
yangcq88517 2:723cccd7659a 129 * @param rx data receiving line
yangcq88517 2:723cccd7659a 130 * @param baudRate baud rate
yangcq88517 2:723cccd7659a 131 * @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 132 *
yangcq88517 2:723cccd7659a 133 */
yangcq88517 0:415f4b1b988e 134 XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape);
yangcq88517 0:415f4b1b988e 135
yangcq88517 2:723cccd7659a 136 /** Create a SerialData instance with other serial interface.
yangcq88517 2:723cccd7659a 137 *
yangcq88517 2:723cccd7659a 138 * @param serial class that implementes ISerial interface.
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