mirror of https://github.com/jgoerzen/xbnet.git
fixing
This commit is contained in:
parent
1bd4875838
commit
612e05d82f
|
@ -25,7 +25,7 @@ mod ser;
|
|||
mod xb;
|
||||
mod xbpacket;
|
||||
mod xbrx;
|
||||
mod pipe;
|
||||
// mod pipe;
|
||||
mod ping;
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn pong(xbreframer: &mut XBReframer, ser: &XBSer, sender: crossbeam_channel:
|
|||
loop {
|
||||
let (addr_64, addr_16, payload) = xbreframer.rxframe(ser);
|
||||
if payload.starts_with(b"Ping ") {
|
||||
let resp = format!("Pong {}", Strimg::from_utf8_lossy(payload[5..]));
|
||||
let resp = format!("Pong {}", String::from_utf8_lossy(&payload[5..]));
|
||||
sender.send((XBDestAddr::U64(addr_64), Bytes::from(resp.as_bytes())));
|
||||
}
|
||||
}
|
||||
|
|
30
src/pipe.rs
30
src/pipe.rs
|
@ -17,34 +17,4 @@
|
|||
|
||||
use std::io;
|
||||
use std::io::{Read, Write};
|
||||
use crate::lorastik::{LoraStik, ReceivedFrames};
|
||||
use crossbeam_channel;
|
||||
|
||||
/// A thread for stdin processing
|
||||
pub fn stdintolora(ls: &mut LoraStik) -> io::Result<()> {
|
||||
let stdin = io::stdin();
|
||||
let mut br = io::BufReader::new(stdin);
|
||||
|
||||
let mut buf = vec![0u8; 1024];
|
||||
|
||||
loop {
|
||||
let res = br.read(&mut buf)?;
|
||||
if res == 0 {
|
||||
// EOF
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
ls.transmit(&buf[0..res]);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn loratostdout(receiver: crossbeam_channel::Receiver<ReceivedFrames>) -> io::Result<()> {
|
||||
let mut stdout = io::stdout();
|
||||
|
||||
loop {
|
||||
let data = receiver.recv().unwrap();
|
||||
stdout.write_all(&data.0)?;
|
||||
stdout.flush()?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ use log::*;
|
|||
use std::sync::{Arc, Mutex};
|
||||
use std::time::Duration;
|
||||
use std::path::PathBuf;
|
||||
use bytes::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct XBSer {
|
||||
|
@ -70,11 +71,11 @@ impl XBSer {
|
|||
/// Transmits a command with terminating EOL characters
|
||||
pub fn writeln(&mut self, mut data: &str) -> io::Result<()> {
|
||||
trace!("{:?} SEROUT: {}", self.portname, data);
|
||||
let mut data = ByteMut::from(data.as_bytes());
|
||||
data.push(b"\r\n");
|
||||
let mut data = BytesMut::from(data.as_bytes());
|
||||
data.put(&b"\r\n"[..]);
|
||||
// Give the receiver a chance to process
|
||||
// FIXME: lock this only once
|
||||
self.swrite.lock().unwrap().write_all(data)?;
|
||||
self.swrite.lock().unwrap().write_all(&data)?;
|
||||
self.swrite.lock().unwrap().flush()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,10 +153,10 @@ fn writerthread(ser: XBSer, maxpacketsize: usize,
|
|||
serport.flush();
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Serialization error: {}", e),
|
||||
error!("Serialization error: {:?}", e);
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
};
|
||||
},
|
||||
Err(e) => {
|
||||
error!("Packetization error: {}", e);
|
||||
|
|
|
@ -65,7 +65,7 @@ pub fn rxxbpacket(ser: &XBSer) -> Option<RXPacket> {
|
|||
let length = usize::from(u16::from_be_bytes(lenbytes));
|
||||
|
||||
// Now read the rest of the frame.
|
||||
let mut inner = [0u8; length];
|
||||
let mut inner = vec![0u8; length];
|
||||
|
||||
serport.read_exact(&mut inner).unwrap();
|
||||
|
||||
|
@ -124,7 +124,7 @@ impl XBReframer {
|
|||
*olddata
|
||||
} else {
|
||||
BytesMut::new()
|
||||
}
|
||||
};
|
||||
|
||||
frame.extend_from_slice(&packet.payload[1..]);
|
||||
if packet.payload[0] == 0x0 {
|
||||
|
|
Loading…
Reference in New Issue