aqhome: started rewriting message code, start using new event2 lib.

This commit is contained in:
Martin Preuss
2025-02-25 01:13:07 +01:00
parent f1f24168e5
commit cf8edbbd5f
58 changed files with 5393 additions and 163 deletions

84
aqhome/msg/node/0BUILD Normal file
View File

@@ -0,0 +1,84 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhmsg_node" >
<includes type="c" >
$(gwenhywfar_cflags)
-I$(topsrcdir)
-I$(topbuilddir)
</includes>
<includes type="tm2" >
--include=$(builddir)
--include=$(srcdir)
</includes>
<define name="BUILDING_AQHOME" />
<setVar name="local/cflags">$(visibility_cflags)</setVar>
<setVar name="tm2flags" >
--api=AQHOME_API
</setVar>
<setVar name="local/typefiles" >
</setVar>
<setVar name="local/built_sources" >
</setVar>
<setVar name="local/built_headers_pub">
</setVar>
<setVar name="local/built_headers_priv" >
</setVar>
<headers dist="false" install="$(pkgincludedir)/msg" >
$(local/built_headers_pub)
</headers>
<headers dist="true" install="$(pkgincludedir)/msg" >
m_node.h
m_device.h
m_recvstats.h
m_sendstats.h
</headers>
<headers dist="true" >
</headers>
<sources>
$(local/typefiles)
m_node.c
m_device.c
m_recvstats.c
m_sendstats.c
</sources>
<extradist>
</extradist>
<useTargets>
</useTargets>
<subdirs>
</subdirs>
</target>
</gwbuild>

186
aqhome/msg/node/m_device.c Normal file
View File

@@ -0,0 +1,186 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "aqhome/msg/node/m_device.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <ctype.h>
#define AQH_MSG_OFFS_DEVICE_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_DEVICE_MANUF 4 /* 4 bytes */
#define AQH_MSG_OFFS_DEVICE_DEVTYPE 8 /* 2 bytes */
#define AQH_MSG_OFFS_DEVICE_DEVVERSION 10 /* 1 byte */
#define AQH_MSG_OFFS_DEVICE_DEVREVISION 11 /* 1 byte */
#define AQH_MSG_OFFS_DEVICE_FWVARIANT 12 /* 1 byte */
#define AQH_MSG_OFFS_DEVICE_FWVMAJOR 13 /* 1 byte */
#define AQH_MSG_OFFS_DEVICE_FWVMINOR 14 /* 1 byte */
#define AQH_MSG_OFFS_DEVICE_FWVPATCH 15 /* 1 byte */
static void _addDeviceId(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf);
static int _isAllGraphic(uint32_t value, int len);
static void _printChars(uint32_t value, int len, GWEN_BUFFER *dbuf);
uint32_t AQH_DeviceMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_UID, 0);
}
uint32_t AQH_DeviceMessage_GetManufacturer(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_MANUF, 0);
}
uint16_t AQH_DeviceMessage_GetDeviceType(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVTYPE, 0);
}
uint8_t AQH_DeviceMessage_GetDeviceVersion(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVVERSION, 0);
}
uint8_t AQH_DeviceMessage_GetDeviceRevision(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_DEVREVISION, 0);
}
uint8_t AQH_DeviceMessage_GetFirmwareVariant(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVARIANT, 0);
}
uint8_t AQH_DeviceMessage_GetFirmwareVersionMajor(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMAJOR, 0);
}
uint8_t AQH_DeviceMessage_GetFirmwareVersionMinor(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVMINOR, 0);
}
uint8_t AQH_DeviceMessage_GetFirmwareVersionPatchlevel(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_DEVICE_FWVPATCH, 0);
}
void AQH_DeviceMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (msg) {
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: DEVICE %s (uid=0x%08x, dev=%08x:%04x v%d.%d (",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sText,
(unsigned int) AQH_DeviceMessage_GetUid(msg),
AQH_DeviceMessage_GetManufacturer(msg),
AQH_DeviceMessage_GetDeviceType(msg),
AQH_DeviceMessage_GetDeviceVersion(msg),
AQH_DeviceMessage_GetDeviceRevision(msg));
_addDeviceId(msg, dbuf);
GWEN_Buffer_AppendArgs(dbuf,
"), fw=%d.%d.%d (%d))\n",
AQH_DeviceMessage_GetFirmwareVersionMajor(msg),
AQH_DeviceMessage_GetFirmwareVersionMinor(msg),
AQH_DeviceMessage_GetFirmwareVersionPatchlevel(msg),
AQH_DeviceMessage_GetFirmwareVariant(msg));
}
}
void _addDeviceId(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf)
{
uint32_t v;
v=AQH_DeviceMessage_GetManufacturer(msg);
if (_isAllGraphic(v, 4))
_printChars(v, 4, dbuf);
else
GWEN_Buffer_AppendArgs(dbuf, "%08x", v);
GWEN_Buffer_AppendByte(dbuf, ' ');
v=AQH_DeviceMessage_GetDeviceType(msg);
if (_isAllGraphic(v, 2)) {
_printChars(v, 2, dbuf);
GWEN_Buffer_AppendArgs(dbuf, "%d", AQH_DeviceMessage_GetDeviceVersion(msg));
}
else {
GWEN_Buffer_AppendArgs(dbuf, "%04x", v);
GWEN_Buffer_AppendArgs(dbuf, " v%d", AQH_DeviceMessage_GetDeviceVersion(msg));
}
}
int _isAllGraphic(uint32_t value, int len)
{
int i;
for (i=0; i<len; i++) {
uint8_t v;
v=value & 0xff;
if (!(isgraph(v) || isblank(v) || v==0))
return 0;
value=value>>8;
}
return 1;
}
void _printChars(uint32_t value, int len, GWEN_BUFFER *dbuf)
{
int i;
for (i=0; i<len; i++) {
uint8_t v;
v=value&0xff;
if (isgraph(v))
GWEN_Buffer_AppendByte(dbuf, v);
value=value>>8;
}
}

