diff --git a/master/master/lib/serial.c b/master/master/lib/serial.c --- a/master/master/lib/serial.c +++ b/master/master/lib/serial.c @@ -116,8 +116,9 @@ void serial_sendCommand( char moduleID, data++; } - serial0_sendChar(checkSum); + serial0_sendChar(']'); //bracket indicates end of command + serial0_sendChar(checkSum); // checksum moved behind bracket to solve bug FS#29 } void serial_sendResponseData() diff --git a/master/master/lib/serparser.c b/master/master/lib/serparser.c --- a/master/master/lib/serparser.c +++ b/master/master/lib/serparser.c @@ -149,19 +149,11 @@ int serparser_parse(void) sprintf(buffmeh, "recvd %d bytes data\r\n", dataLength); serial0_sendString((buffmeh)); #endif - if(bufferParsePosition == bufferDataPosition) - { - // We are at the end of the line. No more data to parse. - setParserState(STATE_RESET); - return PARSERESULT_PARSEOK; - } - else - { - setParserState(STATE_RESET); - // we could choose to keep parsing now, or parse the next message next loop around (better idea). - // return now so we hit it the next time around - return PARSERESULT_PARSEOK; - } + + setParserState(STATE_GETCHECKSUM); + // Checksum is now after the close bracket to solve bug FS#29 + + } else // Still receiving data { @@ -189,6 +181,29 @@ int serparser_parse(void) } } + else if(STATE_GETCHECKSUM) + { + // TODO: Compare checksums + if(byte == checksumCalc) { + serial0_sendString("checksum ok\r\n"); + } + else { + serial0_sendString("checksum fail\r\n"); + } + if(bufferParsePosition == bufferDataPosition) + { + // We are at the end of the line. No more data to parse. + setParserState(STATE_RESET); + return PARSERESULT_PARSEOK; + } + else + { + setParserState(STATE_RESET); + // we could choose to keep parsing now, or parse the next message next loop around (better idea). + // return now so we hit it the next time around + return PARSERESULT_PARSEOK; + } + } } return PARSERESULT_NODATA; diff --git a/master/master/lib/serparser.h b/master/master/lib/serparser.h --- a/master/master/lib/serparser.h +++ b/master/master/lib/serparser.h @@ -28,7 +28,8 @@ enum parseStates STATE_RESET = 0, STATE_GETID, STATE_GETDATATYPE, - STATE_GETDATA + STATE_GETDATA, + STATE_GETCHECKSUM, }; // Prototypes