sat-rs/satrs-example/src/ccsds.rs

45 lines
1.1 KiB
Rust
Raw Normal View History

use satrs_core::pus::ReceivesEcssPusTc;
2023-01-10 17:16:57 +01:00
use satrs_core::spacepackets::{CcsdsPacket, SpHeader};
use satrs_core::tmtc::{CcsdsPacketHandler, ReceivesCcsdsTc};
use satrs_example::config::PUS_APID;
2022-09-03 13:47:25 +02:00
2023-09-29 14:11:03 +02:00
#[derive(Clone)]
pub struct CcsdsReceiver<
TcSource: ReceivesCcsdsTc<Error = E> + ReceivesEcssPusTc<Error = E> + Clone,
E,
> {
pub tc_source: TcSource,
2022-09-03 13:47:25 +02:00
}
impl<
TcSource: ReceivesCcsdsTc<Error = E> + ReceivesEcssPusTc<Error = E> + Clone + 'static,
E: 'static,
> CcsdsPacketHandler for CcsdsReceiver<TcSource, E>
{
type Error = E;
2022-09-03 13:47:25 +02:00
fn valid_apids(&self) -> &'static [u16] {
&[PUS_APID]
}
fn handle_known_apid(
&mut self,
sp_header: &SpHeader,
tc_raw: &[u8],
) -> Result<(), Self::Error> {
if sp_header.apid() == PUS_APID {
return self.tc_source.pass_ccsds(sp_header, tc_raw);
2022-09-03 13:47:25 +02:00
}
Ok(())
}
fn handle_unknown_apid(
&mut self,
2022-11-20 18:45:11 +01:00
sp_header: &SpHeader,
2022-09-03 13:47:25 +02:00
_tc_raw: &[u8],
) -> Result<(), Self::Error> {
2022-11-20 18:45:11 +01:00
println!("Unknown APID 0x{:x?} detected", sp_header.apid());
2022-09-03 13:47:25 +02:00
Ok(())
}
}