Changeset - 4b4d7ead8c5a
[Not reviewed]
default
0 1 0
mkanning@CL-SEC241-09.cedarville.edu - 13 years ago 2012-10-25 22:23:40
mkanning@CL-SEC241-09.cedarville.edu
added checksum calculations to parser
1 file changed with 7 insertions and 2 deletions:
0 comments (0 inline, 0 general)
master/master/lib/serparser.c
Show inline comments
 
@@ -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;
 
			}
 
 
		}
0 comments (0 inline, 0 general)