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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
|
||||
#define AQH_MSG_OFFS_RECVSTATS_UID 0
|
||||
#define AQH_MSG_OFFS_RECVSTATS_PACKETSIN 4
|
||||
#define AQH_MSG_OFFS_RECVSTATS_ERRORS 6
|
||||
#define AQH_MSG_OFFS_RECVSTATS_HANDLED 8
|
||||
#define AQH_MSG_OFFS_RECVSTATS_CRCERRORS 6
|
||||
#define AQH_MSG_OFFS_RECVSTATS_IOERRORS 8
|
||||
|
||||
#define AQH_MSG_RECVSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED+2)
|
||||
#define AQH_MSG_RECVSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_IOERRORS+2)
|
||||
|
||||
|
||||
|
||||
@@ -54,12 +54,12 @@ uint16_t AQH_RecvStatsMsg_GetPacketsIn(const GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_RecvStatsMsg_GetErrors(const GWEN_MSG *msg)
|
||||
uint16_t AQH_RecvStatsMsg_GetCrcErrors(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_ERRORS;
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_CRCERRORS;
|
||||
return (uint16_t)(ptr[0])+(ptr[1]<<8);
|
||||
}
|
||||
return 0;
|
||||
@@ -67,12 +67,12 @@ uint16_t AQH_RecvStatsMsg_GetErrors(const GWEN_MSG *msg)
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_RecvStatsMsg_GetHandled(const GWEN_MSG *msg)
|
||||
uint16_t AQH_RecvStatsMsg_GetIoErrors(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED;
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_IOERRORS;
|
||||
return (uint16_t)(ptr[0])+(ptr[1]<<8);
|
||||
}
|
||||
return 0;
|
||||
@@ -85,14 +85,14 @@ void AQH_RecvStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const
|
||||
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMRECVSTATS) &&
|
||||
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_RECVSTATS_MINSIZE)) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"0x%02x->0x%02x: RECVSTATS %s (uid=0x%08x, in=%d, errors=%d, handled=%d)\n",
|
||||
"0x%02x->0x%02x: RECVSTATS %s (uid=0x%08x, in=%d, crc errors=%d, io errors=%d)\n",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
sText,
|
||||
(unsigned int) AQH_RecvStatsMsg_GetUid(msg),
|
||||
AQH_RecvStatsMsg_GetPacketsIn(msg),
|
||||
AQH_RecvStatsMsg_GetErrors(msg),
|
||||
AQH_RecvStatsMsg_GetHandled(msg));
|
||||
AQH_RecvStatsMsg_GetCrcErrors(msg),
|
||||
AQH_RecvStatsMsg_GetIoErrors(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
AQHOME_API uint32_t AQH_RecvStatsMsg_GetUid(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetPacketsIn(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetErrors(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetHandled(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetCrcErrors(const GWEN_MSG *msg);
|
||||
AQHOME_API uint16_t AQH_RecvStatsMsg_GetIoErrors(const GWEN_MSG *msg);
|
||||
|
||||
|
||||
AQHOME_API void AQH_RecvStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
Reference in New Issue
Block a user