started working on aqhome-data.

this will be the data daemon storing datapoints, accessable via IPC.
This commit is contained in:
Martin Preuss
2023-08-14 02:00:37 +02:00
parent 51a13f286f
commit 5fdb33c192
24 changed files with 1976 additions and 26 deletions

View File

@@ -18,8 +18,6 @@
<headers>
<header type="sys" loc="pre">aqhome/api.h</header>
<header type="sys" loc="pre">aqdatabase/aqdb_value.h</header>
<header type="sys" loc="pre">gwenhywfar/timestamp.h</header>
</headers>
</lang>
@@ -27,21 +25,7 @@
<members>
<member name="id" type="uint64_t" maxlen="8">
<default>0</default>
<preset>0</preset>
<flags>with_getbymember</flags>
<access>public</access>
</member>
<member name="valueId" type="uint64_t" maxlen="8">
<default>0</default>
<preset>0</preset>
<flags></flags>
<access>public</access>
</member>
<member name="timestamp" type="gwen_timestamp" maxlen="8" >
<member name="timestamp" type="uint64_t" maxlen="8" >
<access>public</access>
<flags>with_sortbymember</flags>
<default>0</default>

View File

@@ -47,6 +47,7 @@
<headers dist="true" install="$(pkgincludedir)/ipc" >
endpoint_ipc.h
msg_ipc_result.h
msg_ipc_qwords.h
</headers>
@@ -60,6 +61,7 @@
endpoint_ipc.c
msg_ipc_result.c
msg_ipc_qwords.c
</sources>

View File

@@ -48,6 +48,8 @@
ipc_data.h
msg_data_getvalues_rsp.c
msg_data_getvalues_rsp.h
msg_data_values.h
msg_data_datapoints.h
</headers>
@@ -61,6 +63,8 @@
ipc_data.c
msg_data_getvalues_req.c
msg_data_getvalues_rsp.c
msg_data_values.c
msg_data_datapoints.c
</sources>

View File

@@ -19,6 +19,26 @@
#define AQH_IPC_PROTOCOL_DATA_VERSION 1
#define AQH_MSGTYPE_IPC_DATA_RESULT 0x001 /* AQH_ResultIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ 0x100 /* AQH_QwordsIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP 0x200 /* AQH_ValuesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDVALUES_REQ 0x300 /* AQH_ValuesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDVALUES_RSP 0x400 /* AQH_ResultIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_EDITVALUE_REQ 0x500 /* AQH_ValuesDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_EDITVALUE_RSP 0x600 /* AQH_ResultIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDDATAPOINTS_REQ 0x700 /* AQH_DataPointsDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDDATAPOINTS_RSP 0x800 /* AQH_ResultIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETDATAPOINTS_REQ 0x900 /* AQH_DataPointsDataIpcMsg (1 pair: fromTime, toTime) */
#define AQH_MSGTYPE_IPC_DATA_GETDATAPOINTS_RSP 0xa00 /* AQH_DataPointsDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATAPOINT_REQ 0xb00 /* AQH_DataPointsDataIpcMsg (0 datapoints) */
#define AQH_MSGTYPE_IPC_DATA_GETLASTDATAPOINT_RSP 0xc00 /* AQH_DataPointsDataIpcMsg */

View File

