mini code pour xbee

Dependencies:   mbed ConfigFile EthernetInterface WebSocketClient mbed-rtos

Fork of app4Coordo by APP Team

Files at this revision

API Documentation at this revision

Comitter:
passelin
Date:
Mon Feb 24 23:25:17 2014 +0000
Parent:
3:85025db3fbd1
Child:
5:bf1d3d99cfe9
Commit message:
update

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
WebSocketClient.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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Mon Feb 24 23:25:17 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/EthernetInterface/#6a67d2bddc7c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WebSocketClient.lib	Mon Feb 24 23:25:17 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/samux/code/WebSocketClient/#4567996414a5
--- a/main.cpp	Mon Feb 24 18:57:38 2014 +0000
+++ b/main.cpp	Mon Feb 24 23:25:17 2014 +0000
@@ -1,21 +1,36 @@
 #include "mbed.h"
 #include <string>
 #include "ConfigFile.h"
+#include "EthernetInterface.h"
+#include "Websocket.h"
 
+// Pins
 DigitalOut myled(LED1);
 DigitalOut myled2(LED2);
 DigitalOut reset(p8);
+
+// Serial COMs
 Serial pc(USBTX, USBRX);
 Serial xbee(p13, p14);
 
+// Variables
 string test;
 bool trame_ready;
 
+// Ethernet interface
+EthernetInterface eth;
+
+// view @ http://sockets.mbed.org/demo/viewer
+Websocket ws("ws://89.16.167.192:443/ws/trixrabbit/wo");
+
+// Configuration file
 LocalFileSystem local("local");
 ConfigFile cfg;
 
+// State machine ENUM
 enum {STEP_START, STEP_LENGTH, STEP_TYPE, STEP_MAC, STEP_NET, STEP_OPT, STEP_DATA, STEP_CHECK};
 
+
 void configInit()
 {
     char *key1 = "PANID";
@@ -33,15 +48,37 @@
      */
     if (cfg.getValue(key1, &value[0], sizeof(value))) 
     {
-        printf("'%s'='%s'\n", key1, value);
+        pc.printf("'%s'='%s'\n", key1, value);
     }
     
     if (cfg.getValue(key2, &value[0], sizeof(value))) 
     {
-        printf("'%s'='%s'\n", key2, value);
+        pc.printf("'%s'='%s'\n", key2, value);
     }
 }
 
+void eth_init()
+{
+    eth.init();
+    eth.connect();
+    
+    pc.printf("IP Address is %s\n", eth.getIPAddress());
+    
+    wait(2);
+
+    if(!ws.connect())
+    {
+         error("Failure establish connection to the WebSocket.\n");
+    }
+     
+    /*while(1) {
+            ws.send("CAFE CAFE CFAE");
+            wait(1.0);
+    }*/
+
+    
+}
+
 void xbee_init()
 {
     reset = 0;
@@ -51,7 +88,6 @@
 
 void xbee_receive()
 {
-    // TODO: analyze trame before sending to PC (or WebSocket)
     static int state = STEP_START;
     
     char data = xbee.getc();
@@ -134,9 +170,7 @@
                             
         case STEP_CHECK:    //check CS
                             state = STEP_START;
-                            break;
-                               
-                               
+                            break;                            
     }
   
 }
@@ -145,6 +179,7 @@
 {
     
     configInit();
+    eth_init();
     xbee_init();
 
     
@@ -158,9 +193,6 @@
         if(xbee.readable())
         {
             xbee_receive();
-            
-            //pc.printf("%x ", xbee.getc());
-            //pc.putc(xbee.getc()); 
             myled2 = ! myled2;
         }
         
@@ -172,8 +204,19 @@
         
         if(trame_ready == true)
         {
+            //test = "TESTESTESTESTEST";
             pc.printf(test.c_str());
+            
+            char *buffer =new char[test.size()+1];
+            buffer[test.size()]=0;
+            memcpy(buffer,test.c_str(),test.size());
+            
+            ws.send(buffer);
+            
             trame_ready = false;
         }
     }
+    
+    //ws.close();
+   // eth.disconnect();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Mon Feb 24 23:25:17 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#f88660a9bed1