From 27c1a9850cbd6ed31e2196f4e47d5d7f2638d51a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 22 Dec 2022 09:15:59 +0100 Subject: [PATCH] basic HK reply TM packing and handling --- satrs-example/pyclient/main.py | 9 +++++++++ satrs-example/src/main.rs | 23 ++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/satrs-example/pyclient/main.py b/satrs-example/pyclient/main.py index be63b2b..c06f9ed 100755 --- a/satrs-example/pyclient/main.py +++ b/satrs-example/pyclient/main.py @@ -142,6 +142,15 @@ class PusHandler(SpecificApidHandlerBase): self.verif_wrapper.log_to_console(tm_packet, res) self.verif_wrapper.log_to_file(tm_packet, res) dedicated_handler = True + if service == 3: + LOGGER.info("No handling for HK packets implemented") + LOGGER.info(f"Raw packet: 0x[{packet.hex(sep=',')}]") + pus_tm = PusTelemetry.unpack(packet) + if pus_tm.subservice == 25: + if len(pus_tm.source_data) < 8: + raise ValueError("No addressable ID in HK packet") + json_str = pus_tm.source_data[8:] + dedicated_handler = True if service == 5: tm_packet = Service5Tm.unpack(packet) if service == 17: diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 238c62e..fd3e3bf 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -17,6 +17,7 @@ use satrs_core::pus::event_man::{ DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken, PusEventDispatcher, }; +use satrs_core::pus::hk::Subservice; use satrs_core::pus::verification::{ MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, }; @@ -25,7 +26,8 @@ use satrs_core::seq_count::SimpleSeqCountProvider; use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT}; use spacepackets::time::cds::TimeProvider; use spacepackets::time::TimeWriter; -use spacepackets::tm::PusTm; +use spacepackets::tm::{PusTm, PusTmSecondaryHeader}; +use spacepackets::{SequenceFlags, SpHeader}; use std::collections::HashMap; use std::net::{IpAddr, SocketAddr}; use std::sync::mpsc::{channel, TryRecvError}; @@ -81,11 +83,12 @@ fn main() { let tc_store = TcStore { pool: Arc::new(RwLock::new(Box::new(tc_pool))), }; + let sock_addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT); let (tc_source_tx, tc_source_rx) = channel(); let (tm_funnel_tx, tm_funnel_rx) = channel(); let (tm_server_tx, tm_server_rx) = channel(); - let sender = MpscVerifSender::new(tm_store.pool.clone(), tm_funnel_tx.clone()); + let verif_sender = MpscVerifSender::new(tm_store.pool.clone(), tm_funnel_tx.clone()); let verif_cfg = VerificationReporterCfg::new( PUS_APID, #[allow(clippy::box_default)] @@ -95,7 +98,7 @@ fn main() { 8, ) .unwrap(); - let verif_reporter = VerificationReporterWithSender::new(&verif_cfg, Box::new(sender)); + let verif_reporter = VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender)); // Create event handling components let (event_request_tx, event_request_rx) = channel::(); @@ -139,6 +142,9 @@ fn main() { tm_server_rx, }; + let aocs_to_funnel = tm_funnel_tx.clone(); + let mut aocs_tm_store = tm_store.clone(); + println!("Starting TMTC task"); let jh0 = thread::spawn(move || { core_tmtc_task(core_args, tc_args, tm_args); @@ -195,6 +201,7 @@ fn main() { .generate_pus_event_tm_generic(&mut sender, ×tamp, event, None) .expect("Sending TM as event failed"); } + thread::sleep(Duration::from_millis(400)); } }); @@ -207,6 +214,16 @@ fn main() { Ok(request) => { println!("ACS thread: Received HK request {:?}", request.0); update_time(&mut time_provider, &mut timestamp); + let mut sp_header = + SpHeader::tc(PUS_APID, SequenceFlags::Unsegmented, 0, 0).unwrap(); + let sec_header = PusTmSecondaryHeader::new_simple( + 3, + Subservice::TmHkPacket as u8, + ×tamp, + ); + let pus_tm = PusTm::new(&mut sp_header, sec_header, None, true); + let addr = aocs_tm_store.add_pus_tm(&pus_tm); + aocs_to_funnel.send(addr).expect("Sending HK TM failed"); let started_token = reporter_aocs .start_success(request.1, ×tamp) .expect("Sending start success failed");