From 043541f9364c83530937f2d90419421c1884a6a2 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 1 Oct 2023 23:58:19 +0200 Subject: [PATCH] Set timestampCreation on created devices, show that in aqhome-tool. --- apps/aqhome-data/loop.c | 1 + apps/aqhome-tool/data/getdevices.c | 9 +-------- apps/aqhome-tool/utils.c | 26 ++++++++++++++++++++++++++ apps/aqhome-tool/utils.h | 5 +++++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/apps/aqhome-data/loop.c b/apps/aqhome-data/loop.c index 64db4a3..a8d0f4c 100644 --- a/apps/aqhome-data/loop.c +++ b/apps/aqhome-data/loop.c @@ -207,6 +207,7 @@ AQH_DEVICE *_getOrCreateDeviceForDriver(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *epD AQH_Device_SetDriver(device, serviceName); AQH_Device_SetNameForDriver(device, nameForDriver); AQH_Device_SetNameForSystem(device, GWEN_Buffer_GetStart(buf)); + AQH_Device_SetTimestampCreation(device, (uint64_t) time(NULL)); AQH_Storage_AddDevice(aqh->storage, device); } else { diff --git a/apps/aqhome-tool/data/getdevices.c b/apps/aqhome-tool/data/getdevices.c index 4337aa5..945133d 100644 --- a/apps/aqhome-tool/data/getdevices.c +++ b/apps/aqhome-tool/data/getdevices.c @@ -185,14 +185,7 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs) device=AQH_Device_List_First(deviceList); while(device) { - uint64_t deviceId; - const char *deviceName; - - deviceId=AQH_Device_GetId(device); - deviceName=AQH_Device_GetNameForSystem(device); - - fprintf(stdout, "%lu\t%s\n", (unsigned long int) deviceId, deviceName?deviceName:""); - + Utils_PrintDevice(device); device=AQH_Device_List_Next(device); } AQH_Device_List_free(deviceList); diff --git a/apps/aqhome-tool/utils.c b/apps/aqhome-tool/utils.c index 6c12dd4..1edf0e5 100644 --- a/apps/aqhome-tool/utils.c +++ b/apps/aqhome-tool/utils.c @@ -298,5 +298,31 @@ void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const c +void Utils_PrintDevice(const AQH_DEVICE *device) +{ + GWEN_TIMESTAMP *ts; + uint64_t deviceId; + const char *deviceName; + uint64_t timestamp; + + deviceId=AQH_Device_GetId(device); + deviceName=AQH_Device_GetNameForSystem(device); + timestamp=AQH_Device_GetTimestampCreation(device); + ts=timestamp?GWEN_Timestamp_fromLocalTime((time_t) timestamp):NULL; + if (ts) + fprintf(stdout, "%lu\t%s\t%04d/%02d/%02d-%02d:%02d:%02d\n", + deviceId, + deviceName, + GWEN_Timestamp_GetYear(ts), + GWEN_Timestamp_GetMonth(ts), + GWEN_Timestamp_GetDay(ts), + GWEN_Timestamp_GetHour(ts), + GWEN_Timestamp_GetMinute(ts), + GWEN_Timestamp_GetSecond(ts)); + else + fprintf(stdout, "%lu\t%s\t\n", + deviceId, + deviceName); +} diff --git a/apps/aqhome-tool/utils.h b/apps/aqhome-tool/utils.h index e3ba98c..3a1e0cb 100644 --- a/apps/aqhome-tool/utils.h +++ b/apps/aqhome-tool/utils.h @@ -13,6 +13,9 @@ #include #include +#include +#include + GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs); @@ -31,6 +34,8 @@ void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const void Utils_PrintSingleDataPoint(uint64_t timestamp, double data, const char *valueUnits); void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits); +void Utils_PrintDevice(const AQH_DEVICE *device); + #endif