2021-11-24 15:56:25 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
@file ccsds_handler.py
|
|
|
|
@brief Test commanding of CCSDS Handler
|
|
|
|
@author J. Meier
|
|
|
|
@date 20.11.2021
|
|
|
|
"""
|
2023-01-16 14:18:15 +01:00
|
|
|
import enum
|
2022-01-25 18:23:02 +01:00
|
|
|
import struct
|
|
|
|
|
2023-01-26 11:31:26 +01:00
|
|
|
from eive_tmtc.config.definitions import CustomServiceList
|
2021-11-24 15:56:25 +01:00
|
|
|
from spacepackets.ecss.tc import PusTelecommand
|
2023-01-26 11:31:26 +01:00
|
|
|
from tmtccmd.config.tmtc import (
|
|
|
|
tmtc_definitions_provider,
|
|
|
|
OpCodeEntry,
|
|
|
|
TmtcDefinitionWrapper,
|
|
|
|
)
|
2022-08-08 16:32:18 +02:00
|
|
|
from tmtccmd.tc import DefaultPusQueueHelper
|
2023-01-31 12:56:13 +01:00
|
|
|
from tmtccmd.tc.pus_200_fsfw_mode import create_mode_command, Mode
|
2022-07-08 16:25:46 +02:00
|
|
|
from tmtccmd.util import ObjectIdU32
|
2023-01-25 14:51:32 +01:00
|
|
|
from eive_tmtc.config.object_ids import CCSDS_HANDLER_ID
|
2021-11-24 15:56:25 +01:00
|
|
|
|
|
|
|
|
2023-01-25 14:14:22 +01:00
|
|
|
class ActionId(enum.IntEnum):
|
2021-11-24 15:56:25 +01:00
|
|
|
# Configures input rate of syrlinks to 400 Khz (results in downlink rate of 200 kbps)
|
2023-01-25 14:51:32 +01:00
|
|
|
# SET_LOW_RATE = 0
|
2021-11-24 15:56:25 +01:00
|
|
|
# Configures input rate of syrlinks to 2000 Khz (results in downlink rate of 1000 kbps)
|
2023-01-25 14:51:32 +01:00
|
|
|
# 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
|
2022-01-31 07:34:20 +01:00
|
|
|
EN_TRANSMITTER = 2
|
2023-01-25 14:51:32 +01:00
|
|
|
# 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.
|
2022-01-31 07:34:20 +01:00
|
|
|
DIS_TRANSMITTER = 3
|
2022-01-25 18:23:02 +01:00
|
|
|
# Sets an arbitrary bitrate. Normally only set low and set high rate commands should be
|
|
|
|
# required
|
2022-01-31 07:34:20 +01:00
|
|
|
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
|
2021-11-24 15:56:25 +01:00
|
|
|
|
|
|
|
|
2023-01-25 14:51:32 +01:00
|
|
|
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"]
|
2023-01-26 11:31:26 +01:00
|
|
|
DISABLE = ["disable"]
|
2023-01-25 14:51:32 +01:00
|
|
|
ENABLE_ACTION = ["legacy_enable_tx"]
|
|
|
|
DISABLE_ACTION = ["legacy_disable_tx"]
|
|
|
|
|
|
|
|
|
2023-01-26 11:31:26 +01:00
|
|
|
class Info:
|
|
|
|
ENABLE_WITH_LOW_DATARATE = "Enable TX with low datarate"
|
|
|
|
ENABLE_WITH_HIGH_DATARATE = "Enable TX with high datarate"
|
|
|
|
DISABLE = "Disable TX"
|
|
|
|
ENABLE_ACTION = "Enable TX (legacy)"
|
|
|
|
DISABLE_ACTION = "Disable TX (legacy)"
|
|
|
|
|
|
|
|
|
2022-08-08 16:32:18 +02:00
|
|
|
def pack_ccsds_handler_test(
|
|
|
|
object_id: ObjectIdU32, q: DefaultPusQueueHelper, op_code: str
|
|
|
|
):
|
2022-07-04 17:59:09 +02:00
|
|
|
obyt = object_id.as_bytes
|
2023-01-26 11:31:26 +01:00
|
|
|
prefix = "CCSDS Handler"
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd(f"Testing CCSDS handler with object id: {object_id.as_hex_string}")
|
2023-01-25 14:51:32 +01:00
|
|
|
if op_code in OpCode.ENABLE_WITH_LOW_DATARATE:
|
2023-01-26 11:31:26 +01:00
|
|
|
q.add_log_cmd(f"{prefix}: {Info.ENABLE_WITH_LOW_DATARATE}")
|
2023-01-25 14:51:32 +01:00
|
|
|
q.add_pus_tc(create_mode_command(obyt, Mode.ON, Submode.DATARATE_LOW))
|
|
|
|
if op_code in OpCode.ENABLE_WITH_HIGH_DATARATE:
|
2023-01-26 11:31:26 +01:00
|
|
|
q.add_log_cmd(f"{prefix}: {Info.ENABLE_WITH_HIGH_DATARATE}")
|
2023-01-25 14:51:32 +01:00
|
|
|
q.add_pus_tc(create_mode_command(obyt, Mode.ON, Submode.DATARATE_HIGH))
|
2023-01-26 11:31:26 +01:00
|
|
|
if op_code in OpCode.DISABLE:
|
|
|
|
q.add_log_cmd(f"{prefix}: {Info.DISABLE}")
|
2023-01-25 14:51:32 +01:00
|
|
|
q.add_pus_tc(create_mode_command(obyt, Mode.OFF, 0))
|
|
|
|
if op_code in OpCode.ENABLE_ACTION:
|
2023-01-26 11:31:26 +01:00
|
|
|
q.add_log_cmd(f"{prefix}: {Info.ENABLE_ACTION}")
|
2023-01-25 14:14:22 +01:00
|
|
|
command = obyt + struct.pack("!I", ActionId.EN_TRANSMITTER)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2023-01-26 11:31:26 +01:00
|
|
|
if op_code in OpCode.DISABLE_ACTION:
|
|
|
|
q.add_log_cmd(f"{prefix}: {Info.DISABLE_ACTION}")
|
2023-01-25 14:14:22 +01:00
|
|
|
command = obyt + struct.pack("!I", ActionId.DIS_TRANSMITTER)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2022-01-25 18:23:02 +01:00
|
|
|
if op_code == "4":
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("CCSDS Handler: Set arbitrary bitrate")
|
2022-01-25 18:23:02 +01:00
|
|
|
bitrate = int(input("Specify bit rate (bps): "))
|
2022-02-03 16:02:55 +01:00
|
|
|
command = (
|
2022-07-04 17:59:09 +02:00
|
|
|
obyt
|
2023-01-25 14:14:22 +01:00
|
|
|
+ struct.pack("!I", ActionId.ARBITRARY_BITRATE)
|
2022-02-03 16:02:55 +01:00
|
|
|
+ struct.pack("!I", bitrate)
|
|
|
|
)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2022-01-31 07:34:20 +01:00
|
|
|
if op_code == "5":
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("CCSDS Handler: Enable tx clock manipulator")
|
2023-01-25 14:14:22 +01:00
|
|
|
command = obyt + struct.pack("!I", ActionId.ENABLE_TX_CLK_MANIPULATOR)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2022-01-31 07:34:20 +01:00
|
|
|
if op_code == "6":
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("CCSDS Handler: Disable tx clock manipulator")
|
2023-01-25 14:14:22 +01:00
|
|
|
command = obyt + struct.pack("!I", ActionId.DISABLE_TX_CLK_MANIPULATOR)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2022-01-31 07:34:20 +01:00
|
|
|
if op_code == "7":
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("CCSDS Handler: Update tx data on rising edge of tx clock")
|
2023-01-25 14:14:22 +01:00
|
|
|
command = obyt + struct.pack("!I", ActionId.UPDATE_ON_RISING_EDGE)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2022-01-31 07:34:20 +01:00
|
|
|
if op_code == "8":
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_log_cmd("CCSDS Handler: Update tx data on falling edge of tx clock")
|
2023-01-25 14:14:22 +01:00
|
|
|
command = obyt + struct.pack("!I", ActionId.UPDATE_ON_FALLING_EDGE)
|
2022-07-04 17:59:09 +02:00
|
|
|
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
|
2023-01-26 11:31:26 +01:00
|
|
|
|
|
|
|
|
|
|
|
@tmtc_definitions_provider
|
|
|
|
def add_ccsds_cmds(defs: TmtcDefinitionWrapper):
|
|
|
|
oce = OpCodeEntry()
|
|
|
|
oce.add(OpCode.ENABLE_WITH_LOW_DATARATE, Info.ENABLE_WITH_LOW_DATARATE)
|
|
|
|
oce.add(OpCode.ENABLE_WITH_HIGH_DATARATE, Info.ENABLE_WITH_HIGH_DATARATE)
|
|
|
|
oce.add(OpCode.DISABLE, Info.DISABLE)
|
|
|
|
oce.add(OpCode.ENABLE_ACTION, Info.ENABLE_ACTION)
|
|
|
|
oce.add(OpCode.DISABLE_ACTION, Info.DISABLE_ACTION)
|
|
|
|
oce.add("4", "CCSDS Handler: Set arbitrary bitrate")
|
|
|
|
oce.add("5", "CCSDS Handler: Enable tx clock manipulator")
|
|
|
|
oce.add("6", "CCSDS Handler: Disable tx clock manipulator")
|
|
|
|
oce.add("7", "CCSDS Handler: Update tx data on rising edge")
|
|
|
|
oce.add("8", "CCSDS Handler: Update tx data on falling edge")
|
|
|
|
defs.add_service(CustomServiceList.CCSDS_HANDLER.value, "CCSDS Handler", oce)
|