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 tmtccmd.config.definitions import QueueCommands
|
|
|
|
from tmtccmd.tc.packer import TcQueueT
|
|
|
|
from spacepackets.ecss.tc import PusTelecommand
|
|
|
|
|
|
|
|
|
|
|
|
class CommandIds:
|
|
|
|
# Configures input rate of syrlinks to 400 Khz (results in downlink rate of 200 kbps)
|
|
|
|
SET_LOW_RATE = bytearray([0x0, 0x0, 0x0, 0x0])
|
|
|
|
# Configures input rate of syrlinks to 2000 Khz (results in downlink rate of 1000 kbps)
|
|
|
|
SET_HIGH_RATE = bytearray([0x0, 0x0, 0x0, 0x1])
|
|
|
|
# Enables the syrlinks transmitter (by using RS485 enables lines)
|
|
|
|
EN_TRANSMITTER = bytearray([0x0, 0x0, 0x0, 0x2])
|
|
|
|
# Disables the syrlinks transmitter (by using RS485 enables lines)
|
|
|
|
DIS_TRANSMITTER = bytearray([0x0, 0x0, 0x0, 0x3])
|
2022-01-25 18:23:02 +01:00
|
|
|
# Sets an arbitrary bitrate. Normally only set low and set high rate commands should be
|
|
|
|
# required
|
|
|
|
ARBITRARY_BITRATE = bytearray([0x0, 0x0, 0x0, 0x4])
|
2021-11-24 15:56:25 +01:00
|
|
|
|
|
|
|
|
2022-01-18 14:03:56 +01:00
|
|
|
def pack_ccsds_handler_test(
|
|
|
|
object_id: bytearray, tc_queue: TcQueueT, op_code: str
|
|
|
|
) -> TcQueueT:
|
2021-11-24 15:56:25 +01:00
|
|
|
tc_queue.appendleft(
|
2022-01-27 16:38:20 +01:00
|
|
|
(
|
|
|
|
QueueCommands.PRINT,
|
|
|
|
"Testing CCSDS handler with object id: 0x" + object_id.hex(),
|
|
|
|
)
|
2021-11-24 15:56:25 +01:00
|
|
|
)
|
|
|
|
if op_code == "0":
|
|
|
|
tc_queue.appendleft((QueueCommands.PRINT, "CCSDS Handler: Set low rate"))
|
|
|
|
command = object_id + CommandIds.SET_LOW_RATE
|
|
|
|
command = PusTelecommand(service=8, subservice=128, ssc=20, app_data=command)
|
|
|
|
tc_queue.appendleft(command.pack_command_tuple())
|
|
|
|
if op_code == "1":
|
|
|
|
tc_queue.appendleft((QueueCommands.PRINT, "CCSDS Handler: Set high rate"))
|
|
|
|
command = object_id + CommandIds.SET_HIGH_RATE
|
|
|
|
command = PusTelecommand(service=8, subservice=128, ssc=21, app_data=command)
|
|
|
|
tc_queue.appendleft(command.pack_command_tuple())
|
|
|
|
if op_code == "2":
|
2022-01-18 14:03:56 +01:00
|
|
|
tc_queue.appendleft(
|
|
|
|
(QueueCommands.PRINT, "CCSDS Handler: Enables the transmitter")
|
|
|
|
)
|
2021-11-24 15:56:25 +01:00
|
|
|
command = object_id + CommandIds.EN_TRANSMITTER
|
2022-01-25 18:23:02 +01:00
|
|
|
command = PusTelecommand(service=8, subservice=128, ssc=22, app_data=command)
|
2021-11-24 15:56:25 +01:00
|
|
|
tc_queue.appendleft(command.pack_command_tuple())
|
|
|
|
if op_code == "3":
|
2022-01-18 14:03:56 +01:00
|
|
|
tc_queue.appendleft(
|
|
|
|
(QueueCommands.PRINT, "CCSDS Handler: Disables the transmitter")
|
|
|
|
)
|
2021-11-24 15:56:25 +01:00
|
|
|
command = object_id + CommandIds.DIS_TRANSMITTER
|
2022-01-25 18:23:02 +01:00
|
|
|
command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command)
|
|
|
|
tc_queue.appendleft(command.pack_command_tuple())
|
|
|
|
if op_code == "4":
|
2022-01-27 16:38:20 +01:00
|
|
|
tc_queue.appendleft(
|
|
|
|
(QueueCommands.PRINT, "CCSDS Handler: Set arbitrary bitrate")
|
|
|
|
)
|
2022-01-25 18:23:02 +01:00
|
|
|
bitrate = int(input("Specify bit rate (bps): "))
|
2022-01-27 16:38:20 +01:00
|
|
|
command = object_id + CommandIds.ARBITRARY_BITRATE + struct.pack("!I", bitrate)
|
2022-01-25 18:23:02 +01:00
|
|
|
command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command)
|
2021-11-24 15:56:25 +01:00
|
|
|
tc_queue.appendleft(command.pack_command_tuple())
|
|
|
|
|
|
|
|
return tc_queue
|