Merge remote-tracking branch 'origin/main' into tricky-pus-abstraction-changes
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good
All checks were successful
Rust/sat-rs/pipeline/head This commit looks good
This commit is contained in:
commit
e2086391bc
@ -1,6 +1,6 @@
|
||||
use crate::events::EventU32;
|
||||
use crate::pus::event_man::{EventRequest, EventRequestWithToken};
|
||||
use crate::pus::verification::{StdVerifReporterWithSender, TcStateToken};
|
||||
use crate::pus::verification::TcStateToken;
|
||||
use crate::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PartialPusHandlingError, PusPacketHandlerResult,
|
||||
PusPacketHandlingError,
|
||||
@ -10,6 +10,7 @@ use spacepackets::ecss::event::Subservice;
|
||||
use spacepackets::ecss::PusPacket;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
use super::verification::VerificationReporterWithSender;
|
||||
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHandler};
|
||||
|
||||
pub struct PusService5EventHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
@ -22,9 +23,9 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService5EventHandler<TcInMemConv
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
event_request_tx: Sender<EventRequestWithToken>,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
event_request_tx: Sender<EventRequestWithToken>,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceHandler::new(
|
||||
|
@ -646,6 +646,8 @@ pub mod std_mod {
|
||||
InvalidSubservice(u8),
|
||||
#[error("not enough application data available: {0}")]
|
||||
NotEnoughAppData(String),
|
||||
#[error("PUS packet too large, does not fit in buffer: {0}")]
|
||||
PusPacketTooLarge(usize),
|
||||
#[error("invalid application data")]
|
||||
InvalidAppData(String),
|
||||
#[error("invalid format of TC in memory: {0:?}")]
|
||||
@ -687,12 +689,20 @@ pub mod std_mod {
|
||||
}
|
||||
|
||||
pub trait EcssTcInMemConverter {
|
||||
fn cache_ecss_tc_in_memory<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<(), PusPacketHandlingError>;
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8];
|
||||
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError>;
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8];
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError> {
|
||||
self.cache_ecss_tc_in_memory(possible_packet)?;
|
||||
Ok(PusTcReader::new(self.tc_slice_raw())?.0)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EcssTcInVecConverter {
|
||||
@ -700,10 +710,11 @@ pub mod std_mod {
|
||||
}
|
||||
|
||||
impl EcssTcInMemConverter for EcssTcInVecConverter {
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
fn cache_ecss_tc_in_memory<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError> {
|
||||
) -> Result<(), PusPacketHandlingError> {
|
||||
self.pus_tc_raw = None;
|
||||
match &possible_packet.tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(_) => {
|
||||
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
|
||||
@ -714,8 +725,7 @@ pub mod std_mod {
|
||||
self.pus_tc_raw = Some(vec.clone());
|
||||
}
|
||||
};
|
||||
let (tc, _) = PusTcReader::new(self.pus_tc_raw.as_ref().unwrap())?;
|
||||
Ok(tc)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8] {
|
||||
@ -728,14 +738,14 @@ pub mod std_mod {
|
||||
|
||||
pub struct EcssTcInStoreConverter {
|
||||
pub shared_tc_store: SharedPool,
|
||||
pub pus_buf: [u8; 2048],
|
||||
pub pus_buf: Vec<u8>,
|
||||
}
|
||||
|
||||
impl EcssTcInStoreConverter {
|
||||
pub fn new(shared_tc_store: SharedPool) -> Self {
|
||||
pub fn new(shared_tc_store: SharedPool, max_expected_tc_size: usize) -> Self {
|
||||
Self {
|
||||
shared_tc_store,
|
||||
pus_buf: [0; 2048],
|
||||
pus_buf: alloc::vec![0; max_expected_tc_size],
|
||||
}
|
||||
}
|
||||
|
||||
@ -747,27 +757,30 @@ pub mod std_mod {
|
||||
.map_err(|_| PusPacketHandlingError::EcssTmtc(EcssTmtcError::StoreLock))?;
|
||||
let tc_guard = tc_pool.read_with_guard(addr);
|
||||
let tc_raw = tc_guard.read().unwrap();
|
||||
if tc_raw.len() > self.pus_buf.len() {
|
||||
return Err(PusPacketHandlingError::PusPacketTooLarge(tc_raw.len()));
|
||||
}
|
||||
self.pus_buf[0..tc_raw.len()].copy_from_slice(tc_raw);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl EcssTcInMemConverter for EcssTcInStoreConverter {
|
||||
fn convert_ecss_tc_in_memory_to_reader<'a>(
|
||||
fn cache_ecss_tc_in_memory<'a>(
|
||||
&'a mut self,
|
||||
possible_packet: &'a AcceptedEcssTcAndToken,
|
||||
) -> Result<PusTcReader<'a>, PusPacketHandlingError> {
|
||||
Ok(match &possible_packet.tc_in_memory {
|
||||
) -> Result<(), PusPacketHandlingError> {
|
||||
match &possible_packet.tc_in_memory {
|
||||
super::TcInMemory::StoreAddr(addr) => {
|
||||
self.copy_tc_to_buf(*addr)?;
|
||||
PusTcReader::new(&self.pus_buf)?.0
|
||||
}
|
||||
super::TcInMemory::Vec(_) => {
|
||||
return Err(PusPacketHandlingError::InvalidTcInMemoryFormat(
|
||||
possible_packet.tc_in_memory.clone(),
|
||||
));
|
||||
}
|
||||
})
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn tc_slice_raw(&self) -> &[u8] {
|
||||
|
@ -1,11 +1,11 @@
|
||||
use crate::pool::SharedPool;
|
||||
use crate::pus::scheduler::PusScheduler;
|
||||
use crate::pus::verification::StdVerifReporterWithSender;
|
||||
use crate::pus::{EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError};
|
||||
use spacepackets::ecss::{scheduling, PusPacket};
|
||||
use spacepackets::time::cds::TimeProvider;
|
||||
use std::boxed::Box;
|
||||
|
||||
use super::verification::VerificationReporterWithSender;
|
||||
use super::{EcssTcInMemConverter, PusServiceBase, PusServiceHandler};
|
||||
|
||||
/// This is a helper class for [std] environments to handle generic PUS 11 (scheduling service)
|
||||
@ -27,7 +27,7 @@ impl<TcInMemConverter: EcssTcInMemConverter> PusService11SchedHandler<TcInMemCon
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
shared_tc_store: SharedPool,
|
||||
scheduler: PusScheduler,
|
||||
|
@ -144,7 +144,7 @@ mod tests {
|
||||
VerificationReporterWithSender::new(&verif_cfg, Box::new(verif_sender));
|
||||
let test_srv_tm_sender = MpscTmInStoreSender::new(0, "TEST_SENDER", shared_tm_store, tm_tx);
|
||||
let test_srv_tc_receiver = MpscTcInStoreReceiver::new(0, "TEST_RECEIVER", test_srv_tc_rx);
|
||||
let in_store_converter = EcssTcInStoreConverter::new(tc_pool_shared.clone());
|
||||
let in_store_converter = EcssTcInStoreConverter::new(tc_pool_shared.clone(), 2048);
|
||||
let mut pus_17_handler = PusService17TestHandler::new(
|
||||
Box::new(test_srv_tc_receiver),
|
||||
Box::new(test_srv_tm_sender),
|
||||
|
@ -7,9 +7,7 @@
|
||||
//! routing without the overhead and complication of using message queues. However, it also requires
|
||||
#[cfg(feature = "alloc")]
|
||||
use downcast_rs::{impl_downcast, Downcast};
|
||||
#[cfg(feature = "serde")]
|
||||
use serde::{Deserialize, Serialize};
|
||||
use spacepackets::{ByteConversionError, SpHeader};
|
||||
use spacepackets::SpHeader;
|
||||
|
||||
#[cfg(feature = "alloc")]
|
||||
pub mod ccsds_distrib;
|
||||
@ -24,40 +22,6 @@ pub use pus_distrib::{PusDistributor, PusServiceProvider};
|
||||
|
||||
pub type TargetId = u32;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct AddressableId {
|
||||
pub target_id: TargetId,
|
||||
pub unique_id: u32,
|
||||
}
|
||||
|
||||
impl AddressableId {
|
||||
pub fn from_raw_be(buf: &[u8]) -> Result<Self, ByteConversionError> {
|
||||
if buf.len() < 8 {
|
||||
return Err(ByteConversionError::FromSliceTooSmall {
|
||||
found: buf.len(),
|
||||
expected: 8,
|
||||
});
|
||||
}
|
||||
Ok(Self {
|
||||
target_id: u32::from_be_bytes(buf[0..4].try_into().unwrap()),
|
||||
unique_id: u32::from_be_bytes(buf[4..8].try_into().unwrap()),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
|
||||
if buf.len() < 8 {
|
||||
return Err(ByteConversionError::ToSliceTooSmall {
|
||||
found: buf.len(),
|
||||
expected: 8,
|
||||
});
|
||||
}
|
||||
buf[0..4].copy_from_slice(&self.target_id.to_be_bytes());
|
||||
buf[4..8].copy_from_slice(&self.unique_id.to_be_bytes());
|
||||
Ok(8)
|
||||
}
|
||||
}
|
||||
|
||||
/// Generic trait for object which can receive any telecommands in form of a raw bytestream, with
|
||||
/// no assumptions about the received protocol.
|
||||
///
|
||||
|
1
satrs-example/.gitignore
vendored
Normal file
1
satrs-example/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/output.log
|
@ -17,6 +17,7 @@ zerocopy = "0.6"
|
||||
csv = "1"
|
||||
num_enum = "0.7"
|
||||
thiserror = "1"
|
||||
derive-new = "0.5"
|
||||
|
||||
[dependencies.satrs-core]
|
||||
# version = "0.1.0-alpha.1"
|
||||
|
@ -1,4 +1,37 @@
|
||||
use derive_new::new;
|
||||
use satrs_core::spacepackets::ByteConversionError;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
|
||||
pub enum AcsHkIds {
|
||||
TestMgmSet = 1,
|
||||
}
|
||||
|
||||
#[derive(Debug, new, Copy, Clone)]
|
||||
pub struct HkUniqueId {
|
||||
target_id: u32,
|
||||
set_id: u32,
|
||||
}
|
||||
|
||||
impl HkUniqueId {
|
||||
#[allow(dead_code)]
|
||||
pub fn target_id(&self) -> u32 {
|
||||
self.target_id
|
||||
}
|
||||
#[allow(dead_code)]
|
||||
pub fn set_id(&self) -> u32 {
|
||||
self.set_id
|
||||
}
|
||||
|
||||
pub fn write_to_be_bytes(&self, buf: &mut [u8]) -> Result<usize, ByteConversionError> {
|
||||
if buf.len() < 8 {
|
||||
return Err(ByteConversionError::ToSliceTooSmall {
|
||||
found: buf.len(),
|
||||
expected: 8,
|
||||
});
|
||||
}
|
||||
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(8)
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,68 @@
|
||||
use derive_new::new;
|
||||
use num_enum::{IntoPrimitive, TryFromPrimitive};
|
||||
use satrs_core::events::{EventU32TypedSev, SeverityInfo};
|
||||
use satrs_core::objects::ObjectId;
|
||||
use satrs_core::spacepackets::ecss::tc::IsPusTelecommand;
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::spacepackets::{ByteConversionError, CcsdsPacket};
|
||||
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;
|
||||
|
||||
pub type Apid = u16;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum TargetIdCreationError {
|
||||
#[error("byte conversion")]
|
||||
ByteConversion(#[from] ByteConversionError),
|
||||
#[error("not enough app data to generate target ID")]
|
||||
NotEnoughAppData(usize),
|
||||
}
|
||||
|
||||
// TODO: can these stay pub?
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, new)]
|
||||
pub struct TargetIdWithApid {
|
||||
pub apid: Apid,
|
||||
pub target: TargetId,
|
||||
}
|
||||
|
||||
impl fmt::Display for TargetIdWithApid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}, {}", self.apid, self.target)
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetIdWithApid {
|
||||
pub fn apid(&self) -> Apid {
|
||||
self.apid
|
||||
}
|
||||
pub fn target_id(&self) -> TargetId {
|
||||
self.target
|
||||
}
|
||||
}
|
||||
|
||||
impl TargetIdWithApid {
|
||||
pub fn from_tc(
|
||||
tc: &(impl CcsdsPacket + PusPacket + IsPusTelecommand),
|
||||
) -> Result<Self, TargetIdCreationError> {
|
||||
if tc.user_data().len() < 4 {
|
||||
return Err(ByteConversionError::FromSliceTooSmall {
|
||||
found: tc.user_data().len(),
|
||||
expected: 8,
|
||||
}
|
||||
.into());
|
||||
}
|
||||
Ok(Self {
|
||||
apid: tc.apid(),
|
||||
target: u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap()),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub const PUS_APID: u16 = 0x02;
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, TryFromPrimitive, IntoPrimitive)]
|
||||
@ -20,6 +77,8 @@ pub enum RequestTargetId {
|
||||
AcsSubsystem = 1,
|
||||
}
|
||||
|
||||
pub const AOCS_APID: u16 = 1;
|
||||
|
||||
pub const ACS_OBJECT_ID: ObjectId = ObjectId {
|
||||
id: RequestTargetId::AcsSubsystem as u32,
|
||||
name: "ACS_SUBSYSTEM",
|
||||
|
@ -4,13 +4,14 @@ pub fn setup_logger() -> Result<(), fern::InitError> {
|
||||
out.finish(format_args!(
|
||||
"{}[{}][{}] {}",
|
||||
chrono::Local::now().format("[%Y-%m-%d][%H:%M:%S]"),
|
||||
record.target(), //(std::thread::current().name().expect("unnamed_thread"),
|
||||
std::thread::current().name().expect("unnamed_thread"),
|
||||
record.level(),
|
||||
message
|
||||
))
|
||||
})
|
||||
.level(log::LevelFilter::Debug)
|
||||
.chain(std::io::stdout())
|
||||
.chain(fern::log_file("output.log")?)
|
||||
.apply()?;
|
||||
Ok(())
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
mod ccsds;
|
||||
mod hk;
|
||||
mod logging;
|
||||
mod logger;
|
||||
mod pus;
|
||||
mod requests;
|
||||
mod tcp;
|
||||
@ -12,8 +12,8 @@ use satrs_core::hal::std::tcp_server::ServerConfig;
|
||||
use satrs_core::hal::std::udp_server::UdpTcServer;
|
||||
|
||||
use crate::ccsds::CcsdsReceiver;
|
||||
use crate::hk::AcsHkIds;
|
||||
use crate::logging::setup_logger;
|
||||
use crate::hk::{AcsHkIds, HkUniqueId};
|
||||
use crate::logger::setup_logger;
|
||||
use crate::pus::action::{Pus8Wrapper, PusService8ActionHandler};
|
||||
use crate::pus::event::Pus5Wrapper;
|
||||
use crate::pus::hk::{Pus3Wrapper, PusService3HkHandler};
|
||||
@ -42,7 +42,7 @@ use satrs_core::pus::test::PusService17TestHandler;
|
||||
use satrs_core::pus::verification::{
|
||||
TcStateStarted, VerificationReporterCfg, VerificationReporterWithSender, VerificationToken,
|
||||
};
|
||||
use satrs_core::pus::{MpscTcInStoreReceiver, MpscTmInStoreSender};
|
||||
use satrs_core::pus::{EcssTcInStoreConverter, MpscTcInStoreReceiver, MpscTmInStoreSender};
|
||||
use satrs_core::seq_count::{CcsdsSimpleSeqCountProvider, SequenceCountProviderCore};
|
||||
use satrs_core::spacepackets::ecss::tm::{PusTmCreator, PusTmZeroCopyWriter};
|
||||
use satrs_core::spacepackets::{
|
||||
@ -50,10 +50,11 @@ use satrs_core::spacepackets::{
|
||||
SpHeader,
|
||||
};
|
||||
use satrs_core::tmtc::tm_helper::SharedTmStore;
|
||||
use satrs_core::tmtc::{AddressableId, CcsdsDistributor, TargetId};
|
||||
use satrs_core::tmtc::{CcsdsDistributor, TargetId};
|
||||
use satrs_core::ChannelId;
|
||||
use satrs_example::{
|
||||
RequestTargetId, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, PUS_APID, SERVER_PORT,
|
||||
RequestTargetId, TargetIdWithApid, TcReceiverId, TmSenderId, OBSW_SERVER_ADDR, PUS_APID,
|
||||
SERVER_PORT,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::net::{IpAddr, SocketAddr};
|
||||
@ -131,7 +132,8 @@ fn main() {
|
||||
// Some request are targetable. This map is used to retrieve sender handles based on a target ID.
|
||||
let mut request_map = HashMap::new();
|
||||
let (acs_thread_tx, acs_thread_rx) = channel::<RequestWithToken>();
|
||||
request_map.insert(RequestTargetId::AcsSubsystem as TargetId, acs_thread_tx);
|
||||
let target_apid = TargetIdWithApid::new(PUS_APID, RequestTargetId::AcsSubsystem as TargetId);
|
||||
request_map.insert(target_apid, acs_thread_tx);
|
||||
|
||||
let tc_source_wrapper = PusTcSource {
|
||||
tc_store: tc_store.clone(),
|
||||
@ -177,10 +179,10 @@ fn main() {
|
||||
);
|
||||
let pus17_handler = PusService17TestHandler::new(
|
||||
Box::new(test_srv_receiver),
|
||||
tc_store.pool.clone(),
|
||||
Box::new(test_srv_tm_sender),
|
||||
PUS_APID,
|
||||
verif_reporter.clone(),
|
||||
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
||||
);
|
||||
let mut pus_17_wrapper = Service17CustomWrapper {
|
||||
pus17_handler,
|
||||
@ -202,10 +204,11 @@ fn main() {
|
||||
.expect("Creating PUS Scheduler failed");
|
||||
let pus_11_handler = PusService11SchedHandler::new(
|
||||
Box::new(sched_srv_receiver),
|
||||
tc_store.pool.clone(),
|
||||
Box::new(sched_srv_tm_sender),
|
||||
PUS_APID,
|
||||
verif_reporter.clone(),
|
||||
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
||||
tc_store.pool.clone(),
|
||||
scheduler,
|
||||
);
|
||||
let mut pus_11_wrapper = Pus11Wrapper {
|
||||
@ -226,10 +229,10 @@ fn main() {
|
||||
);
|
||||
let pus_5_handler = PusService5EventHandler::new(
|
||||
Box::new(event_srv_receiver),
|
||||
tc_store.pool.clone(),
|
||||
Box::new(event_srv_tm_sender),
|
||||
PUS_APID,
|
||||
verif_reporter.clone(),
|
||||
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
||||
event_request_tx,
|
||||
);
|
||||
let mut pus_5_wrapper = Pus5Wrapper { pus_5_handler };
|
||||
@ -247,10 +250,10 @@ fn main() {
|
||||
);
|
||||
let pus_8_handler = PusService8ActionHandler::new(
|
||||
Box::new(action_srv_receiver),
|
||||
tc_store.pool.clone(),
|
||||
Box::new(action_srv_tm_sender),
|
||||
PUS_APID,
|
||||
verif_reporter.clone(),
|
||||
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
||||
request_map.clone(),
|
||||
);
|
||||
let mut pus_8_wrapper = Pus8Wrapper { pus_8_handler };
|
||||
@ -265,10 +268,10 @@ fn main() {
|
||||
MpscTcInStoreReceiver::new(TcReceiverId::PusHk as ChannelId, "PUS_8_TC_RECV", pus_hk_rx);
|
||||
let pus_3_handler = PusService3HkHandler::new(
|
||||
Box::new(hk_srv_receiver),
|
||||
tc_store.pool.clone(),
|
||||
Box::new(hk_srv_tm_sender),
|
||||
PUS_APID,
|
||||
verif_reporter.clone(),
|
||||
EcssTcInStoreConverter::new(tc_store.pool.clone(), 2048),
|
||||
request_map,
|
||||
);
|
||||
let mut pus_3_wrapper = Pus3Wrapper { pus_3_handler };
|
||||
@ -440,9 +443,13 @@ 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, RequestTargetId::AcsSubsystem as u32);
|
||||
if request.targeted_request.target_id
|
||||
assert_eq!(
|
||||
target.target_id(),
|
||||
RequestTargetId::AcsSubsystem as u32
|
||||
);
|
||||
if request.targeted_request.target_id.target
|
||||
== AcsHkIds::TestMgmSet as u32
|
||||
{
|
||||
let mut sp_header = SpHeader::tm(
|
||||
@ -458,11 +465,8 @@ fn main() {
|
||||
×tamp,
|
||||
);
|
||||
let mut buf: [u8; 8] = [0; 8];
|
||||
let addressable_id = AddressableId {
|
||||
target_id: target,
|
||||
unique_id,
|
||||
};
|
||||
addressable_id.write_to_be_bytes(&mut buf).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,
|
||||
|
@ -1,47 +1,44 @@
|
||||
use crate::requests::{ActionRequest, Request, RequestWithToken};
|
||||
use log::{error, warn};
|
||||
use satrs_core::pool::SharedPool;
|
||||
use satrs_core::pus::verification::{
|
||||
FailParams, StdVerifReporterWithSender, TcStateAccepted, VerificationToken,
|
||||
FailParams, TcStateAccepted, VerificationReporterWithSender, VerificationToken,
|
||||
};
|
||||
use satrs_core::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceHandler,
|
||||
EcssTcInMemConverter, EcssTcInStoreConverter, EcssTcReceiver, EcssTmSender,
|
||||
PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, PusServiceHandler,
|
||||
};
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::tmtc::TargetId;
|
||||
use satrs_example::tmtc_err;
|
||||
use satrs_example::{tmtc_err, TargetIdWithApid};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub struct PusService8ActionHandler {
|
||||
psb: PusServiceHandler,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
pub struct PusService8ActionHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
psb: PusServiceHandler<TcInMemConverter>,
|
||||
request_handlers: HashMap<TargetIdWithApid, Sender<RequestWithToken>>,
|
||||
}
|
||||
|
||||
impl PusService8ActionHandler {
|
||||
impl<TcInMemConverter: EcssTcInMemConverter> PusService8ActionHandler<TcInMemConverter> {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
shared_tc_pool: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: VerificationReporterWithSender,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
request_handlers: HashMap<TargetIdWithApid, Sender<RequestWithToken>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_pool,
|
||||
tm_sender,
|
||||
tm_apid,
|
||||
verification_handler,
|
||||
tc_in_mem_converter,
|
||||
),
|
||||
request_handlers,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PusService8ActionHandler {
|
||||
fn handle_action_request_with_id(
|
||||
&self,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
@ -51,6 +48,7 @@ impl PusService8ActionHandler {
|
||||
let user_data = tc.user_data();
|
||||
if user_data.len() < 8 {
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_failure(
|
||||
@ -62,7 +60,8 @@ impl PusService8ActionHandler {
|
||||
"Expected at least 4 bytes".into(),
|
||||
));
|
||||
}
|
||||
let target_id = u32::from_be_bytes(user_data[0..4].try_into().unwrap());
|
||||
//let target_id = u32::from_be_bytes(user_data[0..4].try_into().unwrap());
|
||||
let target_id = TargetIdWithApid::from_tc(tc).unwrap();
|
||||
let action_id = u32::from_be_bytes(user_data[4..8].try_into().unwrap());
|
||||
if let Some(sender) = self.request_handlers.get(&target_id) {
|
||||
sender
|
||||
@ -77,8 +76,9 @@ impl PusService8ActionHandler {
|
||||
.expect("Forwarding action request failed");
|
||||
} else {
|
||||
let mut fail_data: [u8; 4] = [0; 4];
|
||||
fail_data.copy_from_slice(&target_id.to_be_bytes());
|
||||
fail_data.copy_from_slice(&target_id.target.to_be_bytes());
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_failure(
|
||||
@ -104,11 +104,12 @@ impl PusService8ActionHandler {
|
||||
}
|
||||
let ecss_tc_and_token = possible_packet.unwrap();
|
||||
self.psb
|
||||
.convert_possible_packet_to_tc_buf(&ecss_tc_and_token)?;
|
||||
let (tc, _) = PusTcReader::new(&self.psb.pus_buf).unwrap();
|
||||
.tc_in_mem_converter
|
||||
.cache_ecss_tc_in_memory(&ecss_tc_and_token)?;
|
||||
let tc = PusTcReader::new(self.psb.tc_in_mem_converter.tc_slice_raw())?.0;
|
||||
let subservice = tc.subservice();
|
||||
let mut partial_error = None;
|
||||
let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
|
||||
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);
|
||||
match subservice {
|
||||
128 => {
|
||||
self.handle_action_request_with_id(ecss_tc_and_token.token, &tc, &time_stamp)?;
|
||||
@ -116,6 +117,7 @@ impl PusService8ActionHandler {
|
||||
_ => {
|
||||
let fail_data = [subservice];
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_failure(
|
||||
@ -140,7 +142,7 @@ impl PusService8ActionHandler {
|
||||
}
|
||||
|
||||
pub struct Pus8Wrapper {
|
||||
pub(crate) pus_8_handler: PusService8ActionHandler,
|
||||
pub(crate) pus_8_handler: PusService8ActionHandler<EcssTcInStoreConverter>,
|
||||
}
|
||||
|
||||
impl Pus8Wrapper {
|
||||
|
@ -1,9 +1,9 @@
|
||||
use log::{error, warn};
|
||||
use satrs_core::pus::event_srv::PusService5EventHandler;
|
||||
use satrs_core::pus::PusPacketHandlerResult;
|
||||
use satrs_core::pus::{EcssTcInStoreConverter, PusPacketHandlerResult};
|
||||
|
||||
pub struct Pus5Wrapper {
|
||||
pub pus_5_handler: PusService5EventHandler,
|
||||
pub pus_5_handler: PusService5EventHandler<EcssTcInStoreConverter>,
|
||||
}
|
||||
|
||||
impl Pus5Wrapper {
|
||||
|
@ -1,39 +1,37 @@
|
||||
use crate::requests::{Request, RequestWithToken};
|
||||
use log::{error, warn};
|
||||
use satrs_core::hk::{CollectionIntervalFactor, HkRequest};
|
||||
use satrs_core::pool::SharedPool;
|
||||
use satrs_core::pus::verification::{FailParams, StdVerifReporterWithSender};
|
||||
use satrs_core::pus::{
|
||||
EcssTcReceiver, EcssTmSender, PusPacketHandlerResult, PusPacketHandlingError, PusServiceHandler,
|
||||
EcssTcInMemConverter, EcssTcInStoreConverter, EcssTcReceiver, EcssTmSender,
|
||||
PusPacketHandlerResult, PusPacketHandlingError, PusServiceBase, PusServiceHandler,
|
||||
};
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::{hk, PusPacket};
|
||||
use satrs_core::tmtc::{AddressableId, TargetId};
|
||||
use satrs_example::{hk_err, tmtc_err};
|
||||
use satrs_example::{hk_err, tmtc_err, TargetIdWithApid};
|
||||
use std::collections::HashMap;
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub struct PusService3HkHandler {
|
||||
psb: PusServiceHandler,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
pub struct PusService3HkHandler<TcInMemConverter: EcssTcInMemConverter> {
|
||||
psb: PusServiceHandler<TcInMemConverter>,
|
||||
request_handlers: HashMap<TargetIdWithApid, Sender<RequestWithToken>>,
|
||||
}
|
||||
|
||||
impl PusService3HkHandler {
|
||||
impl<TcInMemConverter: EcssTcInMemConverter> PusService3HkHandler<TcInMemConverter> {
|
||||
pub fn new(
|
||||
tc_receiver: Box<dyn EcssTcReceiver>,
|
||||
shared_tc_pool: SharedPool,
|
||||
tm_sender: Box<dyn EcssTmSender>,
|
||||
tm_apid: u16,
|
||||
verification_handler: StdVerifReporterWithSender,
|
||||
request_handlers: HashMap<TargetId, Sender<RequestWithToken>>,
|
||||
tc_in_mem_converter: TcInMemConverter,
|
||||
request_handlers: HashMap<TargetIdWithApid, Sender<RequestWithToken>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
psb: PusServiceHandler::new(
|
||||
tc_receiver,
|
||||
shared_tc_pool,
|
||||
tm_sender,
|
||||
tm_apid,
|
||||
verification_handler,
|
||||
tc_in_mem_converter,
|
||||
),
|
||||
request_handlers,
|
||||
}
|
||||
@ -45,15 +43,17 @@ impl PusService3HkHandler {
|
||||
return Ok(PusPacketHandlerResult::Empty);
|
||||
}
|
||||
let ecss_tc_and_token = possible_packet.unwrap();
|
||||
self.psb
|
||||
.convert_possible_packet_to_tc_buf(&ecss_tc_and_token)?;
|
||||
let (tc, _) = PusTcReader::new(&self.psb.pus_buf).unwrap();
|
||||
let tc = self
|
||||
.psb
|
||||
.tc_in_mem_converter
|
||||
.convert_ecss_tc_in_memory_to_reader(&ecss_tc_and_token)?;
|
||||
let subservice = tc.subservice();
|
||||
let mut partial_error = None;
|
||||
let time_stamp = self.psb.get_current_timestamp(&mut partial_error);
|
||||
let time_stamp = PusServiceBase::get_current_timestamp(&mut partial_error);
|
||||
let user_data = tc.user_data();
|
||||
if user_data.is_empty() {
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_failure(
|
||||
@ -72,6 +72,7 @@ impl PusService3HkHandler {
|
||||
&hk_err::UNIQUE_ID_MISSING
|
||||
};
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_failure(
|
||||
@ -83,12 +84,11 @@ impl PusService3HkHandler {
|
||||
"Expected at least 8 bytes of app data".into(),
|
||||
));
|
||||
}
|
||||
let addressable_id = AddressableId::from_raw_be(user_data).unwrap();
|
||||
if !self
|
||||
.request_handlers
|
||||
.contains_key(&addressable_id.target_id)
|
||||
{
|
||||
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) {
|
||||
self.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_failure(
|
||||
@ -96,16 +96,12 @@ impl PusService3HkHandler {
|
||||
FailParams::new(Some(&time_stamp), &hk_err::UNKNOWN_TARGET_ID, None),
|
||||
)
|
||||
.expect("Sending start failure TM failed");
|
||||
let tgt_id = addressable_id.target_id;
|
||||
return Err(PusPacketHandlingError::NotEnoughAppData(format!(
|
||||
"Unknown target ID {tgt_id}"
|
||||
"Unknown target ID {target_id}"
|
||||
)));
|
||||
}
|
||||
let send_request = |target: TargetId, request: HkRequest| {
|
||||
let sender = self
|
||||
.request_handlers
|
||||
.get(&addressable_id.target_id)
|
||||
.unwrap();
|
||||
let send_request = |target: TargetIdWithApid, request: HkRequest| {
|
||||
let sender = self.request_handlers.get(&target).unwrap();
|
||||
sender
|
||||
.send(RequestWithToken::new(
|
||||
target,
|
||||
@ -115,23 +111,15 @@ impl PusService3HkHandler {
|
||||
.unwrap_or_else(|_| panic!("Sending HK request {request:?} failed"));
|
||||
};
|
||||
if subservice == hk::Subservice::TcEnableHkGeneration as u8 {
|
||||
send_request(
|
||||
addressable_id.target_id,
|
||||
HkRequest::Enable(addressable_id.unique_id),
|
||||
);
|
||||
send_request(target_id, HkRequest::Enable(unique_id));
|
||||
} else if subservice == hk::Subservice::TcDisableHkGeneration as u8 {
|
||||
send_request(
|
||||
addressable_id.target_id,
|
||||
HkRequest::Disable(addressable_id.unique_id),
|
||||
);
|
||||
send_request(target_id, HkRequest::Disable(unique_id));
|
||||
} else if subservice == hk::Subservice::TcGenerateOneShotHk as u8 {
|
||||
send_request(
|
||||
addressable_id.target_id,
|
||||
HkRequest::OneShot(addressable_id.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
|
||||
.common
|
||||
.verification_handler
|
||||
.borrow_mut()
|
||||
.start_failure(
|
||||
@ -148,9 +136,9 @@ impl PusService3HkHandler {
|
||||
));
|
||||
}
|
||||
send_request(
|
||||
addressable_id.target_id,
|
||||
target_id,
|
||||
HkRequest::ModifyCollectionInterval(
|
||||
addressable_id.unique_id,
|
||||
unique_id,
|
||||
CollectionIntervalFactor::from_be_bytes(user_data[8..12].try_into().unwrap()),
|
||||
),
|
||||
);
|
||||
@ -160,7 +148,7 @@ impl PusService3HkHandler {
|
||||
}
|
||||
|
||||
pub struct Pus3Wrapper {
|
||||
pub(crate) pus_3_handler: PusService3HkHandler,
|
||||
pub(crate) pus_3_handler: PusService3HkHandler<EcssTcInStoreConverter>,
|
||||
}
|
||||
|
||||
impl Pus3Wrapper {
|
||||
|
@ -2,10 +2,10 @@ use crate::tmtc::PusTcSource;
|
||||
use log::{error, info, warn};
|
||||
use satrs_core::pus::scheduler::TcInfo;
|
||||
use satrs_core::pus::scheduler_srv::PusService11SchedHandler;
|
||||
use satrs_core::pus::PusPacketHandlerResult;
|
||||
use satrs_core::pus::{EcssTcInStoreConverter, PusPacketHandlerResult};
|
||||
|
||||
pub struct Pus11Wrapper {
|
||||
pub pus_11_handler: PusService11SchedHandler,
|
||||
pub pus_11_handler: PusService11SchedHandler<EcssTcInStoreConverter>,
|
||||
pub tc_source_wrapper: PusTcSource,
|
||||
}
|
||||
|
||||
|
@ -1,18 +1,18 @@
|
||||
use log::{info, warn};
|
||||
use satrs_core::events::EventU32;
|
||||
use satrs_core::params::Params;
|
||||
use satrs_core::pus::test::PusService17TestHandler;
|
||||
use satrs_core::pus::verification::FailParams;
|
||||
use satrs_core::pus::PusPacketHandlerResult;
|
||||
use satrs_core::pus::{EcssTcInMemConverter, PusPacketHandlerResult};
|
||||
use satrs_core::spacepackets::ecss::tc::PusTcReader;
|
||||
use satrs_core::spacepackets::ecss::PusPacket;
|
||||
use satrs_core::spacepackets::time::cds::TimeProvider;
|
||||
use satrs_core::spacepackets::time::TimeWriter;
|
||||
use satrs_core::{events::EventU32, pus::EcssTcInStoreConverter};
|
||||
use satrs_example::{tmtc_err, TEST_EVENT};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
pub struct Service17CustomWrapper {
|
||||
pub pus17_handler: PusService17TestHandler,
|
||||
pub pus17_handler: PusService17TestHandler<EcssTcInStoreConverter>,
|
||||
pub test_srv_event_sender: Sender<(EventU32, Option<Params>)>,
|
||||
}
|
||||
|
||||
@ -38,9 +38,9 @@ impl Service17CustomWrapper {
|
||||
warn!("PUS17: Subservice {subservice} not implemented")
|
||||
}
|
||||
PusPacketHandlerResult::CustomSubservice(subservice, token) => {
|
||||
let psb_mut = &mut self.pus17_handler.psb;
|
||||
let buf = psb_mut.pus_buf;
|
||||
let (tc, _) = PusTcReader::new(&buf).unwrap();
|
||||
let (tc, _) =
|
||||
PusTcReader::new(self.pus17_handler.psb.tc_in_mem_converter.tc_slice_raw())
|
||||
.unwrap();
|
||||
let time_stamper = TimeProvider::from_now_with_u16_days().unwrap();
|
||||
let mut stamp_buf: [u8; 7] = [0; 7];
|
||||
time_stamper.write_to_bytes(&mut stamp_buf).unwrap();
|
||||
@ -49,12 +49,17 @@ impl Service17CustomWrapper {
|
||||
self.test_srv_event_sender
|
||||
.send((TEST_EVENT.into(), None))
|
||||
.expect("Sending test event failed");
|
||||
let start_token = psb_mut
|
||||
let start_token = self
|
||||
.pus17_handler
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_success(token.into(), Some(&stamp_buf))
|
||||
.start_success(token, Some(&stamp_buf))
|
||||
.expect("Error sending start success");
|
||||
psb_mut
|
||||
self.pus17_handler
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.completion_success(start_token, Some(&stamp_buf))
|
||||
@ -63,6 +68,7 @@ impl Service17CustomWrapper {
|
||||
let fail_data = [tc.subservice()];
|
||||
self.pus17_handler
|
||||
.psb
|
||||
.common
|
||||
.verification_handler
|
||||
.get_mut()
|
||||
.start_failure(
|
||||
|
@ -1,7 +1,8 @@
|
||||
use derive_new::new;
|
||||
use satrs_core::hk::HkRequest;
|
||||
use satrs_core::mode::ModeRequest;
|
||||
use satrs_core::pus::verification::{TcStateAccepted, VerificationToken};
|
||||
use satrs_core::tmtc::TargetId;
|
||||
use satrs_example::TargetIdWithApid;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
@ -19,18 +20,12 @@ pub enum Request {
|
||||
Action(ActionRequest),
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
#[derive(Clone, Eq, PartialEq, Debug, new)]
|
||||
pub struct TargetedRequest {
|
||||
pub(crate) target_id: TargetId,
|
||||
pub(crate) target_id: TargetIdWithApid,
|
||||
pub(crate) request: Request,
|
||||
}
|
||||
|
||||
impl TargetedRequest {
|
||||
pub fn new(target_id: TargetId, request: Request) -> Self {
|
||||
Self { target_id, request }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||
pub struct RequestWithToken {
|
||||
pub(crate) targeted_request: TargetedRequest,
|
||||
@ -39,7 +34,7 @@ pub struct RequestWithToken {
|
||||
|
||||
impl RequestWithToken {
|
||||
pub fn new(
|
||||
target_id: u32,
|
||||
target_id: TargetIdWithApid,
|
||||
request: Request,
|
||||
token: VerificationToken<TcStateAccepted>,
|
||||
) -> Self {
|
||||
|
Loading…
Reference in New Issue
Block a user