A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE
Fork of xbee_lib by
Diff: xbee.cpp
- Revision:
- 2:cb627ea9b817
- Parent:
- 1:c3d9bdcb0b03
- Child:
- 3:682615a0717e
diff -r c3d9bdcb0b03 -r cb627ea9b817 xbee.cpp --- 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; +}