From 492d364246b3417ce3815dc58b405f493e77b9f7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Apr 2024 11:35:05 +0200 Subject: [PATCH 1/6] relative timeshift --- eive_tmtc/tmtc/time.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/eive_tmtc/tmtc/time.py b/eive_tmtc/tmtc/time.py index 1e7fdc7..c8f79a1 100644 --- a/eive_tmtc/tmtc/time.py +++ b/eive_tmtc/tmtc/time.py @@ -1,6 +1,7 @@ import enum +import struct import logging -from datetime import datetime +import datetime from spacepackets.ecss import PusTelecommand, PusService @@ -8,26 +9,31 @@ from tmtccmd.tmtc import DefaultPusQueueHelper from tmtccmd.config import CmdTreeNode +_LOGGER = logging.getLogger(__name__) + class Subservice(enum.IntEnum): SET_TIME = 128 DUMP_TIME = 129 + RELATIVE_TIMESHIFT = 130 class CmdStr: SET_CURRENT_TIME = "set_curr_time" + RELATIVE_TIMESHIFT = "relative_timeshift" DUMP_TIME = "dump_time" class Info: SET_CURRENT_TIME = "Setting current time in ASCII format" + RELATIVE_TIMESHIFT = "Shift time with a relative offset" DUMP_TIME = "Dump system time as event" def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str): if cmd_str == CmdStr.SET_CURRENT_TIME: - current_time = datetime.utcnow().isoformat() + "Z" + "\0" + current_time = datetime.datetime.now(datetime.UTC).isoformat() + "Z" + "\0" current_time_ascii = current_time.encode("ascii") - logging.getLogger(__name__).info( + _LOGGER.info( f"Current time in ASCII format: {current_time_ascii}" ) q.add_log_cmd(Info.SET_CURRENT_TIME) @@ -38,6 +44,17 @@ def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str): app_data=current_time_ascii, ) ) + elif cmd_str == CmdStr.RELATIVE_TIMESHIFT: + nanos = input("Specify relative timeshift in nanoseconds") + nanos_packed = struct.pack("!Q", nanos) + q.add_log_cmd(Info.RELATIVE_TIMESHIFT) + q.add_pus_tc( + PusTelecommand( + service=PusService.S9_TIME_MGMT, + subservice=Subservice.RELATIVE_TIMESHIFT, + app_data=nanos_packed + ) + ) elif cmd_str == CmdStr.DUMP_TIME: q.add_log_cmd(Info.DUMP_TIME) q.add_pus_tc( @@ -51,4 +68,5 @@ def create_time_node() -> CmdTreeNode: time_node = CmdTreeNode("time", "Time Management") time_node.add_child(CmdTreeNode(CmdStr.SET_CURRENT_TIME, "Set current time")) time_node.add_child(CmdTreeNode(CmdStr.DUMP_TIME, "Dumpy current time")) + time_node.add_child(CmdTreeNode(CmdStr.RELATIVE_TIMESHIFT,Info.RELATIVE_TIMESHIFT)) return time_node From d182a9d5ec51ea069c78d728c759b53ded8bb222 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Apr 2024 13:24:40 +0200 Subject: [PATCH 2/6] re-run black --- eive_tmtc/config/custom_mode_op.py | 1 + eive_tmtc/config/object_ids.py | 1 + eive_tmtc/pus_tc/cmd_demux.py | 1 + eive_tmtc/pus_tm/event_handler.py | 4 ++-- eive_tmtc/pus_tm/hk_handler.py | 1 + eive_tmtc/pus_tm/pus_handler.py | 1 + eive_tmtc/tmtc/time.py | 17 +++++++++-------- 7 files changed, 16 insertions(+), 10 deletions(-) diff --git a/eive_tmtc/config/custom_mode_op.py b/eive_tmtc/config/custom_mode_op.py index 7981371..6143aaa 100644 --- a/eive_tmtc/config/custom_mode_op.py +++ b/eive_tmtc/config/custom_mode_op.py @@ -3,6 +3,7 @@ @details Template configuration file. Copy this folder to the TMTC commander root and adapt it to your needs. """ + import enum from tmtccmd import CcsdsTmtcBackend diff --git a/eive_tmtc/config/object_ids.py b/eive_tmtc/config/object_ids.py index cb81d07..3d1c1c5 100644 --- a/eive_tmtc/config/object_ids.py +++ b/eive_tmtc/config/object_ids.py @@ -3,6 +3,7 @@ @details Template configuration file. Copy this folder to the TMTC commander root and adapt it to your needs. """ + import logging import os.path from typing import Dict diff --git a/eive_tmtc/pus_tc/cmd_demux.py b/eive_tmtc/pus_tc/cmd_demux.py index 0f0f5ec..33e5548 100644 --- a/eive_tmtc/pus_tc/cmd_demux.py +++ b/eive_tmtc/pus_tc/cmd_demux.py @@ -1,5 +1,6 @@ """Hook function which packs telecommands based on service and operation code string """ + import logging from typing import List, cast diff --git a/eive_tmtc/pus_tm/event_handler.py b/eive_tmtc/pus_tm/event_handler.py index 496c28b..8dc5a31 100644 --- a/eive_tmtc/pus_tm/event_handler.py +++ b/eive_tmtc/pus_tm/event_handler.py @@ -124,8 +124,8 @@ def handle_event_packet( # noqa C901: Complexity okay here pw.dlog(f"New time (UTC): {new_time_dt}") if info.name == "CLOCK_DUMP": specific_handler = True - # param 1 is timeval seconds, param 2 is timeval subsecond milliseconds - time = event_def.param1 + event_def.param2 / 1000.0 + # param 1 is timeval seconds, param 2 is timeval subsecond microseconds + time = event_def.param1 + event_def.param2 / 1000000.0 time_dt = datetime.datetime.fromtimestamp(time, datetime.timezone.utc) pw.dlog(f"Current time: {time_dt}") if info.name == "ACTIVE_SD_INFO": diff --git a/eive_tmtc/pus_tm/hk_handler.py b/eive_tmtc/pus_tm/hk_handler.py index 56c53af..bee9f23 100644 --- a/eive_tmtc/pus_tm/hk_handler.py +++ b/eive_tmtc/pus_tm/hk_handler.py @@ -1,4 +1,5 @@ """HK Handling for EIVE OBSW""" + import dataclasses import logging import base64 # noqa diff --git a/eive_tmtc/pus_tm/pus_handler.py b/eive_tmtc/pus_tm/pus_handler.py index f3e62d1..7767b7f 100644 --- a/eive_tmtc/pus_tm/pus_handler.py +++ b/eive_tmtc/pus_tm/pus_handler.py @@ -1,5 +1,6 @@ """Core EIVE TM handler module """ + import logging import sqlite3 import uuid diff --git a/eive_tmtc/tmtc/time.py b/eive_tmtc/tmtc/time.py index c8f79a1..97413c5 100644 --- a/eive_tmtc/tmtc/time.py +++ b/eive_tmtc/tmtc/time.py @@ -11,6 +11,7 @@ from tmtccmd.config import CmdTreeNode _LOGGER = logging.getLogger(__name__) + class Subservice(enum.IntEnum): SET_TIME = 128 DUMP_TIME = 129 @@ -31,11 +32,11 @@ class Info: def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str): if cmd_str == CmdStr.SET_CURRENT_TIME: - current_time = datetime.datetime.now(datetime.UTC).isoformat() + "Z" + "\0" - current_time_ascii = current_time.encode("ascii") - _LOGGER.info( - f"Current time in ASCII format: {current_time_ascii}" + current_time = ( + datetime.datetime.now(datetime.timezone.utc).isoformat() + "Z" + "\0" ) + current_time_ascii = current_time.encode("ascii") + _LOGGER.info(f"Current time in ASCII format: {current_time_ascii}") q.add_log_cmd(Info.SET_CURRENT_TIME) q.add_pus_tc( PusTelecommand( @@ -45,14 +46,14 @@ def pack_time_management_cmd(q: DefaultPusQueueHelper, cmd_str: str): ) ) elif cmd_str == CmdStr.RELATIVE_TIMESHIFT: - nanos = input("Specify relative timeshift in nanoseconds") - nanos_packed = struct.pack("!Q", nanos) + nanos = int(input("Specify relative timeshift in nanoseconds: ")) + nanos_packed = struct.pack("!q", nanos) q.add_log_cmd(Info.RELATIVE_TIMESHIFT) q.add_pus_tc( PusTelecommand( service=PusService.S9_TIME_MGMT, subservice=Subservice.RELATIVE_TIMESHIFT, - app_data=nanos_packed + app_data=nanos_packed, ) ) elif cmd_str == CmdStr.DUMP_TIME: @@ -68,5 +69,5 @@ def create_time_node() -> CmdTreeNode: time_node = CmdTreeNode("time", "Time Management") time_node.add_child(CmdTreeNode(CmdStr.SET_CURRENT_TIME, "Set current time")) time_node.add_child(CmdTreeNode(CmdStr.DUMP_TIME, "Dumpy current time")) - time_node.add_child(CmdTreeNode(CmdStr.RELATIVE_TIMESHIFT,Info.RELATIVE_TIMESHIFT)) + time_node.add_child(CmdTreeNode(CmdStr.RELATIVE_TIMESHIFT, Info.RELATIVE_TIMESHIFT)) return time_node From de84bf112b74347e2022e3850b60ca73cb1d8ce9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Apr 2024 13:25:45 +0200 Subject: [PATCH 3/6] changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57eb6b9..2142692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,8 @@ list yields a list of all related PRs for each release. ## Added -- Added version set for STR +- Added version set for STR. +- Command for relative timeshift. ## Fixed From 3ae6ccfb7775dc091a63fad6b3e040ce6bd501a8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Apr 2024 13:35:06 +0200 Subject: [PATCH 4/6] this should do the job --- eive_tmtc/pus_tm/event_handler.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eive_tmtc/pus_tm/event_handler.py b/eive_tmtc/pus_tm/event_handler.py index 8dc5a31..e5cfc35 100644 --- a/eive_tmtc/pus_tm/event_handler.py +++ b/eive_tmtc/pus_tm/event_handler.py @@ -122,6 +122,12 @@ def handle_event_packet( # noqa C901: Complexity okay here new_time_dt = datetime.datetime.fromtimestamp(new_time, datetime.timezone.utc) pw.dlog(f"Old time (UTC): {old_time_dt}") pw.dlog(f"New time (UTC): {new_time_dt}") + if info.name == "CLOCK_DUMP_LEGACY": + specific_handler = True + # param 1 is timeval seconds, param 2 is timeval subsecond milliseconds + time = event_def.param1 + event_def.param2 / 1000.0 + time_dt = datetime.datetime.fromtimestamp(time, datetime.timezone.utc) + pw.dlog(f"Current time: {time_dt}") if info.name == "CLOCK_DUMP": specific_handler = True # param 1 is timeval seconds, param 2 is timeval subsecond microseconds From 5bdba2dbad71b94a7b9c9240793eae40dda08de2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Apr 2024 13:35:34 +0200 Subject: [PATCH 5/6] update events --- eive_tmtc/config/events.csv | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/eive_tmtc/config/events.csv b/eive_tmtc/config/events.csv index 200cbdb..1a30260 100644 --- a/eive_tmtc/config/events.csv +++ b/eive_tmtc/config/events.csv @@ -76,8 +76,9 @@ Event ID (dec); Event ID (hex); Name; Severity; Description; File Path 7903;0x1edf;BIT_LOCK_LOST;INFO;A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0;fsfw/src/fsfw/datalinklayer/DataLinkLayer.h 7905;0x1ee1;FRAME_PROCESSING_FAILED;LOW;The CCSDS Board could not interpret a TC;fsfw/src/fsfw/datalinklayer/DataLinkLayer.h 8900;0x22c4;CLOCK_SET;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h -8901;0x22c5;CLOCK_DUMP;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h +8901;0x22c5;CLOCK_DUMP_LEGACY;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h 8902;0x22c6;CLOCK_SET_FAILURE;LOW;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h +8903;0x22c7;CLOCK_DUMP;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h 9100;0x238c;TC_DELETION_FAILED;MEDIUM;Deletion of a TC from the map failed. P1: First 32 bit of request ID, P2. Last 32 bit of Request ID;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h 9700;0x25e4;TEST;INFO;No description;fsfw/src/fsfw/pus/Service17Test.h 10600;0x2968;CHANGE_OF_SETUP_PARAMETER;LOW;No description;fsfw/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h From 5a0edbefa8449f4796d7d0976822c8fda139c598 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 8 Apr 2024 13:38:28 +0200 Subject: [PATCH 6/6] fix comment block --- eive_tmtc/config/events.csv | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/eive_tmtc/config/events.csv b/eive_tmtc/config/events.csv index 1a30260..34aa934 100644 --- a/eive_tmtc/config/events.csv +++ b/eive_tmtc/config/events.csv @@ -75,10 +75,10 @@ Event ID (dec); Event ID (hex); Name; Severity; Description; File Path 7902;0x1ede;BIT_LOCK;INFO;A Bit Lock signal. Was detected. P1: raw BLO state, P2: 0;fsfw/src/fsfw/datalinklayer/DataLinkLayer.h 7903;0x1edf;BIT_LOCK_LOST;INFO;A previously found Bit Lock signal was lost. P1: raw BLO state, P2: 0;fsfw/src/fsfw/datalinklayer/DataLinkLayer.h 7905;0x1ee1;FRAME_PROCESSING_FAILED;LOW;The CCSDS Board could not interpret a TC;fsfw/src/fsfw/datalinklayer/DataLinkLayer.h -8900;0x22c4;CLOCK_SET;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h -8901;0x22c5;CLOCK_DUMP_LEGACY;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h -8902;0x22c6;CLOCK_SET_FAILURE;LOW;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h -8903;0x22c7;CLOCK_DUMP;INFO;No description;fsfw/src/fsfw/pus/Service9TimeManagement.h +8900;0x22c4;CLOCK_SET;INFO;Clock has been set. P1: old timeval seconds. P2: new timeval seconds.;fsfw/src/fsfw/pus/Service9TimeManagement.h +8901;0x22c5;CLOCK_DUMP_LEGACY;INFO;Clock dump event. P1: timeval seconds P2: timeval milliseconds.;fsfw/src/fsfw/pus/Service9TimeManagement.h +8902;0x22c6;CLOCK_SET_FAILURE;LOW;Clock could not be set. P1: Returncode.;fsfw/src/fsfw/pus/Service9TimeManagement.h +8903;0x22c7;CLOCK_DUMP;INFO;Clock dump event. P1: timeval seconds P2: timeval microseconds.;fsfw/src/fsfw/pus/Service9TimeManagement.h 9100;0x238c;TC_DELETION_FAILED;MEDIUM;Deletion of a TC from the map failed. P1: First 32 bit of request ID, P2. Last 32 bit of Request ID;fsfw/src/fsfw/pus/Service11TelecommandScheduling.h 9700;0x25e4;TEST;INFO;No description;fsfw/src/fsfw/pus/Service17Test.h 10600;0x2968;CHANGE_OF_SETUP_PARAMETER;LOW;No description;fsfw/src/fsfw_hal/devicehandlers/MgmLIS3MDLHandler.h