From d2144aab26b2d9e1c0fad8400f342f9d6b7bf700 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 11:19:23 +0200 Subject: [PATCH 01/40] add code to send mgm data --- deps/tmtccmd | 2 +- pus_tc/system/__init__.py | 2 +- pus_tm/hk_handling.py | 2 +- tmtc/__init__.py | 0 {pus_tc/system => tmtc}/acs_ctrl.py | 48 +++++++++++++++++++++++++++-- tmtcc.py | 2 +- 6 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 tmtc/__init__.py rename {pus_tc/system => tmtc}/acs_ctrl.py (71%) diff --git a/deps/tmtccmd b/deps/tmtccmd index 403c5fd..d042315 160000 --- a/deps/tmtccmd +++ b/deps/tmtccmd @@ -1 +1 @@ -Subproject commit 403c5fd2b1cd28af8de2b39f308b633892e660e5 +Subproject commit d042315e4cc0b5d0b13ceaaf5e3f36e8ad455740 diff --git a/pus_tc/system/__init__.py b/pus_tc/system/__init__.py index 80c3a56..8b13789 100644 --- a/pus_tc/system/__init__.py +++ b/pus_tc/system/__init__.py @@ -1 +1 @@ -from . import acs_ctrl + diff --git a/pus_tm/hk_handling.py b/pus_tm/hk_handling.py index 8a7e022..8eabcb7 100644 --- a/pus_tm/hk_handling.py +++ b/pus_tm/hk_handling.py @@ -1,5 +1,5 @@ """HK Handling for EIVE OBSW""" -from pus_tc.system.acs_ctrl import handle_acs_ctrl_mgm_data +from tmtc.acs_ctrl import handle_acs_ctrl_mgm_data from pus_tm.devs.plpcdu import handle_plpcdu_hk from pus_tm.devs.rad_sensor import handle_rad_sensor_data from pus_tm.devs.sus import handle_sus_hk diff --git a/tmtc/__init__.py b/tmtc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pus_tc/system/acs_ctrl.py b/tmtc/acs_ctrl.py similarity index 71% rename from pus_tc/system/acs_ctrl.py rename to tmtc/acs_ctrl.py index 35ef21b..e794461 100644 --- a/pus_tc/system/acs_ctrl.py +++ b/tmtc/acs_ctrl.py @@ -1,5 +1,8 @@ import enum +import socket import struct +from socket import AF_INET +from typing import Tuple from config.definitions import CustomServiceList from config.object_ids import ACS_CONTROLLER @@ -11,8 +14,12 @@ from tmtccmd.config.tmtc import ( OpCodeEntry, ) from tmtccmd.tc import DefaultPusQueueHelper, service_provider -from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid, \ - enable_periodic_hk_command_with_interval, disable_periodic_hk_command +from tmtccmd.tc.pus_3_fsfw_hk import ( + generate_one_hk_command, + make_sid, + enable_periodic_hk_command_with_interval, + disable_periodic_hk_command, +) from tmtccmd.util.tmtc_printer import FsfwTmTcPrinter LOGGER = get_console_logger() @@ -34,6 +41,12 @@ class Info: DISABLE_MGM_HK = "Disable MGM HK data generation" +PERFORM_MGM_CALIBRATION = False +CALIBRATION_SOCKET_HOST = "localhost" +CALIBRATION_SOCKET_PORT = 6677 +CALIBRATION_ADDR = (CALIBRATION_SOCKET_HOST, CALIBRATION_SOCKET_PORT) + + @tmtc_definitions_provider def acs_cmd_defs(defs: TmtcDefinitionWrapper): oce = OpCodeEntry() @@ -122,4 +135,35 @@ def handle_acs_ctrl_mgm_data(printer: FsfwTmTcPrinter, hk_data: bytes): for entry in zip(print_str_list, formatted_list): pw.dlog(f"{entry[0].ljust(28)}: {entry[1]}") current_idx += 1 + if PERFORM_MGM_CALIBRATION: + perform_mgm_calibration(pw, mgm_0_lis3_floats_ut) assert current_idx == 61 + + +def perform_mgm_calibration(pw: PrintWrapper, mgm_tuple: Tuple): + calibr_socket = socket.socket(AF_INET, socket.SOCK_STREAM) + try: + declare_api_cmd = "declare_api_version 2" + calibr_socket.connect(CALIBRATION_ADDR) + calibr_socket.sendall(f"{declare_api_cmd}\n".encode()) + calibr_socket.settimeout(0.2) + calibr_socket.setblocking(False) + reply = calibr_socket.recv(1024) + pw.dlog( + f"Received reply {reply} from Helmholtz Socket for command {declare_api_cmd}" + ) + if len(mgm_tuple) != 3: + pw.dlog(f"MGM tuple has invalid length {len(mgm_tuple)}") + mgm_list = [mgm / 10e6 for mgm in mgm_tuple] + command = ( + f"magnetometer_field {mgm_list[0]} {mgm_list[1]} {mgm_list[2]}\n".encode() + ) + calibr_socket.sendall(command) + reply = calibr_socket.recv(1024) + pw.dlog( + f"Received reply {reply} from Helmholtz Socket for command magnetometer_field" + ) + except socket.timeout: + pw.dlog("Socket timeout") + except ConnectionRefusedError or OSError: + pw.dlog("Connecting to Calibration Socket on addrss {} failed") diff --git a/tmtcc.py b/tmtcc.py index d346fe9..934837e 100755 --- a/tmtcc.py +++ b/tmtcc.py @@ -205,7 +205,7 @@ def main(): printer = FsfwTmTcPrinter(tmtc_logger.logger) raw_logger = RawTmtcTimedLogWrapper( when=ROTATING_TIMED_LOGGER_INTERVAL_WHEN, - interval=ROTATING_TIMED_LOGGER_INTERVAL + interval=ROTATING_TIMED_LOGGER_INTERVAL, ) pus_verificator = PusVerificator() ccsds_handler, tc_handler = setup_tmtc( From 7c84f4983066adcd7d6e6905b8914be008cce6be Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Wed, 17 Aug 2022 15:24:39 +0200 Subject: [PATCH 02/40] mgm calib fixes --- tmtc/acs_ctrl.py | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tmtc/acs_ctrl.py b/tmtc/acs_ctrl.py index e794461..22b8113 100644 --- a/tmtc/acs_ctrl.py +++ b/tmtc/acs_ctrl.py @@ -2,7 +2,7 @@ import enum import socket import struct from socket import AF_INET -from typing import Tuple +from typing import Tuple, Optional from config.definitions import CustomServiceList from config.object_ids import ACS_CONTROLLER @@ -41,11 +41,17 @@ class Info: DISABLE_MGM_HK = "Disable MGM HK data generation" -PERFORM_MGM_CALIBRATION = False +PERFORM_MGM_CALIBRATION = True CALIBRATION_SOCKET_HOST = "localhost" CALIBRATION_SOCKET_PORT = 6677 CALIBRATION_ADDR = (CALIBRATION_SOCKET_HOST, CALIBRATION_SOCKET_PORT) +if PERFORM_MGM_CALIBRATION: + CALIBR_SOCKET = socket.socket(AF_INET, socket.SOCK_STREAM) + CALIBR_SOCKET.setblocking(False) + CALIBR_SOCKET.settimeout(0.2) + CALIBR_SOCKET.connect(CALIBRATION_ADDR) + @tmtc_definitions_provider def acs_cmd_defs(defs: TmtcDefinitionWrapper): @@ -141,29 +147,39 @@ def handle_acs_ctrl_mgm_data(printer: FsfwTmTcPrinter, hk_data: bytes): def perform_mgm_calibration(pw: PrintWrapper, mgm_tuple: Tuple): - calibr_socket = socket.socket(AF_INET, socket.SOCK_STREAM) + global CALIBR_SOCKET, CALIBRATION_ADDR try: declare_api_cmd = "declare_api_version 2" - calibr_socket.connect(CALIBRATION_ADDR) - calibr_socket.sendall(f"{declare_api_cmd}\n".encode()) - calibr_socket.settimeout(0.2) - calibr_socket.setblocking(False) - reply = calibr_socket.recv(1024) - pw.dlog( - f"Received reply {reply} from Helmholtz Socket for command {declare_api_cmd}" - ) + CALIBR_SOCKET.sendall(f"{declare_api_cmd}\n".encode()) + reply = CALIBR_SOCKET.recv(1024) + if len(reply) != 2: + pw.dlog(f"MGM calibration: Reply received command {declare_api_cmd} has invalid length {len(reply)}") + return + else: + if str(reply[0]) == "0": + pw.dlog(f"MGM calibration: API version 2 was not accepted") + return if len(mgm_tuple) != 3: pw.dlog(f"MGM tuple has invalid length {len(mgm_tuple)}") mgm_list = [mgm / 10e6 for mgm in mgm_tuple] command = ( f"magnetometer_field {mgm_list[0]} {mgm_list[1]} {mgm_list[2]}\n".encode() ) - calibr_socket.sendall(command) - reply = calibr_socket.recv(1024) - pw.dlog( - f"Received reply {reply} from Helmholtz Socket for command magnetometer_field" - ) + CALIBR_SOCKET.sendall(command) + reply = CALIBR_SOCKET.recv(1024) + if len(reply) != 2: + pw.dlog(f"MGM calibration: Reply received command magnetometer_field has invalid length {len(reply)}") + return + else: + if str(reply[0]) == "0": + pw.dlog(f"MGM calibration: magnetmeter field format was not accepted") + return + pw.dlog(f"Sent data {mgm_list} to Helmholtz Testbench successfully") except socket.timeout: pw.dlog("Socket timeout") + except BlockingIOError as e: + pw.dlog(f"Error {e}") + except ConnectionResetError as e: + pw.dlog("Socket was closed") except ConnectionRefusedError or OSError: pw.dlog("Connecting to Calibration Socket on addrss {} failed") From 75c28cc7e5ab4ee8d51f568485a4845bf8efc7cb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 17 Aug 2022 17:25:16 +0200 Subject: [PATCH 03/40] small bugfix --- tmtc/acs_ctrl.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtc/acs_ctrl.py b/tmtc/acs_ctrl.py index e794461..e0b108b 100644 --- a/tmtc/acs_ctrl.py +++ b/tmtc/acs_ctrl.py @@ -154,7 +154,7 @@ def perform_mgm_calibration(pw: PrintWrapper, mgm_tuple: Tuple): ) if len(mgm_tuple) != 3: pw.dlog(f"MGM tuple has invalid length {len(mgm_tuple)}") - mgm_list = [mgm / 10e6 for mgm in mgm_tuple] + mgm_list = [mgm / 1e6 for mgm in mgm_tuple] command = ( f"magnetometer_field {mgm_list[0]} {mgm_list[1]} {mgm_list[2]}\n".encode() ) From 2d2702381abf4ce50b524bb329b638bc54e2721b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 18 Aug 2022 11:09:35 +0200 Subject: [PATCH 04/40] update tmtc --- .run/Ping Command.run.xml | 2 +- ...un.xml => Test Service w Listener.run.xml} | 4 +-- ...ervice 17.run.xml => Test Service.run.xml} | 4 +-- config/definitions.py | 4 ++- deps/tmtccmd | 2 +- pus_tc/cmd_definitions.py | 16 +++++++++- pus_tc/devs/__init__.py | 1 + pus_tc/devs/common_power.py | 19 ----------- pus_tc/devs/power.py | 32 +++++++++++++++++-- pus_tc/procedure_packer.py | 10 ++++-- tmtc/acs_ctrl.py | 10 ++++-- 11 files changed, 69 insertions(+), 35 deletions(-) rename .run/{tmtcc_Service_17.run.xml => Test Service w Listener.run.xml} (82%) rename .run/{Service 17.run.xml => Test Service.run.xml} (83%) diff --git a/.run/Ping Command.run.xml b/.run/Ping Command.run.xml index 6cd3521..7c81b41 100644 --- a/.run/Ping Command.run.xml +++ b/.run/Ping Command.run.xml @@ -13,7 +13,7 @@