re-implemented SetData command.

Allows for string values to be sent.
This commit is contained in:
Martin Preuss
2024-02-14 23:07:20 +01:00
parent eeffe225ec
commit 0cf3976fc7
5 changed files with 161 additions and 31 deletions

View File

@@ -15,7 +15,7 @@
#include "./aqhome_data_p.h"
#include "./loop.h"
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/ipc/data/msg_data_multidata.h"
#include "aqhome/ipc/data/msg_data_set.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_result.h"
#include "aqhome/ipc/msg_ipc_tag16.h"
@@ -37,7 +37,7 @@
* ------------------------------------------------------------------------------------------------
*/
static int _forwardDataToDriver(AQHOME_DATA *aqh, const AQH_VALUE *v, uint64_t timestamp, double datapoint);
static int _forwardDataToDriver(AQHOME_DATA *aqh, const AQH_VALUE *v, const char *data);
@@ -52,44 +52,30 @@ void AqHomeData_HandleSetData(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *epSrc, GWEN_M
int resultCode=AQH_MSG_IPC_SUCCESS;
AQH_VALUE *recvdValue;
const char *valueName;
const GWEN_TAG16 *tag;
const uint64_t *dataPoints;
unsigned int numberOfPoints;
char *valueDataFreeable;
AQH_VALUE *systemValue;
AQH_MultiDataDataIpcMsg_Parse(recvdMsg, 0);
recvdValue=AQH_MultiDataDataIpcMsg_ReadValue(recvdMsg);
AQH_SetDataIpcMsg_Parse(recvdMsg, 0);
recvdValue=AQH_SetDataIpcMsg_ReadValue(recvdMsg);
valueName=recvdValue?AQH_Value_GetNameForSystem(recvdValue):NULL;
tag=AQH_Tag16IpcMsg_FindFirstTagByType(recvdMsg, AQH_MSGDATA_MULTIDATA_TAGS_DATA);
dataPoints=tag?((const uint64_t*)GWEN_Tag16_GetTagData(tag)):NULL;
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
valueDataFreeable=AQH_SetDataIpcMsg_ReadData(recvdMsg);
if (numberOfPoints>0) {
AQH_VALUE *value;
value=AQH_Storage_GetValueByNameForSystem(aqh->storage, valueName);
if (value) {
if (AQH_Value_GetValueType(value)==AQH_ValueType_Actor) {
union {double f; uint64_t i;} u;
u.i=dataPoints[1];
resultCode=_forwardDataToDriver(aqh, value, dataPoints[0], u.f);
}
else {
DBG_INFO(NULL, "Value \"%s\" is not an actor", valueName);
resultCode=AQH_MSG_IPC_ERROR_INVALID;
}
systemValue=AQH_Storage_GetValueByNameForSystem(aqh->storage, valueName);
if (systemValue) {
if (AQH_Value_GetValueType(systemValue)==AQH_ValueType_Actor) {
resultCode=_forwardDataToDriver(aqh, systemValue, valueDataFreeable);
}
else {
DBG_INFO(NULL, "Unknown value \"%s\"", valueName);
DBG_INFO(NULL, "Value \"%s\" is not an actor", valueName);
resultCode=AQH_MSG_IPC_ERROR_INVALID;
}
}
else {
DBG_INFO(NULL, "No datapoints");
DBG_INFO(NULL, "Unknown value \"%s\"", valueName);
resultCode=AQH_MSG_IPC_ERROR_INVALID;
}
AQH_Value_free(recvdValue);
free(valueDataFreeable);
outMsg=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_DATA_RESULT, resultCode);
GWEN_MsgEndpoint_AddSendMessage(epSrc, outMsg);
@@ -97,7 +83,7 @@ void AqHomeData_HandleSetData(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *epSrc, GWEN_M
int _forwardDataToDriver(AQHOME_DATA *aqh, const AQH_VALUE *v, uint64_t timestamp, double datapoint)
int _forwardDataToDriver(AQHOME_DATA *aqh, const AQH_VALUE *v, const char *data)
{
const char *driverName;
@@ -110,7 +96,7 @@ int _forwardDataToDriver(AQHOME_DATA *aqh, const AQH_VALUE *v, uint64_t timestam
GWEN_MSG *driverMsg;
DBG_INFO(AQH_LOGDOMAIN, "Sending SETDATA msg to driver endpoint (%s)", GWEN_MsgEndpoint_GetName(ep));
driverMsg=AQH_MultiDataDataIpcMsg_newForOne(AQH_MSGTYPE_IPC_DATA_SETDATA, v, timestamp, datapoint);
driverMsg=AQH_SetDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_SETDATA, v, data);
GWEN_MsgEndpoint_AddSendMessage(ep, driverMsg);
return AQH_MSG_IPC_SUCCESS;
}

View File

@@ -52,6 +52,7 @@
msg_data_getdata.h
msg_data_multidata.h
msg_data_values.h
msg_data_set.h
</headers>
@@ -69,6 +70,7 @@
msg_data_getdata.c
msg_data_multidata.c
msg_data_values.c
msg_data_set.c
</sources>

View File

@@ -31,7 +31,7 @@
#define AQH_MSGTYPE_IPC_DATA_UPDATEDATA 0x100 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_DATACHANGED 0x200 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x300 /* AQH_MultiDataDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_SETDATA 0x300 /* AQH_SetDataIpcMsg */
#define AQH_MSGTYPE_IPC_DATA_ADDVALUE 0x400 /* AQH_AddValueDataIpcMsg */

View File

@@ -0,0 +1,104 @@
/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 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_set.h>
#include <aqhome/ipc/data/ipc_data.h>
#include <aqhome/ipc/msg_ipc_tag16.h>
#include <gwenhywfar/msg.h>
#include <gwenhywfar/buffer.h>
#include <gwenhywfar/debug.h>
#include <gwenhywfar/msg_ipc.h>
#include <gwenhywfar/text.h>
#include <gwenhywfar/tag16.h>
#include <string.h>
#define AQH_MSGDATA_SET_MINSIZE GWEN_MSGIPC_OFFS_PAYLOAD
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* code
* ------------------------------------------------------------------------------------------------
*/
GWEN_MSG *AQH_SetDataIpcMsg_new(uint16_t code, const AQH_VALUE *value, const char *data)
{
GWEN_MSG *msg;
GWEN_BUFFER *buf;
int rv;
buf=GWEN_Buffer_new(0, 256, 0, 1);
rv=AQH_DataIpc_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_Tag16IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, code,
GWEN_Buffer_GetUsedBytes(buf), (const uint8_t*) GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
return msg;
}
void AQH_SetDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy)
{
AQH_Tag16IpcMsg_ExtendAndParse(msg, doCopy);
}
AQH_VALUE *AQH_SetDataIpcMsg_ReadValue(const GWEN_MSG *msg)
{
return AQH_DataIpc_ReadValueFromTagList(AQH_Tag16IpcMsg_GetTags(msg), AQH_MSGDATA_SET_TAGS_VALUE);
}
char *AQH_SetDataIpcMsg_ReadData(const GWEN_MSG *msg)
{
return AQH_Tag16IpcMsg_GetTagDataAsNewString(msg, AQH_MSGDATA_SET_TAGS_DATA, NULL);
}
void AQH_SetDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText)
{
if (GWEN_Msg_GetBytesInBuffer(msg)>=AQH_MSGDATA_SET_MINSIZE) {
GWEN_Buffer_AppendArgs(dbuf,
"SET (code=%d, proto=%d, proto version=%d)\n",
GWEN_IpcMsg_GetCode(msg),
GWEN_IpcMsg_GetProtoId(msg),
GWEN_IpcMsg_GetProtoVersion(msg));
}
}

View File

@@ -0,0 +1,38 @@
/****************************************************************************
* 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_SET_H
#define AQH_MSG_IPC_DATA_SET_H
#include <aqhome/api.h>
#include <aqhome/data/value.h>
#include <gwenhywfar/msg_ipc.h>
/**
*/
#define AQH_MSGDATA_SET_TAGS_VALUE 0xc1
#define AQH_MSGDATA_SET_TAGS_DATA 0x02
AQHOME_API GWEN_MSG *AQH_SetDataIpcMsg_new(uint16_t code, const AQH_VALUE *value, const char *data);
AQHOME_API void AQH_SetDataIpcMsg_Parse(GWEN_MSG *msg, int doCopy);
AQHOME_API AQH_VALUE *AQH_SetDataIpcMsg_ReadValue(const GWEN_MSG *msg);
AQHOME_API char *AQH_SetDataIpcMsg_ReadData(const GWEN_MSG *msg);
AQHOME_API void AQH_SetDataIpcMsg_DumpToBuffer(const GWEN_MSG *msg, GWEN_BUFFER *dbuf, const char *sText);
#endif