Implemented setdata in server and aqhome-tool.
This commit is contained in:
@@ -45,6 +45,7 @@
|
||||
c_getvalues.h
|
||||
c_getdatapoints.h
|
||||
c_getlastdatapoint.h
|
||||
c_setdata.h
|
||||
</headers>
|
||||
|
||||
<sources>
|
||||
@@ -59,6 +60,7 @@
|
||||
c_getvalues.c
|
||||
c_getdatapoints.c
|
||||
c_getlastdatapoint.c
|
||||
c_setdata.c
|
||||
main.c
|
||||
</sources>
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
@@ -47,58 +48,63 @@ void AqHomeData_HandleGetLastDataPoint(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep,
|
||||
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;
|
||||
uint64_t timestamp=0;
|
||||
union {double f; uint64_t i;} u;
|
||||
int rv;
|
||||
|
||||
valueId=AQH_Value_GetId(value);
|
||||
rv=AQH_Storage_GetLastDataPoint(aqh->storage, valueId, ×tamp, &(u.f));
|
||||
if (rv<0) {
|
||||
switch(rv) {
|
||||
case GWEN_ERROR_INVALID: resultCode=AQH_MSG_IPC_ERROR_INVALID; break;
|
||||
case GWEN_ERROR_NO_DATA: resultCode=AQH_MSG_IPC_ERROR_NODATA; break;
|
||||
default: resultCode=AQH_MSG_IPC_ERROR_GENERIC; break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint64_t array[2];
|
||||
|
||||
array[0]=timestamp;
|
||||
array[1]=u.i;
|
||||
outMsg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP, AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG,
|
||||
valueId,
|
||||
AQH_Value_GetNameForSystem(value),
|
||||
AQH_Value_GetValueUnits(value),
|
||||
array, 1);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
|
||||
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;
|
||||
uint64_t timestamp=0;
|
||||
union {double f; uint64_t i;} u;
|
||||
int rv;
|
||||
|
||||
valueId=AQH_Value_GetId(value);
|
||||
rv=AQH_Storage_GetLastDataPoint(aqh->storage, valueId, ×tamp, &(u.f));
|
||||
if (rv<0) {
|
||||
switch(rv) {
|
||||
case GWEN_ERROR_INVALID: resultCode=AQH_MSG_IPC_ERROR_INVALID; break;
|
||||
case GWEN_ERROR_NO_DATA: resultCode=AQH_MSG_IPC_ERROR_NODATA; break;
|
||||
default: resultCode=AQH_MSG_IPC_ERROR_GENERIC; break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint64_t array[2];
|
||||
|
||||
array[0]=timestamp;
|
||||
array[1]=u.i;
|
||||
outMsg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETLASTDATA_RSP, AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG,
|
||||
valueId,
|
||||
AQH_Value_GetNameForSystem(value),
|
||||
AQH_Value_GetValueUnits(value),
|
||||
array, 1);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
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);
|
||||
}
|
||||
|
||||
131
apps/aqhome-data/c_setdata.c
Normal file
131
apps/aqhome-data/c_setdata.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/****************************************************************************
|
||||
* 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 "./c_setdata.h"
|
||||
#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>
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* defines
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
void AqHomeData_HandleSetData(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *recvdMsg)
|
||||
{
|
||||
GWEN_MSG *outMsg;
|
||||
int resultCode=AQH_MSG_IPC_SUCCESS;
|
||||
|
||||
if (AQH_IpcEndpoint_GetPermissions(ep) & AQH_IPCENDPOINT_PERMS_SETDATA) {
|
||||
if (AQH_DataPointsDataIpcMsg_IsValid(recvdMsg)) {
|
||||
uint32_t numValues;
|
||||
|
||||
numValues=AQH_DataPointsDataIpcMsg_GetNumValues(recvdMsg);
|
||||
if (numValues==1) {
|
||||
const char *s;
|
||||
|
||||
s=AQH_DataPointsDataIpcMsg_GetValueName(recvdMsg);
|
||||
if (s && *s) {
|
||||
AQH_VALUE *v;
|
||||
|
||||
v=AQH_Storage_GetValueByNameForSystem(aqh->storage, s);
|
||||
if (v==NULL) {
|
||||
resultCode=AQH_MSG_IPC_ERROR_NOTFOUND;
|
||||
}
|
||||
else {
|
||||
const uint64_t *dataPoints;
|
||||
|
||||
dataPoints=AQH_DataPointsDataIpcMsg_GetDataPoints(recvdMsg);
|
||||
if (dataPoints) {
|
||||
const char *driverName;
|
||||
|
||||
driverName=AQH_Value_GetDriver(v);
|
||||
if (driverName && *driverName) {
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
|
||||
ep=AqHomeData_GetIpcEndpointByServiceName(aqh, driverName);
|
||||
if (ep) {
|
||||
GWEN_MSG *driverMsg;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Sending SETDATA msg to driver endpoint (%s)", GWEN_MsgEndpoint_GetName(ep));
|
||||
driverMsg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_SETDATA,
|
||||
0, /* flags */
|
||||
AQH_Value_GetId(v),
|
||||
AQH_Value_GetNameForDriver(v),
|
||||
AQH_Value_GetValueUnits(v),
|
||||
dataPoints, numValues);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, driverMsg);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Driver \"%s\" not available", driverName);
|
||||
resultCode=AQH_MSG_IPC_ERROR_GENERIC;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "No driver name");
|
||||
resultCode=AQH_MSG_IPC_ERROR_GENERIC;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "No datapoints");
|
||||
resultCode=AQH_MSG_IPC_ERROR_BADDATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Value without name ");
|
||||
resultCode=AQH_MSG_IPC_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Invalid number of datapoints");
|
||||
resultCode=AQH_MSG_IPC_ERROR_BADDATA;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Invalid message received");
|
||||
resultCode=AQH_MSG_IPC_ERROR_BADDATA;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No permissions to set data");
|
||||
resultCode=AQH_MSG_IPC_ERROR_PERMS;
|
||||
}
|
||||
|
||||
outMsg=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_DATA_RESULT, resultCode);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
25
apps/aqhome-data/c_setdata.h
Normal file
25
apps/aqhome-data/c_setdata.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/****************************************************************************
|
||||
* 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 AQHOME_DATA_C_SETDATA_H
|
||||
#define AQHOME_DATA_C_SETDATA_H
|
||||
|
||||
|
||||
#include "./aqhome_data.h"
|
||||
|
||||
|
||||
void AqHomeData_HandleSetData(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *recvdMsg);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include "./c_getdatapoints.h"
|
||||
#include "./c_getlastdatapoint.h"
|
||||
#include "./c_getvalues.h"
|
||||
#include "./c_setdata.h"
|
||||
#include "./aqhome_data_p.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/data/msg_data_values.h"
|
||||
@@ -134,6 +135,7 @@ void _handleIpcMsg(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
||||
case AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ: AqHomeData_HandleGetValues(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_DATA_GETDATA_REQ: AqHomeData_HandleGetDataPoints(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_DATA_GETLASTDATA_REQ: AqHomeData_HandleGetLastDataPoint(aqh, ep, msg); break;
|
||||
case AQH_MSGTYPE_IPC_DATA_SETDATA: AqHomeData_HandleSetData(aqh, ep, msg); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user