Skip to content

Conversation

@EleKtr1X
Copy link

Purpose

Closes #478.

New Changes

  • Created a Python script to generate a header file from some TOML input (in particular a telemetry_input.toml file)
    • This includes serialization/deserialization functions
  • This makes it easier for new types of telemetry to be added

Example TOML file:

[[messages]]
id = 1
name = "system_health"

[[messages.signals]]
name = "cpu_temp"
bit_width = 15
min_value = -40
max_value = 85
value_type = "continuous"

[[messages.signals]]
name = "battery_level"
bit_width = 7
min_value = 0
max_value = 100
value_type = "discrete"

Outputted header file:

#pragma once

#include <stdint.h>

// system_health
#define telemetry_system_health_msg_id 1
#define telemetry_system_health_cpu_temp_max 85
#define telemetry_system_health_cpu_temp_min -40
#define telemetry_system_health_battery_level_max 100
#define telemetry_system_health_battery_level_min 0

typedef struct {
    uint16_t cpu_temp; // 15 bits
    uint8_t battery_level; // 7 bits
} telemetry_system_health_msg_t;

static telemetry_system_health_msg_t system_health_mailbox = {0};

void telemetry_set_system_health_cpu_temp(float value) {
    value = (value - -40) / 125 * 0x7fff;
    system_health_mailbox.cpu_temp = (uint16_t)(value + 0.5);
}

float telemetry_get_system_health_cpu_temp(void) {
    uint16_t value = system_health_mailbox.cpu_temp;
    return ((float)value / 0x7fff * 125) + -40;
}

void telemetry_set_system_health_battery_level(uint8_t value) {
    system_health_mailbox.battery_level = value & 0x7f;
}

uint8_t telemetry_get_system_health_battery_level(void) {
    return system_health_mailbox.battery_level;
}

void serialize_system_health(uint8_t* buffer) {
    uint64_t bit_stream = 0U;
    uint32_t bit_offset = 0U;
    bit_stream |= ((uint64_t)system_health_mailbox.cpu_temp & 0x7fff) << bit_offset;
    bit_offset += 15;
    bit_stream |= ((uint64_t)system_health_mailbox.battery_level & 0x7f) << bit_offset;
    bit_offset += 7;
    for (int i = 0; i < 3; ++i) {
        buffer[i] = (bit_stream >> (8 * i)) & 0xFF;
    }
}

void deserialize_system_health(uint8_t* buffer) {
    uint64_t bit_stream = 0U;
    uint32_t bit_offset = 0U;
    for (int i = 0; i < 3; ++i) {
        bit_stream |= ((uint64_t)buffer[i]) << (8 * i);
    }
    system_health_mailbox.cpu_temp = (bit_stream >> bit_offset) & 0x7fff;
    bit_offset += 15;
    system_health_mailbox.battery_level = (bit_stream >> bit_offset) & 0x7f;
    bit_offset += 7;
}

Testing

Explain tests that you ran to verify code functionality.

  • I have unit-tested this PR. Otherwise, explain why it cannot be unit-tested.
  • I have tested this PR on a board if the code will run on a board (Only required for firmware developers).
  • I have tested this PR by running the ARO website (Only required if the code will impact the ARO website).
  • I have tested this PR by running the MCC website (Only required if the code will impact the MCC website).
  • I have included screenshots of the tests performed below.

Outstanding Changes

  • This code is mostly a proof-of-concept, so it may need some small tweaks in the future
    • Most importantly I used TypedDicts due to mypy's type checking, but these types might need to be modified if necessary
  • Until we get actual telemetry files, it will not be possible to add unit tests, but I did add some error checking to ensure the header file will compile correctly

@EleKtr1X EleKtr1X self-assigned this Oct 15, 2025
@github-actions
Copy link

Pull reviewers stats

Stats of the last 120 days for UWOrbital:

User Total reviews Time to review Total comments
Adityya-K 47 23h 8m 145
kepler452b123 16 6d 6h 38m 64
camspec 15 13h 51m 102
Yarik-Popov 7 1d 1h 41m 58
Navtajh04 3 11d 5h 50m 49
sunray4 1 12d 21m 9
proprogrammer504 1 8d 6h 19m 5

⚡️ Pull request stats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create telemetry code generator

1 participant