allow type/lifetime/ref erasure
This commit is contained in:
parent
9b4ada9bcb
commit
86710efc56
@ -302,12 +302,94 @@ pub struct VerificationReporterCore {
|
|||||||
apid: u16,
|
apid: u16,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VerificationSendable<'slice, State> {
|
pub struct VerificationSendableErased<State> {
|
||||||
token: Option<VerificationToken<State>>,
|
token: Option<VerificationToken<State>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn increment_seq_counter(
|
||||||
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
|
) {
|
||||||
|
if let Some(seq_counter) = seq_counter {
|
||||||
|
seq_counter.increment();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<State> VerificationSendableErased<State> {
|
||||||
|
pub fn send_success_verif_failure(
|
||||||
|
self,
|
||||||
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
|
) {
|
||||||
|
increment_seq_counter(seq_counter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl VerificationSendableErased<TcStateNone> {
|
||||||
|
pub fn send_success_acceptance_success(
|
||||||
|
self,
|
||||||
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
|
) -> VerificationToken<TcStateAccepted> {
|
||||||
|
increment_seq_counter(seq_counter);
|
||||||
|
VerificationToken {
|
||||||
|
state: PhantomData,
|
||||||
|
req_id: self.token.unwrap().req_id(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn send_failure(self) -> VerificationToken<TcStateNone> {
|
||||||
|
self.token.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VerificationSendableErased<TcStateAccepted> {
|
||||||
|
pub fn send_success_start_success(
|
||||||
|
self,
|
||||||
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
|
) -> VerificationToken<TcStateStarted> {
|
||||||
|
increment_seq_counter(seq_counter);
|
||||||
|
VerificationToken {
|
||||||
|
state: PhantomData,
|
||||||
|
req_id: self.token.unwrap().req_id(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn send_failure(self) -> VerificationToken<TcStateAccepted> {
|
||||||
|
self.token.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl VerificationSendableErased<TcStateStarted> {
|
||||||
|
pub fn send_success_step_or_completion_success(
|
||||||
|
self,
|
||||||
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
|
) {
|
||||||
|
increment_seq_counter(seq_counter);
|
||||||
|
}
|
||||||
|
pub fn send_failure(self) -> Option<VerificationToken<TcStateStarted>> {
|
||||||
|
self.token
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct VerificationSendable<'slice, State> {
|
||||||
|
inner: VerificationSendableErased<State>,
|
||||||
pus_tm: Option<PusTm<'slice>>,
|
pus_tm: Option<PusTm<'slice>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<State> From<VerificationSendable<'_, State>> for VerificationSendableErased<State> {
|
||||||
|
fn from(value: VerificationSendable<State>) -> Self {
|
||||||
|
value.inner
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'slice, State> VerificationSendable<'slice, State> {
|
impl<'slice, State> VerificationSendable<'slice, State> {
|
||||||
|
pub(crate) fn new(pus_tm: PusTm<'slice>, token: VerificationToken<State>) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: VerificationSendableErased { token: Some(token) },
|
||||||
|
pus_tm: Some(pus_tm),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub(crate) fn new_no_token(pus_tm: PusTm<'slice>) -> Self {
|
||||||
|
Self {
|
||||||
|
inner: VerificationSendableErased { token: None },
|
||||||
|
pus_tm: Some(pus_tm),
|
||||||
|
}
|
||||||
|
}
|
||||||
pub fn pus_tm(&self) -> &PusTm<'slice> {
|
pub fn pus_tm(&self) -> &PusTm<'slice> {
|
||||||
self.pus_tm.as_ref().unwrap()
|
self.pus_tm.as_ref().unwrap()
|
||||||
}
|
}
|
||||||
@ -316,23 +398,19 @@ impl<'slice, State> VerificationSendable<'slice, State> {
|
|||||||
self.pus_tm.as_mut().unwrap()
|
self.pus_tm.as_mut().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn downgrade(self) -> VerificationSendableErased<State> {
|
||||||
|
self.into()
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn take_tm(&mut self) -> PusTm<'slice> {
|
pub(crate) fn take_tm(&mut self) -> PusTm<'slice> {
|
||||||
self.pus_tm.take().unwrap()
|
self.pus_tm.take().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn increment_seq_counter(
|
|
||||||
&self,
|
|
||||||
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
|
||||||
) {
|
|
||||||
if let Some(seq_counter) = seq_counter {
|
|
||||||
seq_counter.increment();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn send_success_verif_failure(
|
pub fn send_success_verif_failure(
|
||||||
self,
|
self,
|
||||||
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
) {
|
) {
|
||||||
self.increment_seq_counter(seq_counter);
|
self.inner.send_success_verif_failure(seq_counter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,14 +419,10 @@ impl<'slice> VerificationSendable<'slice, TcStateNone> {
|
|||||||
self,
|
self,
|
||||||
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
) -> VerificationToken<TcStateAccepted> {
|
) -> VerificationToken<TcStateAccepted> {
|
||||||
self.increment_seq_counter(seq_counter);
|
self.inner.send_success_acceptance_success(seq_counter)
|
||||||
VerificationToken {
|
|
||||||
state: PhantomData,
|
|
||||||
req_id: self.token.unwrap().req_id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
pub fn send_failure(self) -> (PusTm<'slice>, VerificationToken<TcStateNone>) {
|
pub fn send_failure(self) -> (PusTm<'slice>, VerificationToken<TcStateNone>) {
|
||||||
(self.pus_tm.unwrap(), self.token.unwrap())
|
(self.pus_tm.unwrap(), self.inner.token.unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -357,14 +431,11 @@ impl<'slice> VerificationSendable<'slice, TcStateAccepted> {
|
|||||||
self,
|
self,
|
||||||
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
) -> VerificationToken<TcStateStarted> {
|
) -> VerificationToken<TcStateStarted> {
|
||||||
self.increment_seq_counter(seq_counter);
|
self.inner.send_success_start_success(seq_counter)
|
||||||
VerificationToken {
|
|
||||||
state: PhantomData,
|
|
||||||
req_id: self.token.unwrap().req_id(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_failure(self) -> (PusTm<'slice>, VerificationToken<TcStateAccepted>) {
|
pub fn send_failure(self) -> (PusTm<'slice>, VerificationToken<TcStateAccepted>) {
|
||||||
(self.pus_tm.unwrap(), self.token.unwrap())
|
(self.pus_tm.unwrap(), self.inner.token.unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,10 +444,10 @@ impl<'slice> VerificationSendable<'slice, TcStateStarted> {
|
|||||||
self,
|
self,
|
||||||
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
seq_counter: Option<&(impl SequenceCountProviderCore<u16> + ?Sized)>,
|
||||||
) {
|
) {
|
||||||
self.increment_seq_counter(seq_counter);
|
increment_seq_counter(seq_counter);
|
||||||
}
|
}
|
||||||
pub fn send_failure(self) -> (PusTm<'slice>, Option<VerificationToken<TcStateStarted>>) {
|
pub fn send_failure(self) -> (PusTm<'slice>, Option<VerificationToken<TcStateStarted>>) {
|
||||||
(self.pus_tm.unwrap(), self.token)
|
(self.pus_tm.unwrap(), self.inner.token)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,8 +499,7 @@ impl VerificationReporterCore {
|
|||||||
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
seq_counter: &(impl SequenceCountProviderCore<u16> + ?Sized),
|
||||||
time_stamp: &'slice [u8],
|
time_stamp: &'slice [u8],
|
||||||
) -> Result<VerificationSendable<'slice, State>, VerificationErrorWithToken<State>> {
|
) -> Result<VerificationSendable<'slice, State>, VerificationErrorWithToken<State>> {
|
||||||
Ok(VerificationSendable {
|
Ok(VerificationSendable::new(
|
||||||
pus_tm: Some(
|
|
||||||
self.create_pus_verif_success_tm(
|
self.create_pus_verif_success_tm(
|
||||||
buf,
|
buf,
|
||||||
subservice,
|
subservice,
|
||||||
@ -439,9 +509,8 @@ impl VerificationReporterCore {
|
|||||||
None::<&dyn EcssEnumeration>,
|
None::<&dyn EcssEnumeration>,
|
||||||
)
|
)
|
||||||
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
||||||
),
|
token,
|
||||||
token: Some(token),
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Package a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard.
|
/// Package a PUS TM\[1, 1\] packet, see 8.1.2.1 of the PUS standard.
|
||||||
@ -471,8 +540,7 @@ impl VerificationReporterCore {
|
|||||||
params: FailParams<'slice, '_>,
|
params: FailParams<'slice, '_>,
|
||||||
) -> Result<VerificationSendable<'slice, TcStateNone>, VerificationErrorWithToken<TcStateNone>>
|
) -> Result<VerificationSendable<'slice, TcStateNone>, VerificationErrorWithToken<TcStateNone>>
|
||||||
{
|
{
|
||||||
Ok(VerificationSendable {
|
Ok(VerificationSendable::new(
|
||||||
pus_tm: Some(
|
|
||||||
self.create_pus_verif_fail_tm(
|
self.create_pus_verif_fail_tm(
|
||||||
buf,
|
buf,
|
||||||
Subservice::TmAcceptanceFailure.into(),
|
Subservice::TmAcceptanceFailure.into(),
|
||||||
@ -482,9 +550,8 @@ impl VerificationReporterCore {
|
|||||||
¶ms,
|
¶ms,
|
||||||
)
|
)
|
||||||
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
||||||
),
|
token,
|
||||||
token: Some(token),
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard.
|
/// Package and send a PUS TM\[1, 3\] packet, see 8.1.2.3 of the PUS standard.
|
||||||
@ -523,8 +590,7 @@ impl VerificationReporterCore {
|
|||||||
VerificationSendable<'slice, TcStateAccepted>,
|
VerificationSendable<'slice, TcStateAccepted>,
|
||||||
VerificationErrorWithToken<TcStateAccepted>,
|
VerificationErrorWithToken<TcStateAccepted>,
|
||||||
> {
|
> {
|
||||||
Ok(VerificationSendable {
|
Ok(VerificationSendable::new(
|
||||||
pus_tm: Some(
|
|
||||||
self.create_pus_verif_fail_tm(
|
self.create_pus_verif_fail_tm(
|
||||||
buf,
|
buf,
|
||||||
Subservice::TmStartFailure.into(),
|
Subservice::TmStartFailure.into(),
|
||||||
@ -534,9 +600,8 @@ impl VerificationReporterCore {
|
|||||||
¶ms,
|
¶ms,
|
||||||
)
|
)
|
||||||
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
||||||
),
|
token,
|
||||||
token: Some(token),
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard.
|
/// Package and send a PUS TM\[1, 5\] packet, see 8.1.2.5 of the PUS standard.
|
||||||
@ -550,17 +615,16 @@ impl VerificationReporterCore {
|
|||||||
time_stamp: &'slice [u8],
|
time_stamp: &'slice [u8],
|
||||||
step: impl EcssEnumeration,
|
step: impl EcssEnumeration,
|
||||||
) -> Result<VerificationSendable<'slice, TcStateStarted>, EcssTmError> {
|
) -> Result<VerificationSendable<'slice, TcStateStarted>, EcssTmError> {
|
||||||
Ok(VerificationSendable {
|
Ok(VerificationSendable::new_no_token(
|
||||||
pus_tm: Some(self.create_pus_verif_success_tm(
|
self.create_pus_verif_success_tm(
|
||||||
buf,
|
buf,
|
||||||
Subservice::TmStepSuccess.into(),
|
Subservice::TmStepSuccess.into(),
|
||||||
seq_counter.get(),
|
seq_counter.get(),
|
||||||
&token.req_id,
|
&token.req_id,
|
||||||
time_stamp,
|
time_stamp,
|
||||||
Some(&step),
|
Some(&step),
|
||||||
)?),
|
)?,
|
||||||
token: None,
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard.
|
/// Package and send a PUS TM\[1, 6\] packet, see 8.1.2.6 of the PUS standard.
|
||||||
@ -577,8 +641,7 @@ impl VerificationReporterCore {
|
|||||||
VerificationSendable<'slice, TcStateStarted>,
|
VerificationSendable<'slice, TcStateStarted>,
|
||||||
VerificationErrorWithToken<TcStateStarted>,
|
VerificationErrorWithToken<TcStateStarted>,
|
||||||
> {
|
> {
|
||||||
Ok(VerificationSendable {
|
Ok(VerificationSendable::new(
|
||||||
pus_tm: Some(
|
|
||||||
self.create_pus_verif_fail_tm(
|
self.create_pus_verif_fail_tm(
|
||||||
buf,
|
buf,
|
||||||
Subservice::TmStepFailure.into(),
|
Subservice::TmStepFailure.into(),
|
||||||
@ -588,9 +651,8 @@ impl VerificationReporterCore {
|
|||||||
¶ms.bp,
|
¶ms.bp,
|
||||||
)
|
)
|
||||||
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
||||||
),
|
token,
|
||||||
token: Some(token),
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard.
|
/// Package and send a PUS TM\[1, 7\] packet, see 8.1.2.7 of the PUS standard.
|
||||||
@ -630,8 +692,7 @@ impl VerificationReporterCore {
|
|||||||
VerificationSendable<'slice, TcStateStarted>,
|
VerificationSendable<'slice, TcStateStarted>,
|
||||||
VerificationErrorWithToken<TcStateStarted>,
|
VerificationErrorWithToken<TcStateStarted>,
|
||||||
> {
|
> {
|
||||||
Ok(VerificationSendable {
|
Ok(VerificationSendable::new(
|
||||||
pus_tm: Some(
|
|
||||||
self.create_pus_verif_fail_tm(
|
self.create_pus_verif_fail_tm(
|
||||||
buf,
|
buf,
|
||||||
Subservice::TmCompletionFailure.into(),
|
Subservice::TmCompletionFailure.into(),
|
||||||
@ -641,9 +702,8 @@ impl VerificationReporterCore {
|
|||||||
¶ms,
|
¶ms,
|
||||||
)
|
)
|
||||||
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
.map_err(|e| VerificationErrorWithToken(e, token))?,
|
||||||
),
|
token,
|
||||||
token: Some(token),
|
))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_pus_verif_success_tm<'slice>(
|
fn create_pus_verif_success_tm<'slice>(
|
||||||
|
Loading…
Reference in New Issue
Block a user