projects
/
m17rt
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Round trip packet modulation and demodulation via RRC
[m17rt]
/
m17core
/
src
/
decode.rs
diff --git
a/m17core/src/decode.rs
b/m17core/src/decode.rs
index 9fd83cdba625f9ead891b0c5a5ceb72783521ce5..911d67371cf5f5273446992cd2d472cb4ac18b47 100755
(executable)
--- a/
m17core/src/decode.rs
+++ b/
m17core/src/decode.rs
@@
-3,8
+3,8
@@
use crate::{
fec::{self, p_1, p_2, p_3},
interleave::interleave,
protocol::{
fec::{self, p_1, p_2, p_3},
interleave::interleave,
protocol::{
- LsfFrame, PacketFrame, PacketFrameCounter, StreamFrame, BERT_SYNC,
LSF_SYNC, PACKET_SYNC
,
- STREAM_SYNC,
+ LsfFrame, PacketFrame, PacketFrameCounter, StreamFrame, BERT_SYNC,
END_OF_TRANSMISSION
,
+
LSF_SYNC, PACKET_SYNC, PREAMBLE,
STREAM_SYNC,
},
random::random_xor,
};
},
random::random_xor,
};
@@
-33,6
+33,8
@@
pub(crate) enum SyncBurst {
Bert,
Stream,
Packet,
Bert,
Stream,
Packet,
+ Preamble,
+ EndOfTransmission,
}
impl SyncBurst {
}
impl SyncBurst {
@@
-42,6
+44,8
@@
impl SyncBurst {
Self::Bert => BERT_SYNC,
Self::Stream => STREAM_SYNC,
Self::Packet => PACKET_SYNC,
Self::Bert => BERT_SYNC,
Self::Stream => STREAM_SYNC,
Self::Packet => PACKET_SYNC,
+ Self::Preamble => PREAMBLE,
+ Self::EndOfTransmission => END_OF_TRANSMISSION,
}
}
}
}
}
}
@@
-54,17
+58,18
@@
pub(crate) fn sync_burst_correlation(target: [i8; 8], samples: &[f32]) -> (f32,
let mut pos_max: f32 = f32::MIN;
let mut neg_max: f32 = f32::MAX;
for i in 0..8 {
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 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 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);
}
if sym_diff > SYNC_BIT_THRESHOLD {
return (f32::MAX, gain, shift);
}
@@
-94,7
+99,7
@@
pub(crate) fn parse_lsf(frame: &[f32] /* length 192 */) -> Option<LsfFrame> {
None => return None,
};
debug!("full lsf: {:?}", lsf.0);
None => return None,
};
debug!("full lsf: {:?}", lsf.0);
- let crc = lsf.crc();
+ let crc = lsf.c
heck_c
rc();
debug!("recv crc: {:04X}", crc);
debug!("destination: {:?}", lsf.destination());
debug!("source: {:?}", lsf.source());
debug!("recv crc: {:04X}", crc);
debug!("destination: {:?}", lsf.destination());
debug!("source: {:?}", lsf.source());
@@
-141,8
+146,10
@@
pub(crate) fn parse_packet(frame: &[f32] /* length 192 */) -> Option<PacketFrame
Some(packet) => packet,
None => return None,
};
Some(packet) => packet,
None => return None,
};
- let final_frame = (packet[25] & 0x04) > 0;
- let number = packet[25] >> 3;
+ // 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) & 0x1f;
let counter = if final_frame {
PacketFrameCounter::FinalFrame {
payload_len: number as usize,
let counter = if final_frame {
PacketFrameCounter::FinalFrame {
payload_len: number as usize,