4180 mbed xbee final

Dependents:   4180_Zigbee

Files at this revision

API Documentation at this revision

Comitter:
Samer
Date:
Tue Apr 21 19:21:39 2015 +0000
Commit message:
Working send and recieve; need atof

Changed in this revision

Zigbee_control.cpp Show annotated file Show diff for this revision Revisions of this file
Zigbee_control.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 0b5c5f57157c Zigbee_control.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Zigbee_control.cpp	Tue Apr 21 19:21:39 2015 +0000
@@ -0,0 +1,69 @@
+#include "Zigbee_control.h"
+
+DigitalOut led(LED1);
+Serial xbee1(p13, p14);
+DigitalOut rst1(p11);
+DigitalOut test(p9);
+Serial pc(USBTX, USBRX);
+
+void Zigbee_setup(void)
+{
+  xbee1.attach(&callback);  
+}
+void send_Zigbee_string(char c[])
+{
+    led =0;
+    int i=0;
+    while(c[i]!='\0'){
+        xbee1.putc(c[i]);
+      pc.putc(c[i]);
+        i++;
+        led =1;
+        }
+        xbee1.putc('\n');
+        led =0;
+        
+}
+
+char recieve_Zigbee_char(void)
+{
+    return xbee1.getc();
+}
+
+void send_Zigbee_char(char x)
+{
+    if(x=='\r')
+        x = '\n';
+    xbee1.putc(x);
+    
+}
+
+bool Zigbee_status(void)
+{
+    return xbee1.readable();
+}
+
+void callback()
+{
+    test =1;
+    led =1;
+    char c = xbee1.getc();
+    test =0;   
+    led =0;
+}
+char *read_Zigbee_string(void)
+{
+    static char retstr[256]; 
+    int i=0; 
+    retstr[i] = recieve_Zigbee_char();
+    while(retstr[i] != '\\'){
+        if(Zigbee_status()){
+        i++;
+     // z = read_Zigbee_string();
+        retstr[i]= recieve_Zigbee_char();
+        }
+     }
+     retstr[i++]='\0';
+
+     return retstr;
+}
\ No newline at end of file
diff -r 000000000000 -r 0b5c5f57157c Zigbee_control.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Zigbee_control.h	Tue Apr 21 19:21:39 2015 +0000
@@ -0,0 +1,10 @@
+#include "mbed.h"
+
+void flashled(void);
+void send_Zigbee_string(char c[]);
+char recieve_Zigbee_char(void);
+void send_Zigbee_char(char x);
+bool Zigbee_status(void);
+void Zigbee_setup(void);
+void callback(void);
+char *read_Zigbee_string(void);
\ No newline at end of file