Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Last fixes for release #345

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flight_computer/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions flight_computer/src/tasks/task_telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ground_station/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 17 additions & 8 deletions ground_station/src/hmi/hmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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;
Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions ground_station/src/hmi/hmi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ class Hmi {
Window window;

uint32_t menuIndex = 0;

uint32_t flashFreeMemory = 100;

bool link1Log = false;
bool link2Log = false;
};
11 changes: 5 additions & 6 deletions ground_station/src/hmi/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,24 +59,23 @@ 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;

static uint32_t blinkStatus = 0;

// 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);
}

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 9 additions & 6 deletions ground_station/src/logging/recorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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++;

Expand Down
10 changes: 8 additions & 2 deletions ground_station/src/logging/recorder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand All @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion ground_station/src/navigation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down