new mib crate

This commit is contained in:
Robin Müller 2022-11-27 22:05:42 +01:00
parent 7e0d3f394a
commit b0b41a07dc
No known key found for this signature in database
GPG Key ID: BE6480244DFE612C
19 changed files with 341 additions and 65 deletions

117
Cargo.lock generated
View File

@ -15,9 +15,9 @@ dependencies = [
[[package]]
name = "aho-corasick"
version = "0.7.19"
version = "0.7.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e"
checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
dependencies = [
"memchr",
]
@ -31,6 +31,15 @@ dependencies = [
"libc",
]
[[package]]
name = "array-init"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23589ecb866b460d3a0f1278834750268c607e8e28a1b982c907219f3178cd72"
dependencies = [
"nodrop",
]
[[package]]
name = "atomic-polyfill"
version = "0.1.10"
@ -85,6 +94,18 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bstr"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
"serde",
]
[[package]]
name = "bumpalo"
version = "3.11.1"
@ -110,9 +131,9 @@ checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cc"
version = "1.0.76"
version = "1.0.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76a284da2e6fe2092f2353e51713435363112dfd60030e22add80be333fb928f"
checksum = "e9f73505338f7d905b19d18738976aae232eb46b8efc15554ffc56deb5d9ebe4"
[[package]]
name = "cfg-if"
@ -205,13 +226,35 @@ dependencies = [
[[package]]
name = "crossbeam-utils"
version = "0.8.13"
version = "0.8.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "422f23e724af1240ec469ea1e834d87a4b59ce2efe2c6a96256b0c47e2fd86aa"
checksum = "4fb766fa798726286dbbb842f174001dab8abc7b627a1dd86e0b7222a95d929f"
dependencies = [
"cfg-if",
]
[[package]]
name = "csv"
version = "1.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1"
dependencies = [
"bstr",
"csv-core",
"itoa 0.4.8",
"ryu",
"serde",
]
[[package]]
name = "csv-core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90"
dependencies = [
"memchr",
]
[[package]]
name = "cxx"
version = "1.0.82"
@ -389,6 +432,12 @@ dependencies = [
"cxx-build",
]
[[package]]
name = "itoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4"
[[package]]
name = "itoa"
version = "1.0.4"
@ -444,6 +493,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "maybe-uninit"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
[[package]]
name = "memchr"
version = "2.5.0"
@ -465,6 +520,12 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "546c37ac5d9e56f55e73b677106873d9d9f5190605e41a856503623648488cae"
[[package]]
name = "nodrop"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "num-integer"
version = "0.1.45"
@ -509,7 +570,7 @@ dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"smallvec 1.10.0",
"windows-sys",
]
@ -568,6 +629,12 @@ dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132"
[[package]]
name = "regex-syntax"
version = "0.6.28"
@ -645,9 +712,11 @@ name = "satrs-example"
version = "0.1.0"
dependencies = [
"crossbeam-channel",
"csv",
"delegate 0.8.0",
"satrs-core",
"satrs-macros",
"satrs-mib",
"spacepackets",
"zerocopy",
]
@ -659,10 +728,22 @@ dependencies = [
"proc-macro2",
"quote",
"satrs-core",
"satrs-mib",
"syn",
"trybuild",
]
[[package]]
name = "satrs-mib"
version = "0.1.0"
dependencies = [
"csv",
"satrs-core",
"satrs-macros",
"serde",
"serde-hex",
]
[[package]]
name = "scopeguard"
version = "1.1.0"
@ -705,6 +786,17 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "serde-hex"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca37e3e4d1b39afd7ff11ee4e947efae85adfddf4841787bfa47c470e96dc26d"
dependencies = [
"array-init",
"serde",
"smallvec 0.6.14",
]
[[package]]
name = "serde_derive"
version = "1.0.147"
@ -722,11 +814,20 @@ version = "1.0.89"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db"
dependencies = [
"itoa",
"itoa 1.0.4",
"ryu",
"serde",
]
[[package]]
name = "smallvec"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b97fcaeba89edba30f044a10c6a3cc39df9c3f17d7cd829dd1446cab35f890e0"
dependencies = [
"maybe-uninit",
]
[[package]]
name = "smallvec"
version = "1.10.0"

