a
Fork of xbee_api by
xbeeFrame.h@11:c8737cf52430, 2014-02-01 (annotated)
- Committer:
- ammanvedi
- Date:
- Sat Feb 01 17:29:36 2014 +0000
- Revision:
- 11:c8737cf52430
- Parent:
- 10:61e607fa8621
added ifdef declarations
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ammanvedi | 11:c8737cf52430 | 1 | #ifndef FRAME_DEVICE |
ammanvedi | 11:c8737cf52430 | 2 | #define FRAME_DEVICE |
ammanvedi | 11:c8737cf52430 | 3 | |
noname77 | 10:61e607fa8621 | 4 | #define FRAME_SIZE 127 |
noname77 | 10:61e607fa8621 | 5 | #define STARTBYTE 0x7E |
noname77 | 10:61e607fa8621 | 6 | #define MAX_DATA_LEN 70 |
noname77 | 10:61e607fa8621 | 7 | |
noname77 | 10:61e607fa8621 | 8 | #define TX_STATUS 0x89 |
noname77 | 10:61e607fa8621 | 9 | #define TX_REQUEST_64 0x00 |
noname77 | 10:61e607fa8621 | 10 | #define RX_PACKET_64 0x80 |
noname77 | 10:61e607fa8621 | 11 | |
noname77 | 7:8e5855f18ad3 | 12 | class xbeeFrame : public xbee |
noname77 | 7:8e5855f18ad3 | 13 | { |
noname77 | 7:8e5855f18ad3 | 14 | private: |
noname77 | 7:8e5855f18ad3 | 15 | PinName _tx; |
noname77 | 7:8e5855f18ad3 | 16 | PinName _rx; |
noname77 | 7:8e5855f18ad3 | 17 | PinName _reset; |
noname77 | 7:8e5855f18ad3 | 18 | |
noname77 | 8:3ef2044c1302 | 19 | char _apiFrame[FRAME_SIZE]; //fully assembled frame |
noname77 | 7:8e5855f18ad3 | 20 | unsigned char _length[2]; //length bytes |
noname77 | 7:8e5855f18ad3 | 21 | unsigned char _frameType; //frame type |
noname77 | 7:8e5855f18ad3 | 22 | unsigned char _frameID; //frame id |
noname77 | 7:8e5855f18ad3 | 23 | unsigned char _destAddr[8]; //destination address |
noname77 | 7:8e5855f18ad3 | 24 | unsigned char _sourceAddr[8]; //source address |
noname77 | 7:8e5855f18ad3 | 25 | unsigned char _options; //other options |
noname77 | 8:3ef2044c1302 | 26 | char* _payload; //actual data to be sent/received |
noname77 | 7:8e5855f18ad3 | 27 | unsigned char _checksum; //checksum byte |
noname77 | 7:8e5855f18ad3 | 28 | unsigned char _rssi; // RSSI |
noname77 | 8:3ef2044c1302 | 29 | char* _rfData; //pointer to an array to store incoming data |
noname77 | 7:8e5855f18ad3 | 30 | unsigned char _status; //status of transmitted frame |
noname77 | 7:8e5855f18ad3 | 31 | |
noname77 | 7:8e5855f18ad3 | 32 | public: |
noname77 | 7:8e5855f18ad3 | 33 | /** Configure serial data pin. |
noname77 | 7:8e5855f18ad3 | 34 | * @param tx The serial tx pin the xbee is conected to. |
noname77 | 7:8e5855f18ad3 | 35 | * @param rx The serial rx pin the xbee is conected to. |
noname77 | 7:8e5855f18ad3 | 36 | * @param reset The pin connected to the Xbee reset pin. |
noname77 | 7:8e5855f18ad3 | 37 | */ |
noname77 | 7:8e5855f18ad3 | 38 | xbeeFrame(PinName tx, PinName rx, PinName reset); |
noname77 | 7:8e5855f18ad3 | 39 | ~xbeeFrame(); |
noname77 | 7:8e5855f18ad3 | 40 | /** Initializes the frame |
noname77 | 7:8e5855f18ad3 | 41 | */ |
noname77 | 7:8e5855f18ad3 | 42 | void InitFrame(void); |
noname77 | 7:8e5855f18ad3 | 43 | /** Assembles the frame to be sent |
noname77 | 7:8e5855f18ad3 | 44 | */ |
noname77 | 7:8e5855f18ad3 | 45 | void AssembleFrame(void); |
noname77 | 7:8e5855f18ad3 | 46 | /** Calculates the checksum of the frame |
noname77 | 7:8e5855f18ad3 | 47 | * @return Returns the checksum of the frame |
noname77 | 7:8e5855f18ad3 | 48 | */ |
noname77 | 7:8e5855f18ad3 | 49 | char CalculateChecksum(void); |
noname77 | 7:8e5855f18ad3 | 50 | /** Calculates the length of the frame |
noname77 | 7:8e5855f18ad3 | 51 | * @return Returns the length of the frame |
noname77 | 7:8e5855f18ad3 | 52 | */ |
noname77 | 7:8e5855f18ad3 | 53 | int CalculateLength(void); |
noname77 | 7:8e5855f18ad3 | 54 | /** Get the length of the frame |
noname77 | 7:8e5855f18ad3 | 55 | * @return Returns the length of the packet |
noname77 | 7:8e5855f18ad3 | 56 | */ |
noname77 | 7:8e5855f18ad3 | 57 | int GetLength(void); |
noname77 | 10:61e607fa8621 | 58 | /** Get the type of the frame |
noname77 | 10:61e607fa8621 | 59 | * @return Returns the type of the packet |
noname77 | 10:61e607fa8621 | 60 | */ |
noname77 | 10:61e607fa8621 | 61 | int GetType(void); |
noname77 | 10:61e607fa8621 | 62 | /** Get the status of the sent frame |
noname77 | 10:61e607fa8621 | 63 | * @return Returns the status of sent packet |
noname77 | 10:61e607fa8621 | 64 | */ |
noname77 | 10:61e607fa8621 | 65 | int GetStatus(void); |
noname77 | 7:8e5855f18ad3 | 66 | /** Set the packet destination address |
noname77 | 7:8e5855f18ad3 | 67 | * @param dest_address Pointer to a array storing destination address |
noname77 | 7:8e5855f18ad3 | 68 | */ |
noname77 | 8:3ef2044c1302 | 69 | void SetDestination(unsigned char* dest); |
noname77 | 7:8e5855f18ad3 | 70 | /** Set the packet payload |
noname77 | 7:8e5855f18ad3 | 71 | * @param payload Pointer to a array storing payload (must be '\0' ended) |
noname77 | 7:8e5855f18ad3 | 72 | */ |
noname77 | 7:8e5855f18ad3 | 73 | void SetPayload(char* payload); |
noname77 | 7:8e5855f18ad3 | 74 | /** Parses the received frame into proper data fields |
noname77 | 7:8e5855f18ad3 | 75 | */ |
noname77 | 7:8e5855f18ad3 | 76 | void ParseFrame(void); |
noname77 | 7:8e5855f18ad3 | 77 | /** Prints the received frame information |
noname77 | 7:8e5855f18ad3 | 78 | */ |
noname77 | 8:3ef2044c1302 | 79 | void PrintData(void); |
noname77 | 8:3ef2044c1302 | 80 | /** Sends the frame |
noname77 | 8:3ef2044c1302 | 81 | */ |
noname77 | 8:3ef2044c1302 | 82 | void SendFrame(void); |
noname77 | 7:8e5855f18ad3 | 83 | /** Receives the frame |
noname77 | 7:8e5855f18ad3 | 84 | */ |
noname77 | 9:08ccd085662f | 85 | void ReceiveFrame(char* buf, int timeout); |
noname77 | 8:3ef2044c1302 | 86 | /** Returns pointer to api frame |
noname77 | 8:3ef2044c1302 | 87 | */ |
noname77 | 8:3ef2044c1302 | 88 | char* GetFramePointer(void); |
noname77 | 7:8e5855f18ad3 | 89 | /** Indicates if the frame has been received |
noname77 | 7:8e5855f18ad3 | 90 | */ |
noname77 | 7:8e5855f18ad3 | 91 | unsigned char frameReceived; |
noname77 | 8:3ef2044c1302 | 92 | |
noname77 | 8:3ef2044c1302 | 93 | void PrintPayload(); |
ammanvedi | 11:c8737cf52430 | 94 | }; |
ammanvedi | 11:c8737cf52430 | 95 | |
ammanvedi | 11:c8737cf52430 | 96 | #endif |