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

View File

@@ -108,9 +108,13 @@
<useTargets>
aqhmsg_node
aqhmsg_ipc
</useTargets>
<subdirs>
node
ipc
</subdirs>

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

@@ -0,0 +1,84 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhmsg_ipc" >
<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_ipc.h
m_ipc_tag16.h
m_ipc_result.h
</headers>
<headers dist="true" >
</headers>
<sources>
$(local/typefiles)
m_ipc.c
m_ipc_tag16.c
m_ipc_result.c
</sources>
<extradist>
</extradist>
<useTargets>
aqhmsg_ipcd
</useTargets>
<subdirs>
data
</subdirs>
</target>
</gwbuild>

View File

@@ -0,0 +1,90 @@
<?xml?>
<gwbuild>
<target type="ConvenienceLibrary" name="aqhmsg_ipcd" >
<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_ipcd.h
m_ipcd_connect.h
m_ipcd_multidata.h
m_ipcd_devices.h
m_ipcd_values.h
m_ipcd_getdata.h
m_ipcd_setdata.h
</headers>
<headers dist="true" >
</headers>
<sources>
$(local/typefiles)
m_ipcd.c
m_ipcd_connect.c
m_ipcd_multidata.c
m_ipcd_devices.c
m_ipcd_values.c
m_ipcd_getdata.c
m_ipcd_setdata.c
</sources>
<extradist>
</extradist>
<useTargets>
</useTargets>
<subdirs>
</subdirs>
</target>
</gwbuild>

View File

@@ -0,0 +1,56 @@
/****************************************************************************
* 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/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
const char *AQH_IpcdMessage_MsgTypeToChar(uint16_t i)
{
switch(i) {
case AQH_MSGTYPE_IPC_DATA_RESULT: return "Result";
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: return "Connect(Req)";
case AQH_MSGTYPE_IPC_DATA_UPDATEDATA: return "UpdateData";
case AQH_MSGTYPE_IPC_DATA_DATACHANGED: return "DataChanged";
case AQH_MSGTYPE_IPC_DATA_SETDATA: return "SetData";
case AQH_MSGTYPE_IPC_DATA_ADDVALUE: return "AddValue";
case AQH_MSGTYPE_IPC_DATA_GETDATA_REQ: return "GetData(Req)";
case AQH_MSGTYPE_IPC_DATA_GETDATA_RSP: return "GetData(Rsp)";
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ: return "GetLastData(Req)";
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP: return "GetLastData(Rsp)";
case AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ: return "GetValues(Req)";
case AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP: return "GetValues(Rsp)";
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ: return "GetDevices(Req)";
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP: return "GetDevices(Rsp)";
case AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ: return "ModDevice(Req)";
case AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE: return "AnnounceValue";
default: return "(unknown)";
}
}

View File

@@ -0,0 +1,57 @@
/****************************************************************************
* 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_IPCD_H
#define AQH_M_IPCD_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#define AQH_IPC_PROTOCOL_DATA_ID 2
#define AQH_IPC_PROTOCOL_DATA_VERSION 1
#define AQH_MSGTYPE_IPC_DATA_RESULT 0x0001 /* AQH_ResultIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x0010 /* serviceName, userName, password */
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x0300 /* AQH_SetDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x0400 /* AQH_AddValueDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x0500 /* AQH_GetDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x0600 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x0700 /* AQH_GetDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x0800 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x0900 /* GWEN_IpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0x0a00 /* AQH_ValuesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ 0x0b00 /* GWEN_IpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP 0x0c00 /* AQH_DevicesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ 0x0d00 /* AQH_DevicesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE 0x0e00 /* AQH_ValuesDataIpcMsg */
AQHOME_API const char *AQH_IpcdMessage_MsgTypeToChar(uint16_t i);
#endif

View File

