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:
86:ba3a118b0080
Parent:
85:dd8176285b6e
Child:
87:6d95f853dab3
--- a/main.cpp	Mon Feb 25 21:26:34 2019 +0000
+++ b/main.cpp	Thu May 02 20:34:16 2019 +0000
@@ -23,7 +23,7 @@
 
 static int current_state = 0; 
 static int have_legfile = 0;  
-static int upside_down = 0;  
+
 static bool file_opened = false;
 
 void FSM() {                    // FSM loop runs at 10 hz
@@ -147,7 +147,8 @@
     //sd_card();
                    //  mbedLogger().initializeDiagFile();
     // load config data from files
-    mbedLogger().setLogTime();
+    configFileIO().load_StartTime();
+    //     mbedLogger().setLogTime();  replaced by call in configfileIO
     int print_diag = 0;    // do not print to diag file before it is named
     configFileIO().load_LogVers_config(print_diag);    // version numbers of the log and diag files from "logvers.txt"
     mbedLogger().initializeDiagFile(print_diag);
@@ -216,8 +217,23 @@
     char buf[256];
     //xbee().printf("\n\n\r 2018-08-14 FSG PCB XBee (setup complete) \n\n\r");
     sprintf(buf, "\n\n\r in setup():  starting legController().loadleg() \n\n\r");
+    mbedLogger().appendDiagFile(buf,3);
+    have_legfile = legController().loadLeg();  // this should be 1 if the legfile reader has found 1 or more legs
+    sprintf(buf, "Time is amystery, here is a message before the basic call\n");
+    mbedLogger().appendDiagFile(buf,3);
+    int jj;
+    long int kk;
+    time_t secval;
+    
+    sprintf(buf, "sizeof int=%d    size of long int = %d  size of time_t = %d\n", (sizeof jj), (sizeof kk), (sizeof secval));
+    mbedLogger().appendDiagFile(buf,3);
+    
+    secval = mbedLogger().getSystemTime();
+    sprintf(buf, "Time as a basic string = %s\n", ctime(&secval));
+    mbedLogger().appendDiagFile(buf,3);
+    
+    sprintf(buf, "Time is still amystery, here is a message after the basic call\n");
     mbedLogger().appendDiagFile(buf,0);
-    have_legfile = legController().loadLeg();  // this should be 1 if the legfile reader has found 1 or more legs
     
     //set time of logger (to current or close-to-current time)   now set earlier  at line 149
     // mbedLogger().setLogTime();
@@ -262,14 +278,14 @@
     setup();    //setup electronics/hardware
     // on landing, check orientation, if upside down, fix that first
     systemTicker.attach_us(&system_timer, 1000);         // Interrupt timer running at 0.001 seconds       (slower than original ADC time interval)
-    
+    led2()=1; led4()=0;
     unsigned int tNow = 0;
     int vernum=0;
     int diagnum=0;
      char buf[256];
     xbee().printf("\n\n\r 2018-08-14 FSG PCB XBee (setup complete) \n\n\r");
-    sprintf(buf, "\n\n\r 2018-08-14 FSG PCB XBee line234main (setup complete) \n\n\r");
-    mbedLogger().appendDiagFile(buf,0);
+    sprintf(buf, "\n\n\r 2019-feb-25 FSG PCB XBee line271main (setup complete) \n\n\r");
+    mbedLogger().appendDiagFile(buf,3);
     sprintf(buf, "finished setting up and will exit\n\n\r");
     mbedLogger().appendDiagFile(buf,3);
     //tNow=5; sprintf(buf, "log file config values logfile= %s     diag file= %s\n", configFileIO().logFilesStruct.logFileName,
@@ -282,8 +298,8 @@
     sprintf(buf, "logfiles_struct values - direct LOG FILE VERSION ().logversion=%d           diag file version().diagversion = %d\n", 
     configFileIO().logFilesStruct.logversion,   configFileIO().logFilesStruct.diagversion);
     mbedLogger().appendDiagFile(buf,3);
-     sprintf(buf, "try another message after closing file up and then will exit\n\n\r");
-    mbedLogger().appendDiagFile(buf,0);
+     //sprintf(buf, "try another message after closing file up and then will exit\n\n\r");
+    //mbedLogger().appendDiagFile(buf,0);
     
     
     // increment the log file names once
@@ -299,11 +315,15 @@
         if(have_legfile) {
             //install the leg variables in a structure, and set the state there.
             stateMachine().getLegParams(); //should set up everything with proper LEG_POSITION_DIVE state
+            sprintf(buf, "have_legfile succeeded \n\r");
+             mbedLogger().appendDiagFile(buf,3);
             }
-        if(upside_down ) {  // should this be done inside the statemachine? 
-            //turn right side up ;  
-            upside_down =0;
+        if(!have_legfile) {
+            sprintf(buf, "have_legfile failed!   .... will exit\n\n\r");
+            mbedLogger().appendDiagFile(buf,3);
+            keeprunning = 0;
             }
+  
     while (keeprunning) {
         if( read_ticker() ) {                       // read_ticker runs at the speed of 10 kHz (adc timing)
             ++tNow;
@@ -332,7 +352,12 @@
                     log_loop = true;
                     log_function();
                     sprintf(buf, "hit 1 second  log interval in main loop tNow =%d  imu.roll = %f not-unsampled \n\n\r", tNow, imu().getRoll());  
-                    mbedLogger().appendDiagFile(buf,0);
+                    mbedLogger().appendDiagFile(buf,3);
+                    led3()=0; led2()=0;
+                }
+                if ( (tNow % 5000) == 0 ) {   // 5 second intervals
+                    
+                    led3()=1; led2()=1;
                 }
                 //update the log and diagnostics files
                 if ( (tNow % 31000) == 0 ) {   // 1.0 hour intervals= 3600*1000  check for testing via 4 second intervals
@@ -341,7 +366,7 @@
                     vernum = configFileIO().logFilesStruct.logversion;
                     diagnum = configFileIO().logFilesStruct.diagversion;
                     sprintf(buf, "cycle log file names at tnow=%d at  seconds. This message should be in old diag file\n\n\r", tNow);
-                    mbedLogger().appendDiagFile(buf,0);
+                    mbedLogger().appendDiagFile(buf,3);
                   cycle_logfiles(vernum,diagnum);
                     sprintf(buf, "cycled log files at tNow = %d at seconds, This message should be in a NEW diag file\n\n\r", tNow);
                     mbedLogger().appendDiagFile(buf,3);
@@ -351,26 +376,29 @@
                     // initialize new log and diagnostics files
                     log_loop = true;
                     log_function();
+                    led3()=1;
                 }
             } // end else { at  **88**
             if(current_state == FB_EXIT) {
                 log_loop=true;
-                log_function();
+                log_function(); led2()=1;
                 keeprunning=0;  // and this will force exit to the main while() loop.
                 //  switch state to EOL_WAIT, spit out xbee messages,  wait 60 seconds or so. if keyboard comes back, do not exit
                 sprintf(buf, "INSIDE  main loop: BUT now called to exit out of it via FB_EXIT\n\n\r");
-                mbedLogger().appendDiagFile(buf,0);
+                mbedLogger().appendDiagFile(buf,3);
             }
         }  // end if(read_ticker) {
     }  // end while(keeprunning)
     mbedLogger().appendLogFile(current_state, 1);
     sprintf(buf, "outside of main loop:  exiting out of the leg loop via FB_EXIT\n\n\r");
-    mbedLogger().appendDiagFile(buf,0);
-    wait(25);
-
+    mbedLogger().appendDiagFile(buf,3);
+    led1()=1; led2() =1; led3()=1 ;led4() = 1;
+    wait(5);
+    
     mbedLogger().appendLogFile(current_state, 1);
     mbedLogger().appendLogFile(current_state, 0);
-    sprintf(buf, "wait 25 more seconds? out of the leg loop via FB_EXIT\n\n\r");
+    sprintf(buf, "wait 5 more seconds? out of the leg loop via FB_EXIT\n\n\r");
     mbedLogger().appendDiagFile(buf,0);
+    led1()=0; led2()=0; led3()= 0 ;led4()=0;
     exit(0);
 }  // end main()
\ No newline at end of file