# HG changeset patch # User mkanning@CL-SEC241-09.cedarville.edu # Date 2012-10-25 22:23:40 # Node ID 4b4d7ead8c5aedeb48a9b3d851120e2e25bda115 # Parent 1e2b7cbcf224a676dfcdaf2d0c03f5c415684e9e added checksum calculations to parser 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 @@ -39,6 +39,9 @@ char data[16]; //ID of the sensor of most recent transmission char sensorID; +//checksum to be calculated and then compared to the received checksum +char checksumCalc; + /* return char from UART (h/w buffer) */ uint8_t uart_getchar(void) { @@ -52,8 +55,6 @@ uint8_t uart_getchar(void) return 0; } - - /* Process incoming serial data */ int uart_Parser(void) { @@ -84,6 +85,7 @@ int uart_Parser(void) if(byte == MODULE_ID) //this transmission is intended for the master; continue parsing { bufferPosition++; + checksumCalc += byte; dataLength = 0; //reset dataLength here to protect from bad inputs } else //this transmission is intended for another module; stop parsing and reset @@ -95,6 +97,7 @@ int uart_Parser(void) { sensorID = byte; //store the type of data receiving bufferPosition++; + checksumCalc += byte; } else if (bufferPosition == MAX_CMD_LEN) //command is too long and bad data has been recieved; reset { @@ -110,6 +113,8 @@ int uart_Parser(void) { data[dataLength] = byte; dataLength++; + bufferPosition++; + checksumCalc += byte; } }