bump spacepackets, clippy fixes

This commit is contained in:
Robin Müller 2023-02-04 15:35:18 +01:00
parent 44ce25cd82
commit 7dbbd18be4
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
8 changed files with 85 additions and 155 deletions

View File

@ -53,10 +53,10 @@ default-features = false
optional = true optional = true
[dependencies.spacepackets] [dependencies.spacepackets]
version = "0.5.2" # version = "0.5.2"
# path = "../spacepackets" # path = "../spacepackets"
# git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git" git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git"
# rev = "..." rev = "cfa5f8099c95389628440a1611766e3b178fcdb3"
default-features = false default-features = false

View File

@ -7,56 +7,8 @@ use spacepackets::{SpHeader, MAX_APID};
use crate::pus::EcssTmSenderCore; use crate::pus::EcssTmSenderCore;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use allocvec::EventReporter; 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<Subservices> for u8 {
fn from(enumeration: Subservices) -> Self {
enumeration as u8
}
}
impl TryFrom<u8> for Subservices {
type Error = ();
fn try_from(value: u8) -> Result<Self, Self::Error> {
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 { pub struct EventReporterBase {
msg_count: u16, msg_count: u16,
apid: u16, apid: u16,
@ -85,7 +37,7 @@ impl EventReporterBase {
) -> Result<(), EcssTmErrorWithSend<E>> { ) -> Result<(), EcssTmErrorWithSend<E>> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, buf,
Subservices::TmInfoReport, Subservice::TmInfoReport,
sender, sender,
time_stamp, time_stamp,
event_id, event_id,
@ -103,7 +55,7 @@ impl EventReporterBase {
) -> Result<(), EcssTmErrorWithSend<E>> { ) -> Result<(), EcssTmErrorWithSend<E>> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, buf,
Subservices::TmLowSeverityReport, Subservice::TmLowSeverityReport,
sender, sender,
time_stamp, time_stamp,
event_id, event_id,
@ -121,7 +73,7 @@ impl EventReporterBase {
) -> Result<(), EcssTmErrorWithSend<E>> { ) -> Result<(), EcssTmErrorWithSend<E>> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, buf,
Subservices::TmMediumSeverityReport, Subservice::TmMediumSeverityReport,
sender, sender,
time_stamp, time_stamp,
event_id, event_id,
@ -139,7 +91,7 @@ impl EventReporterBase {
) -> Result<(), EcssTmErrorWithSend<E>> { ) -> Result<(), EcssTmErrorWithSend<E>> {
self.generate_and_send_generic_tm( self.generate_and_send_generic_tm(
buf, buf,
Subservices::TmHighSeverityReport, Subservice::TmHighSeverityReport,
sender, sender,
time_stamp, time_stamp,
event_id, event_id,
@ -150,7 +102,7 @@ impl EventReporterBase {
fn generate_and_send_generic_tm<E>( fn generate_and_send_generic_tm<E>(
&mut self, &mut self,
buf: &mut [u8], buf: &mut [u8],
subservice: Subservices, subservice: Subservice,
sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized), sender: &mut (impl EcssTmSenderCore<Error = E> + ?Sized),
time_stamp: &[u8], time_stamp: &[u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
@ -165,7 +117,7 @@ impl EventReporterBase {
fn generate_generic_event_tm<'a>( fn generate_generic_event_tm<'a>(
&'a self, &'a self,
buf: &'a mut [u8], buf: &'a mut [u8],
subservice: Subservices, subservice: Subservice,
time_stamp: &'a [u8], time_stamp: &'a [u8],
event_id: impl EcssEnumeration, event_id: impl EcssEnumeration,
aux_data: Option<&[u8]>, 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 { match severity {
Severity::INFO => Subservices::TmInfoReport, Severity::INFO => Subservice::TmInfoReport,
Severity::LOW => Subservices::TmLowSeverityReport, Severity::LOW => Subservice::TmLowSeverityReport,
Severity::MEDIUM => Subservices::TmMediumSeverityReport, Severity::MEDIUM => Subservice::TmMediumSeverityReport,
Severity::HIGH => Subservices::TmHighSeverityReport, Severity::HIGH => Subservice::TmHighSeverityReport,
} }
} }

View File

@ -1,8 +1 @@
#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub use spacepackets::ecss::hk::*;
pub enum Subservice {
TcEnableGeneration = 5,
TcDisableGeneration = 6,
TmHkPacket = 25,
TcGenerateOneShotHk = 27,
TcModifyCollectionInterval = 31,
}

View File

@ -83,16 +83,6 @@ impl From<TimestampError> for ScheduleError {
#[cfg(feature = "std")] #[cfg(feature = "std")]
impl Error for ScheduleError {} 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. /// 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 /// It is assumed that the actual telecommand data is stored in a separate TC pool offering
@ -323,17 +313,9 @@ impl PusScheduler {
mod tests { mod tests {
use crate::pool::{LocalPool, PoolCfg, PoolProvider, StoreAddr}; use crate::pool::{LocalPool, PoolCfg, PoolProvider, StoreAddr};
use crate::pus::scheduling::{PusScheduler, ScheduleError}; 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::tc::PusTc;
use spacepackets::time::{cds, TimeWriter, UnixTimestamp}; use spacepackets::time::{cds, TimeWriter, UnixTimestamp};
use spacepackets::{CcsdsPacket, SpHeader}; use spacepackets::SpHeader;
use std::cell::RefCell;
use std::sync::mpsc;
use std::sync::mpsc::{channel, Receiver, TryRecvError};
use std::time::Duration; use std::time::Duration;
use std::vec::Vec; use std::vec::Vec;
#[allow(unused_imports)] #[allow(unused_imports)]
@ -404,7 +386,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let worked = scheduler scheduler
.insert_unwrapped_and_stored_tc( .insert_unwrapped_and_stored_tc(
UnixTimestamp::new_only_seconds(100), UnixTimestamp::new_only_seconds(100),
StoreAddr { StoreAddr {
@ -414,7 +396,7 @@ mod tests {
) )
.unwrap(); .unwrap();
let worked = scheduler scheduler
.insert_unwrapped_and_stored_tc( .insert_unwrapped_and_stored_tc(
UnixTimestamp::new_only_seconds(300), UnixTimestamp::new_only_seconds(300),
StoreAddr { StoreAddr {
@ -465,10 +447,14 @@ mod tests {
let first_addr = pool.add(&[2, 2, 2]).unwrap(); 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(); 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 i = 0;
let mut test_closure_1 = |boolvar: bool, store_addr: &StoreAddr| { 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(); 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(); 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 i = 0;
let mut test_closure = |boolvar: bool, store_addr: &StoreAddr| { let mut test_closure = |boolvar: bool, store_addr: &StoreAddr| {
@ -572,10 +562,14 @@ mod tests {
let first_addr = pool.add(&[2, 2, 2]).unwrap(); 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(); 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 i = 0;
let mut test_closure_1 = |boolvar: bool, store_addr: &StoreAddr| { let mut test_closure_1 = |boolvar: bool, store_addr: &StoreAddr| {

View File

@ -88,6 +88,7 @@ use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl};
use spacepackets::{SpHeader, MAX_APID}; use spacepackets::{SpHeader, MAX_APID};
pub use crate::seq_count::SeqCountProviderSimple; pub use crate::seq_count::SeqCountProviderSimple;
pub use spacepackets::ecss::verification::*;
#[cfg(feature = "alloc")] #[cfg(feature = "alloc")]
pub use alloc_mod::{ pub use alloc_mod::{
@ -103,24 +104,6 @@ pub use stdmod::{
StdVerifSenderError, 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<Subservice> 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 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. /// This field equivalent to the first two bytes of the CCSDS space packet header.
#[derive(Debug, Eq, Copy, Clone)] #[derive(Debug, Eq, Copy, Clone)]

View File

@ -18,7 +18,7 @@ use satrs_core::pus::event_man::{
DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken, DefaultPusMgmtBackendProvider, EventReporter, EventRequest, EventRequestWithToken,
PusEventDispatcher, PusEventDispatcher,
}; };
use satrs_core::pus::hk::Subservice; use satrs_core::pus::hk::Subservice as HkSubservice;
use satrs_core::pus::verification::{ use satrs_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender, MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
}; };
@ -229,7 +229,7 @@ fn main() {
.unwrap(); .unwrap();
let sec_header = PusTmSecondaryHeader::new_simple( let sec_header = PusTmSecondaryHeader::new_simple(
3, 3,
Subservice::TmHkPacket as u8, HkSubservice::TmHkPacket as u8,
&timestamp, &timestamp,
); );
let mut buf: [u8; 8] = [0; 8]; let mut buf: [u8; 8] = [0; 8];

View File

@ -3,7 +3,7 @@ use crate::requests::{Request, RequestWithToken};
use crate::tmtc::{PusTcSource, TmStore}; use crate::tmtc::{PusTcSource, TmStore};
use satrs_core::events::EventU32; use satrs_core::events::EventU32;
use satrs_core::pool::StoreAddr; 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::event_man::{EventRequest, EventRequestWithToken};
use satrs_core::pus::hk; use satrs_core::pus::hk;
use satrs_core::pus::scheduling::PusScheduler; use satrs_core::pus::scheduling::PusScheduler;
@ -37,28 +37,37 @@ pub struct PusReceiver {
scheduler: Rc<RefCell<PusScheduler>>, scheduler: Rc<RefCell<PusScheduler>>,
} }
pub struct PusTmArgs {
/// All telemetry is sent with this sender handle.
pub tm_tx: Sender<StoreAddr>,
/// 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<EventRequestWithToken>,
/// Request routing helper. Maps targeted request to their recipient.
pub request_map: HashMap<u32, Sender<RequestWithToken>>,
/// Required for scheduling of telecommands.
pub tc_source: PusTcSource,
pub scheduler: Rc<RefCell<PusScheduler>>,
}
impl PusReceiver { impl PusReceiver {
pub fn new( pub fn new(apid: u16, tm_arguments: PusTmArgs, tc_arguments: PusTcArgs) -> Self {
apid: u16,
tm_tx: Sender<StoreAddr>,
tm_store: TmStore,
verif_reporter: StdVerifReporterWithSender,
tc_source: PusTcSource,
event_request_tx: Sender<EventRequestWithToken>,
request_map: HashMap<u32, Sender<RequestWithToken>>,
scheduler: Rc<RefCell<PusScheduler>>,
) -> Self {
Self { Self {
tm_helper: PusTmWithCdsShortHelper::new(apid), tm_helper: PusTmWithCdsShortHelper::new(apid),
tm_tx, tm_tx: tm_arguments.tm_tx,
tm_store, tm_store: tm_arguments.tm_store,
verif_reporter, verif_reporter: tm_arguments.verif_reporter,
tc_source, tc_source: tc_arguments.tc_source,
event_request_tx, event_request_tx: tc_arguments.event_request_tx,
request_map, request_map: tc_arguments.request_map,
stamper: TimeProvider::new_with_u16_days(0, 0), stamper: TimeProvider::new_with_u16_days(0, 0),
time_stamp: [0; 7], 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())); let event_id = EventU32::from(u32::from_be_bytes(app_data.try_into().unwrap()));
match PusPacket::subservice(pus_tc).try_into() { match PusPacket::subservice(pus_tc).try_into() {
Ok(Subservices::TcEnableEventGeneration) => { Ok(event::Subservice::TcEnableEventGeneration) => {
self.update_time_stamp(); self.update_time_stamp();
let start_token = send_start_acceptance(&mut self.verif_reporter, &self.time_stamp); let start_token = send_start_acceptance(&mut self.verif_reporter, &self.time_stamp);
self.event_request_tx self.event_request_tx
@ -261,7 +270,7 @@ impl PusReceiver {
}) })
.expect("Sending event request failed"); .expect("Sending event request failed");
} }
Ok(Subservices::TcDisableEventGeneration) => { Ok(event::Subservice::TcDisableEventGeneration) => {
self.update_time_stamp(); self.update_time_stamp();
let start_token = send_start_acceptance(&mut self.verif_reporter, &self.time_stamp); let start_token = send_start_acceptance(&mut self.verif_reporter, &self.time_stamp);
self.event_request_tx self.event_request_tx

View File

@ -12,7 +12,7 @@ use std::thread;
use std::time::Duration; use std::time::Duration;
use crate::ccsds::CcsdsReceiver; use crate::ccsds::CcsdsReceiver;
use crate::pus::PusReceiver; use crate::pus::{PusReceiver, PusTcArgs, PusTmArgs};
use crate::requests::RequestWithToken; use crate::requests::RequestWithToken;
use satrs_core::pool::{SharedPool, StoreAddr, StoreError}; use satrs_core::pool::{SharedPool, StoreAddr, StoreError};
use satrs_core::pus::event_man::EventRequestWithToken; 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 sched_clone = scheduler.clone();
let mut pus_receiver = PusReceiver::new( let pus_tm_args = PusTmArgs {
PUS_APID, tm_tx: tm_args.tm_sink_sender,
tm_args.tm_sink_sender, tm_store: tm_args.tm_store.clone(),
tm_args.tm_store.clone(), verif_reporter: args.verif_reporter,
args.verif_reporter, };
tc_args.tc_source.clone(), let pus_tc_args = PusTcArgs {
args.event_request_tx, event_request_tx: args.event_request_tx,
args.request_map, request_map: args.request_map,
sched_clone, 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 { let ccsds_receiver = CcsdsReceiver {
tc_source: tc_args.tc_source.clone(), tc_source: tc_args.tc_source.clone(),
@ -234,14 +236,11 @@ fn core_tmtc_loop(
let mut scheduler = scheduler.borrow_mut(); let mut scheduler = scheduler.borrow_mut();
scheduler.update_time_from_now().unwrap(); scheduler.update_time_from_now().unwrap();
match scheduler.release_telecommands(releaser, pool.as_mut()) { if let Ok(released_tcs) = scheduler.release_telecommands(releaser, pool.as_mut()) {
Ok(released_tcs) => {
if released_tcs > 0 { if released_tcs > 0 {
println!("{} Tc(s) released from scheduler", released_tcs); println!("{} Tc(s) released from scheduler", released_tcs);
} }
} }
Err(_) => {}
}
drop(pool); drop(pool);
drop(scheduler); drop(scheduler);