tes

Dependencies:   ASyncTicker EthernetInterface WebSocketClient mbed-rtos mbed MbedJSONValue xbee_lib

Files at this revision

API Documentation at this revision

Comitter:
ammanvedi
Date:
Sat Feb 01 17:30:02 2014 +0000
Parent:
4:84abfe990493
Child:
6:c1bd3fadce09
Commit message:
COMMIT PRIOR TO REMOVAL OF DEPRECIATED CODE

Changed in this revision

btNode.cpp Show annotated file Show diff for this revision Revisions of this file
btNode.h 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
xbee_lib.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/btNode.cpp	Sat Feb 01 17:30:02 2014 +0000
@@ -0,0 +1,90 @@
+#include "btNode.h"
+#include "mbed.h"
+#include "xbee.h"
+#include "xbeeFrame.h"
+
+const char btNode::ADDRESS[8] = {0x00, 0x13, 0xA2, 0x00, 0x40, 0x9B, 0x6D, 0xB0};
+ 
+btNode::btNode(int D_ID){
+    ID = D_ID;
+
+}
+ 
+std::string btNode::SendMessage(std::string msg) {
+    
+    xbeeFrame xbee(p9,
+               p10,
+               p11);
+    
+    std::string full_msg = "";
+    
+    char send_data[50]   = "xbee string";
+    
+        char   to_send[100];
+        char * p = to_send;
+        char * r = send_data;
+
+        while (*r)
+        {
+            *p++ = *r++;
+        }
+
+        *p++ = ' ';
+        r    = (char *)msg.c_str();
+
+        while (*r)
+        {
+            *p++ = *r++;
+        }
+
+        *p++ = '\r';
+        *p   = '\0';
+        
+        printf("the data to send from class  is %s\n\r\n\r", to_send);
+        
+        char data_buf[50];
+
+        xbee.InitFrame();
+        xbee.SetDestination((unsigned char *) ADDRESS);
+        xbee.SetPayload(to_send);
+        printf("sending payload: %s\n\r\n\r", to_send);
+        xbee.AssembleFrame();
+        xbee.SendFrame();
+        
+        
+        
+        for (int i = 0; i < 2; i++)
+        {
+            xbee.ReceiveFrame(data_buf, 500);
+
+            if (xbee.frameReceived)
+            {
+                xbee.frameReceived = 0;
+
+                if (xbee.GetType() == TX_STATUS)
+                {
+                    if (xbee.GetStatus() == 0)
+                    {
+                        printf("Send success!\n\r");
+                    }
+                    else
+                    {
+                        //printf("Send failed :(\n\r");
+                        return "sending failed....";
+                    }
+                }
+                else if (xbee.GetType() == RX_PACKET_64)
+                {
+                    printf("Received data: %s\n\r", data_buf);
+                }
+            }
+        }
+    
+        
+        
+        std::string response(data_buf);
+        
+        
+        return response ;
+
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/btNode.h	Sat Feb 01 17:30:02 2014 +0000
@@ -0,0 +1,19 @@
+#ifndef BT_DEVICE
+#define BT_DEVICE
+
+#include <string>
+#include "xbee.h"
+#include "xbeeFrame.h"
+ 
+class btNode {
+public:
+    btNode(int D_ID);
+    std::string SendMessage(std::string msg);
+  
+private:  
+    int ID;
+    static const char ADDRESS[8];
+    //const char dest_address[8] ={0x00, 0x13, 0xA2, 0x00, 0x40, 0x9B, 0x6D, 0xB0};
+};
+ 
+#endif
\ No newline at end of file
--- a/main.cpp	Sat Feb 01 01:37:50 2014 +0000
+++ b/main.cpp	Sat Feb 01 17:30:02 2014 +0000
@@ -1,17 +1,13 @@
-
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include <stdio.h>
-#include <string.h>
 #include "Websocket.h"
-#include "Updateable.h"
-#include "ASyncTicker.h"
 #include "xbee.h"
 #include "xbeeFrame.h"
 #include "MbedJSONValue.h"
 #include <ctype.h>
 #include <string>
-
+#include "btNode.h"
 #define PORT 80
 
 // status leds
@@ -26,20 +22,31 @@
 EthernetInterface ethernet;
 Websocket         ws("ws://192.168.0.4:8080/");
 
+
+btNode b(30);
+
+/* v1 depreciated
+
 xbeeFrame xbee(p9,
                p10,
                p11);
 
-const char dest_address[8] =
+
+
+char dest_address[8] =
 {
     0x00, 0x13, 0xA2, 0x00, 0x40, 0x9B, 0x6D, 0xB0
 };
 char       send_data[50]   = "xbee string";
 
+*/
+
 void pull_requests()
 {
 }
 
+
+
 void pull_updates()
 {
     // build json request string
@@ -98,7 +105,15 @@
             // data was revieved
             printf("id :  %s  string: %s (original: %s) \n\r", id, new_msg, str);
         }
-
+        
+        std::string real_msg(new_msg);
+        
+        std::string result = b.SendMessage(real_msg);
+        
+        printf("xbee response : %s\n\r\n\r", result);
+        
+        
+/* V1 DEPRECIATED
         char   to_send[100];
         char * p = to_send;
         char * r = send_data;
@@ -153,11 +168,17 @@
                 }
             }
         }
-    }
+    } 
+    */
+}
 }
 
 int main()
 {
+    
+    
+    
+    
     led_ethernet = 0;
     led_socket   = 0;
 
--- a/xbee_lib.lib	Sat Feb 01 01:37:50 2014 +0000
+++ b/xbee_lib.lib	Sat Feb 01 17:30:02 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/noname77/code/xbee_api/#61e607fa8621
+http://mbed.org/users/noname77/code/xbee_api/#c8737cf52430