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: StateMachine/StateMachine.cpp
- Revision:
- 69:919ac8d7e023
- Parent:
- 68:8f549749b8ce
- Child:
- 70:0e5180befedd
--- a/StateMachine/StateMachine.cpp Wed Jun 27 23:01:53 2018 +0000 +++ b/StateMachine/StateMachine.cpp Fri Jun 29 14:21:22 2018 +0000 @@ -63,9 +63,7 @@ } //Finite State Machine (FSM) -int StateMachine::runStateMachine() { - static int transmit_packet_number = 1; //for data transmission - +int StateMachine::runStateMachine() { // finite state machine ... each state has at least one exit criteria switch (_state) { case SIT_IDLE : @@ -74,9 +72,9 @@ if (!_isTimeoutRunning) { if (_debug_menu_on) - showDebugMenu(); + printDebugMenu(); else - showSimpleMenu(); + printSimpleMenu(); pc().printf("\r\n\nstate: SIT_IDLE\r\n"); _isTimeoutRunning = true; @@ -693,12 +691,13 @@ pc().printf("TRANSMIT_MBED_LOG set to zero\n\r"); - //get number of packets (lines in the file) - mbedLogger().getNumberOfPacketsInCurrentLog(); + //function to read the file and get number of lines (packets to transmit) + _timeout = mbedLogger().getNumberOfPacketsInCurrentLog(); mbedLogger().setTransmitPacketNumber(0); //reset to zero } + //TIMED OUT if (timer.read() > _timeout) { //mbedLogger().closeLogFile(); //on timeout close the log file that was opened for reading //pc().printf("\r\nTRANSMIT_MBED_LOG: timed out!\r\n"); @@ -717,29 +716,18 @@ pc().printf("\r\n\nstate: TRANSMIT_MBED_LOG (log filed closed)\r\n"); } - //IF THIS IS ZERO -// if (mbedLogger().currentPacketNumber() > transmit_packet_number) { -// pc().printf("mbedLogger().currentPacketNumber() > transmit_packet_number"); -// -// //STATE -// _state = SIT_IDLE; -// -// timer.reset(); -// _isTimeoutRunning = false; -// -// mbedLogger().closeLogFile(); //on timeout close the log file that was opened for reading -// } - //What is active? + mbedLogger().fsmTransmitData(); + mbedLogger().checkForPythonTransmitRequest(); //boolean function that transmits until it's finished - if (mbedLogger().fsmTransmitData()) - ; - else { - mbedLogger().closeLogFile(); - pc().printf("StateMachine: TRANSMIT_MBED_LOG (closeLogFile)\n\r"); - _state = SIT_IDLE; - } +// if (mbedLogger().fsmTransmitData()) +// ; +// else { +// pc().printf("StateMachine: TRANSMIT_MBED_LOG (closeLogFile)\n\n\r"); +// mbedLogger().closeLogFile(); +// _state = SIT_IDLE; +// } break; @@ -787,7 +775,7 @@ } // output the keyboard menu for user's reference -void StateMachine::showSimpleMenu() { +void StateMachine::printSimpleMenu() { pc().printf("\r\r\n\nSIMPLE KEYBOARD MENU (06/27/2018):\r\r\n"); //make sure depth sensor tares itself on startup pc().printf(" Neutral Positions BCE: %0.1f BMM: %0.1f \r\n", _neutral_bce_pos_mm, _neutral_batt_pos_mm); @@ -816,7 +804,7 @@ pc().printf(" * (asterisk) to go to DEBUG keyboard menu\r\n"); } -void StateMachine::showDebugMenu() { +void StateMachine::printDebugMenu() { pc().printf("\r\r\n\nDEBUG KEYBOARD MENU (06/27/2018):\r\r\n"); pc().printf(" Y to go into CHECK NEUTRAL TUNING (This is on a timer! Uses NEUTRAL positions!)\r\n"); pc().printf(" V to POSITION DIVE (initiate motor position-based dive cycle)\r\n"); @@ -1421,6 +1409,7 @@ } else if (user_input == 'G') { + wait(2); _keyboard_state = TRANSMIT_MBED_LOG; } @@ -1771,7 +1760,9 @@ batt().unpause(); //this is now active rudder().unpause(); - while (1) { + while (1) { + wait(0.1); + if (pc().readable()) { TUNING_key = pc().getc(); //get each keystroke }