Started working on aqhome-nodes which will replace aqhomed.
This commit is contained in:
@@ -15,9 +15,10 @@
|
||||
#include "./aqhome_data_p.h"
|
||||
#include "./loop.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/data/msg_data_datapoints.h"
|
||||
#include "aqhome/ipc/data/msg_data_multidata.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
#include "aqhome/ipc/msg_ipc_tag16.h"
|
||||
|
||||
#include <gwenhywfar/debug.h>
|
||||
|
||||
@@ -36,7 +37,7 @@
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _readDataPoints(AQHOME_DATA *aqh, const AQH_VALUE *v, const uint64_t *dataPoints, uint32_t numValues);
|
||||
static int _storeDataPoints(AQHOME_DATA *aqh, const AQH_VALUE *v, const uint64_t *dataPoints, int numValues);
|
||||
static void _sendDataChangedMsgToAllClients(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *epSrc, const AQH_VALUE *v,
|
||||
const uint64_t *dataPoints, uint32_t numValues);
|
||||
|
||||
@@ -51,63 +52,58 @@ void AqHomeData_HandleUpdateData(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const
|
||||
{
|
||||
GWEN_MSG *outMsg;
|
||||
int resultCode=AQH_MSG_IPC_SUCCESS;
|
||||
GWEN_TAG16_LIST *tagList;
|
||||
char *valueName=NULL;
|
||||
char *valueUnits=NULL;
|
||||
int valueType;
|
||||
const uint64_t *dataPoints=NULL;
|
||||
unsigned int numberOfPoints=0;
|
||||
|
||||
if (AQH_IpcEndpoint_GetPermissions(ep) & AQH_IPCENDPOINT_PERMS_ADDDATA) {
|
||||
if (AQH_DataPointsDataIpcMsg_IsValid(recvdMsg)) {
|
||||
uint32_t numValues;
|
||||
|
||||
numValues=AQH_DataPointsDataIpcMsg_GetNumValues(recvdMsg);
|
||||
if (numValues) {
|
||||
const char *s;
|
||||
|
||||
s=AQH_DataPointsDataIpcMsg_GetValueName(recvdMsg);
|
||||
if (s && *s) {
|
||||
AQH_VALUE *v;
|
||||
|
||||
v=AqHomeData_GetOrCreateValueForDriver(aqh, ep, s, AQH_DataPointsDataIpcMsg_GetUnits(recvdMsg), 0);
|
||||
if (v==NULL) {
|
||||
resultCode=AQH_MSG_IPC_ERROR_PERMS;
|
||||
}
|
||||
else {
|
||||
const uint64_t *dataPoints;
|
||||
|
||||
dataPoints=AQH_DataPointsDataIpcMsg_GetDataPoints(recvdMsg);
|
||||
if (dataPoints)
|
||||
resultCode=_readDataPoints(aqh, v, dataPoints, numValues);
|
||||
else {
|
||||
DBG_INFO(NULL, "No datapoints");
|
||||
resultCode=AQH_MSG_IPC_ERROR_BADDATA;
|
||||
}
|
||||
if (resultCode==AQH_MSG_IPC_SUCCESS)
|
||||
_sendDataChangedMsgToAllClients(aqh, ep, v, dataPoints, numValues);
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Value without name ");
|
||||
resultCode=AQH_MSG_IPC_ERROR_INVALID;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "No datapoints");
|
||||
resultCode=AQH_MSG_IPC_ERROR_BADDATA;
|
||||
}
|
||||
tagList=AQH_Tag16IpcMsg_ParseTags(recvdMsg, 0);
|
||||
if (tagList) {
|
||||
const GWEN_TAG16 *tag;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_NAME);
|
||||
valueName=tag?GWEN_Tag16_GetTagDataAsNewString(tag, NULL):NULL;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_UNITS);
|
||||
valueUnits=tag?GWEN_Tag16_GetTagDataAsNewString(tag, NULL):NULL;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_TYPE);
|
||||
valueType=tag?GWEN_Tag16_GetTagDataAsUint32(tag, 0):0;
|
||||
|
||||
tag=GWEN_Tag16_List_FindFirstByTagType(tagList, AQH_MSGDATA_MULTIDATA_TAGS_DATA);
|
||||
dataPoints=(const uint64_t*)GWEN_Tag16_GetTagData(tag);
|
||||
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
|
||||
}
|
||||
|
||||
if (numberOfPoints>0) {
|
||||
AQH_VALUE *value;
|
||||
|
||||
value=AqHomeData_GetOrCreateValueForDriver(aqh, ep, valueName, valueUnits, valueType);
|
||||
if (value) {
|
||||
resultCode=_storeDataPoints(aqh, value, dataPoints, numberOfPoints);
|
||||
if (resultCode==AQH_MSG_IPC_SUCCESS)
|
||||
_sendDataChangedMsgToAllClients(aqh, ep, value, dataPoints, numberOfPoints);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Invalid message received");
|
||||
resultCode=AQH_MSG_IPC_ERROR_BADDATA;
|
||||
DBG_INFO(NULL, "No permissions to add datapoint for value \"%s\"", valueName);
|
||||
resultCode=AQH_MSG_IPC_ERROR_PERMS;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(AQH_LOGDOMAIN, "No permissions to add data");
|
||||
resultCode=AQH_MSG_IPC_ERROR_PERMS;
|
||||
DBG_INFO(NULL, "No datapoints");
|
||||
resultCode=AQH_MSG_IPC_ERROR_INVALID;
|
||||
}
|
||||
free(valueName);
|
||||
|
||||
outMsg=AQH_ResultIpcMsg_new(AQH_MSGTYPE_IPC_DATA_RESULT, resultCode);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
|
||||
}
|
||||
|
||||
|
||||
int _readDataPoints(AQHOME_DATA *aqh, const AQH_VALUE *v, const uint64_t *dataPoints, uint32_t numValues)
|
||||
|
||||
int _storeDataPoints(AQHOME_DATA *aqh, const AQH_VALUE *v, const uint64_t *dataPoints, int numValues)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
@@ -145,13 +141,12 @@ void _sendDataChangedMsgToAllClients(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *epSrc,
|
||||
GWEN_MSG *msg;
|
||||
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Sending update msg to endpoint %s", GWEN_MsgEndpoint_GetName(ep));
|
||||
msg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_DATACHANGED,
|
||||
0, /* flags */
|
||||
AQH_Value_GetId(v),
|
||||
AQH_Value_GetNameForSystem(v),
|
||||
AQH_Value_GetValueUnits(v),
|
||||
dataPoints, numValues);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, msg);
|
||||
msg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_DATACHANGED,
|
||||
AQH_Value_GetNameForSystem(v),
|
||||
AQH_Value_GetValueUnits(v),
|
||||
AQH_Value_GetValueType(v),
|
||||
dataPoints, numValues);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, msg);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(AQH_LOGDOMAIN, "Endpoint %s doesn't want updates", GWEN_MsgEndpoint_GetName(ep));
|
||||
|
||||
Reference in New Issue
Block a user