aqhome: Prepared reorganizing IPC and nodes code around built-in event2 api.

This commit is contained in:
Martin Preuss
2025-02-26 00:49:33 +01:00
parent cf8edbbd5f
commit f63079af11
54 changed files with 2390 additions and 202 deletions

View File

@@ -49,6 +49,19 @@
m_device.h
m_recvstats.h
m_sendstats.h
m_memstats.h
m_sysstats.h
m_addr.h
m_needaddr.h
m_ping.h
m_pong.h
m_reboot.h
m_value.h
m_flashstart.h
m_flashdata.h
m_flashend.h
m_flashready.h
m_flashresponse.h
</headers>
@@ -63,6 +76,19 @@
m_device.c
m_recvstats.c
m_sendstats.c
m_memstats.c
m_sysstats.c
m_addr.c
m_needaddr.c
m_ping.c
m_pong.c
m_reboot.c
m_value.c
m_flashstart.c
m_flashdata.c
m_flashend.c
m_flashready.c
m_flashresponse.c
</sources>

52
aqhome/msg/node/m_addr.c Normal file
View File

@@ -0,0 +1,52 @@
/****************************************************************************
* 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_addr.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_ADDR_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_ADDR_ADDR 4 /* 1 bytes */
uint32_t AQH_AddrMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_ADDR_UID, 0);
}
uint8_t AQH_AddrMessage_GetAddr(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_ADDR_ADDR, 0);
}
void AQH_AddrMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: ADDR(%s) %s (uid=0x%08x, addr=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_AddrMessage_GetUid(msg),
AQH_AddrMessage_GetAddr(msg));
}

28
aqhome/msg/node/m_addr.h Normal file
View File

@@ -0,0 +1,28 @@
/****************************************************************************
* 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_ADDR_H
#define AQH_M_ADDR_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
/* This message is used for message types ClaimAddr, DenyAddr, HaveAddr */
AQHOME_API uint32_t AQH_AddrMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_AddrMessage_GetAddr(const AQH_MESSAGE *msg);
AQHOME_API void AQH_AddrMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,99 @@
/****************************************************************************
* 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_flashdata.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_FLASHDATA_ADDRESS 0 /* 4 bytes */
#define AQH_MSG_OFFS_FLASHDATA_DATA 4 /* x bytes */
#define AQH_MSG_FLASHDATA_MINSIZE (AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_DATA)
AQH_MESSAGE *AQH_FlashDataMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr,
const uint8_t *dataPtr, uint32_t dataLen)
{
AQH_MESSAGE *msg;
uint8_t *ptr;
uint32_t i;
msg=AQH_NodeMessage_prepare(destAddr, srcAddr, code, dataLen+4);
ptr=AQH_NodeMessage_GetPayloadPointer(msg);
*(ptr++)=addr & 0xff;
*(ptr++)=(addr>>8) & 0xff;
*(ptr++)=(addr>>16) & 0xff;
*(ptr++)=(addr>>24) & 0xff;
for (i=0; i<dataLen; i++) {
*(ptr++)=*(dataPtr++);
}
AQH_NodeMessage_AddChecksum(msg);
return msg;
}
uint32_t AQH_FlashDataMessage_GetAddress(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHDATA_ADDRESS, 0);
}
uint8_t AQH_FlashDataMessage_GetDataLen(const AQH_MESSAGE *msg)
{
if (msg) {
uint8_t payloadLen;
payloadLen=AQH_NodeMessage_GetPayloadLength(msg);
if (payloadLen>=4)
return payloadLen-4; /* subtract uid bytes */
}
return 0;
}
const uint8_t *AQH_FlashDataMessage_GetDataPtr(const AQH_MESSAGE *msg)
{
if (msg && AQH_FlashDataMessage_GetDataLen(msg))
return AQH_NodeMessage_GetPayloadPointer(msg)+4;
return NULL;
}
void AQH_FlashDataMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHDATA(%s) %s (data address=0x%04x, data length=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
AQH_FlashDataMessage_GetAddress(msg),
AQH_FlashDataMessage_GetDataLen(msg));
}

View File

