This commit is contained in:
John Goerzen 2020-09-24 21:19:25 -05:00
parent 1a5c2c47bf
commit 119f4be2b2
3 changed files with 27 additions and 5 deletions

View File

@ -53,6 +53,14 @@ struct Opt {
/// Serial port to use to communicate with radio
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)]
cmd: Command,
}
@ -102,7 +110,7 @@ fn main() {
info!("xbnet starting");
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();
match opt.cmd {

View File

@ -81,6 +81,8 @@ impl XB {
mut ser_reader: XBSerReader,
mut ser_writer: XBSerWriter,
initfile: Option<PathBuf>,
disable_xbee_acks: bool,
request_xbee_tx_reports: bool,
) -> (XB, crossbeam_channel::Sender<XBTX>, thread::JoinHandle<()>) {
// FIXME: make this maximum of 5 configurable
let (writertx, writerrx) = crossbeam_channel::bounded(5);
@ -146,7 +148,7 @@ impl XB {
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 {
@ -164,6 +166,8 @@ fn writerthread(
mut ser: XBSerWriter,
maxpacketsize: usize,
writerrx: crossbeam_channel::Receiver<XBTX>,
disable_xbee_acks: bool,
request_xbee_tx_reports: bool,
) {
let mut packetstream = PacketStream::new();
for item in writerrx.iter() {
@ -173,7 +177,7 @@ fn writerthread(
// Here we receive a block of data, which hasn't been
// 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) => {
for packet in packets.into_iter() {
match packet.serialize() {

View File

@ -186,6 +186,8 @@ impl PacketStream {
maxpacketsize: usize,
dest: &XBDestAddr,
data: &[u8],
disable_xbee_acks: bool,
request_xbee_tx_reports: bool,
) -> Result<Vec<XBTXRequest>, String> {
let mut retval = Vec::new();
if data.is_empty() {
@ -202,12 +204,20 @@ impl PacketStream {
let mut payload = BytesMut::new();
payload.put_u8(chunks_remaining - 1);
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 {
frame_id,
dest_addr: dest.clone(),
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),
};