A library allowing basic functions of the XBEE pro to be used. Currently supported are: Enter/exit config mode, reading device serial number, setting encryption key, writing settings to non volatile memory and sending data strings.
Dependents: Seeed_XBee_Shield Seeed_XBee_Shield-2
Fork of xbee_lib by
Revision 2:cb627ea9b817, committed 2012-08-29
- Comitter:
- tristanjph
- Date:
- Wed Aug 29 13:27:02 2012 +0000
- Parent:
- 1:c3d9bdcb0b03
- Child:
- 3:682615a0717e
- Commit message:
- Update send/receive added setting network pan id
Changed in this revision
xbee.cpp | Show annotated file Show diff for this revision Revisions of this file |
xbee.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/xbee.cpp Wed Aug 29 10:39:42 2012 +0000 +++ b/xbee.cpp Wed Aug 29 13:27:02 2012 +0000 @@ -27,7 +27,7 @@ return 1; } -int xbee::GetSerial() +int xbee::GetSerial(int *serial_no) { int sh1,sh2,sh3,sl1,sl2,sl3,sl4; Serial DATA(_tx,_rx); @@ -49,18 +49,14 @@ return 1; } -int xbee::SetKey() +int xbee::SetKey(char* key) { Serial DATA(_tx,_rx); DATA.printf("ATEE 1 \r"); DATA.scanf ("%*s"); wait_ms(1); - DATA.printf("ATKY %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x \r", - security_key[0],security_key[1],security_key[2],security_key[3], - security_key[4],security_key[5],security_key[6],security_key[7], - security_key[8],security_key[9],security_key[10],security_key[11], - security_key[12],security_key[13],security_key[14],security_key[15]); + DATA.printf("ATKY %s \r",key); DATA.scanf ("%*s"); return 1; } @@ -83,22 +79,34 @@ return 1; } -int xbee::SendData() +int xbee::SendData(char *data_buf) { Serial DATA(_tx,_rx); - DATA.printf("%s",sendData); + DATA.printf("%s",data_buf); return 1; } -void xbee::RecieveData(int numchar) +void xbee::RecieveData(char *data_buf, int numchar) { int count=0; + if(numchar == 0) { + numchar = sizeof(data_buf); + } Serial DATA(_tx,_rx); while(numchar!=count) { if(DATA.readable()) { - readData[count] = DATA.getc(); - count++; + *data_buf = DATA.getc(); + data_buf+=1; count++; } } +} +int xbee::SetPanId(int pan_id) +{ + Serial DATA(_tx,_rx); + wait_ms(5); + DATA.printf("ATID %i\r",pan_id); + DATA.scanf ("%*s"); + return 1; +}
--- a/xbee.h Wed Aug 29 10:39:42 2012 +0000 +++ b/xbee.h Wed Aug 29 13:27:02 2012 +0000 @@ -1,48 +1,55 @@ #include "mbed.h" /** Xbee interface class for configuring, sending and recieving data using an Xbee */ -class xbee { +class xbee +{ private: PinName _tx; PinName _rx; 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 + /** 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. */ xbee(PinName tx, PinName rx); ~xbee(); - /** Puts the Xbee into config mode - * @return Returns 1 on success + /** Puts the Xbee into config mode. + * @return Returns 1 on success. */ int ConfigMode(); - /** Gets the serial number of the Xbee - * @return Returns 1 on success + /** Gets the serial number/mac address of the Xbee and places it into serial_no. + * @param serial_no array to store the serial of Xbee (must be 8 long). + * @return Returns 1 on success. + */ + int GetSerial(int*); + /** Sets the encryption key to the one stored in security_key. + * @param key Pointer to the network key to set. + * @return Returns 1 on success. */ - int GetSerial(); - /** Sets the encryption key for the Xbee - * @return Returns 1 on success + int SetKey(char*); + /** Sets the id of the PAN network for the Xbee to use + * @param pan_id The id of the PAN for the Xbee to use. + * @return Returns 1 on success. */ - int SetKey(); - /** Writes the settings to the Non volatile memory on the Xbee - * @return Returns 1 on success + int SetPanId(int); + /** Writes the settings to the Non volatile memory on the Xbee + * @param key Pointer to the network key to set. + * @return Returns 1 on success. */ int WriteSettings(); /** Exits config mode - * @return Returns 1 on success + * @return Returns 1 on success. */ int ExitConfigMode(); - /** Sends data in the sendData buffer - * @return Returns 1 on success - */ - int SendData(); - /** Recieves data and puts it into the recieveData buffer. Will over write anything already in the buffer - * @param numchar Number of characters to read + /** Sends data in the send_Data buffer. + * @param data_buf Pointer to the buffer of data to send. + * @returns 1 on success. */ - void RecieveData(int numchar); - - int serial_no[8]; - int security_key[16]; - char sendData[202]; - char readData[202]; + int SendData(char*); + /** Recieves data sent to the xbee. + * @param data_buf Pointer to the buffer to put recieved data into. + * @param numchar Number of characters to read. If 0, will use the size of data_buf. + */ + void RecieveData(char*, int); + }; \ No newline at end of file