View File

@@ -0,0 +1,42 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_M_DEVICE_H
#define AQH_M_DEVICE_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_DeviceMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_DeviceMessage_GetManufacturer(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_DeviceMessage_GetDeviceType(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_DeviceMessage_GetDeviceVersion(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_DeviceMessage_GetDeviceRevision(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVariant(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVersionMajor(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVersionMinor(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_DeviceMessage_GetFirmwareVersionPatchlevel(const AQH_MESSAGE *msg);
AQHOME_API void AQH_DeviceMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

262
aqhome/msg/node/m_node.c Normal file
View File

@@ -0,0 +1,262 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/text.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static uint8_t _calcCrc8Checksum(const uint8_t *ptr, uint8_t len);
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_NodeMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen, const uint8_t *payload)
{
AQH_MESSAGE *msg;
uint8_t *ptr;
uint32_t len;
len=AQH_MSG_OFFS_ALL_DATA_BEGIN+payloadLen+1; /* dest, len, code, src, payload, crc8 */
msg=AQH_Message_new();
AQH_Message_SetData(msg, NULL, len); /* auto-malloc len bytes */
ptr=AQH_Message_GetMsgPointer(msg);
ptr[AQH_MSG_OFFS_ALL_DEST_ADDRESS]=destAddr & 0xff;
ptr[AQH_MSG_OFFS_ALL_PAYLOAD_LEN]=payloadLen+2; /* code, src, payload */
ptr[AQH_MSG_OFFS_ALL_MSG_TYPE]=code;
ptr[AQH_MSG_OFFS_ALL_SRC_ADDRESS]=srcAddr;
if (payloadLen && payload)
memmove(ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN, payload, payloadLen);
AQH_Message_SetUsedSize(msg, len);
AQH_NodeMessage_AddChecksum(msg);
return msg;
}
AQH_MESSAGE *AQH_NodeMessage_fromBuffer(const uint8_t *ptr, uint32_t len)
{
if (ptr && len) {
AQH_MESSAGE *msg;
msg=AQH_Message_new();
AQH_Message_SetData(msg, ptr, len);
AQH_Message_SetUsedSize(msg, len);
return msg;
}
return NULL;
}
uint8_t AQH_NodeMessage_GetDestAddress(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DEST_ADDRESS, 0);
}
uint8_t AQH_NodeMessage_GetMsgType(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_MSG_TYPE, 0);
}
uint8_t AQH_NodeMessage_GetSourceAddress(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_SRC_ADDRESS, 0);
}
uint8_t AQH_NodeMessage_GetPayloadLength(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_PAYLOAD_LEN, 2)-2; /* minus src addr, command */
}
uint8_t *AQH_NodeMessage_GetPayloadPointer(const AQH_MESSAGE *msg)
{
return msg?(AQH_Message_GetMsgPointer(msg)+AQH_MSG_OFFS_ALL_DATA_BEGIN):NULL;
}
void AQH_NodeMessage_AddChecksum(AQH_MESSAGE *msg)
{
if (msg) {
uint8_t *ptr;
uint32_t msgLenWithoutChecksum;
uint8_t checksum;
ptr=AQH_Message_GetMsgPointer(msg);
msgLenWithoutChecksum=AQH_Message_GetUsedSize(msg);
checksum=_calcCrc8Checksum(ptr, msgLenWithoutChecksum);
AQH_Message_WriteUint8At(msg, msgLenWithoutChecksum, checksum);
AQH_Message_IncUsedSize(msg, 1);
}
}
int AQH_NodeMessage_IsValid(AQH_MESSAGE *msg)
{
if (msg) {
uint8_t *ptr;
uint32_t len;
uint8_t checksum;
ptr=AQH_Message_GetMsgPointer(msg);
len=AQH_Message_GetUsedSize(msg);
checksum=_calcCrc8Checksum(ptr, len);
return (checksum==0)?1:0;
}
return 0;
}
void AQH_NodeMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (msg) {
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: %s %d (\"%s\")\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sText,
AQH_NodeMessage_GetMsgType(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)));
GWEN_Text_DumpString2Buffer((const char*)AQH_Message_GetMsgPointer(msg), AQH_Message_GetUsedSize(msg), dbuf, 34);
}
}
const char *AQH_NodeMessage_MsgTypeToChar(uint8_t i)
{
switch(i) {
case AQH_MSG_TYPE_PING: return "Ping";
case AQH_MSG_TYPE_PONG: return "Pong";
case AQH_MSG_TYPE_COMSENDSTATS: return "SendStats";
case AQH_MSG_TYPE_COMRECVSTATS: return "RecvStats";
case AQH_MSG_TYPE_TWIBUSMEMBER: return "TwiBusMember";
case AQH_MSG_TYPE_DEBUG: return "Debug";
case AQH_MSG_TYPE_VALUE: return "Value";
case AQH_MSG_TYPE_VALUE2: return "Value2";
case AQH_MSG_TYPE_NEED_ADDRESS: return "NeedAddress";
case AQH_MSG_TYPE_HAVE_ADDRESS: return "HaveAddress";
case AQH_MSG_TYPE_CLAIM_ADDRESS: return "ClaimAddress";
case AQH_MSG_TYPE_DENY_ADDRESS: return "DenyAddress";
case AQH_MSG_TYPE_ADDRESS_RANGE: return "Range";
case AQH_MSG_TYPE_FLASH_START: return "FlashStart";
case AQH_MSG_TYPE_FLASH_END: return "FlashEnd";
case AQH_MSG_TYPE_FLASH_READY: return "FlashReady";
case AQH_MSG_TYPE_FLASH_DATA: return "FlashData";
case AQH_MSG_TYPE_FLASH_RSP: return "FlashResponse";
case AQH_MSG_TYPE_DEVICE: return "Device";
case AQH_MSG_TYPE_MEMSTATS: return "MemStats";
case AQH_MSG_TYPE_SYSSTATS: return "SysStats";
case AQH_MSG_TYPE_REBOOT_REQ: return "RebootRequest";
case AQH_MSG_TYPE_REBOOT_RSP: return "RebootResponse";
default: return "(unknown)";
}
}
uint32_t AQH_NodeMessage_GetMsgGroup(uint8_t msgType)
{
switch(msgType) {
case AQH_MSG_TYPE_PING:
case AQH_MSG_TYPE_PONG:
case AQH_MSG_TYPE_COMSENDSTATS:
case AQH_MSG_TYPE_COMRECVSTATS:
case AQH_MSG_TYPE_TWIBUSMEMBER:
case AQH_MSG_TYPE_DEBUG:
case AQH_MSG_TYPE_DEVICE:
case AQH_MSG_TYPE_MEMSTATS:
case AQH_MSG_TYPE_SYSSTATS:
return AQH_MSG_TYPEGROUP_INFO;
case AQH_MSG_TYPE_VALUE:
case AQH_MSG_TYPE_VALUE2:
case AQH_MSG_TYPE_VALUE_REPORT:
case AQH_MSG_TYPE_VALUE_SET:
case AQH_MSG_TYPE_VALUE_SET_ACK:
case AQH_MSG_TYPE_VALUE_SET_NACK:
return AQH_MSG_TYPEGROUP_VALUES;
case AQH_MSG_TYPE_NEED_ADDRESS:
case AQH_MSG_TYPE_HAVE_ADDRESS:
case AQH_MSG_TYPE_CLAIM_ADDRESS:
case AQH_MSG_TYPE_DENY_ADDRESS:
case AQH_MSG_TYPE_ADDRESS_RANGE:
return AQH_MSG_TYPEGROUP_ADDRESS;
case AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS:
return AQH_MSG_TYPEGROUP_ADMIN;
case AQH_MSG_TYPE_FLASH_START:
case AQH_MSG_TYPE_FLASH_END:
case AQH_MSG_TYPE_FLASH_READY:
case AQH_MSG_TYPE_FLASH_DATA:
case AQH_MSG_TYPE_FLASH_RSP:
case AQH_MSG_TYPE_REBOOT_REQ:
case AQH_MSG_TYPE_REBOOT_RSP:
return AQH_MSG_TYPEGROUP_FLASH;
default:
return 0;
}
}
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;
}

