Skip to content

Commit

Permalink
[GS] Logging improvements
Browse files Browse the repository at this point in the history
1. Log data from both links into a single file,
2. Add units in log headers,
3. Fix logging icon refresh,
4. Fix free size calculation; Free size is refreshed after logging
stops.
  • Loading branch information
stojadin2701 committed Oct 8, 2023
1 parent c98f52e commit fca5b62
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 23 deletions.
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

0 comments on commit fca5b62

Please sign in to comment.