XBee and XBee-PRO ZigBee RF modules provide cost-effective wireless connectivity to electronic devices. They are interoperable with other ZigBee PRO feature set devices, including devices from other vendors.
Core/APIFrame.h@1:3dc0ec2f9fd6, 2015-10-22 (annotated)
- Committer:
- yangcq88517
- Date:
- Thu Oct 22 20:02:11 2015 +0000
- Revision:
- 1:3dc0ec2f9fd6
- Parent:
- 0:837e6c48e90d
- Child:
- 3:6b205ec8624b
bug fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangcq88517 | 0:837e6c48e90d | 1 | #ifndef UK_AC_HERTS_SMARTLAB_XBEE_APIFrame |
yangcq88517 | 0:837e6c48e90d | 2 | #define UK_AC_HERTS_SMARTLAB_XBEE_APIFrame |
yangcq88517 | 0:837e6c48e90d | 3 | |
yangcq88517 | 0:837e6c48e90d | 4 | #include "BufferedArray.h" |
yangcq88517 | 0:837e6c48e90d | 5 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 6 | /// An API frame is the structured data sent and received through the serial interface of the radio module when it is configured in API or API escaped operating modes. API frames are used to communicate with the module or with other modules in the network. |
yangcq88517 | 0:837e6c48e90d | 7 | class APIFrame : public BufferedArray |
yangcq88517 | 0:837e6c48e90d | 8 | { |
yangcq88517 | 0:837e6c48e90d | 9 | private: |
yangcq88517 | 1:3dc0ec2f9fd6 | 10 | /// Checksum value for the API fram. |
yangcq88517 | 0:837e6c48e90d | 11 | char checkSum; |
yangcq88517 | 0:837e6c48e90d | 12 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 13 | /// A state to indicate whether this packet's checksum is verified while process. |
yangcq88517 | 0:837e6c48e90d | 14 | bool isVerify; |
yangcq88517 | 0:837e6c48e90d | 15 | |
yangcq88517 | 0:837e6c48e90d | 16 | public: |
yangcq88517 | 0:837e6c48e90d | 17 | static const char Tx64_Request =0x00; |
yangcq88517 | 0:837e6c48e90d | 18 | static const char Tx16_Request =0x01; |
yangcq88517 | 0:837e6c48e90d | 19 | static const char AT_Command = 0x08; |
yangcq88517 | 0:837e6c48e90d | 20 | static const char AT_Command_Queue_Parameter_Value = 0x09; |
yangcq88517 | 0:837e6c48e90d | 21 | static const char ZigBee_Transmit_Request = 0x10; |
yangcq88517 | 0:837e6c48e90d | 22 | static const char Explicit_Addressing_ZigBee_Command_Frame = 0x11; |
yangcq88517 | 0:837e6c48e90d | 23 | static const char Remote_Command_Request = 0x17; |
yangcq88517 | 0:837e6c48e90d | 24 | static const char Create_Source_Route = 0x21; |
yangcq88517 | 0:837e6c48e90d | 25 | static const char Register_Joining_Device = 0x24; |
yangcq88517 | 0:837e6c48e90d | 26 | static const char Rx64_Receive_Packet = 0x80; |
yangcq88517 | 0:837e6c48e90d | 27 | static const char Rx16_Receive_Packet = 0x81; |
yangcq88517 | 0:837e6c48e90d | 28 | static const char Rx64_IO_Data_Sample_Rx_Indicator = 0x82; |
yangcq88517 | 0:837e6c48e90d | 29 | static const char Rx16_IO_Data_Sample_Rx_Indicator = 0x83; |
yangcq88517 | 0:837e6c48e90d | 30 | static const char AT_Command_Response = 0x88; |
yangcq88517 | 0:837e6c48e90d | 31 | static const char XBee_Transmit_Status = 0x89; |
yangcq88517 | 0:837e6c48e90d | 32 | static const char Modem_Status = 0x8A; |
yangcq88517 | 0:837e6c48e90d | 33 | static const char ZigBee_Transmit_Status = 0x8B; |
yangcq88517 | 0:837e6c48e90d | 34 | static const char ZigBee_Receive_Packet = 0x90; |
yangcq88517 | 0:837e6c48e90d | 35 | static const char ZigBee_Explicit_Rx_Indicator = 0x91; |
yangcq88517 | 0:837e6c48e90d | 36 | static const char ZigBee_IO_Data_Sample_Rx_Indicator = 0x92; |
yangcq88517 | 0:837e6c48e90d | 37 | static const char XBee_Sensor_Read_Indicato = 0x94; |
yangcq88517 | 0:837e6c48e90d | 38 | static const char Node_Identification_Indicator = 0x95; |
yangcq88517 | 0:837e6c48e90d | 39 | static const char Remote_Command_Response = 0x97; |
yangcq88517 | 0:837e6c48e90d | 40 | static const char Over_the_Air_Firmware_Update_Status = 0xA0; |
yangcq88517 | 0:837e6c48e90d | 41 | static const char Route_Record_Indicator = 0xA1; |
yangcq88517 | 0:837e6c48e90d | 42 | static const char Device_Authenticated_Indicator = 0xA2; |
yangcq88517 | 0:837e6c48e90d | 43 | static const char Many_to_One_Route_Request_Indicator = 0xA3; |
yangcq88517 | 0:837e6c48e90d | 44 | |
yangcq88517 | 0:837e6c48e90d | 45 | static const char StartDelimiter = 0x7E; |
yangcq88517 | 0:837e6c48e90d | 46 | |
yangcq88517 | 0:837e6c48e90d | 47 | APIFrame(int payloadLength); |
yangcq88517 | 0:837e6c48e90d | 48 | |
yangcq88517 | 0:837e6c48e90d | 49 | APIFrame(APIFrame * frame); |
yangcq88517 | 0:837e6c48e90d | 50 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 51 | /** Get the API frame type. |
yangcq88517 | 1:3dc0ec2f9fd6 | 52 | * |
yangcq88517 | 0:837e6c48e90d | 53 | * @returns |
yangcq88517 | 0:837e6c48e90d | 54 | * Tx64_Request =0x00, |
yangcq88517 | 0:837e6c48e90d | 55 | * Tx16_Request =0x01, |
yangcq88517 | 0:837e6c48e90d | 56 | * AT_Command = 0x08, |
yangcq88517 | 0:837e6c48e90d | 57 | * AT_Command_Queue_Parameter_Value = 0x09, |
yangcq88517 | 0:837e6c48e90d | 58 | * ZigBee_Transmit_Request = 0x10, |
yangcq88517 | 0:837e6c48e90d | 59 | * Explicit_Addressing_ZigBee_Command_Frame = 0x11, |
yangcq88517 | 0:837e6c48e90d | 60 | * Remote_Command_Request = 0x17, |
yangcq88517 | 0:837e6c48e90d | 61 | * Create_Source_Route = 0x21, |
yangcq88517 | 0:837e6c48e90d | 62 | * Register_Joining_Device = 0x24, |
yangcq88517 | 0:837e6c48e90d | 63 | * Rx64_Receive_Packet = 0x80, |
yangcq88517 | 0:837e6c48e90d | 64 | * Rx16_Receive_Packet = 0x81, |
yangcq88517 | 0:837e6c48e90d | 65 | * Rx64_IO_Data_Sample_Rx_Indicator = 0x82, |
yangcq88517 | 0:837e6c48e90d | 66 | * Rx16_IO_Data_Sample_Rx_Indicator = 0x83, |
yangcq88517 | 0:837e6c48e90d | 67 | * AT_Command_Response = 0x88, |
yangcq88517 | 0:837e6c48e90d | 68 | * XBee_Transmit_Status = 0x89, |
yangcq88517 | 0:837e6c48e90d | 69 | * Modem_Status = 0x8A, |
yangcq88517 | 0:837e6c48e90d | 70 | * ZigBee_Transmit_Status = 0x8B, |
yangcq88517 | 0:837e6c48e90d | 71 | * ZigBee_Receive_Packet = 0x90, |
yangcq88517 | 0:837e6c48e90d | 72 | * ZigBee_Explicit_Rx_Indicator = 0x91, |
yangcq88517 | 0:837e6c48e90d | 73 | * ZigBee_IO_Data_Sample_Rx_Indicator = 0x92, |
yangcq88517 | 0:837e6c48e90d | 74 | * XBee_Sensor_Read_Indicato = 0x94, |
yangcq88517 | 0:837e6c48e90d | 75 | * Node_Identification_Indicator = 0x95, |
yangcq88517 | 0:837e6c48e90d | 76 | * Remote_Command_Response = 0x97, |
yangcq88517 | 0:837e6c48e90d | 77 | * Over_the_Air_Firmware_Update_Status = 0xA0, |
yangcq88517 | 0:837e6c48e90d | 78 | * Route_Record_Indicator = 0xA1, |
yangcq88517 | 0:837e6c48e90d | 79 | * Device_Authenticated_Indicator = 0xA2, |
yangcq88517 | 0:837e6c48e90d | 80 | * Many_to_One_Route_Request_Indicator = 0xA3, |
yangcq88517 | 0:837e6c48e90d | 81 | */ |
yangcq88517 | 0:837e6c48e90d | 82 | char getFrameType(); |
yangcq88517 | 0:837e6c48e90d | 83 | |
yangcq88517 | 0:837e6c48e90d | 84 | void setFrameType(char identifier); |
yangcq88517 | 0:837e6c48e90d | 85 | |
yangcq88517 | 0:837e6c48e90d | 86 | void allocate(int length); |
yangcq88517 | 0:837e6c48e90d | 87 | |
yangcq88517 | 0:837e6c48e90d | 88 | void rewind(); |
yangcq88517 | 0:837e6c48e90d | 89 | |
yangcq88517 | 0:837e6c48e90d | 90 | bool convert(APIFrame * frame); |
yangcq88517 | 0:837e6c48e90d | 91 | |
yangcq88517 | 0:837e6c48e90d | 92 | /** Write 8-bit data into current posiston and increase by 1. |
yangcq88517 | 0:837e6c48e90d | 93 | * @param value sigle byte |
yangcq88517 | 0:837e6c48e90d | 94 | */ |
yangcq88517 | 0:837e6c48e90d | 95 | void set(char value); |
yangcq88517 | 0:837e6c48e90d | 96 | |
yangcq88517 | 0:837e6c48e90d | 97 | /** Write array of data into current posiston, and increase by the lenght. |
yangcq88517 | 0:837e6c48e90d | 98 | * @param value array of byte |
yangcq88517 | 0:837e6c48e90d | 99 | * @param offset start point of the data |
yangcq88517 | 0:837e6c48e90d | 100 | * @param length length to write |
yangcq88517 | 0:837e6c48e90d | 101 | */ |
yangcq88517 | 0:837e6c48e90d | 102 | void sets(const char * value, int offset, int length); |
yangcq88517 | 0:837e6c48e90d | 103 | |
yangcq88517 | 0:837e6c48e90d | 104 | /** Write 8-bit data into specific posiston and deos not affect the current position. |
yangcq88517 | 0:837e6c48e90d | 105 | * @param position where to write |
yangcq88517 | 0:837e6c48e90d | 106 | * @param value sigle byte |
yangcq88517 | 0:837e6c48e90d | 107 | */ |
yangcq88517 | 0:837e6c48e90d | 108 | void set(int position, char value); |
yangcq88517 | 0:837e6c48e90d | 109 | |
yangcq88517 | 0:837e6c48e90d | 110 | /** Write array of data into specific posiston and deos not affect the current position. |
yangcq88517 | 0:837e6c48e90d | 111 | * @param position where to write |
yangcq88517 | 0:837e6c48e90d | 112 | * @param value array of byte |
yangcq88517 | 0:837e6c48e90d | 113 | * @param offset start point of the data |
yangcq88517 | 0:837e6c48e90d | 114 | * @param length length to write |
yangcq88517 | 0:837e6c48e90d | 115 | */ |
yangcq88517 | 0:837e6c48e90d | 116 | void sets(int position, const char * value, int offset, int length); |
yangcq88517 | 0:837e6c48e90d | 117 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 118 | /** Get checksum. |
yangcq88517 | 1:3dc0ec2f9fd6 | 119 | * @returns the checksum value |
yangcq88517 | 1:3dc0ec2f9fd6 | 120 | */ |
yangcq88517 | 0:837e6c48e90d | 121 | char getCheckSum(); |
yangcq88517 | 0:837e6c48e90d | 122 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 123 | /** Set checksum. |
yangcq88517 | 1:3dc0ec2f9fd6 | 124 | * @param value checksum value |
yangcq88517 | 1:3dc0ec2f9fd6 | 125 | */ |
yangcq88517 | 0:837e6c48e90d | 126 | void setCheckSum(char value); |
yangcq88517 | 0:837e6c48e90d | 127 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 128 | /** Check is the API frame's checksum is verified. |
yangcq88517 | 1:3dc0ec2f9fd6 | 129 | * @returns true checksum match, |
yangcq88517 | 1:3dc0ec2f9fd6 | 130 | * false checksum not match |
yangcq88517 | 1:3dc0ec2f9fd6 | 131 | */ |
yangcq88517 | 0:837e6c48e90d | 132 | bool verifyChecksum(); |
yangcq88517 | 0:837e6c48e90d | 133 | |
yangcq88517 | 1:3dc0ec2f9fd6 | 134 | /// Calculate the checksum value. |
yangcq88517 | 0:837e6c48e90d | 135 | void calculateChecksum(); |
yangcq88517 | 0:837e6c48e90d | 136 | }; |
yangcq88517 | 0:837e6c48e90d | 137 | |
yangcq88517 | 0:837e6c48e90d | 138 | #endif |