XBee and XBee-PRO ZigBee RF modules provide cost-effective wireless connectivity to electronic devices. They are interoperable with other ZigBee PRO feature set devices, including devices from other vendors.
Revision 0:837e6c48e90d, committed 2015-10-22
- Comitter:
- yangcq88517
- Date:
- Thu Oct 22 12:28:26 2015 +0000
- Child:
- 1:3dc0ec2f9fd6
- Commit message:
- initial upload
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/APIFrame.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,106 @@ +#include "APIFrame.h" + +APIFrame::APIFrame(int payloadLength) + :BufferedArray(payloadLength) +{} + +APIFrame::APIFrame(APIFrame * frame) + :BufferedArray(frame) +{ + this->checkSum = frame->checkSum; + this->isVerify = frame->isVerify; +} + +char APIFrame::getFrameType() +{ + return data[0]; +} + +void APIFrame::setFrameType(char identifier) {} + +void APIFrame::allocate(int length) +{ + BufferedArray::allocate(length); + isVerify = false; +} + +void APIFrame::rewind() +{ + BufferedArray::rewind(); + isVerify = false; +} + +bool APIFrame::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + this->data = frame->data; + this->index = frame->index; + this->max = frame->max; + this->checkSum = frame->checkSum; + this->isVerify = frame->isVerify; + return true; +} + +void APIFrame::set(char value) +{ + BufferedArray::set(value); + isVerify = false; +} + +void APIFrame::sets(const char * value, int offset, int length) +{ + BufferedArray::sets(value, offset, length); + isVerify = false; +} + +void APIFrame::set(int position, char value) +{ + BufferedArray::set(position, value); + isVerify = false; +} + +void APIFrame::sets(int position, const char * value, int offset, int length) +{ + BufferedArray::sets(position, value, offset, length); + isVerify = false; +} + +char APIFrame::getCheckSum() +{ + return checkSum; +} + +void APIFrame::setCheckSum(char value) +{ + checkSum = value; +} + +bool APIFrame::verifyChecksum() +{ + if (isVerify) + return true; + + char temp = 0x00; + for (int i = 0; i < index; i++) + temp += data[i]; + if (temp + checkSum == 0xFF) + isVerify = true; + else + isVerify = false; + + return isVerify; +} + +void APIFrame::calculateChecksum() +{ + if (isVerify) + return; + + char CS = 0x00; + for (int i = 0; i < index; i++) + CS += data[i]; + checkSum = 0xFF - CS; + isVerify = true; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/APIFrame.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,126 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_APIFrame +#define UK_AC_HERTS_SMARTLAB_XBEE_APIFrame + +#include "BufferedArray.h" + +class APIFrame : public BufferedArray +{ +private: + char checkSum; + + /// <summary> + /// a state to indicate whether this packet's checksum is verified while process + /// </summary> + bool isVerify; + +public: + static const char Tx64_Request =0x00; + static const char Tx16_Request =0x01; + static const char AT_Command = 0x08; + static const char AT_Command_Queue_Parameter_Value = 0x09; + static const char ZigBee_Transmit_Request = 0x10; + static const char Explicit_Addressing_ZigBee_Command_Frame = 0x11; + static const char Remote_Command_Request = 0x17; + static const char Create_Source_Route = 0x21; + static const char Register_Joining_Device = 0x24; + static const char Rx64_Receive_Packet = 0x80; + static const char Rx16_Receive_Packet = 0x81; + static const char Rx64_IO_Data_Sample_Rx_Indicator = 0x82; + static const char Rx16_IO_Data_Sample_Rx_Indicator = 0x83; + static const char AT_Command_Response = 0x88; + static const char XBee_Transmit_Status = 0x89; + static const char Modem_Status = 0x8A; + static const char ZigBee_Transmit_Status = 0x8B; + static const char ZigBee_Receive_Packet = 0x90; + static const char ZigBee_Explicit_Rx_Indicator = 0x91; + static const char ZigBee_IO_Data_Sample_Rx_Indicator = 0x92; + static const char XBee_Sensor_Read_Indicato = 0x94; + static const char Node_Identification_Indicator = 0x95; + static const char Remote_Command_Response = 0x97; + static const char Over_the_Air_Firmware_Update_Status = 0xA0; + static const char Route_Record_Indicator = 0xA1; + static const char Device_Authenticated_Indicator = 0xA2; + static const char Many_to_One_Route_Request_Indicator = 0xA3; + + static const char StartDelimiter = 0x7E; + + APIFrame(int payloadLength); + + APIFrame(APIFrame * frame); + + /** + * @returns + * Tx64_Request =0x00, + * Tx16_Request =0x01, + * AT_Command = 0x08, + * AT_Command_Queue_Parameter_Value = 0x09, + * ZigBee_Transmit_Request = 0x10, + * Explicit_Addressing_ZigBee_Command_Frame = 0x11, + * Remote_Command_Request = 0x17, + * Create_Source_Route = 0x21, + * Register_Joining_Device = 0x24, + * Rx64_Receive_Packet = 0x80, + * Rx16_Receive_Packet = 0x81, + * Rx64_IO_Data_Sample_Rx_Indicator = 0x82, + * Rx16_IO_Data_Sample_Rx_Indicator = 0x83, + * AT_Command_Response = 0x88, + * XBee_Transmit_Status = 0x89, + * Modem_Status = 0x8A, + * ZigBee_Transmit_Status = 0x8B, + * ZigBee_Receive_Packet = 0x90, + * ZigBee_Explicit_Rx_Indicator = 0x91, + * ZigBee_IO_Data_Sample_Rx_Indicator = 0x92, + * XBee_Sensor_Read_Indicato = 0x94, + * Node_Identification_Indicator = 0x95, + * Remote_Command_Response = 0x97, + * Over_the_Air_Firmware_Update_Status = 0xA0, + * Route_Record_Indicator = 0xA1, + * Device_Authenticated_Indicator = 0xA2, + * Many_to_One_Route_Request_Indicator = 0xA3, + */ + char getFrameType(); + + void setFrameType(char identifier); + + void allocate(int length); + + void rewind(); + + bool convert(APIFrame * frame); + + /** Write 8-bit data into current posiston and increase by 1. + * @param value sigle byte + */ + void set(char value); + + /** Write array of data into current posiston, and increase by the lenght. + * @param value array of byte + * @param offset start point of the data + * @param length length to write + */ + void sets(const char * value, int offset, int length); + + /** Write 8-bit data into specific posiston and deos not affect the current position. + * @param position where to write + * @param value sigle byte + */ + void set(int position, char value); + + /** Write array of data into specific posiston and deos not affect the current position. + * @param position where to write + * @param value array of byte + * @param offset start point of the data + * @param length length to write + */ + void sets(int position, const char * value, int offset, int length); + + char getCheckSum(); + + void setCheckSum(char value); + + bool verifyChecksum(); + + void calculateChecksum(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/BufferedArray.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,132 @@ +#include "BufferedArray.h" + +BufferedArray::BufferedArray() +{ + max = EXPANDSIZE; + data = new char[EXPANDSIZE]; + index = 0; +} + +BufferedArray::BufferedArray(int size) +{ + max = size; + data = new char[size]; + index = 0; +} + +BufferedArray::BufferedArray(BufferedArray * bufferedArray) +{ + if (bufferedArray != NULL) { + this->data = bufferedArray->data; + this->index = bufferedArray->index; + this->max = bufferedArray->max; + } +} + +BufferedArray::~BufferedArray() +{ + if (data == NULL) + return; + + delete[] data; +} + +char * BufferedArray::gets() +{ + return data; +} + +char * BufferedArray::gets(int position) +{ + return data + position; +} + +char BufferedArray::get(int position) +{ + return *(data + position); +} + +int BufferedArray::getPosition() +{ + return index; +} + +void BufferedArray::setPosition(int position) +{ + if (this->index > max) + this->index = max; + else this->index = position; +} + +void BufferedArray::allocate(int length) +{ + if (length <= 0) + return; + + if (length > max) { + delete[] data; + data = new char[length]; + } + + rewind(); +} + +void BufferedArray::rewind() +{ + index = 0; +} + +void BufferedArray::expandSpace(int length) +{ + max += EXPANDSIZE * (1 + length / EXPANDSIZE); + char * temp = new char[max]; + memcpy(temp, data, index); + delete[] data; + data = temp; +} + +void BufferedArray::set(int position, char value) +{ + if (position < 0) + return; + + if (position >= max) + expandSpace(1); + + data[position] = value; +} + +void BufferedArray::set(char value) +{ + set(index, value); + index++; +} + +void BufferedArray::sets(const char * value, int offset, int length) +{ + if (length <= 0) + return; + + if (offset < 0) + return; + + sets(index, value, offset, length); + index += length; +} + +void BufferedArray::sets(int position, const char * value, int offset, int length) +{ + if (position < 0) + return; + + if (length <= 0) + return; + + if (offset < 0) + return; + + if (position + length - offset > max) + expandSpace(position + length - offset - max); + + memcpy(data + position, value + offset, length); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/BufferedArray.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,103 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_BufferedArray +#define UK_AC_HERTS_SMARTLAB_XBEE_BufferedArray + +#include "mbed.h" + +/** +* Represent a generic, dynamic-length raw binary data buffer. +*/ +class BufferedArray +{ +protected : + /// initial size and automatically increase length. + static const int EXPANDSIZE = 20; + + /// Raw data + char * data; + + /// Current index of the data, could also used as data lendth. + int index; + + /// Max data size that the raw data can hold. + int max; + + void expandSpace(int length); + +public: + BufferedArray(); + + BufferedArray(int size); + + BufferedArray(BufferedArray * bufferedArray); + + ~BufferedArray(); + + /** Get the raw data. + * @returns char array. + */ + char * gets(); + + /** Get the raw data from a specific location. + * + * @param position where to retrieve + * + * @returns char array. + */ + char * gets(int position); + + /** Get 1 byte data from a specific location. + * + * @param position where to retrieve + * + * @returns char. + */ + char get(int position); + + /** Get the current index. + * @returns char array. + */ + int getPosition(); + + /** Set the index within the max length of raw data. + * @param position where to begin read and write + */ + void setPosition(int position); + + /** Reset the raw data. + * @param length current max size for the raw data + */ + void allocate(int length); + + /** Reset the position and does not affect the content of the data. + * @param length current max size for the raw data + */ + void rewind(); + + /** Write 8-bit data into current posiston and increase by 1. + * @param value sigle byte + */ + void set(char value); + + /** Write array of data into current posiston, and increase by the lenght. + * @param value array of byte + * @param offset start point of the data + * @param length length to write + */ + void sets(const char * value, int offset, int length); + + /** Write 8-bit data into specific posiston and deos not affect the current position. + * @param position where to write + * @param value sigle byte + */ + void set(int position, char value); + + /** Write array of data into specific posiston and deos not affect the current position. + * @param position where to write + * @param value array of byte + * @param offset start point of the data + * @param length length to write + */ + void sets(int position, const char * value, int offset, int length); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/CoreAPI.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,281 @@ +#include "CoreAPI.h" + +CoreAPI::CoreAPI(ISerial * serial, bool escape) + :xBeeRx64Indicator(NULL),xBeeRx16Indicator(NULL),xBeeRx64IOSampleIndicator(NULL),xBeeRx16IOSampleIndicator(NULL),xBeeTxStatusIndicator(NULL), + aTCommandIndicator(NULL),modemStatusIndicator(NULL),zigBeeTxStatusIndicator(NULL),zigBeeRxIndicator(NULL), + zigBeeExplicitRxIndicator(NULL),zigBeeIOSampleIndicator(NULL),sensorReadIndicator(NULL),nodeIdentificationIndicator(NULL), + remoteCommandIndicator(NULL),routeRecordIndicator(NULL),manyToOneRouteIndicator(NULL) +{ + this->serial = serial; + isEscapeMode = escape; + msg = new APIFrame(INITIAL_FRAME_LENGTH); + isRunning = false; + isChecksum = false; +} + +CoreAPI::~CoreAPI() +{ + delete msg; +} + + +void CoreAPI::setVerifyChecksum(bool isCheck) +{ + isChecksum = isCheck; +} + +void CoreAPI::start() +{ + if (!isRunning) { + isRunning = true; + + if (!serial->isOpen()) + serial->open(); + } +} + +void CoreAPI::stop() +{ + if (isRunning) { + isRunning = false; + serial->close(); + } +} + +void CoreAPI::send(APIFrame * request) +{ + if (!isRunning) + return; + + request->calculateChecksum(); + int size = request->getPosition(); + + serial->writeByte(KEY); + + writeByte(size >> 8); + writeByte(size); + + for (int i = 0; i < size; i++) + writeByte(request->get(i)); + + writeByte(request->getCheckSum()); +} + +int CoreAPI::readByte() +{ + int value = serial->readByte(); + + if (isEscapeMode) + return serial->readByte() ^ 0x20; + + return value; +} + +void CoreAPI::writeByte(char data) +{ + if (isEscapeMode) { + if (data == KEY || data == ESCAPED || data == XON || data == XOFF) { + serial->writeByte(ESCAPED); + serial->writeByte(data ^ 0x20); + return; + } + } + + serial->writeByte(data); +} + +APIFrame * CoreAPI::getResponse() +{ + if (readByte() != KEY) + return NULL; + + int length = getLength(); + + msg->allocate(length); + + readPayLoad(length); + + if (isChecksum) { + if (msg->verifyChecksum()) + return msg; + else + return NULL; + } else return msg; +} + +int CoreAPI::getLength() +{ + int msb = readByte(); + + int lsb = readByte(); + + return (msb << 8) | lsb; +} + +void CoreAPI::readPayLoad(int length) +{ + for (int i = 0; i < length; i++) + msg->set(readByte()); + + msg->setCheckSum(readByte()); +} + +XBeeRx64Indicator * CoreAPI::getXBeeRx64() +{ + if (getResponse() == NULL) + return NULL; + + if (xBeeRx64Indicator.convert(msg)) + return &xBeeRx64Indicator; + else return NULL; +} + +XBeeRx16Indicator * CoreAPI::getXBeeRx16() +{ + if (getResponse() == NULL) + return NULL; + + if (xBeeRx16Indicator.convert(msg)) + return &xBeeRx16Indicator; + else return NULL; +} + +XBeeRx64IOSampleIndicator * CoreAPI::getXBeeRx64IOSample() +{ + if (getResponse() == NULL) + return NULL; + + if (xBeeRx64IOSampleIndicator.convert(msg)) + return &xBeeRx64IOSampleIndicator; + else return NULL; +} + +XBeeRx16IOSampleIndicator * CoreAPI::getXBeeRx16IOSample() +{ + if (getResponse() == NULL) + return NULL; + + if (xBeeRx16IOSampleIndicator.convert(msg)) + return &xBeeRx16IOSampleIndicator; + else return NULL; +} + +XBeeTxStatusIndicator * CoreAPI::getXBeeTxStatus() +{ + if (getResponse() == NULL) + return NULL; + + if (xBeeTxStatusIndicator.convert(msg)) + return &xBeeTxStatusIndicator; + else return NULL; +} + +ATCommandIndicator * CoreAPI::getATCommand() +{ + if (getResponse() == NULL) + return NULL; + + if (aTCommandIndicator.convert(msg)) + return &aTCommandIndicator; + else return NULL; +} + +ModemStatusIndicator * CoreAPI::getModemStatus() +{ + if (getResponse() == NULL) + return NULL; + + if (modemStatusIndicator.convert(msg)) + return &modemStatusIndicator; + else return NULL; +} + +ZigBeeTxStatusIndicator * CoreAPI::getZigBeeTxStatus() +{ + if (getResponse() == NULL) + return NULL; + + if (zigBeeTxStatusIndicator.convert(msg)) + return &zigBeeTxStatusIndicator; + else return NULL; +} + +ZigBeeRxIndicator * CoreAPI::getZigBeeRx() +{ + if (getResponse() == NULL) + return NULL; + + if (zigBeeRxIndicator.convert(msg)) + return &zigBeeRxIndicator; + else return NULL; +} + +ZigBeeExplicitRxIndicator * CoreAPI::getZigBeeExplicitRx() +{ + if (getResponse() == NULL) + return NULL; + + if (zigBeeExplicitRxIndicator.convert(msg)) + return &zigBeeExplicitRxIndicator; + else return NULL; +} + +ZigBeeIOSampleIndicator * CoreAPI::getZigBeeIOSample() +{ + if (getResponse() == NULL) + return NULL; + + if (zigBeeIOSampleIndicator.convert(msg)) + return &zigBeeIOSampleIndicator; + else return NULL; +} + +SensorReadIndicator * CoreAPI::getSensorRead() +{ + if (getResponse() == NULL) + return NULL; + + if (sensorReadIndicator.convert(msg)) + return &sensorReadIndicator; + else return NULL; +} + +NodeIdentificationIndicator * CoreAPI::getNodeIdentification() +{ + if (getResponse() == NULL) + return NULL; + + if (nodeIdentificationIndicator.convert(msg)) + return &nodeIdentificationIndicator; + else return NULL; +} + +RemoteCommandIndicator * CoreAPI::getRemoteCommand() +{ + if (getResponse() == NULL) + return NULL; + + if (remoteCommandIndicator.convert(msg)) + return &remoteCommandIndicator; + else return NULL; +} + +RouteRecordIndicator * CoreAPI::getRouteRecord() +{ + if (getResponse() == NULL) + return NULL; + + if (routeRecordIndicator.convert(msg)) + return &routeRecordIndicator; + else return NULL; +} + +ManyToOneRouteIndicator * CoreAPI::getManyToOneRoute() +{ + if (getResponse() == NULL) + return NULL; + + if (manyToOneRouteIndicator.convert(msg)) + return &manyToOneRouteIndicator; + else return NULL; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/CoreAPI.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,169 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_CoreAPI +#define UK_AC_HERTS_SMARTLAB_XBEE_CoreAPI + +#include "APIFrame.h" +#include "ISerial.h" + +#include "ATCommandRequest.h" +#include "CreateSourceRouteRequest.h" +#include "IOCDetectionConfigRequest.h" +#include "PinConfigurationRequest.h" +#include "RemoteATCommandRequest.h" +#include "RemoteIODetectionConfigRequest.h" +#include "RemotePinConfigurationRequest.h" +#include "XBeeTx16Request.h" +#include "XBeeTx64Request.h" +#include "ZigBeeExplicitTxRequest.h" +#include "ZigBeeTxRequest.h" + + +#include "XBeeRx64Indicator.h" +#include "XBeeRx16Indicator.h" +#include "XBeeRx64IOSampleIndicator.h" +#include "XBeeRx16IOSampleIndicator.h" +#include "XBeeTxStatusIndicator.h" +#include "ATCommandIndicator.h" +#include "ModemStatusIndicator.h" +#include "ZigBeeTxStatusIndicator.h" +#include "ZigBeeRxIndicator.h" +#include "ZigBeeExplicitRxIndicator.h" +#include "ZigBeeIOSampleIndicator.h" +#include "SensorReadIndicator.h" +#include "NodeIdentificationIndicator.h" +#include "RemoteCommandIndicator.h" +#include "RouteRecordIndicator.h" +#include "ManyToOneRouteIndicator.h" + +class CoreAPI +{ +private: + static const char KEY = 0x7E; + static const char ESCAPED = 0x7D; + static const char XON = 0x11; + static const char XOFF = 0x13; + static const int INITIAL_FRAME_LENGTH = 100; + + ISerial * serial; + bool isEscapeMode; + bool isRunning; + bool isChecksum; + + APIFrame * msg; + XBeeRx64Indicator xBeeRx64Indicator; + XBeeRx16Indicator xBeeRx16Indicator; + XBeeRx64IOSampleIndicator xBeeRx64IOSampleIndicator; + XBeeRx16IOSampleIndicator xBeeRx16IOSampleIndicator; + XBeeTxStatusIndicator xBeeTxStatusIndicator; + ATCommandIndicator aTCommandIndicator; + ModemStatusIndicator modemStatusIndicator; + ZigBeeTxStatusIndicator zigBeeTxStatusIndicator; + ZigBeeRxIndicator zigBeeRxIndicator; + ZigBeeExplicitRxIndicator zigBeeExplicitRxIndicator; + ZigBeeIOSampleIndicator zigBeeIOSampleIndicator; + SensorReadIndicator sensorReadIndicator; + NodeIdentificationIndicator nodeIdentificationIndicator; + RemoteCommandIndicator remoteCommandIndicator; + RouteRecordIndicator routeRecordIndicator; + ManyToOneRouteIndicator manyToOneRouteIndicator; + +protected: + + /// <summary> + /// read one byte payload, which allready handle the escape char, if less than 0 means error occured + /// </summary> + /// <returns></returns> + int readByte(); + + /// <summary> + /// write one byte to the payload, which allready handle the escape char + /// </summary> + /// <param name="data"></param> + void writeByte(char data); + + void packetProcess(); + + int getLength(); + + void readPayLoad(int length); + +public: + CoreAPI(ISerial * serial, bool escape); + + ~CoreAPI(); + + /// <summary> + /// get or set whether to verify receive packet's checksum + /// </summary> + void setVerifyChecksum(bool isCheck); + + /// <summary> + /// to start send and process response, must be called before any function + /// </summary> + void start(); + + /// <summary> + /// stop so the serial port can be used for other purpose + /// </summary> + void stop(); + + /// <summary> + /// a general function to send frame out, do not process response + /// </summary> + /// <param name="request"></param> + void send(APIFrame * request); + + APIFrame * getResponse(); + + XBeeRx64Indicator * getXBeeRx64(); + + XBeeRx16Indicator * getXBeeRx16(); + + XBeeRx64IOSampleIndicator * getXBeeRx64IOSample(); + + XBeeRx16IOSampleIndicator * getXBeeRx16IOSample(); + + XBeeTxStatusIndicator * getXBeeTxStatus(); + + ATCommandIndicator * getATCommand(); + + ModemStatusIndicator * getModemStatus(); + + ZigBeeTxStatusIndicator * getZigBeeTxStatus(); + + ZigBeeRxIndicator * getZigBeeRx(); + + ZigBeeExplicitRxIndicator * getZigBeeExplicitRx(); + + ZigBeeIOSampleIndicator * getZigBeeIOSample(); + + SensorReadIndicator * getSensorRead(); + + NodeIdentificationIndicator * getNodeIdentification(); + + RemoteCommandIndicator * getRemoteCommand(); + + RouteRecordIndicator * getRouteRecord(); + + ManyToOneRouteIndicator * getManyToOneRoute(); +}; + + + + + + + + + + + + + + + + + + + + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Core/ISerial.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,26 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ISerial +#define UK_AC_HERTS_SMARTLAB_XBEE_ISerial + +class ISerial +{ +public: + /// <summary> + /// if success return non zero, -1 means something is wrong + /// </summary> + /// <returns></returns> + virtual int readByte() = 0; + + virtual void writeByte(char data) = 0; + + /// <summary> + /// check if the serial port is already open + /// </summary> + /// <returns></returns> + virtual bool isOpen() = 0; + + virtual void open() = 0; + + virtual void close() = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/Address.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,85 @@ +#include "Address.h" + +Address * BROADCAST_ZIGBEE = new Address(0x00000000, 0x0000FFFF, 0xFFFE); +Address * BROADCAST_XBEE = new Address(0x00000000, 0x00000000, 0xFFFF); + +Address::Address() {} + +Address::Address(const char * address64, const char * NET16) +{ + if (address64 != NULL) + memcpy(value,address64,8); + + if (NET16 != NULL) { + value[8] = NET16[0]; + value[9] = NET16[1]; + } +} + +Address::Address(const char * addr) +{ + if (addr != NULL) + memcpy(value,addr,10); +} + +Address::Address(long serialNumberHigh, long serialNumberLow, int networkAddress) +{ + setSerialNumberHigh(serialNumberHigh); + setSerialNumberLow(serialNumberLow); + setNetworkAddress(networkAddress); +} + +long Address::getSerialNumberHigh() +{ + return (value[0] << 24) | (value[1] << 16) | (value[2] << 8) | value[3]; +} + +long Address::getSerialNumberLow() +{ + return (value[4] << 24) | (value[5] << 16) | (value[6] << 8) | value[7]; +} + +int Address::getNetworkAddress() +{ + return (value[8] << 8) | value[9]; +} + +void Address::setSerialNumberHigh(long serialNumberHigh) +{ + value[0] = serialNumberHigh >> 24; + value[1] = serialNumberHigh >> 16; + value[2] = serialNumberHigh >> 8; + value[3] = serialNumberHigh; +} + +void Address::setSerialNumberLow(long serialNumberLow) +{ + value[4] = serialNumberLow >> 24; + value[5] = serialNumberLow >> 16; + value[6] = serialNumberLow >> 8; + value[7] = serialNumberLow; +} + +void Address::setNetworkAddress(int networkAddress) +{ + value[8] = networkAddress >> 8; + value[9] = networkAddress; +} + +const char * Address::getAddressValue() +{ + return value; +} + +bool operator ==(const Address &a,const Address &b) +{ + for (uint8_t i = 0; i < 8; i++) + if (a.value[i] != b.value[i]) + return false; + return true; +} + +bool operator !=(const Address &a,const Address &b) +{ + return !(a==b); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/Address.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,61 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_Address +#define UK_AC_HERTS_SMARTLAB_XBEE_Address + +#include "mbed.h" + +class Address +{ +protected: + // total 10 bytes + // IEEE 64 + 16bit networ address + char value[10]; +public: + static Address * BROADCAST_ZIGBEE; + static Address * BROADCAST_XBEE; + + /// <summary> + /// create empty address : 0x00000000 0x00000000 0x0000 + /// this is the default ZigBee Coordinatior + /// </summary> + Address(); + + /// <summary> + /// create address from byte[8 + 2] value : 8 bytes of ieee + 2 bytes network + /// </summary> + /// <param name="Address64"></param> + /// <param name="NET16"></param> + Address(const char * address64, const char * NET16); + + /// <summary> + /// create address from byte[10] value : 8 bytes of ieee follow 2 bytes network + /// </summary> + /// <param name="value"></param> + Address(const char * addr); + + Address(long serialNumberHigh, long serialNumberLow, int networkAddress); + + long getSerialNumberHigh(); + + long getSerialNumberLow(); + + int getNetworkAddress(); + + void setSerialNumberHigh(long SerialNumberHigh); + + void setSerialNumberLow(long SerialNumberLow); + + void setNetworkAddress(int NetworkAddress); + + /// <summary> + /// total 10 bytes + /// IEEE 64 + 16bit networ address + /// </summary> + /// <returns></returns> + const char * getAddressValue(); + + friend bool operator ==(const Address &a,const Address &b); + + friend bool operator !=(const Address &a,const Address &b); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/ExplicitAddress.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,68 @@ +#include "ExplicitAddress.h" + +ExplicitAddress::ExplicitAddress() +{ } + +ExplicitAddress::ExplicitAddress (const char * address, const char * explicitAddress ) + : Address(address) +{ + memcpy(explicitValue, explicitAddress, 6); +} + +ExplicitAddress::ExplicitAddress(long SerialNumberHigh, long SerialNumberLow, int NetworkAddress, int SourceEndpoint, int DestinationEndpoint, int ClusterID, int ProfileID) + : Address(SerialNumberHigh, SerialNumberLow, NetworkAddress) +{ + explicitValue[0] = SourceEndpoint; + explicitValue[1] = DestinationEndpoint; + explicitValue[2] = ClusterID >> 8; + explicitValue[3] = ClusterID; + explicitValue[4] = ProfileID >> 8; + explicitValue[5] = ProfileID; +} + +char * ExplicitAddress::getExplicitValue() +{ + return explicitValue; +} + +int ExplicitAddress::getSourceEndpoint() +{ + return explicitValue[0]; +} + +void ExplicitAddress::setSourceEndpoint(int SourceEndpoint) +{ + explicitValue[0] = SourceEndpoint; +} + +int ExplicitAddress::getDestinationEndpoint() +{ + return explicitValue[1]; +} + +void ExplicitAddress::setDestinationEndpoint(int DestinationEndpoint) +{ + explicitValue[1] = DestinationEndpoint; +} + +int ExplicitAddress::getClusterID() +{ + return (explicitValue[2] << 8) | explicitValue[3]; +} + +void ExplicitAddress::setClusterID(int ClusterID) +{ + explicitValue[2] = ClusterID >> 8; + explicitValue[3] = ClusterID; +} + +int ExplicitAddress::getProfileID() +{ + return (explicitValue[4] << 8) | explicitValue[5]; +} + +void ExplicitAddress::setProfileID(int ProfileID) +{ + explicitValue[4] = ProfileID >> 8; + explicitValue[5] = ProfileID; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/ExplicitAddress.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,44 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ExplicitAddress +#define UK_AC_HERTS_SMARTLAB_XBEE_ExplicitAddress + +#include "Address.h" + +class ExplicitAddress : public Address +{ +private: + // total 6 bytes + // 1 byte of SourceEndpoint + 1 byte of DestinationEndpoint + 2 bytes of ClusterID + 2 bytes of ProfileID + char explicitValue[6]; + +public: + ExplicitAddress() ; + + ExplicitAddress (const char * AddressValue, const char * ExplicitValue ); + + ExplicitAddress(long SerialNumberHigh, long SerialNumberLow, int NetworkAddress, int SourceEndpoint, int DestinationEndpoint, int ClusterID, int ProfileID); + + /// <summary> + /// total 6 bytes + /// 1 byte of SourceEndpoint + 1 byte of DestinationEndpoint + 2 bytes of ClusterID + 2 bytes of ProfileID + /// </summary> + /// <returns></returns> + char * getExplicitValue(); + + int getSourceEndpoint(); + + void setSourceEndpoint(int SourceEndpoint); + + int getDestinationEndpoint(); + + void setDestinationEndpoint(int DestinationEndpoint); + + int getClusterID(); + + void setClusterID(int ClusterID); + + int getProfileID(); + + void setProfileID(int ProfileID); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/Pin.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,48 @@ +#include "Pin.h" + +char Pin::bitfield[2] = {0,0}; + +Pin::Pin(char number) +{ + num = number; +} + +Pin::Pin(char number, char msbCom, char lsbCom, char msbIODet, char lsbIODet) +{ + num = number; + com[0] = msbCom; + com[1] = lsbCom; + IODet[0] = msbIODet; + IODet[1] = lsbIODet; +} + +char Pin::getNumber() +{ + return num; +} + +char* Pin::getCommand() +{ + return com; +} + +char* Pin::IOChangeDetectionConfiguration(const Pin *Pins, char Length) +{ + Pin::bitfield[0] = 0; + Pin::bitfield[1] = 0; + for (const Pin *i = Pins; i< Pins + Length; i++) { + Pin::bitfield[0] |= i->IODet[0]; + Pin::bitfield[1] |= i->IODet[1]; + } + return Pin::bitfield; +} + +char* Pin::getIODetection() +{ + return IODet; +} + +bool operator <(const Pin &a,const Pin &b) +{ + return a.num < b.num; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/Pin.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,31 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_Pin +#define UK_AC_HERTS_SMARTLAB_XBEE_Pin + +class Pin +{ +private: + static char bitfield[2]; + + char num; + + char com[2]; + + char IODet[2]; + +public: + Pin(char number); + + Pin(char number, char msbCom, char lsbCom, char msbIODet, char lsbIODet); + + char getNumber(); + + char* getCommand(); + + char* getIODetection(); + + static char* IOChangeDetectionConfiguration(const Pin *Pins, char Length); + + friend bool operator <(const Pin &a,const Pin &b); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/XBeePins.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,22 @@ +#include "XBeePins.h" + +Pin XBeePins::P1_VCC = Pin(1); +Pin XBeePins::P2_DOUT = Pin(2); +Pin XBeePins::P3_DIN_CONFIG = Pin(3); +Pin XBeePins::P4_DO8 = Pin(4); +Pin XBeePins::P5_RESET = Pin(5); +Pin XBeePins::P6_RSSI_PWM0 = Pin(6); +Pin XBeePins::P7_PWM1 = Pin(7); +Pin XBeePins::P8_RESERVED = Pin(8); +Pin XBeePins::P9_DTR_SLEEP_DIO8 = Pin(9,0x44,0x38,0x00,0x00); +Pin XBeePins::P10_GND = Pin(10); +Pin XBeePins::P11_AD4_DIO4 = Pin(11,0x44,0x34,0x00,0x10); +Pin XBeePins::P12_CTS_DIO7 = Pin(12,0x44,0x37,0x00,0x80); +Pin XBeePins::P13_ON_SLEEP = Pin(13); +Pin XBeePins::P14_VREF = Pin(14); +Pin XBeePins::P15_ASSOCIATE_AD5_DIO5 = Pin(15,0x44,0x35,0x00,0x20); +Pin XBeePins::P16_RTS_AD6_DIO6 = Pin(16,0x44,0x36,0x00,0x40); +Pin XBeePins::P17_AD3_DIO3 = Pin(17,0x44,0x33,0x00,0x08); +Pin XBeePins::P18_AD2_DIO2 = Pin(18,0x44,0x32,0x00,0x04); +Pin XBeePins::P19_AD1_DIO1 = Pin(19,0x44,0x31,0x00,0x02); +Pin XBeePins::P20_AD0_DIO0 = Pin(20,0x44,0x30,0x00,0x01); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/XBeePins.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,31 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeePins +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeePins + +#include "Pin.h" + +class XBeePins +{ +public: + static Pin P1_VCC; + static Pin P2_DOUT; + static Pin P3_DIN_CONFIG; + static Pin P4_DO8; + static Pin P5_RESET; + static Pin P6_RSSI_PWM0; + static Pin P7_PWM1; + static Pin P8_RESERVED; + static Pin P9_DTR_SLEEP_DIO8; + static Pin P10_GND; + static Pin P11_AD4_DIO4; + static Pin P12_CTS_DIO7; + static Pin P13_ON_SLEEP; + static Pin P14_VREF; + static Pin P15_ASSOCIATE_AD5_DIO5; + static Pin P16_RTS_AD6_DIO6; + static Pin P17_AD3_DIO3; + static Pin P18_AD2_DIO2; + static Pin P19_AD1_DIO1; + static Pin P20_AD0_DIO0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/ZigBeePins.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,22 @@ +#include "ZigBeePins.h" + +Pin ZigBeePins::P1_VCC = Pin(1); +Pin ZigBeePins::P2_DOUT = Pin(2); +Pin ZigBeePins::P3_DIN_CONFIG = Pin(3); +Pin ZigBeePins::P4_DIO12 = Pin(4,0x50,0x32,0x10,0x00); +Pin ZigBeePins::P5_RESET = Pin(5); +Pin ZigBeePins::P6_RSSI_PWM_DIO10 = Pin(6,0x50,0x30,0x04,0x00); +Pin ZigBeePins::P7_PWM_DIO11 = Pin(7,0x50,0x31,0x08,0x00); +Pin ZigBeePins::P8_RESERVED = Pin(8); +Pin ZigBeePins::P9_DTR_SLEEP_DIO8 = Pin(9); +Pin ZigBeePins::P10_GND = Pin(10); +Pin ZigBeePins::P11_DIO4 = Pin(11,0x44,0x34,0x00,0x10); +Pin ZigBeePins::P12_CTS_DIO7 = Pin(12,0x44,0x37,0x00,0x80); +Pin ZigBeePins::P13_ON_SLEEP = Pin(13); +Pin ZigBeePins::P14_VREF = Pin(14); +Pin ZigBeePins::P15_ASSOCIATE_DIO5 = Pin(15,0x44,0x35,0x00,0x20); +Pin ZigBeePins::P16_RTS_DIO6 = Pin(16,0x44,0x36,0x00,0x40); +Pin ZigBeePins::P17_AD3_DIO3 = Pin(17,0x44,0x33,0x00,0x08); +Pin ZigBeePins::P18_AD2_DIO2 = Pin(18,0x44,0x32,0x00,0x04); +Pin ZigBeePins::P19_AD1_DIO1 = Pin(19,0x44,0x31,0x00,0x02); +Pin ZigBeePins::P20_AD0_DIO0_COMMISSIONONG_BUTTON = Pin(20,0x44,0x30,0x00,0x01); \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Device/ZigBeePins.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,31 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeePins +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeePins + +#include "Pin.h" + +class ZigBeePins +{ +public: + static Pin P1_VCC; + static Pin P2_DOUT; + static Pin P3_DIN_CONFIG; + static Pin P4_DIO12; + static Pin P5_RESET; + static Pin P6_RSSI_PWM_DIO10; + static Pin P7_PWM_DIO11; + static Pin P8_RESERVED; + static Pin P9_DTR_SLEEP_DIO8; + static Pin P10_GND; + static Pin P11_DIO4; + static Pin P12_CTS_DIO7; + static Pin P13_ON_SLEEP; + static Pin P14_VREF; + static Pin P15_ASSOCIATE_DIO5; + static Pin P16_RTS_DIO6; + static Pin P17_AD3_DIO3; + static Pin P18_AD2_DIO2; + static Pin P19_AD1_DIO1; + static Pin P20_AD0_DIO0_COMMISSIONONG_BUTTON; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Helper/IOSampleDecoder.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,146 @@ +#include "IOSampleDecoder.h" + +int IOSampleDecoder::XBeeSamplesParse(IOSamples * samples, const char * IOSamplePayload, int offset) +{ + // at least 3 bytes, 1 byte of [number of samples] + 2 bytes of [digital channel mask] and [analog channel mask]. + int numofsamples = IOSamplePayload[offset]; + + if (numofsamples <= 0) + return 0; + + if (samples!= NULL) + delete[] samples; + + // first byte is the number of sample + int index = offset + 1; + + samples = new IOSamples[numofsamples]; + + int digitMask = ((IOSamplePayload[index] & 0x01) << 8) | IOSamplePayload[index + 1]; + int analogMask = IOSamplePayload[index] & 0xFE; + + // sample start at +2 [mask] + index += 2; + + for (int i = 0; i < numofsamples; i++) { + map<Pin, int> * analog = (samples + i)->getAnalogs(); + map<Pin, int> * digital = (samples + i)->getDigitals(); + if (digitMask != 0) { + if ((digitMask & 0x01) == 0x01) + (*digital)[XBeePins::P20_AD0_DIO0] = (IOSamplePayload[index + 1] & 0x01) == 0x01 ? 1 : 0; + if ((digitMask & 0x02) == 0x02) + (*digital)[XBeePins::P19_AD1_DIO1] = (IOSamplePayload[index + 1] & 0x02) == 0x02 ? 1 : 0; + if ((digitMask & 0x04) == 0x04) + (*digital)[XBeePins::P18_AD2_DIO2] = (IOSamplePayload[index + 1] & 0x04) == 0x04 ? 1 : 0; + if ((digitMask & 0x08) == 0x08) + (*digital)[XBeePins::P17_AD3_DIO3] = (IOSamplePayload[index + 1] & 0x08) == 0x08 ? 1 : 0; + if ((digitMask & 0x10) == 0x10) + (*digital)[XBeePins::P11_AD4_DIO4] = (IOSamplePayload[index + 1] & 0x10) == 0x10 ? 1 : 0; + if ((digitMask & 0x20) == 0x20) + (*digital)[XBeePins::P15_ASSOCIATE_AD5_DIO5] = (IOSamplePayload[index + 1] & 0x20) == 0x20 ? 1 : 0; + if ((digitMask & 0x40) == 0x40) + (*digital)[XBeePins::P16_RTS_AD6_DIO6] = (IOSamplePayload[index + 1] & 0x40) == 0x40 ? 1 : 0; + if ((digitMask & 0x80) == 0x80) + (*digital)[XBeePins::P12_CTS_DIO7] = (IOSamplePayload[index + 1] & 0x80) == 0x80 ? 1 : 0; + if (((digitMask >> 8) & 0x01) == 0x01) + (*digital)[XBeePins::P9_DTR_SLEEP_DIO8] = (IOSamplePayload[index] & 0x01) == 0x01 ? 1 : 0; + + //skip the 2 [digital sample] + index += 2; + } + + if (analogMask != 0) { + if ((analogMask & 0x02) == 0x02) + (*analog)[XBeePins::P20_AD0_DIO0] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x04) == 0x04) + (*analog)[XBeePins::P19_AD1_DIO1] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x08) == 0x08) + (*analog)[XBeePins::P18_AD2_DIO2] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x10) == 0x10) + (*analog)[XBeePins::P17_AD3_DIO3] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x20) == 0x20) + (*analog)[XBeePins::P11_AD4_DIO4] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x40) == 0x40) + (*analog)[XBeePins::P15_ASSOCIATE_AD5_DIO5] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + } + } + + return numofsamples; +} + +int IOSampleDecoder::ZigBeeSamplesParse(IOSamples * samples, const char * IOSamplePayload, int offset) +{ + // at least 4 bytes, 1 byte of [number of samples] + 2 bytes of [digital channel mask] + 1 bytes of [analog channel mask]. + + // the [number of samples] always set to 1. + int numofsamples = IOSamplePayload[offset]; + + if (numofsamples <= 0) + return 0; + + if (samples!= NULL) + delete[] samples; + + int index = offset + 1; + + int digitMask = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + int analogMask = IOSamplePayload[index++]; + + samples = new IOSamples[numofsamples]; + + for (int i = 0; i < numofsamples; i++) { + map<Pin, int> * analog = (samples + i)->getAnalogs(); + map<Pin, int> * digital = (samples + i)->getDigitals(); + + if (digitMask != 0) { + if ((digitMask & 0x01) == 0x01) + (*digital)[ZigBeePins::P20_AD0_DIO0_COMMISSIONONG_BUTTON] = (IOSamplePayload[index + 1] & 0x01) == 0x01 ? 1 : 0; + if ((digitMask & 0x02) == 0x02) + (*digital)[ZigBeePins::P19_AD1_DIO1] = (IOSamplePayload[index + 1] & 0x02) == 0x02 ? 1 : 0; + if ((digitMask & 0x04) == 0x04) + (*digital)[ZigBeePins::P18_AD2_DIO2] = (IOSamplePayload[index + 1] & 0x04) == 0x04 ? 1 : 0; + if ((digitMask & 0x08) == 0x08) + (*digital)[ZigBeePins::P17_AD3_DIO3] = (IOSamplePayload[index + 1] & 0x08) == 0x08 ? 1 : 0; + if ((digitMask & 0x10) == 0x10) + (*digital)[ZigBeePins::P11_DIO4] = (IOSamplePayload[index + 1] & 0x10) == 0x10 ? 1 : 0; + if ((digitMask & 0x20) == 0x20) + (*digital)[ZigBeePins::P15_ASSOCIATE_DIO5] = (IOSamplePayload[index + 1] & 0x20) == 0x20 ? 1 : 0; + if ((digitMask & 0x40) == 0x40) + (*digital)[ZigBeePins::P16_RTS_DIO6] = (IOSamplePayload[index + 1] & 0x40) == 0x40 ? 1 : 0; + if ((digitMask & 0x80) == 0x80) + (*digital)[ZigBeePins::P12_CTS_DIO7] = (IOSamplePayload[index + 1] & 0x80) == 0x80 ? 1 : 0; + + if (((digitMask >> 8) & 0x04) == 0x04) + (*digital)[ZigBeePins::P6_RSSI_PWM_DIO10] = (IOSamplePayload[index] & 0x04) == 0x04 ? 1 : 0; + if (((digitMask >> 8) & 0x08) == 0x08) + (*digital)[ZigBeePins::P7_PWM_DIO11] = (IOSamplePayload[index] & 0x08) == 0x08 ? 1 : 0; + if (((digitMask >> 8) & 0x10) == 0x10) + (*digital)[ZigBeePins::P4_DIO12] = (IOSamplePayload[index] & 0x10) == 0x10 ? 1 : 0; + + index += 2;// 2 [digital sample] + } + if (analogMask != 0x00) { //analog mask + if ((analogMask & 0x01) == 0x01) + (*analog)[ZigBeePins::P20_AD0_DIO0_COMMISSIONONG_BUTTON] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x02) == 0x02) + (*analog)[ZigBeePins::P19_AD1_DIO1] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x04) == 0x04) + (*analog)[ZigBeePins::P18_AD2_DIO2] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x08) == 0x08) + (*analog)[ZigBeePins::P17_AD3_DIO3] = (IOSamplePayload[index++] << 8) | IOSamplePayload[index++]; + + if ((analogMask & 0x80) == 0x80) + (samples + i)->setSupplyVoltage((IOSamplePayload[index++] << 8) | IOSamplePayload[index++]); + } + } + + return numofsamples; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Helper/IOSampleDecoder.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,19 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_IOSampleDecoder +#define UK_AC_HERTS_SMARTLAB_XBEE_IOSampleDecoder + +#include "mbed.h" +#include "IOSamples.h" +#include "XBeePins.h" +#include "ZigBeePins.h" + +class IOSampleDecoder +{ +public : + // return the lenght of io ample + static int XBeeSamplesParse(IOSamples * samples, const char * IOSamplePayload, int offset = 0); + + // return the lenght of io ample + static int ZigBeeSamplesParse(IOSamples * samples, const char * IOSamplePayload, int offset = 0); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ATCommandIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,55 @@ +#include "ATCommandIndicator.h" + +ATCommandIndicator::ATCommandIndicator(APIFrame *frame) + : RxBase(frame) +{ } + +int ATCommandIndicator::getFrameID() +{ + return data[1]; +} + +char * ATCommandIndicator::getRequestCommand() +{ + return data + 2; +} + +int ATCommandIndicator::getCommandStatus() +{ + return data[4]; +} + +char * ATCommandIndicator::getParameter() +{ + if (getParameterLength() <= 0) + return NULL; + + return data + 5; +} + +char ATCommandIndicator::getParameter(int index) +{ + return data[5 + index]; +} + +int ATCommandIndicator::getParameterLength() +{ + return getPosition() - 5; +} + +int ATCommandIndicator::getParameterOffset() +{ + return 5; +} + +bool ATCommandIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::AT_Command_Response) + return false; + + return APIFrame::convert(frame); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ATCommandIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,42 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ATCommandIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ATCommandIndicator + +#include "RxBase.h" +#include "ICommandResponse.h" + +class ATCommandIndicator : public ICommandResponse, public RxBase +{ +public : + ATCommandIndicator(APIFrame * frame); + + virtual int getFrameID(); + + virtual char * getRequestCommand(); + + /** + * + * @returns + * OK = 0x00, + * ERROR = 0x01, + * INVALID_COMMAND = 0x02, + * INVALID_Parameter = 0x03, + * TRANSMISSION_FAILED = 0x04, + */ + virtual int getCommandStatus(); + + /// <summary> + /// if parameter not presented, null will be returned. + /// </summary> + /// <returns></returns> + virtual char * getParameter(); + + virtual char getParameter(int index); + + virtual int getParameterLength(); + + virtual int getParameterOffset(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ICommandResponse.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,31 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ICommandResponse +#define UK_AC_HERTS_SMARTLAB_XBEE_ICommandResponse + +class ICommandResponse +{ +public: + virtual int getFrameID() = 0; + + virtual char * getRequestCommand() = 0; + + /** + * + * @returns + * OK = 0x00, + * ERROR = 0x01, + * INVALID_COMMAND = 0x02, + * INVALID_Parameter = 0x03, + * TRANSMISSION_FAILED = 0x04, + */ + virtual int getCommandStatus() = 0; + + virtual char * getParameter() = 0; + + virtual char getParameter(int index) = 0; + + virtual int getParameterLength() = 0; + + virtual int getParameterOffset() = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/IPayloadResponse.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,37 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_IPayloadResponse +#define UK_AC_HERTS_SMARTLAB_XBEE_IPayloadResponse + +#include "Address.h" + +class IPayloadResponse +{ +public: + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus() = 0; + + virtual Address getRemoteDevice() = 0; + + virtual char * getReceivedData() = 0; + + virtual int getReceivedDataOffset() = 0; + + virtual char getReceivedData(int index) = 0; + + virtual int getReceivedDataLength() = 0; + + /// <summary> + /// not apply to ZigBee + /// </summary> + /// <returns></returns> + virtual int getRSSI() = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ISampleResponse.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,38 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ISampleResponse +#define UK_AC_HERTS_SMARTLAB_XBEE_ISampleResponse + +#include "Address.h" +#include "IOSamples.h" +#include "IOSampleDecoder.h" + +class ISampleResponse +{ +protected: + IOSamples * samples; + +public: + virtual IOSamples * getIOSamples() = 0; + + virtual int getSamplesCount() = 0; + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus() = 0; + + virtual Address getRemoteDevice() = 0; + + /// <summary> + /// not apply to ZigBee + /// </summary> + /// <returns></returns> + virtual int getRSSI() = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ITransmitStatus.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ITransmitStatus +#define UK_AC_HERTS_SMARTLAB_XBEE_ITransmitStatus + +#include "Address.h" + +class ITransmitStatus +{ +public: + virtual int getFrameID() = 0; + + /** + *SUCCESS = 0x00, + * MAC_ACK_FAILURE = 0x01, + * CCA_FAILURE = 0x02, + * TRANSMISSION_WAS_PURGED = 0x03, + * PHYSICAL_ERROR_OCCURRED_ON_THE_INTERFACE_WITH_THE_WIFI_TRANSCEIVER = 0x04, + * INVALID_DESTINATION_ENDPOINT = 0x15, + * NO_BUFFERS = 0x18, + * NETWORK_ACK_FAILURE = 0x21, + * NOT_JOINED_TO_NETWORK = 0x22, + * SELF_ADDRESSED = 0x23, + * ADDRESS_NOT_FOUND = 0x24, + * ROUTE_NOT_FOUND = 0x25, + * BROADCAST_SOURCE_FAILED_TO_HEAR_A_NEIGBOR_RELAY_THE_MESSAGE = 0x26, + * INVALID_BINDING_TABLE_INDEX = 0x2B, + * INVALID_ENDPOINT = 0x2C, + * ATTEMPTED_BROADCAST_WITH_APS_TRANSMISSION = 0x2D, + * ATTEMPTED_UNICAST_WITH_APS_TRANSMISSION_BUT_EE_0 = 0x2E, + * SOFTWARE_ERROR_OCCURRED = 0x31, + * RESOURCE_ERROR_LACK_OF_FREE_BUFFERS_TIMERS_ETC = 0x32, + * DATA_PAYLOAD_TOO_LARGE = 0x74, + * INDIRECT_MESSAGE_UNREQUESTED = 0x75, + * ATTEMPT_TO_CREATE_A_CLIENT_SOCKET_FAILED = 0x76, + * KEY_NOT_AUTHORIZED = 0xBB, + */ + virtual int getDeliveryStatus() = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ManyToOneRouteIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,21 @@ +#include "ManyToOneRouteIndicator.h" + +ManyToOneRouteIndicator::ManyToOneRouteIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +Address ManyToOneRouteIndicator::getRemoteDevice() +{ + return Address(data + 1); +} + +bool ManyToOneRouteIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Many_to_One_Route_Request_Indicator) + return false; + + return APIFrame::convert(frame); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ManyToOneRouteIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,17 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ManyToOneRouteIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ManyToOneRouteIndicator + +#include "RxBase.h" +#include "Address.h" + +class ManyToOneRouteIndicator: public RxBase +{ +public: + ManyToOneRouteIndicator(APIFrame * frame); + + Address getRemoteDevice(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ModemStatusIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,21 @@ +#include "ModemStatusIndicator.h" + +ModemStatusIndicator::ModemStatusIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +int ModemStatusIndicator::getModemStatus() +{ + return data[1]; +} + +bool ModemStatusIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Modem_Status) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ModemStatusIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,50 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ModemStatusIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ModemStatusIndicator + +#include "RxBase.h" + +class ModemStatusIndicator: public RxBase +{ +public: + ModemStatusIndicator(APIFrame * frame); + + /** + * + * @returns + * + * HARDWARE_RESET = 0x00, + * WATCHDOG_TIMER_RESET = 0x01, + * JOINED_NETWORK = 0x02, + * DISASSOCIATED = 0x03, + * + * CONFIGURATION_ERROR = 0x04, + * COORDINATOR_REALIGNMENT = 0x05, + * + * COORDINATOR_START = 0x06, + * NETWORK_SECURITY_KEY_WAS_UPDATED = 0x07, + * + * NETWORK_WOKE_UP = 0x0B, + * NETWORK_WENT_TO_SLEEP = 0x0C, + * + * VOLTAGE_SPPLY_LIMIT_EXCEEDED = 0x0D, + * MODEM_CONFIGURATION_CHANGED_WHILE_JOIN_IN_PRIGRESS = 0x11, + * + * //0x80+ STACK_ERROR + * STACK_ERROR = 0x80, + * + * SEND_JOIN_ISSIED_WITHOUT_CONNECTING_AP = 0x82, + * ACCESS_POINT_NOT_FOUND = 0x83, + * PSK_NOT_FOUND = 0x84, + * SSID_NOT_FOUND = 0x87, + * + * FAILED_TO_JOIN_WITH_SECURITY_ENABLED = 0x88, + * INVALID_CHANNEL = 0x8A, + * FAILED_TO_JOIN_ACCESS_POINT = 0x8E, + * + */ + int getModemStatus(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/NodeIdentificationIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,68 @@ +#include "NodeIdentificationIndicator.h" + +NodeIdentificationIndicator::NodeIdentificationIndicator(APIFrame * frame) + : RxBase(frame) +{ + offset = getPosition() - 8; +} + +int NodeIdentificationIndicator::getReceiveStatus() +{ + return data[11]; +} + +Address NodeIdentificationIndicator::getRemoteDevice() +{ + return Address(data + 14, data + 8); +} + +Address NodeIdentificationIndicator::getSenderDevice() +{ + return Address(data + 1); +} + +char * NodeIdentificationIndicator::getNIString() +{ + int length = getPosition() - 31; + + if (length <= 0) + return NULL; + + return data + 22; +} + +int NodeIdentificationIndicator::getParentNetworkAddress() +{ + return (data[offset] << 8) | data[offset + 1]; +} + +int NodeIdentificationIndicator::getDeviceType() +{ + return data[offset + 2]; +} + +int NodeIdentificationIndicator::getSourceEvent() +{ + return data[offset + 3]; +} + +int NodeIdentificationIndicator::getDigiProfileID() +{ + return (data[offset + 4] << 8) | data[offset + 5]; +} + +int NodeIdentificationIndicator::getManufacturerID() +{ + return (data[offset + 6] << 8) | data[offset + 7]; +} + +bool NodeIdentificationIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Node_Identification_Indicator) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/NodeIdentificationIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,64 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_NodeIdentificationIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_NodeIdentificationIndicator + +#include "Address.h" +#include "RxBase.h" + +class NodeIdentificationIndicator : public RxBase +{ +private: + int offset; + +public: + NodeIdentificationIndicator(APIFrame * frame); + + /** + * + * @returns + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + * + */ + int getReceiveStatus(); + + Address getRemoteDevice(); + + Address getSenderDevice(); + + char * getNIString(); + + int getParentNetworkAddress(); + + /* + * + * @returns + * COORDINATOR = 0x00, + * ROUTER = 0x01, + * END_DEVICE = 0x02, + * + */ + int getDeviceType(); + + /* + * + * @returns + * FRAME_SENT_BY_NODE_IDENTIFICATION_PUSHBUTTON_EVENT = 0x01, + * FRAME_SENT_AFTER_JOINING_EVENT_OCCURRED = 0x02, + * FRAME_SENT_AFTER_POWER_CYCLE_EVENT_OCCURRED = 0x03, + * + */ + int getSourceEvent(); + + int getDigiProfileID(); + + int getManufacturerID(); + + bool convert(APIFrame * frame); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/RemoteCommandIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,59 @@ +#include "RemoteCommandIndicator.h" + +RemoteCommandIndicator::RemoteCommandIndicator(APIFrame * frame) + : RxBase(frame) +{} + +int RemoteCommandIndicator::getFrameID() +{ + return data[1]; +} + +char * RemoteCommandIndicator::getRequestCommand() +{ + return data + 12; +} + +int RemoteCommandIndicator::getCommandStatus() +{ + return data[14]; +} + +Address RemoteCommandIndicator::getRemoteDevice() +{ + return Address(data + 2); +} + +char * RemoteCommandIndicator::getParameter() +{ + if (getParameterLength() <= 0) + return NULL; + + return data + 15; +} + +char RemoteCommandIndicator::getParameter(int index) +{ + return data[15 + index]; +} + +int RemoteCommandIndicator::getParameterLength() +{ + return getPosition() - 15; +} + +int RemoteCommandIndicator::getParameterOffset() +{ + return 15; +} + +bool RemoteCommandIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Remote_Command_Response) + return false; + + return APIFrame::convert(frame); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/RemoteCommandIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,42 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RemoteCommandIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_RemoteCommandIndicator + +#include "Address.h" +#include "RxBase.h" +#include "ICommandResponse.h" + +class RemoteCommandIndicator : public ICommandResponse, public RxBase +{ +public: + + RemoteCommandIndicator(APIFrame * frame); + + virtual int getFrameID(); + + virtual char * getRequestCommand(); + + /** + * + * @returns + * OK = 0x00, + * ERROR = 0x01, + * INVALID_COMMAND = 0x02, + * INVALID_Parameter = 0x03, + * TRANSMISSION_FAILED = 0x04, + */ + virtual int getCommandStatus(); + + Address getRemoteDevice(); + + virtual char * getParameter(); + + virtual char getParameter(int index); + + virtual int getParameterLength(); + + virtual int getParameterOffset(); + + bool convert(APIFrame * frame); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/RouteRecordIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#include "RouteRecordIndicator.h" + +RouteRecordIndicator::RouteRecordIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +Address RouteRecordIndicator::getRemoteDevice() +{ + return Address(data + 1); +} + +int RouteRecordIndicator::getReceiveStatus() +{ + return data[11]; +} + +int RouteRecordIndicator::getNumberOfAddresses() +{ + return data[12]; +} + +int RouteRecordIndicator::getAddresses(int index) +{ + if (index >= getNumberOfAddresses()) + return -1; + + return (data[13 + (index << 2)] << 8) | data[13 + (index << 2) + 1]; +} + +bool RouteRecordIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Route_Record_Indicator) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/RouteRecordIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,35 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RouteRecordIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_RouteRecordIndicator + +#include "Address.h" +#include "RxBase.h" + +class RouteRecordIndicator : public RxBase +{ +public: + RouteRecordIndicator(APIFrame * frame); + + Address getRemoteDevice(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + int getReceiveStatus(); + + int getNumberOfAddresses(); + + /** Array of NET16 address + * index is [0, getNumberOfAddresses() -1], -1 means not avaliable + */ + int getAddresses(int index); + + bool convert(APIFrame * frame); +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/RxBase.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,14 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RxBase +#define UK_AC_HERTS_SMARTLAB_XBEE_RxBase + +#include "APIFrame.h" + +class RxBase: public APIFrame +{ +public: + RxBase(APIFrame * frame) + : APIFrame(frame) + { } +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/SensorReadIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,56 @@ +#include "SensorReadIndicator.h" + +SensorReadIndicator::SensorReadIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +Address SensorReadIndicator::GetRemoteDevice() +{ + return Address(data + 1); +} + +int SensorReadIndicator::GetReceiveStatus() +{ + return data[11]; +} + +int SensorReadIndicator::GetOneWireSensor() +{ + return data[12]; +} + +int SensorReadIndicator::GetAD0() +{ + return (data[13] << 8) | data[14]; +} + +int SensorReadIndicator::GetAD1() +{ + return (data[15] << 8) | data[16]; +} + +int SensorReadIndicator::GetAD2() +{ + return (data[17] << 8) | data[18]; +} + +int SensorReadIndicator::GetAD3() +{ + return (data[19] << 8) | data[20]; +} + +int SensorReadIndicator::GetThemometer() +{ + return (data[21] << 8) | data[22]; +} + +bool SensorReadIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::XBee_Sensor_Read_Indicato) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/SensorReadIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,46 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_SensorReadIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_SensorReadIndicator + +#include "RxBase.h" +#include "Address.h" + +class SensorReadIndicator: public RxBase +{ +public: + SensorReadIndicator(APIFrame * frame); + + Address GetRemoteDevice(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + int GetReceiveStatus(); + + /** + * AD_SENSOR_READ = 0x01, + * TEMPERATURE_SENSOR_READ = 0x02, + * HUMIDITY_SENSOR_READ = 0x03, + * WATER_PRESENT = 0x60, + */ + int GetOneWireSensor(); + + int GetAD0(); + + int GetAD1(); + + int GetAD2(); + + int GetAD3(); + + int GetThemometer(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx16IOSampleIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,41 @@ +#include "XBeeRx16IOSampleIndicator.h" + +XBeeRx16IOSampleIndicator::XBeeRx16IOSampleIndicator(APIFrame *frame) + : RxBase(frame) {} + +int XBeeRx16IOSampleIndicator::getRSSI() +{ + return data[3] * -1; +} + +IOSamples * XBeeRx16IOSampleIndicator::getIOSamples() +{ + IOSampleDecoder::XBeeSamplesParse(samples, data + 5); + return samples; +} + +int XBeeRx16IOSampleIndicator::getSamplesCount() +{ + return data[5]; +} + +int XBeeRx16IOSampleIndicator::getReceiveStatus() +{ + return data[4]; +} + +Address XBeeRx16IOSampleIndicator::getRemoteDevice() +{ + return Address(NULL, data + 1); +} + +bool XBeeRx16IOSampleIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Rx16_IO_Data_Sample_Rx_Indicator) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx16IOSampleIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,36 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx16IOSampleIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx16IOSampleIndicator + +#include "RxBase.h" +#include "Address.h" +#include "IOSamples.h" +#include "ISampleResponse.h" + +class XBeeRx16IOSampleIndicator: public ISampleResponse, public RxBase +{ +public: + XBeeRx16IOSampleIndicator(APIFrame *frame); + + virtual int getRSSI(); + + virtual IOSamples * getIOSamples(); + + virtual int getSamplesCount(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus(); + + virtual Address getRemoteDevice(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx16Indicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,54 @@ +#include "XBeeRx16Indicator.h" + +XBeeRx16Indicator::XBeeRx16Indicator(APIFrame * frame) + : RxBase(frame) +{ } + +char * XBeeRx16Indicator::getReceivedData() +{ + if (getReceivedDataLength() <= 0) + return NULL; + + return data + 5; +} + +int XBeeRx16Indicator::getReceivedDataOffset() +{ + return 5; +} + +char XBeeRx16Indicator::getReceivedData(int index) +{ + return data[5 + index]; +} + +int XBeeRx16Indicator::getReceivedDataLength() +{ + return getPosition() - 5; +} + +int XBeeRx16Indicator::getRSSI() +{ + return data[3] * -1; +} + +int XBeeRx16Indicator::getReceiveStatus() +{ + return data[4]; +} + +Address XBeeRx16Indicator::getRemoteDevice() +{ + return Address(NULL, data + 1); +} + +bool XBeeRx16Indicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Rx16_Receive_Packet) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx16Indicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx16Indicator +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx16Indicator + +#include "RxBase.h" +#include "Address.h" +#include "IPayloadResponse.h" + +class XBeeRx16Indicator: public IPayloadResponse, public RxBase +{ +public: + XBeeRx16Indicator(APIFrame * frame); + + virtual char * getReceivedData(); + + virtual int getReceivedDataOffset(); + + virtual char getReceivedData(int index); + + virtual int getReceivedDataLength(); + + virtual int getRSSI(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus(); + + virtual Address getRemoteDevice(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx64IOSampleIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,41 @@ +#include "XBeeRx64IOSampleIndicator.h" + +XBeeRx64IOSampleIndicator::XBeeRx64IOSampleIndicator(APIFrame *frame) + : RxBase(frame) {} + +int XBeeRx64IOSampleIndicator::getRSSI() +{ + return data[9] * -1; +} + +IOSamples * XBeeRx64IOSampleIndicator::getIOSamples() +{ + IOSampleDecoder::XBeeSamplesParse(samples, data + 11); + return samples; +} + +int XBeeRx64IOSampleIndicator::getSamplesCount() +{ + return data[11]; +} + +int XBeeRx64IOSampleIndicator::getReceiveStatus() +{ + return data[10]; +} + +Address XBeeRx64IOSampleIndicator::getRemoteDevice() +{ + return Address(data + 1 , NULL); +} + +bool XBeeRx64IOSampleIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Rx64_IO_Data_Sample_Rx_Indicator) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx64IOSampleIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,36 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx64IOSampleIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx64IOSampleIndicator + +#include "RxBase.h" +#include "Address.h" +#include "IOSamples.h" +#include "ISampleResponse.h" + +class XBeeRx64IOSampleIndicator: public ISampleResponse, public RxBase +{ +public: + XBeeRx64IOSampleIndicator(APIFrame *frame); + + virtual int getRSSI(); + + virtual IOSamples * getIOSamples(); + + virtual int getSamplesCount(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus(); + + virtual Address getRemoteDevice(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx64Indicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,55 @@ +#include "XBeeRx64Indicator.h" + +XBeeRx64Indicator::XBeeRx64Indicator(APIFrame * frame) + : RxBase(frame) +{ } + +char * XBeeRx64Indicator::getReceivedData() +{ + if (getReceivedDataLength() <= 0) + return NULL; + + return data + 11; +} + +int XBeeRx64Indicator::getReceivedDataOffset() +{ + return 11; +} + +char XBeeRx64Indicator::getReceivedData(int index) +{ + return data[11 + index]; +} + +int XBeeRx64Indicator::getReceivedDataLength() +{ + return getPosition() - 11; +} + +int XBeeRx64Indicator::getRSSI() +{ + return data[9] * -1; +} + +int XBeeRx64Indicator::getReceiveStatus() +{ + return data[10]; +} + +Address XBeeRx64Indicator::getRemoteDevice() +{ + return Address(data + 1, NULL); +} + +bool XBeeRx64Indicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::Rx64_Receive_Packet) + return false; + + return APIFrame::convert(frame); +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeRx64Indicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx64Indicator +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeRx64Indicator + +#include "RxBase.h" +#include "Address.h" +#include "IPayloadResponse.h" + +class XBeeRx64Indicator: public IPayloadResponse, public RxBase +{ +public: + XBeeRx64Indicator(APIFrame * frame); + + virtual char * getReceivedData(); + + virtual int getReceivedDataOffset(); + + virtual char getReceivedData(int index); + + virtual int getReceivedDataLength(); + + virtual int getRSSI(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus(); + + virtual Address getRemoteDevice(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeTxStatusIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,26 @@ +#include "XBeeTxStatusIndicator.h" + +XBeeTxStatusIndicator::XBeeTxStatusIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +int XBeeTxStatusIndicator::getFrameID() +{ + return data[1]; +} + +int XBeeTxStatusIndicator::getDeliveryStatus() +{ + return data[2]; +} + +bool XBeeTxStatusIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::XBee_Transmit_Status) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/XBeeTxStatusIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,44 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeTxStatusIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeTxStatusIndicator + +#include "RxBase.h" +#include "ITransmitStatus.h" + +class XBeeTxStatusIndicator: public ITransmitStatus, public RxBase +{ +public: + XBeeTxStatusIndicator(APIFrame * frame); + + virtual int getFrameID(); + + /** + *SUCCESS = 0x00, + * MAC_ACK_FAILURE = 0x01, + * CCA_FAILURE = 0x02, + * TRANSMISSION_WAS_PURGED = 0x03, + * PHYSICAL_ERROR_OCCURRED_ON_THE_INTERFACE_WITH_THE_WIFI_TRANSCEIVER = 0x04, + * INVALID_DESTINATION_ENDPOINT = 0x15, + * NO_BUFFERS = 0x18, + * NETWORK_ACK_FAILURE = 0x21, + * NOT_JOINED_TO_NETWORK = 0x22, + * SELF_ADDRESSED = 0x23, + * ADDRESS_NOT_FOUND = 0x24, + * ROUTE_NOT_FOUND = 0x25, + * BROADCAST_SOURCE_FAILED_TO_HEAR_A_NEIGBOR_RELAY_THE_MESSAGE = 0x26, + * INVALID_BINDING_TABLE_INDEX = 0x2B, + * INVALID_ENDPOINT = 0x2C, + * ATTEMPTED_BROADCAST_WITH_APS_TRANSMISSION = 0x2D, + * ATTEMPTED_UNICAST_WITH_APS_TRANSMISSION_BUT_EE_0 = 0x2E, + * SOFTWARE_ERROR_OCCURRED = 0x31, + * RESOURCE_ERROR_LACK_OF_FREE_BUFFERS_TIMERS_ETC = 0x32, + * DATA_PAYLOAD_TOO_LARGE = 0x74, + * INDIRECT_MESSAGE_UNREQUESTED = 0x75, + * ATTEMPT_TO_CREATE_A_CLIENT_SOCKET_FAILED = 0x76, + * KEY_NOT_AUTHORIZED = 0xBB, + */ + virtual int getDeliveryStatus(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeExplicitRxIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,59 @@ +#include "ZigBeeExplicitRxIndicator.h" + +ZigBeeExplicitRxIndicator::ZigBeeExplicitRxIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +char * ZigBeeExplicitRxIndicator::getReceivedData() +{ + if (getReceivedDataLength() <=0) + return NULL; + + return data + 18; +} + +int ZigBeeExplicitRxIndicator::getReceivedDataOffset() +{ + return 18; +} + +char ZigBeeExplicitRxIndicator::getReceivedData(int index) +{ + return data[18 + index]; +} + +int ZigBeeExplicitRxIndicator::getReceivedDataLength() +{ + return getPosition() - 18; +} + +ExplicitAddress ZigBeeExplicitRxIndicator::getExplicitRemoteDevice() +{ + return ExplicitAddress(data + 1, data + 11); +} + +Address ZigBeeExplicitRxIndicator::getRemoteDevice() +{ + return Address(data + 1); +} + +int ZigBeeExplicitRxIndicator::getReceiveStatus() +{ + return data[17]; +} + +int ZigBeeExplicitRxIndicator::getRSSI() +{ + return 0; +} + +bool ZigBeeExplicitRxIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::ZigBee_Explicit_Rx_Indicator) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeExplicitRxIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,34 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeExplicitRxIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeExplicitRxIndicator + +#include "RxBase.h" +#include "Address.h" +#include "ExplicitAddress.h" +#include "IPayloadResponse.h" + +class ZigBeeExplicitRxIndicator: public IPayloadResponse, public RxBase +{ +public: + + ZigBeeExplicitRxIndicator(APIFrame * frame); + + virtual char * getReceivedData(); + + virtual int getReceivedDataOffset(); + + virtual char getReceivedData(int index); + + virtual int getReceivedDataLength(); + + ExplicitAddress getExplicitRemoteDevice(); + + virtual Address getRemoteDevice(); + + virtual int getReceiveStatus(); + + virtual int getRSSI(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeIOSampleIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,41 @@ +#include "ZigBeeIOSampleIndicator.h" + +ZigBeeIOSampleIndicator::ZigBeeIOSampleIndicator(APIFrame *frame) + : RxBase(frame) {} + +int ZigBeeIOSampleIndicator::getRSSI() +{ + return 0; +} + +IOSamples * ZigBeeIOSampleIndicator::getIOSamples() +{ + IOSampleDecoder::ZigBeeSamplesParse(samples, data + 12); + return samples; +} + +int ZigBeeIOSampleIndicator::getSamplesCount() +{ + return data[12]; +} + +int ZigBeeIOSampleIndicator::getReceiveStatus() +{ + return data[11]; +} + +Address ZigBeeIOSampleIndicator::getRemoteDevice() +{ + return Address(data + 1); +} + +bool ZigBeeIOSampleIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::ZigBee_IO_Data_Sample_Rx_Indicator) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeIOSampleIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,36 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeIOSampleIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeIOSampleIndicator + +#include "RxBase.h" +#include "Address.h" +#include "IOSamples.h" +#include "ISampleResponse.h" + +class ZigBeeIOSampleIndicator: public ISampleResponse, public RxBase +{ +public: + ZigBeeIOSampleIndicator(APIFrame *frame); + + virtual int getRSSI(); + + virtual IOSamples * getIOSamples(); + + virtual int getSamplesCount(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus(); + + virtual Address getRemoteDevice(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeRxIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,54 @@ +#include "ZigBeeRxIndicator.h" + +ZigBeeRxIndicator::ZigBeeRxIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +char * ZigBeeRxIndicator::getReceivedData() +{ + if (getReceivedDataLength() <= 0) + return NULL; + + return data + 12; +} + +int ZigBeeRxIndicator::getReceivedDataOffset() +{ + return 12; +} + +char ZigBeeRxIndicator::getReceivedData(int index) +{ + return data[12 + index]; +} + +int ZigBeeRxIndicator::getReceivedDataLength() +{ + return getPosition() - 12; +} + +int ZigBeeRxIndicator::getReceiveStatus() +{ + return data[11]; +} + +Address ZigBeeRxIndicator::getRemoteDevice() +{ + return Address(data + 1); +} + +int ZigBeeRxIndicator::getRSSI() +{ + return 0; +} + +bool ZigBeeRxIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::ZigBee_Receive_Packet) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeRxIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeRxIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeRxIndicator + +#include "RxBase.h" +#include "Address.h" +#include "IPayloadResponse.h" + +class ZigBeeRxIndicator: public IPayloadResponse, public RxBase +{ +public: + ZigBeeRxIndicator(APIFrame * frame); + + virtual char * getReceivedData(); + + virtual int getReceivedDataOffset(); + + virtual char getReceivedData(int index); + + virtual int getReceivedDataLength(); + + /** + * bit mask + * SUCCESS = 0x00, + * PACKET_ACKNOWLEDGED = 0x01, + * PACKET_WAS_A_BROADCAST = 0x02, + * PACKET_RECEIVED_ON_BOARDCAST_PAN = 0x04, + * PACKET_ENCRYPTED_WITH_APS_ENCRYPTION = 0x20, + * PACKET_WAS_SENT_FROM_AN_END_DEVICE = 0x40, + */ + virtual int getReceiveStatus(); + + virtual Address getRemoteDevice(); + + virtual int getRSSI(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeTxStatusIndicator.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,41 @@ +#include "ZigBeeTxStatusIndicator.h" + +ZigBeeTxStatusIndicator::ZigBeeTxStatusIndicator(APIFrame * frame) + : RxBase(frame) +{ } + +int ZigBeeTxStatusIndicator::getFrameID() +{ + return data[1]; +} + +int ZigBeeTxStatusIndicator::getDeliveryStatus() +{ + return data[5]; +} + +int ZigBeeTxStatusIndicator::getDestinationAddress16() +{ + return (data[2] << 8) | data[3]; +} + +int ZigBeeTxStatusIndicator::getTransmitRetryCount() +{ + return data[4]; +} + +int ZigBeeTxStatusIndicator::getDiscoveryStatus() +{ + return data[6]; +} + +bool ZigBeeTxStatusIndicator::convert(APIFrame * frame) +{ + if (frame == NULL) + return false; + + if (frame->getFrameType() != APIFrame::ZigBee_Transmit_Status) + return false; + + return APIFrame::convert(frame); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Indicator/ZigBeeTxStatusIndicator.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,57 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeTxStatusIndicator +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeTxStatusIndicator + +#include "RxBase.h" +#include "ITransmitStatus.h" + +class ZigBeeTxStatusIndicator: public ITransmitStatus, public RxBase +{ +public: + ZigBeeTxStatusIndicator(APIFrame * frame); + + virtual int getFrameID(); + + /** + *SUCCESS = 0x00, + * MAC_ACK_FAILURE = 0x01, + * CCA_FAILURE = 0x02, + * TRANSMISSION_WAS_PURGED = 0x03, + * PHYSICAL_ERROR_OCCURRED_ON_THE_INTERFACE_WITH_THE_WIFI_TRANSCEIVER = 0x04, + * INVALID_DESTINATION_ENDPOINT = 0x15, + * NO_BUFFERS = 0x18, + * NETWORK_ACK_FAILURE = 0x21, + * NOT_JOINED_TO_NETWORK = 0x22, + * SELF_ADDRESSED = 0x23, + * ADDRESS_NOT_FOUND = 0x24, + * ROUTE_NOT_FOUND = 0x25, + * BROADCAST_SOURCE_FAILED_TO_HEAR_A_NEIGBOR_RELAY_THE_MESSAGE = 0x26, + * INVALID_BINDING_TABLE_INDEX = 0x2B, + * INVALID_ENDPOINT = 0x2C, + * ATTEMPTED_BROADCAST_WITH_APS_TRANSMISSION = 0x2D, + * ATTEMPTED_UNICAST_WITH_APS_TRANSMISSION_BUT_EE_0 = 0x2E, + * SOFTWARE_ERROR_OCCURRED = 0x31, + * RESOURCE_ERROR_LACK_OF_FREE_BUFFERS_TIMERS_ETC = 0x32, + * DATA_PAYLOAD_TOO_LARGE = 0x74, + * INDIRECT_MESSAGE_UNREQUESTED = 0x75, + * ATTEMPT_TO_CREATE_A_CLIENT_SOCKET_FAILED = 0x76, + * KEY_NOT_AUTHORIZED = 0xBB, + */ + virtual int getDeliveryStatus(); + + int getDestinationAddress16(); + + int getTransmitRetryCount(); + + /** + * NO_DISCOVERY_OVERHEAD = 0x00, + * ADDRESS_DISCOVERY = 0x01, + * ROUTE_DISCOVERY = 0x02, + * ADDRESS_AND_ROUTE_DISCOVERY = 0x03, + * EXTENED_TIMEOUT_DISCOVERY = 0x40, + */ + int getDiscoveryStatus(); + + bool convert(APIFrame * frame); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/OptionsBase.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,35 @@ +#include "OptionsBase.h" + +OptionsBase::OptionsBase() +{ + value = 0x00; +} + +OptionsBase::OptionsBase(char option) +{ + value = option; +} + +OptionsBase OptionsBase::DEFAULT = OptionsBase(); + +OptionsBase OptionsBase::DisableRetriesRouteRepair = OptionsBase(0x01); + +bool OptionsBase::getDisableRetriesRouteRepair() +{ + if ((value & 0x01) == 0x01) + return true; + else return false; +} + +void OptionsBase::setDisableRetriesRouteRepair(bool status) +{ + if (status) + value |= 0x01; + else + value &= 0xFE; +} + +char OptionsBase::getValue() +{ + return value; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/OptionsBase.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,24 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_OptionsBase +#define UK_AC_HERTS_SMARTLAB_XBEE_OptionsBase + +class OptionsBase +{ +protected : + char value; +public: + OptionsBase(); + + OptionsBase(char option); + + static OptionsBase DEFAULT; + + static OptionsBase DisableRetriesRouteRepair; + + bool getDisableRetriesRouteRepair(); + + void setDisableRetriesRouteRepair(bool status); + + char getValue(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/RemoteCommandOptions.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,34 @@ +#include "RemoteCommandOptions.h" + + +RemoteCommandOptions::RemoteCommandOptions() + : TransmitOptions() +{ } + +RemoteCommandOptions::RemoteCommandOptions(char option) + : TransmitOptions(option) +{ } + +RemoteCommandOptions::RemoteCommandOptions(bool disable_retries_and_route_repair, bool apply_changes, bool enable_APS_encryption, bool use_extended_transmission_timeout) + : TransmitOptions(disable_retries_and_route_repair, enable_APS_encryption, use_extended_transmission_timeout) +{ + if (apply_changes) + value |= 0x02; +} + +RemoteCommandOptions RemoteCommandOptions::ApplyChanges = RemoteCommandOptions (0x02); + +void RemoteCommandOptions::setApplyChanges(bool status) +{ + if (status) + value |= 0x02; + else + value &= 0xFD; +} + +bool RemoteCommandOptions::getApplyChanges() +{ + if (value & 0x02 == 0x02) + return true; + else return false; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/RemoteCommandOptions.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,23 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RemoteCommandOptions +#define UK_AC_HERTS_SMARTLAB_XBEE_RemoteCommandOptions + +#include "TransmitOptions.h" + +class RemoteCommandOptions : public TransmitOptions +{ +public : + RemoteCommandOptions(); + + RemoteCommandOptions(char option); + + RemoteCommandOptions(bool disable_retries_and_route_repair, bool apply_changes, bool enable_APS_encryption, bool use_extended_transmission_timeout); + + static RemoteCommandOptions ApplyChanges; + + bool getApplyChanges(); + + void setApplyChanges(bool status); + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/TransmitOptions.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,54 @@ +#include "TransmitOptions.h" + +TransmitOptions::TransmitOptions() + : OptionsBase() +{ } + +TransmitOptions::TransmitOptions(char option) + : OptionsBase(option) +{ } + +TransmitOptions::TransmitOptions(bool disable_retries_and_route_repair, bool enable_APS_encryption, bool use_extended_transmission_timeout) +{ + value = 0x00; + if (disable_retries_and_route_repair) + value |= 0x01; + if (enable_APS_encryption) + value |= 0x20; + if (use_extended_transmission_timeout) + value |= 0x40; +} + +TransmitOptions TransmitOptions::EnableAPS = TransmitOptions(0x20); + +TransmitOptions TransmitOptions::UseExtendedTimeout = TransmitOptions(0x40); + +bool TransmitOptions::getEnableAPS() +{ + if (value & 0x20 == 0x20) + return true; + else return false; +} + +void TransmitOptions::setEnableAPS(bool status) +{ + if (status) + value |= 0x20; + else + value &= 0xDF; +} + +bool TransmitOptions::getUseExtendedTimeout() +{ + if ((value & 0x40) == 0x40) + return true; + else return false; +} + +void TransmitOptions::setUseExtendedTimeout(bool status) +{ + if (status) + value |= 0x40; + else + value &= 0xBF; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/TransmitOptions.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,33 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_TransmitOptions +#define UK_AC_HERTS_SMARTLAB_XBEE_TransmitOptions + +#include "OptionsBase.h" + +class TransmitOptions : public OptionsBase +{ + //Default = 0x00; + //Disable_Retries_Route_Repair = 0x01; + //Enable_APS = 0x20; + //Use_Extended_Timeout = 0x40; + +public: + TransmitOptions(); + + TransmitOptions(char option); + + TransmitOptions(bool disable_retries_and_route_repair, bool enable_APS_encryption, bool use_extended_transmission_timeout); + + static TransmitOptions EnableAPS; + + static TransmitOptions UseExtendedTimeout; + + bool getEnableAPS(); + + void setEnableAPS(bool status); + + bool getUseExtendedTimeout(); + + void setUseExtendedTimeout(bool status); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/Tx16TransmitOptions.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,70 @@ +#include "Tx16TransmitOptions.h" + +Tx16TransmitOptions::Tx16TransmitOptions() { } + +Tx16TransmitOptions::Tx16TransmitOptions(char value):OptionsBase(value) +{ } + +Tx16TransmitOptions::Tx16TransmitOptions(bool disable_retries_and_route_repair, bool force_long_header, bool disable_long_header, bool invoke_traceroute) +{ + value = 0x00; + if (disable_retries_and_route_repair) + value |= 0x01; + if (force_long_header) + value |= 0x02; + if (disable_long_header) + value |= 0x04; + if (invoke_traceroute) + value |= 0x08; +} + +Tx16TransmitOptions Tx16TransmitOptions::ForceLongHeader = Tx16TransmitOptions(0x02); + +Tx16TransmitOptions Tx16TransmitOptions::DisableLongHeader = Tx16TransmitOptions(0x04); + +Tx16TransmitOptions Tx16TransmitOptions::InvokeTraceroute = Tx16TransmitOptions(0x08); + +bool Tx16TransmitOptions::getForceLongHeader() +{ + if ((value & 0x02) == 0x02) + return true; + else return false; +} + +void Tx16TransmitOptions::setForceLongHeader(bool status) +{ + if (status) + value |= 0x02; + else + value &= 0xFD; +} + +bool Tx16TransmitOptions::getDisableLongHeader() +{ + if ((value & 0x04) == 0x04) + return true; + else return false; +} + +void Tx16TransmitOptions::setDisableLongHeader(bool status) +{ + if (status) + value |= 0x04; + else + value &= 0xFB; +} + +bool Tx16TransmitOptions::getInvokeTraceroute() +{ + if ((value & 0x08) == 0x08) + return true; + else return false; +} + +void Tx16TransmitOptions::setInvokeTraceroute(bool status) +{ + if (status) + value |= 0x08; + else + value &= 0xF7; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/Tx16TransmitOptions.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,40 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_Tx16TransmitOptions +#define UK_AC_HERTS_SMARTLAB_XBEE_Tx16TransmitOptions + +#include "OptionsBase.h" + +class Tx16TransmitOptions : public OptionsBase +{ + + //0x01 - Disable retries and route repair + //0x02 - Force a long header to precede this packet + //0x04 - Disable Sending of long header + //0x08 - Invoke Traceroute + +public: + static Tx16TransmitOptions ForceLongHeader; + + static Tx16TransmitOptions DisableLongHeader; + + static Tx16TransmitOptions InvokeTraceroute; + + Tx16TransmitOptions(); + + Tx16TransmitOptions(char value); + + Tx16TransmitOptions(bool disable_retries_and_route_repair, bool force_long_header, bool disable_long_header, bool invoke_traceroute); + + bool getForceLongHeader(); + + void setForceLongHeader(bool status); + + bool getDisableLongHeader(); + + void setDisableLongHeader(bool status); + + bool getInvokeTraceroute(); + + void setInvokeTraceroute(bool status); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/Tx64TransmitOptions.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,90 @@ +#include "Tx64TransmitOptions.h" + +Tx64TransmitOptions::Tx64TransmitOptions() { } + +Tx64TransmitOptions::Tx64TransmitOptions(char value) + : OptionsBase(value) +{ } + +Tx64TransmitOptions::Tx64TransmitOptions(bool disable_retries_and_route_repair, bool donot_repeat_packet, bool send_packet_with_broadcast_PanID, bool invoke_traceroute, bool purge_packet_if_delayed_due_to_duty_cycle) +{ + value = 0x00; + if (disable_retries_and_route_repair) + value |= 0x01; + if (donot_repeat_packet) + value |= 0x02; + if (send_packet_with_broadcast_PanID) + value |= 0x04; + if (invoke_traceroute) + value |= 0x08; + if (purge_packet_if_delayed_due_to_duty_cycle) + value |= 0x10; +} + +Tx64TransmitOptions Tx64TransmitOptions::DonotRepeatPacket = Tx64TransmitOptions(0x02); + +Tx64TransmitOptions Tx64TransmitOptions::SendPacketWithBroadcastPanID = Tx64TransmitOptions(0x04); + +Tx64TransmitOptions Tx64TransmitOptions::InvokeTraceroute = Tx64TransmitOptions(0x08); + +Tx64TransmitOptions Tx64TransmitOptions::PurgePacketWhenDelayed = Tx64TransmitOptions(0x10); + +bool Tx64TransmitOptions::getDonotRepeatPacket() +{ + if ((value & 0x02) == 0x02) + return true; + else return false; +} + +void Tx64TransmitOptions::setDonotRepeatPacket(bool status) +{ + if (status) + value |= 0x02; + else + value &= 0xFD; +} + +bool Tx64TransmitOptions::getSendPacketWithBroadcastPanID() +{ + if ((value & 0x04) == 0x04) + return true; + else return false; +} + +void Tx64TransmitOptions::setSendPacketWithBroadcastPanID(bool status) +{ + if (status) + value |= 0x04; + else + value &= 0xFB; +} + +bool Tx64TransmitOptions::getInvokeTraceroute() +{ + if ((value & 0x08) == 0x08) + return true; + else return false; +} + +void Tx64TransmitOptions::setInvokeTraceroute(bool status) +{ + if (status) + value |= 0x08; + else + value &= 0xF7; +} + +bool Tx64TransmitOptions::getPurgePacketWhenDelayed() +{ + if ((value & 0x10) == 0x10) + return true; + else return false; +} + +void Tx64TransmitOptions::setPurgePacketWhenDelayed(bool status) +{ + if (status) + value |= 0x10; + else + value &= 0xEF; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Options/Tx64TransmitOptions.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,45 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_Tx64TransmitOptions +#define UK_AC_HERTS_SMARTLAB_XBEE_Tx64TransmitOptions + +#include "OptionsBase.h" + +class Tx64TransmitOptions : public OptionsBase +{ + //0x01 - Disable retries and route repair (XTEND and XBEE) + //0x02 - Don't repeat this packet (not implemented) + //0x04 - Send packet with Broadcast Pan ID (XBEE only) + //0x08 - Invoke Traceroute (XTEND version 8030 only) + //0x10 (XB868DP) If the packet would be delayed due to duty cycle then purge it. All other bits must be set to 0 +public: + Tx64TransmitOptions(); + + Tx64TransmitOptions(char vlaue); + + Tx64TransmitOptions(bool disable_retries_and_route_repair, bool donot_repeat_packet, bool send_packet_with_broadcast_PanID, bool invoke_traceroute, bool purge_packet_if_delayed_due_to_duty_cycle); + + static Tx64TransmitOptions DonotRepeatPacket; + + static Tx64TransmitOptions SendPacketWithBroadcastPanID; + + static Tx64TransmitOptions InvokeTraceroute; + + static Tx64TransmitOptions PurgePacketWhenDelayed; + + bool getDonotRepeatPacket(); + + void setDonotRepeatPacket(bool status); + + bool getSendPacketWithBroadcastPanID(); + + void setSendPacketWithBroadcastPanID(bool status); + + bool getInvokeTraceroute(); + + void setInvokeTraceroute(bool status); + + bool getPurgePacketWhenDelayed(); + + void setPurgePacketWhenDelayed(bool status); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ATCommandRequest.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,31 @@ +#include "ATCommandRequest.h" + +ATCommandRequest::ATCommandRequest(char frameID, const char * command, const char * parameter, int offset, int length) + : TxBase(2 + (parameter == NULL ? 0 : length), APIFrame::AT_Command, frameID) +{ + set(command[0]); + set(command[1]); + + if (parameter != NULL) + sets(parameter, offset, length); +} + +void ATCommandRequest::setAppleChanges(bool appleChanges) +{ + if (appleChanges) + setFrameType(APIFrame::AT_Command); + else + setFrameType(APIFrame::AT_Command_Queue_Parameter_Value); +} + +void ATCommandRequest::setCommand(const char * command) +{ + set(2, command[0]); + set(3, command[1]); +} + +void ATCommandRequest::setParameter(const char * parameter, int offset, int length) +{ + setPosition(4); + sets(parameter, offset, length); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ATCommandRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,31 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ATCommandRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_ATCommandRequest + +#include "TxBase.h" +#include "ICommandRequest.h" + +class ATCommandRequest: public TxBase, public ICommandRequest +{ + +public: + //0x08 or 0x09 + //FrameID + //AT_Command + //Parameter_Value + + /// <summary> + /// + /// </summary> + /// <param name="FrameID"></param> + /// <param name="AT_Command"></param> + /// <param name="Parameter_Value">this can be null</param> + ATCommandRequest(char frameID, const char * command, const char * parameter=NULL, int offset=0, int length=0); + + virtual void setAppleChanges(bool appleChanges); + + virtual void setCommand(const char * command); + + virtual void setParameter(const char * parameter, int offset, int length); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/CreateSourceRouteRequest.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,24 @@ +#include "CreateSourceRouteRequest.h" + +CreateSourceRouteRequest::CreateSourceRouteRequest(char frameID, Address * remoteAddress, int * addresses, int size) + : TxBase(12 + (size << 2), APIFrame::Create_Source_Route, frameID) +{ + sets(remoteAddress->getAddressValue(), 0, 10); + set(0x00); + setAddresses(addresses, size); +} + +void CreateSourceRouteRequest::setRemoteAddress(Address * remoteAddress) +{ + sets(2, remoteAddress->getAddressValue(), 0, 10); +} + +void CreateSourceRouteRequest::setAddresses(int * addresses, int size) +{ + setPosition(13); + set(size); + for (int i = 0; i< size; i++) { + set(addresses[i] >> 8); + set(addresses[i]); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/CreateSourceRouteRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,36 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_CreateSourceRouteRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_CreateSourceRouteRequest + +#include "TxBase.h" +#include "Address.h" + +class CreateSourceRouteRequest: public TxBase +{ + +public: + //0x21 + //FrameID + //RemoteDevice (64 + 16) + //0x00 + //Number of Address + //Address List + + /// <summary> + /// + /// </summary> + /// <param name="FrameID"></param> + /// <param name="AT_Command"></param> + /// <param name="Parameter_Value">this can be null</param> + CreateSourceRouteRequest(char frameID, Address * remoteAddress, int * addresses, int size); + + void setRemoteAddress(Address * remoteAddress); + + /** + * + * @param addresses array of network address + * + */ + void setAddresses(int * addresses, int size); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ICommandRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,16 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ICommandRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_ICommandRequest + +class ICommandRequest +{ + +public: + + virtual void setAppleChanges(bool appleChanges) = 0; + + virtual void setCommand(const char * command) = 0; + + virtual void setParameter(const char * parameter, int offset, int length) = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/IOCDetectionConfigRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,16 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_IOCDetectionConfigRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_IOCDetectionConfigRequest + +#include "Pin.h" +#include "ATCommands.h" +#include "ATCommandRequest.h" + +class IOCDetectionConfigRequest : public ATCommandRequest +{ +public: + IOCDetectionConfigRequest(char frameID, Pin * pins, int size) + : ATCommandRequest(frameID, ATCommands::Digital_IO_Change_Detection, Pin::IOChangeDetectionConfiguration(pins, size), 0, 2) + { } +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/IPayloadRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,15 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_IPayloadRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_IPayloadRequest + +class IPayloadRequest +{ + +public: + virtual void setPayload(const char * data,int offset, int length) = 0; + + virtual void setTransmitOptions(OptionsBase * transmitOptions) = 0; + + virtual void setRemoteAddress(Address * remoteAddress) = 0; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/PinConfigurationRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_PinConfigurationRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_PinConfigurationRequest + +#include "Pin.h" +#include "ATCommands.h" +#include "ATCommandRequest.h" + +class PinConfigurationRequest : public ATCommandRequest +{ +public: + /** + * @param function + *DISABLED = 0x00, + *RESERVED_FOR_PIN_SPECIFIC_ALTERNATE_FUNCTIONALITIES = 0x01, + *ANALOG_INPUT_SINGLE_ENDED = 0x02, + *DIGITAL_INPUT_MONITORED = 0x03, + *DIGITAL_OUTPUT_DEFAULT_LOW = 0x04, + *DIGITAL_OUTPUT_DEFAULT_HIGH = 0x05, + *ALTERNATE_FUNCTIONALITIES_WHERE_APPLICABLE = 0x06//0x06~0x09 + */ + PinConfigurationRequest(char frameID, Pin * pin, char function) + : ATCommandRequest(frameID, pin->getCommand(), &function, 0, 1) + { } + + /** + * @param function + *DISABLED = 0x00, + *RESERVED_FOR_PIN_SPECIFIC_ALTERNATE_FUNCTIONALITIES = 0x01, + *ANALOG_INPUT_SINGLE_ENDED = 0x02, + *DIGITAL_INPUT_MONITORED = 0x03, + *DIGITAL_OUTPUT_DEFAULT_LOW = 0x04, + *DIGITAL_OUTPUT_DEFAULT_HIGH = 0x05, + *ALTERNATE_FUNCTIONALITIES_WHERE_APPLICABLE = 0x06//0x06~0x09 + */ + void setPinFunction(char function) { data[4] = function; } + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/RemoteATCommandRequest.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,40 @@ +#include "RemoteATCommandRequest.h" + +RemoteATCommandRequest::RemoteATCommandRequest(char frameID, Address * remoteAddress, const char * command, OptionsBase * transmitOptions, const char * parameter, int parameterOffset, int parameterLength) + : TxBase(13 + (parameter == NULL ? 0 : parameterLength), APIFrame::Remote_Command_Request, frameID) +{ + sets(remoteAddress->getAddressValue(), 0, 10); + set(transmitOptions->getValue()); + sets(command, 0, 2); + + if (parameter != NULL) + sets(parameter, parameterOffset, parameterLength); +} + +void RemoteATCommandRequest::setTransmitOptions(OptionsBase * transmitOptions) +{ + data[12] = transmitOptions->getValue(); +} + +void RemoteATCommandRequest::setAppleChanges(bool appleChanges) +{ + if (appleChanges) + data[12] |= 0x02; + else data[12] &= 0xFD; +} + +void RemoteATCommandRequest::setCommand(const char * command) +{ + sets(13, command, 0, 2); +} + +void RemoteATCommandRequest::setParameter(const char * parameter, int offset, int length) +{ + setPosition(15); + sets(parameter, offset, length); +} + +void RemoteATCommandRequest::setRemoteAddress(Address * remoteAddress) +{ + sets(2, remoteAddress->getAddressValue(), 0, 10); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/RemoteATCommandRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RemoteATCommandRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_RemoteATCommandRequest + +#include "TxBase.h" +#include "ICommandRequest.h" + +class RemoteATCommandRequest : public TxBase, public ICommandRequest +{ + +public: + //0x17 + //FrameID; + //RemoteDevice + //Remote Command Options + //AT_Command + //Parameter_Value + + /// <summary> + /// + /// </summary> + /// <param name="FrameID"></param> + /// <param name="RemoteDevice"></param> + /// <param name="options">RemoteCommandOptions</param> + /// <param name="AT_Command"></param> + /// <param name="Parameter_Value">this can be null</param> + RemoteATCommandRequest(char frameID, Address * remoteAddress, const char * command, OptionsBase * transmitOptions, const char * parameter=NULL, int parameterOffset=0, int parameterLength=0); + + void setTransmitOptions(OptionsBase * transmitOptions); + + virtual void setAppleChanges(bool appleChanges); + + virtual void setCommand(const char * command); + + virtual void setParameter(const char * parameter, int offset, int length); + + void setRemoteAddress(Address * remoteAddress); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/RemoteIODetectionConfigRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,16 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RemoteIODetectionConfigRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_RemoteIODetectionConfigRequest + +#include "Pin.h" +#include "ATCommands.h" +#include "RemoteATCommandRequest.h" + +class RemoteIODetectionConfigRequest : public RemoteATCommandRequest +{ +public: + RemoteIODetectionConfigRequest(char frameID, Address * remoteAddress, Pin * pins, int size) + : RemoteATCommandRequest(frameID, remoteAddress, ATCommands::Digital_IO_Change_Detection, &RemoteCommandOptions::ApplyChanges, Pin::IOChangeDetectionConfiguration(pins, size), 0, 2) + { } +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/RemotePinConfigurationRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,39 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_RemotePinConfigurationRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_RemotePinConfigurationRequest + +#include "Pin.h" +#include "Address.h" +#include "ATCommands.h" +#include "RemoteATCommandRequest.h" + +class RemotePinConfigurationRequest : public RemoteATCommandRequest +{ +public: + /** + * @param function + *DISABLED = 0x00, + *RESERVED_FOR_PIN_SPECIFIC_ALTERNATE_FUNCTIONALITIES = 0x01, + *ANALOG_INPUT_SINGLE_ENDED = 0x02, + *DIGITAL_INPUT_MONITORED = 0x03, + *DIGITAL_OUTPUT_DEFAULT_LOW = 0x04, + *DIGITAL_OUTPUT_DEFAULT_HIGH = 0x05, + *ALTERNATE_FUNCTIONALITIES_WHERE_APPLICABLE = 0x06//0x06~0x09 + */ + RemotePinConfigurationRequest(char frameID, Address * remoteAddress, Pin * pin, char function) + : RemoteATCommandRequest(frameID, remoteAddress, pin->getCommand(), &RemoteCommandOptions::ApplyChanges, &function, 0, 1) + { } + + /** + * @param function + *DISABLED = 0x00, + *RESERVED_FOR_PIN_SPECIFIC_ALTERNATE_FUNCTIONALITIES = 0x01, + *ANALOG_INPUT_SINGLE_ENDED = 0x02, + *DIGITAL_INPUT_MONITORED = 0x03, + *DIGITAL_OUTPUT_DEFAULT_LOW = 0x04, + *DIGITAL_OUTPUT_DEFAULT_HIGH = 0x05, + *ALTERNATE_FUNCTIONALITIES_WHERE_APPLICABLE = 0x06//0x06~0x09 + */ + void setPinFunction(char function) { data[15] = function; } +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/TxBase.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,19 @@ +#include "TxBase.h" + +TxBase::TxBase(int length, char identifier, char frameID) + : APIFrame(length + 2) +{ + setFrameType(identifier); + setFrameID(frameID); + setPosition(2); +} + +void TxBase::setFrameID(char frameID) +{ + data[1] = frameID; +} + +char TxBase::getFrameID() +{ + return data[1]; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/TxBase.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,33 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_TxBase +#define UK_AC_HERTS_SMARTLAB_XBEE_TxBase + +#include "APIFrame.h" + +#include "Address.h" +#include "OptionsBase.h" +#include "TransmitOptions.h" +#include "RemoteCommandOptions.h" + +class TxBase : public APIFrame +{ + +public: + + /// <summary> + /// + /// </summary> + /// <param name="Length">the length of payload not include Frame Type, Frame ID and CheckSum</param> + /// <param name="identifier">Frame Type</param> + /// <param name="frameID">Frame ID</param> + TxBase(int length, char identifier, char frameID); + + /// <summary> + /// this does not affect the position, will always write to position 1 + /// </summary> + /// <param name="identifier"></param> + void setFrameID(char frameID); + + char getFrameID(); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/XBeeTx16Request.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,27 @@ +#include "XBeeTx16Request.h" + +XBeeTx16Request::XBeeTx16Request(char frameID, Address * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length) + : TxBase(3 + length, APIFrame::Tx16_Request, frameID) +{ + set(remoteAddress->getNetworkAddress() >> 8); + set(remoteAddress->getNetworkAddress()); + set(transmitOptions->getValue()); + sets(payload, offset, length); +} + +void XBeeTx16Request::setPayload(const char * data, int offset, int length) +{ + setPosition(5); + sets(data, offset, length); +} + +void XBeeTx16Request::setTransmitOptions(OptionsBase * transmitOptions) +{ + data[4] = transmitOptions->getValue(); +} + +void XBeeTx16Request::setRemoteAddress(Address * remoteAddress) +{ + data[2] = remoteAddress->getNetworkAddress() >> 8; + data[3] = remoteAddress->getNetworkAddress(); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/XBeeTx16Request.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,24 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeTx16Request +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeTx16Request + +#include "TxBase.h" +#include "IPayloadRequest.h" + +class XBeeTx16Request : public TxBase, public IPayloadRequest +{ + +public: + XBeeTx16Request(char frameID, Address * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length); + + virtual void setPayload(const char * data, int offset, int length); + + virtual void setTransmitOptions(OptionsBase * transmitOptions); + + /// <summary> + /// the ieee 64 bit address is ignored + /// </summary> + /// <param name="networkAddress"></param> + virtual void setRemoteAddress(Address * remoteAddress); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/XBeeTx64Request.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,25 @@ +#include "XBeeTx64Request.h" + +XBeeTx64Request::XBeeTx64Request(char frameID, Address * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length) + : TxBase(9 + length, APIFrame::Tx64_Request, frameID) +{ + sets(remoteAddress->getAddressValue(), 0, 8); + set(transmitOptions->getValue()); + sets(payload, offset, length); +} + +void XBeeTx64Request::setPayload(const char * data, int offset, int length) +{ + setPosition(11); + sets(data, offset, length); +} + +void XBeeTx64Request::setTransmitOptions(OptionsBase * transmitOptions) +{ + data[10] = transmitOptions->getValue(); +} + +void XBeeTx64Request::setRemoteAddress(Address * remoteAddress) +{ + sets(2, remoteAddress->getAddressValue(), 0, 8); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/XBeeTx64Request.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,24 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_XBeeTx64Request +#define UK_AC_HERTS_SMARTLAB_XBEE_XBeeTx64Request + +#include "TxBase.h" +#include "IPayloadRequest.h" + +class XBeeTx64Request : public TxBase, public IPayloadRequest +{ + +public: + XBeeTx64Request(char frameID, Address * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length); + + virtual void setPayload(const char * data, int offset, int length); + + virtual void setTransmitOptions(OptionsBase * transmitOptions); + + /// <summary> + /// the ieee 64 bit address is ignored + /// </summary> + /// <param name="networkAddress"></param> + virtual void setRemoteAddress(Address * remoteAddress); +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ZigBeeExplicitTxRequest.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,38 @@ +#include "ZigBeeExplicitTxRequest.h" + +ZigBeeExplicitTxRequest::ZigBeeExplicitTxRequest(char frameID, ExplicitAddress * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length) + : TxBase(18 + length, APIFrame::Explicit_Addressing_ZigBee_Command_Frame, frameID) +{ + sets(remoteAddress->getAddressValue(), 0, 10); + sets(remoteAddress->getExplicitValue(), 0, 6); + set(0x00); + set(transmitOptions->getValue()); + sets(payload, offset, length); +} + +void ZigBeeExplicitTxRequest::setBroadcastRadius(char broadcastRadius) +{ + data[18] = broadcastRadius; +} + +void ZigBeeExplicitTxRequest::setTransmitOptions(OptionsBase * transmitOptions) +{ + data[19] = transmitOptions->getValue(); +} + +void ZigBeeExplicitTxRequest::setPayload(const char * data, int offset, int length) +{ + setPosition(20); + sets(data, offset, length); +} + +void ZigBeeExplicitTxRequest::setRemoteAddress(Address * remoteAddress) +{ + sets(2, remoteAddress->getAddressValue(), 0, 10); +} + +void ZigBeeExplicitTxRequest::setRemoteAddress(ExplicitAddress * remoteAddress) +{ + sets(2, remoteAddress->getAddressValue(), 0, 10); + sets(12, remoteAddress->getExplicitValue(), 0, 6); +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ZigBeeExplicitTxRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,36 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeExplicitTxRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeExplicitTxRequest + +#include "TxBase.h" +#include "IPayloadRequest.h" +#include "ExplicitAddress.h" + +class ZigBeeExplicitTxRequest : public TxBase, public IPayloadRequest +{ + +public: + //0x11 + //FrameID; + //ExplicitRemoteDevice + //Source Endpoint + //Destination Endpoint + //Cluster ID + //Profile ID + //Broadcast_Radius; + //TransmitOptions; + //RF_Data; + ZigBeeExplicitTxRequest(char frameID, ExplicitAddress * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length); + + virtual void setPayload(const char * data, int offset, int length); + + virtual void setTransmitOptions(OptionsBase * transmitOptions); + + virtual void setRemoteAddress(Address * remoteAddress); + + void setRemoteAddress(ExplicitAddress * remoteAddress); + + void setBroadcastRadius(char broadcastRadius); + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ZigBeeTxRequest.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,32 @@ +#include "ZigBeeTxRequest.h" + +ZigBeeTxRequest::ZigBeeTxRequest(char frameID, Address * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length) + : TxBase(9 + length, APIFrame::ZigBee_Transmit_Request, frameID) +{ + sets(remoteAddress->getAddressValue(), 0, 10); + set(0x00); + set(transmitOptions->getValue()); + sets(payload, offset, length); +} + +void ZigBeeTxRequest::setPayload(const char * data, int offset, int length) +{ + setPosition(14); + sets(data, offset, length); +} + +void ZigBeeTxRequest::setTransmitOptions(OptionsBase * transmitOptions) +{ + data[13] = transmitOptions->getValue(); +} + +void ZigBeeTxRequest::setRemoteAddress(Address * remoteAddress) +{ + sets(2, remoteAddress->getAddressValue(), 0, 10); +} + + +void ZigBeeTxRequest::setBroadcastRadius(char broadcastRadius) +{ + data[12] = broadcastRadius; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Request/ZigBeeTxRequest.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,29 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeTxRequest +#define UK_AC_HERTS_SMARTLAB_XBEE_ZigBeeTxRequest + +#include "TxBase.h" +#include "IPayloadRequest.h" + +class ZigBeeTxRequest : public TxBase, public IPayloadRequest +{ + +public: + //0x10 + //FrameID; + //RemoteDevice + //Broadcast_Radius; + //TransmitOptions; + //RF_Data; + ZigBeeTxRequest(char frameID, Address * remoteAddress, OptionsBase * transmitOptions, const char * payload, int offset, int length); + + virtual void setPayload(const char * data, int offset, int length); + + virtual void setTransmitOptions(OptionsBase * transmitOptions); + + virtual void setRemoteAddress(Address * remoteAddress); + + void setBroadcastRadius(char broadcastRadius); + +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Type/ATCommands.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,15 @@ +#include "ATCommands.h" + +char * ATCommands::IO_Sampling_Rate = "IR"; + +char * ATCommands::Digital_IO_Change_Detection = "IC"; + +char * ATCommands::Instant_Sample = "IS"; + +char * ATCommands::Node_Descovery = "ND"; + +char * ATCommands::Destination_Node_Descovery = "DN"; + +char * ATCommands::Node_Identifier = "NI"; + +char * ATCommands::Node_Join_Time = "NJ"; \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Type/ATCommands.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,22 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_ATCommands +#define UK_AC_HERTS_SMARTLAB_XBEE_ATCommands + +class ATCommands +{ +public: + static char * IO_Sampling_Rate; + + static char * Digital_IO_Change_Detection; + + static char * Instant_Sample; + + static char * Node_Descovery; + + static char * Destination_Node_Descovery; + + static char * Node_Identifier; + + static char * Node_Join_Time; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Type/IOSamples.cpp Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,35 @@ +#include "IOSamples.h" + +map<Pin, int> * IOSamples::getAnalogs() +{ + return &analog; +} + +int IOSamples::getAnalog(Pin * pin) +{ + if (analog.count(*pin)) + return analog[*pin]; + else return -1; +} + +map<Pin, int> * IOSamples::getDigitals() +{ + return &digital; +} + +int IOSamples::getDigital(Pin * pin) +{ + if (digital.count(*pin)) + return digital[*pin]; + else return 2; +} + +int IOSamples::getSupplyVoltage() +{ + return SUPPLY_VOLTAGE; +} + +void IOSamples::setSupplyVoltage(int voltage) +{ + SUPPLY_VOLTAGE = voltage; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Type/IOSamples.h Thu Oct 22 12:28:26 2015 +0000 @@ -0,0 +1,40 @@ +#ifndef UK_AC_HERTS_SMARTLAB_XBEE_IOSamples +#define UK_AC_HERTS_SMARTLAB_XBEE_IOSamples + +#include "Pin.h" +#include <map> + +using namespace std; + +class IOSamples +{ +private : + int SUPPLY_VOLTAGE; + + map<Pin, int> analog; + + map<Pin, int> digital; + +public: + map<Pin, int> * getAnalogs(); + + /** + * -1 means not avaliable + */ + int getAnalog(Pin * pin); + + map<Pin, int> * getDigitals(); + + /** + * LOW = 0, + * HIGH = 1, + * UNMONITORED = 2, + */ + int getDigital(Pin * pin); + + int getSupplyVoltage(); + + void setSupplyVoltage(int voltage); +}; + +#endif \ No newline at end of file