diff --git a/TARS/src/mcu_main/main.cpp b/TARS/src/mcu_main/main.cpp index 650d662a..8ed62b9d 100644 --- a/TARS/src/mcu_main/main.cpp +++ b/TARS/src/mcu_main/main.cpp @@ -297,8 +297,9 @@ static THD_FUNCTION(dataLogger_THD, arg) { #ifdef THREAD_DEBUG Serial.println("Data Logging thread entrance"); #endif - - sd_logger.update(); + if (datalog_is_running) { + sd_logger.update(); + } chThdSleepMilliseconds(6); } diff --git a/TARS/src/mcu_main/telemetry.cpp b/TARS/src/mcu_main/telemetry.cpp index b606011a..e54984ab 100644 --- a/TARS/src/mcu_main/telemetry.cpp +++ b/TARS/src/mcu_main/telemetry.cpp @@ -109,7 +109,7 @@ void Telemetry::handleCommand(const telemetry_command &cmd) { return; } last_command_id = (int16_t)cmd.cmd_id; - + /* * Write frequency to SD card to save * between runs @@ -130,6 +130,14 @@ void Telemetry::handleCommand(const telemetry_command &cmd) { } Serial.println("[DEBUG]: Got abort"); } + + if (cmd.command == START_LOGGING) { + datalog_is_running = true; + } + + if (cmd.command == STOP_LOGGING) { + datalog_is_running = false; + } } // #define TLM_DEBUG diff --git a/TARS/src/mcu_main/telemetry.h b/TARS/src/mcu_main/telemetry.h index 6a0d1d74..7b61d0ca 100644 --- a/TARS/src/mcu_main/telemetry.h +++ b/TARS/src/mcu_main/telemetry.h @@ -69,7 +69,7 @@ struct TelemetryPacket { }; // Commands transmitted from ground station to rocket -enum CommandType { SET_FREQ, SET_CALLSIGN, ABORT, TEST_FLAPS, EMPTY }; +enum CommandType { SET_FREQ, SET_CALLSIGN, ABORT, TEST_FLAPS, EMPTY, START_LOGGING, STOP_LOGGING }; struct telemetry_command { CommandType command; @@ -90,6 +90,8 @@ struct command_handler_struct { class Telemetry { public: bool abort = false; + bool datalog_is_running = false; + Telemetry(); diff --git a/ground/src/feather/main.cpp b/ground/src/feather/main.cpp index c1983ee6..58487b52 100644 --- a/ground/src/feather/main.cpp +++ b/ground/src/feather/main.cpp @@ -331,6 +331,10 @@ void SerialInput(const char* key, const char* value) { return; } else if (strcmp(key, "FLAP") == 0) { command.command = CommandType::TEST_FLAP; + } else if (strcmp(key, "START_LOGGING") == 0) { + command.command = CommandType::START_LOGGING; + } else if (strcmp(key, "STOP_LOGGING") == 0) { + command.command = CommandType::STOP_LOGGING; } else { SerialError(); return;