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@6:5f31ddc17239, 2015-11-14 (annotated)
- Committer:
- yangcq88517
- Date:
- Sat Nov 14 16:42:36 2015 +0000
- Revision:
- 6:5f31ddc17239
- Parent:
- 3:6b205ec8624b
change to unsigned char array
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yangcq88517 | 0:837e6c48e90d | 1 | #include "APIFrame.h" |
yangcq88517 | 0:837e6c48e90d | 2 | |
yangcq88517 | 6:5f31ddc17239 | 3 | APIFrame::APIFrame(unsigned int payloadLength) |
yangcq88517 | 6:5f31ddc17239 | 4 | :BufferedArray(payloadLength, 10) |
yangcq88517 | 0:837e6c48e90d | 5 | {} |
yangcq88517 | 0:837e6c48e90d | 6 | |
yangcq88517 | 0:837e6c48e90d | 7 | APIFrame::APIFrame(APIFrame * frame) |
yangcq88517 | 0:837e6c48e90d | 8 | :BufferedArray(frame) |
yangcq88517 | 0:837e6c48e90d | 9 | { |
yangcq88517 | 1:3dc0ec2f9fd6 | 10 | if (frame != NULL) { |
yangcq88517 | 1:3dc0ec2f9fd6 | 11 | this->checkSum = frame->checkSum; |
yangcq88517 | 1:3dc0ec2f9fd6 | 12 | this->isVerify = frame->isVerify; |
yangcq88517 | 1:3dc0ec2f9fd6 | 13 | } |
yangcq88517 | 0:837e6c48e90d | 14 | } |
yangcq88517 | 0:837e6c48e90d | 15 | |
yangcq88517 | 6:5f31ddc17239 | 16 | unsigned char APIFrame::getFrameType() |
yangcq88517 | 0:837e6c48e90d | 17 | { |
yangcq88517 | 0:837e6c48e90d | 18 | return data[0]; |
yangcq88517 | 0:837e6c48e90d | 19 | } |
yangcq88517 | 0:837e6c48e90d | 20 | |
yangcq88517 | 6:5f31ddc17239 | 21 | void APIFrame::setFrameType(unsigned char identifier) |
yangcq88517 | 1:3dc0ec2f9fd6 | 22 | { |
yangcq88517 | 1:3dc0ec2f9fd6 | 23 | data[0] = identifier; |
yangcq88517 | 1:3dc0ec2f9fd6 | 24 | } |
yangcq88517 | 0:837e6c48e90d | 25 | |
yangcq88517 | 6:5f31ddc17239 | 26 | void APIFrame::allocate(unsigned long length) |
yangcq88517 | 0:837e6c48e90d | 27 | { |
yangcq88517 | 0:837e6c48e90d | 28 | BufferedArray::allocate(length); |
yangcq88517 | 0:837e6c48e90d | 29 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 30 | } |
yangcq88517 | 0:837e6c48e90d | 31 | |
yangcq88517 | 0:837e6c48e90d | 32 | void APIFrame::rewind() |
yangcq88517 | 0:837e6c48e90d | 33 | { |
yangcq88517 | 0:837e6c48e90d | 34 | BufferedArray::rewind(); |
yangcq88517 | 0:837e6c48e90d | 35 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 36 | } |
yangcq88517 | 0:837e6c48e90d | 37 | |
yangcq88517 | 0:837e6c48e90d | 38 | bool APIFrame::convert(APIFrame * frame) |
yangcq88517 | 0:837e6c48e90d | 39 | { |
yangcq88517 | 0:837e6c48e90d | 40 | if (frame == NULL) |
yangcq88517 | 0:837e6c48e90d | 41 | return false; |
yangcq88517 | 0:837e6c48e90d | 42 | |
yangcq88517 | 0:837e6c48e90d | 43 | this->data = frame->data; |
yangcq88517 | 0:837e6c48e90d | 44 | this->index = frame->index; |
yangcq88517 | 0:837e6c48e90d | 45 | this->max = frame->max; |
yangcq88517 | 0:837e6c48e90d | 46 | this->checkSum = frame->checkSum; |
yangcq88517 | 0:837e6c48e90d | 47 | this->isVerify = frame->isVerify; |
yangcq88517 | 0:837e6c48e90d | 48 | return true; |
yangcq88517 | 0:837e6c48e90d | 49 | } |
yangcq88517 | 0:837e6c48e90d | 50 | |
yangcq88517 | 6:5f31ddc17239 | 51 | void APIFrame::set(unsigned char value) |
yangcq88517 | 0:837e6c48e90d | 52 | { |
yangcq88517 | 0:837e6c48e90d | 53 | BufferedArray::set(value); |
yangcq88517 | 0:837e6c48e90d | 54 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 55 | } |
yangcq88517 | 0:837e6c48e90d | 56 | |
yangcq88517 | 6:5f31ddc17239 | 57 | void APIFrame::sets(const unsigned char * value, unsigned long offset, unsigned long length) |
yangcq88517 | 0:837e6c48e90d | 58 | { |
yangcq88517 | 0:837e6c48e90d | 59 | BufferedArray::sets(value, offset, length); |
yangcq88517 | 0:837e6c48e90d | 60 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 61 | } |
yangcq88517 | 0:837e6c48e90d | 62 | |
yangcq88517 | 6:5f31ddc17239 | 63 | void APIFrame::set(unsigned long position, unsigned char value) |
yangcq88517 | 0:837e6c48e90d | 64 | { |
yangcq88517 | 0:837e6c48e90d | 65 | BufferedArray::set(position, value); |
yangcq88517 | 0:837e6c48e90d | 66 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 67 | } |
yangcq88517 | 0:837e6c48e90d | 68 | |
yangcq88517 | 6:5f31ddc17239 | 69 | void APIFrame::sets(unsigned long position, const unsigned char * value, unsigned long offset, unsigned long length) |
yangcq88517 | 0:837e6c48e90d | 70 | { |
yangcq88517 | 0:837e6c48e90d | 71 | BufferedArray::sets(position, value, offset, length); |
yangcq88517 | 0:837e6c48e90d | 72 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 73 | } |
yangcq88517 | 0:837e6c48e90d | 74 | |
yangcq88517 | 0:837e6c48e90d | 75 | char APIFrame::getCheckSum() |
yangcq88517 | 0:837e6c48e90d | 76 | { |
yangcq88517 | 0:837e6c48e90d | 77 | return checkSum; |
yangcq88517 | 0:837e6c48e90d | 78 | } |
yangcq88517 | 0:837e6c48e90d | 79 | |
yangcq88517 | 6:5f31ddc17239 | 80 | void APIFrame::setCheckSum(unsigned char value) |
yangcq88517 | 0:837e6c48e90d | 81 | { |
yangcq88517 | 0:837e6c48e90d | 82 | checkSum = value; |
yangcq88517 | 0:837e6c48e90d | 83 | } |
yangcq88517 | 0:837e6c48e90d | 84 | |
yangcq88517 | 0:837e6c48e90d | 85 | bool APIFrame::verifyChecksum() |
yangcq88517 | 0:837e6c48e90d | 86 | { |
yangcq88517 | 0:837e6c48e90d | 87 | if (isVerify) |
yangcq88517 | 0:837e6c48e90d | 88 | return true; |
yangcq88517 | 0:837e6c48e90d | 89 | |
yangcq88517 | 0:837e6c48e90d | 90 | char temp = 0x00; |
yangcq88517 | 0:837e6c48e90d | 91 | for (int i = 0; i < index; i++) |
yangcq88517 | 0:837e6c48e90d | 92 | temp += data[i]; |
yangcq88517 | 0:837e6c48e90d | 93 | if (temp + checkSum == 0xFF) |
yangcq88517 | 0:837e6c48e90d | 94 | isVerify = true; |
yangcq88517 | 0:837e6c48e90d | 95 | else |
yangcq88517 | 0:837e6c48e90d | 96 | isVerify = false; |
yangcq88517 | 0:837e6c48e90d | 97 | |
yangcq88517 | 0:837e6c48e90d | 98 | return isVerify; |
yangcq88517 | 0:837e6c48e90d | 99 | } |
yangcq88517 | 0:837e6c48e90d | 100 | |
yangcq88517 | 0:837e6c48e90d | 101 | void APIFrame::calculateChecksum() |
yangcq88517 | 0:837e6c48e90d | 102 | { |
yangcq88517 | 0:837e6c48e90d | 103 | if (isVerify) |
yangcq88517 | 0:837e6c48e90d | 104 | return; |
yangcq88517 | 0:837e6c48e90d | 105 | |
yangcq88517 | 0:837e6c48e90d | 106 | char CS = 0x00; |
yangcq88517 | 0:837e6c48e90d | 107 | for (int i = 0; i < index; i++) |
yangcq88517 | 0:837e6c48e90d | 108 | CS += data[i]; |
yangcq88517 | 0:837e6c48e90d | 109 | checkSum = 0xFF - CS; |
yangcq88517 | 0:837e6c48e90d | 110 | isVerify = true; |
yangcq88517 | 0:837e6c48e90d | 111 | } |