diff --git a/flight_computer/platformio.ini b/flight_computer/platformio.ini index c7b5fd84..78c88178 100644 --- a/flight_computer/platformio.ini +++ b/flight_computer/platformio.ini @@ -35,7 +35,7 @@ check_src_filters = build_unflags=-fno-rtti build_flags = - -D FIRMWARE_VERSION='"3.0.0"' + -D FIRMWARE_VERSION='"3.0.1"' -D ARM_MATH_CM4 -D ARM_MATH_MATRIX_CHECK -D ARM_MATH_ROUNDING diff --git a/flight_computer/src/tasks/task_telemetry.cpp b/flight_computer/src/tasks/task_telemetry.cpp index 50363537..5eabccda 100644 --- a/flight_computer/src/tasks/task_telemetry.cpp +++ b/flight_computer/src/tasks/task_telemetry.cpp @@ -54,6 +54,7 @@ enum state_e { #define INDEX_OP 0 #define INDEX_LEN 1 #define TELE_MAX_POWER 30 +static constexpr uint32_t kDefaultPaGain = 34; void Telemetry::PackTxMessage(uint32_t ts, gnss_data_t* gnss, packed_tx_msg_t* tx_payload, estimation_output_t estimation_data) const noexcept { @@ -294,9 +295,15 @@ void Telemetry::ParseRxMessage(packed_rx_msg_t* rx_payload) noexcept { if (global_cats_config.telemetry_settings.adaptive_power == ON) { if (fsm_updated && (m_fsm_enum == THRUSTING)) { SendSettings(CMD_POWER_LEVEL, TELE_MAX_POWER); + // Send PA gain to update power level; 34 is already the default value on telemetry chip + // NOTE: This line has to stay here forever as telemetry code can't be updated for all boards + SendSettings(CMD_PA_GAIN, kDefaultPaGain); } if (fsm_updated && (m_fsm_enum == TOUCHDOWN)) { SendSettings(CMD_POWER_LEVEL, global_cats_config.telemetry_settings.power_level); + // Send PA gain to update power level; 34 is already the default value on telemetry chip + // NOTE: This line has to stay here forever as telemetry code can't be updated for all boards + SendSettings(CMD_PA_GAIN, kDefaultPaGain); } } diff --git a/ground_station/platformio.ini b/ground_station/platformio.ini index dbdec98b..9d777dcc 100644 --- a/ground_station/platformio.ini +++ b/ground_station/platformio.ini @@ -65,7 +65,7 @@ lib_deps = build_flags = -DCFG_TUSB_CONFIG_FILE='"sdkconfig.h"' ; Use default TinyUSB configuration - -DFIRMWARE_VERSION='"1.0.1"' ; Enter Firmware Version here + -DFIRMWARE_VERSION='"1.1.0"' ; Enter Firmware Version here -DUSB_MANUFACTURER='"CATS"' ; USB Manufacturer string -DUSB_PRODUCT='"CATS Groundstation"' ; USB Product String -D USB_SERIAL="0" ; Enter Device Serial Number here diff --git a/ground_station/src/hmi/hmi.cpp b/ground_station/src/hmi/hmi.cpp index 8dc69c12..00d5264c 100644 --- a/ground_station/src/hmi/hmi.cpp +++ b/ground_station/src/hmi/hmi.cpp @@ -115,8 +115,12 @@ void Hmi::initLive() { window.initLive(); } void Hmi::live() { bool updated = false; - /* Dual Mode */ if (link1.data.isUpdated() && link1.info.isUpdated()) { + // We log after LIFTOFF and stop either never (if neverStopLogging == TRUE) or at TOUCHDOWN + link1Log = (link1.data.state() > 2) && (systemConfig.config.neverStopLogging || link1.data.state() < 7); + if (link1Log) { + recorder.record(&link1.data.rxData, 1); + } window.updateLive(&link1.data, &link1.info, 0); updated = true; } else if (link1.info.isUpdated()) { @@ -125,11 +129,10 @@ void Hmi::live() { } if (link2.data.isUpdated() && link2.info.isUpdated()) { - if (link2.data.state() > 2) { - recorder.record(&link2.data.rxData); - isLogging = true; - } else { - isLogging = false; + // We log after LIFTOFF and stop either never (if neverStopLogging == TRUE) or at TOUCHDOWN + link2Log = (link2.data.state() > 2) && (systemConfig.config.neverStopLogging || link2.data.state() < 7); + if (link2Log) { + recorder.record(&link2.data.rxData, 2); } window.updateLive(&link2.data, &link2.info, 1); updated = true; @@ -138,12 +141,15 @@ void Hmi::live() { updated = true; } + isLogging = link1Log || link2Log; + if (updated) { window.refresh(); } if (backButton.wasPressed()) { state = MENU; + isLogging = false; window.initMenu(menuIndex); } } @@ -575,13 +581,16 @@ void Hmi::update(void *pvParameter) { if (millis() - barUpdate >= 1000) { barUpdate = millis(); float voltage = analogRead(18) * 0.00059154929; - int32_t free_memory = utils.getFlashMemoryUsage(); + if (!ref->isLogging) { + ref->flashFreeMemory = utils.getFlashMemoryUsage(); + } if (link2.time.isUpdated()) { setTime(link2.time.hour(), link2.time.minute(), link2.time.second(), 0, 0, 0); adjustTime(systemConfig.config.timeZoneOffset * 3600); timeValid = true; } - ref->window.updateBar(voltage, digitalRead(21), ref->isLogging, link2.location.isValid(), timeValid, free_memory); + ref->window.updateBar(voltage, digitalRead(21), ref->isLogging, link2.location.isValid(), timeValid, + ref->flashFreeMemory); } ref->upButton.read(); diff --git a/ground_station/src/hmi/hmi.hpp b/ground_station/src/hmi/hmi.hpp index 7c67770b..623433bb 100644 --- a/ground_station/src/hmi/hmi.hpp +++ b/ground_station/src/hmi/hmi.hpp @@ -99,4 +99,9 @@ class Hmi { Window window; uint32_t menuIndex = 0; + + uint32_t flashFreeMemory = 100; + + bool link1Log = false; + bool link2Log = false; }; diff --git a/ground_station/src/hmi/window.cpp b/ground_station/src/hmi/window.cpp index 9017d05d..48d3b778 100644 --- a/ground_station/src/hmi/window.cpp +++ b/ground_station/src/hmi/window.cpp @@ -59,9 +59,7 @@ void Window::initBar() { void Window::updateBar(float batteryVoltage, bool usb, bool logging, bool location, bool time, int32_t free_memory) { static int32_t oldHour = 0; static int32_t oldMinute = 0; - static float oldBatteryVoltage = 0; static bool oldUsbStatus = false; - static bool oldLocationStatus = false; static bool oldLoggingStatus = false; static int32_t oldFreeMemory = 0; @@ -69,14 +67,15 @@ void Window::updateBar(float batteryVoltage, bool usb, bool logging, bool locati // Logging if (logging != oldLoggingStatus) { - display.drawBitmap(65, 1, bar_download, 16, 16, !logging); + display.drawBitmap(75, 1, bar_download, 16, 16, !logging); + oldLoggingStatus = logging; } if (logging) { - display.drawBitmap(65, 1, bar_download, 16, 16, blinkStatus); + display.drawBitmap(75, 1, bar_download, 16, 16, blinkStatus); } // Location - if (location != oldLocationStatus) { + if (location) { display.drawBitmap(329, 1, bar_location, 16, 16, !location); } @@ -132,7 +131,7 @@ void Window::updateBar(float batteryVoltage, bool usb, bool logging, bool locati } // Battery - if (batteryVoltage != oldBatteryVoltage && !usb) { + if (batteryVoltage && !usb) { if (batteryVoltage > 3.3f) { display.fillRect(373, 5, 6, 8, BLACK); display.drawRoundRect(371, 3, 24, 12, 2, BLACK); diff --git a/ground_station/src/logging/recorder.cpp b/ground_station/src/logging/recorder.cpp index 7d6edf69..7c54b5f4 100644 --- a/ground_station/src/logging/recorder.cpp +++ b/ground_station/src/logging/recorder.cpp @@ -20,7 +20,7 @@ bool Recorder::begin() { number++; } while (fatfs.exists(fileName)); - queue = xQueueCreate(10, sizeof(packedRXMessage)); + queue = xQueueCreate(64, sizeof(RecorderElement)); xTaskCreate(recordTask, "task_recorder", 4096, this, 1, NULL); initialized = true; return initialized; @@ -34,22 +34,25 @@ void Recorder::createFile() { return; } fileCreated = true; - file.println("ts,state,errors,lat,lon,altitude,velocity,battery,pyro1,pyro2"); + file.println( + "link,ts[deciseconds],state,errors,lat[deg/10000],lon[deg/10000],altitude[m],velocity[m/" + "s],battery[decivolts],pyro1,pyro2"); } void Recorder::recordTask(void *pvParameter) { Recorder *ref = (Recorder *)pvParameter; char line[128]; uint32_t count = 0; - packedRXMessage element; + RecorderElement element; while (ref->initialized) { if (xQueueReceive(ref->queue, &element, portMAX_DELAY) == pdPASS) { if (!ref->fileCreated) { ref->createFile(); } - snprintf(line, 128, "%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", element.timestamp, element.state, element.errors, - element.lat, element.lon, element.altitude, element.velocity, element.voltage, - (bool)(element.pyro_continuity & 0x01), (bool)(element.pyro_continuity & 0x02)); + const auto &data = element.data; + snprintf(line, 128, "%hu,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d", element.source, data.timestamp, data.state, data.errors, + data.lat, data.lon, data.altitude, data.velocity, data.voltage, (bool)(data.pyro_continuity & 0x01), + (bool)(data.pyro_continuity & 0x02)); ref->file.println(line); count++; diff --git a/ground_station/src/logging/recorder.hpp b/ground_station/src/logging/recorder.hpp index 73430b48..7b6b324f 100644 --- a/ground_station/src/logging/recorder.hpp +++ b/ground_station/src/logging/recorder.hpp @@ -3,6 +3,11 @@ #include "telemetry/telemetryData.hpp" #include "utils.hpp" +struct RecorderElement { + packedRXMessage data; + uint8_t source; // Link 1 or Link 2 +}; + class Recorder { public: Recorder(const char* directory) : directory(directory) {} @@ -12,9 +17,10 @@ class Recorder { void disable() { enabled = false; } - void record(packedRXMessage* data) { + void record(packedRXMessage* data, uint8_t link_source) { if (enabled) { - xQueueSend(queue, data, 0); + RecorderElement rec_elem = {*data, link_source}; + xQueueSend(queue, &rec_elem, 0); } } diff --git a/ground_station/src/navigation.cpp b/ground_station/src/navigation.cpp index 9bccdd6c..24d736d6 100644 --- a/ground_station/src/navigation.cpp +++ b/ground_station/src/navigation.cpp @@ -15,7 +15,7 @@ bool Navigation::begin() { calibration = CALIB_CONCLUDED; - xTaskCreate(navigationTask, "task_recorder", 1024, this, 1, NULL); + xTaskCreate(navigationTask, "task_navigation", 1024, this, 1, NULL); return true; }