Raspberry-mbedsoftware

Dependencies:   C12832 mbed

Fork of XBee_read by Alex Louden

Files at this revision

API Documentation at this revision

Comitter:
Perijah
Date:
Thu Mar 24 14:53:25 2016 +0000
Parent:
0:2eaf86314aea
Commit message:
mbed connected to raspberry will be equiped with this software.

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Thu Mar 24 14:53:25 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
--- a/main.cpp	Fri Jun 04 10:23:38 2010 +0000
+++ b/main.cpp	Thu Mar 24 14:53:25 2016 +0000
@@ -1,43 +1,70 @@
 #include "mbed.h"
-#include "TextLCD.h"
+#include "C12832.h"
 
 Serial xbee1(p9, p10);
-DigitalOut rst1(p11);
+DigitalOut rst1(p30);
+int dataRecieved[10];           //array to store the data that's recieved. Max amount is 10.
 
-DigitalOut myled(LED1);
-DigitalOut myled2(LED2);
+Serial pc(USBTX, USBRX); // tx, rx
+
+
 
-TextLCD lcd(p16, p15, p14, p17, p18, p19, p20); // rs, rw, e, d0, d1, d2, d3
+void lezen()                    //read the data 
+{
+    int flag = 0;
+    int adress = 0;
+    int size = 0;
+    int checkSum = 0;
+    int checkCompare = 0;       //checksum must be equal to checkCompare
+    wait_ms(100);
+    flag = xbee1.getc();        //get flag. If flag is correct the transmission can continue. If not, this methode ends and will be called again in the main method. 
+    if(flag == 0x7E) {
+        adress = xbee1.getc();  //get the adress. 
+        checkCompare =(checkCompare+ adress);   //build checkCompare
+        size = xbee1.getc();    //size of the data that is to be recieved. This will help filling the array dataRecieved. 
+        for(int n=0 ; n<size ; n++) {
+            dataRecieved[n] = xbee1.getc();
+            checkCompare +=dataRecieved[n];
+        }
+        checkCompare = checkCompare % 256;
+        checkSum = xbee1.getc();    
+        
+     if(checkSum==checkCompare) {//if everything is correct it will print on to the pc. 
+        pc.printf("%x,%x,%x,%x \n\r",adress,size,dataRecieved[0],checkSum);
+    }
 
-int main() {
+    } else {    //if the flag is incorrect, the method ends.
+
+    }
+
+
+}
+
+
+
+
+
+
+
+int main()
+{
+
+    xbee1.baud(57600);
+
     rst1 = 0;   //Set reset pin to 0
-    myled = 0;
-    myled2= 0;
+
     wait_ms(1);
     rst1 = 1;   //Set reset pin to 1
     wait_ms(1);
 
-    lcd.printf("starting");
-    wait(2);
-    lcd.cls();
+
+
 
-    int a = 0;
-    int prev = 0;
+    xbee1.attach(lezen);    //interrupt triggerd 
+
 
     while (1) {
 
-        if(xbee1.readable()){
-            prev = a;
-            a = xbee1.getc(); //XBee read
-            
-            if (a != prev){
-                if (a < 10){
-                    lcd.printf("%d", a);
-                }
-                if (a == 254 || a == 253){
-                    lcd.cls();
-                }
-            }
-        }
+
     }
 }