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.

Dependencies:   BufferedArray

Dependents:   MBEDminiproject

Committer:
yangcq88517
Date:
Sat Nov 14 16:42:36 2015 +0000
Revision:
6:5f31ddc17239
Parent:
3:6b205ec8624b
change to unsigned char array

Who changed what in which revision?

UserRevisionLine numberNew 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 6:5f31ddc17239 11 unsigned 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 6:5f31ddc17239 17 static const unsigned char Tx64_Request =0x00;
yangcq88517 6:5f31ddc17239 18 static const unsigned char Tx16_Request =0x01;
yangcq88517 6:5f31ddc17239 19 static const unsigned char AT_Command = 0x08;
yangcq88517 6:5f31ddc17239 20 static const unsigned char AT_Command_Queue_Parameter_Value = 0x09;
yangcq88517 6:5f31ddc17239 21 static const unsigned char ZigBee_Transmit_Request = 0x10;
yangcq88517 6:5f31ddc17239 22 static const unsigned char Explicit_Addressing_ZigBee_Command_Frame = 0x11;
yangcq88517 6:5f31ddc17239 23 static const unsigned char Remote_Command_Request = 0x17;
yangcq88517 6:5f31ddc17239 24 static const unsigned char Create_Source_Route = 0x21;
yangcq88517 6:5f31ddc17239 25 static const unsigned char Register_Joining_Device = 0x24;
yangcq88517 6:5f31ddc17239 26 static const unsigned char Rx64_Receive_Packet = 0x80;
yangcq88517 6:5f31ddc17239 27 static const unsigned char Rx16_Receive_Packet = 0x81;
yangcq88517 6:5f31ddc17239 28 static const unsigned char Rx64_IO_Data_Sample_Rx_Indicator = 0x82;
yangcq88517 6:5f31ddc17239 29 static const unsigned char Rx16_IO_Data_Sample_Rx_Indicator = 0x83;
yangcq88517 6:5f31ddc17239 30 static const unsigned char AT_Command_Response = 0x88;
yangcq88517 6:5f31ddc17239 31 static const unsigned char XBee_Transmit_Status = 0x89;
yangcq88517 6:5f31ddc17239 32 static const unsigned char Modem_Status = 0x8A;
yangcq88517 6:5f31ddc17239 33 static const unsigned char ZigBee_Transmit_Status = 0x8B;
yangcq88517 6:5f31ddc17239 34 static const unsigned char ZigBee_Receive_Packet = 0x90;
yangcq88517 6:5f31ddc17239 35 static const unsigned char ZigBee_Explicit_Rx_Indicator = 0x91;
yangcq88517 6:5f31ddc17239 36 static const unsigned char ZigBee_IO_Data_Sample_Rx_Indicator = 0x92;
yangcq88517 6:5f31ddc17239 37 static const unsigned char XBee_Sensor_Read_Indicato = 0x94;
yangcq88517 6:5f31ddc17239 38 static const unsigned char Node_Identification_Indicator = 0x95;
yangcq88517 6:5f31ddc17239 39 static const unsigned char Remote_Command_Response = 0x97;
yangcq88517 6:5f31ddc17239 40 static const unsigned char Over_the_Air_Firmware_Update_Status = 0xA0;
yangcq88517 6:5f31ddc17239 41 static const unsigned char Route_Record_Indicator = 0xA1;
yangcq88517 6:5f31ddc17239 42 static const unsigned char Device_Authenticated_Indicator = 0xA2;
yangcq88517 6:5f31ddc17239 43 static const unsigned char Many_to_One_Route_Request_Indicator = 0xA3;
yangcq88517 0:837e6c48e90d 44
yangcq88517 6:5f31ddc17239 45 static const unsigned char StartDelimiter = 0x7E;
yangcq88517 0:837e6c48e90d 46
yangcq88517 6:5f31ddc17239 47 APIFrame(unsigned 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 6:5f31ddc17239 82 unsigned char getFrameType();
yangcq88517 0:837e6c48e90d 83
yangcq88517 6:5f31ddc17239 84 void setFrameType(unsigned char identifier);
yangcq88517 0:837e6c48e90d 85
yangcq88517 6:5f31ddc17239 86 void allocate(unsigned long 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 6:5f31ddc17239 95 void set(unsigned 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 6:5f31ddc17239 102 void sets(const unsigned char * value, unsigned long offset, unsigned long 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 6:5f31ddc17239 108 void set(unsigned long position, unsigned 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 6:5f31ddc17239 116 void sets(unsigned long position, const unsigned char * value, unsigned long offset, unsigned long 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 6:5f31ddc17239 126 void setCheckSum(unsigned 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