- Add new shared subcrate satrs-shared to split off some shared components not expected to change very often. - Renmame `satrs-core` to `satrs`. It is expected that sat-rs will remain the primary crate, so the core information is superfluous, and core also implies stability, which will not be the case for some time.
This commit is contained in:
21
satrs-shared/Cargo.toml
Normal file
21
satrs-shared/Cargo.toml
Normal file
@ -0,0 +1,21 @@
|
||||
[package]
|
||||
name = "satrs-shared"
|
||||
description = "Components shared by multiple sat-rs crates"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
|
||||
[dependencies.serde]
|
||||
version = "1"
|
||||
default-features = false
|
||||
optional = true
|
||||
|
||||
[dependencies.spacepackets]
|
||||
version = "0.9.0"
|
||||
default-features = false
|
||||
|
||||
[features]
|
||||
serde = ["dep:serde", "spacepackets/serde"]
|
1
satrs-shared/src/lib.rs
Normal file
1
satrs-shared/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod res_code;
|
60
satrs-shared/src/res_code.rs
Normal file
60
satrs-shared/src/res_code.rs
Normal file
@ -0,0 +1,60 @@
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use spacepackets::ecss::{EcssEnumU16, EcssEnumeration};
|
||||
use spacepackets::util::UnsignedEnum;
|
||||
use spacepackets::ByteConversionError;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct ResultU16 {
|
||||
group_id: u8,
|
||||
unique_id: u8,
|
||||
}
|
||||
|
||||
impl ResultU16 {
|
||||
pub const fn const_new(group_id: u8, unique_id: u8) -> Self {
|
||||
Self {
|
||||
group_id,
|
||||
unique_id,
|
||||
}
|
||||
}
|
||||
pub fn raw(&self) -> u16 {
|
||||
((self.group_id as u16) << 8) | self.unique_id as u16
|
||||
}
|
||||
pub fn group_id(&self) -> u8 {
|
||||
self.group_id
|
||||
}
|
||||
pub fn unique_id(&self) -> u8 {
|
||||
self.unique_id
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ResultU16> for EcssEnumU16 {
|
||||
fn from(v: ResultU16) -> Self {
|
||||
EcssEnumU16::new(v.raw())
|
||||
}
|
||||
}
|
||||
|
||||
impl UnsignedEnum for ResultU16 {
|
||||
fn size(&self) -> usize {
|
||||
core::mem::size_of::<u16>()
|
||||
}
|
||||
|
||||
fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
|
||||
if buf.len() < 2 {
|
||||
return Err(ByteConversionError::ToSliceTooSmall {
|
||||
found: buf.len(),
|
||||
expected: 2,
|
||||
});
|
||||
}
|
||||
buf[0] = self.group_id;
|
||||
buf[1] = self.unique_id;
|
||||
Ok(self.size())
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssEnumeration for ResultU16 {
|
||||
fn pfc(&self) -> u8 {
|
||||
16
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user