C++ Library for the PsiSwarm Robot - Version 0.8

Dependents:   PsiSwarm_V8_Blank_CPP Autonomia_RndmWlk

Fork of PsiSwarmV7_CPP by Psi Swarm Robot

Revision:
15:be92991621b4
Parent:
14:d32d948f7a76
--- a/serial.cpp	Tue Jun 27 17:01:58 2017 +0000
+++ b/serial.cpp	Fri Jul 14 12:34:22 2017 +0000
@@ -1012,40 +1012,53 @@
             send_message = 1;
             break;
         case 125:
+            send_message = 2;
             strcpy(command,"GET BEACON DATA");
-            if(allow_commands) {
-                command_status = 1;
-                beacon_data_needing = 1;
-            } else command_status = 2;
+            unsigned short beacon_data[8];
+            sensors.store_background_raw_ir_values();
+            for(int sensor=0; sensor<8; sensor++) {
+                beacon_data[sensor] = sensors.get_background_raw_ir_value(sensor);
+            }
+            // beacon_data holds the array of IR values at the middle of the beacon flash
+            
+            // As an example - we will now wait for 20% of the beacon period and check the background value
+            // background_data holds the true background values (no beacon)
+            int maximum1 = 0, maximum2 = 0, max1_sensor = 8, max2_sensor = 8; 
+            for(int i = 0; i < 8; i++){
+                if(beacon_data[i] > maximum1){
+                    maximum2 = maximum1;
+                    max2_sensor = max1_sensor;
+                    max1_sensor = i;
+                    maximum1 = beacon_data[i];
+                }
+                else if(beacon_data[i] > maximum2){
+                    max2_sensor = i;
+                    maximum2 = beacon_data[i];
+                }
+            }
+            pc.printf("%c%1d,%4d,%1d,%4d,",RESPONSE_MESSAGE_BYTE,max1_sensor,maximum1,max2_sensor,maximum2);
             break;
-        case 126:
-            strcpy(command,"GET BACKGROUND  DATA");
-            if(allow_commands) {
-                command_status = 1;
-                beacon_data_needing = 2;
-            } else command_status = 2;
+        case 255:
+            send_message = 2;
+            pc.printf("swarm");
             break;
-        case 127:
-            strcpy(command,"GET BOTH BEACON AND BACKGROUND  DATA");
-            if(allow_commands) {
-                command_status = 1;
-                beacon_data_needing = 3;
-            } else command_status = 2;
-            break;
+            
     }
 
 
-    if(send_message) {
-        char message_length = strlen(ret_message);
-        switch(interface) {
-            case 0:
-                pc.printf("%c%c%s",RESPONSE_MESSAGE_BYTE,message_length,ret_message);
-                break;
-            case 1:
-                bt.printf("%c%c%s",RESPONSE_MESSAGE_BYTE,message_length,ret_message);
-                break;
+    if(send_message>0) {
+        if(send_message == 1){
+            char message_length = strlen(ret_message);
+            switch(interface) {
+                case 0:
+                    pc.printf("%c%c%s",RESPONSE_MESSAGE_BYTE,message_length,ret_message);
+                    break;
+                case 1:
+                    bt.printf("%c%c%s",RESPONSE_MESSAGE_BYTE,message_length,ret_message);
+                    break;
+            }
+        psi.debug("Received %s request message: %s %s [%02x%02x%02x]\nReply: %s [%d ch]\n",iface, command, subcommand,message[0],message[1],message[2],ret_message,message_length);
         }
-        psi.debug("Received %s request message: %s %s [%02x%02x%02x]\nReply: %s [%d ch]\n",iface, command, subcommand,message[0],message[1],message[2],ret_message,message_length);
     } else {
         switch(interface) {
             case 0: