Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
"cyclic_redundancy": true,
"iqi": false
},
"parsing_params": {
"error_codes": {
"0x00": "A general error has occurred",
"0x01": "The process in proc_id has died"
},
"status_codes": {
"0x00": "All systems nominal",
"0x01": "The telemetry system just changed to the idle state",
"0x02": "The telemetry system just changed to the airborne state",
"0x03": "The telemetry system just changed to the ascent state",
"0x04": "The telemetry system just detected apogee",
"0x05": "The telemetry system just changed to the landed state",
"0x06": "The telemetry system is still in the idle state",
"0x07": "The telemetry system is still in the airborne state",
"0x08": "The telemetry system is still in the ascent stage",
"0x09": "The telemetry system is still in the descent stage",
"0x0A": "The telemetry system is still in the landed state"
}
},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can probably be hardcoded as enums in the packet spec files. In the case that we want to dynamically update these, we'll need to reboot anyway. This would also leave this file as radio configs, and if sometime in the future we want more configs for things like anomalous faults, we can have that be a new file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure? I was told in the chat to put it in the config

"approved_callsigns": {
"VA3INI": "Matteo Golin",
"VA3ZTA": "Darwin Jull",
Expand Down
2 changes: 2 additions & 0 deletions modules/misc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ class Config:
telemetry_buffer_size: int = 20
radio_parameters: RadioParameters = field(default_factory=RadioParameters)
approved_callsigns: dict[str, str] = field(default_factory=dict[str, str])
parsing_parameters: dict[str, dict[str, Any]] = field(default_factory=dict[str, dict[str, Any]])

def __post_init__(self):
if len(self.approved_callsigns) == 0:
Expand All @@ -144,6 +145,7 @@ def from_json(cls, data: JSON) -> Self:
telemetry_buffer_size=data.get("telemetry_buffer_size", cls.telemetry_buffer_size),
radio_parameters=RadioParameters.from_json(data.get("radio_params", dict())),
approved_callsigns=data.get("approved_callsigns", dict()),
parsing_parameters=data.get("parsing_params", dict())
)


Expand Down
28 changes: 27 additions & 1 deletion modules/telemetry/packet_spec/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
from modules.telemetry.packet_spec.headers import *
from modules.misc.unit_conversions import *
from typing import Any

from modules.misc.config import Config

@dataclass
class Block:
# A format for the struct class to unpack the block from bytes
_struct_format: str = field(default="", init=False, repr=False)
config = Config.from_json({})

@classmethod
def size(cls) -> int:
Expand Down Expand Up @@ -225,6 +226,27 @@ def output_formatted(self, into: dict[str, Any]):
add_to_dict(into, ["magnetic_field", "magnitude"], magnitude(self.x_axis, self.y_axis, self.z_axis))


@dataclass
class FlightStatus(TimedBlock):
_struct_format: str = field(default="<hB", init=False, repr=False)
flight_status: int
def output_formatted(self, into: dict[str, Any]):
add_to_dict(into, ["flight_status", "flight_status"], self.config.parsing_parameters["status_codes"][self.flight_status])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to add the mission time to the dict as well, the identifier for the status itself can just be "status"


@dataclass
class FlightError(TimedBlock):
_struct_format: str = field(default="<hBB", init=False, repr=False)
measurement_time: int
proc_id: int
error_code: int

proc_id = proc_id & 0b00011111

def output_formatted(self, into: dict[str, Any]):
add_to_dict(into, ["flight_error", "mission_time"], self.measurement_time)
add_to_dict(into, ["flight_error", "proc_id"], self.proc_id)
add_to_dict(into, ["flight_error", "error_code"], self.config.parsing_parameters["error_codes"][self.error_code])

class InvalidBlockContents(Exception):
"""Exception raised when invalid block contents are encountered"""

Expand Down Expand Up @@ -277,6 +299,10 @@ def get_block_class(type: BlockType) -> type[Block]:
return Voltage
case BlockType.MAGNETIC_FIELD:
return MagneticField
case BlockType.STATUS_MESSAGE:
return FlightStatus
case BlockType.ERROR_MESSAGE:
return FlightError
case _:
raise ValueError(f"Unsupported block type: {type}")

Expand Down
2 changes: 2 additions & 0 deletions modules/telemetry/packet_spec/headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class BlockType(IntEnum):
COORDINATES = 0x07
VOLTAGE = 0x08
MAGNETIC_FIELD = 0x09
STATUS_MESSAGE = 0x0A
ERROR_MESSAGE = 0x0B


class InvalidHeaderFieldValueError(Exception):
Expand Down
Loading