done
Rust/sat-rs/pipeline/pr-main This commit looks good Details

This commit is contained in:
Robin Müller 2024-01-30 23:59:29 +01:00
parent b27842c2bb
commit b79b5d2009
Signed by: muellerr
GPG Key ID: A649FB78196E3849
2 changed files with 20 additions and 28 deletions

View File

@ -1,5 +1,5 @@
use derive_new::new;
use satrs_example::TargetIdWithApid;
use satrs_core::spacepackets::ByteConversionError;
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum AcsHkIds {
@ -8,36 +8,30 @@ pub enum AcsHkIds {
#[derive(Debug, new, Copy, Clone)]
pub struct HkUniqueId {
id: u32,
}
impl From<u32> for HkUniqueId {
fn from(id: u32) -> Self {
Self { id }
}
target_id: u32,
set_id: u32,
}
impl HkUniqueId {
#[allow(dead_code)]
pub fn id(&self) -> u32 {
self.id
pub fn target_id(&self) -> u32 {
self.target_id
}
#[allow(dead_code)]
pub fn set_id(&self) -> u32 {
self.set_id
}
pub fn bytes_from_target_id(&self, buf: &mut [u8], target_id: u32) -> Result<(), ()> {
pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
if buf.len() < 8 {
return Err(());
return Err(ByteConversionError::ToSliceTooSmall {
found: buf.len(),
expected: 8,
});
}
buf[0..4].copy_from_slice(&self.id.to_be_bytes());
buf[4..8].copy_from_slice(&target_id.to_be_bytes());
buf[0..4].copy_from_slice(&self.target_id.to_be_bytes());
buf[4..8].copy_from_slice(&self.set_id.to_be_bytes());
Ok(())
}
pub fn bytes_from_target_id_with_apid(
&self,
buf: &mut [u8],
target_id: TargetIdWithApid,
) -> Result<(), ()> {
self.bytes_from_target_id(buf, target_id.target)
Ok(8)
}
}

View File

@ -442,6 +442,7 @@ fn main() {
match request.targeted_request.request {
Request::Hk(hk_req) => match hk_req {
HkRequest::OneShot(unique_id) => {
// TODO: We should check whether the unique ID is even valid.
let target = request.targeted_request.target_id;
assert_eq!(
target.target_id(),
@ -463,11 +464,8 @@ fn main() {
&timestamp,
);
let mut buf: [u8; 8] = [0; 8];
let hk_id = HkUniqueId::new(unique_id);
hk_id
.bytes_from_target_id_with_apid(&mut buf, target)
.unwrap();
let hk_id = HkUniqueId::new(target.target_id(), unique_id);
hk_id.write_to_be_bytes(&mut buf).unwrap();
let pus_tm = PusTmCreator::new(
&mut sp_header,
sec_header,