@@ -0,0 +1,31 @@
/****************************************************************************
* 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_FLASHDATA_H
#define AQH_M_FLASHDATA_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_FlashDataMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint32_t addr,
const uint8_t *dataPtr, uint32_t dataLen);
AQHOME_API uint32_t AQH_FlashDataMessage_GetAddress(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashDataMessage_GetDataLen(const AQH_MESSAGE *msg);
AQHOME_API const uint8_t *AQH_FlashDataMessage_GetDataPtr(const AQH_MESSAGE *msg);
AQHOME_API void AQH_FlashDataMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,62 @@
/****************************************************************************
* 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_flashend.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_FLASHEND_REASON 0 /* 1 byte */
AQH_MESSAGE *AQH_FlashEndMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason)
{
AQH_MESSAGE *msg;
uint8_t *ptr;
msg=AQH_NodeMessage_prepare(destAddr, srcAddr, code, 1);
ptr=AQH_NodeMessage_GetPayloadPointer(msg);
*(ptr++)=reason & 0xff;
AQH_NodeMessage_AddChecksum(msg);
return msg;
}
uint8_t AQH_FlashEndMessage_GetReason(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHEND_REASON, 0);
}
void AQH_FlashEndMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHEND(%s) %s (reason=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
AQH_FlashEndMessage_GetReason(msg));
}

View File

@@ -0,0 +1,26 @@
/****************************************************************************
* 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_FLASHEND_H
#define AQH_M_FLASHEND_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_FlashEndMessage_new(uint8_t srcAddr, uint8_t destAddr, uint8_t code, uint8_t reason);
AQHOME_API uint8_t AQH_FlashEndMessage_GetReason(const AQH_MESSAGE *msg);
AQHOME_API void AQH_FlashEndMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,126 @@
/****************************************************************************
* 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_flashready.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
//#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_FLASHREADY_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_FLASHREADY_MANUF 4 /* 4 bytes */
#define AQH_MSG_OFFS_FLASHREADY_DEVTYPE 8 /* 2 bytes */
#define AQH_MSG_OFFS_FLASHREADY_DEVVERSION 10 /* 1 byte */
#define AQH_MSG_OFFS_FLASHREADY_DEVREVISION 11 /* 1 byte */
#define AQH_MSG_OFFS_FLASHREADY_FWVARIANT 12 /* 1 byte */
#define AQH_MSG_OFFS_FLASHREADY_FWVMAJOR 13 /* 1 byte */
#define AQH_MSG_OFFS_FLASHREADY_FWVMINOR 14 /* 1 byte */
#define AQH_MSG_OFFS_FLASHREADY_FWVPATCH 15 /* 1 byte */
#define AQH_MSG_OFFS_FLASHREADY_PAGESIZE 16 /* 2 bytes */
uint32_t AQH_FlashReadyMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_UID, 0);
}
uint32_t AQH_FlashReadyMessage_GetManufacturer(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_MANUF, 0);
}
uint16_t AQH_FlashReadyMessage_GetDeviceType(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVTYPE, 0);
}
uint8_t AQH_FlashReadyMessage_GetDeviceVersion(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVVERSION, 0);
}
uint8_t AQH_FlashReadyMessage_GetDeviceRevision(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_DEVREVISION, 0);
}
uint8_t AQH_FlashReadyMessage_GetFirmwareVariant(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVARIANT, 0);
}
uint8_t AQH_FlashReadyMessage_GetFirmwareVersionMajor(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVMAJOR, 0);
}
uint8_t AQH_FlashReadyMessage_GetFirmwareVersionMinor(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVMINOR, 0);
}
uint8_t AQH_FlashReadyMessage_GetFirmwareVersionPatchlevel(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_FWVPATCH, 0);
}
uint16_t AQH_FlashReadyMessage_GetPagesize(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHREADY_PAGESIZE, 0);
}
void AQH_FlashReadyMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: FLASHREADY(%s) %s (uid=0x%08x, dev=%08x:%04x v%d.%d, fw=%d.%d.%d (%d) pagesize=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_FlashReadyMessage_GetUid(msg),
AQH_FlashReadyMessage_GetManufacturer(msg),
AQH_FlashReadyMessage_GetDeviceType(msg),
AQH_FlashReadyMessage_GetDeviceVersion(msg),
AQH_FlashReadyMessage_GetDeviceRevision(msg),
AQH_FlashReadyMessage_GetFirmwareVersionMajor(msg),
AQH_FlashReadyMessage_GetFirmwareVersionMinor(msg),
AQH_FlashReadyMessage_GetFirmwareVersionPatchlevel(msg),
AQH_FlashReadyMessage_GetFirmwareVariant(msg),
AQH_FlashReadyMessage_GetPagesize(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_FLASHREADY_H
#define AQH_M_FLASHREADY_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_FlashReadyMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_FlashReadyMessage_GetManufacturer(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_FlashReadyMessage_GetDeviceType(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashReadyMessage_GetDeviceVersion(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashReadyMessage_GetDeviceRevision(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashReadyMessage_GetFirmwareVariant(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashReadyMessage_GetFirmwareVersionMajor(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashReadyMessage_GetFirmwareVersionMinor(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_FlashReadyMessage_GetFirmwareVersionPatchlevel(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_FlashReadyMessage_GetPagesize(const AQH_MESSAGE *msg);
AQHOME_API void AQH_FlashReadyMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,45 @@
/****************************************************************************
* 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_flashresponse.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_FLASHRESPONSE_CODE 0 /* 1 byte */
uint8_t AQH_FlashResponseMessage_GetCode(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHRESPONSE_CODE, 0);
}
void AQH_FlashResponseMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf, "0x%02x->0x%02x: FLASHRESPONSE(%s) %s (code=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
AQH_FlashResponseMessage_GetCode(msg));
}

View File

@@ -0,0 +1,26 @@
/****************************************************************************
* 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_FLASHRESPONSE_H
#define AQH_M_FLASHRESPONSE_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint8_t AQH_FlashResponseMessage_GetCode(const AQH_MESSAGE *msg);
AQHOME_API void AQH_FlashResponseMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,55 @@
/****************************************************************************
* 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_flashstart.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_FLASHSTART_UID 0 /* 4 bytes */
AQH_MESSAGE *AQH_FlashStartMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t uid)
{
uint32_t payload;
payload=GWEN_ENDIAN_HTOLE32(uid);
return AQH_NodeMessage_new(destAddr, srcAddr, code, sizeof(payload), (const uint8_t*)&payload);
}
uint32_t AQH_FlashStartMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_FLASHSTART_UID, 0);
}
void AQH_FlashStartMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: FLASHSTART(%s) %s (uid=0x%08x)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_FlashStartMessage_GetUid(msg));
}

View File

@@ -0,0 +1,31 @@
/****************************************************************************
* 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_FLASHSTART_H
#define AQH_M_FLASHSTART_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_FlashStartMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t uid);
AQHOME_API uint32_t AQH_FlashStartMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API void AQH_FlashStartMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,89 @@
/****************************************************************************
* 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_memstats.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_MEMSTATS_SECONDS 0 /* 4 bytes */
#define AQH_MSG_OFFS_MEMSTATS_UID 4 /* 4 bytes */
#define AQH_MSG_OFFS_MEMSTATS_STACKUSAGE 8 /* 2 bytes */
#define AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED 10 /* 1 byte */
#define AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED 11 /* 1 byte */
#define AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER 12 /* 2 bytes */
uint32_t AQH_MemStatsMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_UID, 0);
}
uint32_t AQH_MemStatsMessage_GetSeconds(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_SECONDS, 0);
}
uint16_t AQH_MemStatsMessage_GetStackUsage(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_STACKUSAGE, 0);
}
uint8_t AQH_MemStatsMessage_GetBuffersUsed(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_BUFFERSUSED, 0);
}
uint8_t AQH_MemStatsMessage_GetMaxBuffersUsed(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_MAXBUFFERSUSED, 0);
}
uint16_t AQH_MemStatsMessage_GetRecvNoBufferErrors(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_MEMSTATS_RECVNOBUFFER, 0);
}
void AQH_MemStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: MEMSTATS(%s) %s (uid=0x%08x, uptime=%d, stack used=%d, buffers used=%d(max=%d), no recvbuf=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_MemStatsMessage_GetUid(msg),
AQH_MemStatsMessage_GetSeconds(msg),
AQH_MemStatsMessage_GetStackUsage(msg),
AQH_MemStatsMessage_GetBuffersUsed(msg),
AQH_MemStatsMessage_GetMaxBuffersUsed(msg),
AQH_MemStatsMessage_GetRecvNoBufferErrors(msg));
}

View File

@@ -0,0 +1,38 @@
/****************************************************************************
* 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_MEMSTATS_H
#define AQH_M_MEMSTATS_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_MemStatsMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_MemStatsMessage_GetSeconds(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_MemStatsMessage_GetStackUsage(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_MemStatsMessage_GetBuffersUsed(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_MemStatsMessage_GetMaxBuffersUsed(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_MemStatsMessage_GetRecvNoBufferErrors(const AQH_MESSAGE *msg);
AQHOME_API void AQH_MemStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,43 @@
/****************************************************************************
* 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_needaddr.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_NEEDADDR_UID 0 /* 4 bytes */
uint32_t AQH_NeedAddrMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_NEEDADDR_UID, 0);
}
void AQH_NeedAddrMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: NEEDADDR(%s) %s (uid=0x%08x)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_NeedAddrMessage_GetUid(msg));
}

View File

@@ -0,0 +1,25 @@
/****************************************************************************
* 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_NEEDADDR_H
#define AQH_M_NEEDADDR_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_NeedAddrMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API void AQH_NeedAddrMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -10,9 +10,25 @@
# include <config.h>
#endif
#include "aqhome/msg/node/m_node.h"
#include "aqhome/msg/node/m_device.h"
#include "aqhome/msg/node/m_recvstats.h"
#include "aqhome/msg/node/m_sendstats.h"
#include "aqhome/msg/node/m_memstats.h"
#include "aqhome/msg/node/m_sysstats.h"
#include "aqhome/msg/node/m_addr.h"
#include "aqhome/msg/node/m_needaddr.h"
#include "aqhome/msg/node/m_ping.h"
#include "aqhome/msg/node/m_pong.h"
#include "aqhome/msg/node/m_reboot.h"
#include "aqhome/msg/node/m_value.h"
#include "aqhome/msg/node/m_flashstart.h"
#include "aqhome/msg/node/m_flashdata.h"
#include "aqhome/msg/node/m_flashend.h"
#include "aqhome/msg/node/m_flashready.h"
#include "aqhome/msg/node/m_flashresponse.h"
#include <gwenhywfar/text.h>
@@ -49,7 +65,7 @@ AQH_MESSAGE *AQH_NodeMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code
if (payloadLen && payload)
memmove(ptr+AQH_MSG_OFFS_ALL_DATA_BEGIN, payload, payloadLen);
AQH_Message_SetUsedSize(msg, len);
AQH_Message_SetUsedSize(msg, len-1);
AQH_NodeMessage_AddChecksum(msg);
return msg;
@@ -57,6 +73,29 @@ AQH_MESSAGE *AQH_NodeMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code
AQH_MESSAGE *AQH_NodeMessage_prepare(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen)
{
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;
AQH_Message_SetUsedSize(msg, len-1);
return msg;
}
AQH_MESSAGE *AQH_NodeMessage_fromBuffer(const uint8_t *ptr, uint32_t len)
{
if (ptr && len) {
@@ -191,6 +230,42 @@ const char *AQH_NodeMessage_MsgTypeToChar(uint8_t i)
void AQH_NodeMessage_DumpSpecificToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (msg && dbuf) {
switch(AQH_NodeMessage_GetMsgType(msg)) {
case AQH_MSG_TYPE_PING: AQH_PingMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_PONG: AQH_PongMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_COMSENDSTATS: AQH_SendStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_COMRECVSTATS: AQH_RecvStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_VALUE: AQH_ValueMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_NEED_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_HAVE_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_CLAIM_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_DENY_ADDRESS: AQH_AddrMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_START: AQH_FlashStartMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_END: AQH_FlashEndMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_READY: AQH_FlashReadyMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_DATA: AQH_FlashDataMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_FLASH_RSP: AQH_FlashResponseMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_DEVICE: AQH_DeviceMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_MEMSTATS: AQH_MemStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_SYSSTATS: AQH_SysStatsMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_REBOOT_REQ: AQH_RebootMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_REBOOT_RSP: AQH_RebootMessage_DumpToBuffer(msg, dbuf, sText); break;
case AQH_MSG_TYPE_DEBUG:
case AQH_MSG_TYPE_TWIBUSMEMBER:
case AQH_MSG_TYPE_ADDRESS_RANGE:
default: AQH_NodeMessage_DumpToBuffer(msg, dbuf, sText); break;
}
}
}
uint32_t AQH_NodeMessage_GetMsgGroup(uint8_t msgType)
{
switch(msgType) {

View File

@@ -72,19 +72,11 @@
#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 AQH_MESSAGE *AQH_NodeMessage_prepare(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint8_t payloadLen);
AQHOME_API 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);
@@ -117,5 +109,10 @@ 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);
/**
* Calls the dump function of the given message according to its message type.
*/
AQHOME_API void AQH_NodeMessage_DumpSpecificToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

