simplified message handling, switch from XOR checksum to CRC8 with polynomial 0x97.

0x97 allows for detection of all 1-3 bit errors in a message of up to
119 bytes
(see https://www.faa.gov/aircraft/air_cert/design_approvals/air_software/media/TC-14-49.pdf)
This commit is contained in:
Martin Preuss
2023-04-07 23:22:40 +02:00
parent 4e1f08b567
commit 7eb462173c
33 changed files with 281 additions and 367 deletions

View File

@@ -22,6 +22,7 @@
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6
#define AQH_MSG_OFFS_SENDSTATS_ABORTED 8
#define AQH_MSG_OFFS_SENDSTATS_NOBUFFER 10
#define AQH_MSG_SENDSTATS_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED+2)
@@ -29,56 +30,35 @@
uint32_t AQH_SendStatsMsg_GetUid(const GWEN_MSG *msg)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_UID;
return (uint32_t)(ptr[0])+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24);
}
return 0;
return AQH_NodeMsg_GetUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_UID, 0);
}
uint16_t AQH_SendStatsMsg_GetPacketsOut(const GWEN_MSG *msg)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_PACKETSOUT;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return 0;
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_PACKETSOUT, 0);
}
uint16_t AQH_SendStatsMsg_GetCollisions(const GWEN_MSG *msg)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_COLLISIONS;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return 0;
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_COLLISIONS, 0);
}
uint16_t AQH_SendStatsMsg_GetAborted(const GWEN_MSG *msg)
{
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
const uint8_t *ptr;
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED, 0);
}
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_ABORTED;
return (uint16_t)(ptr[0])+(ptr[1]<<8);
}
return 0;
uint16_t AQH_SendStatsMsg_GetNoBufferErrors(const GWEN_MSG *msg)
{
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_NOBUFFER, 0);
}
@@ -88,14 +68,15 @@ void AQH_SendStatsMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const
if ((AQH_NodeMsg_GetMsgType(msg)==AQH_MSG_TYPE_COMSENDSTATS) &&
(GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_SENDSTATS_MINSIZE)) {
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, aborted=%d)\n",
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, aborted=%d, no buffer=%d)\n",
AQH_NodeMsg_GetSourceAddress(msg),
AQH_NodeMsg_GetDestAddress(msg),
sText,
(unsigned int) AQH_SendStatsMsg_GetUid(msg),
AQH_SendStatsMsg_GetPacketsOut(msg),
AQH_SendStatsMsg_GetCollisions(msg),
AQH_SendStatsMsg_GetAborted(msg));
AQH_SendStatsMsg_GetAborted(msg),
AQH_SendStatsMsg_GetNoBufferErrors(msg));
}
}