From 51a13f286f024c5b8726a5e90a3d2ed08319a02c Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 13 Aug 2023 17:56:31 +0200 Subject: [PATCH] started work on IPC protocol for data service. --- aqhome/ipc/data/0BUILD | 82 +++++++++ aqhome/ipc/data/ipc_data.c | 16 ++ aqhome/ipc/data/ipc_data.h | 28 +++ aqhome/ipc/data/msg_data_getvalues_req.c | 52 ++++++ aqhome/ipc/data/msg_data_getvalues_req.h | 28 +++ aqhome/ipc/data/msg_data_getvalues_rsp.c | 210 +++++++++++++++++++++++ aqhome/ipc/data/msg_data_getvalues_rsp.h | 42 +++++ 7 files changed, 458 insertions(+) create mode 100644 aqhome/ipc/data/0BUILD create mode 100644 aqhome/ipc/data/ipc_data.c create mode 100644 aqhome/ipc/data/ipc_data.h create mode 100644 aqhome/ipc/data/msg_data_getvalues_req.c create mode 100644 aqhome/ipc/data/msg_data_getvalues_req.h create mode 100644 aqhome/ipc/data/msg_data_getvalues_rsp.c create mode 100644 aqhome/ipc/data/msg_data_getvalues_rsp.h diff --git a/aqhome/ipc/data/0BUILD b/aqhome/ipc/data/0BUILD new file mode 100644 index 0000000..f601838 --- /dev/null +++ b/aqhome/ipc/data/0BUILD @@ -0,0 +1,82 @@ + + + + + + + + $(gwenhywfar_cflags) + -I$(topsrcdir) + -I$(topbuilddir) + + + + --include=$(builddir) + --include=$(srcdir) + + + + + + $(visibility_cflags) + + + + --api=AQHOME_API + + + + + + + + + + + + + + + + + + $(local/built_headers_pub) + + + + + ipc_data.h + msg_data_getvalues_rsp.c + msg_data_getvalues_rsp.h + + + + + + + + + $(local/typefiles) + + ipc_data.c + msg_data_getvalues_req.c + msg_data_getvalues_rsp.c + + + + + + + + + + + + + + + + + + + diff --git a/aqhome/ipc/data/ipc_data.c b/aqhome/ipc/data/ipc_data.c new file mode 100644 index 0000000..94f35cc --- /dev/null +++ b/aqhome/ipc/data/ipc_data.c @@ -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 +#endif + + +#include + + diff --git a/aqhome/ipc/data/ipc_data.h b/aqhome/ipc/data/ipc_data.h new file mode 100644 index 0000000..fb7202d --- /dev/null +++ b/aqhome/ipc/data/ipc_data.h @@ -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 + +#include + + +#define AQH_IPC_PROTOCOL_DATA_ID 1 +#define AQH_IPC_PROTOCOL_DATA_VERSION 1 + + + + + +#endif + + + diff --git a/aqhome/ipc/data/msg_data_getvalues_req.c b/aqhome/ipc/data/msg_data_getvalues_req.c new file mode 100644 index 0000000..fdc59a9 --- /dev/null +++ b/aqhome/ipc/data/msg_data_getvalues_req.c @@ -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 +#endif + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + + + + +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)); + } +} + + + + + + + diff --git a/aqhome/ipc/data/msg_data_getvalues_req.h b/aqhome/ipc/data/msg_data_getvalues_req.h new file mode 100644 index 0000000..7395bcd --- /dev/null +++ b/aqhome/ipc/data/msg_data_getvalues_req.h @@ -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 + +#include + + + +AQHOME_API GWEN_MSG *AQH_GetValuesReqDataIpcMsg_new(uint16_t code); + + + + + +#endif + + + diff --git a/aqhome/ipc/data/msg_data_getvalues_rsp.c b/aqhome/ipc/data/msg_data_getvalues_rsp.c new file mode 100644 index 0000000..a31273d --- /dev/null +++ b/aqhome/ipc/data/msg_data_getvalues_rsp.c @@ -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 +#endif + +#include +#include + +#include +#include + +#include +#include + +#include + + +#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) { + 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)); + } +} + + + + + + + diff --git a/aqhome/ipc/data/msg_data_getvalues_rsp.h b/aqhome/ipc/data/msg_data_getvalues_rsp.h new file mode 100644 index 0000000..5c4c587 --- /dev/null +++ b/aqhome/ipc/data/msg_data_getvalues_rsp.h @@ -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 + +#include + +#include + + +#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 + + +