most functionality to splashdwon, find neutral and start mission. short timeouts still in code for testing, will adjust to go directly to sit_idle after splashdown

Dependencies:   mbed MODSERIAL FATFileSystem

Revision:
87:6d95f853dab3
Parent:
86:ba3a118b0080
Child:
88:1813f583cee9
--- a/ConfigFileIO/ConfigFileIO.cpp	Thu May 02 20:34:16 2019 +0000
+++ b/ConfigFileIO/ConfigFileIO.cpp	Wed May 08 13:24:04 2019 +0000
@@ -354,7 +354,7 @@
     if (!cfg.read("/local/logvers.txt")) {   //   "/local/leg_mission.txt"
             error("Lognames version file logvers.txt  File Read Error");
     }
-    char value[BUFSIZ];
+    char value[BUFSIZ]; //  chang
  
     
     if (cfg.getValue("LogFileVers", &value[0] , sizeof(value))) {
@@ -372,7 +372,7 @@
         sprintf(buf, "in configfileIO: diag file version number is %d\n", version);
         if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
         //  buf[256]= {0};
-        sprintf(buf, "in ConfigFileIO:   diag file string is DIAG%03d.txt", version);
+        sprintf(buf, "in ConfigFileIO:   diag file string is DIAG%03d.txt\n", version);
         if(print_diag == 1) {mbedLogger().appendDiagFile(buf,3);}
         // buf[256]= {0};
         sprintf(buf, "DIAG%03d.txt", version);
@@ -385,6 +385,74 @@
     }
     return count;
 }
+int ConfigFileIO::load_setneutral_status() { 
+    ConfigFile cfg;
+    int count = 0;
+    int setval = 0;
+    int bce_mm = 240;
+    int batt_mm = 40;
+    if (!cfg.read("/local/neutral.txt")) {   
+       error("setneutral file neutral.txt  File Read Error");
+       //  set values in struct to defaults??
+    }
+    char value[BUFSIZ];
+ 
+    
+    if (cfg.getValue("neutral_set", &value[0] , sizeof(value))) {
+        setval = atoi(value);  
+        neutralStruct.setval = setval;
+        count++;
+    }
+    if (cfg.getValue("bce_neutral_mm", &value[0] , sizeof(value))) {
+        bce_mm = atoi(value);  
+        char buf[256];
+        sprintf(buf, "in configfileIO: bce_neutral_mm  is %d\n", bce_mm);
+        mbedLogger().appendDiagFile(buf,3);
+        //  buf[256]= {0};
+        neutralStruct.bce_neutral_mm = bce_mm;
+        count++;
+    }
+    if (cfg.getValue("batt_neutral_mm", &value[0] , sizeof(value))) {
+        batt_mm = atoi(value);  
+        char buf[256];
+        sprintf(buf, "in configfileIO: batt_neutral_mm  is %d\n", batt_mm);
+        mbedLogger().appendDiagFile(buf,3);
+        //  buf[256]= {0};
+        neutralStruct.batt_neutral_mm = batt_mm;
+        count++;
+    }
+    return count;
+}
+void ConfigFileIO::saveNeutralStatus(int setval, int bce_neutral_mm, int batt_neutral_mm) {
+    ConfigFile neutral_txt;    
+       
+    //convert input numbers into text and save them to text file
+    char string_setval[128];  
+    sprintf(string_setval, "%d", setval);
+    neutral_txt.setValue("# Neutral set status and values\nneutral_set", string_setval);
+    
+    char string_bce[128];  
+    sprintf(string_bce, "%d", bce_neutral_mm);
+    neutral_txt.setValue("bce_neutral_mm", string_bce);
+    
+    char string_batt[128];  
+    sprintf(string_batt, "%d", batt_neutral_mm);
+    neutral_txt.setValue("batt_neutral_mm", string_batt);
+
+        
+    //SAVE THE DATA!    also put the data insto the neutral struct
+    neutralStruct.batt_neutral_mm = batt_neutral_mm; 
+    neutralStruct.bce_neutral_mm = bce_neutral_mm;
+    neutralStruct.setval = setval;
+    xbee().printf("(ConfigFileIO) Saving neutral set status  parameters!");
+    
+    if (!neutral_txt.write("/local/neutral.txt")) {
+        xbee().printf("\n\rERROR: (SAVE) Failure to write neutral.txt file.");
+    }
+    else {
+        xbee().printf("\n\rFile neutral.txt successful written.\n\r");
+    }  
+}
 int ConfigFileIO::load_BATT_config() { // I could copy this mode to read one line of a leg_mission file. One line or multiple lines?
     ConfigFile cfg;
     int count = 0;
@@ -429,7 +497,57 @@
     
     return count;     
 }
-
+void ConfigFileIO::report_still_inverted( float roll_value, int yotime) {
+     ConfigFile still_inverted;
+      
+      char string_yotime[128];  
+    sprintf(string_yotime, "%d", yotime);
+    still_inverted.setValue("# Still Inverted after START_SWIM yo timeout timeout\n yo_time", string_yotime);
+    
+    char string_roll[128];  
+    sprintf(string_roll, "%f", roll_value);
+    still_inverted.setValue("inverted_roll_value", string_roll);
+    
+            
+    //SAVE THE DATA!   
+    
+    xbee().printf("(ConfigFileIO) Saving still_inverted status after start_swim timeout!");
+    
+    if (!still_inverted.write("/local/inverted.txt")) {  // I assume this will build a new file if one is not already there
+        xbee().printf("\n\rERROR: (SAVE) Failure to write inverted.txt file.");
+    }
+    else {
+        xbee().printf("\n\rFile inverted.txt  written.\n\r");  // raspberry Pi will need to delete this file on finding it
+    } 
+     
+    }
+void ConfigFileIO::report_no_neutral_found(int bce_last_pos, int batt_last_pos) {  // this will tell the Raspberry Pi that neutral was not found -- BAD
+    ConfigFile no_neutral;    
+       int setval = 0;
+    //convert input numbers into text and save them to text file
+    char string_setval[128];  
+    sprintf(string_setval, "%d", setval);
+    no_neutral.setValue("# Find_Neutral  success or failure\nneutral_found", string_setval);
+    
+    char string_batt[128];  
+    sprintf(string_batt, "%d", batt_last_pos);
+    no_neutral.setValue("batt_last_position", string_batt);
+    
+    sprintf(string_batt, "%d", bce_last_pos);
+    no_neutral.setValue("bce_last_position", string_batt);
+    
+        
+    //SAVE THE DATA!    also put the data insto the neutral struct
+    
+    xbee().printf("(ConfigFileIO) Saving find_neutral failure status!");
+    
+    if (!no_neutral.write("/local/no_float.txt")) {  // I assume this will build a new file if one is not already there
+        xbee().printf("\n\rERROR: (SAVE) Failure to write no_float.txt file.");
+    }
+    else {
+        xbee().printf("\n\rFile no_float.txt  written.\n\r");
+    } 
+}
 int ConfigFileIO::load_DEPTH_config() {
     ConfigFile cfg;
     int count = 0;