102 lines
4.3 KiB
Python
102 lines
4.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""
|
|
@file ccsds_handler.py
|
|
@brief Test commanding of CCSDS Handler
|
|
@author J. Meier
|
|
@date 20.11.2021
|
|
"""
|
|
import enum
|
|
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
|
|
# 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). 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). 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
|
|
ARBITRARY_BITRATE = 4
|
|
ENABLE_TX_CLK_MANIPULATOR = 5
|
|
DISABLE_TX_CLK_MANIPULATOR = 6
|
|
# Tx data will be updated on rising edge of tx clock
|
|
UPDATE_ON_RISING_EDGE = 7
|
|
# Tx data will be updated on falling edge of tx clock
|
|
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 in OpCode.ENABLE_WITH_LOW_DATARATE:
|
|
q.add_log_cmd("CCSDS Handler: Set low rate")
|
|
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")
|
|
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))
|
|
if op_code == "3":
|
|
q.add_log_cmd("CCSDS Handler: Disables the transmitter")
|
|
command = obyt + struct.pack("!I", ActionId.DIS_TRANSMITTER)
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
|
if op_code == "4":
|
|
q.add_log_cmd("CCSDS Handler: Set arbitrary bitrate")
|
|
bitrate = int(input("Specify bit rate (bps): "))
|
|
command = (
|
|
obyt
|
|
+ struct.pack("!I", ActionId.ARBITRARY_BITRATE)
|
|
+ struct.pack("!I", bitrate)
|
|
)
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
|
if op_code == "5":
|
|
q.add_log_cmd("CCSDS Handler: Enable tx clock manipulator")
|
|
command = obyt + struct.pack("!I", ActionId.ENABLE_TX_CLK_MANIPULATOR)
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
|
if op_code == "6":
|
|
q.add_log_cmd("CCSDS Handler: Disable tx clock manipulator")
|
|
command = obyt + struct.pack("!I", ActionId.DISABLE_TX_CLK_MANIPULATOR)
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
|
if op_code == "7":
|
|
q.add_log_cmd("CCSDS Handler: Update tx data on rising edge of tx clock")
|
|
command = obyt + struct.pack("!I", ActionId.UPDATE_ON_RISING_EDGE)
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
|
if op_code == "8":
|
|
q.add_log_cmd("CCSDS Handler: Update tx data on falling edge of tx clock")
|
|
command = obyt + struct.pack("!I", ActionId.UPDATE_ON_FALLING_EDGE)
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|