@@ -0,0 +1,218 @@
/****************************************************************************
* 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/ipc/data/msg_data_datapoints.h>
#include <aqhome/ipc/data/ipc_data.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/msg_ipc.h>
#include <string.h>
#define AQH_MSGDATA_DATAPOINTS_OFFS_FLAGS 0 /* 4 bytes */
#define AQH_MSGDATA_DATAPOINTS_OFFS_NUMVALUES 4 /* 4 bytes */
#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUEID 8 /* 8 byte */
#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME 16 /* 104 byte */
# define AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME 104
#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS 120 /* 16 byte */
# define AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS 16
#define AQH_MSGDATA_DATAPOINTS_OFFS_VALUES 136
#define AQH_MSGDATA_DATAPOINTS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUES)
static void _writeQword(uint64_t i64, uint8_t *ptr);
GWEN_MSG *AQH_DataPointsDataIpcMsg_new(uint16_t code, uint32_t flags,
uint64_t valueId, const char *valueName, const char *units,
const uint64_t *i64Ptr, int numOfDataPoints)
{
GWEN_MSG *msg;
uint8_t *ptr;
int payloadSize;
int i;
payloadSize=AQH_MSGDATA_DATAPOINTS_OFFS_VALUES+(numOfDataPoints*16);
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, payloadSize, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD;
*(ptr++)=flags & 0xff;
*(ptr++)=(flags>>8) & 0xff;
*(ptr++)=(flags>>16) & 0xff;
*(ptr++)=(flags>>24) & 0xff;
*(ptr++)=numOfDataPoints & 0xff;
*(ptr++)=(numOfDataPoints>>8) & 0xff;
*(ptr++)=(numOfDataPoints>>16) & 0xff;
*(ptr++)=(numOfDataPoints>>24) & 0xff;
_writeQword(valueId, ptr);
ptr+=8;
if (valueName) {
strncpy((char*) ptr, valueName, AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME-1);
ptr[AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME-1]=0;
}
else
memset(ptr, 0, AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME);
ptr+=AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME;
if (units) {
strncpy((char*) ptr, units, AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS-1);
ptr[AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS-1]=0;
}
else
memset(ptr, 0, AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS);
ptr+=AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS;
for (i=0; i<numOfDataPoints; i++) {
_writeQword(*i64Ptr, ptr);
i64Ptr++;
ptr+=8;
_writeQword(*i64Ptr, ptr);
i64Ptr++;
ptr+=8;
}
return msg;
}
void _writeQword(uint64_t i64, uint8_t *ptr)
{
*(ptr++)=i64 & 0xff;
*(ptr++)=(i64>>8) & 0xff;
*(ptr++)=(i64>>16) & 0xff;
*(ptr++)=(i64>>24) & 0xff;
*(ptr++)=(i64>>32) & 0xff;
*(ptr++)=(i64>>40) & 0xff;
*(ptr++)=(i64>>48) & 0xff;
*(ptr++)=(i64>>56) & 0xff;
}
uint32_t AQH_DataPointsDataIpcMsg_GetFlags(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_FLAGS, 0);
}
uint32_t AQH_DataPointsDataIpcMsg_GetNumValues(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_NUMVALUES, 0);
}
uint64_t AQH_DataPointsDataIpcMsg_GetValueId(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUEID, 0);
}
const char *AQH_DataPointsDataIpcMsg_GetValueName(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_MINSIZE)
return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME);
return NULL;
}
const char *AQH_DataPointsDataIpcMsg_GetUnits(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_MINSIZE)
return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS);
return NULL;
}
const uint64_t *AQH_DataPointsDataIpcMsg_GetDataPoints(const GWEN_MSG *msg)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_MINSIZE)
return (const uint64_t*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUES);
return NULL;
}
int AQH_DataPointsDataIpcMsg_IsValid(const GWEN_MSG *msg)
{
int msgLen;
int numValues;
const uint8_t *ptr;
msgLen=GWEN_Msg_GetBytesInBuffer(msg);
if (msgLen<AQH_MSGDATA_DATAPOINTS_MINSIZE) {
DBG_ERROR(AQH_LOGDOMAIN, "Message too small (%d<%d)", GWEN_Msg_GetBytesInBuffer(msg), AQH_MSGDATA_DATAPOINTS_MINSIZE);
return 0;
}
numValues=(int)AQH_DataPointsDataIpcMsg_GetNumValues(msg);
if (msgLen<(numValues*16)+AQH_MSGDATA_DATAPOINTS_OFFS_VALUES+GWEN_MSGIPC_OFFS_PAYLOAD) {
DBG_ERROR(AQH_LOGDOMAIN, "Message too small to contain %d values", numValues);
return 0;
}
ptr=GWEN_Msg_GetConstBuffer(msg);
if (ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUENAME+AQH_MSGDATA_DATAPOINTS_SIZE_VALUENAME-1]!=0) {
DBG_ERROR(AQH_LOGDOMAIN, "Name string for value is not null-terminated");
return 0;
}
if (ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_DATAPOINTS_OFFS_VALUEUNITS+AQH_MSGDATA_DATAPOINTS_SIZE_VALUEUNITS-1]!=0) {
DBG_ERROR(AQH_LOGDOMAIN, "Units string for value is not null-terminated");
return 0;
}
return 1;
}
void AQH_DataPointsDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_DATAPOINTS_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf,
"DATAPOINTS (code=%d, proto=%d, proto version=%d, flags=0x%08x, values=%d)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg),
(unsigned int)AQH_DataPointsDataIpcMsg_GetFlags(msg),
AQH_DataPointsDataIpcMsg_GetNumValues(msg));
}
}