@@ -0,0 +1,90 @@
/****************************************************************************
* 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/ipc/data/m_ipcd_connect.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
const char *clientId, const char *userId, const char *password, uint32_t flags)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
buf=GWEN_Buffer_new(0, 256, 0, 1);
if (clientId && *clientId)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_CLIENTID, clientId, buf);
if (userId && *userId)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_USERID, userId, buf);
if (password && *password)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_CONNECT_TAGS_PASSWORD, password, buf);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_CONNECT_TAGS_FLAGS, flags, buf);
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
void AQH_IpcdMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
{
char *clientId=NULL;
char *userId=NULL;
uint32_t flags=0;
if (tagList) {
clientId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_CLIENTID, NULL);
userId=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_CONNECT_TAGS_USERID, NULL);
flags=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_CONNECT_TAGS_FLAGS, 0);
}
GWEN_Buffer_AppendArgs(dbuf,
"CONNECT(%s) %s (code=%d, proto=%d, proto version=%d, clientId=%s, userId=%s, flags=%08x)\n",
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
clientId?clientId:"<empty>",
userId?userId:"<empty>",
flags);
free(userId);
free(clientId);
}

View File

@@ -0,0 +1,40 @@
/****************************************************************************
* 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_IPCD_CONNECT_H
#define AQH_M_IPCD_CONNECT_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/tag16.h>
#define AQH_MSGDATA_CONNECT_TAGS_CLIENTID 0x0001
#define AQH_MSGDATA_CONNECT_TAGS_USERID 0x0002
#define AQH_MSGDATA_CONNECT_TAGS_PASSWORD 0x0003
#define AQH_MSGDATA_CONNECT_TAGS_FLAGS 0x0004
#define AQH_MSGDATA_CONNECT_FLAGS_WANTUPDATES 0x0001
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageConnect_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const char *clientId, const char *userId, const char *password,
uint32_t flags);
AQHOME_API void AQH_IpcdMessageConnect_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,119 @@
/****************************************************************************
* 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/ipc/data/m_ipcd_devices.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcdMessageDevices_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
uint32_t flags, const AQH_DEVICE_LIST *deviceList)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
int rv;
buf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_DEVICES_TAGS_FLAGS, flags, buf);
rv=AQH_Tag16_WriteDeviceListAsTagsToBuffer(AQH_MSGDATA_DEVICES_TAGS_DEVICE, deviceList, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return NULL;
}
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
AQH_DEVICE_LIST *AQH_IpcdMessageDevices_ReadDeviceList(const GWEN_TAG16_LIST *tagList)
{
if (tagList) {
AQH_DEVICE_LIST *deviceList;
deviceList=AQH_Tag16_ReadDevicesFromTagList(tagList, AQH_MSGDATA_DEVICES_TAGS_DEVICE);
if (deviceList==NULL) {
DBG_INFO(AQH_LOGDOMAIN, "No device list received");
}
return deviceList;
}
return NULL;
}
AQH_DEVICE *AQH_IpcdMessageDevices_ReadFirstDevice(const GWEN_TAG16_LIST *tagList)
{
if (tagList) {
AQH_DEVICE *device;
device=AQH_Tag16_ReadDeviceFromTagList(tagList, AQH_MSGDATA_DEVICES_TAGS_DEVICE);
if (device==NULL) {
DBG_INFO(AQH_LOGDOMAIN, "No device received");
}
return device;
}
return NULL;
}
uint32_t AQH_IpcdMessageDevices_GetFlags(const GWEN_TAG16_LIST *tagList)
{
return tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_DEVICES_TAGS_FLAGS, 0):0;
}
void AQH_IpcdMessageDevices_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText)
{
uint32_t flags;
flags=AQH_IpcdMessageDevices_GetFlags(tagList);
GWEN_Buffer_AppendArgs(dbuf,
"DEVICES(%s) %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
(unsigned int) flags);
}

View File

@@ -0,0 +1,41 @@
/****************************************************************************
* 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_IPCD_DEVICES_H
#define AQH_M_IPCD_DEVICES_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <aqhome/data/device.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#define AQH_MSGDATA_DEVICES_FLAGS_LASTMSG 0x0001
#define AQH_MSGDATA_DEVICES_TAGS_FLAGS 0x01
#define AQH_MSGDATA_DEVICES_TAGS_DEVICE 0xc2
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageDevices_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
uint32_t flags, const AQH_DEVICE_LIST *deviceList);
AQHOME_API AQH_DEVICE_LIST *AQH_IpcdMessageDevices_ReadDeviceList(const GWEN_TAG16_LIST *tagList);
AQHOME_API AQH_DEVICE *AQH_IpcdMessageDevices_ReadFirstDevice(const GWEN_TAG16_LIST *tagList);
AQHOME_API uint32_t AQH_IpcdMessageDevices_GetFlags(const GWEN_TAG16_LIST *tagList);
AQHOME_API void AQH_IpcdMessageDevices_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,87 @@
/****************************************************************************
* 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/ipc/data/m_ipcd_getdata.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcdMessageGetData_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
buf=GWEN_Buffer_new(0, 256, 0, 1);
if (valueName && *valueName)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_GETDATA_TAGS_NAME, valueName, buf);
GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_BEGIN, tsBegin, buf);
GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_END, tsEnd, buf);
GWEN_Tag16_WriteUint64TagToBuffer(AQH_MSGDATA_GETDATA_TAGS_NUM, num, buf);
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
void AQH_IpcdMessageGetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText)
{
char *valueName;
uint64_t tsBegin;
uint64_t tsEnd;
valueName=tagList?AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_GETDATA_TAGS_NAME, NULL):NULL;
tsBegin=tagList?AQH_Tag16_GetTagDataAsUint64(tagList, AQH_MSGDATA_GETDATA_TAGS_BEGIN, 0):0;
tsEnd=tagList?AQH_Tag16_GetTagDataAsUint64(tagList, AQH_MSGDATA_GETDATA_TAGS_END, 0):0;
GWEN_Buffer_AppendArgs(dbuf,
"GETDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, tsBegin=%lu, tsEnd=%lu)\n",
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
valueName?valueName:"<empty>",
(unsigned long int) tsBegin,
(unsigned long int) tsEnd);
free(valueName);
}

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_IPCD_GETDATA_H
#define AQH_M_IPCD_GETDATA_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#define AQH_MSGDATA_GETDATA_TAGS_NAME 0x0001
#define AQH_MSGDATA_GETDATA_TAGS_BEGIN 0x0020
#define AQH_MSGDATA_GETDATA_TAGS_END 0x0021
#define AQH_MSGDATA_GETDATA_TAGS_NUM 0x0022
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageGetData_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const char *valueName, uint64_t tsBegin, uint64_t tsEnd, uint64_t num);
AQHOME_API void AQH_IpcdMessageGetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,158 @@
/****************************************************************************
* 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/ipc/data/m_ipcd_multidata.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcdMessageMultiData_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const AQH_VALUE *value, const uint64_t *i64Ptr, int numOfDataPoints)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
int rv;
buf=GWEN_Buffer_new(0, 256, 0, 1);
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_VALUE, value, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return NULL;
}
if (i64Ptr && numOfDataPoints)
GWEN_Tag16_WriteTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_DATA, (const uint8_t*)i64Ptr, numOfDataPoints*2*sizeof(uint64_t), buf);
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
AQH_MESSAGE *AQH_IpcdMessageMultiData_newForOne(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const AQH_VALUE *value, uint64_t timeStamp, double dataPoint)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
int rv;
union {double f; uint64_t i;} u;
uint64_t arrayToSend[2];
buf=GWEN_Buffer_new(0, 256, 0, 1);
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_VALUE, value, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return NULL;
}
arrayToSend[0]=timeStamp;
u.f=dataPoint;
arrayToSend[1]=u.i;
GWEN_Tag16_WriteTagToBuffer(AQH_MSGDATA_MULTIDATA_TAGS_DATA, (const uint8_t*) arrayToSend, 2*sizeof(uint64_t), buf);
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
AQH_VALUE *AQH_IpcdMessageMultiData_ReadValue(const GWEN_TAG16_LIST *tagList)
{
return tagList?AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_MULTIDATA_TAGS_VALUE):NULL;
}
void AQH_IpcdMessageMultiData_ReadDatapoints(const GWEN_TAG16_LIST *tagList, const uint64_t **pDataPtr, uint64_t *pNumberOfPoints)
{
if (tagList) {
const GWEN_TAG16 *tag;
unsigned int numberOfPoints;
const uint64_t *dataPoints;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_DATA);
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
dataPoints=tag?((const uint64_t*) GWEN_Tag16_GetTagData(tag)):NULL;
if (numberOfPoints>0 && dataPoints) {
*pDataPtr=dataPoints;
*pNumberOfPoints=numberOfPoints;
}
}
}
void AQH_IpcdMessageMultiData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
{
AQH_VALUE *value;
const GWEN_TAG16 *tag;
const char *valueName;
const char *valueUnits;
int valueType;
unsigned int numberOfPoints=0;
value=tagList?AQH_IpcdMessageMultiData_ReadValue(tagList):NULL;
valueName=value?AQH_Value_GetNameForSystem(value):NULL;
valueUnits=value?AQH_Value_GetValueUnits(value):NULL;
valueType=value?AQH_Value_GetValueType(value):0;
tag=tagList?GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_DATA):NULL;
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
GWEN_Buffer_AppendArgs(dbuf,
"MULTIDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, datapoints=%u)\n",
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
valueName?valueName:"<empty>",
valueUnits?valueUnits:"<empty>",
valueType,
numberOfPoints);
AQH_Value_free(value);
}

View File

@@ -0,0 +1,44 @@
/****************************************************************************
* 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_IPCD_MULTIDATA_H
#define AQH_M_IPCD_MULTIDATA_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#define AQH_MSGDATA_MULTIDATA_TAGS_VALUE 0xc1
#define AQH_MSGDATA_MULTIDATA_TAGS_DATA 0xc2
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageMultiData_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const AQH_VALUE *value, const uint64_t *i64Ptr, int numOfDataPoints);
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageMultiData_newForOne(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const AQH_VALUE *value, uint64_t timeStamp, double dataPoint);
AQHOME_API AQH_VALUE *AQH_IpcdMessageMultiData_ReadValue(const GWEN_TAG16_LIST *tagList);
AQHOME_API void AQH_IpcdMessageMultiData_ReadDatapoints(const GWEN_TAG16_LIST *tagList,
const uint64_t **pDataPtr, uint64_t *pNumberOfPoints);
AQHOME_API void AQH_IpcdMessageMultiData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,120 @@
/****************************************************************************
* 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/ipc/data/m_ipcd_setdata.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcdMessageSetData_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const AQH_VALUE *value, const char *data)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
int rv;
buf=GWEN_Buffer_new(0, 256, 0, 1);
rv=AQH_Tag16_WriteValueAsTagToBuffer(AQH_MSGDATA_SET_TAGS_VALUE, value, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return NULL;
}
if (data && *data)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_SET_TAGS_DATA, data, buf);
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
AQH_VALUE *AQH_IpcdMessageSetData_ReadValue(const GWEN_TAG16_LIST *tagList)
{
if (tagList) {
AQH_VALUE *value;
value=AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_SET_TAGS_VALUE);
if (value==NULL) {
DBG_INFO(AQH_LOGDOMAIN, "No value received");
}
return value;
}
return NULL;
}
char *AQH_IpcdMessageSetData_ReadData(const GWEN_TAG16_LIST *tagList)
{
return AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_SET_TAGS_DATA, NULL);
}
void AQH_IpcdMessageSetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText)
{
AQH_VALUE *value;
const char *valueName;
const char *valueUnits;
int valueType;
char *data;
value=tagList?AQH_IpcdMessageSetData_ReadValue(tagList):NULL;
valueName=value?AQH_Value_GetNameForSystem(value):NULL;
valueUnits=value?AQH_Value_GetValueUnits(value):NULL;
valueType=value?AQH_Value_GetValueType(value):0;
data=tagList?AQH_IpcdMessageSetData_ReadData(tagList):NULL;
GWEN_Buffer_AppendArgs(dbuf,
"SETDATA(%s) %s (code=%d, proto=%d, proto version=%d, name=%s, units=%s, type=%d, value=%s)\n",
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
valueName?valueName:"<empty>",
valueUnits?valueUnits:"<empty>",
valueType,
data?data:"<empty>");
free(data);
AQH_Value_free(value);
}

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.
****************************************************************************/
#ifndef AQH_M_IPCD_SETDATA_H
#define AQH_M_IPCD_SETDATA_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#define AQH_MSGDATA_SET_TAGS_VALUE 0xc1
#define AQH_MSGDATA_SET_TAGS_DATA 0x02
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageSetData_new(uint16_t code,
uint32_t msgId, uint32_t refMsgId,
const AQH_VALUE *value, const char *data);
AQHOME_API AQH_VALUE *AQH_IpcdMessageSetData_ReadValue(const GWEN_TAG16_LIST *tagList);
AQHOME_API char *AQH_IpcdMessageSetData_ReadData(const GWEN_TAG16_LIST *tagList);
AQHOME_API void AQH_IpcdMessageSetData_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,119 @@
/****************************************************************************
* 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/ipc/data/m_ipcd_values.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/data/m_ipcd.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcdMessageValues_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
uint32_t flags, const AQH_VALUE_LIST *valueList)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
int rv;
buf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_VALUES_TAGS_FLAGS, flags, buf);
rv=AQH_Tag16_WriteValueListAsTagsToBuffer(AQH_MSGDATA_VALUES_TAGS_VALUE, valueList, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return NULL;
}
msg=AQH_IpcMessage_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
AQH_VALUE_LIST *AQH_IpcdMessageDevices_ReadValueList(const GWEN_TAG16_LIST *tagList)
{
if (tagList) {
AQH_VALUE_LIST *valueList;
valueList=AQH_Tag16_ReadValuesFromTagList(tagList, AQH_MSGDATA_VALUES_TAGS_VALUE);
if (valueList==NULL) {
DBG_INFO(AQH_LOGDOMAIN, "No value list received");
}
return valueList;
}
return NULL;
}
AQH_VALUE *AQH_IpcdMessageValues_ReadFirstValue(const GWEN_TAG16_LIST *tagList)
{
if (tagList) {
AQH_VALUE *value;
value=AQH_Tag16_ReadValueFromTagList(tagList, AQH_MSGDATA_VALUES_TAGS_VALUE);
if (value==NULL) {
DBG_INFO(AQH_LOGDOMAIN, "No value received");
}
return value;
}
return NULL;
}
uint32_t AQH_IpcdMessageValues_GetFlags(const GWEN_TAG16_LIST *tagList)
{
return tagList?AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_VALUES_TAGS_FLAGS, 0):0;
}
void AQH_IpcdMessageValues_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText)
{
uint32_t flags;
flags=AQH_IpcdMessageValues_GetFlags(tagList);
GWEN_Buffer_AppendArgs(dbuf,
"VALUES(%s) %s (code=%d, proto=%d, proto version=%d, flags=0x%08x)\n",
AQH_IpcdMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
(unsigned int) flags);
}

View File

@@ -0,0 +1,41 @@
/****************************************************************************
* 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_IPCD_VALUES_H
#define AQH_M_IPCD_VALUES_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#define AQH_MSGDATA_VALUES_FLAGS_LASTMSG 0x0001
#define AQH_MSGDATA_VALUES_TAGS_FLAGS 0x01
#define AQH_MSGDATA_VALUES_TAGS_VALUE 0xc2
AQHOME_API AQH_MESSAGE *AQH_IpcdMessageValues_new(uint16_t code, uint32_t msgId, uint32_t refMsgId,
uint32_t flags, const AQH_VALUE_LIST *valueList);
AQHOME_API AQH_VALUE_LIST *AQH_IpcdMessageDevices_ReadValueList(const GWEN_TAG16_LIST *tagList);
AQHOME_API AQH_VALUE *AQH_IpcdMessageValues_ReadFirstValue(const GWEN_TAG16_LIST *tagList);
AQHOME_API uint32_t AQH_IpcdMessageValues_GetFlags(const GWEN_TAG16_LIST *tagList);
AQHOME_API void AQH_IpcdMessageValues_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

159
aqhome/msg/ipc/m_ipc.c Normal file
View File

@@ -0,0 +1,159 @@
/****************************************************************************
* 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/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcMessage_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
uint32_t msgId, uint32_t refMsgId,
uint32_t payloadLen, const uint8_t *payload)
{
AQH_MESSAGE *msg;
uint32_t len;
len=AQH_IPCMSG_OFFS_PAYLOAD+payloadLen;
msg=AQH_Message_new();
AQH_Message_SetData(msg, NULL, len); /* auto-malloc len bytes */
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_SIZE, len);
AQH_Message_WriteUint8At(msg, AQH_IPCMSG_OFFS_PROTOID, protoId);
AQH_Message_WriteUint8At(msg, AQH_IPCMSG_OFFS_PROTOVER, protoVer);
AQH_Message_WriteUint16At(msg, AQH_IPCMSG_OFFS_CODE, code);
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_ID, msgId);
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_REFID, refMsgId);
if (payloadLen && payload)
AQH_Message_WriteBytesAt(msg, AQH_IPCMSG_OFFS_PAYLOAD, payload, payloadLen);
AQH_Message_SetUsedSize(msg, len);
return msg;
}
AQH_MESSAGE *AQH_IpcMessage_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;
}
void AQH_IpcMessage_AdjustMsgSize(AQH_MESSAGE *msg)
{
if (msg)
AQH_Message_WriteUint32At(msg, AQH_IPCMSG_OFFS_SIZE, AQH_Message_GetUsedSize(msg));
}
uint32_t AQH_IpcMessage_GetMsgSize(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_IPCMSG_OFFS_SIZE, 0);
}
uint8_t AQH_IpcMessage_GetProtoId(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_IPCMSG_OFFS_PROTOID, 0);
}
uint8_t AQH_IpcMessage_GetProtoVersion(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint8At(msg, AQH_IPCMSG_OFFS_PROTOVER, 0);
}
uint16_t AQH_IpcMessage_GetCode(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint16At(msg, AQH_IPCMSG_OFFS_CODE, 0);
}
uint32_t AQH_IpcMessage_GetMsgId(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_IPCMSG_OFFS_ID, 0);
}
uint32_t AQH_IpcMessage_GetRefMsgId(const AQH_MESSAGE *msg)
{
return AQH_Message_ReadUint32At(msg, AQH_IPCMSG_OFFS_REFID, 0);
}
uint32_t AQH_IpcMessage_GetPayloadLength(const AQH_MESSAGE *msg)
{
return msg?(AQH_IpcMessage_GetMsgSize(msg)-AQH_IPCMSG_OFFS_PAYLOAD):0;
}
uint8_t *AQH_IpcMessage_GetPayloadPointer(const AQH_MESSAGE *msg)
{
return msg?(AQH_Message_GetMsgPointer(msg)+AQH_IPCMSG_OFFS_PAYLOAD):NULL;
}
const char *AQH_IpcMessage_MsgTypeToChar(uint16_t i)
{
switch(i) {
case AQH_MSGTYPE_IPC_DATA_RESULT: return "Result";
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: return "Connect(Req)";
case AQH_MSGTYPE_IPC_DATA_UPDATEDATA: return "UpdateData";
case AQH_MSGTYPE_IPC_DATA_DATACHANGED: return "DataChanged";
case AQH_MSGTYPE_IPC_DATA_SETDATA: return "SetData";
case AQH_MSGTYPE_IPC_DATA_ADDVALUE: return "AddValue";
case AQH_MSGTYPE_IPC_DATA_GETDATA_REQ: return "GetData(Req)";
case AQH_MSGTYPE_IPC_DATA_GETDATA_RSP: return "GetData(Rsp)";
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ: return "GetLastData(Req)";
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP: return "GetLastData(Rsp)";
case AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ: return "GetValues(Req)";
case AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP: return "GetValues(Rsp)";
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ: return "GetDevices(Req)";
case AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP: return "GetDevices(Rsp)";
case AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ: return "ModDevice(Req)";
case AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE: return "AnnounceValue";
default: return "(unknown)";
}
}

