master to control sensor node

Dependencies:   mbed

Revision:
3:646a628b8656
Parent:
2:5d88c51f53dc
Child:
4:5518470323de
--- a/gateway.cpp	Tue Nov 10 21:13:21 2015 +0000
+++ b/gateway.cpp	Tue Nov 10 23:37:54 2015 +0000
@@ -3,6 +3,9 @@
 #include <string>
 #include "packet.h"
 
+#define NODE 1
+
+//unsigned short TYPE = 4;
 
 // RF tranceiver to link with handheld.
 MRF24J40 mrf(p11, p12, p13, p14, p21);
@@ -17,6 +20,9 @@
 char rxBuffer[128];
 int rxLen;
 
+packet* sxBuffer;
+packet* gxBuffer;
+
 //***************** Do not change these methods (please) *****************//
 
 /**
@@ -54,27 +60,32 @@
 * @param maxLength The length of the data to send.
 *                  If you are sending a null-terminated string you can pass strlen(data)+1
 */
-void rf_send(char *data, uint8_t len)
+void rf_send(packet *data, uint8_t len)
 {
     //We need to prepend the message with a valid ZigBee header
-    uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00};
-    uint8_t *send_buf = (uint8_t *) malloc( sizeof(uint8_t) * (len+8) );
-
-    for(uint8_t i = 0; i < len+8; i++) {
+    //uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00};
+    //uint8_t *send_buf = (uint8_t *) malloc( sizeof(uint8_t) * (len) );
+    //for(uint8_t i = 0; i < len+8; i++) {
         //prepend the 8-byte header
-        send_buf[i] = (i<8) ? header[i] : data[i-8];
+        //send_buf[i] = (i<8) ? header[i] : data[i-8];
     }
     //pc.printf("Sent: %s\r\n", send_buf+8);
-
-    mrf.Send(send_buf, len+8);
-    free(send_buf);
+    
+    //for(unit8_t i = 0; i < len; i++){
+        //}
+      
+    mrf.Send((unit8_t *) data, (len*4)+4);
+    //free(send_buf);
 }
 
 int main() {
     mrf.SetChannel(15);
     int nodes = 6;
     char buffer[128];
-    while(1) {
+    
+    packet buffer(NODE,2,HELLO_TYPE,4.0,5.0);
+    rf_send(buffer, 2);
+   /* while(1) {
        pc.printf("Select operation: \r\n");
        pc.printf("1) get node list\r\n");
        pc.printf("2) Update data rates\r\n");
@@ -106,6 +117,6 @@
             pc.printf("unknown command\r\n");
             break;
         }
-       
+   */
        }
 }