View File

@@ -0,0 +1,54 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_IPC_DATA_DATAPOINTS_H
#define AQH_MSG_IPC_DATA_DATAPOINTS_H
#include <aqhome/api.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/msg_ipc.h>
#define AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG 0x0001
AQHOME_API GWEN_MSG *AQH_DataPointsDataIpcMsg_new(uint16_t code, uint32_t flags,
uint64_t valueId, const char *valueName, const char *units,
const uint64_t *i64Ptr, int numOfDataPoints);
AQHOME_API uint32_t AQH_DataPointsDataIpcMsg_GetFlags(const GWEN_MSG *msg);
AQHOME_API uint32_t AQH_DataPointsDataIpcMsg_GetNumValues(const GWEN_MSG *msg);
AQHOME_API uint64_t AQH_DataPointsDataIpcMsg_GetValueId(const GWEN_MSG *msg);
AQHOME_API const char *AQH_DataPointsDataIpcMsg_GetValueName(const GWEN_MSG *msg);
AQHOME_API const char *AQH_DataPointsDataIpcMsg_GetUnits(const GWEN_MSG *msg);
AQHOME_API const uint64_t *AQH_DataPointsDataIpcMsg_GetDataPoints(const GWEN_MSG *msg);
AQHOME_API int AQH_DataPointsDataIpcMsg_IsValid(const GWEN_MSG *msg);
AQHOME_API void AQH_DataPointsDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -0,0 +1,251 @@
/****************************************************************************
* 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/ipc/data/msg_data_values.h>
#include <aqhome/ipc/data/ipc_data.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/msg_ipc.h>
#include <string.h>
#define AQH_MSGDATA_VALUES_OFFS_FLAGS 0 /* 4 bytes */
#define AQH_MSGDATA_VALUES_OFFS_NUMVALUES 4 /* 4 bytes */
#define AQH_MSGDATA_VALUES_OFFS_VALUES 8 /* 8 byte */
#define AQH_MSGDATA_VALUES_VALUES_OFFS_ID 0 /* 8 byte */
#define AQH_MSGDATA_VALUES_VALUES_OFFS_NAME 8 /* 104 byte */
# define AQH_MSGDATA_VALUES_VALUES_SIZE_NAME 104 /* 104 byte */
#define AQH_MSGDATA_VALUES_VALUES_OFFS_UNITS 112 /* 16 bytes */
# define AQH_MSGDATA_VALUES_VALUES_SIZE_UNITS 16
#define AQH_MSGDATA_VALUES_VALUES_SIZE 128
#define AQH_MSGDATA_VALUES_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_VALUES_OFFS_VALUES)
static void _writeValue(const AQH_VALUE *value, uint8_t *ptr);
GWEN_MSG *AQH_ValuesDataIpcMsg_new(uint16_t code, uint32_t flags, const AQH_VALUE_LIST *valueList)
{
GWEN_MSG *msg;
uint8_t *ptr;
int count;
int payloadSize;
count=AQH_Value_List_GetCount(valueList);
payloadSize=AQH_MSGDATA_VALUES_OFFS_VALUES+(count*AQH_MSGDATA_VALUES_VALUES_SIZE);
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, payloadSize, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD;
*(ptr++)=flags & 0xff;
*(ptr++)=(flags>>8) & 0xff;
*(ptr++)=(flags>>16) & 0xff;
*(ptr++)=(flags>>24) & 0xff;
*(ptr++)=count & 0xff;
*(ptr++)=(count>>8) & 0xff;
*(ptr++)=(count>>16) & 0xff;
*(ptr++)=(count>>24) & 0xff;
if (count>0) {
const AQH_VALUE *value;
value=AQH_Value_List_First(valueList);
while(value) {
_writeValue(value, ptr);
ptr+=AQH_MSGDATA_VALUES_VALUES_SIZE;
value=AQH_Value_List_Next(value);
}
}
return msg;
}
GWEN_MSG *AQH_ValuesDataIpcMsg_newForOneValue(uint16_t code, uint32_t flags, const AQH_VALUE *value)
{
GWEN_MSG *msg;
uint8_t *ptr;
int count;
int payloadSize;
count=1;
payloadSize=AQH_MSGDATA_VALUES_OFFS_VALUES+AQH_MSGDATA_VALUES_VALUES_SIZE;
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, payloadSize, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD;
*(ptr++)=flags & 0xff;
*(ptr++)=(flags>>8) & 0xff;
*(ptr++)=(flags>>16) & 0xff;
*(ptr++)=(flags>>24) & 0xff;
*(ptr++)=count & 0xff;
*(ptr++)=(count>>8) & 0xff;
*(ptr++)=(count>>16) & 0xff;
*(ptr++)=(count>>24) & 0xff;
_writeValue(value, ptr);
return msg;
}
void _writeValue(const AQH_VALUE *value, uint8_t *ptr)
{
uint64_t i64;
const char *name;
const char *units;
i64=AQH_Value_GetId(value);
name=AQH_Value_GetName(value);
units=AQH_Value_GetValueUnits(value);
*(ptr++)=i64 & 0xff;
*(ptr++)=(i64>>8) & 0xff;
*(ptr++)=(i64>>16) & 0xff;
*(ptr++)=(i64>>24) & 0xff;
*(ptr++)=(i64>>32) & 0xff;
*(ptr++)=(i64>>40) & 0xff;
*(ptr++)=(i64>>48) & 0xff;
*(ptr++)=(i64>>56) & 0xff;
if (name) {
strncpy((char*) ptr, name, AQH_MSGDATA_VALUES_VALUES_SIZE_NAME-1);
ptr[AQH_MSGDATA_VALUES_VALUES_SIZE_NAME-1]=0;
}
else
memset(ptr, 0, AQH_MSGDATA_VALUES_VALUES_SIZE_NAME);
ptr+=AQH_MSGDATA_VALUES_VALUES_SIZE_NAME;
if (units) {
strncpy((char*) ptr, units, AQH_MSGDATA_VALUES_VALUES_SIZE_UNITS-1);
ptr[AQH_MSGDATA_VALUES_VALUES_SIZE_UNITS-1]=0;
}
else
memset(ptr, 0, AQH_MSGDATA_VALUES_VALUES_SIZE_UNITS);
ptr+=AQH_MSGDATA_VALUES_VALUES_SIZE_UNITS;
}
uint32_t AQH_ValuesDataIpcMsg_GetFlags(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_VALUES_OFFS_FLAGS, 0);
}
uint32_t AQH_ValuesDataIpcMsg_GetNumValues(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_VALUES_OFFS_NUMVALUES, 0);
}
uint64_t AQH_ValuesDataIpcMsg_GetValueId(const GWEN_MSG *msg, int idx)
{
uint32_t pos;
pos=
AQH_MSGDATA_VALUES_OFFS_VALUES+
(idx*AQH_MSGDATA_VALUES_VALUES_SIZE)+
AQH_MSGDATA_VALUES_VALUES_OFFS_ID;
return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+pos, 0);
}
const char *AQH_ValuesDataIpcMsg_GetValueName(const GWEN_MSG *msg, int idx)
{
uint32_t pos;
pos=
AQH_MSGDATA_VALUES_OFFS_VALUES+
(idx*AQH_MSGDATA_VALUES_VALUES_SIZE)+
AQH_MSGDATA_VALUES_VALUES_OFFS_NAME;
if (GWEN_Msg_GetBytesInBuffer(msg)>=pos+GWEN_MSGIPC_OFFS_PAYLOAD)
return (const char*) (GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+pos);
return NULL;
}
int AQH_ValuesDataIpcMsg_IsValid(const GWEN_MSG *msg)
{
int msgLen;
int numValues;
const uint8_t *ptr;
int i;
msgLen=GWEN_Msg_GetBytesInBuffer(msg);
if (msgLen<AQH_MSGDATA_VALUES_MINSIZE) {
DBG_ERROR(AQH_LOGDOMAIN, "Message too small (%d<%d)", GWEN_Msg_GetBytesInBuffer(msg), AQH_MSGDATA_VALUES_MINSIZE);
return 0;
}
numValues=(int)AQH_ValuesDataIpcMsg_GetNumValues(msg);
if (msgLen<(numValues*AQH_MSGDATA_VALUES_VALUES_SIZE)+AQH_MSGDATA_VALUES_OFFS_VALUES+GWEN_MSGIPC_OFFS_PAYLOAD) {
DBG_ERROR(AQH_LOGDOMAIN, "Message too small to contain %d values", numValues);
return 0;
}
ptr=GWEN_Msg_GetConstBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_VALUES_OFFS_VALUES;
for (i=0; i<numValues; i++) {
if (ptr[AQH_MSGDATA_VALUES_VALUES_OFFS_NAME+AQH_MSGDATA_VALUES_VALUES_SIZE_NAME-1]!=0) {
DBG_ERROR(AQH_LOGDOMAIN, "Name string for value %d is not null-terminated", i);
return 0;
}
if (ptr[AQH_MSGDATA_VALUES_VALUES_OFFS_UNITS+AQH_MSGDATA_VALUES_VALUES_SIZE_UNITS-1]!=0) {
DBG_ERROR(AQH_LOGDOMAIN, "Units string for value %d is not null-terminated", i);
return 0;
}
ptr+=AQH_MSGDATA_VALUES_VALUES_SIZE;
}
return 1;
}
void AQH_ValuesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_VALUES_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf,
"VALUES (code=%d, proto=%d, proto version=%d, flags=0x%08x, values=%d)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg),
(unsigned int)AQH_ValuesDataIpcMsg_GetFlags(msg),
AQH_ValuesDataIpcMsg_GetNumValues(msg));
}
}

