pub enum Frame {
Lsf(LsfFrame),
Stream(StreamFrame),
- // Packet
+ Packet(PacketFrame),
// BERT
}
+#[derive(Debug, Clone, PartialEq, Eq)]
pub enum PacketType {
/// RAW
Raw,
}
impl PacketType {
+ pub fn from_proto(buf: &[u8]) -> Option<(Self, usize)> {
+ buf.utf8_chunks()
+ .next()
+ .and_then(|chunk| chunk.valid().chars().next())
+ .map(|c| match c as u32 {
+ 0x00 => (PacketType::Raw, 1),
+ 0x01 => (PacketType::Ax25, 1),
+ 0x02 => (PacketType::Aprs, 1),
+ 0x03 => (PacketType::SixLowPan, 1),
+ 0x04 => (PacketType::Ipv4, 1),
+ 0x05 => (PacketType::Sms, 1),
+ 0x06 => (PacketType::Winlink, 1),
+ _ => (PacketType::Other(c), c.len_utf8()),
+ })
+ }
+
pub fn as_proto(&self) -> ([u8; 4], usize) {
match self {
PacketType::Raw => ([0, 0, 0, 0], 1),
}
}
}
-
- pub fn from_proto(&self, buf: &[u8]) -> Option<PacketType> {
- buf.utf8_chunks()
- .next()
- .and_then(|chunk| chunk.valid().chars().next())
- .map(|c| match c as u32 {
- 0x00 => PacketType::Raw,
- 0x01 => PacketType::Ax25,
- 0x02 => PacketType::Aprs,
- 0x03 => PacketType::SixLowPan,
- 0x04 => PacketType::Ipv4,
- 0x05 => PacketType::Sms,
- 0x06 => PacketType::Winlink,
- _ => PacketType::Other(c),
- })
- }
}
#[derive(Debug, Clone, PartialEq, Eq)]
}
}
+ // TODO: encryption sub-type
+
pub fn channel_access_number(&self) -> u8 {
(self.0[12] >> 7) & 0x0f
}
pub stream_data: [u8; 16],
}
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct PacketFrame {
+ /// Application packet payload (chunk)
+ pub payload: [u8; 25],
+
+ /// Frame counter, which provides different information depending on whether this is the last frame or not.
+ pub counter: PacketFrameCounter,
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum PacketFrameCounter {
+ /// Any packet frame that comes after the LSF and is not the final frame.
+ Frame {
+ /// Which frame this is in the superframe, from 0 to 31 inclusive.
+ ///
+ /// If a 33rd frame exists (index 32), it will be a `FinalFrame` instead.
+ ///
+ /// All 25 bytes of of `payload` are filled and valid.
+ index: usize,
+ },
+ /// The final frame in the packet superframe.
+ FinalFrame {
+ /// The number of bytes in `payload` that are filled.
+ payload_len: usize,
+ },
+}
+
pub struct LichCollection([Option<[u8; 5]>; 6]);
impl LichCollection {