reworked com stack.
- prepared for use of CRC8 - organized code in more files - recv stats message now contains crc errors and io errors
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
|
||||
static uint8_t _calcChecksum(const uint8_t *ptr, uint8_t len);
|
||||
static uint8_t _calcXorChecksum(const uint8_t *ptr, uint8_t len);
|
||||
|
||||
|
||||
|
||||
@@ -105,7 +105,7 @@ int AQH_NodeMsg_IsMsgComplete(const GWEN_MSG *msg)
|
||||
int AQH_NodeMsg_IsChecksumValid(const GWEN_MSG *msg)
|
||||
{
|
||||
if (msg && AQH_NodeMsg_IsMsgComplete(msg))
|
||||
return (_calcChecksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg))==0)?1:0;
|
||||
return (_calcXorChecksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg))==0)?1:0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ int AQH_NodeMsg_AddChecksum(GWEN_MSG *msg)
|
||||
if (msg) {
|
||||
int rv;
|
||||
|
||||
rv=GWEN_Msg_AddByte(msg, _calcChecksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg)));
|
||||
rv=GWEN_Msg_AddByte(msg, _calcXorChecksum(GWEN_Msg_GetConstBuffer(msg), GWEN_Msg_GetBytesInBuffer(msg)));
|
||||
if (rv<0) {
|
||||
DBG_INFO(NULL, "here (%d)", rv);
|
||||
return rv;
|
||||
@@ -171,7 +171,7 @@ uint32_t AQH_NodeMsg_GetMsgGroup(uint8_t msgType)
|
||||
|
||||
|
||||
|
||||
uint8_t _calcChecksum(const uint8_t *ptr, uint8_t len)
|
||||
uint8_t _calcXorChecksum(const uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
int i;
|
||||
uint8_t x=0;
|
||||
@@ -185,4 +185,26 @@ uint8_t _calcChecksum(const uint8_t *ptr, uint8_t len)
|
||||
|
||||
|
||||
|
||||
uint8_t _calcCrc8Checksum(const uint8_t *ptr, uint8_t len)
|
||||
{
|
||||
int i;
|
||||
uint8_t x=0xff;
|
||||
|
||||
for (i=0; i<len; i++, ptr++) {
|
||||
int j;
|
||||
|
||||
x^=*ptr;
|
||||
for (j=0; j<8; j++) {
|
||||
if (x & 0x80)
|
||||
x=(uint8_t) (x<<1)^0x97;
|
||||
else
|
||||
x<<=1;
|
||||
}
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user