diff --git a/fsrc-core/src/lib.rs b/fsrc-core/src/lib.rs index 70d4b93..02298a0 100644 --- a/fsrc-core/src/lib.rs +++ b/fsrc-core/src/lib.rs @@ -23,6 +23,7 @@ pub mod hal; pub mod objects; #[cfg(feature = "alloc")] pub mod pool; +pub mod pus; pub mod tmtc; extern crate downcast_rs; diff --git a/fsrc-core/src/pus/mod.rs b/fsrc-core/src/pus/mod.rs new file mode 100644 index 0000000..20c53ec --- /dev/null +++ b/fsrc-core/src/pus/mod.rs @@ -0,0 +1,11 @@ +use crate::pool::StoreError; +use spacepackets::time::TimestampError; + +pub mod verification; + +#[derive(Debug, Copy, Clone)] +pub enum SendStoredTmError { + SendError(E), + TimeStampError(TimestampError), + StoreError(StoreError), +} diff --git a/fsrc-core/src/pus/verification.rs b/fsrc-core/src/pus/verification.rs new file mode 100644 index 0000000..b750f27 --- /dev/null +++ b/fsrc-core/src/pus/verification.rs @@ -0,0 +1,140 @@ +use crate::pus::SendStoredTmError; +use alloc::boxed::Box; +use alloc::vec::Vec; +use spacepackets::tc::PusTc; +use spacepackets::time::{TimeWriter, TimestampError}; +use spacepackets::tm::{PusTm, PusTmSecondaryHeader}; +use spacepackets::SpHeader; +use spacepackets::{CcsdsPacket, PacketId, PacketSequenceCtrl}; +use std::marker::PhantomData; + +#[derive(Debug, Eq, PartialEq, Copy, Clone)] +pub struct RequestId { + version_number: u8, + packet_id: PacketId, + psc: PacketSequenceCtrl, +} + +impl RequestId { + pub fn new(tc: &PusTc) -> Self { + RequestId { + version_number: tc.ccsds_version(), + packet_id: tc.packet_id(), + psc: tc.psc(), + } + } +} + +pub trait VerificationSender { + fn send_verification_tm(&mut self, tm: PusTm) -> Result<(), SendStoredTmError>; +} + +pub struct VerificationReporter { + apid: u16, + msg_count: u16, + dest_id: u16, + time_stamper: Box, + time_stamp_buf: Vec, +} + +impl VerificationReporter { + pub fn add_tc(&mut self, req_id: RequestId) -> VerificationToken { + VerificationToken::::new(req_id) + } + + pub fn acceptance_success( + &mut self, + token: VerificationToken, + sender: &mut impl VerificationSender, + ) -> Result, SendStoredTmError> { + let tm = self + .create_tm(1, 1) + .map_err(|e| SendStoredTmError::TimeStampError(e))?; + sender.send_verification_tm(tm)?; + self.msg_count += 1; + Ok(VerificationToken { + state: PhantomData, + req_id: token.req_id, + }) + } + + pub fn acceptance_failure(self, _token: VerificationToken) { + unimplemented!(); + } + + pub fn start_success( + &mut self, + token: VerificationToken, + ) -> VerificationToken { + VerificationToken { + state: PhantomData, + req_id: token.req_id, + } + } + + pub fn start_failure(&mut self, _token: VerificationToken) { + unimplemented!(); + } + + pub fn step_success(&mut self, _token: &VerificationToken) { + unimplemented!(); + } + + pub fn step_failure(&mut self, _token: VerificationToken) { + unimplemented!(); + } + + pub fn completion_success(&mut self, _token: VerificationToken) { + unimplemented!(); + } + pub fn completion_failure(&mut self, _token: VerificationToken) { + unimplemented!(); + } + + fn create_tm(&mut self, service: u8, subservice: u8) -> Result { + let mut sp_header = SpHeader::tm(self.apid, 0, 0).unwrap(); + // I think it is okay to panic here. This error should never happen, I consider + // this a configuration error. + self.time_stamper + .write_to_bytes(self.time_stamp_buf.as_mut_slice())?; + let tm_sec_header = PusTmSecondaryHeader::new( + service, + subservice, + self.msg_count, + self.dest_id, + &self.time_stamp_buf, + ); + Ok(PusTm::new(&mut sp_header, tm_sec_header, None, true)) + } +} + +pub struct VerificationToken { + state: PhantomData, + req_id: RequestId, +} + +pub struct StateNone; +pub struct StateAccepted; +pub struct StateStarted; + +impl VerificationToken { + fn new(req_id: RequestId) -> VerificationToken { + VerificationToken { + state: PhantomData, + req_id, + } + } +} + +#[cfg(test)] +mod tests { + use crate::pus::verification::VerificationToken; + + #[test] + pub fn test_basic_type_state() { + //let mut reporter = VerificationToken::new(); + //let mut accepted = reporter.acceptance_success(); + //let started = accepted.start_success(); + //started.completion_success(); + } +} diff --git a/spacepackets b/spacepackets index 42d3487..96d389a 160000 --- a/spacepackets +++ b/spacepackets @@ -1 +1 @@ -Subproject commit 42d3487c1934cfecf9b2d599c2f81fde52a61cc3 +Subproject commit 96d389a6515f763f179c23742a9f578659ae9509