add xbee_wrapper that uses the 'packet' interface

This commit is contained in:
Adrien Marquès 2018-12-02 21:44:53 +01:00
parent 33f343caf6
commit 120a1e56bf
2 changed files with 61 additions and 0 deletions

View File

@ -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;
};

31
node/main/xbee_wrapper.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef _WBEE_WRAPPER_H_
#define _WBEE_WRAPPER_H_
#include <Wire.h>
#include <XBee.h>
#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