TargetIdWithApid #63
@ -1,5 +1,5 @@
|
|||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use satrs_example::TargetIdWithApid;
|
use satrs_core::spacepackets::ByteConversionError;
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||||
pub enum AcsHkIds {
|
pub enum AcsHkIds {
|
||||||
@ -8,36 +8,30 @@ pub enum AcsHkIds {
|
|||||||
|
|
||||||
#[derive(Debug, new, Copy, Clone)]
|
#[derive(Debug, new, Copy, Clone)]
|
||||||
pub struct HkUniqueId {
|
pub struct HkUniqueId {
|
||||||
id: u32,
|
target_id: u32,
|
||||||
}
|
set_id: u32,
|
||||||
lkoester marked this conversation as resolved
Outdated
|
|||||||
|
|
||||||
impl From<u32> for HkUniqueId {
|
|
||||||
fn from(id: u32) -> Self {
|
|
||||||
Self { id }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HkUniqueId {
|
impl HkUniqueId {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn id(&self) -> u32 {
|
pub fn target_id(&self) -> u32 {
|
||||||
self.id
|
self.target_id
|
||||||
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub fn set_id(&self) -> u32 {
|
||||||
|
self.set_id
|
||||||
lkoester marked this conversation as resolved
Outdated
muellerr
commented
`target_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 {
|
if buf.len() < 8 {
|
||||||
muellerr marked this conversation as resolved
muellerr
commented
I would rename this to Returntype probably is I would rename this to `write_to_be_bytes` for consistent naming. targetID and set ID are members to they do not need to be input parameters.
Returntype probably is `Result<usize, ByteConversionError>`. returning the written size makes it easier to chain low level write conversions
|
|||||||
return Err(());
|
return Err(ByteConversionError::ToSliceTooSmall {
|
||||||
|
found: buf.len(),
|
||||||
|
expected: 8,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
buf[0..4].copy_from_slice(&self.id.to_be_bytes());
|
buf[0..4].copy_from_slice(&self.target_id.to_be_bytes());
|
||||||
buf[4..8].copy_from_slice(&target_id.to_be_bytes());
|
buf[4..8].copy_from_slice(&self.set_id.to_be_bytes());
|
||||||
|
|
||||||
Ok(())
|
Ok(8)
|
||||||
}
|
|
||||||
|
|
||||||
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)
|
|
||||||
}
|
}
|
||||||
muellerr marked this conversation as resolved
Outdated
muellerr
commented
I'd create a constructor which constructs this type from a I'd create a constructor which constructs this type from a `TargetIdWithApid` and the unique ID ( `u32`)
|
|||||||
}
|
}
|
||||||
|
@ -442,6 +442,7 @@ fn main() {
|
|||||||
match request.targeted_request.request {
|
match request.targeted_request.request {
|
||||||
Request::Hk(hk_req) => match hk_req {
|
Request::Hk(hk_req) => match hk_req {
|
||||||
HkRequest::OneShot(unique_id) => {
|
HkRequest::OneShot(unique_id) => {
|
||||||
|
// TODO: We should check whether the unique ID is even valid.
|
||||||
let target = request.targeted_request.target_id;
|
let target = request.targeted_request.target_id;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
target.target_id(),
|
target.target_id(),
|
||||||
@ -463,11 +464,8 @@ fn main() {
|
|||||||
×tamp,
|
×tamp,
|
||||||
);
|
);
|
||||||
let mut buf: [u8; 8] = [0; 8];
|
let mut buf: [u8; 8] = [0; 8];
|
||||||
|
let hk_id = HkUniqueId::new(target.target_id(), unique_id);
|
||||||
let hk_id = HkUniqueId::new(unique_id);
|
hk_id.write_to_be_bytes(&mut buf).unwrap();
|
||||||
hk_id
|
|
||||||
.bytes_from_target_id_with_apid(&mut buf, target)
|
|
||||||
.unwrap();
|
|
||||||
let pus_tm = PusTmCreator::new(
|
let pus_tm = PusTmCreator::new(
|
||||||
&mut sp_header,
|
&mut sp_header,
|
||||||
sec_header,
|
sec_header,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user
I would make the
set_id
(u32) a member and rename id totarget_id