mirror of https://github.com/jgoerzen/xbnet.git
some tweaks
This commit is contained in:
parent
44db52ff32
commit
6683b4fef8
|
@ -49,10 +49,11 @@ pub fn displaypongs(xbreframer: &mut XBReframer, ser: &XBSer) -> () {
|
|||
/// Reply to pings
|
||||
pub fn pong(xbreframer: &mut XBReframer, ser: &XBSer, sender: crossbeam_channel::Sender<(XBDestAddr, Bytes)>) -> io::Result<()> {
|
||||
loop {
|
||||
let (addr_64, _addr_16, payload) = xbreframer.rxframe(ser);
|
||||
let (fromu64, _addr_16, payload) = xbreframer.rxframe(ser);
|
||||
if payload.starts_with(b"Ping ") {
|
||||
println!("RECV from {}: {}", hex::encode(fromu64.to_be_bytes()), String::from_utf8_lossy(&payload));
|
||||
let resp = Bytes::from(format!("Pong {}", String::from_utf8_lossy(&payload[5..])));
|
||||
sender.send((XBDestAddr::U64(addr_64), resp)).unwrap();
|
||||
sender.send((XBDestAddr::U64(fromu64), resp)).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
|
||||
use bytes::*;
|
||||
use std::convert::{TryInto, TryFrom};
|
||||
use std::fmt;
|
||||
|
||||
/** XBee transmissions can give either a 64-bit or a 16-bit destination
|
||||
address. This permits the user to select one. */
|
||||
#[derive(Eq, PartialEq, Debug, Clone)]
|
||||
#[derive(Eq, PartialEq, Clone)]
|
||||
pub enum XBDestAddr {
|
||||
/// A 16-bit destination address. When a 64-bit address is given, this is transmitted as 0xFFFE.
|
||||
U16(u16),
|
||||
|
@ -32,6 +33,23 @@ pub enum XBDestAddr {
|
|||
U64(u64)
|
||||
}
|
||||
|
||||
impl fmt::Debug for XBDestAddr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
XBDestAddr::U16(x) => {
|
||||
f.write_str("U16(")?;
|
||||
f.write_str(&hex::encode(x.to_be_bytes()))?;
|
||||
f.write_str(")")
|
||||
},
|
||||
XBDestAddr::U64(x) => {
|
||||
f.write_str("U64(")?;
|
||||
f.write_str(&hex::encode(x.to_be_bytes()))?;
|
||||
f.write_str(")")
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Possible errors from serialization */
|
||||
#[derive(Eq, PartialEq, Debug)]
|
||||
pub enum TXGenError {
|
||||
|
|
Loading…
Reference in New Issue