Andriy Makukha / Mbed 2 deprecated football_project_wo_output

Dependencies:   mbed

Fork of football_project by MZJ

Files at this revision

API Documentation at this revision

Comitter:
elmbed
Date:
Sun Jan 03 20:05:15 2016 +0000
Parent:
27:b7b8a2441353
Child:
29:ae208b014987
Child:
30:c60b0d52b067
Commit message:
Fixed 'z' command

Changed in this revision

Radio.cpp 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
proto_code.cpp Show annotated file Show diff for this revision Revisions of this file
types.h Show annotated file Show diff for this revision Revisions of this file
--- a/Radio.cpp	Thu Dec 31 17:47:15 2015 +0000
+++ b/Radio.cpp	Sun Jan 03 20:05:15 2016 +0000
@@ -36,6 +36,8 @@
   radio.promiscuous(promiscuousMode);
 }
 
+
+
 void radio_send(Message *m)
 {
     static byte payload [6] = {0};
@@ -45,7 +47,7 @@
         return;    
     }
     
-    //writeToPhone("Sending message: %c to: %d\r\n", m->command, m->cone);
+    writeToPhone("Sending message: %c to: %d from: %d\r\n", m->command, m->cone, NODE_ID);
     
     payload[0] = (byte)m->command;
     payload[4] = (byte)m->value & 255;
@@ -53,12 +55,8 @@
     payload[2] = (byte)(m->value >> 16);
     payload[1] = (byte)(m->value >> 24);
     payload[5] = (byte)'%';
-  
-    #ifdef MASTER
-    radio.send(2, payload, sizeof(payload));  
-    #else
-    radio.send(1, payload, sizeof(payload));  
-    #endif      
+ 
+    radio.send(m->cone, payload, sizeof(payload));     
 }
 
 bool radio_receive_complete()
@@ -75,13 +73,13 @@
     
     if (radio.receiveDone())
     {
-        //writeToPhone("Received: %d bytes", radio.DATALEN);
+        writeToPhone("Received: %d bytes", radio.DATALEN);
         if (radio.DATALEN < 6)
         {
             return false;    
         }
         
-        //writeToPhone("Got message from: %d\r\n", radio.SENDERID);
+        writeToPhone("Got message from: %d\r\n", radio.SENDERID);
         
         m->cone    = radio.SENDERID;
         m->command = radio.DATA[0];
--- a/main.cpp	Thu Dec 31 17:47:15 2015 +0000
+++ b/main.cpp	Sun Jan 03 20:05:15 2016 +0000
@@ -192,7 +192,12 @@
 
     // Get MAC addr so we can create a device name using it.
     ble.getAddress( pAdType, macAddr );
-    sprintf( deviceName, "T%02X%02X", macAddr[1], macAddr[0] );
+    
+    #ifdef MASTER
+    sprintf( deviceName, "M%02X%02X", macAddr[1], macAddr[0] );
+    #else
+    sprintf( deviceName, "S%02X%02X", macAddr[1], macAddr[0] );
+    #endif
 
     ble.accumulateAdvertisingPayload( GapAdvertisingData::COMPLETE_LOCAL_NAME,
                                       (const uint8_t *)deviceName, strlen(deviceName) );
@@ -425,7 +430,7 @@
         }
     }
 }
