aqhome-nodes: write db on fini(). Extract info from DEVICE message.

This commit is contained in:
Martin Preuss
2024-09-18 00:15:43 +02:00
parent 08399ecf87
commit 7590aa3717
4 changed files with 30 additions and 11 deletions

View File

@@ -90,6 +90,21 @@ void AqHomed_NodeMsgToDb(AQHOMED *aqh, const GWEN_MSG *msg)
void AqHomed_WriteNodeDb(AQHOMED *aqh)
{
if (aqh->dbFile) {
GWEN_DB_NODE *dbNodeDb;
AQH_NodeDb_ClearModified(aqh->nodeDb);
dbNodeDb=GWEN_DB_Group_new("nodeDb");
AQH_NodeDb_toDb(aqh->nodeDb, dbNodeDb);
GWEN_DB_WriteFile(dbNodeDb, aqh->dbFile, GWEN_DB_FLAGS_DEFAULT);
GWEN_DB_Group_free(dbNodeDb);
}
}
void _handleMsgValue2(AQHOMED *aqh, const GWEN_MSG *msg)
{
AQH_NODE_INFO *ni;
@@ -192,7 +207,14 @@ void _handleMsgDevice(AQHOMED *aqh, const GWEN_MSG *msg)
uid=AQH_DeviceMsg_GetUid(msg);
ni=_getOrCreateNodeAndUpdateUidAddr(aqh, msg, uid);
if (ni) {
// TODO
AQH_NodeInfo_SetManufacturer(ni, AQH_DeviceMsg_GetManufacturer(msg));
AQH_NodeInfo_SetDeviceType(ni, AQH_DeviceMsg_GetDeviceType(msg));
AQH_NodeInfo_SetDeviceVersion(ni, (AQH_DeviceMsg_GetDeviceVersion(msg)<<8)+AQH_DeviceMsg_GetDeviceRevision(msg));
AQH_NodeInfo_SetFirmwareVersion(ni,
(AQH_DeviceMsg_GetFirmwareVariant(msg)<<24) |
(AQH_DeviceMsg_GetFirmwareVersionMajor(msg)<<16) |
(AQH_DeviceMsg_GetFirmwareVersionMinor(msg)<<8) |
AQH_DeviceMsg_GetFirmwareVersionPatchlevel(msg));
_updateTimestampLastChange(ni);
AQH_NodeDb_SetModified(aqh->nodeDb);
}

View File

@@ -16,6 +16,8 @@
void AqHomed_NodeMsgToDb(AQHOMED *aqh, const GWEN_MSG *msg);
void AqHomed_WriteNodeDb(AQHOMED *aqh);
#endif

View File

@@ -12,6 +12,7 @@
#include "./fini.h"
#include "./db.h"
#include "./aqhomed_p.h"
#include <gwenhywfar/gwenhywfar.h>
@@ -61,6 +62,8 @@ void AqHomed_Fini(AQHOMED *aqh)
aqh->ipcdEndpoint=NULL;
aqh->brokerEndpoint=NULL;
AqHomed_WriteNodeDb(aqh);
if (aqh->pidFile)
remove(aqh->pidFile);
}

View File

@@ -78,16 +78,8 @@ void AqHomed_Loop(AQHOMED *aqh, int timeoutInMsecs)
GWEN_Msg_List_GetCount(GWEN_MsgEndpoint_GetSendMessageList(aqh->brokerEndpoint)));
#endif
if (AQH_NodeDb_IsModified(aqh->nodeDb)) {
if (aqh->dbFile) {
GWEN_DB_NODE *dbNodeDb;
dbNodeDb=GWEN_DB_Group_new("nodeDb");
AQH_NodeDb_toDb(aqh->nodeDb, dbNodeDb);
GWEN_DB_WriteFile(dbNodeDb, aqh->dbFile, GWEN_DB_FLAGS_DEFAULT);
GWEN_DB_Group_free(dbNodeDb);
}
}
if (AQH_NodeDb_IsModified(aqh->nodeDb))
AqHomed_WriteNodeDb(aqh);
}
}