55
aqhome/msg/node/m_ping.c Normal file
View File

@@ -0,0 +1,55 @@
/****************************************************************************
* 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_ping.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_PING_TIMESTAMP 0 /* 4 bytes */
AQH_MESSAGE *AQH_PingMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t timestamp)
{
uint32_t payload;
payload=GWEN_ENDIAN_HTOLE32(timestamp);
return AQH_NodeMessage_new(destAddr, srcAddr, code, sizeof(payload), (const uint8_t*)&payload);
}
uint32_t AQH_PingMessage_GetTimestamp(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PING_TIMESTAMP, 0);
}
void AQH_PingMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: PING(%s) %s (timestamp=0x%08x)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_PingMessage_GetTimestamp(msg));
}

28
aqhome/msg/node/m_ping.h Normal file
View File

@@ -0,0 +1,28 @@
/****************************************************************************
* 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_PING_H
#define AQH_M_PING_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_PingMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t timestamp);
AQHOME_API uint32_t AQH_PingMessage_GetTimestamp(const AQH_MESSAGE *msg);
AQHOME_API void AQH_PingMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

55
aqhome/msg/node/m_pong.c Normal file
View File

@@ -0,0 +1,55 @@
/****************************************************************************
* 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_pong.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_PONG_TIMESTAMP 0 /* 4 bytes */
AQH_MESSAGE *AQH_PongMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t timestamp)
{
uint32_t payload;
payload=GWEN_ENDIAN_HTOLE32(timestamp);
return AQH_NodeMessage_new(destAddr, srcAddr, code, sizeof(payload), (const uint8_t*)&payload);
}
uint32_t AQH_PongMessage_GetTimestamp(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_PONG_TIMESTAMP, 0);
}
void AQH_PongMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: PONG(%s) %s (uid=0x%08x)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_PongMessage_GetTimestamp(msg));
}

28
aqhome/msg/node/m_pong.h Normal file
View File

@@ -0,0 +1,28 @@
/****************************************************************************
* 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_PONG_H
#define AQH_M_PONG_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_PongMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t timestamp);
AQHOME_API uint32_t AQH_PongMessage_GetTimestamp(const AQH_MESSAGE *msg);
AQHOME_API void AQH_PongMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,56 @@
/****************************************************************************
* 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_reboot.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_REBOOT_UID 0 /* 4 bytes */
AQH_MESSAGE *AQH_RebootMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t uid)
{
uint32_t payload;
payload=GWEN_ENDIAN_HTOLE32(uid);
return AQH_NodeMessage_new(destAddr, srcAddr, code, sizeof(payload), (const uint8_t*)&payload);
}
uint32_t AQH_RebootMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_REBOOT_UID, 0);
}
void AQH_RebootMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: REBOOT(%s) %s (uid=0x%08x)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_RebootMessage_GetUid(msg));
}

View File

@@ -0,0 +1,29 @@
/****************************************************************************
* 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_REBOOT_H
#define AQH_M_REBOOT_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API AQH_MESSAGE *AQH_RebootMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code, uint32_t uid);
AQHOME_API uint32_t AQH_RebootMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API void AQH_RebootMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,71 @@
/****************************************************************************
* 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_sysstats.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#define AQH_MSG_OFFS_SYSSTATS_SECONDS 0 /* 4 bytes */
#define AQH_MSG_OFFS_SYSSTATS_UID 4 /* 4 bytes */
#define AQH_MSG_OFFS_SYSSTATS_COMIRQS 8 /* 2 bytes */
#define AQH_MSG_OFFS_SYSSTATS_TIMERIRQS 10 /* 2 bytes */
uint32_t AQH_SysStatsMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_UID, 0);
}
uint32_t AQH_SysStatsMessage_GetSeconds(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_SECONDS, 0);
}
uint16_t AQH_SysStatsMessage_GetComInterrupts(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_COMIRQS, 0);
}
uint16_t AQH_SysStatsMessage_GetTimerInterrupts(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_SYSSTATS_TIMERIRQS, 0);
}
void AQH_SysStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: SYSSTATS(%s) %s (uid=0x%08x, uptime=%d, com irqs=%d, timer irqs=%d)\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
AQH_NodeMessage_MsgTypeToChar(AQH_NodeMessage_GetMsgType(msg)),
sText,
(unsigned int) AQH_SysStatsMessage_GetUid(msg),
AQH_SysStatsMessage_GetSeconds(msg),
AQH_SysStatsMessage_GetComInterrupts(msg),
AQH_SysStatsMessage_GetTimerInterrupts(msg));
}

