2023-02-16 01:02:14 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import dataclasses
|
|
|
|
import enum
|
|
|
|
import struct
|
|
|
|
|
2023-09-29 14:11:03 +02:00
|
|
|
from spacepackets.ecss.tc import PacketId, PacketType
|
|
|
|
|
2023-02-16 01:02:14 +01:00
|
|
|
EXAMPLE_PUS_APID = 0x02
|
2023-09-29 14:11:03 +02:00
|
|
|
EXAMPLE_PUS_PACKET_ID_TM = PacketId(PacketType.TM, True, EXAMPLE_PUS_APID)
|
|
|
|
TM_PACKET_IDS = [EXAMPLE_PUS_PACKET_ID_TM]
|
2023-02-16 01:02:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EventSeverity(enum.IntEnum):
|
2023-02-16 10:09:02 +01:00
|
|
|
INFO = 0
|
|
|
|
LOW = 1
|
|
|
|
MEDIUM = 2
|
2023-02-16 01:02:14 +01:00
|
|
|
HIGH = 3
|
|
|
|
|
|
|
|
|
|
|
|
@dataclasses.dataclass
|
|
|
|
class EventU32:
|
|
|
|
severity: EventSeverity
|
|
|
|
group_id: int
|
|
|
|
unique_id: int
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def unpack(cls, data: bytes) -> EventU32:
|
|
|
|
if len(data) < 4:
|
|
|
|
raise ValueError("passed data too short")
|
|
|
|
event_raw = struct.unpack("!I", data[0:4])[0]
|
|
|
|
return cls(
|
|
|
|
severity=EventSeverity((event_raw >> 30) & 0b11),
|
|
|
|
group_id=(event_raw >> 16) & 0x3FFF,
|
|
|
|
unique_id=event_raw & 0xFFFF,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-04-03 18:04:32 +02:00
|
|
|
class Apid(enum.IntEnum):
|
|
|
|
SCHED = 1
|
|
|
|
GENERIC_PUS = 2
|
|
|
|
ACS = 3
|
|
|
|
CFDP = 4
|
|
|
|
|
|
|
|
|
|
|
|
class AcsId(enum.IntEnum):
|
|
|
|
MGM_0 = 0
|
2023-02-16 01:02:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AcsHkIds(enum.IntEnum):
|
|
|
|
MGM_SET = 1
|
|
|
|
|
|
|
|
|
|
|
|
def make_addressable_id(target_id: int, unique_id: int) -> bytes:
|
|
|
|
byte_string = bytearray(struct.pack("!I", target_id))
|
|
|
|
byte_string.extend(struct.pack("!I", unique_id))
|
|
|
|
return byte_string
|