From f56cc998f6010b378cb55bbc098b25f621189bdb Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Mon, 30 Nov 2015 20:17:14 -0200
Subject: [PATCH] Added parity check and calc

---
 Protocol.cpp | 23 +++++++++++++++++++++--
 Protocol.h   |  5 ++++-
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/Protocol.cpp b/Protocol.cpp
index 146b712..cb2fd14 100644
--- a/Protocol.cpp
+++ b/Protocol.cpp
@@ -9,6 +9,25 @@ void Protocol::setMessage(Message message){
     this->message = message;
 }
 
+bool Protocol::send(int socket) {
+    return true;
+}
+
+char Protocol::calcParity() {
+    char parity = 0x00;
+    char *m = this->message.c_ctrl.begin + this->message.c_ctrl.size + this->message.c_ctrl.seqType + (&data[0]);
+    for(int i=0; i < strlen(m); ++i) {
+        parity = parity^m[i];
+    }
+    this->message.c_ctrl.parity = parity;
+    return parity;
+}
+
+bool Protocol::checkParity() {
+    char parity = this->calcParity();
+    return (parity == this->message.c_ctrl.parity);
+}
+
 Protocol::Protocol(){
-    message.begin = 0x7E;
-}
\ No newline at end of file
+    this->message.c_ctrl.begin = 0x7E;
+}
diff --git a/Protocol.h b/Protocol.h
index e361922..adcc994 100644
--- a/Protocol.h
+++ b/Protocol.h
@@ -11,7 +11,10 @@ public:
 
     Message getMessage();
     void setMessage(Message message);
+    bool send(int socket);
+    char calcParity();
+    bool checkParity();
 
     Protocol();
 };
-#endif
\ No newline at end of file
+#endif
-- 
GitLab