Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Revision:
62:9b34dc1b265d
Parent:
52:060fdec99780
Child:
64:8886b5e4ab57
diff -r dd7002ceea96 -r 9b34dc1b265d Radio.cpp
--- a/Radio.cpp	Sun Jan 17 07:03:51 2016 +0000
+++ b/Radio.cpp	Mon Jan 18 08:51:31 2016 +0000
@@ -2,6 +2,7 @@
 #include <SPI.h>
 #include "types.h"
 #include "TA.h"
+#include "DataStore.hh"
 
 #define RADIO_STARTUP_ID 99
 #define NETWORKID     101   //the same on all nodes that talk to each other
@@ -25,13 +26,7 @@
 extern "C" void writeToPhone(char *format, ...);
 extern unsigned long millis();
 
-#ifdef MASTER
-static bool is_master = true;
-#else
-static bool is_master = false;
-#endif
-
-static int my_node_id = NODE_ID;
+extern bool is_master;
 
 struct node_id_mapping
 {
@@ -51,7 +46,7 @@
 
 void radio_init()
 {
-  radio.initialize(FREQUENCY, my_node_id, NETWORKID);
+  radio.initialize(FREQUENCY, datastore_node_id(), NETWORKID);
   radio.encrypt(0);
   radio.promiscuous(promiscuousMode);
 }
@@ -74,9 +69,9 @@
     if (em->m.command == 'R')
     {
         // We have been given a node id
-        my_node_id = em->m.value;
+        datastore_set_node_id(em->m.value);
         
-        if( Dbg )  writeToPhone("NID: %d\r\n", my_node_id);
+        if( Dbg )  writeToPhone("NID: %d\r\n", datastore_node_id());
         
         // Now reset the radio :)
         radio_init();
@@ -219,7 +214,7 @@
             slave_process(&em);    
             
         }
-        else if (radio.TARGETID == my_node_id)
+        else if (radio.TARGETID == datastore_node_id())
         {
             memcpy(m, &lm, sizeof(Message));
             
@@ -253,14 +248,14 @@
         return; // Only needed for slave cones    
     }
     
-    if (my_node_id != RADIO_STARTUP_ID && current - last_send > 1000L)
+    if (datastore_node_id() != RADIO_STARTUP_ID && current - last_send > 1000L)
     {
-        if( Dbg )  writeToPhone("NID: %d\r\n", my_node_id);
+        if( Dbg )  writeToPhone("NID: %d\r\n", datastore_node_id());
         last_send = current;
     }
     
     // Send out an i'm here message
-    if (my_node_id != RADIO_STARTUP_ID || current - last_send < 1000L)
+    if (datastore_node_id() != RADIO_STARTUP_ID || current - last_send < 1000L)
     {
         return;
     }