This commit is contained in:
John Goerzen 2020-09-20 21:28:15 -05:00
parent a8a9f73d9e
commit 1bd4875838
2 changed files with 8 additions and 7 deletions

View File

@ -29,6 +29,7 @@ use format_escape_default::format_escape_default;
use std::path::PathBuf; use std::path::PathBuf;
use bytes::Bytes; use bytes::Bytes;
use std::convert::TryInto; use std::convert::TryInto;
use crate::xbpacket::*;
pub fn mkerror(msg: &str) -> Error { pub fn mkerror(msg: &str) -> Error {
Error::new(ErrorKind::Other, msg) Error::new(ErrorKind::Other, msg)
@ -42,13 +43,13 @@ pub struct ReceivedFrames(pub Vec<u8>, pub Option<(String, String)>);
#[derive(Clone)] #[derive(Clone)]
pub struct XB { pub struct XB {
ser: XBSer, pub ser: XBSer,
/// My 64-bit MAC address /// My 64-bit MAC address
mymac: u64, pub mymac: u64,
/// Maximum packet size /// Maximum packet size
maxpacketsize: usize, pub maxpacketsize: usize,
} }
/// Assert that a given response didn't indicate an EOF, and that it /// Assert that a given response didn't indicate an EOF, and that it
@ -89,7 +90,7 @@ impl XB {
let reader = BufReader::new(f); let reader = BufReader::new(f);
for line in reader.lines() { for line in reader.lines() {
if line.unwrap().len() > 0 { if line.unwrap().len() > 0 {
self.ser.writeln(line.unwrap()).unwrap(); ser.writeln(&line.unwrap()).unwrap();
assert_response(ser.readln().unwrap().unwrap(), String::from("OK")); assert_response(ser.readln().unwrap().unwrap(), String::from("OK"));
} }
} }
@ -141,14 +142,14 @@ fn writerthread(ser: XBSer, maxpacketsize: usize,
// 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 packetize_data(maxpacketsize, dest, data) { match packetize_data(maxpacketsize, dest, &data) {
Ok(packets) => { Ok(packets) => {
let serport = ser.swrite.lock().unwrap(); let serport = ser.swrite.lock().unwrap();
for packet in packets.into_iter() { for packet in packets.into_iter() {
match packet.serialize() { match packet.serialize() {
Ok(datatowrite) => { Ok(datatowrite) => {
trace!("TX to {:?} data {}", dest, hex::encode(datatowrite)); trace!("TX to {:?} data {}", dest, hex::encode(datatowrite));
serport.write_all(datatowrite).unwrap(); serport.write_all(&datatowrite).unwrap();
serport.flush(); serport.flush();
}, },
Err(e) => { Err(e) => {

View File

@ -87,7 +87,7 @@ pub fn rxxbpacket(ser: &XBSer) -> Option<RXPacket> {
let sender_addr64 = inner.get_u64(); let sender_addr64 = inner.get_u64();
let sender_addr16 = inner.get_u16(); let sender_addr16 = inner.get_u16();
let sender_rxoptions = inner.get_u8(); let rx_options = inner.get_u8();
let payload = inner.to_bytes(); let payload = inner.to_bytes();
trace!("SERIN: packet from {} / {}, payload {}", hex::encode(sender_addr64.to_be_bytes()), hex::encode(sender_addr16.to_be_bytes()), hex::encode(payload)); trace!("SERIN: packet from {} / {}, payload {}", hex::encode(sender_addr64.to_be_bytes()), hex::encode(sender_addr16.to_be_bytes()), hex::encode(payload));
Some(RXPacket {sender_addr64, sender_addr16, rx_options, payload}) Some(RXPacket {sender_addr64, sender_addr16, rx_options, payload})