aqhome: Added node db.

This commit is contained in:
Martin Preuss
2023-02-22 21:25:10 +01:00
parent 7a1968e962
commit 614a942a0e
9 changed files with 383 additions and 30 deletions

83
aqhome/nodes/0BUILD Normal file
View 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
View 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
View 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
View 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
View 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>