xbee in api mode library

Fork of xbee_lib by Tristan Hughes

Committer:
noname77
Date:
Sun Jan 26 17:19:28 2014 +0000
Revision:
10:61e607fa8621
Parent:
9:08ccd085662f
some working code

Who changed what in which revision?

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