add returncode module
This commit is contained in:
parent
2315012448
commit
7e0d3f394a
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -647,6 +647,7 @@ dependencies = [
|
|||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"delegate 0.8.0",
|
"delegate 0.8.0",
|
||||||
"satrs-core",
|
"satrs-core",
|
||||||
|
"satrs-macros",
|
||||||
"spacepackets",
|
"spacepackets",
|
||||||
"zerocopy",
|
"zerocopy",
|
||||||
]
|
]
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
use spacepackets::{ByteConversionError, SizeMissmatch};
|
||||||
|
use spacepackets::ecss::{EcssEnumeration, EcssEnumU16};
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub struct ResultU16 {
|
pub struct ResultU16 {
|
||||||
group_id: u8,
|
group_id: u8,
|
||||||
@ -22,6 +25,30 @@ impl ResultU16 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<ResultU16> for EcssEnumU16 {
|
||||||
|
fn from(v: ResultU16) -> Self {
|
||||||
|
EcssEnumU16::new(v.raw())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EcssEnumeration for ResultU16 {
|
||||||
|
fn pfc(&self) -> u8 {
|
||||||
|
16
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<(), ByteConversionError> {
|
||||||
|
if buf.len() < 2 {
|
||||||
|
return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch {
|
||||||
|
found: buf.len(),
|
||||||
|
expected: 2
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
buf[0] = self.group_id;
|
||||||
|
buf[1] = self.unique_id;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ResultU16Ext {
|
pub struct ResultU16Ext {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
@ -13,5 +13,8 @@ zerocopy = "0.6"
|
|||||||
[dependencies.spacepackets]
|
[dependencies.spacepackets]
|
||||||
path = "../spacepackets"
|
path = "../spacepackets"
|
||||||
|
|
||||||
|
[dependencies.satrs-macros]
|
||||||
|
path = "../satrs-macros"
|
||||||
|
|
||||||
[dependencies.satrs-core]
|
[dependencies.satrs-core]
|
||||||
path = "../satrs-core"
|
path = "../satrs-core"
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
mod ccsds;
|
mod ccsds;
|
||||||
mod pus;
|
mod pus;
|
||||||
mod tmtc;
|
mod tmtc;
|
||||||
|
mod results;
|
||||||
|
|
||||||
use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID};
|
use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID};
|
||||||
use satrs_core::event_man::{
|
use satrs_core::event_man::{
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use crate::tmtc::TmStore;
|
use crate::tmtc::TmStore;
|
||||||
|
use crate::results::{INVALID_PUS_SERVICE, INVALID_PUS_SUBSERVICE, NOT_ENOUGH_APP_DATA};
|
||||||
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::Subservices;
|
||||||
@ -8,11 +9,12 @@ use satrs_core::pus::verification::{
|
|||||||
};
|
};
|
||||||
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
|
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
|
||||||
use satrs_core::tmtc::PusServiceProvider;
|
use satrs_core::tmtc::PusServiceProvider;
|
||||||
use spacepackets::ecss::{EcssEnumU16, PusPacket};
|
use spacepackets::ecss::PusPacket;
|
||||||
use spacepackets::tc::PusTc;
|
use spacepackets::tc::PusTc;
|
||||||
use spacepackets::time::{CdsShortTimeProvider, TimeWriter};
|
use spacepackets::time::{CdsShortTimeProvider, TimeWriter};
|
||||||
use spacepackets::SpHeader;
|
use spacepackets::SpHeader;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
|
use satrs_core::resultcode::ResultU16;
|
||||||
|
|
||||||
pub struct PusReceiver {
|
pub struct PusReceiver {
|
||||||
pub tm_helper: PusTmWithCdsShortHelper,
|
pub tm_helper: PusTmWithCdsShortHelper,
|
||||||
@ -64,8 +66,9 @@ impl PusServiceProvider for PusReceiver {
|
|||||||
} else if service == 5 {
|
} else if service == 5 {
|
||||||
self.handle_event_service(pus_tc, accepted_token);
|
self.handle_event_service(pus_tc, accepted_token);
|
||||||
} else {
|
} else {
|
||||||
// TODO: Unknown service verification failure
|
self.update_time_stamp();
|
||||||
// TODO: Unknown service returncode
|
self.verif_reporter.start_failure(accepted_token, FailParams::new(&self.time_stamp, &INVALID_PUS_SERVICE, None))
|
||||||
|
.expect("Start failure verification failed")
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -89,12 +92,11 @@ impl PusReceiver {
|
|||||||
.completion_success(start_token, &self.time_stamp)
|
.completion_success(start_token, &self.time_stamp)
|
||||||
.expect("Error sending completion success");
|
.expect("Error sending completion success");
|
||||||
} else {
|
} else {
|
||||||
// TODO: Unknown Subservice returncode
|
|
||||||
self.update_time_stamp();
|
self.update_time_stamp();
|
||||||
self.verif_reporter
|
self.verif_reporter
|
||||||
.start_failure(
|
.start_failure(
|
||||||
token,
|
token,
|
||||||
FailParams::new(&self.time_stamp, &EcssEnumU16::new(2), None),
|
FailParams::new(&self.time_stamp, &INVALID_PUS_SUBSERVICE, None),
|
||||||
)
|
)
|
||||||
.expect("Sending start failure TM failed");
|
.expect("Sending start failure TM failed");
|
||||||
}
|
}
|
||||||
@ -112,12 +114,12 @@ impl PusReceiver {
|
|||||||
fn handle_event_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
|
fn handle_event_service(&mut self, pus_tc: &PusTc, token: VerificationToken<TcStateAccepted>) {
|
||||||
let send_start_failure = |verif_reporter: &mut StdVerifReporterWithSender,
|
let send_start_failure = |verif_reporter: &mut StdVerifReporterWithSender,
|
||||||
timestamp: &[u8; 7],
|
timestamp: &[u8; 7],
|
||||||
failure_code: EcssEnumU16,
|
failure_code: &ResultU16,
|
||||||
failure_data: Option<&[u8]>| {
|
failure_data: Option<&[u8]>| {
|
||||||
verif_reporter
|
verif_reporter
|
||||||
.start_failure(
|
.start_failure(
|
||||||
token,
|
token,
|
||||||
FailParams::new(timestamp, &failure_code, failure_data),
|
FailParams::new(timestamp, failure_code, failure_data),
|
||||||
)
|
)
|
||||||
.expect("Sending start failure TM failed");
|
.expect("Sending start failure TM failed");
|
||||||
};
|
};
|
||||||
@ -132,7 +134,7 @@ impl PusReceiver {
|
|||||||
send_start_failure(
|
send_start_failure(
|
||||||
&mut self.verif_reporter,
|
&mut self.verif_reporter,
|
||||||
&self.time_stamp,
|
&self.time_stamp,
|
||||||
EcssEnumU16::new(1),
|
&NOT_ENOUGH_APP_DATA,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -143,7 +145,7 @@ impl PusReceiver {
|
|||||||
send_start_failure(
|
send_start_failure(
|
||||||
&mut self.verif_reporter,
|
&mut self.verif_reporter,
|
||||||
&self.time_stamp,
|
&self.time_stamp,
|
||||||
EcssEnumU16::new(1),
|
&NOT_ENOUGH_APP_DATA,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
@ -171,12 +173,11 @@ impl PusReceiver {
|
|||||||
.expect("Sending event request failed");
|
.expect("Sending event request failed");
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
// TODO: Unknown Subservice returncode
|
|
||||||
self.update_time_stamp();
|
self.update_time_stamp();
|
||||||
send_start_failure(
|
send_start_failure(
|
||||||
&mut self.verif_reporter,
|
&mut self.verif_reporter,
|
||||||
&self.time_stamp,
|
&self.time_stamp,
|
||||||
EcssEnumU16::new(2),
|
&INVALID_PUS_SUBSERVICE,
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
15
satrs-example/src/results.rs
Normal file
15
satrs-example/src/results.rs
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
use satrs_core::resultcode::ResultU16;
|
||||||
|
use satrs_macros::resultcode;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum GroupId {
|
||||||
|
Tmtc = 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[resultcode]
|
||||||
|
pub const INVALID_PUS_SERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 0);
|
||||||
|
#[resultcode]
|
||||||
|
pub const INVALID_PUS_SUBSERVICE: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 1);
|
||||||
|
|
||||||
|
#[resultcode(info="Not enough data inside the TC application data field")]
|
||||||
|
pub const NOT_ENOUGH_APP_DATA: ResultU16 = ResultU16::const_new(GroupId::Tmtc as u8, 2);
|
@ -85,7 +85,11 @@ impl ResultExtGenerator {
|
|||||||
let result_code_name = self.name_str.to_owned().unwrap();
|
let result_code_name = self.name_str.to_owned().unwrap();
|
||||||
let name_as_str = result_code_name.to_string();
|
let name_as_str = result_code_name.to_string();
|
||||||
let gen_struct_name = format_ident!("{}_EXT", result_code_name);
|
let gen_struct_name = format_ident!("{}_EXT", result_code_name);
|
||||||
let info_str = self.info_str.to_owned().unwrap();
|
let info_str = if let Some(info_str) = &self.info_str {
|
||||||
|
info_str.value()
|
||||||
|
} else {
|
||||||
|
String::from("")
|
||||||
|
};
|
||||||
let gen_struct = quote! {
|
let gen_struct = quote! {
|
||||||
const #gen_struct_name: satrs_core::resultcode::ResultU16Ext =
|
const #gen_struct_name: satrs_core::resultcode::ResultU16Ext =
|
||||||
satrs_core::resultcode::ResultU16Ext::const_new(
|
satrs_core::resultcode::ResultU16Ext::const_new(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user