let mut pos_max: f32 = f32::MIN;
let mut neg_max: f32 = f32::MAX;
for i in 0..8 {
- pos_max = pos_max.max(samples[i * 10]);
- neg_max = neg_max.min(samples[i * 10]);
+ pos_max = pos_max.max(samples[i]);
+ neg_max = neg_max.min(samples[i]);
}
let gain = (pos_max - neg_max) / 2.0;
let shift = pos_max + neg_max;
if gain < SYNC_MIN_GAIN {
return (f32::MAX, gain, shift);
}
+
let mut diff = 0.0;
for i in 0..8 {
- let sym_diff = (((samples[i * 10] - shift) / gain) - target[i] as f32).abs();
+ let sym_diff = (((samples[i] - shift) / gain) - target[i] as f32).abs();
if sym_diff > SYNC_BIT_THRESHOLD {
return (f32::MAX, gain, shift);
}
None => return None,
};
debug!("full lsf: {:?}", lsf.0);
- let crc = lsf.crc();
+ let crc = lsf.check_crc();
debug!("recv crc: {:04X}", crc);
debug!("destination: {:?}", lsf.destination());
debug!("source: {:?}", lsf.source());
Some(packet) => packet,
None => return None,
};
+ // TODO: the spec is inconsistent about which bit in packet[25] is EOF
+ // https://github.com/M17-Project/M17_spec/issues/147
let final_frame = (packet[25] & 0x80) > 0;
- let number = (packet[25] >> 2) & 0x01f;
+ let number = (packet[25] >> 2) & 0x1f;
let counter = if final_frame {
PacketFrameCounter::FinalFrame {
payload_len: number as usize,