[avr] add DOW CRC8 function and add the checksum to a ctrl message

This commit is contained in:
Bart Van Der Meerssche 2011-01-15 23:03:16 +01:00
parent 968e25c863
commit f74b124884
2 changed files with 23 additions and 1 deletions

View File

@ -20,6 +20,7 @@
// $Id$ // $Id$
#include <avr/eeprom.h> #include <avr/eeprom.h>
#include <util/crc16.h>
#include "global.h" #include "global.h"
#include "main.h" #include "main.h"
@ -204,9 +205,19 @@ void ctrlRxToTxLoop(void)
} }
} }
uint8_t ctrlCalcCrc8(cBuffer* buffer)
{
uint8_t i, crc = 0;
for (i = 0; i < buffer->datalength; i++) {
crc = _crc_ibutton_update(crc, bufferGetAtIndex(buffer, i));
}
return crc;
}
void ctrlDecode(void) void ctrlDecode(void)
{ {
uint8_t cmd[2]; uint8_t cmd[2], crc;
ctrlFlushTxBuffer(); ctrlFlushTxBuffer();
@ -231,6 +242,9 @@ void ctrlDecode(void)
ctrlAddToTxBuffer('z'); ctrlAddToTxBuffer('z');
} }
crc = ctrlCalcCrc8(&ctrlTxBuffer);
ctrlWriteCharToTxBuffer(crc);
ctrlAddToTxBuffer('.'); ctrlAddToTxBuffer('.');
} }

View File

@ -104,6 +104,14 @@ void ctrlFlushTxBuffer(void);
*/ */
void ctrlRxToTxLoop(void); void ctrlRxToTxLoop(void);
/**
* Calculate the CRC-8 checksum over the bytes in the buffer.
*
* @param buffer pointer to the buffer containing the data
* @return CRC-8 checksum
*/
uint8_t ctrlCalcCrc8(cBuffer* buffer);
/** /**
* Decode the message in the ctrl Rx buffer and dispatch to either ctrlCmdGet, * Decode the message in the ctrl Rx buffer and dispatch to either ctrlCmdGet,
* ctrlCmdSet or ctrlCmdCommit. * ctrlCmdSet or ctrlCmdCommit.