From 6b840eff43440a7b44df1cc089338f600a4a6d88 Mon Sep 17 00:00:00 2001 From: "Jakob.Meier" Date: Sun, 10 Jan 2021 11:42:06 +0100 Subject: [PATCH] tmp1075 tests --- config/tmtcc_definitions.py | 1 + config/tmtcc_globals.py | 2 + config/tmtcc_object_ids.py | 4 ++ pus_tc/tmtcc_tc_acu.py | 7 +++- pus_tc/tmtcc_tc_packer_hook.py | 4 ++ pus_tc/tmtcc_tc_service200_mode.py | 52 ++++++++++++++++++++++++++ pus_tc/tmtcc_tc_tmp1075.py | 59 ++++++++++++++++++++++++++++++ tmtc_core | 2 +- 8 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 pus_tc/tmtcc_tc_service200_mode.py create mode 100644 pus_tc/tmtcc_tc_tmp1075.py diff --git a/config/tmtcc_definitions.py b/config/tmtcc_definitions.py index d5a4f24..6ce43ca 100644 --- a/config/tmtcc_definitions.py +++ b/config/tmtcc_definitions.py @@ -32,6 +32,7 @@ class ServiceList(enum.Enum): PDU1 = auto() PDU2 = auto() ACU = auto() + TMP1075 = auto() class SerialConfig(enum.Enum): diff --git a/config/tmtcc_globals.py b/config/tmtcc_globals.py index 6595b01..ae272ed 100644 --- a/config/tmtcc_globals.py +++ b/config/tmtcc_globals.py @@ -154,6 +154,8 @@ def add_globals_post_args_parsing(args: argparse.Namespace): service = ServiceList.PDU2 elif service == "acu": service = ServiceList.ACU + elif service == "tmp1075": + service = ServiceList.TMP1075 else: logger.warning("Service not known! Setting standard service 17") service = ServiceList.SERVICE_17 diff --git a/config/tmtcc_object_ids.py b/config/tmtcc_object_ids.py index 434d5e4..2185b6a 100644 --- a/config/tmtcc_object_ids.py +++ b/config/tmtcc_object_ids.py @@ -16,6 +16,8 @@ class ObjectIds(enum.Enum): PDU1_HANDLER_ID = auto() PDU2_HANDLER_ID = auto() ACU_HANDLER_ID = auto() + TMP1075_1_HANDLER_ID = auto() + TMP1075_2_HANDLER_ID = auto() def set_object_ids(object_id_dict: Dict[ObjectIds, bytearray]): @@ -27,5 +29,7 @@ def set_object_ids(object_id_dict: Dict[ObjectIds, bytearray]): o_ids.PDU1_HANDLER_ID: bytearray([0x44, 0x00, 0x00, 0x2]), o_ids.PDU2_HANDLER_ID: bytearray([0x44, 0x00, 0x00, 0x3]), o_ids.ACU_HANDLER_ID: bytearray([0x44, 0x00, 0x00, 0x4]), + o_ids.TMP1075_1_HANDLER_ID: bytearray([0x44, 0x00, 0x00, 0x5]), + o_ids.TMP1075_2_HANDLER_ID: bytearray([0x44, 0x00, 0x00, 0x6]), } ) diff --git a/pus_tc/tmtcc_tc_acu.py b/pus_tc/tmtcc_tc_acu.py index cf38750..18e803e 100644 --- a/pus_tc/tmtcc_tc_acu.py +++ b/pus_tc/tmtcc_tc_acu.py @@ -10,6 +10,8 @@ from tmtc_core.pus_tc.tmtcc_pus_tc_packer import TcQueueT from tmtc_core.pus_tc.tmtcc_pus_tc_base import PusTelecommand from gomspace.gomspace_common import * from pus_tc.tmtcc_tc_p60dock import P60DockConfigTable +from config.tmtcc_object_ids import ObjectIds +from tmtc_core.core.tmtcc_object_id_manager import get_object_id class ACUTestProcedure: @@ -54,7 +56,8 @@ def pack_acu_test_into(object_id: bytearray, tc_queue: TcQueueT) -> TcQueueT: tc_queue.appendleft(("print", "Testing ACU")) tc_queue.appendleft(("print", "P60 Dock: Enabling ACU connected to X1 slot (channel 0)")) - command = pack_set_param_command(g.P60DOCK_HANDLER_ID, P60DockConfigTable.out_en_0.parameter_address, + p60dock_object_id = get_object_id(ObjectIds.P60DOCK_HANDLER_ID) + command = pack_set_param_command(p60dock_object_id, P60DockConfigTable.out_en_0.parameter_address, P60DockConfigTable.out_en_0.parameter_size, Channel.on) command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) tc_queue.appendleft(command.pack_command_tuple()) @@ -113,7 +116,7 @@ def pack_acu_test_into(object_id: bytearray, tc_queue: TcQueueT) -> TcQueueT: tc_queue.appendleft(command.pack_command_tuple()) tc_queue.appendleft(("print", "P60 Dock: Turning off ACU")) - command = pack_set_param_command(g.P60DOCK_HANDLER_ID, P60DockConfigTable.out_en_0.parameter_address, + command = pack_set_param_command(p60dock_object_id, P60DockConfigTable.out_en_0.parameter_address, P60DockConfigTable.out_en_0.parameter_size, Channel.off) command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) tc_queue.appendleft(command.pack_command_tuple()) diff --git a/pus_tc/tmtcc_tc_packer_hook.py b/pus_tc/tmtcc_tc_packer_hook.py index 5500572..2fced67 100644 --- a/pus_tc/tmtcc_tc_packer_hook.py +++ b/pus_tc/tmtcc_tc_packer_hook.py @@ -19,6 +19,7 @@ from pus_tc.tmtcc_tc_pdu1 import pack_pdu1_test_into from pus_tc.tmtcc_tc_acu import pack_acu_test_into from tmtc_core.core.tmtcc_object_id_manager import get_object_id from config.tmtcc_object_ids import ObjectIds +from pus_tc.tmtcc_tc_tmp1075 import pack_tmp1075_test_into LOGGER = get_logger() @@ -40,6 +41,9 @@ def pack_service_queue_user(service: Union[int, str], op_code: int, service_queu if service == ServiceList.ACU: object_id = get_object_id(ObjectIds.ACU_HANDLER_ID) return pack_acu_test_into(object_id, service_queue) + if service == ServiceList.TMP1075: + object_id = get_object_id(ObjectIds.TMP1075_1_HANDLER_ID) + return pack_tmp1075_test_into(object_id, service_queue) LOGGER.warning("Invalid Service !") diff --git a/pus_tc/tmtcc_tc_service200_mode.py b/pus_tc/tmtcc_tc_service200_mode.py new file mode 100644 index 0000000..2f0641a --- /dev/null +++ b/pus_tc/tmtcc_tc_service200_mode.py @@ -0,0 +1,52 @@ +# -*- coding: utf-8 -*- +""" +@file tmtcc_tc_service200_mode.py +@brief PUS Service 200: PUS custom service 200: Mode commanding +@author R. Mueller +@date 02.05.2020 +""" +from tmtc_core.pus_tc.tmtcc_pus_tc_base import PusTelecommand +from tmtc_core.pus_tc.tmtcc_pus_tc_packer import TcQueueT +from tmtc_core.core.tmtcc_object_id_manager import get_object_id +from config.tmtcc_object_ids import ObjectIds +import struct + +TEST_DEVICE_ID = get_object_id(ObjectIds.TEST_DEVICE) + + +def pack_service200_test_into(tc_queue: TcQueueT) -> TcQueueT: + tc_queue.appendleft(("print", "Testing Service 200")) + # Object ID: Dummy Device + object_id = TEST_DEVICE_ID + # Set On Mode + tc_queue.appendleft(("print", "Testing Service 200: Set Mode On")) + mode_data = pack_mode_data(object_id, 1, 0) + command = PusTelecommand(service=200, subservice=1, ssc=2000, app_data=mode_data) + tc_queue.appendleft(command.pack_command_tuple()) + # Set Normal mode + tc_queue.appendleft(("print", "Testing Service 200: Set Mode Normal")) + mode_data = pack_mode_data(object_id, 2, 0) + command = PusTelecommand(service=200, subservice=1, ssc=2010, app_data=mode_data) + tc_queue.appendleft(command.pack_command_tuple()) + # Set Raw Mode + tc_queue.appendleft(("print", "Testing Service 200: Set Mode Raw")) + mode_data = pack_mode_data(object_id, 3, 0) + command = PusTelecommand(service=200, subservice=1, ssc=2020, app_data=mode_data) + tc_queue.appendleft(command.pack_command_tuple()) + # Set Off Mode + tc_queue.appendleft(("print", "Testing Service 200: Set Mode Off")) + mode_data = pack_mode_data(object_id, 0, 0) + command = PusTelecommand(service=200, subservice=1, ssc=2030, app_data=mode_data) + tc_queue.appendleft(command.pack_command_tuple()) + tc_queue.appendleft(("export", "log/tmtc_log_service200.txt")) + return tc_queue + + +# Mode 0: Off, Mode 1: Mode On, Mode 2: Mode Normal, Mode 3: Mode Raw +def pack_mode_data(object_id: bytearray, mode_: int, submode_: int) -> bytearray: + # Normal mode + mode = struct.pack(">I", mode_) + # Submode default + submode = struct.pack('B', submode_) + mode_data = object_id + mode + submode + return mode_data diff --git a/pus_tc/tmtcc_tc_tmp1075.py b/pus_tc/tmtcc_tc_tmp1075.py new file mode 100644 index 0000000..53d1c1b --- /dev/null +++ b/pus_tc/tmtcc_tc_tmp1075.py @@ -0,0 +1,59 @@ +# -*- coding: utf-8 -*- +""" +@file tmtcc_tc_tmp1075.py +@brief TMP1075 tests +@author J. Meier +@date 06.01.2021 +""" + +from tmtc_core.pus_tc.tmtcc_pus_tc_packer import TcQueueT +from tmtc_core.pus_tc.tmtcc_pus_tc_base import PusTelecommand +from pus_tc.tmtcc_tc_service200_mode import pack_mode_data + + +class Tmp1075TestProcedure: + """ + @brief Use this class to define the tests to perform for the Tmp1075. + @details Setting all to True will run all tests. + Setting all to False will only run the tests set to True. + """ + all = True + start_adc_conversion = False + get_temp = False + set_mode_normal = False # Setting mode to normal starts continuous temperature reading + set_mode_on = False # If mode is MODE_ON, temperature will only be read on command + + +class Tmp1075ActionIds: + get_temp = bytearray([0x0, 0x0, 0x0, 0x01]) + start_adc_conversion = bytearray([0x0, 0x0, 0x0, 0x02]) + + +def pack_tmp1075_test_into(object_id: bytearray, tc_queue: TcQueueT) -> TcQueueT: + tc_queue.appendleft(("print", "Testing Tmp1075 Temperature Sensor Handler")) + + if Tmp1075TestProcedure.all or Tmp1075TestProcedure.start_adc_conversion: + tc_queue.appendleft(("print", "TMP1075: Starting new temperature conversion")) + command = object_id + Tmp1075ActionIds.start_adc_conversion + command = PusTelecommand(service=8, subservice=128, ssc=23, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + + if Tmp1075TestProcedure.all or Tmp1075TestProcedure.get_temp: + tc_queue.appendleft(("print", "TMP1075: Read temperature")) + command = object_id + Tmp1075ActionIds.get_temp + command = PusTelecommand(service=8, subservice=128, ssc=24, app_data=command) + tc_queue.appendleft(command.pack_command_tuple()) + + if Tmp1075TestProcedure.set_mode_normal: + tc_queue.appendleft(("print", "TMP1075:: Set Mode Normal")) + mode_data = pack_mode_data(object_id, 2, 0) + command = PusTelecommand(service=200, subservice=1, ssc=220, app_data=mode_data) + tc_queue.appendleft(command.pack_command_tuple()) + + if Tmp1075TestProcedure.set_mode_on: + tc_queue.appendleft(("print", "TMP1075: Set Mode On")) + mode_data = pack_mode_data(object_id, 1, 0) + command = PusTelecommand(service=200, subservice=1, ssc=221, app_data=mode_data) + tc_queue.appendleft(command.pack_command_tuple()) + + return tc_queue diff --git a/tmtc_core b/tmtc_core index ed4b25a..bdb8d55 160000 --- a/tmtc_core +++ b/tmtc_core @@ -1 +1 @@ -Subproject commit ed4b25ab449cae31ac720f52ad43d13b9d7ce4c5 +Subproject commit bdb8d5533a40c8396dedafc1844fe3645bcf8de3