diff --git a/eive_tmtc/tmtc/com/ccsds_handler.py b/eive_tmtc/tmtc/com/ccsds_handler.py index 5577aba..12a43b0 100644 --- a/eive_tmtc/tmtc/com/ccsds_handler.py +++ b/eive_tmtc/tmtc/com/ccsds_handler.py @@ -10,17 +10,21 @@ import struct from spacepackets.ecss.tc import PusTelecommand from tmtccmd.tc import DefaultPusQueueHelper +from tmtccmd.tc.pus_200_fsfw_modes import create_mode_command, Mode from tmtccmd.util import ObjectIdU32 +from eive_tmtc.config.object_ids import CCSDS_HANDLER_ID class ActionId(enum.IntEnum): # Configures input rate of syrlinks to 400 Khz (results in downlink rate of 200 kbps) - SET_LOW_RATE = 0 + # SET_LOW_RATE = 0 # Configures input rate of syrlinks to 2000 Khz (results in downlink rate of 1000 kbps) - SET_HIGH_RATE = 1 - # Enables the syrlinks transmitter (by using RS485 enables lines) + # SET_HIGH_RATE = 1 + # Enables the syrlinks transmitter (by using RS485 enables lines). Please note that this + # is a legacy command. It is recommended to use mode commands instead EN_TRANSMITTER = 2 - # Disables the syrlinks transmitter (by using RS485 enables lines) + # Disables the syrlinks transmitter (by using RS485 enables lines). Please note that this is + # a legacy command. It is recommended to use mode commands instead. DIS_TRANSMITTER = 3 # Sets an arbitrary bitrate. Normally only set low and set high rate commands should be # required @@ -33,20 +37,36 @@ class ActionId(enum.IntEnum): UPDATE_ON_FALLING_EDGE = 8 +class Submode(enum.IntEnum): + # Informative, do not command this. + UNSET = 0 + DATARATE_LOW = 1 + DATARATE_HIGH = 2 + + +class OpCode: + ENABLE_WITH_LOW_DATARATE = ["enable_low_datarate"] + ENABLE_WITH_HIGH_DATARATE = ["enable_high_datarate"] + DISABLE_HIGH_DATARATE = ["disable"] + ENABLE_ACTION = ["legacy_enable_tx"] + DISABLE_ACTION = ["legacy_disable_tx"] + + def pack_ccsds_handler_test( object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str ): obyt = object_id.as_bytes q.add_log_cmd(f"Testing CCSDS handler with object id: {object_id.as_hex_string}") - if op_code == "0": + if op_code in OpCode.ENABLE_WITH_LOW_DATARATE: q.add_log_cmd("CCSDS Handler: Set low rate") - command = obyt + struct.pack("!I", ActionId.SET_LOW_RATE) - q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - if op_code == "1": + q.add_pus_tc(create_mode_command(obyt, Mode.ON, Submode.DATARATE_LOW)) + if op_code in OpCode.ENABLE_WITH_HIGH_DATARATE: q.add_log_cmd("CCSDS Handler: Set high rate") - command = obyt + struct.pack("!I", ActionId.SET_HIGH_RATE) - q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command)) - if op_code == "2": + q.add_pus_tc(create_mode_command(obyt, Mode.ON, Submode.DATARATE_HIGH)) + if op_code in OpCode.DISABLE_ACTION: + q.add_log_cmd("CCSDS Handler: Disable") + q.add_pus_tc(create_mode_command(obyt, Mode.OFF, 0)) + if op_code in OpCode.ENABLE_ACTION: q.add_log_cmd("CCSDS Handler: Enables the transmitter") command = obyt + struct.pack("!I", ActionId.EN_TRANSMITTER) q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))