From 120a1e56bf8bad7c1d33b2152fa076c45dcc0ca3 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sun, 2 Dec 2018 21:44:53 +0100 Subject: [PATCH] add xbee_wrapper that uses the 'packet' interface --- node/main/xbee_wrapper.cpp | 30 ++++++++++++++++++++++++++++++ node/main/xbee_wrapper.h | 31 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 node/main/xbee_wrapper.cpp create mode 100644 node/main/xbee_wrapper.h diff --git a/node/main/xbee_wrapper.cpp b/node/main/xbee_wrapper.cpp new file mode 100644 index 0000000..471d5fa --- /dev/null +++ b/node/main/xbee_wrapper.cpp @@ -0,0 +1,30 @@ +#include "xbee_wrapper.h" + + +XBeeWrapper::XBeeWrapper(){ xbee = XBee(); }; + + +void XBeeWrapper::begin(unsigned long baud){ + xbee.setSerial(Serial1); + Serial1.begin(baud); +}; + + +uint8_t XBeeWrapper::receive(Packet& pkt){ + xbee.readPacket(); + + if( !xbee.getResponse().isAvailable() ) + return XBWRCV_NONE; + + if( xbee.getResponse().getApiId() != ZB_RX_RESPONSE ) + return XBWRCV_NONE; + + Rx64Response res; + xbee.getResponse().getZBRxResponse(res); + + // extract data and propagate error + if( !pkt.read(res.getData(), res.getDataLength()) ) + return XBWRCV_ERROR; + + return XBWRCV_OK; +}; \ No newline at end of file diff --git a/node/main/xbee_wrapper.h b/node/main/xbee_wrapper.h new file mode 100644 index 0000000..c252c12 --- /dev/null +++ b/node/main/xbee_wrapper.h @@ -0,0 +1,31 @@ +#ifndef _WBEE_WRAPPER_H_ + #define _WBEE_WRAPPER_H_ + + #include + #include + #include "protocol.h" + #include "packet.h" + + #define XBWRCV_OK 0 + #define XBWRCV_NONE 1 + #define XBWRCV_ERROR 2 + + + class XBeeWrapper{ + private: + XBee xbee; + + public: + XBeeWrapper(); + + // initialises the XBee interface + void begin(unsigned long baud); + + // tries to extract a received packet + uint8_t receive(Packet& pkt); + + }; + + + +#endif \ No newline at end of file