fsfw-example-tmtc-common/pus_tc/service_2_raw_cmd.py

67 lines
2.6 KiB
Python
Raw Normal View History

2021-07-14 00:28:33 +02:00
# -*- coding: utf-8 -*-
"""
@file tmtcc_tc_service_2_raw_cmd.py
@brief PUS Service 2: Device Access, native low-level commanding
@author R. Mueller
@date 01.11.2019
"""
import struct
2021-10-13 12:08:50 +02:00
from spacepackets.ecss.tc import PusTelecommand
2022-07-03 20:58:32 +02:00
from tmtccmd.tc import QueueHelper
2022-05-18 23:40:13 +02:00
from tmtccmd.tc.pus_200_fsfw_modes import Modes, pack_mode_data
2021-07-14 00:28:33 +02:00
2021-10-13 12:08:50 +02:00
from common_tmtc.pus_tc import command_data as cmd_data
2021-07-14 00:28:33 +02:00
from common_tmtc.config.object_ids import TEST_DEVICE_0_ID
2022-07-03 20:58:32 +02:00
def pack_service_2_commands_into(q: QueueHelper, op_code: str):
2021-07-14 00:28:33 +02:00
if op_code == "0":
2022-07-03 20:58:32 +02:00
pack_generic_service_2_test_into(0, q)
2021-07-14 00:28:33 +02:00
else:
print(f"pack_service_2_test: Operation code {op_code} unknown!")
2022-07-03 20:58:32 +02:00
def pack_generic_service_2_test_into(init_ssc: int, q: QueueHelper) -> int:
2021-07-14 00:28:33 +02:00
new_ssc = init_ssc
object_id = TEST_DEVICE_0_ID # dummy device
# Set Raw Mode
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 2: Setting Raw Mode")
2021-10-13 12:08:50 +02:00
mode_data = pack_mode_data(object_id, Modes.RAW, 0)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
2021-07-14 00:28:33 +02:00
# toggle wiretapping raw
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 2: Toggling Wiretapping Raw")
2021-07-14 00:28:33 +02:00
wiretapping_toggle_data = pack_wiretapping_mode(object_id, 1)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(
PusTelecommand(service=2, subservice=129, app_data=wiretapping_toggle_data)
2021-07-14 00:28:33 +02:00
)
# send raw command, wiretapping should be returned via TM[2,130] and TC[2,131]
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 2: Sending Raw Command")
2021-07-14 00:28:33 +02:00
raw_command = cmd_data.TEST_COMMAND_0
raw_data = object_id + raw_command
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=2, subservice=128, app_data=raw_data))
2021-07-14 00:28:33 +02:00
# toggle wiretapping off
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 2: Toggle Wiretapping Off")
2021-07-14 00:28:33 +02:00
wiretapping_toggle_data = pack_wiretapping_mode(object_id, 0)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(
PusTelecommand(service=2, subservice=129, app_data=wiretapping_toggle_data)
2021-12-14 15:46:00 +01:00
)
2021-07-14 00:28:33 +02:00
# send raw command which should be returned via TM[2,130]
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 2: Send second raw command")
q.add_pus_tc(PusTelecommand(service=2, subservice=128, app_data=raw_data))
2021-07-14 00:28:33 +02:00
# Set mode off
2022-07-03 20:58:32 +02:00
q.add_log_cmd("Testing Service 2: Setting Off Mode")
2022-05-18 23:40:13 +02:00
mode_data = pack_mode_data(object_id, Modes.OFF, 0)
2022-07-03 20:58:32 +02:00
q.add_pus_tc(PusTelecommand(service=200, subservice=1, app_data=mode_data))
2021-07-14 00:28:33 +02:00
return new_ssc
# wiretappingMode = 0: MODE_OFF, wiretappingMode = 1: MODE_RAW
def pack_wiretapping_mode(object_id, wiretapping_mode_):
2021-12-14 15:46:00 +01:00
wiretapping_mode = struct.pack(
">B", wiretapping_mode_
) # MODE_OFF : 0x00, MODE_RAW: 0x01
2021-07-14 00:28:33 +02:00
wiretapping_toggle_data = object_id + wiretapping_mode
return wiretapping_toggle_data