diff --git a/satrs-example/pyclient/main.py b/satrs-example/pyclient/main.py index 03ef60e..be63b2b 100755 --- a/satrs-example/pyclient/main.py +++ b/satrs-example/pyclient/main.py @@ -1,5 +1,7 @@ #!/usr/bin/env python3 """Example client for the sat-rs example application""" +import enum +import struct import sys import time from typing import Optional @@ -8,9 +10,9 @@ import tmtccmd from spacepackets.ecss import PusTelemetry, PusTelecommand, PusVerificator from spacepackets.ecss.pus_17_test import Service17Tm from spacepackets.ecss.pus_1_verification import UnpackParams, Service1Tm -from spacepackets.util import UnsignedByteField from tmtccmd import CcsdsTmtcBackend, TcHandlerBase, ProcedureParamsWrapper +from tmtccmd.tc.pus_3_fsfw_hk import generate_one_hk_command, make_sid from tmtccmd.core.base import BackendRequest from tmtccmd.pus import VerificationWrapper from tmtccmd.tm import CcsdsTmHandler, SpecificApidHandlerBase @@ -85,6 +87,13 @@ class SatRsConfigHook(TmTcCfgHookBase): info="PUS Service 17 Test", op_code_entry=srv_17, ) + srv_3 = OpCodeEntry() + srv_3.add(HkOpCodes.GENERATE_ONE_SHOT, "Generate AOCS one shot HK") + defs.add_service( + name=CoreServiceList.SERVICE_3, + info="PUS Service 3 Housekeeping", + op_code_entry=srv_3 + ) return defs def perform_mode_operation(self, tmtc_backend: CcsdsTmtcBackend, mode: int): @@ -158,6 +167,24 @@ class PusHandler(SpecificApidHandlerBase): self.printer.handle_long_tm_print(packet_if=tm_packet, info_if=tm_packet) +def make_addressable_id(target_id: int, unique_id: int) -> bytes: + byte_string = bytearray(struct.pack("!I", target_id)) + byte_string.extend(struct.pack("!I", unique_id)) + return byte_string + + +class RequestTargetId(enum.IntEnum): + ACS = 1 + + +class AcsHkIds(enum.IntEnum): + MGM_SET = 1 + + +class HkOpCodes: + GENERATE_ONE_SHOT = ["0", "oneshot"] + + class TcHandler(TcHandlerBase): def __init__( self, @@ -197,17 +224,27 @@ class TcHandler(TcHandlerBase): ) def feed_cb(self, helper: ProcedureWrapper, wrapper: FeedWrapper): - self.queue_helper.queue_wrapper = wrapper.queue_wrapper + q = self.queue_helper + q.queue_wrapper = wrapper.queue_wrapper if helper.proc_type == TcProcedureType.DEFAULT: def_proc = helper.to_def_procedure() service = def_proc.service + op_code = def_proc.op_code if ( service == CoreServiceList.SERVICE_17 or service == CoreServiceList.SERVICE_17_ALT ): - return self.queue_helper.add_pus_tc( + q.add_log_cmd("Sending PUS ping telecommand") + return q.add_pus_tc( PusTelecommand(service=17, subservice=1) ) + if service == CoreServiceList.SERVICE_3: + if op_code in HkOpCodes.GENERATE_ONE_SHOT: + q.add_log_cmd("Sending HK one shot request") + q.add_pus_tc( + generate_one_hk_command(make_addressable_id(RequestTargetId.ACS, AcsHkIds.MGM_SET)) + ) + pass def main(): diff --git a/satrs-example/src/lib.rs b/satrs-example/src/lib.rs index b36a457..83a095b 100644 --- a/satrs-example/src/lib.rs +++ b/satrs-example/src/lib.rs @@ -3,6 +3,11 @@ use std::net::Ipv4Addr; use satrs_mib::res_code::{ResultU16, ResultU16Info}; use satrs_mib::resultcode; +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum RequestTargetId { + AcsSubsystem = 1, +} + #[derive(Debug)] pub enum GroupId { Tmtc = 0, diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 193804a..e198af0 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -5,7 +5,7 @@ mod requests; mod tmtc; use crate::requests::Request; -use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, RequestTargetId, TmStore, PUS_APID}; +use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID}; use satrs_core::event_man::{ EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider, }; @@ -22,7 +22,7 @@ use satrs_core::pus::verification::{ use satrs_core::pus::{EcssTmError, EcssTmSender}; use satrs_core::seq_count::SimpleSeqCountProvider; use satrs_core::tmtc::CcsdsError; -use satrs_example::{OBSW_SERVER_ADDR, SERVER_PORT}; +use satrs_example::{OBSW_SERVER_ADDR, RequestTargetId, SERVER_PORT}; use spacepackets::time::cds::TimeProvider; use spacepackets::time::TimeWriter; use spacepackets::tm::PusTm; diff --git a/satrs-example/src/tmtc.rs b/satrs-example/src/tmtc.rs index 5aab261..9cf9a7f 100644 --- a/satrs-example/src/tmtc.rs +++ b/satrs-example/src/tmtc.rs @@ -20,11 +20,6 @@ use spacepackets::tm::PusTm; pub const PUS_APID: u16 = 0x02; -#[derive(Copy, Clone, Eq, PartialEq, Debug)] -pub enum RequestTargetId { - AcsSubsystem = 1, -} - pub struct CoreTmtcArgs { pub tm_store: TmStore, pub tm_sender: Sender,