
modifications to run via legfile.txt and then exit, manage logfile versions, diagnostics file
Dependencies: mbed MODSERIAL FATFileSystem
Revision 84:eccd8e837134, committed 2019-02-19
- Comitter:
- joel_ssc
- Date:
- Tue Feb 19 20:11:43 2019 +0000
- Parent:
- 83:53f9b1be4eb9
- Commit message:
- updated file management of logfiles and diagfile numbers
Changed in this revision
diff -r 53f9b1be4eb9 -r eccd8e837134 MbedLogger/MbedLogger.cpp --- a/MbedLogger/MbedLogger.cpp Fri Feb 15 16:14:22 2019 +0000 +++ b/MbedLogger/MbedLogger.cpp Tue Feb 19 20:11:43 2019 +0000 @@ -189,7 +189,9 @@ //prints current log file to the screen (terminal) void MbedLogger::printCurrentLogFile() { //open the file for reading - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? _log_file_line_counter = 0; @@ -220,7 +222,9 @@ //OPEN FILE FOR READING - string file_name_string = _file_system_string + "LOG000.csv"; + //string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? _fp = fopen(file_name_string.c_str(), "r"); @@ -336,7 +340,9 @@ void MbedLogger::continuouslyTransmitDataNoTimer() { - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? _fp = fopen(file_name_string.c_str(), "r"); @@ -448,7 +454,9 @@ setTransmitPacketNumber(0); //open the file - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? _fp = fopen(file_name_string.c_str(), "r"); //receive correct checksum, immediately send this packet @@ -479,7 +487,9 @@ //GET TOTAL NUMBER OF PACKETS! //open the file - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? _fp = fopen(file_name_string.c_str(), "r"); //DEFAULT STATE @@ -810,7 +820,9 @@ void MbedLogger::reOpenLineReader() { //open a new one - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? _fp = fopen(file_name_string.c_str(), "r"); //open the log file to read @@ -819,12 +831,15 @@ xbee().printf("ERROR: Log file could not be opened\n\r"); } else { - xbee().printf("Current Log file (LOG000.csv) was opened.\n\r"); + xbee().printf("Current Log file (%s) was opened.\n\r", configFileIO().logFilesStruct.logFileName); } } bool MbedLogger::openLineReader() { - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? + _fp = fopen(file_name_string.c_str(), "r"); //open the log file to read @@ -854,7 +869,10 @@ //takes less than a second to complete, verified 7/24/2018 //open the file - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? + _fp = fopen(file_name_string.c_str(), "r"); fseek(_fp, 0L, SEEK_END); @@ -888,7 +906,10 @@ void MbedLogger::openWriteFile() { xbee().printf("Opening file for reception.\n\r"); - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? + _fp = fopen(file_name_string.c_str(), "w"); } @@ -1344,7 +1365,9 @@ } void MbedLogger::createEmptyLog() { - string file_name_string = _file_system_string + "LOG000.csv"; + // string file_name_string = _file_system_string + "LOG000.csv"; + string file_name_string = _file_system_string + configFileIO().logFilesStruct.logFileName; // "DIAG000.txt"; + //string file_name_string = _file_system_string + "LOG000.csv"; // how to pass in log file name as a string? string empty_log = "EMPTY LOG"; _fp = fopen(file_name_string.c_str(), "w");
diff -r 53f9b1be4eb9 -r eccd8e837134 StateMachine/StateMachine.cpp --- a/StateMachine/StateMachine.cpp Fri Feb 15 16:14:22 2019 +0000 +++ b/StateMachine/StateMachine.cpp Tue Feb 19 20:11:43 2019 +0000 @@ -3,8 +3,8 @@ StateMachine::StateMachine() { _timeout = 20; // generic timeout for every state, seconds - _yo_time = 1.0e7; // timeout for a dive or rise yo, not set for other ops - + _yo_time = 400; // timeout for a dive or rise yo, not set for other ops + _state_transition_time = 60; // time to allow motors to come to rest in float_broadcast _pitchTolerance = 5.0; // pitch angle tolerance for FLOAT_LEVEL state _bceFloatPosition = bce().getTravelLimit(); // bce position for "float" states (max travel limit for BCE is 320 mm) @@ -144,6 +144,8 @@ xbee().printf("\r\n\nstate: EMERGENCY_CLIMB\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running + _yotimer.reset(); + _yotimer.start(); _isTimeoutRunning = true; // what needs to be started? @@ -164,7 +166,7 @@ } else if (depthLoop().getPosition() < 2.0) { //if the depth is greater than 0.2 feet, go to float broadcast _state = FLOAT_BROADCAST; - _fsm_timer.reset(); + _fsm_timer.reset(); _yotimer.reset(); _isTimeoutRunning = false; } @@ -400,7 +402,7 @@ if (!_isTimeoutRunning) { xbee().printf("\r\n\nstate: LEG POSITION DIVE first time - start timer\r\n"); sprintf(buf, "LEG POSITION DIVE start first dive start timer\n\n\r"); - mbedLogger().appendDiagFile(buf,0); + mbedLogger().appendDiagFile(buf,0); _fsm_timer.reset(); // timer goes back to zero I am not sure about this reset jcw _fsm_timer.start(); // background timer starts running _isTimeoutRunning = true; @@ -459,7 +461,8 @@ //retrieve commands from structs (loaded from missionleg.cfg file) leg_max_depth = currentLegStateStruct.max_depth; leg_heading = currentLegStateStruct.heading; - + sprintf(buf, "LEG POSITION DIVE entered via Leg_pos_rise - lpd_oneshots, only restart _yotimer\n\n\r"); + mbedLogger().appendDiagFile(buf,0); //DEPTH COMMAND //depthLoop().setCommand(_depth_command); // I want this to be the max_depth in the legStruct @@ -484,6 +487,8 @@ _state = LEG_POSITION_RISE; // now start a timer on yo_timer for rise finish_leg =1; lpr_oneshots=0; + sprintf(buf, "go to LEG POSITION DIVE on overall leg timeout, set finish_leg=1\n\n\r"); + mbedLogger().appendDiagFile(buf,0); // _fsm_timer.reset(); // _isTimeoutRunning = false; } @@ -493,6 +498,7 @@ xbee().printf("LEG POS DIVE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = LEG_POSITION_RISE; lpr_oneshots = 0; + // _fsm_timer.reset(); // reset time if still inside legg long timeout? // _isTimeoutRunning = false; } else if(_yotimer.read() > _yo_time ) { @@ -500,17 +506,19 @@ sprintf(buf, "LEG POS DIVE: yo_time timed out - go to LEG_POSITION_RISE\n\n\r"); mbedLogger().appendDiagFile(buf,3); _state = LEG_POSITION_RISE; + finish_leg =1; //_yotimer.reset(); //_yotimer.start(); // restart the yo timer for next yo in rise mode -- test if depth is small fraction of max_depth and exit to EC if small enough?? lpr_oneshots=0; if (depthLoop().getPosition() < 0.7* depthLoop().getCommand()) { //too slow - exit - _state = EMERGENCY_CLIMB; + _state = EMERGENCY_CLIMB; // overridden here for testing finish_leg = 1; xbee().printf("LEG POS DIVE:descent too slow (<0.7*maxdepth) - go to EMERGENCY_CLIMB actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); - sprintf(buf, "LEG POS DIVE: descent too slow yo_time timed out - go to emergency climb\n\n\r"); + sprintf(buf, "LEG POS DIVE: descent too slow yo_time timed out - go to emergency climb but not really for testing\n\n\r"); mbedLogger().appendDiagFile(buf,3); - _fsm_timer.reset(); - _isTimeoutRunning = false; + _state = LEG_POSITION_RISE; + // _fsm_timer.reset(); + // _isTimeoutRunning = false; } } @@ -610,8 +618,8 @@ } if (!lpr_oneshots) { xbee().printf("\r\n\nstate: LEG POSITION RISE entered via LEG_POSiTION_DIVE finish\r\n"); - sprintf(buf, "state: LEG POSITION RISE entered via LEG_POSTION_DIVE\n\n\r"); - mbedLogger().appendDiagFile(buf,3); + sprintf(buf, "state: LEG POSITION RISE entered via LEG_POSITION_DIVE\n\n\r"); + mbedLogger().appendDiagFile(buf,3); //_fsm_timer.reset(); // timer goes back to zero --no _yotimer.reset(); //reset yo_timer; _yotimer.start(); //and start it @@ -633,29 +641,42 @@ xbee().printf("LEG POS RISE: BCE cmd: %3.1f\r\n",bce().getSetPosition_mm()); //get the actual commanded position xbee().printf("LEG POS RISE: heading cmd: %3.1f\r\n",headingLoop().getCommand()); lpr_oneshots = 1; - } + } // end if(!lpr_oneshots) // how exit? if (_fsm_timer.read() > _timeout) { xbee().printf("LEG POS RISE: timed out on overall timeout\r\n"); - _state = EMERGENCY_CLIMB; - finish_leg = 1; - _fsm_timer.reset(); - _isTimeoutRunning = false; + // _state = EMERGENCY_CLIMB; + finish_leg = 1; // not going immediately to Emergency_climb and not resetting timers means it will take 1 yo-time of rising first + // _fsm_timer.reset(); + sprintf(buf, "LEG POSITION DIVE Ended via overall timeout\n\n\r"); + mbedLogger().appendDiagFile(buf,0); + // _isTimeoutRunning = false; } - else if (depthLoop().getPosition() < leg_min_depth - 0.5) { + else if (depthLoop().getPosition() < leg_min_depth - 0.5 ) { // add in check for finish_leg. Don't flip flop between states in that case xbee().printf("LEG POS RISE: actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); _state = LEG_POSITION_DIVE; + sprintf(buf, "LEG POSITION RISE flip-flops to LEG_POSITION_DIVE on near surface pressure \n\n\r"); + mbedLogger().appendDiagFile(buf,0); //_fsm_timer.reset(); //_isTimeoutRunning = false; lpd_oneshots=0; + if(finish_leg ==1) { + _state = EMERGENCY_CLIMB; + _fsm_timer.reset(); _yotimer.reset(); + _isTimeoutRunning = false; + sprintf(buf, "LEG POSITION RISE ... ENDS, and since finish_leg=1, go to Emergency climb\n\n\r"); + mbedLogger().appendDiagFile(buf,0); + } } else if(_yotimer.read() > _yo_time ) { xbee().printf("LEG POS RISE: yo_time timed out - go to Emergency_CLIMB. Actual depth: %3.1f (cmd: %3.1f)\r\n", depthLoop().getPosition(), depthLoop().getCommand()); - _state = EMERGENCY_CLIMB; + _state = EMERGENCY_CLIMB; // add diagnostics message finish_leg = 1; - _fsm_timer.reset(); + _fsm_timer.reset(); _yotimer.reset(); _isTimeoutRunning = false; + sprintf(buf, "LEG POSITION DIVE ... ENDS on yo_time too long, exit to emergnecy climb + finish_leg=1\n\n\r"); + mbedLogger().appendDiagFile(buf,0); } // what is active? @@ -712,6 +733,8 @@ xbee().printf("\r\n\nstate: FLOAT_BROADCAST\r\n"); _fsm_timer.reset(); // timer goes back to zero _fsm_timer.start(); // background timer starts running + _yotimer.reset(); + _yotimer.start(); _isTimeoutRunning = true; // what needs to be started? @@ -728,7 +751,7 @@ // how exit? - if (_fsm_timer > _timeout ) { + if (_fsm_timer > _timeout || ( _yotimer > _state_transition_time)) { xbee().printf("FB: timed out\r\n"); _state = SIT_IDLE; _fsm_timer.reset(); @@ -749,7 +772,7 @@ //stop recording data //mbedLogger().closeFile(); - + if(finish_leg == 1) { _state = FB_EXIT; } // allows exit if finish_leg set by leg_POS_dive, or LEG_POS_RISE timeout or too slow yo _isTimeoutRunning = false; }
diff -r 53f9b1be4eb9 -r eccd8e837134 StateMachine/StateMachine.hpp --- a/StateMachine/StateMachine.hpp Fri Feb 15 16:14:22 2019 +0000 +++ b/StateMachine/StateMachine.hpp Tue Feb 19 20:11:43 2019 +0000 @@ -122,6 +122,7 @@ int _timeout; // generic timeout for every state, seconds int _yo_time; // time allowed for one up or down in a leg of yo-yos + int _state_transition_time; float _pitchTolerance; // pitch angle tolerance for neutral finding exit criteria float _bceFloatPosition; // bce position for "float" states float _battFloatPosition; // batt position for "broadcast" state
diff -r 53f9b1be4eb9 -r eccd8e837134 logvers.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/logvers.txt Tue Feb 19 20:11:43 2019 +0000 @@ -0,0 +1,2 @@ +LogFileVers=1 +DiagFileVers=1 \ No newline at end of file
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");
diff -r 53f9b1be4eb9 -r eccd8e837134 new_changelog.txt --- a/new_changelog.txt Fri Feb 15 16:14:22 2019 +0000 +++ b/new_changelog.txt Tue Feb 19 20:11:43 2019 +0000 @@ -72,4 +72,16 @@ - Did not check roll - KNOWN ISSUE of log file not having consistent line length (will throw off python data receiver) Modified code at Carderock (2018-08-16) - - Observations at LASR lead to fixes on the save PID files, zero offsets were saving incorrectly, fixed \ No newline at end of file + - Observations at LASR lead to fixes on the save PID files, zero offsets were saving incorrectly, fixed + 2019 feb 15 Modified code jcw + - LogOO?.csv name and version number is set with logvers.txt + - DIAG00?.txt likewise set with logvers.txt + - diagnostic logging to diagnostics file + - legfile.txt sets parameters ( max-depth, min_depth, heading, timeout, yo_time) for a dive leg, after which mbed program ends + to allow monitor computer to access via usb filesystem + - added states: Leg_position_dive, leg_position_rise, fb_exit to handle above yo-yo leg and exit + have not yet added these states in menu operations. + STILL TO DO: + - test size of log file and set new log file name and update logvers.txt + - allow for something other than 0=leg in legfile.txt so that state will NOT drop into legfile.txt operations mode + - add access to leg_position_dive ( with exit??) to menu operations -maybe \ No newline at end of file