added HkUniqueId
This commit is contained in:
parent
26404cdfe1
commit
a3311f102e
@ -1,4 +1,39 @@
|
||||
use derive_new::new;
|
||||
use zerocopy::AsBytes;
|
||||
use satrs_example::TargetIdWithApid;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum AcsHkIds {
|
||||
TestMgmSet = 1,
|
||||
}
|
||||
|
||||
#[derive(Debug, new, Copy, Clone)]
|
||||
pub struct HkUniqueId {
|
||||
id: u32,
|
||||
}
|
||||
|
||||
impl From<u32> for HkUniqueId {
|
||||
fn from(id: u32) -> Self {
|
||||
Self { id }
|
||||
}
|
||||
}
|
||||
|
||||
impl HkUniqueId {
|
||||
pub fn id(&self) -> u32 {
|
||||
self.id
|
||||
}
|
||||
|
||||
pub fn bytes_from_target_id(&self, buf: &mut [u8], target_id: u32) -> Result<(), ()> {
|
||||
if buf.len() < 8 {
|
||||
return Err(());
|
||||
}
|
||||
buf[0..4].copy_from_slice(&self.id.to_be_bytes());
|
||||
buf[4..8].copy_from_slice(&target_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)
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
use std::fmt;
|
||||
use delegate::delegate;
|
||||
use derive_new::new;
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use satrs_core::events::{EventU32TypedSev, SeverityInfo};
|
||||
use satrs_core::objects::ObjectId;
|
||||
use std::net::Ipv4Addr;
|
||||
use delegate::delegate;
|
||||
use derive_new::new;
|
||||
use thiserror::Error;
|
||||
use satrs_core::spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch};
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::spacepackets::ecss::tc::{GenericPusTcSecondaryHeader, IsPusTelecommand, PusTc};
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::spacepackets::{ByteConversionError, CcsdsPacket, SizeMissmatch};
|
||||
use satrs_core::tmtc::TargetId;
|
||||
use std::fmt;
|
||||
use std::net::Ipv4Addr;
|
||||
use thiserror::Error;
|
||||
|
||||
use satrs_mib::res_code::{ResultU16, ResultU16Info};
|
||||
use satrs_mib::resultcode;
|
||||
@ -25,7 +25,7 @@ pub enum TargetIdCreationError {
|
||||
#[error("byte conversion")]
|
||||
ByteConversion(#[from] ByteConversionError),
|
||||
#[error("not enough app data to generate target ID")]
|
||||
NotEnoughAppData(usize)
|
||||
NotEnoughAppData(usize),
|
||||
}
|
||||
|
||||
// TODO: can these stay pub?
|
||||
@ -45,18 +45,21 @@ impl TargetIdWithApid {
|
||||
pub fn apid(&self) -> Apid {
|
||||
self.apid
|
||||
}
|
||||
pub fn target_id(&self) -> TargetId{
|
||||
pub fn target_id(&self) -> TargetId {
|
||||
self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetIdWithApid {
|
||||
pub fn from_tc(tc: &(impl CcsdsPacket + PusPacket + IsPusTelecommand)) -> Result<Self, TargetIdCreationError> {
|
||||
pub fn from_tc(
|
||||
tc: &(impl CcsdsPacket + PusPacket + IsPusTelecommand),
|
||||
) -> Result<Self, TargetIdCreationError> {
|
||||
if tc.user_data().len() < 4 {
|
||||
return Err(ByteConversionError::FromSliceTooSmall(SizeMissmatch {
|
||||
found: tc.user_data().len(),
|
||||
expected: 8,
|
||||
}).into());
|
||||
})
|
||||
.into());
|
||||
}
|
||||
let target_id = u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap());
|
||||
Ok(Self {
|
||||
|
@ -9,7 +9,7 @@ mod tmtc;
|
||||
|
||||
use log::{info, warn};
|
||||
|
||||
use crate::hk::AcsHkIds;
|
||||
use crate::hk::{AcsHkIds, HkUniqueId};
|
||||
use crate::logging::setup_logger;
|
||||
use crate::pus::action::{Pus8Wrapper, PusService8ActionHandler};
|
||||
use crate::pus::event::Pus5Wrapper;
|
||||
@ -45,9 +45,12 @@ use satrs_core::spacepackets::{
|
||||
SpHeader,
|
||||
};
|
||||
use satrs_core::tmtc::tm_helper::SharedTmStore;
|
||||
use satrs_core::tmtc::{TargetId};
|
||||
use satrs_core::tmtc::TargetId;
|
||||
use satrs_core::ChannelId;
|
||||
use satrs_example::{RequestTargetId, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, PUS_APID, SERVER_PORT, TargetIdWithApid};
|
||||
use satrs_example::{
|
||||
RequestTargetId, TargetIdWithApid, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, PUS_APID,
|
||||
SERVER_PORT,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
use std::sync::mpsc::{channel, TryRecvError};
|
||||
@ -394,7 +397,10 @@ fn main() {
|
||||
Request::Hk(hk_req) => match hk_req {
|
||||
HkRequest::OneShot(unique_id) => {
|
||||
let target = request.targeted_request.target_id;
|
||||
assert_eq!(target.target_id(), RequestTargetId::AcsSubsystem as u32);
|
||||
assert_eq!(
|
||||
target.target_id(),
|
||||
RequestTargetId::AcsSubsystem as u32
|
||||
);
|
||||
if request.targeted_request.target_id.target
|
||||
== AcsHkIds::TestMgmSet as u32
|
||||
{
|
||||
@ -412,7 +418,8 @@ fn main() {
|
||||
);
|
||||
let mut buf: [u8; 8] = [0; 8];
|
||||
|
||||
addressable_id.write_to_be_bytes(&mut buf).unwrap();
|
||||
let hk_id = HkUniqueId::new(1);
|
||||
hk_id.bytes_from_target_id_with_apid(&mut buf, target).unwrap();
|
||||
let pus_tm = PusTmCreator::new(
|
||||
&mut sp_header,
|
||||
sec_header,
|
||||
|
@ -11,7 +11,7 @@ use satrs_core::pus::{
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::tmtc::TargetId;
|
||||
use satrs_example::{TargetIdWithApid, tmtc_err};
|
||||
use satrs_example::{tmtc_err, TargetIdWithApid};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
|
@ -12,7 +12,7 @@ use satrs_core::pus::{
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::{hk, PusPacket};
|
||||
use satrs_core::tmtc::TargetId;
|
||||
use satrs_example::{hk_err, TargetIdWithApid, tmtc_err};
|
||||
use satrs_example::{hk_err, tmtc_err, TargetIdWithApid};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
@ -92,10 +92,7 @@ impl PusServiceHandler for PusService3HkHandler {
|
||||
}
|
||||
let target_id = TargetIdWithApid::from_tc(&tc).expect("invalid tc format");
|
||||
let unique_id = u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap());
|
||||
if !self
|
||||
.request_handlers
|
||||
.contains_key(&target_id)
|
||||
{
|
||||
if !self.request_handlers.contains_key(&target_id) {
|
||||
self.psb
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
@ -109,29 +106,17 @@ impl PusServiceHandler for PusService3HkHandler {
|
||||
)));
|
||||
}
|
||||
let send_request = |target: TargetIdWithApid, request: HkRequest| {
|
||||
let sender = self
|
||||
.request_handlers
|
||||
.get(&target)
|
||||
.unwrap();
|
||||
let sender = self.request_handlers.get(&target).unwrap();
|
||||
sender
|
||||
.send(RequestWithToken::new(target, Request::Hk(request), token))
|
||||
.unwrap_or_else(|_| panic!("Sending HK request {request:?} failed"));
|
||||
};
|
||||
if subservice == hk::Subservice::TcEnableHkGeneration as u8 {
|
||||
send_request(
|
||||
target_id,
|
||||
HkRequest::Enable(unique_id),
|
||||
);
|
||||
send_request(target_id, HkRequest::Enable(unique_id));
|
||||
} else if subservice == hk::Subservice::TcDisableHkGeneration as u8 {
|
||||
send_request(
|
||||
target_id,
|
||||
HkRequest::Disable(unique_id),
|
||||
);
|
||||
send_request(target_id, HkRequest::Disable(unique_id));
|
||||
} else if subservice == hk::Subservice::TcGenerateOneShotHk as u8 {
|
||||
send_request(
|
||||
target_id,
|
||||
HkRequest::OneShot(unique_id),
|
||||
);
|
||||
send_request(target_id, HkRequest::OneShot(unique_id));
|
||||
} else if subservice == hk::Subservice::TcModifyHkCollectionInterval as u8 {
|
||||
if user_data.len() < 12 {
|
||||
self.psb
|
||||
|
Loading…
Reference in New Issue
Block a user