-/*
+
 static uint32_t boot_cnt_data = 0;
 static uint16_t data_block    = 9*20 +75;   // Last block -- Use for app-start count.
 static uint16_t data_size     = 4;
@@ -547,7 +552,7 @@
 
     return  pstorage_register( &pstorage_param, &pstorage_id );
 }
-*/
+
 
 void periodicCallback( void )
 {
@@ -588,7 +593,7 @@
   /*
     // Thread thread( led_thread );
   */
-
+    
  /////pcfc.baud( 57600 );
 
   /*
@@ -617,18 +622,21 @@
     uint32_t pstorageErr = pstorage_init();  // This needs to be called, even though apparently called in bootloader--Check other stuff.
     pstorage_access_status_get( &p_count );
 
-  /*
+  
 //    pcfc.printf( "\r\nInitial pstorage count: %d\r\n", p_count );
 
-    if( NRF_SUCCESS != pstorageErr )  pcfc.printf( "\r\nWarn: pstorage init error: %x\r\n", pstorageErr );
+    if( NRF_SUCCESS != pstorageErr )
+    {
+      writeToPhone( "\r\nWarn: pstorage init error: %x\r\n", pstorageErr );
+    }
       else
       {
           pstorageErr = pstorage_setup();
-          if( NRF_SUCCESS != pstorageErr )  pcfc.printf( "\r\nWarn: pstorage setup error: %x\r\n", pstorageErr );
+          if( NRF_SUCCESS != pstorageErr )  writeToPhone( "\r\nWarn: pstorage setup error: %x\r\n", pstorageErr );
             else
             {
                 pstorageErr = pstorage_read_test();
-                if( NRF_SUCCESS != pstorageErr )  pcfc.printf( "\r\nWarn: pstorage read attempt error: %x\r\n", pstorageErr );
+                if( NRF_SUCCESS != pstorageErr )  writeToPhone( "\r\nWarn: pstorage read attempt error: %x\r\n", pstorageErr );
                   else
                   {
                       // In this test setup, we use the load callback to signal start to clear,
@@ -636,7 +644,7 @@
                   }
             }
       }
-    */
+    
 
     DeviceInformationService deviceInfo( ble, "TRX", "TrueAgility", "SN0001", "hw-rev1", "fw-rev1" );
     BatteryService battService( ble );
--- a/proto_code.cpp	Thu Dec 31 17:47:15 2015 +0000
+++ b/proto_code.cpp	Sun Jan 03 20:05:15 2016 +0000
@@ -45,15 +45,14 @@
 
 static bool active_cones[NUM_CONES + 1]; // + 1 so we can be 1 based like the cone numbers are
 
+const static int CONTROL_CONE = 1;
+
 #ifdef MASTER
 static Mode_t mode = PATTERN;
 static patternState_t state_p = IDLE_P;
 static inputState_t state_i = IDLE_I;
-#define ADDRESS           NODE_ID
 #else
 State_t state = IDLE;
-#define CONTROL_CONE      1
-#define ADDRESS           NODE_ID
 #endif
 
 static Message m1 = { 'm',0,2 };
@@ -136,7 +135,7 @@
 #ifdef MASTER
 static void master_setup()
 {
-    ta.initialize(ADDRESS);
+    ta.initialize(NODE_ID);
   
   uint16_t sent = 0;
   uint16_t lost = 0;
@@ -151,13 +150,16 @@
   //ta.beep(100);  
   int i;
   
-  //for(i=3;i<=3;i++)active_cones[i] = true;
-  for(i=1;i<NUM_CONES+1;i++)active_cones[i] = true;
+  for(i = 1; i < NUM_CONES + 1; ++i)
+  {
+    active_cones[i] = false;
+  }
     
-    unsigned long time = 0;
+  unsigned long time = 0;
   
   // pull course sequences from non-volatile memory  
-  for(uint8_t i=0;i<STATIONS * SEQUENCES;i++){
+  for(uint8_t i = 0; i <STATIONS * SEQUENCES; ++i)
+  {
     cone_table[i] = i+1;
     mask_table[i] = 1;
     time_table[i] = 1000;
@@ -168,7 +170,7 @@
 #else
 static void slave_setup()
 {
-    ta.initialize(ADDRESS);
+    ta.initialize(NODE_ID);
     ta.beep(250);
 }
 #endif
@@ -191,6 +193,7 @@
     static bool process_next_as_mask = false;
     static unsigned long timer;
     static State_t last_state = IDLE;
+    static int counter = 0;
   
     if(last_state != state)
     {
@@ -211,7 +214,10 @@
   
     if(ta.recieve(m_in))
     {
-        ta.beep(1000);
+        //ta.beep(1000);
+        
+        writeToPhone("got message\r\n");
+        
         message = m_in->command;
         switch(m_in->command)
         {
@@ -273,7 +279,7 @@
 
   if(message == 'q')
   {  // Quit
-    //serial.printf("Clear!\n");
+    writeToPhone("Clear!\r\n");
     ta.pulse_off();
     ta.mask_color(0xFF0000);
     state = IDLE;
@@ -295,7 +301,7 @@
   {
     m->value = m_in->value;
     m->command = 'z';
-    m->cone = 3;
+    m->cone = 1;
     ta.send(m);
   }
   
@@ -339,6 +345,7 @@
 static void master_loop()
 {
     static Mode_t last_mode = mode;
+    static int counter = 0;
     
     if (last_mode != mode)
     {
@@ -944,7 +951,7 @@
   
   if(sound == 2)
   {
-    if(active_cone == ADDRESS)
+    if(active_cone == NODE_ID)
     {
         ta.powerup(sound);
     }
@@ -1035,20 +1042,19 @@
 
 static void find_cones(void)
 {
-#if 1
   while(ta.get_buffer_size())
   {
     ta.spin(); // wait for all messages to leave queue
-    }
+  }
   
   ta.beep_off();
   uint8_t i;
   m->command = 'z';
-
+  
   lonely = true;
   
   writeToPhone("Finding cones\r\n");
-  //for (i=3; i <=3; ++i)
+  
   for(i = 2; i < NUM_CONES + 1; ++i)
   {
     active_cones[i] = false;
@@ -1070,7 +1076,7 @@
       {
         writeToPhone("Find timeout for: %d\r\n", i);
         break;
-        }
+      }
         
       //ta.spin();
       
@@ -1079,12 +1085,6 @@
         lonely = false;
         active_cones[m_in->cone] = true;
         
-        writeToPhone("Reply from: %d\r\n", m_in->cone);
-        DEBUG("Reply from cone: ");
-        DEBUG("%d",m_in->cone);
-        DEBUG(", ");
-        DEBUG("%d",delta);
-        DEBUG("ms\n");
         break;
       }
     }
@@ -1101,29 +1101,14 @@
   }
   
   writeToPhone(")\r\n");
-  
-  #endif
 }
 
 static void printMsAsSeconds(unsigned long number)
 {
   uint16_t remainder;
   
-  //DEBUG("%d",number/1000);
-  //DEBUG(".");
-
   remainder = number%1000;
 
-  /*
-  if(remainder < 100)
-    //DEBUG("0");
-    
-  if(remainder < 10)
-    //DEBUG("0");
-    
-  //DEBUG("%d",remainder);
-  */
-
   writeToPhone( "%d.%03d", number/1000, remainder );
 }
 
--- a/types.h	Thu Dec 31 17:47:15 2015 +0000
+++ b/types.h	Sun Jan 03 20:05:15 2016 +0000
@@ -1,11 +1,12 @@
 #ifndef TYPES_H
 #define TYPES_H
 
-#define MASTER
-//#define SLAVE
+//#define MASTER
+#define SLAVE
 
 // these must be here because of magic in the Arduino IDE (otherwise functions cannot retun these types
 #ifdef MASTER
+
 enum Mode_t{ IDLE, FREEFORM, PATTERN };
 #else
 enum State_t{ ACTIVE_TARGET, IDLE, FAIL, SUCCESS };
@@ -23,9 +24,9 @@
   };*/
 
 #ifdef MASTER
-#define NODE_ID 1
+const static int NODE_ID = 1;
 #else
-#define NODE_ID 2     
+const static int NODE_ID = 3;
 #endif
 
 struct Event{