Skip to content
Snippets Groups Projects
Commit f56cc998 authored by Vytor Calixto's avatar Vytor Calixto :space_invader:
Browse files

Added parity check and calc

parent 7b37afdd
No related branches found
No related tags found
1 merge request!1Lento
......@@ -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;
this->message.c_ctrl.begin = 0x7E;
}
......@@ -11,6 +11,9 @@ public:
Message getMessage();
void setMessage(Message message);
bool send(int socket);
char calcParity();
bool checkParity();
Protocol();
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment