team-3/src/c3nav/mesh/dataformats.py

59 lines
2 KiB
Python
Raw Normal View History

2023-10-06 02:19:57 +02:00
from dataclasses import dataclass, field
from enum import IntEnum, unique
2023-10-06 02:46:43 +02:00
from c3nav.mesh.baseformats import FixedHexFormat, FixedStrFormat, SimpleFormat, StructType, VarArrayFormat
class MacAddressFormat(FixedHexFormat):
def __init__(self):
super().__init__(num=6, sep=':')
class MacAddressesListFormat(VarArrayFormat):
def __init__(self):
super().__init__(child_type=MacAddressFormat())
@unique
class LedType(IntEnum):
SERIAL = 1
MULTIPIN = 2
2022-04-15 20:02:42 +02:00
2023-10-06 02:10:17 +02:00
2022-04-15 20:02:42 +02:00
@dataclass
class LedConfig(StructType, union_type_field="led_type"):
2023-10-06 02:10:17 +02:00
led_type: LedType = field(metadata={"format": SimpleFormat('B')})
2022-04-15 20:02:42 +02:00
@dataclass
2023-10-06 02:10:17 +02:00
class SerialLedConfig(LedConfig, led_type=LedType.SERIAL):
gpio: int = field(metadata={"format": SimpleFormat('B')})
rmt: int = field(metadata={"format": SimpleFormat('B')})
@dataclass
2023-10-06 02:10:17 +02:00
class MultipinLedConfig(LedConfig, led_type=LedType.MULTIPIN):
gpio_red: int = field(metadata={"format": SimpleFormat('B')})
gpio_green: int = field(metadata={"format": SimpleFormat('B')})
gpio_blue: int = field(metadata={"format": SimpleFormat('B')})
2023-10-05 20:55:36 +02:00
@dataclass
class RangeItemType(StructType):
address: str = field(metadata={"format": MacAddressFormat()})
distance: int = field(metadata={"format": SimpleFormat('H')})
2023-10-06 02:10:17 +02:00
@dataclass
class FirmwareAppDescription(StructType, no_c_type=True):
magic_word: int = field(metadata={"format": SimpleFormat('I')}, repr=False)
secure_version: int = field(metadata={"format": SimpleFormat('I')})
reserv1: list[int] = field(metadata={"format": SimpleFormat('2I')}, repr=False)
version: str = field(metadata={"format": FixedStrFormat(32)})
project_name: str = field(metadata={"format": FixedStrFormat(32)})
compile_time: str = field(metadata={"format": FixedStrFormat(16)})
compile_date: str = field(metadata={"format": FixedStrFormat(16)})
idf_version: str = field(metadata={"format": FixedStrFormat(32)})
app_elf_sha256: str = field(metadata={"format": FixedHexFormat(32)})
2023-10-06 02:46:43 +02:00
reserv2: list[int] = field(metadata={"format": SimpleFormat('20I')}, repr=False)