View File

@@ -0,0 +1,49 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_IPC_DATA_VALUES_H
#define AQH_MSG_IPC_DATA_VALUES_H
#include <aqhome/api.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/msg_ipc.h>
/**
* This message is used in request AQH_MSGTYPE_IPC_DATA_ADDVALUES_REQ and in response AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP.
*/
#define AQH_MSGDATA_VALUES_FLAGS_LASTMSG 0x0001
AQHOME_API GWEN_MSG *AQH_ValuesDataIpcMsg_new(uint16_t code, uint32_t flags, const AQH_VALUE_LIST *valueList);
AQHOME_API GWEN_MSG *AQH_ValuesDataIpcMsg_newForOneValue(uint16_t code, uint32_t flags, const AQH_VALUE *value);
AQHOME_API uint32_t AQH_ValuesDataIpcMsg_GetFlags(const GWEN_MSG *msg);
AQHOME_API uint32_t AQH_ValuesDataIpcMsg_GetNumValues(const GWEN_MSG *msg);
AQHOME_API uint64_t AQH_ValuesDataIpcMsg_GetValueId(const GWEN_MSG *msg, int idx);
AQHOME_API const char *AQH_ValuesDataIpcMsg_GetValueName(const GWEN_MSG *msg, int idx);
AQHOME_API int AQH_ValuesDataIpcMsg_IsValid(const GWEN_MSG *msg);
AQHOME_API void AQH_ValuesDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