85
aqhome/msg/ipc/m_ipc.h Normal file
View File

@@ -0,0 +1,85 @@
/****************************************************************************
* 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_IPC_H
#define AQH_M_IPC_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#define AQH_IPCMSG_OFFS_SIZE 0 /* 4 bytes: number of all bytes including size, protoid, protover and code */
#define AQH_IPCMSG_OFFS_PROTOID 4 /* 1 byte: protocol id (free to use) */
#define AQH_IPCMSG_OFFS_PROTOVER 5 /* 1 byte: protocol version (free to use) */
#define AQH_IPCMSG_OFFS_CODE 6 /* 2 bytes msg code (meaning depends on protocol) */
#define AQH_IPCMSG_OFFS_ID 8 /* 4 bytes msg id */
#define AQH_IPCMSG_OFFS_REFID 12 /* 4 bytes reference msg id */
#define AQH_IPCMSG_OFFS_PAYLOAD 16 /* begin of payload for a given message */
#define AQH_IPC_PROTOCOL_DATA_ID 2
#define AQH_IPC_PROTOCOL_DATA_VERSION 1
#define AQH_MSGTYPE_IPC_DATA_RESULT 0x0001 /* AQH_ResultIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_CONNECT_REQ 0x0010 /* serviceName, userName, password */
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x0100 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x0200 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x0300 /* AQH_SetDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x0400 /* AQH_AddValueDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATA_REQ 0x0500 /* AQH_GetDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATA_RSP 0x0600 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ 0x0700 /* AQH_GetDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP 0x0800 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x0900 /* GWEN_IpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0x0a00 /* AQH_ValuesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_REQ 0x0b00 /* GWEN_IpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDEVICES_RSP 0x0c00 /* AQH_DevicesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ 0x0d00 /* AQH_DevicesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE 0x0e00 /* AQH_ValuesDataIpcMsg */
AQHOME_API AQH_MESSAGE *AQH_IpcMessage_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
uint32_t msgId, uint32_t refMsgId,
uint32_t payloadLen, const uint8_t *payload);
AQHOME_API AQH_MESSAGE *AQH_IpcMessage_fromBuffer(const uint8_t *ptr, uint32_t len);
AQHOME_API void AQH_IpcMessage_AdjustMsgSize(AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_IpcMessage_GetMsgSize(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_IpcMessage_GetProtoId(const AQH_MESSAGE *msg);
AQHOME_API uint8_t AQH_IpcMessage_GetProtoVersion(const AQH_MESSAGE *msg);
AQHOME_API uint16_t AQH_IpcMessage_GetCode(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_IpcMessage_GetMsgId(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_IpcMessage_GetRefMsgId(const AQH_MESSAGE *msg);
AQHOME_API uint32_t AQH_IpcMessage_GetPayloadLength(const AQH_MESSAGE *msg);
AQHOME_API uint8_t *AQH_IpcMessage_GetPayloadPointer(const AQH_MESSAGE *msg);
AQHOME_API const char *AQH_IpcMessage_MsgTypeToChar(uint16_t i);
#endif

View File

@@ -0,0 +1,81 @@
/****************************************************************************
* 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/ipc/m_ipc_result.h"
#include "aqhome/msg/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
AQH_MESSAGE *AQH_IpcMessageResult_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
uint32_t msgId, uint32_t refMsgId,
int result, const char *text)
{
AQH_MESSAGE *msg;
GWEN_BUFFER *buf;
buf=GWEN_Buffer_new(0, 256, 0, 1);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_MSGDATA_RESULT_TAGS_RESULT, result, buf);
if (text && *text)
GWEN_Tag16_WriteStringTagToBuffer(AQH_MSGDATA_RESULT_TAGS_TEXT, text, buf);
msg=AQH_IpcMessage_new(protoId, protoVer, code, msgId, refMsgId,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
void AQH_IpcMessageResult_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList, GWEN_BUFFER *dbuf, const char *sText)
{
int result=0;
char *text=NULL;
if (tagList) {
result=AQH_Tag16_GetTagDataAsUint32(tagList, AQH_MSGDATA_RESULT_TAGS_RESULT, 0);
text=AQH_Tag16_GetTagDataAsNewString(tagList, AQH_MSGDATA_RESULT_TAGS_TEXT, NULL);
}
GWEN_Buffer_AppendArgs(dbuf,
"RESULT(%s) %s (code=%d, proto=%d, proto version=%d, result=%d, text=\"%s\")\n",
AQH_IpcMessage_MsgTypeToChar(AQH_IpcMessage_GetCode(msg)),
sText?sText:"",
AQH_IpcMessage_GetCode(msg),
AQH_IpcMessage_GetProtoId(msg),
AQH_IpcMessage_GetProtoVersion(msg),
result,
text?text:"");
free(text);
}

View File

@@ -0,0 +1,33 @@
/****************************************************************************
* 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_IPC_RESULT_H
#define AQH_M_IPC_RESULT_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <gwenhywfar/tag16.h>
#define AQH_MSGDATA_RESULT_TAGS_RESULT 0x0001
#define AQH_MSGDATA_RESULT_TAGS_TEXT 0x0002
AQHOME_API AQH_MESSAGE *AQH_IpcMessageResult_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
uint32_t msgId, uint32_t refMsgId,
int result, const char *text);
AQHOME_API void AQH_IpcMessageResult_DumpToBuffer(const AQH_MESSAGE *msg, const GWEN_TAG16_LIST *tagList,
GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,582 @@
/****************************************************************************
* 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/ipc/m_ipc_tag16.h"
#include "aqhome/msg/ipc/m_ipc.h"
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQH_IPCDATA_VALUE_TAGS_ID 0x01
#define AQH_IPCDATA_VALUE_TAGS_DRIVER 0x02
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER 0x03
#define AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM 0x04
#define AQH_IPCDATA_VALUE_TAGS_TYPE 0x05
#define AQH_IPCDATA_VALUE_TAGS_UNITS 0x06
#define AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION 0x07
#define AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER 0x08
#define AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM 0x09
#define AQH_IPCDATA_VALUE_TAGS_MODALITY 0x0a
#define AQH_IPCDATA_DEVICE_TAGS_ID 0x01
#define AQH_IPCDATA_DEVICE_TAGS_DRIVER 0x02
#define AQH_IPCDATA_DEVICE_TAGS_ROOMNAME 0x03
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER 0x04
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM 0x05
#define AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI 0x06
#define AQH_IPCDATA_DEVICE_TAGS_LOCATION 0x07
#define AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION 0x08
#define AQH_IPCDATA_DEVICE_TAGS_DEVTYPE 0x09
#define AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER 0x0a
#define AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION 0x0b
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf);
static AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len);
static void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf);
static AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len);
/* ------------------------------------------------------------------------------------------------
* implementation
* ------------------------------------------------------------------------------------------------
*/
GWEN_TAG16_LIST *AQH_IpcMessageTag16_ParsePayload(const AQH_MESSAGE *msg, int doCopy)
{
if (msg) {
const uint8_t *payloadPtr;
uint32_t payloadSize;
payloadPtr=AQH_IpcMessage_GetPayloadPointer(msg);
payloadSize=AQH_IpcMessage_GetPayloadLength(msg);
return AQH_Tag16_ParseTags(payloadPtr, payloadSize, doCopy);
}
return NULL;
}
GWEN_TAG16_LIST *AQH_Tag16_ParseTags(const uint8_t *payloadPtr, uint32_t payloadSize, int doCopy)
{
if (payloadPtr && payloadSize) {
GWEN_TAG16_LIST *tagList;
tagList=GWEN_Tag16_List_fromBuffer(payloadPtr, payloadSize, doCopy);
if (tagList==NULL) {
DBG_INFO(AQH_LOGDOMAIN, "Error reading tags from message");
return NULL;
}
return tagList;
}
return NULL;
}
char *AQH_Tag16_GetTagDataAsNewString(const GWEN_TAG16_LIST *tagList, unsigned int tagType, const char *defaultValue)
{
if (tagList) {
const GWEN_TAG16 *tag;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, tagType);
if (tag)
return GWEN_Tag16_GetTagDataAsNewString(tag, defaultValue);
}
return defaultValue?strdup(defaultValue):NULL;
}
uint32_t AQH_Tag16_GetTagDataAsUint32(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint32_t defaultValue)
{
if (tagList) {
const GWEN_TAG16 *tag;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, tagType);
return tag?GWEN_Tag16_GetTagDataAsUint32(tag, defaultValue):defaultValue;
}
return defaultValue;
}
uint64_t AQH_Tag16_GetTagDataAsUint64(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint64_t defaultValue)
{
if (tagList) {
const GWEN_TAG16 *tag;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, tagType);
return tag?GWEN_Tag16_GetTagDataAsUint64(tag, defaultValue):defaultValue;
}
return defaultValue;
}
int AQH_Tag16_WriteValueListAsTagsToBuffer(unsigned int tagType, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *buf)
{
if (valueList) {
const AQH_VALUE *value;
value=AQH_Value_List_First(valueList);
while(value) {
int rv;
rv=AQH_Tag16_WriteValueAsTagToBuffer(tagType, value, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return rv;
}
value=AQH_Value_List_Next(value);
}
}
return 0;
}
int AQH_Tag16_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *value, GWEN_BUFFER *buf)
{
int startPos;
int rv;
startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf);
if (startPos<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos);
return startPos;
}
_writeValueFieldsAsTagsToBuffer(value, buf);
rv=GWEN_Tag16_EndTagInBuffer(startPos, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
return 0;
}
int AQH_Tag16_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf)
{
if (deviceList) {
const AQH_DEVICE *device;
device=AQH_Device_List_First(deviceList);
while(device) {
int rv;
rv=AQH_Tag16_WriteDeviceAsTagToBuffer(tagType, device, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
GWEN_Buffer_free(buf);
return rv;
}
device=AQH_Device_List_Next(device);
}
}
return 0;
}
int AQH_Tag16_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf)
{
int startPos;
int rv;
startPos=GWEN_Tag16_StartTagInBuffer(tagType, buf);
if (startPos<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", startPos);
return startPos;
}
_writeDeviceFieldsAsTagsToBuffer(device, buf);
rv=GWEN_Tag16_EndTagInBuffer(startPos, buf);
if (rv<0) {
DBG_INFO(AQH_LOGDOMAIN, "here (%d)", rv);
return rv;
}
return 0;
}
void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf)
{
const char *s;
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_VALUE_TAGS_ID, AQH_Value_GetId(value), buf);
s=AQH_Value_GetDriver(value);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DRIVER, s, buf);
s=AQH_Value_GetName(value);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER, s, buf);
s=AQH_Value_GetNameForSystem(value);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM, s, buf);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_TYPE, AQH_Value_GetValueType(value), buf);
s=AQH_Value_GetValueUnits(value);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_UNITS, s, buf);
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION, AQH_Value_GetTimestampCreation(value), buf);
s=AQH_Value_GetDeviceName(value);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER, s, buf);
s=AQH_Value_GetDeviceNameForSystem(value);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM, s, buf);
GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_MODALITY, AQH_Value_GetModality(value), buf);
}
AQH_VALUE_LIST *AQH_Tag16_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
{
AQH_VALUE_LIST *valueList;
const GWEN_TAG16 *tag;
valueList=AQH_Value_List_new();
tag=GWEN_Tag16_List_First(tagList);
while(tag) {
unsigned int tagType;
AQH_VALUE *value;
tagType=GWEN_Tag16_GetTagType(tag);
if (tagType==wantedTagType) {
value=_readValueFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag));
if (value)
AQH_Value_List_Add(value, valueList);
}
tag=GWEN_Tag16_List_Next(tag);
}
if (AQH_Value_List_GetCount(valueList)<1) {
AQH_Value_List_free(valueList);
return NULL;
}
return valueList;
}
AQH_VALUE *AQH_Tag16_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
{
if (tagList) {
const GWEN_TAG16 *tag;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType);
return tag?_readValueFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL;
}
return NULL;
}
AQH_DEVICE_LIST *AQH_Tag16_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
{
AQH_DEVICE_LIST *deviceList;
const GWEN_TAG16 *tag;
deviceList=AQH_Device_List_new();
tag=GWEN_Tag16_List_First(tagList);
while(tag) {
unsigned int tagType;
AQH_DEVICE *device;
tagType=GWEN_Tag16_GetTagType(tag);
if (tagType==wantedTagType) {
device=_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag));
if (device)
AQH_Device_List_Add(device, deviceList);
}
tag=GWEN_Tag16_List_Next(tag);
}
if (AQH_Device_List_GetCount(deviceList)<1) {
AQH_Device_List_free(deviceList);
return NULL;
}
return deviceList;
}
AQH_DEVICE *AQH_Tag16_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType)
{
if (tagList) {
const GWEN_TAG16 *tag;
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, wantedTagType);
return tag?_readDeviceFromTag((const uint8_t*) GWEN_Tag16_GetTagData(tag), (uint32_t) GWEN_Tag16_GetTagLength(tag)):NULL;
}
return NULL;
}
AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len)
{
GWEN_TAG16_LIST *tagList;
tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0);
if (tagList) {
GWEN_TAG16 *tag;
AQH_VALUE *value;
value=AQH_Value_new();
tag=GWEN_Tag16_List_First(tagList);
while(tag) {
unsigned int tagType;
char *s;
tagType=GWEN_Tag16_GetTagType(tag);
switch(tagType) {
case AQH_IPCDATA_VALUE_TAGS_ID:
AQH_Value_SetId(value, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
break;
case AQH_IPCDATA_VALUE_TAGS_DRIVER:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Value_SetDriver(value, s);
free(s);
break;
case AQH_IPCDATA_VALUE_TAGS_NAMEFORDRIVER:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Value_SetName(value, s);
free(s);
break;
case AQH_IPCDATA_VALUE_TAGS_NAMEFORSYSTEM:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Value_SetNameForSystem(value, s);
free(s);
break;
case AQH_IPCDATA_VALUE_TAGS_TYPE:
AQH_Value_SetValueType(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
break;
case AQH_IPCDATA_VALUE_TAGS_UNITS:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Value_SetValueUnits(value, s);
free(s);
break;
case AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION:
AQH_Value_SetTimestampCreation(value, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
break;
case AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Value_SetDeviceName(value, s);
free(s);
break;
case AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Value_SetDeviceNameForSystem(value, s);
free(s);
break;
case AQH_IPCDATA_VALUE_TAGS_MODALITY:
AQH_Value_SetModality(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0));
break;
default:
DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType);
break;
}
tag=GWEN_Tag16_List_Next(tag);
}
GWEN_Tag16_List_free(tagList);
return value;
}
return NULL;
}
void _writeDeviceFieldsAsTagsToBuffer(const AQH_DEVICE *device, GWEN_BUFFER *buf)
{
const char *s;
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ID, AQH_Device_GetId(device), buf);
s=AQH_Device_GetDriver(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DRIVER, s, buf);
s=AQH_Device_GetRoomName(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_ROOMNAME, s, buf);
s=AQH_Device_GetName(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER, s, buf);
s=AQH_Device_GetNameForSystem(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM, s, buf);
s=AQH_Device_GetNameForGui(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI, s, buf);
s=AQH_Device_GetLocation(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_LOCATION, s, buf);
s=AQH_Device_GetDescription(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION, s, buf);
s=AQH_Device_GetDeviceType(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_DEVTYPE, s, buf);
s=AQH_Device_GetManufacturer(device);
if (s && *s)
GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER, s, buf);
GWEN_Tag16_WriteUint64TagToBuffer(AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION, AQH_Device_GetTimestampCreation(device), buf);
}
AQH_DEVICE *_readDeviceFromTag(const uint8_t *ptr, uint32_t len)
{
GWEN_TAG16_LIST *tagList;
tagList=GWEN_Tag16_List_fromBuffer(ptr, len, 0);
if (tagList) {
GWEN_TAG16 *tag;
AQH_DEVICE *device;
device=AQH_Device_new();
tag=GWEN_Tag16_List_First(tagList);
while(tag) {
unsigned int tagType;
char *s;
tagType=GWEN_Tag16_GetTagType(tag);
switch(tagType) {
case AQH_IPCDATA_DEVICE_TAGS_ID:
AQH_Device_SetId(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
break;
case AQH_IPCDATA_DEVICE_TAGS_DRIVER:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetDriver(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_ROOMNAME:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetRoomName(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORDRIVER:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetName(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORSYSTEM:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetNameForSystem(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_NAMEFORGUI:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetNameForGui(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_LOCATION:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetLocation(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_DESCRIPTION:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetDescription(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_DEVTYPE:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetDeviceType(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_MANUFACTURER:
s=GWEN_Tag16_GetTagDataAsNewString(tag, NULL);
AQH_Device_SetManufacturer(device, s);
free(s);
break;
case AQH_IPCDATA_DEVICE_TAGS_TIMEOFCREATION:
AQH_Device_SetTimestampCreation(device, GWEN_Tag16_GetTagDataAsUint64(tag, 0));
break;
default:
DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType);
break;
}
tag=GWEN_Tag16_List_Next(tag);
}
GWEN_Tag16_List_free(tagList);
return device;
}
return NULL;
}

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.
****************************************************************************/
#ifndef AQH_M_IPC_TAG16_H
#define AQH_M_IPC_TAG16_H
#include <aqhome/api.h>
#include <aqhome/ipc2/message.h>
#include <aqhome/data/value.h>
#include <aqhome/data/device.h>
#include <gwenhywfar/tag16.h>
AQHOME_API GWEN_TAG16_LIST *AQH_IpcMessageTag16_ParsePayload(const AQH_MESSAGE *msg, int doCopy);
AQHOME_API GWEN_TAG16_LIST *AQH_Tag16_ParseTags(const uint8_t *payloadPtr, uint32_t payloadSize, int doCopy);
AQHOME_API char *AQH_Tag16_GetTagDataAsNewString(const GWEN_TAG16_LIST *tagList, unsigned int tagType, const char *defaultValue);
AQHOME_API uint32_t AQH_Tag16_GetTagDataAsUint32(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint32_t defaultValue);
AQHOME_API uint64_t AQH_Tag16_GetTagDataAsUint64(const GWEN_TAG16_LIST *tagList, unsigned int tagType, uint64_t defaultValue);
/* utils */
AQHOME_API int AQH_Tag16_WriteValueListAsTagsToBuffer(unsigned int tagType, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *buf);
AQHOME_API int AQH_Tag16_WriteValueAsTagToBuffer(unsigned int tagType, const AQH_VALUE *value, GWEN_BUFFER *buf);
AQHOME_API AQH_VALUE_LIST *AQH_Tag16_ReadValuesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
AQHOME_API AQH_VALUE *AQH_Tag16_ReadValueFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
AQHOME_API int AQH_Tag16_WriteDeviceListAsTagsToBuffer(unsigned int tagType, const AQH_DEVICE_LIST *deviceList, GWEN_BUFFER *buf);
AQHOME_API int AQH_Tag16_WriteDeviceAsTagToBuffer(unsigned int tagType, const AQH_DEVICE *device, GWEN_BUFFER *buf);
AQHOME_API AQH_DEVICE_LIST *AQH_Tag16_ReadDevicesFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
AQHOME_API AQH_DEVICE *AQH_Tag16_ReadDeviceFromTagList(const GWEN_TAG16_LIST *tagList, unsigned int wantedTagType);
#endif

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