From c5910928815bbdd87486141162c4e61bb49dc3ed Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 17:03:26 +0100 Subject: [PATCH 01/14] add first basic HK packet support --- satrs-example/src/hk.rs | 13 +++++++++++++ satrs-example/src/main.rs | 11 ++++++++++- satrs-example/src/pus.rs | 21 +++++++++++++++------ satrs-example/src/requests.rs | 6 ++++++ satrs-example/src/tmtc.rs | 10 ++++++++++ spacepackets | 2 +- 6 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 satrs-example/src/hk.rs create mode 100644 satrs-example/src/requests.rs diff --git a/satrs-example/src/hk.rs b/satrs-example/src/hk.rs new file mode 100644 index 0000000..01c4139 --- /dev/null +++ b/satrs-example/src/hk.rs @@ -0,0 +1,13 @@ +pub type CollectionIntervalFactor = u32; + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum AcsHkIds { + TestMgmSet = 1, +} + +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum HkRequest { + OneShot(u32), + Enable(u32, CollectionIntervalFactor), + Disable(u32, CollectionIntervalFactor), +} diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index c955507..6692363 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -1,8 +1,11 @@ mod ccsds; +mod hk; mod pus; +mod requests; mod tmtc; -use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID}; +use crate::requests::Request; +use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, RequestTargetId, TmStore, PUS_APID}; use satrs_core::event_man::{ EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider, }; @@ -23,6 +26,7 @@ use satrs_example::{OBSW_SERVER_ADDR, SERVER_PORT}; use spacepackets::time::cds::TimeProvider; use spacepackets::time::TimeWriter; use spacepackets::tm::PusTm; +use std::collections::HashMap; use std::net::{IpAddr, SocketAddr}; use std::sync::mpsc::channel; use std::sync::{mpsc, Arc, RwLock}; @@ -100,12 +104,17 @@ fn main() { let mut reporter1 = reporter_with_sender_0.clone(); event_man.subscribe_all(pus_event_man_send_provider.id()); + let mut request_map = HashMap::new(); + let (acs_thread_tx, acs_thread_rx) = channel::(); + request_map.insert(RequestTargetId::AcsSubsystem as u32, acs_thread_tx); + // Create clones here to allow move for thread 0 let core_args = CoreTmtcArgs { tm_store: tm_store_helper.clone(), tm_sender: tm_funnel_tx.clone(), event_sender, event_request_tx, + request_map, }; println!("Starting TMTC task"); diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 20ba72a..441be53 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -1,3 +1,4 @@ +use crate::requests::Request; use crate::tmtc::TmStore; use satrs_core::events::EventU32; use satrs_core::pool::StoreAddr; @@ -15,14 +16,17 @@ use spacepackets::tc::PusTc; use spacepackets::time::cds::TimeProvider; use spacepackets::time::TimeWriter; use spacepackets::SpHeader; +use std::collections::HashMap; use std::sync::mpsc; +use std::sync::mpsc::Sender; pub struct PusReceiver { pub tm_helper: PusTmWithCdsShortHelper, - pub tm_tx: mpsc::Sender, + pub tm_tx: Sender, pub tm_store: TmStore, pub verif_reporter: StdVerifReporterWithSender, - event_request_tx: mpsc::Sender, + event_request_tx: Sender, + request_map: HashMap>, stamper: TimeProvider, time_stamp: [u8; 7], } @@ -30,10 +34,11 @@ pub struct PusReceiver { impl PusReceiver { pub fn new( apid: u16, - tm_tx: mpsc::Sender, + tm_tx: Sender, tm_store: TmStore, verif_reporter: StdVerifReporterWithSender, - event_request_tx: mpsc::Sender, + event_request_tx: Sender, + request_map: HashMap>, ) -> Self { Self { tm_helper: PusTmWithCdsShortHelper::new(apid), @@ -41,6 +46,7 @@ impl PusReceiver { tm_store, verif_reporter, event_request_tx, + request_map, stamper: TimeProvider::default(), time_stamp: [0; 7], } @@ -65,7 +71,9 @@ impl PusServiceProvider for PusReceiver { if service == 17 { self.handle_test_service(pus_tc, accepted_token); } else if service == 5 { - self.handle_event_service(pus_tc, accepted_token); + self.handle_event_request(pus_tc, accepted_token); + } else if service == 3 { + self.handle_hk_request(pus_tc, accepted_token); } else { self.update_time_stamp(); self.verif_reporter @@ -116,7 +124,8 @@ impl PusReceiver { .expect("Writing timestamp failed"); } - fn handle_event_service(&mut self, pus_tc: &PusTc, token: VerificationToken) { + fn handle_hk_request(&mut self, pus_tc: &PusTc, token: VerificationToken) {} + fn handle_event_request(&mut self, pus_tc: &PusTc, token: VerificationToken) { let send_start_failure = |verif_reporter: &mut StdVerifReporterWithSender, timestamp: &[u8; 7], failure_code: &ResultU16, diff --git a/satrs-example/src/requests.rs b/satrs-example/src/requests.rs new file mode 100644 index 0000000..64bbee4 --- /dev/null +++ b/satrs-example/src/requests.rs @@ -0,0 +1,6 @@ +use crate::hk::HkRequest; + +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +pub enum Request { + HkRequest(HkRequest), +} diff --git a/satrs-example/src/tmtc.rs b/satrs-example/src/tmtc.rs index 03d0db0..200df8f 100644 --- a/satrs-example/src/tmtc.rs +++ b/satrs-example/src/tmtc.rs @@ -1,6 +1,7 @@ use satrs_core::events::EventU32; use satrs_core::hal::host::udp_server::{ReceiveResult, UdpTcServer}; use satrs_core::params::Params; +use std::collections::HashMap; use std::net::SocketAddr; use std::sync::mpsc; use std::sync::mpsc::Sender; @@ -8,7 +9,9 @@ use std::thread; use std::time::Duration; use crate::ccsds::CcsdsReceiver; +use crate::hk::HkRequest; use crate::pus::PusReceiver; +use crate::requests::Request; use crate::UdpTmtcServer; use satrs_core::pool::{SharedPool, StoreAddr}; use satrs_core::pus::event_man::EventRequestWithToken; @@ -18,11 +21,17 @@ 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, pub event_sender: Sender<(EventU32, Option)>, pub event_request_tx: Sender, + pub request_map: HashMap>, } #[derive(Clone)] @@ -53,6 +62,7 @@ pub fn core_tmtc_task( args.tm_store.clone(), verif_reporter, args.event_request_tx, + args.request_map, ); let pus_distributor = PusDistributor::new(Box::new(pus_receiver)); let ccsds_receiver = CcsdsReceiver { diff --git a/spacepackets b/spacepackets index b9cd08c..2756670 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit b9cd08cefe662bb77dd8ae116b65a6f3a05fd91e +Subproject commit 2756670efed153f74be57e4942295c9ee09a3c96 From a9b0de218f44c9045fcc5a3504d61b9188cef0dc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 19 Dec 2022 17:05:50 +0100 Subject: [PATCH 02/14] add HK subservice enum --- satrs-core/src/pus/hk.rs | 2 ++ satrs-core/src/pus/mod.rs | 1 + 2 files changed, 3 insertions(+) create mode 100644 satrs-core/src/pus/hk.rs diff --git a/satrs-core/src/pus/hk.rs b/satrs-core/src/pus/hk.rs new file mode 100644 index 0000000..062b3fb --- /dev/null +++ b/satrs-core/src/pus/hk.rs @@ -0,0 +1,2 @@ +#[derive(Debug, Copy, Clone, PartialEq, Eq)] +pub enum Subservice {} diff --git a/satrs-core/src/pus/mod.rs b/satrs-core/src/pus/mod.rs index ef06002..ba4629a 100644 --- a/satrs-core/src/pus/mod.rs +++ b/satrs-core/src/pus/mod.rs @@ -12,6 +12,7 @@ use spacepackets::{ByteConversionError, SizeMissmatch}; pub mod event; pub mod event_man; +pub mod hk; pub mod verification; /// Generic error type which is also able to wrap a user send error with the user supplied type E. From d83e291c8a935cf9b77e77121762b0a04f3f549c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 15:05:34 +0100 Subject: [PATCH 03/14] add basic subservices --- satrs-core/src/pus/hk.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/satrs-core/src/pus/hk.rs b/satrs-core/src/pus/hk.rs index 062b3fb..9ca1669 100644 --- a/satrs-core/src/pus/hk.rs +++ b/satrs-core/src/pus/hk.rs @@ -1,2 +1,8 @@ #[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum Subservice {} +pub enum Subservice { + EnableGeneration = 5, + DisableGeneration = 6, + HkPacket = 25, + GenerateOneShotHk = 27, + ModifyCollectionInterval = 31, +} From 53ac1e05f49ff16469f35c849c1c22c76cb35eaa Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 15:06:48 +0100 Subject: [PATCH 04/14] added TMTC prefix --- satrs-core/src/pus/hk.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/satrs-core/src/pus/hk.rs b/satrs-core/src/pus/hk.rs index 9ca1669..3771670 100644 --- a/satrs-core/src/pus/hk.rs +++ b/satrs-core/src/pus/hk.rs @@ -1,8 +1,8 @@ #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum Subservice { - EnableGeneration = 5, - DisableGeneration = 6, - HkPacket = 25, - GenerateOneShotHk = 27, - ModifyCollectionInterval = 31, + TcEnableGeneration = 5, + TcDisableGeneration = 6, + TmHkPacket = 25, + TcGenerateOneShotHk = 27, + TcModifyCollectionInterval = 31, } From 58d8e66eb429fe2599b2829d326ab219520f3714 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 15:33:00 +0100 Subject: [PATCH 05/14] continue HK code --- satrs-core/Cargo.toml | 2 ++ satrs-core/src/tmtc/mod.rs | 42 +++++++++++++++++++++----------------- satrs-example/src/hk.rs | 6 ++++-- satrs-example/src/main.rs | 11 ++++++++++ satrs-example/src/pus.rs | 40 ++++++++++++++++++++++++++++++++---- satrs-example/src/tmtc.rs | 1 - 6 files changed, 76 insertions(+), 26 deletions(-) diff --git a/satrs-core/Cargo.toml b/satrs-core/Cargo.toml index 11aa619..da11060 100644 --- a/satrs-core/Cargo.toml +++ b/satrs-core/Cargo.toml @@ -32,6 +32,7 @@ default-features = false [dependencies.serde] version = "1.0" default-features = false +optional = true [dependencies.spacepackets] path = "../spacepackets" @@ -50,6 +51,7 @@ version = "1.0" default = ["std"] std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std"] alloc = ["serde/alloc"] +serde = ["dep:serde"] heapless = [] doc-images = [] diff --git a/satrs-core/src/tmtc/mod.rs b/satrs-core/src/tmtc/mod.rs index b1d0b3d..0a31362 100644 --- a/satrs-core/src/tmtc/mod.rs +++ b/satrs-core/src/tmtc/mod.rs @@ -5,10 +5,11 @@ //! directly dispatch received packets to packet listeners based on packet fields like the CCSDS //! Application Process ID (APID) or the ECSS PUS service type. This allows for fast packet //! routing without the overhead and complication of using message queues. However, it also requires -use crate::error::{FsrcErrorRaw, FsrcGroupIds}; use downcast_rs::{impl_downcast, Downcast}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use spacepackets::tc::PusTc; -use spacepackets::SpHeader; +use spacepackets::{ByteConversionError, SizeMissmatch, SpHeader}; #[cfg(feature = "alloc")] pub mod ccsds_distrib; @@ -19,24 +20,27 @@ pub mod tm_helper; pub use ccsds_distrib::{CcsdsDistributor, CcsdsError, CcsdsPacketHandler}; pub use pus_distrib::{PusDistributor, PusServiceProvider}; -const _RAW_PACKET_ERROR: &str = "raw-tmtc"; -const _CCSDS_ERROR: &str = "ccsds-tmtc"; -const _PUS_ERROR: &str = "pus-tmtc"; +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] +pub struct AddressableId { + pub target_id: u32, + pub unique_id: u32, +} -// TODO: A macro for general and unknown errors would be nice -const _FROM_BYTES_SLICE_TOO_SMALL_ERROR: FsrcErrorRaw = FsrcErrorRaw::new( - FsrcGroupIds::Tmtc as u8, - 0, - _RAW_PACKET_ERROR, - "FROM_BYTES_SLICE_TOO_SMALL_ERROR", -); - -const _FROM_BYTES_ZEROCOPY_ERROR: FsrcErrorRaw = FsrcErrorRaw::new( - FsrcGroupIds::Tmtc as u8, - 1, - _RAW_PACKET_ERROR, - "FROM_BYTES_ZEROCOPY_ERROR", -); +impl AddressableId { + pub fn from_raw_be(buf: &[u8]) -> Result { + if buf.len() < 8 { + return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch { + found: buf.len(), + expected: 8, + })); + } + Ok(Self { + target_id: u32::from_be_bytes(buf[0..4].try_into().unwrap()), + unique_id: u32::from_be_bytes(buf[4..8].try_into().unwrap()), + }) + } +} /// Generic trait for object which can receive any telecommands in form of a raw bytestream, with /// no assumptions about the received protocol. diff --git a/satrs-example/src/hk.rs b/satrs-example/src/hk.rs index 01c4139..96cd37b 100644 --- a/satrs-example/src/hk.rs +++ b/satrs-example/src/hk.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] pub type CollectionIntervalFactor = u32; #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -8,6 +9,7 @@ pub enum AcsHkIds { #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum HkRequest { OneShot(u32), - Enable(u32, CollectionIntervalFactor), - Disable(u32, CollectionIntervalFactor), + Enable(u32), + Disable(u32), + ModifyCollectionInterval(CollectionIntervalFactor), } diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 6692363..3f069fd 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -31,6 +31,7 @@ use std::net::{IpAddr, SocketAddr}; use std::sync::mpsc::channel; use std::sync::{mpsc, Arc, RwLock}; use std::thread; +use std::time::Duration; struct TmFunnel { tm_funnel_rx: mpsc::Receiver, @@ -176,9 +177,19 @@ fn main() { } }); + println!("Starting AOCS thread"); + let jh3 = thread::spawn(move || loop { + match acs_thread_rx.try_recv() { + Ok(_) => {} + Err(_) => {} + } + thread::sleep(Duration::from_millis(500)); + }); + jh0.join().expect("Joining UDP TMTC server thread failed"); jh1.join().expect("Joining TM Funnel thread failed"); jh2.join().expect("Joining Event Manager thread failed"); + jh3.join().expect("Joining AOCS thread failed"); } pub fn update_time(time_provider: &mut TimeProvider, timestamp: &mut [u8]) { diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 441be53..3adc309 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -1,15 +1,17 @@ +use crate::hk::HkRequest; use crate::requests::Request; use crate::tmtc::TmStore; use satrs_core::events::EventU32; use satrs_core::pool::StoreAddr; use satrs_core::pus::event::Subservices; use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken}; +use satrs_core::pus::hk; use satrs_core::pus::verification::{ FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken, }; use satrs_core::res_code::ResultU16; use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper; -use satrs_core::tmtc::PusServiceProvider; +use satrs_core::tmtc::{AddressableId, PusServiceProvider}; use satrs_example::{INVALID_PUS_SERVICE, INVALID_PUS_SUBSERVICE, NOT_ENOUGH_APP_DATA}; use spacepackets::ecss::PusPacket; use spacepackets::tc::PusTc; @@ -17,7 +19,6 @@ use spacepackets::time::cds::TimeProvider; use spacepackets::time::TimeWriter; use spacepackets::SpHeader; use std::collections::HashMap; -use std::sync::mpsc; use std::sync::mpsc::Sender; pub struct PusReceiver { @@ -89,7 +90,7 @@ impl PusServiceProvider for PusReceiver { impl PusReceiver { fn handle_test_service(&mut self, pus_tc: &PusTc, token: VerificationToken) { - if pus_tc.subservice() == 1 { + if PusPacket::subservice(pus_tc) == 1 { println!("Received PUS ping command TC[17,1]"); println!("Sending ping reply PUS TM[17,2]"); let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None); @@ -124,7 +125,38 @@ impl PusReceiver { .expect("Writing timestamp failed"); } - fn handle_hk_request(&mut self, pus_tc: &PusTc, token: VerificationToken) {} + fn handle_hk_request(&mut self, pus_tc: &PusTc, token: VerificationToken) { + if pus_tc.user_data().is_none() { + self.update_time_stamp(); + self.verif_reporter + .start_failure( + token, + FailParams::new(&self.time_stamp, &NOT_ENOUGH_APP_DATA, None), + ) + .expect("Sending start failure TM failed"); + } + let user_data = pus_tc.user_data().unwrap(); + if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 { + if user_data.len() < 8 { + self.update_time_stamp(); + self.verif_reporter + .start_failure( + token, + FailParams::new(&self.time_stamp, &NOT_ENOUGH_APP_DATA, None), + ) + .expect("Sending start failure TM failed"); + } + let addressable_id = AddressableId::from_raw_be(&user_data).unwrap(); + if self.request_map.contains_key(&addressable_id.target_id) { + let sender = self.request_map.get(&addressable_id.target_id).unwrap(); + sender + .send(Request::HkRequest(HkRequest::Enable( + addressable_id.unique_id, + ))) + .expect("Sending HK request failed") + } + } + } fn handle_event_request(&mut self, pus_tc: &PusTc, token: VerificationToken) { let send_start_failure = |verif_reporter: &mut StdVerifReporterWithSender, timestamp: &[u8; 7], diff --git a/satrs-example/src/tmtc.rs b/satrs-example/src/tmtc.rs index 200df8f..5aab261 100644 --- a/satrs-example/src/tmtc.rs +++ b/satrs-example/src/tmtc.rs @@ -9,7 +9,6 @@ use std::thread; use std::time::Duration; use crate::ccsds::CcsdsReceiver; -use crate::hk::HkRequest; use crate::pus::PusReceiver; use crate::requests::Request; use crate::UdpTmtcServer; From 359402d78d2dfd63222f477bf33ae75ef8afb483 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 15:45:09 +0100 Subject: [PATCH 06/14] adding request handling --- satrs-example/src/lib.rs | 40 ++++++++++++++------ satrs-example/src/pus.rs | 79 +++++++++++++++++++++++++++------------- 2 files changed, 83 insertions(+), 36 deletions(-) diff --git a/satrs-example/src/lib.rs b/satrs-example/src/lib.rs index e2b3be6..b36a457 100644 --- a/satrs-example/src/lib.rs +++ b/satrs-example/src/lib.rs @@ -6,21 +6,39 @@ use satrs_mib::resultcode; #[derive(Debug)] pub enum GroupId { Tmtc = 0, + Hk = 1, } pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::UNSPECIFIED; pub const SERVER_PORT: u16 = 7301; -#[resultcode] -pub const INVALID_PUS_SERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 0); -#[resultcode] -pub const INVALID_PUS_SUBSERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 1); +pub mod tmtc_err { + use super::*; -#[resultcode(info = "Not enough data inside the TC application data field")] -pub const NOT_ENOUGH_APP_DATA: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 2); + #[resultcode] + pub const INVALID_PUS_SERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 0); + #[resultcode] + pub const INVALID_PUS_SUBSERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 1); -pub const TMTC_RESULTS: &[ResultU16Info] = &[ - INVALID_PUS_SERVICE_EXT, - INVALID_PUS_SUBSERVICE_EXT, - NOT_ENOUGH_APP_DATA_EXT, -]; + #[resultcode(info = "Not enough data inside the TC application data field")] + pub const NOT_ENOUGH_APP_DATA: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 2); + + pub const TMTC_RESULTS: &[ResultU16Info] = &[ + INVALID_PUS_SERVICE_EXT, + INVALID_PUS_SUBSERVICE_EXT, + NOT_ENOUGH_APP_DATA_EXT, + ]; +} + +pub mod hk_err { + use super::*; + + #[resultcode] + pub const TARGET_ID_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 0); + #[resultcode] + pub const UNIQUE_ID_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 1); + #[resultcode] + pub const UNKNOWN_TARGET_ID: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 2); + #[resultcode] + pub const COLLECTION_INTERVAL_MISSING: ResultU16 = ResultU16::const_new(GroupId::Hk as u8, 3); +} diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 3adc309..bc5caf2 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -12,7 +12,7 @@ use satrs_core::pus::verification::{ use satrs_core::res_code::ResultU16; use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper; use satrs_core::tmtc::{AddressableId, PusServiceProvider}; -use satrs_example::{INVALID_PUS_SERVICE, INVALID_PUS_SUBSERVICE, NOT_ENOUGH_APP_DATA}; +use satrs_example::{hk_err, tmtc_err}; use spacepackets::ecss::PusPacket; use spacepackets::tc::PusTc; use spacepackets::time::cds::TimeProvider; @@ -80,7 +80,7 @@ impl PusServiceProvider for PusReceiver { self.verif_reporter .start_failure( accepted_token, - FailParams::new(&self.time_stamp, &INVALID_PUS_SERVICE, None), + FailParams::new(&self.time_stamp, &tmtc_err::INVALID_PUS_SERVICE, None), ) .expect("Start failure verification failed") } @@ -110,7 +110,7 @@ impl PusReceiver { self.verif_reporter .start_failure( token, - FailParams::new(&self.time_stamp, &INVALID_PUS_SUBSERVICE, None), + FailParams::new(&self.time_stamp, &tmtc_err::INVALID_PUS_SUBSERVICE, None), ) .expect("Sending start failure TM failed"); } @@ -131,30 +131,59 @@ impl PusReceiver { self.verif_reporter .start_failure( token, - FailParams::new(&self.time_stamp, &NOT_ENOUGH_APP_DATA, None), + FailParams::new(&self.time_stamp, &tmtc_err::NOT_ENOUGH_APP_DATA, None), ) .expect("Sending start failure TM failed"); + return; } let user_data = pus_tc.user_data().unwrap(); + if user_data.len() < 8 { + let err = if user_data.len() < 4 { + &hk_err::TARGET_ID_MISSING + } else { + &hk_err::UNIQUE_ID_MISSING + }; + self.update_time_stamp(); + self.verif_reporter + .start_failure(token, FailParams::new(&self.time_stamp, err, None)) + .expect("Sending start failure TM failed"); + return; + } + let addressable_id = AddressableId::from_raw_be(&user_data).unwrap(); + if !self.request_map.contains_key(&addressable_id.target_id) { + self.update_time_stamp(); + self.verif_reporter + .start_failure( + token, + FailParams::new(&self.time_stamp, &hk_err::UNKNOWN_TARGET_ID, None), + ) + .expect("Sending start failure TM failed"); + return; + } if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 { - if user_data.len() < 8 { - self.update_time_stamp(); - self.verif_reporter - .start_failure( - token, - FailParams::new(&self.time_stamp, &NOT_ENOUGH_APP_DATA, None), - ) - .expect("Sending start failure TM failed"); - } - let addressable_id = AddressableId::from_raw_be(&user_data).unwrap(); - if self.request_map.contains_key(&addressable_id.target_id) { - let sender = self.request_map.get(&addressable_id.target_id).unwrap(); - sender - .send(Request::HkRequest(HkRequest::Enable( - addressable_id.unique_id, - ))) - .expect("Sending HK request failed") - } + let sender = self.request_map.get(&addressable_id.target_id).unwrap(); + sender + .send(Request::HkRequest(HkRequest::Enable( + addressable_id.unique_id, + ))) + .expect("Sending HK request failed") + } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcDisableGeneration as u8 { + let sender = self.request_map.get(&addressable_id.target_id).unwrap(); + sender + .send(Request::HkRequest(HkRequest::Disable( + addressable_id.unique_id, + ))) + .expect("Sending HK request failed"); + } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcGenerateOneShotHk as u8 { + let sender = self.request_map.get(&addressable_id.target_id).unwrap(); + sender + .send(Request::HkRequest(HkRequest::OneShot( + addressable_id.unique_id, + ))) + .expect("Sending HK request failed"); + } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcModifyCollectionInterval as u8 + { + if user_data.len() < 12 {} } } fn handle_event_request(&mut self, pus_tc: &PusTc, token: VerificationToken) { @@ -180,7 +209,7 @@ impl PusReceiver { send_start_failure( &mut self.verif_reporter, &self.time_stamp, - &NOT_ENOUGH_APP_DATA, + &tmtc_err::NOT_ENOUGH_APP_DATA, None, ); return; @@ -191,7 +220,7 @@ impl PusReceiver { send_start_failure( &mut self.verif_reporter, &self.time_stamp, - &NOT_ENOUGH_APP_DATA, + &tmtc_err::NOT_ENOUGH_APP_DATA, None, ); return; @@ -223,7 +252,7 @@ impl PusReceiver { send_start_failure( &mut self.verif_reporter, &self.time_stamp, - &INVALID_PUS_SUBSERVICE, + &tmtc_err::INVALID_PUS_SUBSERVICE, None, ); } From 73d3fd664459699f23b880723d14013ac6bbebc7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 16:36:35 +0100 Subject: [PATCH 07/14] bump spacepackets --- spacepackets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacepackets b/spacepackets index 2756670..db471e3 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit 2756670efed153f74be57e4942295c9ee09a3c96 +Subproject commit db471e313c92c313d270d5a6f06c0414abb5fae3 From 2532119fbe4c80bf424cdf08629b018d3eabbd8a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 17:23:11 +0100 Subject: [PATCH 08/14] a lot of clippy fixes --- satrs-core/src/event_man.rs | 6 +++--- satrs-core/src/events.rs | 7 ++----- satrs-core/src/pool.rs | 4 ++-- satrs-core/src/pus/verification.rs | 21 ++++++++++----------- satrs-example/src/main.rs | 1 + satrs-example/src/pus.rs | 29 ++++++++++------------------- 6 files changed, 28 insertions(+), 40 deletions(-) diff --git a/satrs-core/src/event_man.rs b/satrs-core/src/event_man.rs index 3219c0b..530df51 100644 --- a/satrs-core/src/event_man.rs +++ b/satrs-core/src/event_man.rs @@ -211,9 +211,9 @@ impl>) -> Self { - let listener_table = Box::new(DefaultListenerTableProvider::default()); - let sender_table = - Box::new(DefaultSenderTableProvider::::default()); + let listener_table: Box = Box::default(); + let sender_table: Box> = + Box::default(); Self::new_custom_tables(listener_table, sender_table, event_receiver) } } diff --git a/satrs-core/src/events.rs b/satrs-core/src/events.rs index 1c06945..ae0452c 100644 --- a/satrs-core/src/events.rs +++ b/satrs-core/src/events.rs @@ -136,17 +136,14 @@ impl EventBase { impl EventBase { #[inline] fn raw(&self) -> u32 { - (((self.severity as u32) << 30) | ((self.group_id as u32) << 16) | self.unique_id as u32) - as u32 + ((self.severity as u32) << 30) | ((self.group_id as u32) << 16) | self.unique_id as u32 } } impl EventBase { #[inline] fn raw(&self) -> u16 { - (((self.severity as u16) << 14) as u16 - | ((self.group_id as u16) << 8) as u16 - | self.unique_id as u16) as u16 + ((self.severity as u16) << 14) | ((self.group_id as u16) << 8) | self.unique_id as u16 } } diff --git a/satrs-core/src/pool.rs b/satrs-core/src/pool.rs index 70d9dcd..ebc404e 100644 --- a/satrs-core/src/pool.rs +++ b/satrs-core/src/pool.rs @@ -136,7 +136,7 @@ impl StoreAddr { pub const INVALID_ADDR: u32 = 0xFFFFFFFF; pub fn raw(&self) -> u32 { - ((self.pool_idx as u32) << 16) as u32 | self.packet_idx as u32 + ((self.pool_idx as u32) << 16) | self.packet_idx as u32 } } @@ -239,7 +239,7 @@ impl LocalPool { fn validate_addr(&self, addr: &StoreAddr) -> Result<(), StoreError> { let pool_idx = addr.pool_idx as usize; - if pool_idx as usize >= self.pool_cfg.cfg.len() { + if pool_idx >= self.pool_cfg.cfg.len() { return Err(StoreError::InvalidStoreId( StoreIdError::InvalidSubpool(addr.pool_idx), Some(*addr), diff --git a/satrs-core/src/pus/verification.rs b/satrs-core/src/pus/verification.rs index b2466c3..1da862b 100644 --- a/satrs-core/src/pus/verification.rs +++ b/satrs-core/src/pus/verification.rs @@ -569,7 +569,7 @@ impl VerificationReporterBasic { ) -> Result> { let mut source_data_len = size_of::(); if let Some(step) = step { - source_data_len += step.byte_width() as usize; + source_data_len += step.byte_width(); } source_buffer_large_enough(buf.len(), source_data_len)?; let mut idx = 0; @@ -577,7 +577,7 @@ impl VerificationReporterBasic { idx += RequestId::SIZE_AS_BYTES; if let Some(step) = step { // Size check was done beforehand - step.write_to_be_bytes(&mut buf[idx..idx + step.byte_width() as usize]) + step.write_to_be_bytes(&mut buf[idx..idx + step.byte_width()]) .unwrap(); } let mut sp_header = SpHeader::tm_unseg(self.apid(), 0, 0).unwrap(); @@ -601,10 +601,9 @@ impl VerificationReporterBasic { params: &'a FailParams, ) -> Result> { let mut idx = 0; - let mut source_data_len = - RequestId::SIZE_AS_BYTES + params.failure_code.byte_width() as usize; + let mut source_data_len = RequestId::SIZE_AS_BYTES + params.failure_code.byte_width(); if let Some(step) = step { - source_data_len += step.byte_width() as usize; + source_data_len += step.byte_width(); } if let Some(failure_data) = params.failure_data { source_data_len += failure_data.len(); @@ -614,14 +613,14 @@ impl VerificationReporterBasic { idx += RequestId::SIZE_AS_BYTES; if let Some(step) = step { // Size check done beforehand - step.write_to_be_bytes(&mut buf[idx..idx + step.byte_width() as usize]) + step.write_to_be_bytes(&mut buf[idx..idx + step.byte_width()]) .unwrap(); - idx += step.byte_width() as usize; + idx += step.byte_width(); } params .failure_code - .write_to_be_bytes(&mut buf[idx..idx + params.failure_code.byte_width() as usize])?; - idx += params.failure_code.byte_width() as usize; + .write_to_be_bytes(&mut buf[idx..idx + params.failure_code.byte_width()])?; + idx += params.failure_code.byte_width(); if let Some(failure_data) = params.failure_data { buf[idx..idx + failure_data.len()].copy_from_slice(failure_data); } @@ -709,8 +708,8 @@ mod allocmod { source_data_buf: vec![ 0; RequestId::SIZE_AS_BYTES - + cfg.step_field_width as usize - + cfg.fail_code_field_width as usize + + cfg.step_field_width + + cfg.fail_code_field_width + cfg.max_fail_data_len ], seq_counter: cfg.seq_counter.clone(), diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 3f069fd..848246b 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -83,6 +83,7 @@ fn main() { let sender = MpscVerifSender::new(tm_store.clone(), tm_funnel_tx.clone()); let verif_cfg = VerificationReporterCfg::new( PUS_APID, + #[allow(clippy::box_default)] Box::new(SimpleSeqCountProvider::default()), 1, 2, diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index bc5caf2..9167935 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -149,7 +149,7 @@ impl PusReceiver { .expect("Sending start failure TM failed"); return; } - let addressable_id = AddressableId::from_raw_be(&user_data).unwrap(); + let addressable_id = AddressableId::from_raw_be(user_data).unwrap(); if !self.request_map.contains_key(&addressable_id.target_id) { self.update_time_stamp(); self.verif_reporter @@ -160,27 +160,18 @@ impl PusReceiver { .expect("Sending start failure TM failed"); return; } + let send_request = |request: HkRequest| { + let sender = self.request_map.get(&addressable_id.target_id).unwrap(); + sender + .send(Request::HkRequest(request)) + .expect(&format!("Sending HK request {:?} failed", request)) + }; if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 { - let sender = self.request_map.get(&addressable_id.target_id).unwrap(); - sender - .send(Request::HkRequest(HkRequest::Enable( - addressable_id.unique_id, - ))) - .expect("Sending HK request failed") + send_request(HkRequest::Enable(addressable_id.unique_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcDisableGeneration as u8 { - let sender = self.request_map.get(&addressable_id.target_id).unwrap(); - sender - .send(Request::HkRequest(HkRequest::Disable( - addressable_id.unique_id, - ))) - .expect("Sending HK request failed"); + send_request(HkRequest::Disable(addressable_id.unique_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcGenerateOneShotHk as u8 { - let sender = self.request_map.get(&addressable_id.target_id).unwrap(); - sender - .send(Request::HkRequest(HkRequest::OneShot( - addressable_id.unique_id, - ))) - .expect("Sending HK request failed"); + send_request(HkRequest::OneShot(addressable_id.unique_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcModifyCollectionInterval as u8 { if user_data.len() < 12 {} From e963ee7bc476f0fc5e2737665a5cc49540ac14f3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 20 Dec 2022 17:41:07 +0100 Subject: [PATCH 09/14] finish collection interval request --- satrs-example/src/pus.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 9167935..9b6c6dc 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -1,4 +1,4 @@ -use crate::hk::HkRequest; +use crate::hk::{CollectionIntervalFactor, HkRequest}; use crate::requests::Request; use crate::tmtc::TmStore; use satrs_core::events::EventU32; @@ -174,7 +174,23 @@ impl PusReceiver { send_request(HkRequest::OneShot(addressable_id.unique_id)); } else if PusPacket::subservice(pus_tc) == hk::Subservice::TcModifyCollectionInterval as u8 { - if user_data.len() < 12 {} + if user_data.len() < 12 { + self.update_time_stamp(); + self.verif_reporter + .start_failure( + token, + FailParams::new( + &self.time_stamp, + &hk_err::COLLECTION_INTERVAL_MISSING, + None, + ), + ) + .expect("Sending start failure TM failed"); + return; + } + send_request(HkRequest::ModifyCollectionInterval( + CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()), + )); } } fn handle_event_request(&mut self, pus_tc: &PusTc, token: VerificationToken) { From 8d85681ad487fc8b5a7adb85900db9f3cf77c18a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 21 Dec 2022 09:47:27 +0100 Subject: [PATCH 10/14] re-run clippy --- satrs-example/src/main.rs | 13 ++++++++++--- satrs-example/src/pus.rs | 2 +- spacepackets | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 848246b..193804a 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -28,7 +28,7 @@ use spacepackets::time::TimeWriter; use spacepackets::tm::PusTm; use std::collections::HashMap; use std::net::{IpAddr, SocketAddr}; -use std::sync::mpsc::channel; +use std::sync::mpsc::{channel, TryRecvError}; use std::sync::{mpsc, Arc, RwLock}; use std::thread; use std::time::Duration; @@ -181,8 +181,15 @@ fn main() { println!("Starting AOCS thread"); let jh3 = thread::spawn(move || loop { match acs_thread_rx.try_recv() { - Ok(_) => {} - Err(_) => {} + Ok(request) => { + println!("ACS thread: Received request {:?}", request) + } + Err(e) => match e { + TryRecvError::Empty => {} + TryRecvError::Disconnected => { + println!("ACS thread: Message Queue TX disconnected!") + } + }, } thread::sleep(Duration::from_millis(500)); }); diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 9b6c6dc..9772ccb 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -164,7 +164,7 @@ impl PusReceiver { let sender = self.request_map.get(&addressable_id.target_id).unwrap(); sender .send(Request::HkRequest(request)) - .expect(&format!("Sending HK request {:?} failed", request)) + .unwrap_or_else(|_| panic!("Sending HK request {:?} failed", request)); }; if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 { send_request(HkRequest::Enable(addressable_id.unique_id)); diff --git a/spacepackets b/spacepackets index db471e3..83e2cad 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit db471e313c92c313d270d5a6f06c0414abb5fae3 +Subproject commit 83e2cad75377969b1e74379acff2c0dcf858d4cf From da9eb94d98640b193e9524042d92db3711a16a2e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 21 Dec 2022 10:01:19 +0100 Subject: [PATCH 11/14] added basic TC support --- satrs-example/pyclient/main.py | 43 +++++++++++++++++++++++++++++++--- satrs-example/src/lib.rs | 5 ++++ satrs-example/src/main.rs | 4 ++-- satrs-example/src/tmtc.rs | 5 ---- 4 files changed, 47 insertions(+), 10 deletions(-) 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, From b8a0ff1e2d6d9c1c5e5250a51f939a8df6fd1ade Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 21 Dec 2022 10:15:41 +0100 Subject: [PATCH 12/14] hk request works now --- satrs-example/src/main.rs | 2 +- satrs-example/src/pus.rs | 2 +- satrs-example/src/requests.rs | 4 ++++ spacepackets | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index e198af0..9999152 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -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, RequestTargetId, SERVER_PORT}; +use satrs_example::{RequestTargetId, OBSW_SERVER_ADDR, SERVER_PORT}; use spacepackets::time::cds::TimeProvider; use spacepackets::time::TimeWriter; use spacepackets::tm::PusTm; diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 9772ccb..2c8bb84 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -48,7 +48,7 @@ impl PusReceiver { verif_reporter, event_request_tx, request_map, - stamper: TimeProvider::default(), + stamper: TimeProvider::new_with_u16_days(0, 0), time_stamp: [0; 7], } } diff --git a/satrs-example/src/requests.rs b/satrs-example/src/requests.rs index 64bbee4..2ae2d21 100644 --- a/satrs-example/src/requests.rs +++ b/satrs-example/src/requests.rs @@ -1,6 +1,10 @@ use crate::hk::HkRequest; +use satrs_core::pus::verification::{TcStateAccepted, VerificationToken}; #[derive(Copy, Clone, Eq, PartialEq, Debug)] pub enum Request { HkRequest(HkRequest), } + +#[derive(Copy, Clone, Eq, PartialEq, Debug)] +struct RequestWithToken(Request, VerificationToken); diff --git a/spacepackets b/spacepackets index 83e2cad..9b091e3 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit 83e2cad75377969b1e74379acff2c0dcf858d4cf +Subproject commit 9b091e3a3a6f599b093c96327751bcf1bc911ca1 From b1342776ae5e10d0d53aa0024b8fbe63947d8831 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 21 Dec 2022 10:23:32 +0100 Subject: [PATCH 13/14] HK reception works --- satrs-example/src/main.rs | 40 ++++++++++++++++++++++------------- satrs-example/src/pus.rs | 8 +++---- satrs-example/src/requests.rs | 2 +- satrs-example/src/tmtc.rs | 4 ++-- 4 files changed, 32 insertions(+), 22 deletions(-) diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 9999152..b16f86d 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -4,7 +4,7 @@ mod pus; mod requests; mod tmtc; -use crate::requests::Request; +use crate::requests::RequestWithToken; use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID}; use satrs_core::event_man::{ EventManagerWithMpscQueue, MpscEventReceiver, MpscEventU32SendProvider, SendEventProvider, @@ -103,11 +103,12 @@ fn main() { PusEventDispatcher::new(event_reporter, Box::new(pus_tm_backend)); let (pus_event_man_tx, pus_event_man_rx) = channel(); let pus_event_man_send_provider = MpscEventU32SendProvider::new(1, pus_event_man_tx); - let mut reporter1 = reporter_with_sender_0.clone(); + let mut reporter_event_handler = reporter_with_sender_0.clone(); + let mut reporter_aocs = reporter_with_sender_0.clone(); event_man.subscribe_all(pus_event_man_send_provider.id()); let mut request_map = HashMap::new(); - let (acs_thread_tx, acs_thread_rx) = channel::(); + let (acs_thread_tx, acs_thread_rx) = channel::(); request_map.insert(RequestTargetId::AcsSubsystem as u32, acs_thread_tx); // Create clones here to allow move for thread 0 @@ -146,7 +147,7 @@ fn main() { let mut sender = EventTmSender::new(tm_store_helper, tm_funnel_tx); let mut time_provider = TimeProvider::new_with_u16_days(0, 0); let mut report_completion = |event_req: EventRequestWithToken, timestamp: &[u8]| { - reporter1 + reporter_event_handler .completion_success(event_req.token, timestamp) .expect("Sending completion success failed"); }; @@ -179,19 +180,28 @@ fn main() { }); println!("Starting AOCS thread"); - let jh3 = thread::spawn(move || loop { - match acs_thread_rx.try_recv() { - Ok(request) => { - println!("ACS thread: Received request {:?}", request) - } - Err(e) => match e { - TryRecvError::Empty => {} - TryRecvError::Disconnected => { - println!("ACS thread: Message Queue TX disconnected!") + let jh3 = thread::spawn(move || { + let mut timestamp: [u8; 7] = [0; 7]; + let mut time_provider = TimeProvider::new_with_u16_days(0, 0); + loop { + match acs_thread_rx.try_recv() { + Ok(request) => { + println!("ACS thread: Received HK request {:?}", request.0); + update_time(&mut time_provider, &mut timestamp); + let started_token = reporter_aocs.start_success(request.1, ×tamp).unwrap(); + reporter_aocs + .completion_success(started_token, ×tamp) + .unwrap(); } - }, + Err(e) => match e { + TryRecvError::Empty => {} + TryRecvError::Disconnected => { + println!("ACS thread: Message Queue TX disconnected!") + } + }, + } + thread::sleep(Duration::from_millis(500)); } - thread::sleep(Duration::from_millis(500)); }); jh0.join().expect("Joining UDP TMTC server thread failed"); diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index 2c8bb84..49dc6bc 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -1,5 +1,5 @@ use crate::hk::{CollectionIntervalFactor, HkRequest}; -use crate::requests::Request; +use crate::requests::{Request, RequestWithToken}; use crate::tmtc::TmStore; use satrs_core::events::EventU32; use satrs_core::pool::StoreAddr; @@ -27,7 +27,7 @@ pub struct PusReceiver { pub tm_store: TmStore, pub verif_reporter: StdVerifReporterWithSender, event_request_tx: Sender, - request_map: HashMap>, + request_map: HashMap>, stamper: TimeProvider, time_stamp: [u8; 7], } @@ -39,7 +39,7 @@ impl PusReceiver { tm_store: TmStore, verif_reporter: StdVerifReporterWithSender, event_request_tx: Sender, - request_map: HashMap>, + request_map: HashMap>, ) -> Self { Self { tm_helper: PusTmWithCdsShortHelper::new(apid), @@ -163,7 +163,7 @@ impl PusReceiver { let send_request = |request: HkRequest| { let sender = self.request_map.get(&addressable_id.target_id).unwrap(); sender - .send(Request::HkRequest(request)) + .send(RequestWithToken(Request::HkRequest(request), token)) .unwrap_or_else(|_| panic!("Sending HK request {:?} failed", request)); }; if PusPacket::subservice(pus_tc) == hk::Subservice::TcEnableGeneration as u8 { diff --git a/satrs-example/src/requests.rs b/satrs-example/src/requests.rs index 2ae2d21..cac2277 100644 --- a/satrs-example/src/requests.rs +++ b/satrs-example/src/requests.rs @@ -7,4 +7,4 @@ pub enum Request { } #[derive(Copy, Clone, Eq, PartialEq, Debug)] -struct RequestWithToken(Request, VerificationToken); +pub struct RequestWithToken(pub Request, pub VerificationToken); diff --git a/satrs-example/src/tmtc.rs b/satrs-example/src/tmtc.rs index 9cf9a7f..e63502a 100644 --- a/satrs-example/src/tmtc.rs +++ b/satrs-example/src/tmtc.rs @@ -10,7 +10,7 @@ use std::time::Duration; use crate::ccsds::CcsdsReceiver; use crate::pus::PusReceiver; -use crate::requests::Request; +use crate::requests::RequestWithToken; use crate::UdpTmtcServer; use satrs_core::pool::{SharedPool, StoreAddr}; use satrs_core::pus::event_man::EventRequestWithToken; @@ -25,7 +25,7 @@ pub struct CoreTmtcArgs { pub tm_sender: Sender, pub event_sender: Sender<(EventU32, Option)>, pub event_request_tx: Sender, - pub request_map: HashMap>, + pub request_map: HashMap>, } #[derive(Clone)] From 3b34649ed3cedf86996ac031b18320115efb28ab Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 21 Dec 2022 10:24:18 +0100 Subject: [PATCH 14/14] cargo fmt --- satrs-example/src/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index b16f86d..f929798 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -188,10 +188,12 @@ fn main() { Ok(request) => { println!("ACS thread: Received HK request {:?}", request.0); update_time(&mut time_provider, &mut timestamp); - let started_token = reporter_aocs.start_success(request.1, ×tamp).unwrap(); + let started_token = reporter_aocs + .start_success(request.1, ×tamp) + .expect("Sending start success failed"); reporter_aocs .completion_success(started_token, ×tamp) - .unwrap(); + .expect("Sending completion success failed"); } Err(e) => match e { TryRecvError::Empty => {}