more work on data and nodes service.

This commit is contained in:
Martin Preuss
2024-09-26 21:11:33 +02:00
parent b0b6efb1c3
commit 49d037c040
7 changed files with 111 additions and 2 deletions

View File

@@ -136,6 +136,7 @@ AQH_VALUE *AqHomeData_GetOrCreateValueForDriverWithTemplate(AQHOME_DATA *aqh,
AQH_Value_SetNameForSystem(v, GWEN_Buffer_GetStart(buf));
AQH_Value_SetValueUnits(v, AQH_Value_GetValueUnits(valueTemplate));
AQH_Value_SetValueType(v, AQH_Value_GetValueType(valueTemplate));
AQH_Value_SetModality(v, AQH_Value_GetModality(valueTemplate));
AQH_Value_SetTimestampCreation(v, (uint64_t) time(NULL));
if (device) {
AQH_Value_SetDeviceNameForSystem(v, AQH_Device_GetNameForSystem(device));

View File

@@ -14,6 +14,7 @@
#include "./db.h"
#include "./aqhomed_p.h"
#include "aqhome/aqhome.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_sendstats.h"
#include "aqhome/msg/msg_recvstats.h"
@@ -25,6 +26,9 @@
#include "aqhome/msg/msg_device.h"
#include "aqhome/msg/msg_flashready.h"
#include "aqhome/data/value.h"
#include "aqhome/ipc/data/ipc_data.h"
#include "aqhome/ipc/data/msg_data_values.h"
#include <gwenhywfar/gwenhywfar.h>
#include <gwenhywfar/args.h>
@@ -53,6 +57,10 @@ static AQH_NODE_INFO *_getOrCreateNodeAndUpdateUidAddr(AQHOMED *aqh, const GWEN_
static void _updateTimestampLastChange(AQH_NODE_INFO *ni);
static void _assignDeviceId(AQHOMED *aqh, AQH_NODE_INFO *ni, uint32_t uid);
static void _announceNodeValues(AQHOMED *aqh, const AQH_NODE_INFO *ni);
static void _setDeviceName(AQH_VALUE *value, uint32_t uid);
static void _announceValue(AQHOMED *aqh, uint32_t uid, const AQHNODE_VALUE *v);
@@ -240,6 +248,7 @@ void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg)
_assignDeviceId(aqh, ni, uid);
_updateTimestampLastChange(ni);
AQH_NodeDb_SetModified(aqh->nodeDb);
_announceNodeValues(aqh, ni);
}
else {
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");
@@ -248,6 +257,78 @@ void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg)
void _announceNodeValues(AQHOMED *aqh, const AQH_NODE_INFO *ni)
{
const char *devName;
devName=AQH_NodeInfo_GetDeviceId(ni);
if (devName) {
const AQHNODE_DEVICE *devInfo;
devInfo=AqHomed_GetDeviceDefByName(aqh, devName);
if (devInfo) {
const AQHNODE_VALUE_LIST *valueList;
valueList=AQHNODE_Device_GetValueList(devInfo);
if (valueList) {
const AQHNODE_VALUE *v;
v=AQHNODE_Value_List_First(valueList);
while(v) {
DBG_INFO(NULL, "Announcing value \"%08x/%s\" (%d=%s)",
AQH_NodeInfo_GetUid(ni), AQHNODE_Value_GetName(v),
AQHNODE_Value_GetModality(v),
AQH_ValueModality_toString(AQHNODE_Value_GetModality(v)));
_announceValue(aqh, AQH_NodeInfo_GetUid(ni), v);
v=AQHNODE_Value_List_Next(v);
}
}
}
else {
DBG_INFO(NULL, "Node type \"%s\" not in database", devName);
}
}
else {
DBG_INFO(NULL, "Node type not in database");
}
}
void _setDeviceName(AQH_VALUE *value, uint32_t uid)
{
GWEN_BUFFER *buf;
buf=GWEN_Buffer_new(0, 64, 0, 1);
GWEN_Buffer_AppendArgs(buf, "%08x", uid);
AQH_Value_SetDeviceName(value, GWEN_Buffer_GetStart(buf));
GWEN_Buffer_free(buf);
}
void _announceValue(AQHOMED *aqh, uint32_t uid, const AQHNODE_VALUE *v)
{
AQH_VALUE *value;
GWEN_MSG *msg;
value=AQH_Value_new();
_setDeviceName(value, uid);
AQH_Value_SetDriver(value, "nodes");
AQH_Value_SetName(value, AQHNODE_Value_GetName(v));
AQH_Value_SetValueUnits(value, AQHNODE_Value_GetValueUnits(v));
AQH_Value_SetValueType(value, AQHNODE_Value_GetValueType(v));
AQH_Value_SetModality(value, AQHNODE_Value_GetModality(v));
msg=AQH_ValuesDataIpcMsg_newForOneValue(AQH_MSGTYPE_IPC_DATA_ANNOUNCEVALUE,
GWEN_MsgEndpoint_GetNextMessageId(aqh->brokerEndpoint), 0,
0, value);
GWEN_MsgEndpoint_AddSendMessage(aqh->brokerEndpoint, msg);
AQH_Value_free(value);
}
void _handleMsgFlashReady(AQHOMED *aqh, const GWEN_MSG *msg)
{
AQH_NODE_INFO *ni;
@@ -271,6 +352,7 @@ void _handleMsgFlashReady(AQHOMED *aqh, const GWEN_MSG *msg)
_assignDeviceId(aqh, ni, uid);
_updateTimestampLastChange(ni);
AQH_NodeDb_SetModified(aqh->nodeDb);
_announceNodeValues(aqh, ni);
}
else {
DBG_INFO(AQH_LOGDOMAIN, "Error handling message");

View File

@@ -16,6 +16,7 @@
#include "./tty_log.h"
#include "./db.h"
#include "aqhome/aqhome.h"
#include "aqhome/msg/endpoint_tty.h"
#include "aqhome/msg/msg_node.h"
#include "aqhome/msg/msg_value2.h"
@@ -204,7 +205,8 @@ void _publishDouble(AQHOMED *aqh, uint32_t uid, const char *vPath, int vModality
_setDeviceName(value, uid);
AQH_Value_SetName(value, vPath);
AQH_Value_SetValueUnits(value, vUnits);
AQH_Value_SetValueType(value, vModality);
AQH_Value_SetValueType(value, AQH_ValueType_Sensor);
AQH_Value_SetModality(value, vModality);
pubMsg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_UPDATEDATA,
GWEN_MsgEndpoint_GetNextMessageId(aqh->brokerEndpoint), 0,