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
Diff: main.cpp
- Revision:
- 84:eccd8e837134
- Parent:
- 82:0981b9ada820
- Child:
- 85:dd8176285b6e
diff -r 53f9b1be4eb9 -r eccd8e837134 main.cpp --- a/main.cpp Fri Feb 15 16:14:22 2019 +0000 +++ b/main.cpp Tue Feb 19 20:11:43 2019 +0000 @@ -235,6 +235,26 @@ setup_complete = true; } +void cycle_logfiles(int logversion, int diagversion) { + //int logversion; + //int diagversion; + char bufx[256]; + sprintf(bufx, "\n\n\r in cycle_logfiles(%d, %d): starting new diag file. Will add 1 to these values \n\n\r", logversion, diagversion); + mbedLogger().appendDiagFile(bufx,0); + mbedLogger().appendLogFile(current_state, 0); //both files are now closed + //use the present values and increment + //logversion = configFileIO().logFilesStruct.logversion + 1; + //diagversion = configFileIO().logFilesStruct.diagversion + 1; + configFileIO().saveLogVersData(logversion+1, diagversion+1); // updates the file logvers.txt + configFileIO().load_LogVers_config(0); // now read them back into the structure + mbedLogger().initializeDiagFile(0); //don't print before initializing + + + mbedLogger().initializeLogFile(); + mbedLogger().initializeDiagFile(1); + +} + /*************************** v1.8 **************************/ int main() { @@ -251,8 +271,8 @@ mbedLogger().appendDiagFile(buf,0); 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, - configFileIO().logFilesStruct.diagFileName); tNow=0; + //tNow=5; sprintf(buf, "log file config values logfile= %s diag file= %s\n", configFileIO().logFilesStruct.logFileName, + // configFileIO().logFilesStruct.diagFileName); tNow=0; mbedLogger().appendDiagFile(buf,3); vernum = configFileIO().logFilesStruct.logversion; diagnum = configFileIO().logFilesStruct.diagversion; @@ -263,6 +283,13 @@ mbedLogger().appendDiagFile(buf,3); sprintf(buf, "try another messgae after closing file up and then will exit\n\n\r"); mbedLogger().appendDiagFile(buf,0); + + + // increment the log file names once + //cycle_logfiles(vernum,diagnum); + //sprintf(buf, "This message should be in a new diag file\n\n\r"); + //mbedLogger().appendDiagFile(buf,0); + // mbedLogger().appendLogFile(current_state, 1); //wait(5); //exit(0); systemTicker.attach_us(&system_timer, 1000); // Interrupt timer running at 0.001 seconds (slower than original ADC time interval) @@ -272,9 +299,8 @@ //install the leg variables in a structure, and set the state there. stateMachine().getLegParams(); //should set up everything with proper LEG_POSITION_DIVE state } - while (keeprunning) { - if( read_ticker() ) // read_ticker runs at the speed of 10 kHz (adc timing) - { + while (keeprunning) { + if( read_ticker() ) { // read_ticker runs at the speed of 10 kHz (adc timing) ++tNow; //Note to self: Retest data transmission code. @@ -285,35 +311,57 @@ FSM(); } } // end if(currentstate..) - + //NOT TRANSMITTING DATA, NORMAL OPERATIONS - else { - //FSM + else { // **88** + //FSM if ( (tNow % 100) == 0 ) { // 0.1 second intervals fsm_loop = true; FSM(); - + //get commands and update GUI gui().getCommandFSM(); - } - //LOGGING - if ( (tNow % 1000) == 0 ) { // 1.0 second intervals + } + //LOGGING + if ( (tNow % 1000) == 0 ) { // 1.0 second intervals + log_loop = true; + log_function(); + sprintf(buf, "hit 1 second log interval in main loop tNow =%d \n\n\r", tNow); + mbedLogger().appendDiagFile(buf,0); + } + //update the log and diagnostics files + if ( (tNow % 4600) == 0 ) { // 1.0 hour intervals check for testing via 7 second intervals + sprintf(buf, "hit 4.6 second replace_logfiles interval in main loop tNow =%d \n\n\r", tNow); + mbedLogger().appendDiagFile(buf,0); + vernum = configFileIO().logFilesStruct.logversion; + diagnum = configFileIO().logFilesStruct.diagversion; + sprintf(buf, "cycle log file names at 7.6 seconds. This message should be in old diag file\n\n\r"); + mbedLogger().appendDiagFile(buf,0); + cycle_logfiles(vernum,diagnum); + sprintf(buf, "cycled log files at 7 seconds, This message should be in a NEW diag file\n\n\r"); + mbedLogger().appendDiagFile(buf,0); + // close the log and diagnostics files + // increment the version numbers for each + // save the new version numbers + // initialize new log and diagnostics files log_loop = true; log_function(); } - } // end else { - if(current_state == FB_EXIT) { - log_loop=true; - log_function(); - keeprunning=0; // and this will force exit to the main while() loop. - } + } // end else { at **88** + if(current_state == FB_EXIT) { + log_loop=true; + log_function(); + keeprunning=0; // and this will force exit to the main while() loop. + sprintf(buf, "INSIDE main loop: BUT now called to exit out of it via FB_EXIT\n\n\r"); + mbedLogger().appendDiagFile(buf,0); + } } // end if(read_ticker) { } // end while(keeprunning) mbedLogger().appendLogFile(current_state, 1); - sprintf(buf, "exiting out of the leg loop via FB_EXIT\n\n\r"); + sprintf(buf, "outside of main loop: exiting out of the leg loop via FB_EXIT\n\n\r"); mbedLogger().appendDiagFile(buf,0); - wait(25); - + wait(25); + 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");