121
aqhome/msg/node/m_node.h Normal file
View File

@@ -0,0 +1,121 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_M_NODE_H
#define AQH_M_NODE_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/buffer.h>
#define AQH_MAXMSGSIZE 128
#define AQH_MSG_OFFS_ALL_DEST_ADDRESS 0
#define AQH_MSG_OFFS_ALL_PAYLOAD_LEN 1
#define AQH_MSG_OFFS_ALL_PAYLOAD_BEGIN 2
#define AQH_MSG_OFFS_ALL_MSG_TYPE 2
#define AQH_MSG_OFFS_ALL_SRC_ADDRESS 3
#define AQH_MSG_OFFS_ALL_DATA_BEGIN 4
#define AQH_MSG_TYPE_PING 10
#define AQH_MSG_TYPE_PONG 11
#define AQH_MSG_TYPE_COMSENDSTATS 20
#define AQH_MSG_TYPE_COMRECVSTATS 21
#define AQH_MSG_TYPE_TWIBUSMEMBER 30
#define AQH_MSG_TYPE_DEBUG 40
#define AQH_MSG_TYPE_VALUE 50 /* deprecated */
#define AQH_MSG_TYPE_VALUE2 51 /* deprecated */
#define AQH_MSG_TYPE_NEED_ADDRESS 60
#define AQH_MSG_TYPE_HAVE_ADDRESS 61
#define AQH_MSG_TYPE_CLAIM_ADDRESS 62
#define AQH_MSG_TYPE_DENY_ADDRESS 63
#define AQH_MSG_TYPE_ADDRESS_RANGE 64
#define AQH_MSG_TYPE_FLASH_START 70
#define AQH_MSG_TYPE_FLASH_END 71
#define AQH_MSG_TYPE_FLASH_READY 72
#define AQH_MSG_TYPE_FLASH_DATA 73
#define AQH_MSG_TYPE_FLASH_RSP 74
#define AQH_MSG_TYPE_DEVICE 80
#define AQH_MSG_TYPE_MEMSTATS 81
#define AQH_MSG_TYPE_SYSSTATS 82
#define AQH_MSG_TYPE_REBOOT_REQ 90
#define AQH_MSG_TYPE_REBOOT_RSP 91
#define AQH_MSG_TYPE_VALUE_REPORT 100
#define AQH_MSG_TYPE_VALUE_SET 101
#define AQH_MSG_TYPE_VALUE_SET_ACK 102
#define AQH_MSG_TYPE_VALUE_SET_NACK 103
/* internal msg types via NET interface */
#define AQH_MSG_TYPE_NET_SET_ACCEPTED_MSGGROUPS 200
#define AQH_MSG_TYPEGROUP_INFO 0x00000001
#define AQH_MSG_TYPEGROUP_VALUES 0x00000002
#define AQH_MSG_TYPEGROUP_ADDRESS 0x00000004
#define AQH_MSG_TYPEGROUP_FLASH 0x00000008
#define AQH_MSG_TYPEGROUP_ADMIN 0x00000010
#define AQH_MSG_TYPEGROUP_ALL 0xffffffff
#if 0
#define AQH_MSG_MODULES_MASK_TIMER 0x02
#define AQH_MSG_MODULES_MASK_COM 0x04
#define AQH_MSG_MODULES_MASK_LED 0x08
#define AQH_MSG_MODULES_MASK_TWIMASTER 0x10
#define AQH_MSG_MODULES_MASK_LCD 0x20
#define AQH_MSG_MODULES_MASK_SI7021 0x40
#define AQH_MSG_MODULES_MASK_STATS 0x80
#endif
AQHOME_API AQH_MESSAGE *AQH_NodeMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen, const uint8_t *payload);
AQH_MESSAGE *AQH_NodeMessage_fromBuffer(const uint8_t *ptr, uint32_t len);
AQHOME_API uint8_t AQH_NodeMessage_GetDestAddress(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_NodeMessage_GetMsgType(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_NodeMessage_GetSourceAddress(const AQH_MESSAGE *msg);
/**
* Return size of payload (i.e. length of data after AQH_MSG_OFFS_ALL_DATA_BEGIN).
*/
AQHOME_API uint8_t AQH_NodeMessage_GetPayloadLength(const AQH_MESSAGE *msg);
/**
* Return pointer to payload (i.e. data after AQH_MSG_OFFS_ALL_DATA_BEGIN).
*/
AQHOME_API uint8_t *AQH_NodeMessage_GetPayloadPointer(const AQH_MESSAGE *msg);
/**
* Append checksum (uses @ref AQH_Message_GetUsedSize).
*/
AQHOME_API void AQH_NodeMessage_AddChecksum(AQH_MESSAGE *msg);
/**
* Verify checksum.
*/
AQHOME_API int AQH_NodeMessage_IsValid(AQH_MESSAGE *msg);
AQHOME_API const char *AQH_NodeMessage_MsgTypeToChar(uint8_t i);
AQHOME_API uint32_t AQH_NodeMessage_GetMsgGroup(uint8_t msgType);
AQHOME_API void AQH_NodeMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,97 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "aqhome/msg/node/m_recvstats.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_RECVSTATS_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_RECVSTATS_PACKETSIN 4 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_CRCERRORS 6 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_IOERRORS 8 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_NOBUFFER 10 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_HANDLED 12 /* 2 bytes */
#define AQH_MSG_OFFS_RECVSTATS_MISSED 14 /* 2 bytes */
uint32_t AQH_RecvStatsMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_UID, 0);
}
uint16_t AQH_RecvStatsMessage_GetPacketsIn(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_PACKETSIN, 0);
}
uint16_t AQH_RecvStatsMessage_GetCrcErrors(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_CRCERRORS, 0);
}
uint16_t AQH_RecvStatsMessage_GetIoErrors(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_IOERRORS, 0);
}
uint16_t AQH_RecvStatsMessage_GetNoBufferErrors(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_NOBUFFER, 0);
}
uint16_t AQH_RecvStatsMessage_GetHandled(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_HANDLED, 0);
}
uint16_t AQH_RecvStatsMessage_GetMissed(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_RECVSTATS_MISSED, 0);
}
void AQH_RecvStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: RECVSTATS %s "
"(uid=0x%08x, in=%d, crc errs=%d, io errs=%d, nobuf errs=%d, handled=%d, missed=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sText,
(unsigned int) AQH_RecvStatsMessage_GetUid(msg),
AQH_RecvStatsMessage_GetPacketsIn(msg),
AQH_RecvStatsMessage_GetCrcErrors(msg),
AQH_RecvStatsMessage_GetIoErrors(msg),
AQH_RecvStatsMessage_GetNoBufferErrors(msg),
AQH_RecvStatsMessage_GetHandled(msg),
AQH_RecvStatsMessage_GetMissed(msg));
}