148
aqhome/ipc/msg_ipc_qwords.c Normal file
View File

@@ -0,0 +1,148 @@
/****************************************************************************
* 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/ipc/msg_ipc_qwords.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/misc.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/msg_ipc.h>
#define AQH_MSGDATA_QWORDS_OFFS_FLAGS 0 /* 4 bytes */
#define AQH_MSGDATA_QWORDS_OFFS_NUMVALUES 4 /* 4 bytes */
#define AQH_MSGDATA_QWORDS_OFFS_VALUES 8 /* 8 byte */
#define AQH_MSGDATA_QWORDS_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_VALUES)
static void _writeQword(uint64_t i64, uint8_t *ptr);
GWEN_MSG *AQH_QwordsIpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code, uint32_t flags, const uint64_t *i64Ptr, int count)
{
GWEN_MSG *msg;
uint8_t *ptr;
int payloadSize;
int i;
payloadSize=AQH_MSGDATA_QWORDS_OFFS_VALUES+(count*8);
msg=GWEN_IpcMsg_new(protoId, protoVer, code, payloadSize, NULL);
ptr=GWEN_Msg_GetBuffer(msg)+GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_VALUES;
*(ptr++)=flags & 0xff;
*(ptr++)=(flags>>8) & 0xff;
*(ptr++)=(flags>>16) & 0xff;
*(ptr++)=(flags>>24) & 0xff;
*(ptr++)=count & 0xff;
*(ptr++)=(count>>8) & 0xff;
*(ptr++)=(count>>16) & 0xff;
*(ptr++)=(count>>24) & 0xff;
for(i=0; i<count; i++) {
_writeQword(*i64Ptr, ptr);
ptr+=8;
i64Ptr++;
}
return msg;
}
void _writeQword(uint64_t i64, uint8_t *ptr)
{
*(ptr++)=i64 & 0xff;
*(ptr++)=(i64>>8) & 0xff;
*(ptr++)=(i64>>16) & 0xff;
*(ptr++)=(i64>>24) & 0xff;
*(ptr++)=(i64>>32) & 0xff;
*(ptr++)=(i64>>40) & 0xff;
*(ptr++)=(i64>>48) & 0xff;
*(ptr++)=(i64>>56) & 0xff;
}
uint32_t AQH_QwordsIpcMsg_GetFlags(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_FLAGS, 0);
}
uint32_t AQH_QwordsIpcMsg_GetNumValues(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_QWORDS_OFFS_NUMVALUES, 0);
}
uint64_t AQH_QwordsIpcMsg_GetValue(const GWEN_MSG *msg, int idx)
{
uint32_t pos;
pos=AQH_MSGDATA_QWORDS_OFFS_VALUES+(idx*8);
return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+pos, 0);
}
int AQH_QwordsIpcMsg_IsValid(const GWEN_MSG *msg)
{
int msgLen;
int numValues;
msgLen=GWEN_Msg_GetBytesInBuffer(msg);
if (msgLen<AQH_MSGDATA_QWORDS_MINSIZE) {
DBG_ERROR(AQH_LOGDOMAIN, "Message too small (%d<%d)", GWEN_Msg_GetBytesInBuffer(msg), AQH_MSGDATA_QWORDS_MINSIZE);
return 0;
}
numValues=(int)AQH_QwordsIpcMsg_GetNumValues(msg);
if (msgLen<(numValues*8)+AQH_MSGDATA_QWORDS_OFFS_VALUES+GWEN_MSGIPC_OFFS_PAYLOAD) {
DBG_ERROR(AQH_LOGDOMAIN, "Message too small to contain %d values", numValues);
return 0;
}
return 1;
}
void AQH_QwordsIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_QWORDS_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf,
"QWORDS (code=%d, proto=%d, proto version=%d, flags=0x%08x, values=%d)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg),
(unsigned int)AQH_QwordsIpcMsg_GetFlags(msg),
AQH_QwordsIpcMsg_GetNumValues(msg));
}
}

