From 49d037c040b33ae691fd8afb99beb6213067c673 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Thu, 26 Sep 2024 21:11:33 +0200 Subject: [PATCH] more work on data and nodes service. --- apps/aqhome-data/loop.c | 1 + apps/aqhome-nodes/db.c | 82 +++++++++++++++++++++++++++++ apps/aqhome-nodes/loop_tty_broker.c | 4 +- aqhome/ipc/data/ipc_data.c | 7 +++ aqhome/ipc/endpoint_ipc.c | 16 +++++- aqhome/ipc/endpoint_ipc.h | 2 + aqhome/ipc/msg_ipc_result.h | 1 + 7 files changed, 111 insertions(+), 2 deletions(-) diff --git a/apps/aqhome-data/loop.c b/apps/aqhome-data/loop.c index 6c217dc..cbdb418 100644 --- a/apps/aqhome-data/loop.c +++ b/apps/aqhome-data/loop.c @@ -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)); diff --git a/apps/aqhome-nodes/db.c b/apps/aqhome-nodes/db.c index 7da6020..a90fab9 100644 --- a/apps/aqhome-nodes/db.c +++ b/apps/aqhome-nodes/db.c @@ -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 #include @@ -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"); diff --git a/apps/aqhome-nodes/loop_tty_broker.c b/apps/aqhome-nodes/loop_tty_broker.c index 30923aa..0dced0b 100644 --- a/apps/aqhome-nodes/loop_tty_broker.c +++ b/apps/aqhome-nodes/loop_tty_broker.c @@ -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, diff --git a/aqhome/ipc/data/ipc_data.c b/aqhome/ipc/data/ipc_data.c index eb93405..f76c284 100644 --- a/aqhome/ipc/data/ipc_data.c +++ b/aqhome/ipc/data/ipc_data.c @@ -32,6 +32,7 @@ #define AQH_IPCDATA_VALUE_TAGS_TIMEOFCREATION 0x07 #define AQH_IPCDATA_VALUE_TAGS_DEVFORDRIVER 0x08 #define AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM 0x09 +#define AQH_IPCDATA_VALUE_TAGS_MODALITY 0x0a #define AQH_IPCDATA_DEVICE_TAGS_ID 0x01 #define AQH_IPCDATA_DEVICE_TAGS_DRIVER 0x02 @@ -196,6 +197,9 @@ void _writeValueFieldsAsTagsToBuffer(const AQH_VALUE *value, GWEN_BUFFER *buf) s=AQH_Value_GetDeviceNameForSystem(value); if (s && *s) GWEN_Tag16_WriteStringTagToBuffer(AQH_IPCDATA_VALUE_TAGS_DEVFORSYSTEM, s, buf); + + GWEN_Tag16_WriteUint32TagToBuffer(AQH_IPCDATA_VALUE_TAGS_MODALITY, AQH_Value_GetModality(value), buf); + } @@ -347,6 +351,9 @@ AQH_VALUE *_readValueFromTag(const uint8_t *ptr, uint32_t len) AQH_Value_SetDeviceNameForSystem(value, s); free(s); break; + case AQH_IPCDATA_VALUE_TAGS_MODALITY: + AQH_Value_SetModality(value, GWEN_Tag16_GetTagDataAsUint32(tag, 0)); + break; default: DBG_INFO(AQH_LOGDOMAIN, "Unhandled tag typ %d (%02x)", tagType, tagType); break; diff --git a/aqhome/ipc/endpoint_ipc.c b/aqhome/ipc/endpoint_ipc.c index ed210c6..486d225 100644 --- a/aqhome/ipc/endpoint_ipc.c +++ b/aqhome/ipc/endpoint_ipc.c @@ -13,7 +13,10 @@ #include "aqhome/ipc/endpoint_ipc_p.h" +#include "aqhome/ipc/msg_ipc_result.h" + #include +#include #include @@ -50,7 +53,7 @@ void AQH_IpcEndpoint_Extend(GWEN_MSG_ENDPOINT *ep) -void _freeData(void *bp, void *p) +void _freeData(GWEN_UNUSED void *bp, void *p) { AQH_ENDPOINT_IPC *xep; @@ -259,3 +262,14 @@ GWEN_MSG_ENDPOINT *AQH_IpcEndpoint_CreateIpcTcpServiceForSocket(GWEN_SOCKET *sk, +void AQH_IpcEndpoint_SendResponseResult(GWEN_MSG_ENDPOINT *ep, uint32_t refMsgId, uint16_t code, uint32_t resultCode) +{ + GWEN_MSG *msgOut; + uint32_t msgId; + + msgId=GWEN_MsgEndpoint_GetNextMessageId(ep); + msgOut=AQH_ResultIpcMsg_new(code, msgId, refMsgId, resultCode); + GWEN_MsgEndpoint_AddSendMessage(ep, msgOut); +} + + diff --git a/aqhome/ipc/endpoint_ipc.h b/aqhome/ipc/endpoint_ipc.h index f2f52da..444a3ba 100644 --- a/aqhome/ipc/endpoint_ipc.h +++ b/aqhome/ipc/endpoint_ipc.h @@ -55,6 +55,8 @@ AQHOME_API void AQH_IpcEndpoint_SetPassword(GWEN_MSG_ENDPOINT *ep, const char *s AQHOME_API uint32_t AQH_IpcEndpoint_GetPermissions(const GWEN_MSG_ENDPOINT *ep); AQHOME_API void AQH_IpcEndpoint_SetPermissions(GWEN_MSG_ENDPOINT *ep, uint32_t i); +AQHOME_API void AQH_IpcEndpoint_SendResponseResult(GWEN_MSG_ENDPOINT *ep, uint32_t refMsgId, uint16_t code, uint32_t resultCode); + #endif diff --git a/aqhome/ipc/msg_ipc_result.h b/aqhome/ipc/msg_ipc_result.h index 57557c9..9d54b6f 100644 --- a/aqhome/ipc/msg_ipc_result.h +++ b/aqhome/ipc/msg_ipc_result.h @@ -30,6 +30,7 @@ #define AQH_MSG_IPC_ERROR_BADDATA 5 #define AQH_MSG_IPC_ERROR_PERMS 6 #define AQH_MSG_IPC_ERROR_NOTFOUND 7 +#define AQH_MSG_IPC_ERROR_IO 8 AQHOME_API GWEN_MSG *AQH_ResultIpcMsg_new(uint16_t code, uint32_t msgId, uint32_t refMsgId, uint32_t resultCode);