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:
@@ -18,82 +18,47 @@
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
|
||||
#define AQH_MSG_OFFS_DEVICE_UID 0 /* 4 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWTYPE 4 /* 2 bytes */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWLOW 6 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_FWHIGH 7 /* 1 byte */
|
||||
#define AQH_MSG_OFFS_DEVICE_MODULES 8 /* 2 byte */
|
||||
|
||||
#define AQH_MSG_DEVICE_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULES+2)
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_DeviceMsg_GetUid(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_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_DEVICE_UID, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint16_t AQH_DeviceMsg_GetFirmwareType(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWTYPE;
|
||||
return (uint16_t)((ptr[0])+(ptr[1]<<8));
|
||||
}
|
||||
return 0;
|
||||
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWTYPE, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetFirmwareLow(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWLOW;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
return AQH_NodeMsg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWLOW, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetFirmwareHigh(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWHIGH;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
return AQH_NodeMsg_GetUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWHIGH, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetModuleMaskLow(const GWEN_MSG *msg)
|
||||
uint16_t AQH_DeviceMsg_GetModuleMask(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULESLOW;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_DeviceMsg_GetModuleMaskHigh(const GWEN_MSG *msg)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
const uint8_t *ptr;
|
||||
|
||||
ptr=GWEN_Msg_GetConstBuffer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULESHIGH;
|
||||
return ptr[0];
|
||||
}
|
||||
return 0;
|
||||
return AQH_NodeMsg_GetUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MODULES, 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +68,7 @@ void AQH_DeviceMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const ch
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSG_DEVICE_MINSIZE) {
|
||||
uint16_t modules;
|
||||
|
||||
modules=(AQH_DeviceMsg_GetModuleMaskHigh(msg)<<8) | AQH_DeviceMsg_GetModuleMaskLow(msg);
|
||||
modules=AQH_DeviceMsg_GetModuleMask(msg);
|
||||
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: DEVICE %s (uid=0x%08x, fw type=%d, fw ver=%d.%d, mods=0x%04x",
|
||||
AQH_NodeMsg_GetSourceAddress(msg),
|
||||
AQH_NodeMsg_GetDestAddress(msg),
|
||||
|
||||
Reference in New Issue
Block a user