Implemented setdata in server and aqhome-tool.

This commit is contained in:
Martin Preuss
2023-09-12 00:04:37 +02:00
parent 71f5ce8c7e
commit e1639a9d13
12 changed files with 570 additions and 93 deletions

View File

@@ -15,6 +15,7 @@
#include "./aqhome_data_p.h"
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/ipc/data/msg_data_datapoints.h"
#include "aqhome/ipc/endpoint_ipc.h"
#include "aqhome/ipc/msg_ipc_result.h"
#include <gwenhywfar/debug.h>
@@ -48,68 +49,73 @@ void AqHomeData_HandleGetDataPoints(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, con
GWEN_MSG *outMsg;
int resultCode=0;
if (AQH_DataPointsDataIpcMsg_IsValid(recvdMsg)) {
const char *valueName;
valueName=AQH_DataPointsDataIpcMsg_GetValueName(recvdMsg);
if (valueName) {
const AQH_VALUE *value;
value=AQH_Storage_GetValueByNameForSystem(aqh->storage, valueName);
if (value) {
uint64_t valueId;
uint32_t numValues;
uint64_t tsBegin=0;
uint64_t tsEnd=0;
uint64_t *tablePtr;
valueId=AQH_Value_GetId(value);
numValues=AQH_DataPointsDataIpcMsg_GetNumValues(recvdMsg);
if (numValues==1) {
const uint64_t *dataPoints;
dataPoints=AQH_DataPointsDataIpcMsg_GetDataPoints(recvdMsg);
tsBegin=dataPoints[0];
tsEnd=dataPoints[1];
}
tablePtr=AQH_Storage_GetDataPoints(aqh->storage, valueId, tsBegin, tsEnd, AQHOMEDATA_HANDLEGETDATAPOINTS_MAXTABLEENTRIES);
if (tablePtr) {
int numTableEntries;
int numDataPoints;
numTableEntries=(int)(tablePtr[0]);
numDataPoints=numTableEntries/2;
outMsg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG,
valueId,
AQH_Value_GetNameForSystem(value),
AQH_Value_GetValueUnits(value),
&(tablePtr[1]), numDataPoints);
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
free(tablePtr);
return;
if (AQH_IpcEndpoint_GetPermissions(ep) & AQH_IPCENDPOINT_PERMS_READDATA) {
if (AQH_DataPointsDataIpcMsg_IsValid(recvdMsg)) {
const char *valueName;
valueName=AQH_DataPointsDataIpcMsg_GetValueName(recvdMsg);
if (valueName) {
const AQH_VALUE *value;
value=AQH_Storage_GetValueByNameForSystem(aqh->storage, valueName);
if (value) {
uint64_t valueId;
uint32_t numValues;
uint64_t tsBegin=0;
uint64_t tsEnd=0;
uint64_t *tablePtr;
valueId=AQH_Value_GetId(value);
numValues=AQH_DataPointsDataIpcMsg_GetNumValues(recvdMsg);
if (numValues==1) {
const uint64_t *dataPoints;
dataPoints=AQH_DataPointsDataIpcMsg_GetDataPoints(recvdMsg);
tsBegin=dataPoints[0];
tsEnd=dataPoints[1];
}
tablePtr=AQH_Storage_GetDataPoints(aqh->storage, valueId, tsBegin, tsEnd, AQHOMEDATA_HANDLEGETDATAPOINTS_MAXTABLEENTRIES);
if (tablePtr) {
int numTableEntries;
int numDataPoints;
numTableEntries=(int)(tablePtr[0]);
numDataPoints=numTableEntries/2;
outMsg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG,
valueId,
AQH_Value_GetNameForSystem(value),
AQH_Value_GetValueUnits(value),
&(tablePtr[1]), numDataPoints);
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
free(tablePtr);
return;
}
else {
DBG_INFO(NULL, "No matching datapoints for value \"%s\"", valueName);
resultCode=AQH_MSG_IPC_ERROR_NODATA;
}
}
else {
DBG_INFO(NULL, "No matching datapoints for value \"%s\"", valueName);
resultCode=AQH_MSG_IPC_ERROR_NODATA;
DBG_INFO(NULL, "Value \"%s\" not found", valueName);
resultCode=AQH_MSG_IPC_ERROR_NOTFOUND;
}
}
else {
DBG_INFO(NULL, "Value \"%s\" not found", valueName);
resultCode=AQH_MSG_IPC_ERROR_NOTFOUND;
DBG_INFO(NULL, "No value name in request");
resultCode=AQH_MSG_IPC_ERROR_INVALID;
}
}
else {
DBG_INFO(NULL, "No value name in request");
DBG_INFO(NULL, "Invalid request message");
resultCode=AQH_MSG_IPC_ERROR_INVALID;
}
}
else {
DBG_INFO(NULL, "Invalid request message");
resultCode=AQH_MSG_IPC_ERROR_INVALID;
DBG_ERROR(AQH_LOGDOMAIN, "No permissions to read data");
resultCode=AQH_MSG_IPC_ERROR_PERMS;
}
outMsg=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_DATA_RESULT, resultCode);
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
}