[avr] add DOW CRC8 function and add the checksum to a ctrl message
This commit is contained in:
parent
968e25c863
commit
f74b124884
|
@ -20,6 +20,7 @@
|
|||
// $Id$
|
||||
|
||||
#include <avr/eeprom.h>
|
||||
#include <util/crc16.h>
|
||||
|
||||
#include "global.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)
|
||||
{
|
||||
uint8_t cmd[2];
|
||||
uint8_t cmd[2], crc;
|
||||
|
||||
ctrlFlushTxBuffer();
|
||||
|
||||
|
@ -231,6 +242,9 @@ void ctrlDecode(void)
|
|||
ctrlAddToTxBuffer('z');
|
||||
}
|
||||
|
||||
crc = ctrlCalcCrc8(&ctrlTxBuffer);
|
||||
ctrlWriteCharToTxBuffer(crc);
|
||||
|
||||
ctrlAddToTxBuffer('.');
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,14 @@ void ctrlFlushTxBuffer(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,
|
||||
* ctrlCmdSet or ctrlCmdCommit.
|
||||
|
|
Loading…
Reference in New Issue