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.
Core/APIFrame.cpp
- Committer:
- yangcq88517
- Date:
- 2015-10-22
- Revision:
- 1:3dc0ec2f9fd6
- Parent:
- 0:837e6c48e90d
- Child:
- 3:6b205ec8624b
File content as of revision 1:3dc0ec2f9fd6:
#include "APIFrame.h" APIFrame::APIFrame(int payloadLength) :BufferedArray(payloadLength) {} APIFrame::APIFrame(APIFrame * frame) :BufferedArray(frame) { if (frame != NULL) { this->checkSum = frame->checkSum; this->isVerify = frame->isVerify; } } char APIFrame::getFrameType() { return data[0]; } void APIFrame::setFrameType(char identifier) { data[0] = 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; }