diff --git a/aqhome/0BUILD b/aqhome/0BUILD index 6dcdcaf..6eccb1f 100644 --- a/aqhome/0BUILD +++ b/aqhome/0BUILD @@ -43,7 +43,7 @@ - + api.h aqhome.h serial.h @@ -92,7 +92,13 @@ msgendpointmanager.c + + nodes + + + + aqhnodes @@ -100,10 +106,6 @@ - - - - diff --git a/aqhome/libtest.c b/aqhome/libtest.c index 203a243..12ee904 100644 --- a/aqhome/libtest.c +++ b/aqhome/libtest.c @@ -404,7 +404,7 @@ int testEndpoints() AQH_MsgEndpointMgr_AddEndpoint(emgr, epLog); for (;;) { - DBG_INFO(AQH_LOGDOMAIN, "Next loop"); + DBG_DEBUG(AQH_LOGDOMAIN, "Next loop"); AQH_MsgEndpointMgr_LoopOnce(emgr); } diff --git a/aqhome/msgendpoint.c b/aqhome/msgendpoint.c index 9d9a2cb..003bf94 100644 --- a/aqhome/msgendpoint.c +++ b/aqhome/msgendpoint.c @@ -454,7 +454,7 @@ int _internalHandleReadable(AQH_MSG_ENDPOINT *ep) int len; int i; - DBG_INFO(AQH_LOGDOMAIN, "Reading from endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "Reading from endpoint %s", AQH_MsgEndpoint_GetName(ep)); do { rv=read(ep->fd, buffer, sizeof(buffer)); } while( (rv<0) && errno==EINTR); @@ -519,7 +519,7 @@ int _internalHandleWritable(AQH_MSG_ENDPOINT *ep, AQH_MSG_ENDPOINT_MGR *emgr) { AQH_MSG *msg; - DBG_INFO(AQH_LOGDOMAIN, "Writing to endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "Writing to endpoint %s", AQH_MsgEndpoint_GetName(ep)); msg=AQH_Msg_List_First(ep->sendMessageList); if (msg) { uint8_t pos; diff --git a/aqhome/msgendpointmanager.c b/aqhome/msgendpointmanager.c index 1c22a67..b8304f8 100644 --- a/aqhome/msgendpointmanager.c +++ b/aqhome/msgendpointmanager.c @@ -110,44 +110,44 @@ int _ioLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr) tv.tv_sec=2; tv.tv_usec=0; - DBG_INFO(AQH_LOGDOMAIN, "Sampling sockets"); + DBG_DEBUG(AQH_LOGDOMAIN, "Sampling sockets"); ep=AQH_MsgEndpoint_List_First(emgr->endpointList); if (ep==NULL) { DBG_ERROR(AQH_LOGDOMAIN, "No endpoints."); return GWEN_ERROR_GENERIC; } while(ep) { - DBG_INFO(AQH_LOGDOMAIN, "- checking endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "- checking endpoint %s", AQH_MsgEndpoint_GetName(ep)); if (!(AQH_MsgEndpoint_GetFlags(ep) & AQH_MSG_ENDPOINT_FLAGS_NOIO)) { int fd; fd=AQH_MsgEndpoint_GetReadFd(ep); if (fd>=0) { - DBG_INFO(AQH_LOGDOMAIN, " - adding socket %d for read", fd); + DBG_DEBUG(AQH_LOGDOMAIN, " - adding socket %d for read", fd); FD_SET(fd, &readSet); highestRdFd=(fd>highestRdFd)?fd:highestRdFd; } fd=AQH_MsgEndpoint_GetWriteFd(ep); if (fd>=0) { - DBG_INFO(AQH_LOGDOMAIN, " - adding socket %d for write", fd); + DBG_DEBUG(AQH_LOGDOMAIN, " - adding socket %d for write", fd); FD_SET(fd, &writeSet); highestWrFd=(fd>highestWrFd)?fd:highestWrFd; } } else { - DBG_INFO(AQH_LOGDOMAIN, " - endpoint %s does not support IO", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s does not support IO", AQH_MsgEndpoint_GetName(ep)); } ep=AQH_MsgEndpoint_List_Next(ep); } - DBG_INFO(AQH_LOGDOMAIN, "Calling select (highest read socket: %d, highest write socket: %d)", highestRdFd, highestWrFd); + DBG_DEBUG(AQH_LOGDOMAIN, "Calling select (highest read socket: %d, highest write socket: %d)", highestRdFd, highestWrFd); rv=select(((highestRdFd>highestWrFd)?highestRdFd:highestWrFd)+1, (highestRdFd<0)?NULL:&readSet, (highestWrFd<0)?NULL:&writeSet, NULL, &tv); - DBG_INFO(AQH_LOGDOMAIN, "Return from select (%d, %d=%s)", rv, (rv<0)?errno:0, (rv<0)?strerror(errno):"no error"); + DBG_DEBUG(AQH_LOGDOMAIN, "Return from select (%d, %d=%s)", rv, (rv<0)?errno:0, (rv<0)?strerror(errno):"no error"); if (rv<0) { if (errno!=EINTR) { DBG_ERROR(AQH_LOGDOMAIN, "Error on select"); @@ -156,11 +156,11 @@ int _ioLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr) } else if (rv==0) { /* timeout */ - DBG_INFO(AQH_LOGDOMAIN, "timeout"); + DBG_DEBUG(AQH_LOGDOMAIN, "timeout"); return GWEN_ERROR_TRY_AGAIN; } else if (rv) { - DBG_INFO(AQH_LOGDOMAIN, "Letting all endpoints handle IO"); + DBG_DEBUG(AQH_LOGDOMAIN, "Letting all endpoints handle IO"); ep=AQH_MsgEndpoint_List_First(emgr->endpointList); while(ep) { AQH_MSG_ENDPOINT *epNext; @@ -170,19 +170,19 @@ int _ioLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr) epNext=AQH_MsgEndpoint_List_Next(ep); fd=AQH_MsgEndpoint_GetFd(ep); if (fd!=-1 && FD_ISSET(fd, &readSet)) { - DBG_INFO(AQH_LOGDOMAIN, "- endpoint(%s): read", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "- endpoint(%s): read", AQH_MsgEndpoint_GetName(ep)); rv=AQH_MsgEndpoint_HandleReadable(ep, emgr); if (rv<0 && rv!=GWEN_ERROR_TRY_AGAIN) { - DBG_INFO(AQH_LOGDOMAIN, "error, removing endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "error, removing endpoint %s", AQH_MsgEndpoint_GetName(ep)); fd=-1; AQH_MsgEndpointMgr_DelEndpoint(emgr, ep); } } if (fd!=-1 && FD_ISSET(fd, &writeSet)) { - DBG_INFO(AQH_LOGDOMAIN, "- endpoint(%s): write", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "- endpoint(%s): write", AQH_MsgEndpoint_GetName(ep)); rv=AQH_MsgEndpoint_HandleWritable(ep, emgr); if (rv<0 && rv!=GWEN_ERROR_TRY_AGAIN) { - DBG_INFO(AQH_LOGDOMAIN, "error, removing endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "error, removing endpoint %s", AQH_MsgEndpoint_GetName(ep)); fd=-1; AQH_MsgEndpointMgr_DelEndpoint(emgr, ep); } @@ -200,12 +200,12 @@ void _msgLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr) { AQH_MSG_ENDPOINT *ep; - DBG_INFO(AQH_LOGDOMAIN, "Handle endpoint messages"); + DBG_DEBUG(AQH_LOGDOMAIN, "Handle endpoint messages"); ep=AQH_MsgEndpoint_List_First(emgr->endpointList); while(ep) { AQH_MSG *msg; - DBG_INFO(AQH_LOGDOMAIN, "- endpoint(%s)", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "- endpoint(%s)", AQH_MsgEndpoint_GetName(ep)); while( (msg=AQH_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) { uint32_t msgGroup; @@ -216,12 +216,12 @@ void _msgLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr) if (msgGroup & AQH_MSG_ENDPOINT_MSGGROUP_ADMIN) { if (!(AQH_MsgEndpoint_GetGroupId(ep) & AQH_MSG_ENDPOINT_ENDPOINTGROUP_BUS)) { /* only handle admin messages not from nodes */ - DBG_INFO(AQH_LOGDOMAIN, " - handling admin message"); + DBG_DEBUG(AQH_LOGDOMAIN, " - handling admin message"); _handleAdminMsg(emgr, ep, msg); } } else { - DBG_INFO(AQH_LOGDOMAIN, " - distributing message"); + DBG_DEBUG(AQH_LOGDOMAIN, " - distributing message"); _distributeMsg(emgr, ep, msg); } AQH_Msg_free(msg); @@ -237,13 +237,13 @@ void _runAllEndpoints(AQH_MSG_ENDPOINT_MGR *emgr) { AQH_MSG_ENDPOINT *ep; - DBG_INFO(AQH_LOGDOMAIN, "Running all endpoints"); + DBG_DEBUG(AQH_LOGDOMAIN, "Running all endpoints"); ep=AQH_MsgEndpoint_List_First(emgr->endpointList); while(ep) { AQH_MSG_ENDPOINT *next; next=AQH_MsgEndpoint_List_Next(ep); - DBG_INFO(AQH_LOGDOMAIN, "- running endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "- running endpoint %s", AQH_MsgEndpoint_GetName(ep)); AQH_MsgEndpoint_Run(ep); ep=next; } @@ -266,7 +266,7 @@ void _distributeMsg(AQH_MSG_ENDPOINT_MGR *emgr, AQH_MSG_ENDPOINT *srcEp, const A uint32_t acceptedGroupIds; uint32_t acceptedMsgGroups; - DBG_INFO(AQH_LOGDOMAIN, "- checking endpoint %s", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, "- checking endpoint %s", AQH_MsgEndpoint_GetName(ep)); acceptedGroupIds=AQH_MsgEndpoint_GetAcceptedMsgGroups(ep); acceptedMsgGroups=AQH_MsgEndpoint_GetAcceptedMsgGroups(ep); @@ -276,11 +276,11 @@ void _distributeMsg(AQH_MSG_ENDPOINT_MGR *emgr, AQH_MSG_ENDPOINT *srcEp, const A (acceptedGroupIds & srcGroupId) ) { /* endpoint accepts this message */ - DBG_INFO(AQH_LOGDOMAIN, " - endpoint %s accepts message", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s accepts message", AQH_MsgEndpoint_GetName(ep)); AQH_MsgEndpoint_AddSendMessage(ep, AQH_Msg_dup(msg)); } else { - DBG_INFO(AQH_LOGDOMAIN, " - endpoint %s does not accept message", AQH_MsgEndpoint_GetName(ep)); + DBG_DEBUG(AQH_LOGDOMAIN, " - endpoint %s does not accept message", AQH_MsgEndpoint_GetName(ep)); } } ep=AQH_MsgEndpoint_List_Next(ep); diff --git a/aqhome/nodes/0BUILD b/aqhome/nodes/0BUILD new file mode 100644 index 0000000..9fe22c2 --- /dev/null +++ b/aqhome/nodes/0BUILD @@ -0,0 +1,83 @@ + + + + + + + + $(gwenhywfar_cflags) + -I$(topsrcdir) + -I$(topbuilddir) + + + + --include=$(builddir) + --include=$(srcdir) + + + + + + $(visibility_cflags) + + + + --api=AQHOME_API + + + + nodeinfo.t2d + + + + nodeinfo.c + + + + nodeinfo.h + + + + + nodeinfo_p.h + + + + + $(local/built_headers_pub) + + + + + nodedb.h + + + + + nodedb_p.h + + + + + $(local/typefiles) + + nodedb.c + + + + + + + + + + + + + + + + + + + diff --git a/aqhome/nodes/nodedb.c b/aqhome/nodes/nodedb.c new file mode 100644 index 0000000..b1b3b95 --- /dev/null +++ b/aqhome/nodes/nodedb.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * 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 +#endif + +#include "aqhome/nodes/nodedb_p.h" + +#include +#include + + + + +AQH_NODE_DB *AQH_NodeDb_new() +{ + AQH_NODE_DB *ndb; + + GWEN_NEW_OBJECT(AQH_NODE_DB, ndb); + ndb->nodeList=AQH_NodeInfo_List_new(); + return ndb; +} + + + +void AQH_NodeDb_free(AQH_NODE_DB *ndb) +{ + if (ndb) { + AQH_NodeInfo_List_free(ndb->nodeList); + GWEN_FREE_OBJECT(ndb); + } +} + + + +AQH_NODE_INFO_LIST *AQH_NodeDb_GetAllNodeInfos(AQH_NODE_DB *ndb) +{ + return ndb->nodeList; +} + + + +int AQH_NodeDb_AddNodeInfo(AQH_NODE_DB *ndb, AQH_NODE_INFO *ni) +{ + uint32_t uid; + uint8_t busAddr; + + uid=AQH_NodeInfo_GetUid(ni); + if (uid==0) { + DBG_ERROR(AQH_LOGDOMAIN, "Not adding node without UID"); + return GWEN_ERROR_INVALID; + } + if (AQH_NodeDb_GetNodeInfoByUid(ndb, uid)) { + DBG_ERROR(AQH_LOGDOMAIN, "A node with the given UID \"%08x\" already exists", (unsigned int) uid); + return GWEN_ERROR_INVALID; + } + + busAddr=AQH_NodeInfo_GetBusAddress(ni); + if (busAddr==0) { + DBG_ERROR(AQH_LOGDOMAIN, "Not adding node without BUSADDR"); + return GWEN_ERROR_INVALID; + } + if (AQH_NodeDb_GetNodeInfoByBusAddr(ndb, busAddr)) { + DBG_ERROR(AQH_LOGDOMAIN, "A node with the given BUSADDR \"%02x\" already exists", busAddr); + return GWEN_ERROR_INVALID; + } + + DBG_INFO(AQH_LOGDOMAIN, "Adding node UID=%08x BUSADDR=%02x", (unsigned int) uid, busAddr); + AQH_NodeInfo_List_Add(ni, ndb->nodeList); + return 0; +} + + + +AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByBusAddr(AQH_NODE_DB *ndb, uint8_t busAddr) +{ + AQH_NODE_INFO *ni; + + ni=AQH_NodeInfo_List_First(ndb->nodeList); + while(ni) { + if (busAddr==0 || busAddr==AQH_NodeInfo_GetBusAddress(ni)) + return ni; + ni=AQH_NodeInfo_List_Next(ni); + } + + return NULL; +} + + + +AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByUid(AQH_NODE_DB *ndb, uint32_t uid) +{ + AQH_NODE_INFO *ni; + + ni=AQH_NodeInfo_List_First(ndb->nodeList); + while(ni) { + if (uid==0 || uid==AQH_NodeInfo_GetUid(ni)) + return ni; + ni=AQH_NodeInfo_List_Next(ni); + } + + return NULL; +} + + + +AQH_NODE_INFO_LIST *AQH_NodeDb_GetNodeInfosByNodeType(AQH_NODE_DB *ndb, int t) +{ + AQH_NODE_INFO_LIST *resultList; + AQH_NODE_INFO *ni; + + resultList=AQH_NodeInfo_List_new(); + ni=AQH_NodeInfo_List_First(ndb->nodeList); + while(ni) { + if (t==0 || t==AQH_NodeInfo_GetNodeType(ni)) + AQH_NodeInfo_List_Add(AQH_NodeInfo_dup(ni), resultList); + ni=AQH_NodeInfo_List_Next(ni); + } + + if (AQH_NodeInfo_List_GetCount(resultList)<1) { + AQH_NodeInfo_List_free(resultList); + return NULL; + } + + return resultList; +} + + + + + diff --git a/aqhome/nodes/nodedb.h b/aqhome/nodes/nodedb.h new file mode 100644 index 0000000..5076548 --- /dev/null +++ b/aqhome/nodes/nodedb.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * 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 AQH_NODEDB_H +#define AQH_NODEDB_H + + +#include +#include + +#include + + +typedef struct AQH_NODE_DB AQH_NODE_DB; + + +AQHOME_API AQH_NODE_DB *AQH_NodeDb_new(); +AQHOME_API void AQH_NodeDb_free(AQH_NODE_DB *ndb); + +AQHOME_API AQH_NODE_INFO_LIST *AQH_NodeDb_GetAllNodeInfos(AQH_NODE_DB *ndb); +AQHOME_API int AQH_NodeDb_AddNodeInfo(AQH_NODE_DB *ndb, AQH_NODE_INFO *ni); + +AQHOME_API AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByBusAddr(AQH_NODE_DB *ndb, uint8_t busAddr); +AQHOME_API AQH_NODE_INFO *AQH_NodeDb_GetNodeInfoByUid(AQH_NODE_DB *ndb, uint32_t uid); +AQHOME_API AQH_NODE_INFO_LIST *AQH_NodeDb_GetNodeInfosByNodeType(AQH_NODE_DB *ndb, int t); + + + +#endif + diff --git a/aqhome/nodes/nodedb_p.h b/aqhome/nodes/nodedb_p.h new file mode 100644 index 0000000..ab678e1 --- /dev/null +++ b/aqhome/nodes/nodedb_p.h @@ -0,0 +1,23 @@ +/**************************************************************************** + * 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 AQH_NODEDB_P_H +#define AQH_NODEDB_P_H + + +#include "aqhome/nodes/nodedb.h" + + +struct AQH_NODE_DB { + AQH_NODE_INFO_LIST *nodeList; + +}; + + +#endif + diff --git a/aqhome/nodes/nodeinfo.t2d b/aqhome/nodes/nodeinfo.t2d new file mode 100644 index 0000000..6b55043 --- /dev/null +++ b/aqhome/nodes/nodeinfo.t2d @@ -0,0 +1,73 @@ + + + + + + + + AQH_NODE_INFO + AQH_NodeInfo + nodeinfo + + + with_xml + with_db + with_list1 + with_list2 + + + +
aqhome/api.h
+
+ + + + + + +
+ + + + + + 0 + 0 + sortByMember + public + + + + 0 + 0 + public + + + + + 0 + 0 + public + + + + + 0 + 0 + public + + + + + 0 + 0 + public + + + + + +
+ +
+