4180 mbed xbee final

Dependents:   4180_Zigbee

Committer:
Samer
Date:
Tue Apr 21 19:21:39 2015 +0000
Revision:
0:0b5c5f57157c
Working send and recieve; need atof

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Samer 0:0b5c5f57157c 1 #include "Zigbee_control.h"
Samer 0:0b5c5f57157c 2
Samer 0:0b5c5f57157c 3 DigitalOut led(LED1);
Samer 0:0b5c5f57157c 4 Serial xbee1(p13, p14);
Samer 0:0b5c5f57157c 5 DigitalOut rst1(p11);
Samer 0:0b5c5f57157c 6 DigitalOut test(p9);
Samer 0:0b5c5f57157c 7 Serial pc(USBTX, USBRX);
Samer 0:0b5c5f57157c 8
Samer 0:0b5c5f57157c 9 void Zigbee_setup(void)
Samer 0:0b5c5f57157c 10 {
Samer 0:0b5c5f57157c 11 xbee1.attach(&callback);
Samer 0:0b5c5f57157c 12 }
Samer 0:0b5c5f57157c 13 void send_Zigbee_string(char c[])
Samer 0:0b5c5f57157c 14 {
Samer 0:0b5c5f57157c 15 led =0;
Samer 0:0b5c5f57157c 16 int i=0;
Samer 0:0b5c5f57157c 17 while(c[i]!='\0'){
Samer 0:0b5c5f57157c 18 xbee1.putc(c[i]);
Samer 0:0b5c5f57157c 19 pc.putc(c[i]);
Samer 0:0b5c5f57157c 20 i++;
Samer 0:0b5c5f57157c 21 led =1;
Samer 0:0b5c5f57157c 22 }
Samer 0:0b5c5f57157c 23 xbee1.putc('\n');
Samer 0:0b5c5f57157c 24 led =0;
Samer 0:0b5c5f57157c 25
Samer 0:0b5c5f57157c 26 }
Samer 0:0b5c5f57157c 27
Samer 0:0b5c5f57157c 28 char recieve_Zigbee_char(void)
Samer 0:0b5c5f57157c 29 {
Samer 0:0b5c5f57157c 30 return xbee1.getc();
Samer 0:0b5c5f57157c 31 }
Samer 0:0b5c5f57157c 32
Samer 0:0b5c5f57157c 33 void send_Zigbee_char(char x)
Samer 0:0b5c5f57157c 34 {
Samer 0:0b5c5f57157c 35 if(x=='\r')
Samer 0:0b5c5f57157c 36 x = '\n';
Samer 0:0b5c5f57157c 37 xbee1.putc(x);
Samer 0:0b5c5f57157c 38
Samer 0:0b5c5f57157c 39 }
Samer 0:0b5c5f57157c 40
Samer 0:0b5c5f57157c 41 bool Zigbee_status(void)
Samer 0:0b5c5f57157c 42 {
Samer 0:0b5c5f57157c 43 return xbee1.readable();
Samer 0:0b5c5f57157c 44 }
Samer 0:0b5c5f57157c 45
Samer 0:0b5c5f57157c 46 void callback()
Samer 0:0b5c5f57157c 47 {
Samer 0:0b5c5f57157c 48 test =1;
Samer 0:0b5c5f57157c 49 led =1;
Samer 0:0b5c5f57157c 50 char c = xbee1.getc();
Samer 0:0b5c5f57157c 51 test =0;
Samer 0:0b5c5f57157c 52 led =0;
Samer 0:0b5c5f57157c 53 }
Samer 0:0b5c5f57157c 54 char *read_Zigbee_string(void)
Samer 0:0b5c5f57157c 55 {
Samer 0:0b5c5f57157c 56 static char retstr[256];
Samer 0:0b5c5f57157c 57 int i=0;
Samer 0:0b5c5f57157c 58 retstr[i] = recieve_Zigbee_char();
Samer 0:0b5c5f57157c 59 while(retstr[i] != '\\'){
Samer 0:0b5c5f57157c 60 if(Zigbee_status()){
Samer 0:0b5c5f57157c 61 i++;
Samer 0:0b5c5f57157c 62 // z = read_Zigbee_string();
Samer 0:0b5c5f57157c 63 retstr[i]= recieve_Zigbee_char();
Samer 0:0b5c5f57157c 64 }
Samer 0:0b5c5f57157c 65 }
Samer 0:0b5c5f57157c 66 retstr[i++]='\0';
Samer 0:0b5c5f57157c 67
Samer 0:0b5c5f57157c 68 return retstr;
Samer 0:0b5c5f57157c 69 }