}
let mut full_payload = vec![];
full_payload.extend_from_slice(&pack_type[0..pack_type_len]);
- full_payload.extend_from_slice(&payload);
+ full_payload.extend_from_slice(payload);
let crc = m17core::crc::m17_crc(&full_payload);
full_payload.extend_from_slice(&crc.to_be_bytes());
let kiss_frame = KissFrame::new_full_packet(&link_setup.raw.0, &full_payload).unwrap();
// as long as there is only one TNC it is implied there is only ever one stream transmission in flight
pub fn transmit_stream_next(&self, stream: &StreamFrame) {
- let kiss_frame = KissFrame::new_stream_data(&stream).unwrap();
+ let kiss_frame = KissFrame::new_stream_data(stream).unwrap();
let _ = self.event_tx.send(TncControlEvent::Kiss(kiss_frame));
}
}
}
/// Carries a request from a method on M17App to the TNC's writer thread, which will execute it.
+#[allow(clippy::large_enum_variant)]
enum TncControlEvent {
Kiss(KissFrame),
Start,
let mut kiss_buffer = KissBuffer::new();
let mut stream_running = false;
loop {
- let mut buf = kiss_buffer.buf_remaining();
- let n = match tnc.read(&mut buf) {
+ let buf = kiss_buffer.buf_remaining();
+ let n = match tnc.read(buf) {
Ok(n) => n,
Err(_) => break,
};
for s in subs {
s.packet_received(
LinkSetup::new_raw(lsf.clone()),
- packet_type.clone(),
+ packet_type,
packet_payload.clone(),
);
}
while let Ok(ev) = event_rx.recv() {
match ev {
TncControlEvent::Kiss(k) => {
- if let Err(e) = tnc.write_all(&k.as_bytes()) {
+ if let Err(e) = tnc.write_all(k.as_bytes()) {
debug!("kiss send err: {:?}", e);
return;
}
continue;
};
if configs
- .find(|config| {
- config.channels() == 1 && config.sample_format() == SampleFormat::I16
- })
- .is_some()
+ .any(|config| config.channels() == 1 && config.sample_format() == SampleFormat::I16)
{
let Ok(name) = d.name() else {
continue;
continue;
};
if configs
- .find(|config| {
- config.channels() == 1 && config.sample_format() == SampleFormat::I16
- })
- .is_some()
+ .any(|config| config.channels() == 1 && config.sample_format() == SampleFormat::I16)
{
let Ok(name) = d.name() else {
continue;
if let Err(e) = samples.try_send(SoundmodemEvent::BasebandInput(buf.into())) {
debug!("overflow feeding soundmodem: {e:?}");
}
- next_tick = next_tick + TICK;
+ next_tick += TICK;
idx = 0;
std::thread::sleep(next_tick.duration_since(Instant::now()));
}
loop {
std::thread::sleep(next_tick.duration_since(Instant::now()));
- next_tick = next_tick + TICK;
+ next_tick += TICK;
if end_rx.try_recv() != Err(TryRecvError::Empty) {
break;
}
}
}
+impl Default for NullInputSource {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
pub struct OutputBuffer {
pub idling: bool,
// TODO: something more efficient
}
}
+impl Default for OutputBuffer {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
pub trait OutputSink: Send + Sync + 'static {
fn start(&self, event_tx: SyncSender<SoundmodemEvent>, buffer: Arc<RwLock<OutputBuffer>>);
fn close(&self);
loop {
std::thread::sleep(next_tick.duration_since(Instant::now()));
- next_tick = next_tick + TICK;
+ next_tick += TICK;
if end_rx.try_recv() != Err(TryRecvError::Empty) {
break;
}
}
}
+impl Default for NullOutputSink {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl OutputSink for NullOutputSink {
fn start(&self, event_tx: SyncSender<SoundmodemEvent>, buffer: Arc<RwLock<OutputBuffer>>) {
let (end_tx, end_rx) = channel();
loop {
std::thread::sleep(next_tick.duration_since(Instant::now()));
- next_tick = next_tick + TICK;
+ next_tick += TICK;
if end_rx.try_recv() != Err(TryRecvError::Empty) {
break;
}
let mut buffer = buffer.write().unwrap();
let mut taken = 0;
for _ in 0..SAMPLES_PER_TICK {
- if !buffer.samples.pop_front().is_some() {
+ if buffer.samples.pop_front().is_none() {
if !buffer.idling {
debug!("null output had underrun");
let _ = event_tx.send(SoundmodemEvent::OutputUnderrun);
}
}
+impl Default for NullPtt {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
impl Ptt for NullPtt {
fn ptt_on(&mut self) {}
fn ptt_off(&mut self) {}
}
}
+impl Default for Codec2Adapter {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
struct AdapterState {
tx: Option<TxHandle>,
/// Circular buffer of output samples for playback
loop {
let mut last_one = false;
- for mut out in out_buf.chunks_mut(8) {
- for i in 0..160 {
+ for out in out_buf.chunks_mut(8) {
+ for i in in_buf.iter_mut() {
let sample = match samples.next() {
Some(Ok(sample)) => sample,
_ => {
0
}
};
- in_buf[i] = sample;
+ *i = sample;
}
- codec.encode(&mut out, &in_buf);
+ codec.encode(out, &in_buf);
}
tx.transmit_stream_next(&StreamFrame {
lich_idx: lsf_chunk as u8,
lich_part: setup.lich_part(lsf_chunk as u8),
frame_number,
end_of_stream: last_one,
- stream_data: out_buf.clone(),
+ stream_data: out_buf,
});
frame_number += 1;
lsf_chunk = (lsf_chunk + 1) % 6;
fn test_buffer_double() {
let mut buffer = KissBuffer::new();
let buf = buffer.buf_remaining();
- buf[0..8].copy_from_slice(&[FEND, 0x10, 0x01, FEND, FEND, 0x20, 02, FEND]);
+ buf[0..8].copy_from_slice(&[FEND, 0x10, 0x01, FEND, FEND, 0x20, 0x02, FEND]);
buffer.did_write(8);
let next = buffer.next_frame().unwrap();
fn test_buffer_double_shared_fend() {
let mut buffer = KissBuffer::new();
let buf = buffer.buf_remaining();
- buf[0..7].copy_from_slice(&[FEND, 0x10, 0x01, FEND, 0x20, 02, FEND]);
+ buf[0..7].copy_from_slice(&[FEND, 0x10, 0x01, FEND, 0x20, 0x02, FEND]);
buffer.did_write(7);
let next = buffer.next_frame().unwrap();
fn test_buffer_extra_fend() {
let mut buffer = KissBuffer::new();
let buf = buffer.buf_remaining();
- buf[0..10].copy_from_slice(&[FEND, FEND, FEND, 0x10, 0x01, FEND, FEND, 0x20, 02, FEND]);
+ buf[0..10].copy_from_slice(&[FEND, FEND, FEND, 0x10, 0x01, FEND, FEND, 0x20, 0x02, FEND]);
buffer.did_write(10);
let next = buffer.next_frame().unwrap();
sent: usize,
}
+#[allow(clippy::large_enum_variant)]
enum State {
/// Nothing happening. We may have TX data queued but we won't act on it until CSMA opens up.
Idle,