View File

@@ -0,0 +1,29 @@
/****************************************************************************
* 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_SYSSTATS_H
#define AQH_M_SYSSTATS_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
AQHOME_API uint32_t AQH_SysStatsMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_SysStatsMessage_GetSeconds(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SysStatsMessage_GetComInterrupts(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_SysStatsMessage_GetTimerInterrupts(const AQH_MESSAGE *msg);
AQHOME_API void AQH_SysStatsMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

218
aqhome/msg/node/m_value.c Normal file
View File

@@ -0,0 +1,218 @@
/****************************************************************************
* 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_value.h"
#include "aqhome/msg/node/m_node.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/endianfns.h>
#define AQH_MSG_OFFS_VALUE_UID 0 /* 4 bytes */
#define AQH_MSG_OFFS_VALUE_MSGID 4 /* 2 bytes */
#define AQH_MSG_OFFS_VALUE_VALUEID 6 /* 1 byte */
#define AQH_MSG_OFFS_VALUE_VALUETYPE 7 /* 1 byte */
#define AQH_MSG_OFFS_VALUE_VALUE 8 /* 2 bytes */
#define AQH_MSG_OFFS_VALUE_DENOM 10 /* 2 bytes */
AQH_MESSAGE *AQH_ValueMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code,
uint16_t msgId, uint8_t valueId, uint16_t value, uint16_t denom)
{
uint8_t payload[12];
uint8_t *ptr;
ptr=payload;
*(ptr++)=0; /* uid (empty) */
*(ptr++)=0;
*(ptr++)=0;
*(ptr++)=0;
*(ptr++)=msgId & 0xff; /* msgid */
*(ptr++)=(msgId>>8) & 0xff;
*(ptr++)=valueId; /* valueid */
*(ptr++)=0; /* valuetype (empty) */
*(ptr++)=value & 0xff; /* value */
*(ptr++)=(value>>8) & 0xff;
*(ptr++)=denom & 0xff; /* denom */
*(ptr++)=(denom>>8) & 0xff;
return AQH_NodeMessage_new(destAddr, srcAddr, code, sizeof(payload), payload);
}
uint32_t AQH_ValueMessage_GetUid(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_UID, 0);
}
uint16_t AQH_ValueMessage_GetMsgId(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_MSGID, 0);
}
uint8_t AQH_ValueMessage_GetValueId(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_VALUEID, 0);
}
uint8_t AQH_ValueMessage_GetValueType(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_VALUETYPE, 0);
}
uint16_t AQH_ValueMessage_GetValueNom(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_VALUE, 0);
}
uint16_t AQH_ValueMessage_GetValueDenom(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_MSG_OFFS_ALL_DATA_BEGIN+AQH_MSG_OFFS_VALUE_DENOM, 0);
}
const char *AQH_ValueMessage_GetValueTypeName(const AQH_MESSAGE *msg)
{
uint8_t t;
t=AQH_ValueMessage_GetValueType(msg);
switch(t) {
case AQH_MSG_VALUE_TYPE_TEMP: return "temperature";
case AQH_MSG_VALUE_TYPE_HUMIDITY: return "humidity";
case AQH_MSG_VALUE_TYPE_DOOR: return "door_window";
case AQH_MSG_VALUE_TYPE_MOTION: return "motion";
case AQH_MSG_VALUE_TYPE_CO2: return "CO2";
case AQH_MSG_VALUE_TYPE_TVOC: return "TVOC";
default: break;
}
return "unknown";
}
const char *AQH_ValueMessage_GetValueAsWindowStateString(const AQH_MESSAGE *msg)
{
switch(AQH_ValueMessage_GetValueNom(msg)) {
case 0: return "closed";
case 128: return "tilted";
case 255: return "open";
default: break;
}
return "unknown";
}
const char *AQH_ValueMessage_GetValueTypeUnits(const AQH_MESSAGE *msg)
{
uint8_t t;
t=AQH_ValueMessage_GetValueType(msg);
switch(t) {
case AQH_MSG_VALUE_TYPE_TEMP: return "Celsius";
case AQH_MSG_VALUE_TYPE_HUMIDITY: return "%";
case AQH_MSG_VALUE_TYPE_DOOR: return NULL;
case AQH_MSG_VALUE_TYPE_CO2: return "ppm";
case AQH_MSG_VALUE_TYPE_TVOC: return "ppb";
default: break;
}
return NULL;
}
double AQH_ValueMessage_GetValue(const AQH_MESSAGE *msg)
{
double value;
double denom;
uint16_t intDenom;
value=AQH_ValueMessage_GetValueNom(msg);
intDenom=AQH_ValueMessage_GetValueDenom(msg);
if (intDenom==0)
denom=1.0;
else
denom=(double) intDenom;
return (double)(value/denom);
}
void AQH_ValueMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText)
{
const char *sCmd;
switch(AQH_NodeMessage_GetMsgType(msg)) {
case AQH_MSG_TYPE_VALUE_REPORT: sCmd="report"; break;
case AQH_MSG_TYPE_VALUE_SET: sCmd="set"; break;
case AQH_MSG_TYPE_VALUE_SET_ACK: sCmd="ack"; break;
case AQH_MSG_TYPE_VALUE_SET_NACK: sCmd="nack"; break;
default: sCmd="unknown"; break;
}
if (AQH_ValueMessage_GetValueType(msg)==AQH_MSG_VALUE_TYPE_DOOR)
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: VALUE(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%s [%04x/%04x])\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sCmd,
sText,
(unsigned int) AQH_ValueMessage_GetUid(msg),
(unsigned int)AQH_ValueMessage_GetMsgId(msg),
AQH_ValueMessage_GetValueId(msg),
AQH_ValueMessage_GetValueTypeName(msg),
AQH_ValueMessage_GetValueAsWindowStateString(msg),
AQH_ValueMessage_GetValueNom(msg),
AQH_ValueMessage_GetValueDenom(msg));
else
GWEN_Buffer_AppendArgs(dbuf,
"0x%02x->0x%02x: VALUE(%s) %s (uid=0x%08x, msgId=%u, value_id=0x%02x type=%s value=%f [%04x/%04x])\n",
AQH_NodeMessage_GetSourceAddress(msg),
AQH_NodeMessage_GetDestAddress(msg),
sCmd,
sText,
(unsigned int) AQH_ValueMessage_GetUid(msg),
(unsigned int)AQH_ValueMessage_GetMsgId(msg),
AQH_ValueMessage_GetValueId(msg),
AQH_ValueMessage_GetValueTypeName(msg),
AQH_ValueMessage_GetValue(msg),
AQH_ValueMessage_GetValueNom(msg),
AQH_ValueMessage_GetValueDenom(msg));
}

