a

Dependents:   IOT_Sockets

Fork of xbee_api by Wiktor Grajkowski

xbeeFrame.h

Committer:
noname77
Date:
2014-01-25
Revision:
8:3ef2044c1302
Parent:
7:8e5855f18ad3
Child:
9:08ccd085662f

File content as of revision 8:3ef2044c1302:

class xbeeFrame : public xbee
{
private:
    PinName _tx;
    PinName _rx;
    PinName _reset;

    char _apiFrame[FRAME_SIZE];   //fully assembled frame
    unsigned char _length[2];               //length bytes
    unsigned char _frameType;              //frame type
    unsigned char _frameID;                //frame id
    unsigned char _destAddr[8];            //destination address
    unsigned char _sourceAddr[8];          //source address
    unsigned char _options;                 //other options
    char* _payload;                         //actual data to be sent/received
    unsigned char _checksum;                //checksum byte
    unsigned char _rssi;                    // RSSI
    char* _rfData;                          //pointer to an array to store incoming data
    unsigned char _status;                  //status of transmitted frame
    
public:
    /** Configure serial data pin.
      * @param tx The serial tx pin the xbee is conected to.
      * @param rx The serial rx pin the xbee is conected to.
      * @param reset The pin connected to the Xbee reset pin.
      */
    xbeeFrame(PinName tx, PinName rx, PinName reset);
    ~xbeeFrame();
    /** Initializes the frame
      */
    void InitFrame(void);
    /** Assembles the frame to be sent
      */  
    void AssembleFrame(void);
    /** Calculates the checksum of the frame
      * @return Returns the checksum of the frame
      */
    char CalculateChecksum(void);
    /** Calculates the length of the frame
      * @return Returns the length of the frame
      */
    int CalculateLength(void);
    /** Get the length of the frame
      * @return Returns the length of the packet
      */
    int GetLength(void);
    /** Set the packet destination address 
      * @param dest_address Pointer to a array storing destination address
      */
    void SetDestination(unsigned char* dest);
    /** Set the packet payload 
      * @param payload Pointer to a array storing payload (must be '\0' ended)
      */
    void SetPayload(char* payload);    
    /** Parses the received frame into proper data fields
      */
    void ParseFrame(void);
    /** Prints the received frame information
      */
    void PrintData(void);    
    /** Sends the frame
      */
    void SendFrame(void);    
    /** Receives the frame
      */
    void ReceiveFrame(char* buf);
    /** Returns pointer to api frame
      */
    char* GetFramePointer(void);
    /** Indicates if the frame has been received
      */
    unsigned char frameReceived;
    
    void PrintPayload();
};