View File

@ -3,6 +3,7 @@
members = [
"satrs-core",
"satrs-macros",
"satrs-mib",
"satrs-example",
"spacepackets",
]

View File

@ -29,6 +29,10 @@ optional = true
version= "0.5"
default-features = false
[dependencies.serde]
version = "1.0"
default-features = false
[dependencies.spacepackets]
path = "../spacepackets"
@ -42,8 +46,8 @@ version = "1.0"
[features]
default = ["std"]
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std"]
alloc = []
std = ["downcast-rs/std", "alloc", "bus", "postcard/use-std", "crossbeam-channel/std", "serde/std"]
alloc = ["serde/alloc"]
heapless = []
doc-images = []

View File

@ -29,6 +29,6 @@ pub mod params;
#[cfg_attr(doc_cfg, doc(cfg(feature = "alloc")))]
pub mod pool;
pub mod pus;
pub mod resultcode;
pub mod res_code;
pub mod seq_count;
pub mod tmtc;

View File

@ -1,7 +1,8 @@
use serde::{Deserialize, Serialize};
use spacepackets::ecss::{EcssEnumU16, EcssEnumeration};
use spacepackets::{ByteConversionError, SizeMissmatch};
use spacepackets::ecss::{EcssEnumeration, EcssEnumU16};
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ResultU16 {
group_id: u8,
unique_id: u8,
@ -40,7 +41,7 @@ impl EcssEnumeration for ResultU16 {
if buf.len() < 2 {
return Err(ByteConversionError::ToSliceTooSmall(SizeMissmatch {
found: buf.len(),
expected: 2
expected: 2,
}));
}
buf[0] = self.group_id;
@ -48,20 +49,3 @@ impl EcssEnumeration for ResultU16 {
Ok(())
}
}
#[derive(Debug)]
pub struct ResultU16Ext {
pub name: &'static str,
pub result: &'static ResultU16,
pub info: &'static str,
}
impl ResultU16Ext {
pub const fn const_new(
name: &'static str,
result: &'static ResultU16,
info: &'static str,
) -> Self {
Self { name, result, info }
}
}

View File

@ -9,6 +9,7 @@ default-run = "satrs-example"
crossbeam-channel = "0.5"
delegate = "0.8"
zerocopy = "0.6"
csv = "1"
[dependencies.spacepackets]
path = "../spacepackets"
@ -18,3 +19,6 @@ path = "../satrs-macros"
[dependencies.satrs-core]
path = "../satrs-core"
[dependencies.satrs-mib]
path = "../satrs-mib"

View File

@ -22,8 +22,8 @@ fn main() {
.write_to_bytes(&mut buf)
.expect("Creating PUS TC failed");
client
.send_to(&buf[0..size], &addr)
.expect(&*format!("Sending to {:?} failed", addr));
.send_to(&buf[0..size], addr)
.unwrap_or_else(|_| panic!("Sending to {:?} failed", addr));
client
.set_read_timeout(Some(Duration::from_secs(2)))
.expect("Setting read timeout failed");

View File

@ -1,4 +1,27 @@
use std::net::Ipv4Addr;
use satrs_core::res_code::ResultU16;
use satrs_macros::resultcode;
use satrs_mib::res_code::ResultU16Info;
#[derive(Debug)]
pub enum GroupId {
Tmtc = 0,
}
pub const OBSW_SERVER_ADDR: Ipv4Addr = Ipv4Addr::new(127, 0, 0, 1);
pub const SERVER_PORT: u16 = 7301;
#[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);
pub const TMTC_RESULTS: &[ResultU16Info] = &[
INVALID_PUS_SERVICE_EXT,
INVALID_PUS_SUBSERVICE_EXT,
NOT_ENOUGH_APP_DATA_EXT,
];

View File

@ -1,7 +1,6 @@
mod ccsds;
mod pus;
mod tmtc;
mod results;
use crate::tmtc::{core_tmtc_task, CoreTmtcArgs, TmStore, PUS_APID};
use satrs_core::event_man::{

View File

@ -1,5 +1,4 @@
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::pool::StoreAddr;
use satrs_core::pus::event::Subservices;
@ -7,14 +6,15 @@ use satrs_core::pus::event_man::{EventRequest, EventRequestWithToken};
use satrs_core::pus::verification::{
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
};
use satrs_core::res_code::ResultU16;
use satrs_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
use satrs_core::tmtc::PusServiceProvider;
use satrs_example::{INVALID_PUS_SERVICE, INVALID_PUS_SUBSERVICE, NOT_ENOUGH_APP_DATA};
use spacepackets::ecss::PusPacket;
use spacepackets::tc::PusTc;
use spacepackets::time::{CdsShortTimeProvider, TimeWriter};
use spacepackets::SpHeader;
use std::sync::mpsc;
use satrs_core::resultcode::ResultU16;
pub struct PusReceiver {
pub tm_helper: PusTmWithCdsShortHelper,
@ -67,7 +67,11 @@ impl PusServiceProvider for PusReceiver {
self.handle_event_service(pus_tc, accepted_token);
} else {
self.update_time_stamp();
self.verif_reporter.start_failure(accepted_token, FailParams::new(&self.time_stamp, &INVALID_PUS_SERVICE, None))
self.verif_reporter
.start_failure(
accepted_token,
FailParams::new(&self.time_stamp, &INVALID_PUS_SERVICE, None),
)
.expect("Start failure verification failed")
}
Ok(())

View File

@ -1,15 +0,0 @@
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);

View File

@ -21,6 +21,9 @@ path = "../satrs-core"
[dev-dependencies]
trybuild = { version = "1.0", features = ["diff"] }
[dev-dependencies.satrs-mib]
path = "../satrs-mib"
[dependencies.syn]
version = "1.0"
features = ["extra-traits"]

View File

@ -90,11 +90,13 @@ impl ResultExtGenerator {
} else {
String::from("")
};
// TODO: Group string
let gen_struct = quote! {
const #gen_struct_name: satrs_core::resultcode::ResultU16Ext =
satrs_core::resultcode::ResultU16Ext::const_new(
const #gen_struct_name: satrs_mib::res_code::ResultU16Info =
satrs_mib::res_code::ResultU16Info::const_new(
#name_as_str,
&#result_code_name,
"",
#info_str
);
};

View File

@ -1,7 +0,0 @@
use satrs_core::resultcode::ResultU16;
use satrs_macros::*;
#[resultcode(info = "This is a test result where the first parameter is foo")]
const _TEST_RESULT: ResultU16 = ResultU16::const_new(0, 1);
fn main() {}

View File

@ -1,8 +1,8 @@
//! Basic check which just verifies that everything compiles
use satrs_core::resultcode::ResultU16;
use satrs_core::res_code::ResultU16;
use satrs_macros::*;
#[resultcode(info = "This is a test result where the first parameter is foo")]
const TEST_RESULT: ResultU16 = ResultU16::const_new(0, 1);
const _TEST_RESULT: ResultU16 = ResultU16::const_new(0, 1);
fn main() {}

View File

@ -1,10 +1,11 @@
use satrs_core::resultcode::{ResultU16, ResultU16Ext};
use satrs_core::res_code::ResultU16;
use satrs_macros::*;
use satrs_mib::res_code::ResultU16Info;
#[resultcode(info = "This is a test result where the first parameter is foo")]
const TEST_RESULT: ResultU16 = ResultU16::const_new(0, 1);
// Create named reference of auto-generated struct, which can be used by IDEs etc.
const TEST_RESULT_EXT_REF: &ResultU16Ext = &TEST_RESULT_EXT;
const TEST_RESULT_EXT_REF: &ResultU16Info = &TEST_RESULT_EXT;
fn main() {
assert_eq!(TEST_RESULT_EXT.name, "TEST_RESULT");

20
satrs-mib/Cargo.toml Normal file
View File

@ -0,0 +1,20 @@
[package]
name = "satrs-mib"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde-hex = "0.1.0"
csv = "1"
[dependencies.satrs-core]
path = "../satrs-core"
[dependencies.satrs-macros]
path = "../satrs-macros"
[dependencies.serde]
version = "1.0"
default-features = false

1
satrs-mib/src/lib.rs Normal file
View File

@ -0,0 +1 @@
pub mod res_code;

151
satrs-mib/src/res_code.rs Normal file
View File

@ -0,0 +1,151 @@
use std::io;
use std::path::Path;
pub use satrs_core::res_code::ResultU16;
use serde::{Deserialize, Serialize};
use serde_hex::{SerHex, StrictCapPfx};
#[derive(Debug, Copy, Clone, Serialize)]
pub struct ResultU16Info {
pub name: &'static str,
pub result: &'static ResultU16,
pub group_str: &'static str,
pub info: &'static str,
}
impl ResultU16Info {
pub const fn const_new(
name: &'static str,
result: &'static ResultU16,
group_str: &'static str,
info: &'static str,
) -> Self {
Self {
name,
result,
group_str,
info,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct ResultU16InfoSerializable {
#[serde(with = "SerHex::<StrictCapPfx>")]
raw: u16,
#[serde(with = "SerHex::<StrictCapPfx>")]
group_id: u8,
#[serde(with = "SerHex::<StrictCapPfx>")]
unique_id: u8,
name: &'static str,
group_str: &'static str,
info: &'static str,
}
impl From<ResultU16Info> for ResultU16InfoSerializable {
fn from(v: ResultU16Info) -> Self {
Self {
raw: v.result.raw(),
group_id: v.result.group_id(),
unique_id: v.result.unique_id(),
name: v.name,
group_str: v.group_str,
info: v.info,
}
}
}
pub fn print_resultcodes_as_csv(codes: &[ResultU16Info]) -> Result<(), csv::Error> {
let mut wtr = csv::Writer::from_writer(io::stdout());
for result in codes {
wtr.serialize(ResultU16InfoSerializable::from(*result))?;
}
wtr.flush()?;
Ok(())
}
pub fn write_resultcodes_to_csv(
results: &[ResultU16Info],
path: impl AsRef<Path>,
) -> Result<(), csv::Error> {
let mut wtr = csv::Writer::from_path(path)?;
for result_code in results {
wtr.serialize(ResultU16InfoSerializable::from(*result_code))?;
}
wtr.flush()?;
Ok(())
}
#[cfg(test)]
mod tests {
use super::*;
use std::fs::File;
use std::io::{BufRead, BufReader};
// Special solution for this crate because the code generated by a macro will use
// satrs_mib::res_code::*
use crate as satrs_mib;
use satrs_core::res_code::ResultU16;
use satrs_macros::resultcode;
#[derive(Debug)]
#[allow(dead_code)]
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);
pub const TMTC_RESULTS: &[ResultU16Info] = &[
INVALID_PUS_SERVICE_EXT,
INVALID_PUS_SUBSERVICE_EXT,
NOT_ENOUGH_APP_DATA_EXT,
];
const CSV_NAME: &'static str = "dummy.csv";
#[test]
fn test_printout() {
print_resultcodes_as_csv(TMTC_RESULTS).expect("Priting result codes failed");
}
#[test]
fn test_csv_export() {
let csvpath = Path::new(CSV_NAME);
write_resultcodes_to_csv(TMTC_RESULTS, csvpath).expect("CSV export failed");
assert!(csvpath.exists());
let file = File::open(csvpath).expect("Opening CSV file failed");
let buf_reader = BufReader::new(file);
for (idx, line) in buf_reader.lines().enumerate() {
match idx {
0 => {
assert!(line.is_ok());
let line = line.unwrap();
assert_eq!(line, "raw,group_id,unique_id,name,group_str,info");
}
1 => {
assert!(line.is_ok());
let line = line.unwrap();
assert_eq!(line, "0x0000,0x00,0x00,INVALID_PUS_SERVICE,,");
}
2 => {
assert!(line.is_ok());
let line = line.unwrap();
assert_eq!(line, "0x0001,0x00,0x01,INVALID_PUS_SUBSERVICE,,");
}
3 => {
assert!(line.is_ok());
let line = line.unwrap();
assert_eq!(line, "0x0002,0x00,0x02,NOT_ENOUGH_APP_DATA,,Not enough data inside the TC application data field");
}
_ => (),
}
}
std::fs::remove_file(Path::new("dummy.csv")).expect("Removing dummy csv failed");
}
}