View File

@@ -0,0 +1,34 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQH_MSG_IPC_QWORDS_H
#define AQH_MSG_IPC_QWORDS_H
#include <aqhome/api.h>
#include <aqhome/ipc/nodes/ipc_nodes.h>
#include <aqhome/msg/msg_node.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
AQHOME_API GWEN_MSG *AQH_QwordsIpcMsg_new(uint8_t protoId, uint8_t protoVer, uint16_t code,
uint32_t flags, const uint64_t *i64Ptr, int count);
AQHOME_API uint32_t AQH_QwordsIpcMsg_GetFlags(const GWEN_MSG *msg);
AQHOME_API uint32_t AQH_QwordsIpcMsg_GetNumValues(const GWEN_MSG *msg);
AQHOME_API uint64_t AQH_QwordsIpcMsg_GetValue(const GWEN_MSG *msg, int idx);
AQHOME_API int AQH_QwordsIpcMsg_IsValid(const GWEN_MSG *msg);
AQHOME_API void AQH_QwordsIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif

View File

@@ -24,31 +24,33 @@
#define AQH_MSGIPC_RESULT_OFFS_RESULTCODE 0 /* 2 bytes */
#define AQH_MSGIPC_RESULT_OFFS_RESULTCODE 0 /* 4 bytes */
#define AQH_MSGIPC_RESULT_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+2)
#define AQH_MSGIPC_RESULT_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+4)
GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint16_t errorCode)
GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t resultCode)
{
GWEN_MSG *msg;
uint8_t *ptr;
msg=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_RESULT_ID, AQH_IPC_PROTOCOL_RESULT_VERSION, code, AQH_MSGIPC_RESULT_MINSIZE, NULL);
ptr=GWEN_Msg_GetBuffer(msg);
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+0]=errorCode & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+1]=errorCode & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+0]=resultCode & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+1]=(resultCode>>8) & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+2]=(resultCode>>16) & 0xff;
ptr[GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE+3]=(resultCode>>24) & 0xff;
return msg;
}
uint16_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg)
uint32_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg)
{
return GWEN_Msg_GetUint16At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE, 0);
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGIPC_RESULT_OFFS_RESULTCODE, 0);
}

View File

@@ -26,8 +26,8 @@
#define AQH_MSG_IPC_ERROR_NODATA 1
AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint16_t errorCode);
AQHOME_API uint16_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg);
AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t resultCode);
AQHOME_API uint32_t AQH_ResultIpcMsg_GetResultCode(const GWEN_MSG *msg);
AQHOME_API void AQH_ResultIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);