46
aqhome/msg/node/m_value.h Normal file
View File

@@ -0,0 +1,46 @@
/****************************************************************************
* 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_VALUE_H
#define AQH_M_VALUE_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/debug.h>
#define AQH_MSG_VALUE_TYPE_TEMP 1
#define AQH_MSG_VALUE_TYPE_HUMIDITY 2
#define AQH_MSG_VALUE_TYPE_DOOR 3
#define AQH_MSG_VALUE_TYPE_MOTION 6
#define AQH_MSG_VALUE_TYPE_CO2 7
#define AQH_MSG_VALUE_TYPE_TVOC 8
AQHOME_API AQH_MESSAGE *AQH_ValueMessage_new(uint8_t destAddr, uint8_t srcAddr, uint8_t code,
uint16_t msgId, uint8_t valueId, uint16_t value, uint16_t denom);
AQHOME_API uint32_t AQH_ValueMessage_GetUid(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_ValueMessage_GetMsgId(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_ValueMessage_GetValueId(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_ValueMessage_GetValueType(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_ValueMessage_GetValueNom(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_ValueMessage_GetValueDenom(const AQH_MESSAGE *msg);
AQHOME_API const char *AQH_ValueMessage_GetValueTypeName(const AQH_MESSAGE *msg);
AQHOME_API const char *AQH_ValueMessage_GetValueAsWindowStateString(const AQH_MESSAGE *msg);
AQHOME_API const char *AQH_ValueMessage_GetValueTypeUnits(const AQH_MESSAGE *msg);
AQHOME_API double AQH_ValueMessage_GetValue(const AQH_MESSAGE *msg);
AQHOME_API void AQH_ValueMessage_DumpToBuffer(const AQH_MESSAGE *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif