borrowing rules make this difficult

This commit is contained in:
Robin Müller 2022-09-03 16:30:37 +02:00
parent d3469f594d
commit 3c1ed36b11
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
4 changed files with 153 additions and 1 deletions

View File

@ -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;

11
fsrc-core/src/pus/mod.rs Normal file
View File

@ -0,0 +1,11 @@
use crate::pool::StoreError;
use spacepackets::time::TimestampError;
pub mod verification;
#[derive(Debug, Copy, Clone)]
pub enum SendStoredTmError<E> {
SendError(E),
TimeStampError(TimestampError),
StoreError(StoreError),
}

View File

@ -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<E> {
fn send_verification_tm(&mut self, tm: PusTm) -> Result<(), SendStoredTmError<E>>;
}
pub struct VerificationReporter {
apid: u16,
msg_count: u16,
dest_id: u16,
time_stamper: Box<dyn TimeWriter>,
time_stamp_buf: Vec<u8>,
}
impl VerificationReporter {
pub fn add_tc(&mut self, req_id: RequestId) -> VerificationToken<StateNone> {
VerificationToken::<StateNone>::new(req_id)
}
pub fn acceptance_success<E>(
&mut self,
token: VerificationToken<StateNone>,
sender: &mut impl VerificationSender<E>,
) -> Result<VerificationToken<StateAccepted>, SendStoredTmError<E>> {
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<StateNone>) {
unimplemented!();
}
pub fn start_success(
&mut self,
token: VerificationToken<StateAccepted>,
) -> VerificationToken<StateStarted> {
VerificationToken {
state: PhantomData,
req_id: token.req_id,
}
}
pub fn start_failure(&mut self, _token: VerificationToken<StateAccepted>) {
unimplemented!();
}
pub fn step_success(&mut self, _token: &VerificationToken<StateAccepted>) {
unimplemented!();
}
pub fn step_failure(&mut self, _token: VerificationToken<StateAccepted>) {
unimplemented!();
}
pub fn completion_success(&mut self, _token: VerificationToken<StateAccepted>) {
unimplemented!();
}
pub fn completion_failure(&mut self, _token: VerificationToken<StateAccepted>) {
unimplemented!();
}
fn create_tm(&mut self, service: u8, subservice: u8) -> Result<PusTm, TimestampError> {
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> {
state: PhantomData<STATE>,
req_id: RequestId,
}
pub struct StateNone;
pub struct StateAccepted;
pub struct StateStarted;
impl<STATE> VerificationToken<STATE> {
fn new(req_id: RequestId) -> VerificationToken<StateNone> {
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();
}
}

@ -1 +1 @@
Subproject commit 42d3487c1934cfecf9b2d599c2f81fde52a61cc3
Subproject commit 96d389a6515f763f179c23742a9f578659ae9509