2023-09-20 15:18:20 +02:00
|
|
|
pub mod ccsds;
|
|
|
|
pub mod cobs;
|
|
|
|
|
|
|
|
pub use crate::encoding::ccsds::parse_buffer_for_ccsds_space_packets;
|
2023-09-20 15:20:14 +02:00
|
|
|
pub use crate::encoding::cobs::{encode_packet_with_cobs, parse_buffer_for_cobs_encoded_packets};
|
2023-09-20 15:18:20 +02:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
pub(crate) mod tests {
|
2024-04-16 11:04:22 +02:00
|
|
|
use core::cell::RefCell;
|
2023-09-21 16:34:18 +02:00
|
|
|
|
2024-04-16 11:04:22 +02:00
|
|
|
use alloc::collections::VecDeque;
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
tmtc::{PacketAsVec, PacketSenderRaw},
|
|
|
|
ComponentId,
|
|
|
|
};
|
2023-09-21 16:34:18 +02:00
|
|
|
|
2023-09-20 15:18:20 +02:00
|
|
|
use super::cobs::encode_packet_with_cobs;
|
|
|
|
|
|
|
|
pub(crate) const SIMPLE_PACKET: [u8; 5] = [1, 2, 3, 4, 5];
|
|
|
|
pub(crate) const INVERTED_PACKET: [u8; 5] = [5, 4, 3, 2, 1];
|
|
|
|
|
2023-09-21 16:34:18 +02:00
|
|
|
#[derive(Default)]
|
|
|
|
pub(crate) struct TcCacher {
|
2024-04-16 11:04:22 +02:00
|
|
|
pub(crate) tc_queue: RefCell<VecDeque<PacketAsVec>>,
|
2023-09-21 16:34:18 +02:00
|
|
|
}
|
|
|
|
|
2024-04-16 11:04:22 +02:00
|
|
|
impl PacketSenderRaw for TcCacher {
|
2023-09-21 16:34:18 +02:00
|
|
|
type Error = ();
|
|
|
|
|
2024-04-16 11:04:22 +02:00
|
|
|
fn send_packet(&self, sender_id: ComponentId, tc_raw: &[u8]) -> Result<(), Self::Error> {
|
|
|
|
let mut mut_queue = self.tc_queue.borrow_mut();
|
|
|
|
mut_queue.push_back(PacketAsVec::new(sender_id, tc_raw.to_vec()));
|
2023-09-21 16:34:18 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-20 15:18:20 +02:00
|
|
|
pub(crate) fn encode_simple_packet(encoded_buf: &mut [u8], current_idx: &mut usize) {
|
2023-09-21 16:34:18 +02:00
|
|
|
encode_packet_with_cobs(&SIMPLE_PACKET, encoded_buf, current_idx);
|
2023-09-20 15:18:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
pub(crate) fn encode_inverted_packet(encoded_buf: &mut [u8], current_idx: &mut usize) {
|
2023-09-21 16:34:18 +02:00
|
|
|
encode_packet_with_cobs(&INVERTED_PACKET, encoded_buf, current_idx);
|
2023-09-20 15:18:20 +02:00
|
|
|
}
|
|
|
|
}
|