XBee API operation library for mbed for miniprojects

Dependencies:   SmartLabXBeeCore

Fork of SmartLabXBeeAPI2 by CHENGQI YANG

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers XBeeAPI.h Source File

XBeeAPI.h

00001 #ifndef UK_AC_HERTS_SMARTLAB_XBEE_API
00002 #define UK_AC_HERTS_SMARTLAB_XBEE_API
00003 
00004 #include "mbed.h"
00005 #include "SerialData.h"
00006 #include "CoreAPI.h"
00007 
00008 /** XBee API library entry poiont.
00009 * Example:
00010 * @code
00011 * #include "mbed.h"
00012 * #include "XBeeAPI.h"
00013 *
00014 * XBeeAPI xbee(p9, p10, true);
00015 * Address add(0x0013A200,0x406CABD,0x0456);
00016 * XBeeTx16Request tx16(0x00, &add, OptionsBase::DEFAULT, "Hello From XBEE API", 0, 19);
00017 * XBeeRx16Indicator rx16(NULL);
00018 *
00019 * int main()
00020 * {
00021 *    xbee.setVerifyChecksum(false);
00022 *    xbee.start();
00023 *
00024 *    // option 1
00025 *    while(1) {
00026 *        XBeeRx16Indicator * response = xbee.getXBeeRx16();
00027 *        if (response != NULL) {
00028 *            tx16.setPayload(response->getReceivedData(), 0, response->getReceivedDataLength());
00029 *            xbee.send(&tx16);
00030 *        }
00031 *    }
00032 *
00033 *    // option 2
00034 *    while(1) {
00035 *
00036 *        APIFrame * frame = xbee.getResponse();
00037 *        while(frame != NULL) {
00038 *            switch (frame->getFrameType()) {
00039 *                case APIFrame::Tx64_Request :
00040 *                    break;
00041 *                case APIFrame::Tx16_Request :
00042 *                    break;
00043 *                case APIFrame::AT_Command:
00044 *                    break;
00045 *                case APIFrame::AT_Command_Queue_Parameter_Value:
00046 *                    break;
00047 *                case APIFrame::ZigBee_Transmit_Request:
00048 *                    break;
00049 *                case APIFrame::Explicit_Addressing_ZigBee_Command_Frame:
00050 *                    break;
00051 *                case APIFrame::Remote_Command_Request :
00052 *                    break;
00053 *                case APIFrame::Create_Source_Route :
00054 *                    break;
00055 *                case APIFrame::Register_Joining_Device:
00056 *                    break;
00057 *                case APIFrame::Rx64_Receive_Packet :
00058 *                    break;
00059 *                case APIFrame::Rx16_Receive_Packet:
00060 *                    rx16.convert(frame);
00061 *                    tx16.setPayload(rx16.getReceivedData(), 0, rx16.getReceivedDataLength());
00062 *                    xbee.send(&tx16);
00063 *                    break;
00064 *                case APIFrame::Rx64_IO_Data_Sample_Rx_Indicator:
00065 *                    break;
00066 *                case APIFrame::Rx16_IO_Data_Sample_Rx_Indicator :
00067 *                    xbee.send(&tx16);
00068 *                    break;
00069 *                case APIFrame::AT_Command_Response:
00070 *                    break;
00071 *                case APIFrame::XBee_Transmit_Status :
00072 *                    break;
00073 *                case APIFrame::Modem_Status:
00074 *                    break;
00075 *                case APIFrame::ZigBee_Transmit_Status :
00076 *                    break;
00077 *                case APIFrame::ZigBee_Receive_Packet:
00078 *                    break;
00079 *                case APIFrame::ZigBee_Explicit_Rx_Indicator :
00080 *                    break;
00081 *                case APIFrame::ZigBee_IO_Data_Sample_Rx_Indicator :
00082 *                    break;
00083 *                case APIFrame::XBee_Sensor_Read_Indicato :
00084 *                    break;
00085 *                case APIFrame::Node_Identification_Indicator:
00086 *                    break;
00087 *                case APIFrame::Remote_Command_Response:
00088 *                    break;
00089 *                case APIFrame::Over_the_Air_Firmware_Update_Status :
00090 *                    break;
00091 *                case APIFrame::Route_Record_Indicator :
00092 *                    break;
00093 *                case APIFrame::Device_Authenticated_Indicator:
00094 *                    break;
00095 *                case APIFrame::Many_to_One_Route_Request_Indicator:
00096 *                    break;
00097 *            }
00098 *
00099 *            frame = xbee.getResponse();
00100 *        }
00101 *    }
00102 * }
00103 * @endcode
00104 */
00105 class XBeeAPI: public CoreAPI
00106 {
00107 public:
00108 
00109     /** Create a XBeeAPI instance, with baud rate 9600 and no escape.
00110     *
00111     * @param tx data transmission line
00112     * @param rx data receiving line
00113     *
00114     */
00115     XBeeAPI(PinName tx, PinName rx);
00116 
00117     /** Create a XBeeAPI instance, with baud rate 9600.
00118     *
00119     * @param tx data transmission line
00120     * @param rx data receiving line
00121     * @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.
00122     *
00123     */
00124     XBeeAPI(PinName tx, PinName rx, bool isEscape);
00125 
00126     /** Create a XBeeAPI instance. 
00127     *
00128     * @param tx data transmission line
00129     * @param rx data receiving line
00130     * @param baudRate baud rate
00131     * @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.
00132     *
00133     */
00134     XBeeAPI(PinName tx, PinName rx, int baudRate, bool isEscape);
00135 
00136     /** Create a SerialData instance with other serial interface.
00137     *
00138     * @param serial class that implementes ISerial interface.
00139     * @param baudRate baud rate
00140     * @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.
00141     *
00142     */
00143     XBeeAPI(ISerial * serial, bool isEscape);
00144 };
00145 
00146 #endif