eive-tmtc/eive_tmtc/pus_tc/devs/ccsds_handler.py

81 lines
3.6 KiB
Python
Raw Normal View History

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
"""
2022-01-25 18:23:02 +01:00
import struct
2021-11-24 15:56:25 +01:00
from spacepackets.ecss.tc import PusTelecommand
2022-08-08 16:32:18 +02:00
from tmtccmd.tc import DefaultPusQueueHelper
2022-07-08 16:25:46 +02:00
from tmtccmd.util import ObjectIdU32
2021-11-24 15:56:25 +01:00
class CommandIds:
# Configures input rate of syrlinks to 400 Khz (results in downlink rate of 200 kbps)
2022-01-31 07:34:20 +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)
2022-01-31 07:34:20 +01:00
SET_HIGH_RATE = 1
2021-11-24 15:56:25 +01:00
# Enables the syrlinks transmitter (by using RS485 enables lines)
2022-01-31 07:34:20 +01:00
EN_TRANSMITTER = 2
2021-11-24 15:56:25 +01:00
# Disables the syrlinks transmitter (by using RS485 enables lines)
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
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
q.add_log_cmd(f"Testing CCSDS handler with object id: {object_id.as_hex_string}")
2021-11-24 15:56:25 +01:00
if op_code == "0":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("CCSDS Handler: Set low rate")
command = obyt + struct.pack("!I", CommandIds.SET_LOW_RATE)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-11-24 15:56:25 +01:00
if op_code == "1":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("CCSDS Handler: Set high rate")
command = obyt + struct.pack("!I", CommandIds.SET_HIGH_RATE)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-11-24 15:56:25 +01:00
if op_code == "2":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("CCSDS Handler: Enables the transmitter")
command = obyt + struct.pack("!I", CommandIds.EN_TRANSMITTER)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))
2021-11-24 15:56:25 +01:00
if op_code == "3":
2022-07-04 17:59:09 +02:00
q.add_log_cmd("CCSDS Handler: Disables the transmitter")
command = obyt + struct.pack("!I", CommandIds.DIS_TRANSMITTER)
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
2022-02-03 16:02:55 +01:00
+ struct.pack("!I", CommandIds.ARBITRARY_BITRATE)
+ 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")
command = obyt + struct.pack("!I", CommandIds.ENABLE_TX_CLK_MANIPULATOR)
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")
command = obyt + struct.pack("!I", CommandIds.DISABLE_TX_CLK_MANIPULATOR)
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")
command = obyt + struct.pack("!I", CommandIds.UPDATE_ON_RISING_EDGE)
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")
command = obyt + struct.pack("!I", CommandIds.UPDATE_ON_FALLING_EDGE)
q.add_pus_tc(PusTelecommand(service=8, subservice=128, app_data=command))