mirror of
https://github.com/jgoerzen/xbnet.git
synced 2025-01-20 10:48:28 -04:00
update
This commit is contained in:
parent
1a5c2c47bf
commit
119f4be2b2
10
src/main.rs
10
src/main.rs
@ -53,6 +53,14 @@ struct Opt {
|
|||||||
/// Serial port to use to communicate with radio
|
/// Serial port to use to communicate with radio
|
||||||
port: PathBuf,
|
port: PathBuf,
|
||||||
|
|
||||||
|
/// Disable the Xbee-level ACKs
|
||||||
|
#[structopt(long)]
|
||||||
|
disable_xbee_acks: bool,
|
||||||
|
|
||||||
|
/// Request XBee transmit reports. These will appear in debug mode but otherwise are not considered.
|
||||||
|
#[structopt(long)]
|
||||||
|
request_xbee_tx_reports: bool,
|
||||||
|
|
||||||
#[structopt(subcommand)]
|
#[structopt(subcommand)]
|
||||||
cmd: Command,
|
cmd: Command,
|
||||||
}
|
}
|
||||||
@ -102,7 +110,7 @@ fn main() {
|
|||||||
info!("xbnet starting");
|
info!("xbnet starting");
|
||||||
|
|
||||||
let (ser_reader, ser_writer) = ser::new(opt.port).expect("Failed to initialize serial port");
|
let (ser_reader, ser_writer) = ser::new(opt.port).expect("Failed to initialize serial port");
|
||||||
let (mut xb, xbeesender, writerthread) = xb::XB::new(ser_reader, ser_writer, opt.initfile);
|
let (mut xb, xbeesender, writerthread) = xb::XB::new(ser_reader, ser_writer, opt.initfile, opt.disable_xbee_acks, opt.request_xbee_tx_reports);
|
||||||
let mut xbreframer = xbrx::XBReframer::new();
|
let mut xbreframer = xbrx::XBReframer::new();
|
||||||
|
|
||||||
match opt.cmd {
|
match opt.cmd {
|
||||||
|
@ -81,6 +81,8 @@ impl XB {
|
|||||||
mut ser_reader: XBSerReader,
|
mut ser_reader: XBSerReader,
|
||||||
mut ser_writer: XBSerWriter,
|
mut ser_writer: XBSerWriter,
|
||||||
initfile: Option<PathBuf>,
|
initfile: Option<PathBuf>,
|
||||||
|
disable_xbee_acks: bool,
|
||||||
|
request_xbee_tx_reports: bool,
|
||||||
) -> (XB, crossbeam_channel::Sender<XBTX>, thread::JoinHandle<()>) {
|
) -> (XB, crossbeam_channel::Sender<XBTX>, thread::JoinHandle<()>) {
|
||||||
// FIXME: make this maximum of 5 configurable
|
// FIXME: make this maximum of 5 configurable
|
||||||
let (writertx, writerrx) = crossbeam_channel::bounded(5);
|
let (writertx, writerrx) = crossbeam_channel::bounded(5);
|
||||||
@ -146,7 +148,7 @@ impl XB {
|
|||||||
|
|
||||||
debug!("Radio configuration complete");
|
debug!("Radio configuration complete");
|
||||||
|
|
||||||
let writerthread = thread::spawn(move || writerthread(ser_writer, maxpacketsize, writerrx));
|
let writerthread = thread::spawn(move || writerthread(ser_writer, maxpacketsize, writerrx, disable_xbee_acks, request_xbee_tx_reports));
|
||||||
|
|
||||||
(
|
(
|
||||||
XB {
|
XB {
|
||||||
@ -164,6 +166,8 @@ fn writerthread(
|
|||||||
mut ser: XBSerWriter,
|
mut ser: XBSerWriter,
|
||||||
maxpacketsize: usize,
|
maxpacketsize: usize,
|
||||||
writerrx: crossbeam_channel::Receiver<XBTX>,
|
writerrx: crossbeam_channel::Receiver<XBTX>,
|
||||||
|
disable_xbee_acks: bool,
|
||||||
|
request_xbee_tx_reports: bool,
|
||||||
) {
|
) {
|
||||||
let mut packetstream = PacketStream::new();
|
let mut packetstream = PacketStream::new();
|
||||||
for item in writerrx.iter() {
|
for item in writerrx.iter() {
|
||||||
@ -173,7 +177,7 @@ fn writerthread(
|
|||||||
// Here we receive a block of data, which hasn't been
|
// Here we receive a block of data, which hasn't been
|
||||||
// packetized. Packetize it and send out the result.
|
// packetized. Packetize it and send out the result.
|
||||||
|
|
||||||
match packetstream.packetize_data(maxpacketsize, &dest, &data) {
|
match packetstream.packetize_data(maxpacketsize, &dest, &data, disable_xbee_acks, request_xbee_tx_reports) {
|
||||||
Ok(packets) => {
|
Ok(packets) => {
|
||||||
for packet in packets.into_iter() {
|
for packet in packets.into_iter() {
|
||||||
match packet.serialize() {
|
match packet.serialize() {
|
||||||
|
@ -186,6 +186,8 @@ impl PacketStream {
|
|||||||
maxpacketsize: usize,
|
maxpacketsize: usize,
|
||||||
dest: &XBDestAddr,
|
dest: &XBDestAddr,
|
||||||
data: &[u8],
|
data: &[u8],
|
||||||
|
disable_xbee_acks: bool,
|
||||||
|
request_xbee_tx_reports: bool,
|
||||||
) -> Result<Vec<XBTXRequest>, String> {
|
) -> Result<Vec<XBTXRequest>, String> {
|
||||||
let mut retval = Vec::new();
|
let mut retval = Vec::new();
|
||||||
if data.is_empty() {
|
if data.is_empty() {
|
||||||
@ -202,12 +204,20 @@ impl PacketStream {
|
|||||||
let mut payload = BytesMut::new();
|
let mut payload = BytesMut::new();
|
||||||
payload.put_u8(chunks_remaining - 1);
|
payload.put_u8(chunks_remaining - 1);
|
||||||
payload.put_slice(chunk);
|
payload.put_slice(chunk);
|
||||||
let frame_id = 0; // self.get_and_incr_framecounter(); // FIXME: make this configurable whether we get back TX reports.
|
let frame_id = if request_xbee_tx_reports {
|
||||||
|
self.get_and_incr_framecounter()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
let packet = XBTXRequest {
|
let packet = XBTXRequest {
|
||||||
frame_id,
|
frame_id,
|
||||||
dest_addr: dest.clone(),
|
dest_addr: dest.clone(),
|
||||||
broadcast_radius: 0,
|
broadcast_radius: 0,
|
||||||
transmit_options: 0x01, // FIXME: make this configurable whether or not to request ACKs (0x01 disables; 0x00 default)
|
transmit_options: if disable_xbee_acks {
|
||||||
|
0x01
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
},
|
||||||
payload: Bytes::from(payload),
|
payload: Bytes::from(payload),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user