started work on IPC protocol for data service.
This commit is contained in:
82
aqhome/ipc/data/0BUILD
Normal file
82
aqhome/ipc/data/0BUILD
Normal file
@@ -0,0 +1,82 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<target type="ConvenienceLibrary" name="aqhipcdata" >
|
||||
|
||||
<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)/ipc" >
|
||||
$(local/built_headers_pub)
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" install="$(pkgincludedir)/ipc" >
|
||||
ipc_data.h
|
||||
msg_data_getvalues_rsp.c
|
||||
msg_data_getvalues_rsp.h
|
||||
</headers>
|
||||
|
||||
|
||||
<headers dist="true" >
|
||||
</headers>
|
||||
|
||||
|
||||
<sources>
|
||||
$(local/typefiles)
|
||||
|
||||
ipc_data.c
|
||||
msg_data_getvalues_req.c
|
||||
msg_data_getvalues_rsp.c
|
||||
</sources>
|
||||
|
||||
|
||||
<extradist>
|
||||
</extradist>
|
||||
|
||||
|
||||
<useTargets>
|
||||
</useTargets>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
|
||||
|
||||
|
||||
</target>
|
||||
|
||||
</gwbuild>
|
||||
16
aqhome/ipc/data/ipc_data.c
Normal file
16
aqhome/ipc/data/ipc_data.c
Normal file
@@ -0,0 +1,16 @@
|
||||
/****************************************************************************
|
||||
* 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/ipc_data.h>
|
||||
|
||||
|
||||
28
aqhome/ipc/data/ipc_data.h
Normal file
28
aqhome/ipc/data/ipc_data.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/****************************************************************************
|
||||
* 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_H
|
||||
#define AQH_MSG_IPC_DATA_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
|
||||
|
||||
#define AQH_IPC_PROTOCOL_DATA_ID 1
|
||||
#define AQH_IPC_PROTOCOL_DATA_VERSION 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
52
aqhome/ipc/data/msg_data_getvalues_req.c
Normal file
52
aqhome/ipc/data/msg_data_getvalues_req.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/****************************************************************************
|
||||
* This file is part of the project AqHome.
|
||||
* AqHome (c) by 2023 Martin Preuss, all rights reserved.
|
||||
*
|
||||
* The license for this file can be found in the file COPYING which you
|
||||
* should have received along with this file.
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <aqhome/ipc/data/msg_data_getvalues_req.h>
|
||||
#include <aqhome/ipc/data/ipc_data.h>
|
||||
|
||||
#include <gwenhywfar/msg.h>
|
||||
#include <gwenhywfar/buffer.h>
|
||||
|
||||
#include <gwenhywfar/misc.h>
|
||||
#include <gwenhywfar/list.h>
|
||||
#include <gwenhywfar/error.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *AQH_GetValuesReqDataIpcMsg_new(uint16_t code)
|
||||
{
|
||||
return GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_GetValuesReqDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=GWEN_MSGIPC_OFFS_PAYLOAD) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"GETVALUESREQ (code=%d, proto=%d, proto version=%d)\n",
|
||||
GWEN_IpcMsg_GetCode(msg),
|
||||
GWEN_IpcMsg_GetProtoId(msg),
|
||||
GWEN_IpcMsg_GetProtoVersion(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
28
aqhome/ipc/data/msg_data_getvalues_req.h
Normal file
28
aqhome/ipc/data/msg_data_getvalues_req.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/****************************************************************************
|
||||
* 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_GETVALUES_REQ_H
|
||||
#define AQH_MSG_IPC_DATA_GETVALUES_REQ_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_GetValuesReqDataIpcMsg_new(uint16_t code);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
210
aqhome/ipc/data/msg_data_getvalues_rsp.c
Normal file
210
aqhome/ipc/data/msg_data_getvalues_rsp.c
Normal file
@@ -0,0 +1,210 @@
|
||||
/****************************************************************************
|
||||
* 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_getvalues_rsp.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_GETVALUES_RSP_OFFS_FLAGS 0 /* 4 bytes */
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_OFFS_NUMVALUES 4 /* 4 bytes */
|
||||
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_OFFS_VALUES 8 /* 8 byte */
|
||||
|
||||
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_VALUES_OFFS_ID 0 /* 8 byte */
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_VALUES_OFFS_NAME 8 /* 104 byte */
|
||||
# define AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_NAME 104 /* 104 byte */
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_VALUES_OFFS_UNITS 112 /* 16 bytes */
|
||||
# define AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_UNITS 16
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE 128
|
||||
|
||||
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_MINSIZE (GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_GETVALUES_RSP_OFFS_VALUES)
|
||||
|
||||
|
||||
|
||||
|
||||
GWEN_MSG *AQH_GetValuesRspDataIpcMsg_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_GETVALUES_RSP_OFFS_VALUES+(count*AQH_MSGDATA_GETVALUES_RSP_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) {
|
||||
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_GETVALUES_RSP_VALUES_SIZE_NAME-1);
|
||||
ptr[AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_NAME-1]=0;
|
||||
}
|
||||
else
|
||||
memset(ptr, 0, AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_NAME);
|
||||
ptr+=AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_NAME;
|
||||
|
||||
if (units) {
|
||||
strncpy((char*) ptr, units, AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_UNITS-1);
|
||||
ptr[AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_UNITS-1]=0;
|
||||
}
|
||||
else
|
||||
memset(ptr, 0, AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_UNITS);
|
||||
ptr+=AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_UNITS;
|
||||
|
||||
value=AQH_Value_List_Next(value);
|
||||
}
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_GetValuesRspDataIpcMsg_GetFlags(const GWEN_MSG *msg)
|
||||
{
|
||||
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_GETVALUES_RSP_OFFS_FLAGS, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint32_t AQH_GetValuesRspDataIpcMsg_GetNumValues(const GWEN_MSG *msg)
|
||||
{
|
||||
return GWEN_Msg_GetUint32At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+AQH_MSGDATA_GETVALUES_RSP_OFFS_NUMVALUES, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t AQH_GetValuesRspDataIpcMsg_GetValueId(const GWEN_MSG *msg, int idx)
|
||||
{
|
||||
uint32_t pos;
|
||||
|
||||
pos=
|
||||
AQH_MSGDATA_GETVALUES_RSP_OFFS_VALUES+
|
||||
(idx*AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE)+
|
||||
AQH_MSGDATA_GETVALUES_RSP_VALUES_OFFS_ID;
|
||||
return GWEN_Msg_GetUint64At(msg, GWEN_MSGIPC_OFFS_PAYLOAD+pos, 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
const char *AQH_GetValuesRspDataIpcMsg_GetValueName(const GWEN_MSG *msg, int idx)
|
||||
{
|
||||
uint32_t pos;
|
||||
|
||||
pos=
|
||||
AQH_MSGDATA_GETVALUES_RSP_OFFS_VALUES+
|
||||
(idx*AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE)+
|
||||
AQH_MSGDATA_GETVALUES_RSP_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_GetValuesRspDataIpcMsg_IsValid(const GWEN_MSG *msg)
|
||||
{
|
||||
int msgLen;
|
||||
int numValues;
|
||||
const uint8_t *ptr;
|
||||
int i;
|
||||
|
||||
msgLen=GWEN_Msg_GetBytesInBuffer(msg);
|
||||
if (msgLen<AQH_MSGDATA_GETVALUES_RSP_MINSIZE) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Message too small (%d<%d)", GWEN_Msg_GetBytesInBuffer(msg), AQH_MSGDATA_GETVALUES_RSP_MINSIZE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
numValues=(int)AQH_GetValuesRspDataIpcMsg_GetNumValues(msg);
|
||||
if (msgLen<(numValues*AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE)+AQH_MSGDATA_GETVALUES_RSP_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_GETVALUES_RSP_OFFS_VALUES;
|
||||
for (i=0; i<numValues; i++) {
|
||||
if (ptr[AQH_MSGDATA_GETVALUES_RSP_VALUES_OFFS_NAME+AQH_MSGDATA_GETVALUES_RSP_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_GETVALUES_RSP_VALUES_OFFS_UNITS+AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE_UNITS-1]!=0) {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "Units string for value %d is not null-terminated", i);
|
||||
return 0;
|
||||
}
|
||||
ptr+=AQH_MSGDATA_GETVALUES_RSP_VALUES_SIZE;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void AQH_GetValuesRspDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
|
||||
{
|
||||
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_GETVALUES_RSP_MINSIZE) {
|
||||
GWEN_Buffer_AppendArgs(dbuf,
|
||||
"GETVALUESRSP (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_GetValuesRspDataIpcMsg_GetFlags(msg),
|
||||
AQH_GetValuesRspDataIpcMsg_GetNumValues(msg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
42
aqhome/ipc/data/msg_data_getvalues_rsp.h
Normal file
42
aqhome/ipc/data/msg_data_getvalues_rsp.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/****************************************************************************
|
||||
* 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_GETVALUES_RSP_H
|
||||
#define AQH_MSG_IPC_DATA_GETVALUES_RSP_H
|
||||
|
||||
|
||||
#include <aqhome/api.h>
|
||||
|
||||
#include <aqhome/data/value.h>
|
||||
|
||||
#include <gwenhywfar/msg_ipc.h>
|
||||
|
||||
|
||||
#define AQH_MSGDATA_GETVALUES_RSP_FLAGS_LASTMSG 0x0001
|
||||
|
||||
|
||||
AQHOME_API GWEN_MSG *AQH_GetValuesRspDataIpcMsg_new(uint16_t code, uint32_t flags, const AQH_VALUE_LIST *valueList);
|
||||
AQHOME_API uint32_t AQH_GetValuesRspDataIpcMsg_GetFlags(const GWEN_MSG *msg);
|
||||
AQHOME_API uint32_t AQH_GetValuesRspDataIpcMsg_GetNumValues(const GWEN_MSG *msg);
|
||||
|
||||
AQHOME_API uint8_t AQH_GetValuesRspDataIpcMsg_GetValueId(const GWEN_MSG *msg, int idx);
|
||||
AQHOME_API const char *AQH_GetValuesRspDataIpcMsg_GetValueName(const GWEN_MSG *msg, int idx);
|
||||
|
||||
AQHOME_API int AQH_GetValuesRspDataIpcMsg_IsValid(const GWEN_MSG *msg);
|
||||
AQHOME_API void AQH_GetValuesRspDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user