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

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

84
aqhome/msg/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