Skip to content

Commit

Permalink
framing: don't filter on valid_vcids
Browse files Browse the repository at this point in the history
  • Loading branch information
bmflynn committed Feb 6, 2025
1 parent 7442de8 commit 5a25218
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
4 changes: 2 additions & 2 deletions ccsds-lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let frames = decode_frames(
).filter_map(Result::ok);
// 3. Extract packets from Frames
let packets = decode_framed_packets(frames, izone_len, trailer_len, None);
let packets = decode_framed_packets(frames, izone_len, trailer_len);
```

It is also possible to have more control over the decode process for cases that do not
Expand Down Expand Up @@ -87,7 +87,7 @@ let cadus = Synchronizer::new(file, block_len)
let frames = decode_frames(cadus, None, None).filter_map(|z| z.ok());
// 3. Extract packets from Frames
let packets = decode_framed_packets(frames, izone_len, trailer_len, None);
let packets = decode_framed_packets(frames, izone_len, trailer_len);
```

## References:
Expand Down
2 changes: 2 additions & 0 deletions ccsds-lib/src/framing/integrity/reed_solomon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ impl DefaultReedSolomon {
}
}

/// Create a instance that removed parity but does not actually perform the algorithm on any
/// frames. All results will have [Integrity::Skipped].
pub fn noop(interleave: u8) -> Self {
Self {
interleave,
Expand Down
32 changes: 6 additions & 26 deletions ccsds-lib/src/framing/packets.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
use std::{
collections::{HashMap, HashSet, VecDeque},
collections::{HashMap, VecDeque},
fmt::Display,
};

use spacecrafts::Spacecraft;
use tracing::{debug, trace};

use crate::framing::{integrity::Integrity, DecodedFrame, Scid, Vcid};
use crate::spacepacket::{Packet, PrimaryHeader};

use super::Apid;

struct VcidTracker {
vcid: Vcid,
/// Caches partial packets for this vcid
Expand Down Expand Up @@ -67,7 +64,6 @@ where
frames: I,
izone_length: usize,
trailer_length: usize,
valid_apids: HashSet<Apid>,

// Cache of partial packet data from frames that has not yet been decoded into
// packets. There should only be up to about 1 frame worth of data in the cache
Expand Down Expand Up @@ -168,7 +164,7 @@ where
// The start of the cache should always contain a packet primary header
let mut header =
PrimaryHeader::decode(&tracker.cache).expect("failed to decode primary header");
if !valid_packet_header(&header, &self.valid_apids) {
if !valid_packet_header(&header) {
tracker.reset();
continue;
}
Expand Down Expand Up @@ -206,7 +202,7 @@ where
}
header =
PrimaryHeader::decode(&tracker.cache).expect("failed to decode primary header");
if !valid_packet_header(&header, &self.valid_apids) {
if !valid_packet_header(&header) {
tracker.reset();
break;
}
Expand All @@ -225,18 +221,12 @@ where
}
}

/// Perform sanity checks on packet header and return true if the packet header appears to be valid
/// and the APID is in `valid_apids`.
fn valid_packet_header(header: &PrimaryHeader, valid_apids: &HashSet<Apid>) -> bool {
fn valid_packet_header(header: &PrimaryHeader) -> bool {
if header.version != 0 || header.type_flag != 0 {
debug!("bad packet version or type, dropping {header:?}");
false
} else if !valid_apids.is_empty() && !valid_apids.contains(&header.apid) {
debug!("invalid apid for spacecraft, dropping {header:?}");
false
} else {
true
return false;
}
true
}

/// Decodes the provided frames into a packets contained within the frames' MPDUs.
Expand All @@ -251,24 +241,14 @@ pub fn decode_framed_packets<I>(
frames: I,
izone_length: usize,
trailer_length: usize,
spacecraft: Option<Spacecraft>,
) -> impl Iterator<Item = DecodedPacket> + Send
where
I: Iterator<Item = DecodedFrame> + Send,
{
let mut valid_apids = HashSet::default();
if let Some(spacecraft) = spacecraft {
for vcid in spacecraft.vcids {
for apid in vcid.apids {
valid_apids.insert(apid.apid);
}
}
}
FramedPacketIter {
frames: frames.filter(|dc| !dc.frame.is_fill()),
izone_length,
trailer_length,
valid_apids,
cache: HashMap::new(),
ready: VecDeque::new(),
}
Expand Down

0 comments on commit 5a25218

Please sign in to comment.