aqhome: Added node db.
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
</setVar>
|
</setVar>
|
||||||
|
|
||||||
|
|
||||||
<headers dist="true" >
|
<headers dist="true" install="$(pkgincludedir)" >
|
||||||
api.h
|
api.h
|
||||||
aqhome.h
|
aqhome.h
|
||||||
serial.h
|
serial.h
|
||||||
@@ -92,7 +92,13 @@
|
|||||||
msgendpointmanager.c
|
msgendpointmanager.c
|
||||||
</sources>
|
</sources>
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
nodes
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
|
||||||
<useTargets>
|
<useTargets>
|
||||||
|
aqhnodes
|
||||||
</useTargets>
|
</useTargets>
|
||||||
|
|
||||||
<libraries>
|
<libraries>
|
||||||
@@ -100,10 +106,6 @@
|
|||||||
</libraries>
|
</libraries>
|
||||||
|
|
||||||
|
|
||||||
<subdirs>
|
|
||||||
</subdirs>
|
|
||||||
|
|
||||||
|
|
||||||
<extradist>
|
<extradist>
|
||||||
</extradist>
|
</extradist>
|
||||||
|
|
||||||
|
|||||||
@@ -404,7 +404,7 @@ int testEndpoints()
|
|||||||
AQH_MsgEndpointMgr_AddEndpoint(emgr, epLog);
|
AQH_MsgEndpointMgr_AddEndpoint(emgr, epLog);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "Next loop");
|
DBG_DEBUG(AQH_LOGDOMAIN, "Next loop");
|
||||||
AQH_MsgEndpointMgr_LoopOnce(emgr);
|
AQH_MsgEndpointMgr_LoopOnce(emgr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -454,7 +454,7 @@ int _internalHandleReadable(AQH_MSG_ENDPOINT *ep)
|
|||||||
int len;
|
int len;
|
||||||
int i;
|
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 {
|
do {
|
||||||
rv=read(ep->fd, buffer, sizeof(buffer));
|
rv=read(ep->fd, buffer, sizeof(buffer));
|
||||||
} while( (rv<0) && errno==EINTR);
|
} while( (rv<0) && errno==EINTR);
|
||||||
@@ -519,7 +519,7 @@ int _internalHandleWritable(AQH_MSG_ENDPOINT *ep, AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
{
|
{
|
||||||
AQH_MSG *msg;
|
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);
|
msg=AQH_Msg_List_First(ep->sendMessageList);
|
||||||
if (msg) {
|
if (msg) {
|
||||||
uint8_t pos;
|
uint8_t pos;
|
||||||
|
|||||||
@@ -110,44 +110,44 @@ int _ioLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
tv.tv_sec=2;
|
tv.tv_sec=2;
|
||||||
tv.tv_usec=0;
|
tv.tv_usec=0;
|
||||||
|
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "Sampling sockets");
|
DBG_DEBUG(AQH_LOGDOMAIN, "Sampling sockets");
|
||||||
ep=AQH_MsgEndpoint_List_First(emgr->endpointList);
|
ep=AQH_MsgEndpoint_List_First(emgr->endpointList);
|
||||||
if (ep==NULL) {
|
if (ep==NULL) {
|
||||||
DBG_ERROR(AQH_LOGDOMAIN, "No endpoints.");
|
DBG_ERROR(AQH_LOGDOMAIN, "No endpoints.");
|
||||||
return GWEN_ERROR_GENERIC;
|
return GWEN_ERROR_GENERIC;
|
||||||
}
|
}
|
||||||
while(ep) {
|
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)) {
|
if (!(AQH_MsgEndpoint_GetFlags(ep) & AQH_MSG_ENDPOINT_FLAGS_NOIO)) {
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
fd=AQH_MsgEndpoint_GetReadFd(ep);
|
fd=AQH_MsgEndpoint_GetReadFd(ep);
|
||||||
if (fd>=0) {
|
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);
|
FD_SET(fd, &readSet);
|
||||||
highestRdFd=(fd>highestRdFd)?fd:highestRdFd;
|
highestRdFd=(fd>highestRdFd)?fd:highestRdFd;
|
||||||
}
|
}
|
||||||
|
|
||||||
fd=AQH_MsgEndpoint_GetWriteFd(ep);
|
fd=AQH_MsgEndpoint_GetWriteFd(ep);
|
||||||
if (fd>=0) {
|
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);
|
FD_SET(fd, &writeSet);
|
||||||
highestWrFd=(fd>highestWrFd)?fd:highestWrFd;
|
highestWrFd=(fd>highestWrFd)?fd:highestWrFd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
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);
|
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,
|
rv=select(((highestRdFd>highestWrFd)?highestRdFd:highestWrFd)+1,
|
||||||
(highestRdFd<0)?NULL:&readSet,
|
(highestRdFd<0)?NULL:&readSet,
|
||||||
(highestWrFd<0)?NULL:&writeSet,
|
(highestWrFd<0)?NULL:&writeSet,
|
||||||
NULL,
|
NULL,
|
||||||
&tv);
|
&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 (rv<0) {
|
||||||
if (errno!=EINTR) {
|
if (errno!=EINTR) {
|
||||||
DBG_ERROR(AQH_LOGDOMAIN, "Error on select");
|
DBG_ERROR(AQH_LOGDOMAIN, "Error on select");
|
||||||
@@ -156,11 +156,11 @@ int _ioLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
}
|
}
|
||||||
else if (rv==0) {
|
else if (rv==0) {
|
||||||
/* timeout */
|
/* timeout */
|
||||||
DBG_INFO(AQH_LOGDOMAIN, "timeout");
|
DBG_DEBUG(AQH_LOGDOMAIN, "timeout");
|
||||||
return GWEN_ERROR_TRY_AGAIN;
|
return GWEN_ERROR_TRY_AGAIN;
|
||||||
}
|
}
|
||||||
else if (rv) {
|
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);
|
ep=AQH_MsgEndpoint_List_First(emgr->endpointList);
|
||||||
while(ep) {
|
while(ep) {
|
||||||
AQH_MSG_ENDPOINT *epNext;
|
AQH_MSG_ENDPOINT *epNext;
|
||||||
@@ -170,19 +170,19 @@ int _ioLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
epNext=AQH_MsgEndpoint_List_Next(ep);
|
epNext=AQH_MsgEndpoint_List_Next(ep);
|
||||||
fd=AQH_MsgEndpoint_GetFd(ep);
|
fd=AQH_MsgEndpoint_GetFd(ep);
|
||||||
if (fd!=-1 && FD_ISSET(fd, &readSet)) {
|
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);
|
rv=AQH_MsgEndpoint_HandleReadable(ep, emgr);
|
||||||
if (rv<0 && rv!=GWEN_ERROR_TRY_AGAIN) {
|
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;
|
fd=-1;
|
||||||
AQH_MsgEndpointMgr_DelEndpoint(emgr, ep);
|
AQH_MsgEndpointMgr_DelEndpoint(emgr, ep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fd!=-1 && FD_ISSET(fd, &writeSet)) {
|
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);
|
rv=AQH_MsgEndpoint_HandleWritable(ep, emgr);
|
||||||
if (rv<0 && rv!=GWEN_ERROR_TRY_AGAIN) {
|
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;
|
fd=-1;
|
||||||
AQH_MsgEndpointMgr_DelEndpoint(emgr, ep);
|
AQH_MsgEndpointMgr_DelEndpoint(emgr, ep);
|
||||||
}
|
}
|
||||||
@@ -200,12 +200,12 @@ void _msgLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
{
|
{
|
||||||
AQH_MSG_ENDPOINT *ep;
|
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);
|
ep=AQH_MsgEndpoint_List_First(emgr->endpointList);
|
||||||
while(ep) {
|
while(ep) {
|
||||||
AQH_MSG *msg;
|
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)) ) {
|
while( (msg=AQH_MsgEndpoint_TakeFirstReceivedMessage(ep)) ) {
|
||||||
uint32_t msgGroup;
|
uint32_t msgGroup;
|
||||||
|
|
||||||
@@ -216,12 +216,12 @@ void _msgLoopOnce(AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
if (msgGroup & AQH_MSG_ENDPOINT_MSGGROUP_ADMIN) {
|
if (msgGroup & AQH_MSG_ENDPOINT_MSGGROUP_ADMIN) {
|
||||||
if (!(AQH_MsgEndpoint_GetGroupId(ep) & AQH_MSG_ENDPOINT_ENDPOINTGROUP_BUS)) {
|
if (!(AQH_MsgEndpoint_GetGroupId(ep) & AQH_MSG_ENDPOINT_ENDPOINTGROUP_BUS)) {
|
||||||
/* only handle admin messages not from nodes */
|
/* 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);
|
_handleAdminMsg(emgr, ep, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_INFO(AQH_LOGDOMAIN, " - distributing message");
|
DBG_DEBUG(AQH_LOGDOMAIN, " - distributing message");
|
||||||
_distributeMsg(emgr, ep, msg);
|
_distributeMsg(emgr, ep, msg);
|
||||||
}
|
}
|
||||||
AQH_Msg_free(msg);
|
AQH_Msg_free(msg);
|
||||||
@@ -237,13 +237,13 @@ void _runAllEndpoints(AQH_MSG_ENDPOINT_MGR *emgr)
|
|||||||
{
|
{
|
||||||
AQH_MSG_ENDPOINT *ep;
|
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);
|
ep=AQH_MsgEndpoint_List_First(emgr->endpointList);
|
||||||
while(ep) {
|
while(ep) {
|
||||||
AQH_MSG_ENDPOINT *next;
|
AQH_MSG_ENDPOINT *next;
|
||||||
|
|
||||||
next=AQH_MsgEndpoint_List_Next(ep);
|
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);
|
AQH_MsgEndpoint_Run(ep);
|
||||||
ep=next;
|
ep=next;
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ void _distributeMsg(AQH_MSG_ENDPOINT_MGR *emgr, AQH_MSG_ENDPOINT *srcEp, const A
|
|||||||
uint32_t acceptedGroupIds;
|
uint32_t acceptedGroupIds;
|
||||||
uint32_t acceptedMsgGroups;
|
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);
|
acceptedGroupIds=AQH_MsgEndpoint_GetAcceptedMsgGroups(ep);
|
||||||
acceptedMsgGroups=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)
|
(acceptedGroupIds & srcGroupId)
|
||||||
) {
|
) {
|
||||||
/* endpoint accepts this message */
|
/* 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));
|
AQH_MsgEndpoint_AddSendMessage(ep, AQH_Msg_dup(msg));
|
||||||
}
|
}
|
||||||
else {
|
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);
|
ep=AQH_MsgEndpoint_List_Next(ep);
|
||||||
|
|||||||
83
aqhome/nodes/0BUILD
Normal file
83
aqhome/nodes/0BUILD
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<gwbuild>
|
||||||
|
|
||||||
|
<target type="ConvenienceLibrary" name="aqhnodes" >
|
||||||
|
|
||||||
|
<includes type="c" >
|
||||||
|
$(gwenhywfar_cflags)
|
||||||
|
-I$(topsrcdir)
|
||||||
|
-I$(topbuilddir)
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
<includes type="tm2" >
|
||||||
|
--include=$(builddir)
|
||||||
|
--include=$(srcdir)
|
||||||
|
</includes>
|
||||||
|
|
||||||
|
|
||||||
|
<define name="BUILDING_AQHOME" />
|
||||||
|
|
||||||
|
<setVar name="local/cflags">$(visibility_cflags)</setVar>
|
||||||
|
|
||||||
|
|
||||||
|
<setVar name="tm2flags" >
|
||||||
|
--api=AQHOME_API
|
||||||
|
</setVar>
|
||||||
|
|
||||||
|
<setVar name="local/typefiles" >
|
||||||
|
nodeinfo.t2d
|
||||||
|
</setVar>
|
||||||
|
|
||||||
|
<setVar name="local/built_sources" >
|
||||||
|
nodeinfo.c
|
||||||
|
</setVar>
|
||||||
|
|
||||||
|
<setVar name="local/built_headers_pub">
|
||||||
|
nodeinfo.h
|
||||||
|
</setVar>
|
||||||
|
|
||||||
|
|
||||||
|
<setVar name="local/built_headers_priv" >
|
||||||
|
nodeinfo_p.h
|
||||||
|
</setVar>
|
||||||
|
|
||||||
|
|
||||||
|
<headers dist="false" install="$(pkgincludedir)/nodes" >
|
||||||
|
$(local/built_headers_pub)
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
|
||||||
|
<headers dist="true" install="$(pkgincludedir)/nodes" >
|
||||||
|
nodedb.h
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
|
||||||
|
<headers dist="true" >
|
||||||
|
nodedb_p.h
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
|
||||||
|
<sources>
|
||||||
|
$(local/typefiles)
|
||||||
|
|
||||||
|
nodedb.c
|
||||||
|
</sources>
|
||||||
|
|
||||||
|
|
||||||
|
<extradist>
|
||||||
|
</extradist>
|
||||||
|
|
||||||
|
|
||||||
|
<useTargets>
|
||||||
|
</useTargets>
|
||||||
|
|
||||||
|
<subdirs>
|
||||||
|
</subdirs>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</target>
|
||||||
|
|
||||||
|
</gwbuild>
|
||||||
137
aqhome/nodes/nodedb.c
Normal file
137
aqhome/nodes/nodedb.c
Normal file
@@ -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 <config.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "aqhome/nodes/nodedb_p.h"
|
||||||
|
|
||||||
|
#include <gwenhywfar/misc.h>
|
||||||
|
#include <gwenhywfar/debug.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
35
aqhome/nodes/nodedb.h
Normal file
35
aqhome/nodes/nodedb.h
Normal file
@@ -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 <aqhome/api.h>
|
||||||
|
#include <aqhome/nodes/nodeinfo.h>
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
23
aqhome/nodes/nodedb_p.h
Normal file
23
aqhome/nodes/nodedb_p.h
Normal file
@@ -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
|
||||||
|
|
||||||
73
aqhome/nodes/nodeinfo.t2d
Normal file
73
aqhome/nodes/nodeinfo.t2d
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
<?xml?>
|
||||||
|
|
||||||
|
<tm2>
|
||||||
|
<type id="AQH_NODE_INFO" type="pointer">
|
||||||
|
<descr>
|
||||||
|
</descr>
|
||||||
|
<lang id="c">
|
||||||
|
<identifier>AQH_NODE_INFO</identifier>
|
||||||
|
<prefix>AQH_NodeInfo</prefix>
|
||||||
|
<baseFileName>nodeinfo</baseFileName>
|
||||||
|
|
||||||
|
<flags>
|
||||||
|
with_xml
|
||||||
|
with_db
|
||||||
|
with_list1
|
||||||
|
with_list2
|
||||||
|
</flags>
|
||||||
|
|
||||||
|
<headers>
|
||||||
|
<header type="sys" loc="pre">aqhome/api.h</header>
|
||||||
|
</headers>
|
||||||
|
|
||||||
|
<inlines>
|
||||||
|
</inlines>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</lang>
|
||||||
|
|
||||||
|
|
||||||
|
<members>
|
||||||
|
|
||||||
|
<member name="busAddress" type="uint8_t" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<flags>sortByMember</flags>
|
||||||
|
<access>public</access>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="uid" type="uint32_t" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags></flags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="nodeType" type="int" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags></flags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="baseSystemVersion" type="uint32_t" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags></flags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
<member name="mainSystemVersion" type="uint32_t" maxlen="8">
|
||||||
|
<default>0</default>
|
||||||
|
<preset>0</preset>
|
||||||
|
<access>public</access>
|
||||||
|
<flags></flags>
|
||||||
|
</member>
|
||||||
|
|
||||||
|
</members>
|
||||||
|
|
||||||
|
</type>
|
||||||
|
|
||||||
|
</tm2>
|
||||||
|
|
||||||
Reference in New Issue
Block a user