first packet routing components

This commit is contained in:
2022-08-08 01:24:28 +02:00
parent 2843a18867
commit db78b02348
14 changed files with 226 additions and 2 deletions

View File

@ -0,0 +1,19 @@
use crate::tmtc::{ReceivesCcsds, ReceivesTc};
use spacepackets::{CcsdsPacket, SpHeader};
pub trait ApidHandler {
fn get_apid_handler(&self, apid: u16) -> Box<dyn ReceivesCcsds>;
}
struct CcsdsDistributor {
apid_handlers: Box<dyn ApidHandler>,
}
impl ReceivesTc for CcsdsDistributor {
fn pass_tc(&mut self, tm_raw: &[u8]) {
// TODO: Better error handling
let sp_header = SpHeader::from_raw_slice(tm_raw).unwrap();
let mut handler = self.apid_handlers.get_apid_handler(sp_header.apid());
handler.pass_ccsds(&sp_header, tm_raw).unwrap();
}
}

18
fsrc-core/src/tmtc/mod.rs Normal file
View File

@ -0,0 +1,18 @@
use spacepackets::ecss::PusError;
use spacepackets::tc::PusTc;
use spacepackets::{PacketError, SpHeader};
pub mod ccsds_distrib;
pub mod pus_distrib;
pub trait ReceivesTc {
fn pass_tc(&mut self, tc_raw: &[u8]);
}
pub trait ReceivesCcsds {
fn pass_ccsds(&mut self, header: &SpHeader, tm_raw: &[u8]) -> Result<(), PacketError>;
}
pub trait ReceivesPus {
fn pass_pus(&mut self, pus_tc: &PusTc) -> Result<(), PusError>;
}

View File

@ -0,0 +1,39 @@
use crate::tmtc::{ReceivesCcsds, ReceivesPus, ReceivesTc};
use spacepackets::ecss::PusPacket;
use spacepackets::tc::PusTc;
use spacepackets::{CcsdsPacket, PacketError, SpHeader};
pub trait PusServiceProvider {
fn get_apid(&self, service: u8) -> u16;
fn get_service_handler(&self, service: u8, subservice: u8) -> Box<dyn ReceivesPus>;
}
pub struct PusDistributor {
service_provider: Box<dyn PusServiceProvider>,
}
impl ReceivesTc for PusDistributor {
fn pass_tc(&mut self, tm_raw: &[u8]) {
// Convert to ccsds and call pass_ccsds
let sp_header = SpHeader::from_raw_slice(tm_raw).unwrap();
self.pass_ccsds(&sp_header, tm_raw).unwrap();
}
}
impl ReceivesCcsds for PusDistributor {
fn pass_ccsds(&mut self, _header: &SpHeader, tm_raw: &[u8]) -> Result<(), PacketError> {
// TODO: Better error handling
let (tc, _) = PusTc::new_from_raw_slice(tm_raw).unwrap();
let mut srv_provider = self
.service_provider
.get_service_handler(tc.service(), tc.subservice());
let apid = self.service_provider.get_apid(tc.service());
if apid != tc.apid() {
// TODO: Dedicated error
return Ok(());
}
srv_provider.pass_pus(&tc).unwrap();
Ok(())
}
}