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.

Dependencies:   BufferedArray

Dependents:   MBEDminiproject

Revision:
0:837e6c48e90d
Child:
1:3dc0ec2f9fd6
--- /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