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

Core/APIFrame.h

Committer:
yangcq88517
Date:
2015-10-26
Revision:
3:6b205ec8624b
Parent:
1:3dc0ec2f9fd6
Child:
6:5f31ddc17239

File content as of revision 3:6b205ec8624b:

#ifndef UK_AC_HERTS_SMARTLAB_XBEE_APIFrame
#define UK_AC_HERTS_SMARTLAB_XBEE_APIFrame

#include "BufferedArray.h"

/// 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.
class APIFrame : public BufferedArray
{
private:
    /// Checksum value for the API fram.
    char checkSum;

    /// A state to indicate whether this packet's checksum is verified while process.
    bool isVerify;

public:
    static const char Tx64_Request =0x00;
    static const char Tx16_Request =0x01;
    static const char AT_Command = 0x08;
    static const char AT_Command_Queue_Parameter_Value = 0x09;
    static const char ZigBee_Transmit_Request = 0x10;
    static const char Explicit_Addressing_ZigBee_Command_Frame = 0x11;
    static const char Remote_Command_Request = 0x17;
    static const char Create_Source_Route = 0x21;
    static const char Register_Joining_Device = 0x24;
    static const char Rx64_Receive_Packet = 0x80;
    static const char Rx16_Receive_Packet = 0x81;
    static const char Rx64_IO_Data_Sample_Rx_Indicator = 0x82;
    static const char Rx16_IO_Data_Sample_Rx_Indicator = 0x83;
    static const char AT_Command_Response = 0x88;
    static const char XBee_Transmit_Status = 0x89;
    static const char Modem_Status = 0x8A;
    static const char ZigBee_Transmit_Status = 0x8B;
    static const char ZigBee_Receive_Packet = 0x90;
    static const char ZigBee_Explicit_Rx_Indicator = 0x91;
    static const char ZigBee_IO_Data_Sample_Rx_Indicator = 0x92;
    static const char XBee_Sensor_Read_Indicato = 0x94;
    static const char Node_Identification_Indicator = 0x95;
    static const char Remote_Command_Response = 0x97;
    static const char Over_the_Air_Firmware_Update_Status = 0xA0;
    static const char Route_Record_Indicator = 0xA1;
    static const char Device_Authenticated_Indicator = 0xA2;
    static const char Many_to_One_Route_Request_Indicator = 0xA3;

    static const char StartDelimiter = 0x7E;

    APIFrame(int payloadLength);

    APIFrame(APIFrame * frame);

    /** Get the API frame type.
    *
    * @returns
    *    Tx64_Request =0x00,
    *    Tx16_Request =0x01,
    *    AT_Command = 0x08,
    *    AT_Command_Queue_Parameter_Value = 0x09,
    *    ZigBee_Transmit_Request = 0x10,
    *    Explicit_Addressing_ZigBee_Command_Frame = 0x11,
    *    Remote_Command_Request = 0x17,
    *    Create_Source_Route = 0x21,
    *    Register_Joining_Device = 0x24,
    *    Rx64_Receive_Packet = 0x80,
    *    Rx16_Receive_Packet = 0x81,
    *    Rx64_IO_Data_Sample_Rx_Indicator = 0x82,
    *    Rx16_IO_Data_Sample_Rx_Indicator = 0x83,
    *    AT_Command_Response = 0x88,
    *    XBee_Transmit_Status = 0x89,
    *    Modem_Status = 0x8A,
    *    ZigBee_Transmit_Status = 0x8B,
    *    ZigBee_Receive_Packet = 0x90,
    *    ZigBee_Explicit_Rx_Indicator = 0x91,
    *    ZigBee_IO_Data_Sample_Rx_Indicator = 0x92,
    *    XBee_Sensor_Read_Indicato = 0x94,
    *    Node_Identification_Indicator = 0x95,
    *    Remote_Command_Response = 0x97,
    *    Over_the_Air_Firmware_Update_Status = 0xA0,
    *    Route_Record_Indicator = 0xA1,
    *    Device_Authenticated_Indicator = 0xA2,
    *    Many_to_One_Route_Request_Indicator = 0xA3,
    */
    int getFrameType();

    void setFrameType(char identifier);

    void allocate(int length);

    void rewind();
    
    bool convert(APIFrame * frame);

    /** Write 8-bit data into current posiston and increase by 1.
    * @param value sigle byte
    */
    void set(char value);

    /** Write array of data into current posiston, and increase by the lenght.
    * @param value array of byte
    * @param offset start point of the data
    * @param length length to write
    */
    void sets(const char * value, int offset, int length);

    /** Write 8-bit data into specific posiston and deos not affect the current position.
    * @param position where to write
    * @param value sigle byte
    */
    void set(int position, char value);

    /** Write array of data into specific posiston and deos not affect the current position.
    * @param position where to write
    * @param value array of byte
    * @param offset start point of the data
    * @param length length to write
    */
    void sets(int position, const char * value, int offset, int length);

    /** Get checksum.
    * @returns the checksum value
    */
    char getCheckSum();

    /** Set checksum.
    * @param value checksum value
    */
    void setCheckSum(char value);

    /** Check is the API frame's checksum is verified.
    * @returns true checksum match,
    *          false checksum not match
    */
    bool verifyChecksum();

    /// Calculate the checksum value.
    void calculateChecksum();
};

#endif