opportunistic-xbee/node/main/xbee_wrapper.cpp

30 lines
577 B
C++

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