mirror of https://github.com/jgoerzen/xbnet.git
updates
This commit is contained in:
parent
3326b41ab4
commit
9e9699c459
|
@ -80,7 +80,7 @@ fn main() {
|
|||
info!("xbnet starting");
|
||||
|
||||
let xbser = ser::XBSer::new(opt.port).expect("Failed to initialize serial port");
|
||||
let (xb, xbeesender) = xb::XB::new(xbser, opt.initfile);
|
||||
let (xb, xbeesender, writerthread) = xb::XB::new(xbser, opt.initfile);
|
||||
let mut xbreframer = xbrx::XBReframer::new();
|
||||
|
||||
|
||||
|
@ -95,8 +95,11 @@ fn main() {
|
|||
},
|
||||
Command::Pipe{dest} => {
|
||||
let dest_u64:u64 = u64::from_str_radix(&dest, 16).expect("Invalid destination");
|
||||
thread::spawn(move || pipe::stdin_processor(dest_u64, 1600, xbeesender).expect("Failure in stdin_processor"));
|
||||
pipe::stdout_processor(&mut xbreframer, &xb.ser).expect("Failure in stdout_processor");
|
||||
thread::spawn(move || pipe::stdout_processor(&mut xbreframer, &xb.ser).expect("Failure in stdout_processor"));
|
||||
pipe::stdin_processor(dest_u64, 1600, xbeesender).expect("Failure in stdin_processor");
|
||||
// Make sure queued up data is sent
|
||||
writerthread.join();
|
||||
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
10
src/xb.rs
10
src/xb.rs
|
@ -44,7 +44,6 @@ pub enum XBTX {
|
|||
}
|
||||
|
||||
/// Main XBeeNet struct
|
||||
#[derive(Clone)]
|
||||
pub struct XB {
|
||||
pub ser: XBSer,
|
||||
|
||||
|
@ -70,14 +69,14 @@ pub fn assert_response(resp: String, expected: String) -> io::Result<()> {
|
|||
impl XB {
|
||||
/** Creates a new XB. Returns an instance to be used for reading,
|
||||
as well as a separate sender to be used in a separate thread to handle
|
||||
outgoing frames. This will spawn a thread to handle the writing to XBee.
|
||||
outgoing frames. This will spawn a thread to handle the writing to XBee, which is returned.
|
||||
|
||||
If initfile is given, its lines will be sent to the radio, one at a time,
|
||||
expecting OK after each one, to initialize it.
|
||||
|
||||
May panic if an error occurs during initialization.
|
||||
*/
|
||||
pub fn new(mut ser: XBSer, initfile: Option<PathBuf>) -> (XB, crossbeam_channel::Sender<XBTX>) {
|
||||
pub fn new(mut ser: XBSer, initfile: Option<PathBuf>) -> (XB, crossbeam_channel::Sender<XBTX>, thread::JoinHandle<()>) {
|
||||
// FIXME: make this maximum of 5 configurable
|
||||
let (writertx, writerrx) = crossbeam_channel::bounded(5);
|
||||
|
||||
|
@ -144,14 +143,15 @@ impl XB {
|
|||
debug!("Radio configuration complete");
|
||||
|
||||
let ser2 = ser.clone();
|
||||
thread::spawn(move || writerthread(ser2, maxpacketsize, writerrx));
|
||||
let writerthread = thread::spawn(move || writerthread(ser2, maxpacketsize, writerrx));
|
||||
|
||||
(XB {
|
||||
ser,
|
||||
mymac,
|
||||
maxpacketsize,
|
||||
}, writertx)
|
||||
}, writertx, writerthread)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fn writerthread(ser: XBSer, maxpacketsize: usize,
|
||||
|
|
Loading…
Reference in New Issue