some improvements
This commit is contained in:
parent
75bd86c802
commit
6dcb9d719c
@ -1,8 +1,8 @@
|
|||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
|
|
||||||
|
/// This trait encapsulates being able to cast a trait object to its original concrete type
|
||||||
|
/// TODO: Add example code and maybe write derive macro because this code is always the same
|
||||||
pub trait AsAny {
|
pub trait AsAny {
|
||||||
// I am not 100 % sure this is the best idea, but it allows downcasting the trait object
|
|
||||||
// to its original concrete type.
|
|
||||||
fn as_any(&self) -> &dyn Any;
|
fn as_any(&self) -> &dyn Any;
|
||||||
fn as_mut_any(&mut self) -> &mut dyn Any;
|
fn as_mut_any(&mut self) -> &mut dyn Any;
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,15 @@ pub struct PusDistributor {
|
|||||||
impl ReceivesTc for PusDistributor {
|
impl ReceivesTc for PusDistributor {
|
||||||
fn pass_tc(&mut self, tm_raw: &[u8]) {
|
fn pass_tc(&mut self, tm_raw: &[u8]) {
|
||||||
// Convert to ccsds and call pass_ccsds
|
// Convert to ccsds and call pass_ccsds
|
||||||
let sp_header = SpHeader::from_raw_slice(tm_raw).unwrap();
|
match SpHeader::from_raw_slice(tm_raw) {
|
||||||
|
Ok(sp_header) => {
|
||||||
self.pass_ccsds(&sp_header, tm_raw).unwrap();
|
self.pass_ccsds(&sp_header, tm_raw).unwrap();
|
||||||
}
|
}
|
||||||
|
Err(error) => {
|
||||||
|
// TODO: Error handling
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReceivesCcsdsTc for PusDistributor {
|
impl ReceivesCcsdsTc for PusDistributor {
|
||||||
@ -126,7 +132,8 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ApidPacketHandler for ApidHandlerShared {
|
macro_rules! apid_handler_impl {
|
||||||
|
() => {
|
||||||
fn valid_apids(&self) -> &'static [u16] {
|
fn valid_apids(&self) -> &'static [u16] {
|
||||||
&[0x000, 0x002]
|
&[0x000, 0x002]
|
||||||
}
|
}
|
||||||
@ -141,6 +148,11 @@ mod tests {
|
|||||||
fn handle_unknown_apid(&mut self, sp_header: &SpHeader, tc_raw: &[u8]) {
|
fn handle_unknown_apid(&mut self, sp_header: &SpHeader, tc_raw: &[u8]) {
|
||||||
self.handler_base.handle_unknown_apid(&sp_header, tc_raw);
|
self.handler_base.handle_unknown_apid(&sp_header, tc_raw);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ApidPacketHandler for ApidHandlerShared {
|
||||||
|
apid_handler_impl!();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ApidHandlerOwned {
|
struct ApidHandlerOwned {
|
||||||
@ -159,21 +171,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ApidPacketHandler for ApidHandlerOwned {
|
impl ApidPacketHandler for ApidHandlerOwned {
|
||||||
fn valid_apids(&self) -> &'static [u16] {
|
apid_handler_impl!();
|
||||||
&[0x000, 0x002]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_known_apid(&mut self, sp_header: &SpHeader, tc_raw: &[u8]) {
|
|
||||||
self.handler_base.handle_known_apid(&sp_header, tc_raw);
|
|
||||||
self.pus_distrib
|
|
||||||
.pass_ccsds(&sp_header, tc_raw)
|
|
||||||
.expect("Passing PUS packet failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_unknown_apid(&mut self, sp_header: &SpHeader, tc_raw: &[u8]) {
|
|
||||||
self.handler_base.handle_unknown_apid(&sp_header, tc_raw);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pus_distribution() {
|
fn test_pus_distribution() {
|
||||||
let known_packet_queue = Arc::new(Mutex::default());
|
let known_packet_queue = Arc::new(Mutex::default());
|
||||||
|
Loading…
Reference in New Issue
Block a user