eive-tmtc/gomspace/gomspace_common.py

170 lines
5.4 KiB
Python
Raw Normal View History

2020-12-29 11:29:03 +01:00
# -*- coding: utf-8 -*-
"""
@file gomspace_common.py
@brief PDU2 tests
@details All functions and classes common for all gomspace devices are defined in this file.
@author J. Meier
@date 17.12.2020
"""
2021-09-07 14:51:50 +02:00
import enum
2020-12-29 11:29:03 +01:00
2021-09-07 14:51:50 +02:00
from tmtccmd.tc.service_8_functional_cmd import generate_action_command
from tmtccmd.tc.definitions import PusTelecommand
2020-12-29 11:29:03 +01:00
2021-09-07 14:51:50 +02:00
class GomspaceDeviceActionIds(enum.IntEnum):
PING = 1
REBOOT = 4
PARAM_GET = 0
PARAM_SET = 255
WDT_RESET = 9
REQUEST_HK_TABLE = 16
2021-09-20 11:47:04 +02:00
PRINT_SWITCH_V_I = 32
2022-03-14 14:46:00 +01:00
PRINT_LATCHUPS = 33
2021-09-16 14:51:24 +02:00
2022-04-04 18:46:52 +02:00
class GomspaceOpCodes:
# Request HK
2022-04-08 14:46:01 +02:00
REQUEST_CORE_HK_ONCE = ["hk-core", "128"]
REQUEST_AUX_HK_ONCE = ["hk-aux", "129"]
PRINT_SWITCH_V_I = ["print-switch-vi", "130"]
PRINT_LATCHUPS = ["print-latchups", "131"]
class Info:
REQUEST_CORE_HK_ONCE = "Requesting Core HK once"
REQUEST_AUX_HK_ONCE = "Requesting Aux HK once"
class SetIds:
2022-04-12 16:00:37 +02:00
PDU_1_CORE = 1
PDU_1_AUX = 2
PDU_2_CORE = 3
PDU_2_AUX = 4
P60_CORE = 5
P60_AUX = 6
ACU = 7
2020-12-29 11:29:03 +01:00
class TableIds:
config = 1
hk = 4
class TableEntry:
uint8_size = 1
uint16_size = 2
uint32_size = 4
def __init__(self, parameter_address: bytearray, parameter_size):
self.parameter_address = parameter_address
self.parameter_size = parameter_size
class Channel:
on = 1
off = 0
2021-09-07 14:51:50 +02:00
def pack_get_param_command(
2022-01-18 14:03:56 +01:00
object_id: bytearray, table_id: int, memory_address: bytearray, parameter_size: int
2021-09-07 14:51:50 +02:00
) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
"""Function to generate a command to retrieve parameters like the temperature from a gomspace device.
2020-12-29 11:29:03 +01:00
@param object_id: The object id of the gomspace device handler.
@param table_id: The table id of the gomspace device
@param memory_address: Address offset within table of the value to read.
@param parameter_size: Size of the value to read. E.g. temperature is uint16_t and thus parameter_size is 2
@return: The command as bytearray.
"""
2021-09-07 14:51:50 +02:00
app_data = bytearray()
app_data.append(table_id)
app_data.extend(memory_address)
app_data.append(parameter_size)
return generate_action_command(
2022-01-18 14:03:56 +01:00
object_id=object_id,
action_id=GomspaceDeviceActionIds.PARAM_GET,
app_data=app_data,
2021-09-07 14:51:50 +02:00
)
def pack_set_param_command(
2022-01-18 14:03:56 +01:00
object_id: bytearray,
memory_address: bytearray,
parameter_size: int,
parameter: int,
ssc: int = 0,
2021-09-07 14:51:50 +02:00
) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
"""Function to generate a command to set a parameter
2021-09-07 14:51:50 +02:00
:param object_id: The object id of the gomspace device handler.
:param memory_address: Address offset within table of the value to set.
:param parameter: The parameter value to set.
:param parameter_size: Size of the value to set. There are uint8_t, uint16_t and uint32_t
in the device tables.
:param ssc:
:return: The command as bytearray.
2020-12-29 11:29:03 +01:00
"""
2021-09-07 14:51:50 +02:00
action_id = GomspaceDeviceActionIds.PARAM_SET
app_data = bytearray()
app_data += memory_address
app_data.append(parameter_size)
2020-12-29 11:29:03 +01:00
if parameter_size == 1:
2021-09-07 14:51:50 +02:00
app_data.append(parameter)
2020-12-29 11:29:03 +01:00
elif parameter_size == 2:
byte_one = 0xFF00 & parameter >> 8
byte_two = 0xFF & parameter
2021-09-07 14:51:50 +02:00
app_data.append(byte_one)
app_data.append(byte_two)
2020-12-29 11:29:03 +01:00
elif parameter_size == 4:
byte_one = 0xFF000000 & parameter >> 24
byte_two = 0xFF0000 & parameter >> 16
byte_three = 0xFF00 & parameter >> 8
byte_four = 0xFF & parameter
2021-09-07 14:51:50 +02:00
app_data.append(byte_one)
app_data.append(byte_two)
app_data.append(byte_three)
app_data.append(byte_four)
return generate_action_command(
object_id=object_id, action_id=action_id, app_data=app_data, ssc=ssc
)
2020-12-29 11:29:03 +01:00
2021-09-07 14:51:50 +02:00
def pack_ping_command(object_id: bytearray, data: bytearray) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
""" " Function to generate the command to ping a gomspace device
2020-12-29 11:29:03 +01:00
@param object_id Object Id of the gomspace device handler.
@param data Bytearray containing the bytes to send to the gomspace device. For now the on board software
supports only the handling of up to 33 bytes.
@note The ping request sends the specified data to a gompsace device. These
data are simply copied by the device and then sent back.
"""
2021-09-07 14:51:50 +02:00
return generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.PING, app_data=data
)
2020-12-29 11:29:03 +01:00
2021-09-07 14:51:50 +02:00
def pack_gnd_wdt_reset_command(object_id: bytearray) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
""" " Function to generate the command to reset the watchdog of a gomspace device.
2020-12-29 11:29:03 +01:00
@param object_id Object Id of the gomspace device handler.
"""
2022-01-18 14:03:56 +01:00
return generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.WDT_RESET
)
2020-12-29 11:29:03 +01:00
2021-09-07 14:51:50 +02:00
def pack_reboot_command(object_id: bytearray) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
"""Function to generate the command which triggers a reboot of a gomspace device
2020-12-29 11:29:03 +01:00
@param object_id The object id of the gomspace device handler.
"""
2022-01-18 14:03:56 +01:00
return generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.REBOOT
)
2021-02-06 16:35:53 +01:00
2021-09-07 14:51:50 +02:00
def pack_request_full_hk_table_command(object_id: bytearray) -> PusTelecommand:
2022-01-18 14:03:56 +01:00
"""Function to generate the command to request the full housekeeping table from a gomspace
2021-02-06 16:35:53 +01:00
device.
@param object_id The object id of the gomspace device handler.
"""
2021-09-07 14:51:50 +02:00
return generate_action_command(
object_id=object_id, action_id=GomspaceDeviceActionIds.REQUEST_HK_TABLE
)