From 38bd1573e7adc4c561113f12e3afdf8dbff7fea0 Mon Sep 17 00:00:00 2001 From: John Goerzen Date: Sun, 3 Nov 2019 18:15:19 -0600 Subject: [PATCH] Checkpointing packet work --- src/kiss.rs | 2 ++ src/lorastik.rs | 4 ++-- src/main.rs | 6 +++++- src/pipe.rs | 4 +--- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/kiss.rs b/src/kiss.rs index 6a76fca..58cde13 100644 --- a/src/kiss.rs +++ b/src/kiss.rs @@ -38,6 +38,8 @@ pub fn stdintolorakiss(ls: &mut LoraStik, maxframesize: usize) -> io::Result<()> let mut buf = Vec::new(); let res = br.read_until(FEND, &mut buf)?; + // buf now ends with FEND but doesn't begin with it (in the case of a frame) + if res == 0 { // EOF return Ok(()); diff --git a/src/lorastik.rs b/src/lorastik.rs index fef3878..1fe42a7 100644 --- a/src/lorastik.rs +++ b/src/lorastik.rs @@ -108,7 +108,7 @@ impl LoraStik { /// as well as a separate receiver to be used in a separate thread to handle /// incoming frames. The bool specifies whether or not to read the quality /// parameters after a read. - pub fn new(ser: LoraSer, readqual: bool, txwait: u64, eotwait: u64, maxpacketsize: usize) -> (LoraStik, crossbeam_channel::Receiver) { + pub fn new(ser: LoraSer, readqual: bool, txwait: u64, eotwait: u64, maxpacketsize: usize, pack: bool) -> (LoraStik, crossbeam_channel::Receiver) { let (readerlinestx, readerlinesrx) = crossbeam_channel::unbounded(); let (txblockstx, txblocksrx) = crossbeam_channel::bounded(3); let (readeroutput, readeroutputreader) = crossbeam_channel::unbounded(); @@ -117,7 +117,7 @@ impl LoraStik { thread::spawn(move || readerlinesthread(ser2, readerlinestx)); - (LoraStik { readqual, ser, readeroutput, readerlinesrx, txblockstx, txblocksrx, maxpacketsize, + (LoraStik { readqual, ser, readeroutput, readerlinesrx, txblockstx, txblocksrx, maxpacketsize, pack, txdelay: None, txwait: Duration::from_millis(txwait), eotwait: Duration::from_millis(eotwait), diff --git a/src/main.rs b/src/main.rs index 3a0b04f..02f0ac3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,6 +41,10 @@ struct Opt { /// Read and log quality data after receiving packets #[structopt(long)] readqual: bool, + + /// Pack as many bytes as possible into each TX frame, regardless of original framing + #[structopt(long)] + pack: bool, /// Radio initialization command file #[structopt(long, parse(from_os_str))] @@ -100,7 +104,7 @@ fn main() { let maxpacketsize = opt.maxpacketsize; let loraser = ser::LoraSer::new(opt.port).expect("Failed to initialize serial port"); - let (mut ls, radioreceiver) = lorastik::LoraStik::new(loraser, opt.readqual, opt.txwait, opt.eotwait, maxpacketsize); + let (mut ls, radioreceiver) = lorastik::LoraStik::new(loraser, opt.readqual, opt.txwait, opt.eotwait, maxpacketsize, pack); ls.radiocfg(opt.initfile).expect("Failed to configure radio"); let mut ls2 = ls.clone(); diff --git a/src/pipe.rs b/src/pipe.rs index c3abcd3..05b49f4 100644 --- a/src/pipe.rs +++ b/src/pipe.rs @@ -34,9 +34,7 @@ pub fn stdintolora(ls: &mut LoraStik, maxframesize: usize) -> io::Result<()> { return Ok(()); } - for chunk in buf[0..res].chunks(maxframesize) { - ls.transmit(&chunk); - } + ls.transmit(&buf); } }