sat-rs/fsrc-example/src/bin/obsw/main.rs

74 lines
2.3 KiB
Rust
Raw Normal View History

2022-09-03 13:47:25 +02:00
mod ccsds;
2022-08-29 01:33:32 +02:00
mod pus;
mod tmtc;
2022-09-10 13:34:04 +02:00
use crate::tmtc::{core_tmtc_task, TmStore, PUS_APID};
2022-08-29 01:33:32 +02:00
use fsrc_core::hal::host::udp_server::UdpTcServer;
2022-09-10 13:34:04 +02:00
use fsrc_core::pool::{LocalPool, PoolCfg, SharedPool, StoreAddr};
use fsrc_core::pus::verification::{
MpscVerifSender, VerificationReporterCfg, VerificationReporterWithSender,
};
2022-08-29 01:33:32 +02:00
use fsrc_core::tmtc::CcsdsError;
use fsrc_example::{OBSW_SERVER_ADDR, SERVER_PORT};
use std::net::{IpAddr, SocketAddr};
2022-09-10 13:34:04 +02:00
use std::sync::{mpsc, Arc, Mutex, RwLock};
2022-08-29 01:33:32 +02:00
use std::thread;
struct TmFunnel {
tm_funnel_rx: mpsc::Receiver<StoreAddr>,
tm_server_tx: mpsc::Sender<StoreAddr>,
}
struct UdpTmtcServer {
udp_tc_server: UdpTcServer<CcsdsError<()>>,
tm_rx: mpsc::Receiver<StoreAddr>,
2022-09-10 13:34:04 +02:00
tm_store: SharedPool,
2022-08-29 01:33:32 +02:00
}
unsafe impl Send for UdpTmtcServer {}
fn main() {
2022-09-03 13:47:25 +02:00
println!("Running OBSW example");
2022-08-29 01:33:32 +02:00
let pool_cfg = PoolCfg::new(vec![(8, 32), (4, 64), (2, 128)]);
let tm_pool = LocalPool::new(pool_cfg);
2022-09-10 13:34:04 +02:00
let tm_store: SharedPool = Arc::new(RwLock::new(Box::new(tm_pool)));
let tm_store_helper = TmStore {
pool: tm_store.clone(),
};
2022-08-29 01:33:32 +02:00
let addr = SocketAddr::new(IpAddr::V4(OBSW_SERVER_ADDR), SERVER_PORT);
2022-09-10 13:34:04 +02:00
let (tm_funnel_tx, tm_funnel_rx) = mpsc::channel();
2022-08-29 01:33:32 +02:00
let (tm_server_tx, tm_server_rx) = mpsc::channel();
2022-09-10 13:34:04 +02:00
let sender = MpscVerifSender::new(tm_store.clone(), tm_funnel_tx.clone());
let verif_cfg = VerificationReporterCfg::new(PUS_APID, 1, 2, 8);
let reporter_with_sender_0 = Arc::new(Mutex::new(VerificationReporterWithSender::new(
verif_cfg,
Box::new(sender),
)));
2022-08-29 01:33:32 +02:00
let jh0 = thread::spawn(move || {
2022-09-10 13:34:04 +02:00
core_tmtc_task(
tm_funnel_tx.clone(),
tm_server_rx,
tm_store_helper.clone(),
addr,
reporter_with_sender_0,
);
2022-08-29 01:33:32 +02:00
});
let jh1 = thread::spawn(move || {
let tm_funnel = TmFunnel {
tm_server_tx,
tm_funnel_rx,
};
loop {
if let Ok(addr) = tm_funnel.tm_funnel_rx.recv() {
tm_funnel
.tm_server_tx
.send(addr)
.expect("Sending TM to server failed");
}
}
});
jh0.join().expect("Joining UDP TMTC server thread failed");
jh1.join().expect("Joining TM Funnel thread failed");
}