diff --git a/satrs-core/Cargo.toml b/satrs-core/Cargo.toml index 796efaa..b45f8b9 100644 --- a/satrs-core/Cargo.toml +++ b/satrs-core/Cargo.toml @@ -53,10 +53,10 @@ default-features = false optional = true [dependencies.spacepackets] -version = "0.5.2" +# version = "0.5.2" # path = "../spacepackets" -# git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" -# rev = "..." +git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" +rev = "cfa5f8099c95389628440a1611766e3b178fcdb3" default-features = false diff --git a/satrs-core/src/pus/event.rs b/satrs-core/src/pus/event.rs index c81d103..cc85df6 100644 --- a/satrs-core/src/pus/event.rs +++ b/satrs-core/src/pus/event.rs @@ -7,56 +7,8 @@ use spacepackets::{SpHeader, MAX_APID}; use crate::pus::EcssTmSenderCore; #[cfg(feature = "alloc")] pub use allocvec::EventReporter; +pub use spacepackets::ecss::event::*; -#[derive(Debug, Eq, PartialEq, Copy, Clone)] -pub enum Subservices { - TmInfoReport = 1, - TmLowSeverityReport = 2, - TmMediumSeverityReport = 3, - TmHighSeverityReport = 4, - TcEnableEventGeneration = 5, - TcDisableEventGeneration = 6, - TcReportDisabledList = 7, - TmDisabledEventsReport = 8, -} - -impl From for u8 { - fn from(enumeration: Subservices) -> Self { - enumeration as u8 - } -} - -impl TryFrom for Subservices { - type Error = (); - - fn try_from(value: u8) -> Result { - match value { - x if x == Subservices::TmInfoReport as u8 => Ok(Subservices::TmInfoReport), - x if x == Subservices::TmLowSeverityReport as u8 => { - Ok(Subservices::TmLowSeverityReport) - } - x if x == Subservices::TmMediumSeverityReport as u8 => { - Ok(Subservices::TmMediumSeverityReport) - } - x if x == Subservices::TmHighSeverityReport as u8 => { - Ok(Subservices::TmHighSeverityReport) - } - x if x == Subservices::TcEnableEventGeneration as u8 => { - Ok(Subservices::TcEnableEventGeneration) - } - x if x == Subservices::TcDisableEventGeneration as u8 => { - Ok(Subservices::TcDisableEventGeneration) - } - x if x == Subservices::TcReportDisabledList as u8 => { - Ok(Subservices::TcReportDisabledList) - } - x if x == Subservices::TmDisabledEventsReport as u8 => { - Ok(Subservices::TmDisabledEventsReport) - } - _ => Err(()), - } - } -} pub struct EventReporterBase { msg_count: u16, apid: u16, @@ -85,7 +37,7 @@ impl EventReporterBase { ) -> Result<(), EcssTmErrorWithSend> { self.generate_and_send_generic_tm( buf, - Subservices::TmInfoReport, + Subservice::TmInfoReport, sender, time_stamp, event_id, @@ -103,7 +55,7 @@ impl EventReporterBase { ) -> Result<(), EcssTmErrorWithSend> { self.generate_and_send_generic_tm( buf, - Subservices::TmLowSeverityReport, + Subservice::TmLowSeverityReport, sender, time_stamp, event_id, @@ -121,7 +73,7 @@ impl EventReporterBase { ) -> Result<(), EcssTmErrorWithSend> { self.generate_and_send_generic_tm( buf, - Subservices::TmMediumSeverityReport, + Subservice::TmMediumSeverityReport, sender, time_stamp, event_id, @@ -139,7 +91,7 @@ impl EventReporterBase { ) -> Result<(), EcssTmErrorWithSend> { self.generate_and_send_generic_tm( buf, - Subservices::TmHighSeverityReport, + Subservice::TmHighSeverityReport, sender, time_stamp, event_id, @@ -150,7 +102,7 @@ impl EventReporterBase { fn generate_and_send_generic_tm( &mut self, buf: &mut [u8], - subservice: Subservices, + subservice: Subservice, sender: &mut (impl EcssTmSenderCore + ?Sized), time_stamp: &[u8], event_id: impl EcssEnumeration, @@ -165,7 +117,7 @@ impl EventReporterBase { fn generate_generic_event_tm<'a>( &'a self, buf: &'a mut [u8], - subservice: Subservices, + subservice: Subservice, time_stamp: &'a [u8], event_id: impl EcssEnumeration, aux_data: Option<&[u8]>, @@ -332,12 +284,12 @@ mod tests { } } - fn severity_to_subservice(severity: Severity) -> Subservices { + fn severity_to_subservice(severity: Severity) -> Subservice { match severity { - Severity::INFO => Subservices::TmInfoReport, - Severity::LOW => Subservices::TmLowSeverityReport, - Severity::MEDIUM => Subservices::TmMediumSeverityReport, - Severity::HIGH => Subservices::TmHighSeverityReport, + Severity::INFO => Subservice::TmInfoReport, + Severity::LOW => Subservice::TmLowSeverityReport, + Severity::MEDIUM => Subservice::TmMediumSeverityReport, + Severity::HIGH => Subservice::TmHighSeverityReport, } } diff --git a/satrs-core/src/pus/hk.rs b/satrs-core/src/pus/hk.rs index 3771670..50dbc86 100644 --- a/satrs-core/src/pus/hk.rs +++ b/satrs-core/src/pus/hk.rs @@ -1,8 +1 @@ -#[derive(Debug, Copy, Clone, PartialEq, Eq)] -pub enum Subservice { - TcEnableGeneration = 5, - TcDisableGeneration = 6, - TmHkPacket = 25, - TcGenerateOneShotHk = 27, - TcModifyCollectionInterval = 31, -} +pub use spacepackets::ecss::hk::*; diff --git a/satrs-core/src/pus/scheduling.rs b/satrs-core/src/pus/scheduling.rs index 4b41d47..e97da72 100644 --- a/satrs-core/src/pus/scheduling.rs +++ b/satrs-core/src/pus/scheduling.rs @@ -83,16 +83,6 @@ impl From for ScheduleError { #[cfg(feature = "std")] impl Error for ScheduleError {} -//TODO: Move to spacepackets -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum ScheduleSubservice { - EnableScheduling = 1, - DisableScheduling = 2, - ResetScheduling = 3, - InsertActivity = 4, - DeleteActivity = 5, -} - /// This is the core data structure for scheduling PUS telecommands with [alloc] support. /// /// It is assumed that the actual telecommand data is stored in a separate TC pool offering @@ -323,17 +313,9 @@ impl PusScheduler { mod tests { use crate::pool::{LocalPool, PoolCfg, PoolProvider, StoreAddr}; use crate::pus::scheduling::{PusScheduler, ScheduleError}; - use crate::tmtc::ccsds_distrib::tests::generate_ping_tc; - use alloc::rc::Rc; - use core::borrow::BorrowMut; - use spacepackets::ecss::PacketTypeCodes::UnsignedInt; - use spacepackets::ecss::PusPacket; use spacepackets::tc::PusTc; use spacepackets::time::{cds, TimeWriter, UnixTimestamp}; - use spacepackets::{CcsdsPacket, SpHeader}; - use std::cell::RefCell; - use std::sync::mpsc; - use std::sync::mpsc::{channel, Receiver, TryRecvError}; + use spacepackets::SpHeader; use std::time::Duration; use std::vec::Vec; #[allow(unused_imports)] @@ -404,7 +386,7 @@ mod tests { ) .unwrap(); - let worked = scheduler + scheduler .insert_unwrapped_and_stored_tc( UnixTimestamp::new_only_seconds(100), StoreAddr { @@ -414,7 +396,7 @@ mod tests { ) .unwrap(); - let worked = scheduler + scheduler .insert_unwrapped_and_stored_tc( UnixTimestamp::new_only_seconds(300), StoreAddr { @@ -465,10 +447,14 @@ mod tests { let first_addr = pool.add(&[2, 2, 2]).unwrap(); - scheduler.insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), first_addr); + scheduler + .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), first_addr) + .expect("insertion failed"); let second_addr = pool.add(&[5, 6, 7]).unwrap(); - scheduler.insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), second_addr); + scheduler + .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), second_addr) + .expect("insertion failed"); let mut i = 0; let mut test_closure_1 = |boolvar: bool, store_addr: &StoreAddr| { @@ -523,10 +509,14 @@ mod tests { let first_addr = pool.add(&[2, 2, 2]).unwrap(); - scheduler.insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), first_addr); + scheduler + .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), first_addr) + .expect("insertion failed"); let second_addr = pool.add(&[2, 2, 2]).unwrap(); - scheduler.insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), second_addr); + scheduler + .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), second_addr) + .expect("insertion failed"); let mut i = 0; let mut test_closure = |boolvar: bool, store_addr: &StoreAddr| { @@ -572,10 +562,14 @@ mod tests { let first_addr = pool.add(&[2, 2, 2]).unwrap(); - scheduler.insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), first_addr); + scheduler + .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(100), first_addr) + .expect("insertion failed"); let second_addr = pool.add(&[5, 6, 7]).unwrap(); - scheduler.insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), second_addr); + scheduler + .insert_unwrapped_and_stored_tc(UnixTimestamp::new_only_seconds(200), second_addr) + .expect("insertion failed"); let mut i = 0; let mut test_closure_1 = |boolvar: bool, store_addr: &StoreAddr| { diff --git a/satrs-core/src/pus/verification.rs b/satrs-core/src/pus/verification.rs index 5c7a4c7..4da2a09 100644 --- a/satrs-core/src/pus/verification.rs +++ b/satrs-core/src/pus/verification.rs @@ -88,6 +88,7 @@ use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl}; use spacepackets::{SpHeader, MAX_APID}; pub use crate::seq_count::SeqCountProviderSimple; +pub use spacepackets::ecss::verification::*; #[cfg(feature = "alloc")] pub use alloc_mod::{ @@ -103,24 +104,6 @@ pub use stdmod::{ StdVerifSenderError, }; -#[derive(Debug, Eq, PartialEq, Copy, Clone)] -pub enum Subservice { - TmAcceptanceSuccess = 1, - TmAcceptanceFailure = 2, - TmStartSuccess = 3, - TmStartFailure = 4, - TmStepSuccess = 5, - TmStepFailure = 6, - TmCompletionSuccess = 7, - TmCompletionFailure = 8, -} - -impl From for u8 { - fn from(enumeration: Subservice) -> Self { - enumeration as u8 - } -} - /// This is a request identifier as specified in 5.4.11.2 c. of the PUS standard /// This field equivalent to the first two bytes of the CCSDS space packet header. #[derive(Debug, Eq, Copy, Clone)] diff --git a/satrs-example/src/main.rs b/satrs-example/src/main.rs index 32cc6e6..dfe78aa 100644 --- a/satrs-example/src/main.rs +++ b/satrs-example/src/main.rs @@ -18,7 +18,7 @@ use satrs_core::pus::event_man::{ DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken, PusEventDispatcher, }; -use satrs_core::pus::hk::Subservice; +use satrs_core::pus::hk::Subservice as HkSubservice; use satrs_core::pus::verification::{ MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, }; @@ -229,7 +229,7 @@ fn main() { .unwrap(); let sec_header = PusTmSecondaryHeader::new_simple( 3, - Subservice::TmHkPacket as u8, + HkSubservice::TmHkPacket as u8, ×tamp, ); let mut buf: [u8; 8] = [0; 8]; diff --git a/satrs-example/src/pus.rs b/satrs-example/src/pus.rs index a889704..6f9a9ec 100644 --- a/satrs-example/src/pus.rs +++ b/satrs-example/src/pus.rs @@ -3,7 +3,7 @@ use crate::requests::{Request, RequestWithToken}; use crate::tmtc::{PusTcSource, TmStore}; use satrs_core::events::EventU32; use satrs_core::pool::StoreAddr; -use satrs_core::pus::event::Subservices; +use satrs_core::pus::event; use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken}; use satrs_core::pus::hk; use satrs_core::pus::scheduling::PusScheduler; @@ -37,28 +37,37 @@ pub struct PusReceiver { scheduler: Rc>, } +pub struct PusTmArgs { + /// All telemetry is sent with this sender handle. + pub tm_tx: Sender, + /// All TM to be sent is stored here + pub tm_store: TmStore, + /// All verification reporting is done with this reporter. + pub verif_reporter: StdVerifReporterWithSender, +} + +pub struct PusTcArgs { + pub event_request_tx: Sender, + /// Request routing helper. Maps targeted request to their recipient. + pub request_map: HashMap>, + /// Required for scheduling of telecommands. + pub tc_source: PusTcSource, + pub scheduler: Rc>, +} + impl PusReceiver { - pub fn new( - apid: u16, - tm_tx: Sender, - tm_store: TmStore, - verif_reporter: StdVerifReporterWithSender, - tc_source: PusTcSource, - event_request_tx: Sender, - request_map: HashMap>, - scheduler: Rc>, - ) -> Self { + pub fn new(apid: u16, tm_arguments: PusTmArgs, tc_arguments: PusTcArgs) -> Self { Self { tm_helper: PusTmWithCdsShortHelper::new(apid), - tm_tx, - tm_store, - verif_reporter, - tc_source, - event_request_tx, - request_map, + tm_tx: tm_arguments.tm_tx, + tm_store: tm_arguments.tm_store, + verif_reporter: tm_arguments.verif_reporter, + tc_source: tc_arguments.tc_source, + event_request_tx: tc_arguments.event_request_tx, + request_map: tc_arguments.request_map, stamper: TimeProvider::new_with_u16_days(0, 0), time_stamp: [0; 7], - scheduler, + scheduler: tc_arguments.scheduler, } } } @@ -251,7 +260,7 @@ impl PusReceiver { } let event_id = EventU32::from(u32::from_be_bytes(app_data.try_into().unwrap())); match PusPacket::subservice(pus_tc).try_into() { - Ok(Subservices::TcEnableEventGeneration) => { + Ok(event::Subservice::TcEnableEventGeneration) => { self.update_time_stamp(); let start_token = send_start_acceptance(&mut self.verif_reporter, &self.time_stamp); self.event_request_tx @@ -261,7 +270,7 @@ impl PusReceiver { }) .expect("Sending event request failed"); } - Ok(Subservices::TcDisableEventGeneration) => { + Ok(event::Subservice::TcDisableEventGeneration) => { self.update_time_stamp(); let start_token = send_start_acceptance(&mut self.verif_reporter, &self.time_stamp); self.event_request_tx diff --git a/satrs-example/src/tmtc.rs b/satrs-example/src/tmtc.rs index c93602f..ed1df1a 100644 --- a/satrs-example/src/tmtc.rs +++ b/satrs-example/src/tmtc.rs @@ -12,7 +12,7 @@ use std::thread; use std::time::Duration; use crate::ccsds::CcsdsReceiver; -use crate::pus::PusReceiver; +use crate::pus::{PusReceiver, PusTcArgs, PusTmArgs}; use crate::requests::RequestWithToken; use satrs_core::pool::{SharedPool, StoreAddr, StoreError}; use satrs_core::pus::event_man::EventRequestWithToken; @@ -167,16 +167,18 @@ pub fn core_tmtc_task(args: OtherArgs, mut tc_args: TcArgs, tm_args: TmArgs) { )); let sched_clone = scheduler.clone(); - let mut pus_receiver = PusReceiver::new( - PUS_APID, - tm_args.tm_sink_sender, - tm_args.tm_store.clone(), - args.verif_reporter, - tc_args.tc_source.clone(), - args.event_request_tx, - args.request_map, - sched_clone, - ); + let pus_tm_args = PusTmArgs { + tm_tx: tm_args.tm_sink_sender, + tm_store: tm_args.tm_store.clone(), + verif_reporter: args.verif_reporter, + }; + let pus_tc_args = PusTcArgs { + event_request_tx: args.event_request_tx, + request_map: args.request_map, + tc_source: tc_args.tc_source.clone(), + scheduler: sched_clone, + }; + let mut pus_receiver = PusReceiver::new(PUS_APID, pus_tm_args, pus_tc_args); let ccsds_receiver = CcsdsReceiver { tc_source: tc_args.tc_source.clone(), @@ -234,13 +236,10 @@ fn core_tmtc_loop( let mut scheduler = scheduler.borrow_mut(); scheduler.update_time_from_now().unwrap(); - match scheduler.release_telecommands(releaser, pool.as_mut()) { - Ok(released_tcs) => { - if released_tcs > 0 { - println!("{} Tc(s) released from scheduler", released_tcs); - } + if let Ok(released_tcs) = scheduler.release_telecommands(releaser, pool.as_mut()) { + if released_tcs > 0 { + println!("{} Tc(s) released from scheduler", released_tcs); } - Err(_) => {} } drop(pool); drop(scheduler);