xbee_lib from Tristan Hughes with some changes by zac dannelly

Dependents:   potSend potGet serialRangeGet

Fork of xbee_lib by Tristan Hughes

Committer:
tristanjph
Date:
Wed Aug 29 10:39:42 2012 +0000
Revision:
1:c3d9bdcb0b03
Parent:
0:2656fb225c5d
Child:
2:cb627ea9b817
Added receive data and documentation

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tristanjph 0:2656fb225c5d 1 #include "xbee.h"
tristanjph 0:2656fb225c5d 2
tristanjph 0:2656fb225c5d 3
tristanjph 0:2656fb225c5d 4 xbee::xbee(PinName tx, PinName rx)
tristanjph 0:2656fb225c5d 5 {
tristanjph 0:2656fb225c5d 6 _tx = tx;
tristanjph 0:2656fb225c5d 7 _rx = rx;
tristanjph 0:2656fb225c5d 8 }
tristanjph 0:2656fb225c5d 9
tristanjph 0:2656fb225c5d 10 xbee::~xbee()
tristanjph 0:2656fb225c5d 11 {
tristanjph 0:2656fb225c5d 12 }
tristanjph 0:2656fb225c5d 13
tristanjph 0:2656fb225c5d 14 int xbee::ConfigMode()
tristanjph 0:2656fb225c5d 15 {
tristanjph 0:2656fb225c5d 16 int a;
tristanjph 0:2656fb225c5d 17 Serial DATA(_tx,_rx);
tristanjph 0:2656fb225c5d 18 wait(2);
tristanjph 0:2656fb225c5d 19 DATA.printf("+++");
tristanjph 0:2656fb225c5d 20 while (a != 75) {
tristanjph 0:2656fb225c5d 21 if (DATA.readable()) {
tristanjph 0:2656fb225c5d 22 a = DATA.getc();
tristanjph 0:2656fb225c5d 23 }
tristanjph 0:2656fb225c5d 24 }
tristanjph 0:2656fb225c5d 25 wait(1);
tristanjph 0:2656fb225c5d 26 printf("config mode\n");
tristanjph 0:2656fb225c5d 27 return 1;
tristanjph 0:2656fb225c5d 28 }
tristanjph 0:2656fb225c5d 29
tristanjph 0:2656fb225c5d 30 int xbee::GetSerial()
tristanjph 0:2656fb225c5d 31 {
tristanjph 0:2656fb225c5d 32 int sh1,sh2,sh3,sl1,sl2,sl3,sl4;
tristanjph 0:2656fb225c5d 33 Serial DATA(_tx,_rx);
tristanjph 0:2656fb225c5d 34 wait_ms(50);
tristanjph 0:2656fb225c5d 35 DATA.printf("ATSL \r");
tristanjph 0:2656fb225c5d 36 DATA.scanf ("%2x%2x%2x%2x",&sl1,&sl2,&sl3,&sl4);
tristanjph 0:2656fb225c5d 37 wait_ms(500);
tristanjph 0:2656fb225c5d 38 DATA.printf("ATSH \r");
tristanjph 0:2656fb225c5d 39 DATA.scanf ("%2x%2x%2x",&sh1,&sh2,&sh3);
tristanjph 0:2656fb225c5d 40
tristanjph 0:2656fb225c5d 41 serial_no[0] = sh1;
tristanjph 0:2656fb225c5d 42 serial_no[1] = sh2;
tristanjph 0:2656fb225c5d 43 serial_no[2] = sh3;
tristanjph 0:2656fb225c5d 44 serial_no[3] = sl1;
tristanjph 0:2656fb225c5d 45 serial_no[4] = sl2;
tristanjph 0:2656fb225c5d 46 serial_no[5] = sl3;
tristanjph 0:2656fb225c5d 47 serial_no[6] = sl4;
tristanjph 0:2656fb225c5d 48
tristanjph 0:2656fb225c5d 49 return 1;
tristanjph 0:2656fb225c5d 50 }
tristanjph 0:2656fb225c5d 51
tristanjph 0:2656fb225c5d 52 int xbee::SetKey()
tristanjph 0:2656fb225c5d 53 {
tristanjph 0:2656fb225c5d 54 Serial DATA(_tx,_rx);
tristanjph 0:2656fb225c5d 55 DATA.printf("ATEE 1 \r");
tristanjph 0:2656fb225c5d 56
tristanjph 0:2656fb225c5d 57 DATA.scanf ("%*s");
tristanjph 0:2656fb225c5d 58 wait_ms(1);
tristanjph 0:2656fb225c5d 59 DATA.printf("ATKY %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x \r",
tristanjph 0:2656fb225c5d 60 security_key[0],security_key[1],security_key[2],security_key[3],
tristanjph 0:2656fb225c5d 61 security_key[4],security_key[5],security_key[6],security_key[7],
tristanjph 0:2656fb225c5d 62 security_key[8],security_key[9],security_key[10],security_key[11],
tristanjph 0:2656fb225c5d 63 security_key[12],security_key[13],security_key[14],security_key[15]);
tristanjph 0:2656fb225c5d 64 DATA.scanf ("%*s");
tristanjph 0:2656fb225c5d 65 return 1;
tristanjph 0:2656fb225c5d 66 }
tristanjph 0:2656fb225c5d 67
tristanjph 0:2656fb225c5d 68 int xbee::WriteSettings()
tristanjph 0:2656fb225c5d 69 {
tristanjph 0:2656fb225c5d 70 Serial DATA(_tx,_rx);
tristanjph 0:2656fb225c5d 71 wait_ms(5);
tristanjph 0:2656fb225c5d 72 DATA.printf("ATWR \r");
tristanjph 0:2656fb225c5d 73 DATA.scanf ("%*s");
tristanjph 0:2656fb225c5d 74 return 1;
tristanjph 0:2656fb225c5d 75 }
tristanjph 0:2656fb225c5d 76
tristanjph 0:2656fb225c5d 77 int xbee::ExitConfigMode()
tristanjph 0:2656fb225c5d 78 {
tristanjph 0:2656fb225c5d 79 Serial DATA(_tx,_rx);
tristanjph 0:2656fb225c5d 80 wait_ms(5);
tristanjph 0:2656fb225c5d 81 DATA.printf("ATCN \r");
tristanjph 0:2656fb225c5d 82 DATA.scanf ("%*s");
tristanjph 0:2656fb225c5d 83 return 1;
tristanjph 0:2656fb225c5d 84 }
tristanjph 0:2656fb225c5d 85
tristanjph 0:2656fb225c5d 86 int xbee::SendData()
tristanjph 0:2656fb225c5d 87 {
tristanjph 0:2656fb225c5d 88 Serial DATA(_tx,_rx);
tristanjph 0:2656fb225c5d 89 DATA.printf("%s",sendData);
tristanjph 0:2656fb225c5d 90 return 1;
tristanjph 0:2656fb225c5d 91 }
tristanjph 0:2656fb225c5d 92
tristanjph 1:c3d9bdcb0b03 93 void xbee::RecieveData(int numchar)
tristanjph 1:c3d9bdcb0b03 94 {
tristanjph 1:c3d9bdcb0b03 95 int count=0;
tristanjph 1:c3d9bdcb0b03 96 Serial DATA(_tx,_rx);
tristanjph 1:c3d9bdcb0b03 97 while(numchar!=count) {
tristanjph 1:c3d9bdcb0b03 98 if(DATA.readable()) {
tristanjph 1:c3d9bdcb0b03 99 readData[count] = DATA.getc();
tristanjph 1:c3d9bdcb0b03 100 count++;
tristanjph 1:c3d9bdcb0b03 101 }
tristanjph 1:c3d9bdcb0b03 102
tristanjph 1:c3d9bdcb0b03 103 }
tristanjph 1:c3d9bdcb0b03 104