View File

@@ -0,0 +1,32 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_M_RECVSTATS_H
#define AQH_M_RECVSTATS_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_RecvStatsMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetPacketsIn(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetCrcErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetIoErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetNoBufferErrors(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetHandled(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_RecvStatsMessage_GetMissed(const AQH_MESSAGE *msg);
AQHOME_API void AQH_RecvStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,70 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "aqhome/msg/node/m_sendstats.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_SENDSTATS_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_SENDSTATS_PACKETSOUT 4 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_COLLISIONS 6 /* 2 bytes */
#define AQH_MSG_OFFS_SENDSTATS_BUSY 8 /* 2 bytes */
uint32_t AQH_SendStatsMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_UID, 0);
}
uint16_t AQH_SendStatsMessage_GetPacketsOut(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_PACKETSOUT, 0);
}
uint16_t AQH_SendStatsMessage_GetCollisions(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_COLLISIONS, 0);
}
uint16_t AQH_SendStatsMessage_GetBusyErrors(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SENDSTATS_BUSY, 0);
}
void AQH_SendStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (msg)
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SENDSTATS %s (uid=0x%08x, out=%d, collisions=%d, busy line=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sText,
(unsigned int) AQH_SendStatsMessage_GetUid(msg),
AQH_SendStatsMessage_GetPacketsOut(msg),
AQH_SendStatsMessage_GetCollisions(msg),
AQH_SendStatsMessage_GetBusyErrors(msg));
}

View File

@@ -0,0 +1,34 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2025 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifndef AQH_M_SENDSTATS_H
#define AQH_M_SENDSTATS_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_SendStatsMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SendStatsMessage_GetPacketsOut(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SendStatsMessage_GetCollisions(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SendStatsMessage_GetBusyErrors(const AQH_MESSAGE *msg);
AQHOME_API void AQH_SendStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif