diff --git a/Protocol.cpp b/Protocol.cpp index 146b712f302a1343e162fa56aad749db12eb3daf..cb2fd145f95bcff4fc484fd878beec25b6df6d96 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 e361922f0e2f21ab896e7b90b6d3738fa6be00f1..adcc99425e29dc545298746f5871a209636bdca0 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