ops-sat-rs/src/tmtc/tc_source.rs

49 lines
1.5 KiB
Rust
Raw Normal View History

2024-04-13 15:16:53 +02:00
use std::sync::mpsc::{self, TryRecvError};
2024-04-29 21:18:32 +02:00
use ops_sat_rs::HandlingStatus;
2024-04-15 14:13:10 +02:00
use satrs::{pus::MpscTmAsVecSender, tmtc::PacketAsVec};
2024-04-13 15:16:53 +02:00
2024-04-29 21:18:32 +02:00
use crate::pus::PusTcDistributor;
2024-04-13 15:16:53 +02:00
// TC source components where the heap is the backing memory of the received telecommands.
pub struct TcSourceTaskDynamic {
2024-04-15 12:16:01 +02:00
pub tc_receiver: mpsc::Receiver<PacketAsVec>,
pus_distrib: PusTcDistributor<MpscTmAsVecSender>,
2024-04-13 15:16:53 +02:00
}
impl TcSourceTaskDynamic {
pub fn new(
2024-04-15 12:16:01 +02:00
tc_receiver: mpsc::Receiver<PacketAsVec>,
2024-04-13 15:16:53 +02:00
pus_receiver: PusTcDistributor<MpscTmAsVecSender>,
) -> Self {
Self {
tc_receiver,
2024-04-15 12:16:01 +02:00
pus_distrib: pus_receiver,
2024-04-13 15:16:53 +02:00
}
}
pub fn periodic_operation(&mut self) {
self.poll_tc();
}
2024-04-15 14:13:10 +02:00
pub fn poll_tc(&mut self) -> HandlingStatus {
2024-04-15 12:16:01 +02:00
// Right now, we only expect PUS packets. If any other protocols like CFDP are added at
// a later stage, we probably need to check for the APID before routing the packet.
2024-04-13 15:16:53 +02:00
match self.tc_receiver.try_recv() {
2024-04-15 12:16:01 +02:00
Ok(packet_with_sender) => {
self.pus_distrib
.handle_tc_packet(packet_with_sender.sender_id, packet_with_sender.packet)
.ok();
2024-04-15 14:13:10 +02:00
HandlingStatus::HandledOne
2024-04-15 12:16:01 +02:00
}
2024-04-13 15:16:53 +02:00
Err(e) => match e {
2024-04-15 14:13:10 +02:00
TryRecvError::Empty => HandlingStatus::Empty,
2024-04-13 15:16:53 +02:00
TryRecvError::Disconnected => {
log::warn!("tmtc thread: sender disconnected");
2024-04-15 14:13:10 +02:00
HandlingStatus::Empty
2024-04-13 15:16:53 +02:00
}
},
}
}
}