better printout format
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
|
||||
use spacepackets::ecss::PusPacket;
|
||||
use spacepackets::tc::PusTc;
|
||||
use spacepackets::tm::PusTm;
|
||||
use spacepackets::SpHeader;
|
||||
use std::net::{IpAddr, SocketAddr, UdpSocket};
|
||||
use std::time::Duration;
|
||||
|
||||
fn main() {
|
||||
let mut buf = [0; 32];
|
||||
println!("Packing and sending PUS ping command TC[17,1]");
|
||||
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
|
||||
let mut sph = SpHeader::tc(0x02, 0, 0).unwrap();
|
||||
let pus_tc = PusTc::new_simple(&mut sph, 17, 1, None, true);
|
||||
@ -17,8 +20,18 @@ fn main() {
|
||||
client
|
||||
.set_read_timeout(Some(Duration::from_secs(2)))
|
||||
.expect("Setting read timeout failed");
|
||||
if let Ok(len) = client.recv(&mut buf) {
|
||||
println!("Received TM with {} bytes", len);
|
||||
if let Ok(_len) = client.recv(&mut buf) {
|
||||
let (pus_tm, size) = PusTm::new_from_raw_slice(&buf, 7).expect("Parsing PUS TM failed");
|
||||
if pus_tm.service() == 17 && pus_tm.subservice() == 2 {
|
||||
println!("Received PUS Ping Reply TM[17,2]")
|
||||
} else {
|
||||
println!(
|
||||
"Received TM[{}, {}] with {} bytes",
|
||||
pus_tm.service(),
|
||||
pus_tm.subservice(),
|
||||
size
|
||||
);
|
||||
}
|
||||
} else {
|
||||
println!("No reply received for 2 seconds or timeout");
|
||||
}
|
||||
|
37
fsrc-example/src/bin/obsw/ccsds.rs
Normal file
37
fsrc-example/src/bin/obsw/ccsds.rs
Normal file
@ -0,0 +1,37 @@
|
||||
use crate::tmtc::PUS_APID;
|
||||
use fsrc_core::tmtc::{CcsdsPacketHandler, PusDistributor, ReceivesCcsdsTc};
|
||||
use spacepackets::{CcsdsPacket, SpHeader};
|
||||
|
||||
pub struct CcsdsReceiver {
|
||||
pub pus_handler: PusDistributor<()>,
|
||||
}
|
||||
|
||||
impl CcsdsPacketHandler for CcsdsReceiver {
|
||||
type Error = ();
|
||||
|
||||
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 {
|
||||
self.pus_handler
|
||||
.pass_ccsds(sp_header, tc_raw)
|
||||
.expect("Handling PUS packet failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_unknown_apid(
|
||||
&mut self,
|
||||
_sp_header: &SpHeader,
|
||||
_tc_raw: &[u8],
|
||||
) -> Result<(), Self::Error> {
|
||||
println!("Unknown APID detected");
|
||||
Ok(())
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
mod ccsds;
|
||||
mod pus;
|
||||
mod tmtc;
|
||||
|
||||
@ -24,6 +25,7 @@ struct UdpTmtcServer {
|
||||
unsafe impl Send for UdpTmtcServer {}
|
||||
|
||||
fn main() {
|
||||
println!("Running OBSW example");
|
||||
let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]);
|
||||
let tm_pool = LocalPool::new(pool_cfg);
|
||||
let tm_store = Arc::new(Mutex::new(TmStore { pool: tm_pool }));
|
||||
|
@ -1 +1,57 @@
|
||||
use crate::TmStore;
|
||||
use fsrc_core::pool::StoreAddr;
|
||||
use fsrc_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
|
||||
use fsrc_core::tmtc::PusServiceProvider;
|
||||
use spacepackets::tc::{PusTc, PusTcSecondaryHeaderT};
|
||||
use spacepackets::SpHeader;
|
||||
use std::sync::{mpsc, Arc, Mutex};
|
||||
|
||||
pub struct PusReceiver {
|
||||
pub tm_helper: PusTmWithCdsShortHelper,
|
||||
pub tm_tx: mpsc::Sender<StoreAddr>,
|
||||
pub tm_store: Arc<Mutex<TmStore>>,
|
||||
}
|
||||
|
||||
impl PusReceiver {
|
||||
pub fn new(apid: u16, tm_tx: mpsc::Sender<StoreAddr>, tm_store: Arc<Mutex<TmStore>>) -> Self {
|
||||
Self {
|
||||
tm_helper: PusTmWithCdsShortHelper::new(apid),
|
||||
tm_tx,
|
||||
tm_store,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PusServiceProvider for PusReceiver {
|
||||
type Error = ();
|
||||
|
||||
fn handle_pus_tc_packet(
|
||||
&mut self,
|
||||
service: u8,
|
||||
_header: &SpHeader,
|
||||
pus_tc: &PusTc,
|
||||
) -> Result<(), Self::Error> {
|
||||
if service == 17 {
|
||||
self.handle_test_service(pus_tc);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PusReceiver {
|
||||
fn handle_test_service(&mut self, pus_tc: &PusTc) {
|
||||
if pus_tc.subservice() == 1 {
|
||||
println!("Received PUS ping command TC[17,1]");
|
||||
println!("Sending ping reply PUS TM[17,2]");
|
||||
let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None);
|
||||
let addr = self
|
||||
.tm_store
|
||||
.lock()
|
||||
.expect("Locking TM store failed")
|
||||
.add_pus_tm(&ping_reply);
|
||||
self.tm_tx
|
||||
.send(addr)
|
||||
.expect("Sending TM to TM funnel failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,16 +4,12 @@ use std::sync::{mpsc, Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::ccsds::CcsdsReceiver;
|
||||
use crate::pus::PusReceiver;
|
||||
use crate::UdpTmtcServer;
|
||||
use fsrc_core::pool::{LocalPool, StoreAddr};
|
||||
use fsrc_core::tmtc::tm_helper::PusTmWithCdsShortHelper;
|
||||
use fsrc_core::tmtc::{
|
||||
CcsdsDistributor, CcsdsError, CcsdsPacketHandler, PusDistributor, PusServiceProvider,
|
||||
ReceivesCcsdsTc,
|
||||
};
|
||||
use spacepackets::tc::PusTc;
|
||||
use fsrc_core::tmtc::{CcsdsDistributor, CcsdsError, PusDistributor};
|
||||
use spacepackets::tm::PusTm;
|
||||
use spacepackets::{CcsdsPacket, SpHeader};
|
||||
|
||||
pub const PUS_APID: u16 = 0x02;
|
||||
|
||||
@ -22,7 +18,7 @@ pub struct TmStore {
|
||||
}
|
||||
|
||||
impl TmStore {
|
||||
fn add_pus_tm(&mut self, pus_tm: &PusTm) -> StoreAddr {
|
||||
pub fn add_pus_tm(&mut self, pus_tm: &PusTm) -> StoreAddr {
|
||||
let (addr, buf) = self
|
||||
.pool
|
||||
.free_element(pus_tm.len_packed())
|
||||
@ -34,92 +30,6 @@ impl TmStore {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CcsdsReceiver {
|
||||
pub pus_handler: PusDistributor<()>,
|
||||
}
|
||||
|
||||
impl CcsdsPacketHandler for CcsdsReceiver {
|
||||
type Error = ();
|
||||
|
||||
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 {
|
||||
self.pus_handler
|
||||
.pass_ccsds(sp_header, tc_raw)
|
||||
.expect("Handling PUS packet failed");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn handle_unknown_apid(
|
||||
&mut self,
|
||||
_sp_header: &SpHeader,
|
||||
_tc_raw: &[u8],
|
||||
) -> Result<(), Self::Error> {
|
||||
println!("Unknown APID detected");
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
unsafe impl Send for CcsdsReceiver {}
|
||||
|
||||
pub struct PusReceiver {
|
||||
pub tm_helper: PusTmWithCdsShortHelper,
|
||||
pub tm_tx: mpsc::Sender<StoreAddr>,
|
||||
pub tm_store: Arc<Mutex<TmStore>>,
|
||||
}
|
||||
|
||||
impl PusReceiver {
|
||||
pub fn new(apid: u16, tm_tx: mpsc::Sender<StoreAddr>, tm_store: Arc<Mutex<TmStore>>) -> Self {
|
||||
Self {
|
||||
tm_helper: PusTmWithCdsShortHelper::new(apid),
|
||||
tm_tx,
|
||||
tm_store,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl PusServiceProvider for PusReceiver {
|
||||
type Error = ();
|
||||
|
||||
fn handle_pus_tc_packet(
|
||||
&mut self,
|
||||
service: u8,
|
||||
_header: &SpHeader,
|
||||
pus_tc: &PusTc,
|
||||
) -> Result<(), Self::Error> {
|
||||
if service == 17 {
|
||||
self.handle_test_service(pus_tc);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl PusReceiver {
|
||||
fn handle_test_service(&mut self, pus_tc: &PusTc) {
|
||||
println!("Received PUS ping command");
|
||||
let raw_data = pus_tc.raw().expect("Could not retrieve raw data");
|
||||
println!("Raw data: 0x{raw_data:x?}");
|
||||
println!("Sending ping reply");
|
||||
let ping_reply = self.tm_helper.create_pus_tm_timestamp_now(17, 2, None);
|
||||
let addr = self
|
||||
.tm_store
|
||||
.lock()
|
||||
.expect("Locking TM store failed")
|
||||
.add_pus_tm(&ping_reply);
|
||||
self.tm_tx
|
||||
.send(addr)
|
||||
.expect("Sending TM to TM funnel failed");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn core_tmtc_task(
|
||||
tm_creator_tx: mpsc::Sender<StoreAddr>,
|
||||
tm_server_rx: mpsc::Receiver<StoreAddr>,
|
||||
|
Reference in New Issue
Block a user