From 7c320b210f79d74622f3e669fad0e971b638c051 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 25 Oct 2025 16:36:24 +0200 Subject: [PATCH] more work on mdevices module. --- apps/aqhome-cgi/modules/devices/0BUILD | 4 + apps/aqhome-cgi/modules/devices/mdevices.c | 49 +++++++ apps/aqhome-cgi/modules/devices/mdevices.h | 1 + .../modules/devices/mdevices_device.c | 131 ++++++++++++++++++ .../modules/devices/mdevices_device.h | 27 ++++ .../modules/devices/mdevices_index.c | 12 +- .../modules/devices/mdevices_setdevice.c | 105 ++++++++++++++ .../modules/devices/mdevices_setdevice.h | 27 ++++ .../modules/devices/mdevices_valuesgraph.c | 76 ++++++++-- .../modules/devices/mdevices_vgraph.c | 56 +++++--- aqhome/dataclient/client.c | 18 +++ aqhome/dataclient/client.h | 1 + 12 files changed, 471 insertions(+), 36 deletions(-) create mode 100644 apps/aqhome-cgi/modules/devices/mdevices_device.c create mode 100644 apps/aqhome-cgi/modules/devices/mdevices_device.h create mode 100644 apps/aqhome-cgi/modules/devices/mdevices_setdevice.c create mode 100644 apps/aqhome-cgi/modules/devices/mdevices_setdevice.h diff --git a/apps/aqhome-cgi/modules/devices/0BUILD b/apps/aqhome-cgi/modules/devices/0BUILD index 3022c96..051c8ae 100644 --- a/apps/aqhome-cgi/modules/devices/0BUILD +++ b/apps/aqhome-cgi/modules/devices/0BUILD @@ -59,6 +59,8 @@ mdevices_value.h mdevices_setdata.h mdevices_vgraph.h + mdevices_device.h + mdevices_setdevice.h @@ -77,6 +79,8 @@ mdevices_value.c mdevices_setdata.c mdevices_vgraph.c + mdevices_device.c + mdevices_setdevice.c diff --git a/apps/aqhome-cgi/modules/devices/mdevices.c b/apps/aqhome-cgi/modules/devices/mdevices.c index c5572dc..70e1e2d 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices.c +++ b/apps/aqhome-cgi/modules/devices/mdevices.c @@ -19,6 +19,8 @@ #include "aqhome-cgi/modules/devices/mdevices_value.h" #include "aqhome-cgi/modules/devices/mdevices_setdata.h" #include "aqhome-cgi/modules/devices/mdevices_vgraph.h" +#include "aqhome-cgi/modules/devices/mdevices_device.h" +#include "aqhome-cgi/modules/devices/mdevices_setdevice.h" #include "aqhome-cgi/service/module.h" #include "aqhome-cgi/modules/mdataclient.h" @@ -37,6 +39,7 @@ #define GBAA GWEN_Buffer_AppendArgs #define P_DEVICEREAD AQH_MODDEVICES_PERMS_DEVICEREAD +#define P_DEVICEWRITE AQH_MODDEVICES_PERMS_DEVICEWRITE #define P_VALUEREAD AQH_MODDEVICES_PERMS_VALUEREAD #define P_VALUEWRITE AQH_MODDEVICES_PERMS_VALUEWRITE @@ -56,6 +59,8 @@ static void _handleRqValuesGraphGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSIO static void _handleRqValueGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqSetDataPost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _handleRqGraphGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); +static void _handleRqDeviceGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); +static void _handleRqDevicePost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf); static void _addValueActionToForm(const AQH_VALUE *value, GWEN_BUFFER *dbuf); static void _addLastValueToForm(AQH_DATACLIENT *dc, const AQH_VALUE *value, GWEN_BUFFER *dbuf); @@ -69,6 +74,8 @@ static void _addLastValueToForm(AQH_DATACLIENT *dc, const AQH_VALUE *value, GWEN static AQH_MODSERVICE_HANDLER_ENTRY _requestTable[]={ {"index.html", AQCGI_REQUEST_METHOD_GET, P_DEVICEREAD, _handleRqIndexGet}, + {"device.html", AQCGI_REQUEST_METHOD_GET, P_DEVICEREAD | P_VALUEREAD, _handleRqDeviceGet}, + {"device.html", AQCGI_REQUEST_METHOD_POST, P_DEVICEWRITE, _handleRqDevicePost}, {"vtable.html", AQCGI_REQUEST_METHOD_GET, P_DEVICEREAD | P_VALUEREAD, _handleRqValuesTableGet}, {"vgraph.html", AQCGI_REQUEST_METHOD_GET, P_DEVICEREAD | P_VALUEREAD, _handleRqValuesGraphGet}, {"value.html", AQCGI_REQUEST_METHOD_GET, P_DEVICEREAD | P_VALUEREAD, _handleRqValueGet}, @@ -150,6 +157,20 @@ void _handleRqGraphGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, G +void _handleRqDeviceGet(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) +{ + AQH_ModDataClient_HandleRequest(m, rq, session, AQH_ModDevices_RunDevice, dbuf); +} + + + +void _handleRqDevicePost(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, GWEN_BUFFER *dbuf) +{ + AQH_ModDataClient_HandleRequest(m, rq, session, AQH_ModDevices_RunSetDevice, dbuf); +} + + + @@ -343,4 +364,32 @@ AQH_VALUE *AQH_ModDevices_GetValueForDevice(AQH_DATACLIENT *dc, const char *sDev +AQH_DEVICE *AQH_ModDevices_GetDevice(AQH_DATACLIENT *dc, const char *sDeviceName) +{ + AQH_DEVICE_LIST *deviceList; + + deviceList=AQH_DataClient_GetDevices(dc, sDeviceName); + if (deviceList) { + AQH_DEVICE *device; + + device=AQH_Device_List_First(deviceList); + while(device) { + const char *s; + + s=AQH_Device_GetNameForSystem(device); + if (s && *s && 0==strcasecmp(s, sDeviceName)) { + AQH_Device_List_Del(device); + AQH_Device_List_free(deviceList); + return device; + } + device=AQH_Device_List_Next(device); + } + AQH_Device_List_free(deviceList); + } + + return NULL; +} + + + diff --git a/apps/aqhome-cgi/modules/devices/mdevices.h b/apps/aqhome-cgi/modules/devices/mdevices.h index 8a160de..15b0476 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices.h +++ b/apps/aqhome-cgi/modules/devices/mdevices.h @@ -46,6 +46,7 @@ uint32_t AQH_ModDevices_HtmlColorToValueRGBW(uint32_t colorIn); uint32_t AQH_ModDevices_RgbwToHtmlColor(uint32_t colorIn); AQH_VALUE *AQH_ModDevices_GetValueForDevice(AQH_DATACLIENT *dc, const char *sDeviceName, const char *sValueName); +AQH_DEVICE *AQH_ModDevices_GetDevice(AQH_DATACLIENT *dc, const char *sDeviceName); diff --git a/apps/aqhome-cgi/modules/devices/mdevices_device.c b/apps/aqhome-cgi/modules/devices/mdevices_device.c new file mode 100644 index 0000000..ff70697 --- /dev/null +++ b/apps/aqhome-cgi/modules/devices/mdevices_device.c @@ -0,0 +1,131 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2025 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 "./mdevices_device.h" + +#include "aqhome-cgi/service/module.h" +#include "aqhome-cgi/modules/mdataclient.h" + +#include +#include +#include + + +/* ------------------------------------------------------------------------------------------------ + * defs and enums + * ------------------------------------------------------------------------------------------------ + */ + +#define GBAS GWEN_Buffer_AppendString +#define GBAA GWEN_Buffer_AppendArgs + +#define I18N(msg) msg + + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + +static void _runDeviceWithArgs(AQH_MODULE *m, + AQCGI_REQUEST *rq, + AQH_SESSION *session, + AQH_DATACLIENT *dc, + const char *sDeviceName, + GWEN_BUFFER *dbuf); +static void _mkDeviceForm(AQH_DATACLIENT *dc, const char *sDeviceName, const AQH_DEVICE *device, GWEN_BUFFER *dbuf); +static void _addFieldToForm(const char *sFieldTitle, const char *sFieldName, const char *sFieldContent, GWEN_BUFFER *dbuf); + + + +/* ------------------------------------------------------------------------------------------------ + * code + * ------------------------------------------------------------------------------------------------ + */ + +void AQH_ModDevices_RunDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf) +{ + GWEN_DB_NODE *dbQuery; + const char *sDeviceName; + + DBG_ERROR(NULL, "RunValue"); + dbQuery=AQCGI_Request_GetDbQuery(rq); + sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL); + if (sDeviceName && *sDeviceName) { + GWEN_BUFFER *bufDeviceName; + + bufDeviceName=GWEN_Buffer_new(0, 64, 0, 1); + GWEN_Text_UnescapeToBufferTolerant(sDeviceName, bufDeviceName); + _runDeviceWithArgs(m, rq, session, dc, GWEN_Buffer_GetStart(bufDeviceName), dbuf); + GWEN_Buffer_free(bufDeviceName); + } +} + + + +void _runDeviceWithArgs(AQH_MODULE *m, + AQCGI_REQUEST *rq, + AQH_SESSION *session, + AQH_DATACLIENT *dc, + const char *sDeviceName, + GWEN_BUFFER *dbuf) +{ + GWEN_DB_NODE *dbQuery; + AQH_DEVICE *device; + + dbQuery=AQCGI_Request_GetDbQuery(rq); + DBG_ERROR(NULL, "Device=%s", sDeviceName?sDeviceName:""); + + GBAA(dbuf,"

Device %s

\n", sDeviceName); + + device=AQH_ModDevices_GetDevice(dc, sDeviceName); + if (device) { + _mkDeviceForm(dc, sDeviceName, device, dbuf); + AQH_Device_free(device); + } +} + + + +void _mkDeviceForm(AQH_DATACLIENT *dc, const char *sDeviceName, const AQH_DEVICE *device, GWEN_BUFFER *dbuf) +{ + const char *s; + + GBAS(dbuf,"
\n"); + GBAA(dbuf, "\n", sDeviceName); + + GBAS(dbuf,"\n"); + _addFieldToForm(I18N("Room"), "roomName", AQH_Device_GetRoomName(device), dbuf); + _addFieldToForm(I18N("GUI Name"), "nameForGui", AQH_Device_GetNameForGui(device), dbuf); + _addFieldToForm(I18N("Location"), "location", AQH_Device_GetLocation(device), dbuf); + _addFieldToForm(I18N("Description"), "description", AQH_Device_GetDescription(device), dbuf); + GBAS(dbuf,"
\n"); + GBAS(dbuf,"
\n"); + + GBAS(dbuf,""); + GBAS(dbuf, "
\n\n"); +} + + + +void _addFieldToForm(const char *sFieldTitle, const char *sFieldName, const char *sFieldContent, GWEN_BUFFER *dbuf) +{ + GBAS(dbuf, ""); + GBAA(dbuf, "", sFieldName, sFieldTitle); + GBAA(dbuf, "", sFieldName, sFieldContent?sFieldContent:""); + GBAS(dbuf, ""); +} + + + diff --git a/apps/aqhome-cgi/modules/devices/mdevices_device.h b/apps/aqhome-cgi/modules/devices/mdevices_device.h new file mode 100644 index 0000000..aae3489 --- /dev/null +++ b/apps/aqhome-cgi/modules/devices/mdevices_device.h @@ -0,0 +1,27 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2025 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 AQHOME_CGI_MDEVICES_DEVICE_H +#define AQHOME_CGI_MDEVICES_DEVICE_H + + +#include "aqhome-cgi/modules/devices/mdevices.h" + +#include "aqhome/aqhome.h" +#include "aqhome/dataclient/client.h" + +#include + +#include + + + +void AQH_ModDevices_RunDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf); + + +#endif diff --git a/apps/aqhome-cgi/modules/devices/mdevices_index.c b/apps/aqhome-cgi/modules/devices/mdevices_index.c index 22930c5..6381047 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices_index.c +++ b/apps/aqhome-cgi/modules/devices/mdevices_index.c @@ -66,6 +66,7 @@ void AQH_ModDevices_RunIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sess "\n" "" "Name For System" + "Name For GUI" "Room" "Location" "Description" @@ -83,6 +84,9 @@ void AQH_ModDevices_RunIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sess /* name for system */ sDevice=AQH_Device_GetNameForSystem(device); GBAA(dbuf,"%s", sDevice?sDevice:""); + /* nameForGui */ + s=AQH_Device_GetNameForGui(device); + GBAA(dbuf, "%s", s?s:""); /* room */ s=AQH_Device_GetRoomName(device); GBAA(dbuf, "%s", s?s:""); @@ -97,8 +101,12 @@ void AQH_ModDevices_RunIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sess if (perms & AQH_MODDEVICES_PERMS_VALUEREAD) { _addLinkForDevice("vtable.html", sDevice, "table view", "/pics/document-table.png", dbuf); _addLinkForDevice("vgraph.html", sDevice, "graph view", "/pics/graph.png", dbuf); - // TODO: add edit link } + + if (perms & AQH_MODDEVICES_PERMS_DEVICEWRITE) { + _addLinkForDevice("device.html", sDevice, "edit device", "/pics/edit.png", dbuf); + } + GBAS(dbuf, ""); GBAA(dbuf, ""); @@ -118,7 +126,7 @@ void _addLinkForDevice(const char *page, const char *sDevice, const char *action GBAA(dbuf,""); - GBAA(dbuf,"\"action\"", imgName); + GBAA(dbuf,"\"%s\"", imgName, action, action); GBAS(dbuf,""); } diff --git a/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c b/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c new file mode 100644 index 0000000..6edfd72 --- /dev/null +++ b/apps/aqhome-cgi/modules/devices/mdevices_setdevice.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2025 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 "./mdevices_setdevice.h" + +#include "aqhome-cgi/service/module.h" +#include "aqhome-cgi/modules/mdataclient.h" + +#include +#include +#include + + +/* ------------------------------------------------------------------------------------------------ + * defs and enums + * ------------------------------------------------------------------------------------------------ + */ + +#define GBAS GWEN_Buffer_AppendString +#define GBAA GWEN_Buffer_AppendArgs + + + +/* ------------------------------------------------------------------------------------------------ + * forward declarations + * ------------------------------------------------------------------------------------------------ + */ + +static void _handleDeviceForm(AQH_DATACLIENT *dc, AQH_DEVICE *device, GWEN_DB_NODE *dbPost, GWEN_BUFFER *dbuf); + + + +/* ------------------------------------------------------------------------------------------------ + * code + * ------------------------------------------------------------------------------------------------ + */ + +void AQH_ModDevices_RunSetDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf) +{ + AQH_SERVICE *sv; + GWEN_DB_NODE *dbPost; + const char *sDeviceName; + AQH_DEVICE *device; + + DBG_ERROR(NULL, "Post device.html"); + /* sample data */ + sv=AQH_ModService_GetService(m); + dbPost=AQCGI_Request_GetDbPostBody(rq); + sDeviceName=dbPost?GWEN_DB_GetCharValue(dbPost, "device", 0, NULL):NULL; + DBG_ERROR(NULL, "Device=[%s]", sDeviceName?sDeviceName:""); + + device=AQH_ModDevices_GetDevice(dc, sDeviceName); + if (device) { + int rv; + + DBG_ERROR(NULL, "Reading data from form"); + _handleDeviceForm(dc, device, dbPost, dbuf); + DBG_ERROR(NULL, "Updating device on server"); + rv=AQH_DataClient_ModDevice(dc, device); + if (rv<0) { + DBG_ERROR(NULL, "here (%d)", rv); + } + AQH_Device_free(device); + } + else { + DBG_ERROR(NULL, "device not found"); + } + + if (sDeviceName && *sDeviceName) { + GWEN_BUFFER *pbuf; + + pbuf=GWEN_Buffer_new(0, 256, 0, 1); + GBAS(pbuf, "Location: /aqbt/devices/device.html?device="); + GWEN_Text_EscapeToBuffer(sDeviceName, pbuf); + AQCGI_Request_AddResponseHeaderData(rq, GWEN_Buffer_GetStart(pbuf)); + GWEN_Buffer_free(pbuf); + } + AQCGI_Request_SetResponseCode(rq, 303); + AQCGI_Request_SetResponseText(rq, "See other"); +} + + + +void _handleDeviceForm(AQH_DATACLIENT *dc, AQH_DEVICE *device, GWEN_DB_NODE *dbPost, GWEN_BUFFER *dbuf) +{ + AQH_Device_SetRoomName(device, GWEN_DB_GetCharValue(dbPost, "roomName", 0, NULL)); + AQH_Device_SetNameForGui(device, GWEN_DB_GetCharValue(dbPost, "nameForGui", 0, NULL)); + AQH_Device_SetLocation(device, GWEN_DB_GetCharValue(dbPost, "location", 0, NULL)); + AQH_Device_SetDescription(device, GWEN_DB_GetCharValue(dbPost, "description", 0, NULL)); +} + + + + + diff --git a/apps/aqhome-cgi/modules/devices/mdevices_setdevice.h b/apps/aqhome-cgi/modules/devices/mdevices_setdevice.h new file mode 100644 index 0000000..d370f40 --- /dev/null +++ b/apps/aqhome-cgi/modules/devices/mdevices_setdevice.h @@ -0,0 +1,27 @@ +/**************************************************************************** + * This file is part of the project AqHome. + * AqHome (c) by 2025 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 AQHOME_CGI_MDEVICES_SETDEVICE_H +#define AQHOME_CGI_MDEVICES_SETDEVICE_H + + +#include "aqhome-cgi/modules/devices/mdevices.h" + +#include "aqhome/aqhome.h" +#include "aqhome/dataclient/client.h" + +#include + +#include + + + +void AQH_ModDevices_RunSetDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf); + + +#endif diff --git a/apps/aqhome-cgi/modules/devices/mdevices_valuesgraph.c b/apps/aqhome-cgi/modules/devices/mdevices_valuesgraph.c index ef043f0..3163f0e 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices_valuesgraph.c +++ b/apps/aqhome-cgi/modules/devices/mdevices_valuesgraph.c @@ -37,9 +37,10 @@ * ------------------------------------------------------------------------------------------------ */ +static void _writeValueToDetailedTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf); static void _writeValueListToTable(const char *sDeviceName, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *dbuf); static void _writeValueToTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf); -static void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *sPeriod, GWEN_BUFFER *dbuf); +static void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *sPeriod, GWEN_BUFFER *dbuf, int withLink); @@ -58,24 +59,61 @@ void AQH_ModDevices_RunValuesAsGraph(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSI if (!(sDeviceName && *sDeviceName)) AQH_ModDevices_RunIndex(m, rq, session, dc, dbuf); else { - AQH_VALUE_LIST *valueList; + const char *sValueName; - valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0); - if (valueList && AQH_Value_List_GetCount(valueList)) { + sValueName=GWEN_DB_GetCharValue(dbQuery, "value", 0, NULL); + if (sValueName && *sValueName) { + AQH_VALUE *value; - GBAA(dbuf,"

Values for Device %s

\n", sDeviceName); - _writeValueListToTable(sDeviceName, valueList, dbuf); - GBAS(dbuf, "\n"); + GBAA(dbuf,"

Value %s/%s

\n", sDeviceName, sValueName); + value=AQH_ModDevices_GetValueForDevice(dc, sDeviceName, sValueName); + if (value) { + _writeValueToDetailedTable(sDeviceName, value, dbuf); + AQH_Value_free(value); + AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 120"); + } } else { - GBAS(dbuf,"

No values.

\n"); + AQH_VALUE_LIST *valueList; + + valueList=AQH_DataClient_GetValues(dc, sDeviceName, 0); + if (valueList && AQH_Value_List_GetCount(valueList)) { + + GBAA(dbuf,"

Values for Device %s

\n", sDeviceName); + _writeValueListToTable(sDeviceName, valueList, dbuf); + GBAS(dbuf, "\n"); + } + else { + GBAS(dbuf,"

No values.

\n"); + } + AQH_Value_List_free(valueList); + AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 305"); } - AQH_Value_List_free(valueList); } } +void _writeValueToDetailedTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf) +{ + const char *sValueName; + + GBAS(dbuf, "\n"); + sValueName=AQH_Value_GetName(value); + + GBAS(dbuf, "\n"); +} + + + void _writeValueListToTable(const char *sDeviceName, const AQH_VALUE_LIST *valueList, GWEN_BUFFER *dbuf) { const AQH_VALUE *value; @@ -85,7 +123,7 @@ void _writeValueListToTable(const char *sDeviceName, const AQH_VALUE_LIST *value value=AQH_Value_List_First(valueList); while(value) { - if (AQH_Value_GetValueType(value)==AQH_ValueType_Sensor) + if (AQH_Value_GetValueType(value)!=AQH_ValueType_Actor) _writeValueToTable(sDeviceName, value, dbuf); value=AQH_Value_List_Next(value); } @@ -102,16 +140,24 @@ void _writeValueToTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BU sValueName=AQH_Value_GetName(value); GBAS(dbuf, "\n"); } -void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *sPeriod, GWEN_BUFFER *dbuf) +void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *sPeriod, GWEN_BUFFER *dbuf, int withLink) { + if (withLink) { + GBAS(dbuf, ""); + } + GBAS(dbuf, "\"%s\""); + + if (withLink) { + GBAS(dbuf, ""); + } } diff --git a/apps/aqhome-cgi/modules/devices/mdevices_vgraph.c b/apps/aqhome-cgi/modules/devices/mdevices_vgraph.c index c1340c8..b8d35ca 100644 --- a/apps/aqhome-cgi/modules/devices/mdevices_vgraph.c +++ b/apps/aqhome-cgi/modules/devices/mdevices_vgraph.c @@ -46,7 +46,9 @@ enum { VALUEGRAPH_PERIOD_4H=1, VALUEGRAPH_PERIOD_1D, VALUEGRAPH_PERIOD_1W, - VALUEGRAPH_PERIOD_1M + VALUEGRAPH_PERIOD_1M, + VALUEGRAPH_PERIOD_6M, + VALUEGRAPH_PERIOD_12M, }; @@ -268,11 +270,13 @@ AQDG_GRAPH *_mkGraphObjectWithTitle(const char *graphTitle, int period, int prec tbuf=GWEN_Buffer_new(0, 256, 0, 1); switch(period) { - case VALUEGRAPH_PERIOD_4H: s="last 4 hours"; break; - case VALUEGRAPH_PERIOD_1D: s="last 24 hours"; break; - case VALUEGRAPH_PERIOD_1W: s="last 7 days"; break; - case VALUEGRAPH_PERIOD_1M: s="last 30 days"; break; - default: s="last 24 hours"; break; + case VALUEGRAPH_PERIOD_4H: s="last 4 hours"; break; + case VALUEGRAPH_PERIOD_1D: s="last 24 hours"; break; + case VALUEGRAPH_PERIOD_1W: s="last 7 days"; break; + case VALUEGRAPH_PERIOD_1M: s="last 30 days"; break; + case VALUEGRAPH_PERIOD_6M: s="last 6 months"; break; + case VALUEGRAPH_PERIOD_12M: s="last 12 months"; break; + default: s="last 24 hours"; break; } GBAA(tbuf, "%s - %s", graphTitle, s); @@ -293,6 +297,10 @@ int _getPeriodFromString(const char *sPeriod) return VALUEGRAPH_PERIOD_1W; else if (strcasecmp(sPeriod, "1m")==0) return VALUEGRAPH_PERIOD_1M; + else if (strcasecmp(sPeriod, "6m")==0) + return VALUEGRAPH_PERIOD_6M; + else if (strcasecmp(sPeriod, "12m")==0) + return VALUEGRAPH_PERIOD_12M; return VALUEGRAPH_PERIOD_1D; } @@ -315,11 +323,13 @@ void _mkPathForValueAndPeriod(AQH_MODULE *m, const AQH_VALUE *v, int period, GWE /* period */ switch(period) { - case VALUEGRAPH_PERIOD_4H: s="4h"; break; - case VALUEGRAPH_PERIOD_1D: s="1d"; break; - case VALUEGRAPH_PERIOD_1W: s="1w"; break; - case VALUEGRAPH_PERIOD_1M: s="1m"; break; - default: s="1d"; break; + case VALUEGRAPH_PERIOD_4H: s="4h"; break; + case VALUEGRAPH_PERIOD_1D: s="1d"; break; + case VALUEGRAPH_PERIOD_1W: s="1w"; break; + case VALUEGRAPH_PERIOD_1M: s="1m"; break; + case VALUEGRAPH_PERIOD_6M: s="6m"; break; + case VALUEGRAPH_PERIOD_12M: s="12m"; break; + default: s="1d"; break; } GBAA(dbuf, "-%s.png", s); @@ -335,11 +345,13 @@ uint64_t _getStartTimeForPeriod(int period) /* period */ switch(period) { - case VALUEGRAPH_PERIOD_4H: t-=4*60*60; break; - case VALUEGRAPH_PERIOD_1D: t-=24*60*60; break; - case VALUEGRAPH_PERIOD_1W: t-=7*24*60*60; break; - case VALUEGRAPH_PERIOD_1M: t-=30*24*60*60; break; - default: t-=24*60*60; break; + case VALUEGRAPH_PERIOD_4H: t-=4*60*60; break; + case VALUEGRAPH_PERIOD_1D: t-=24*60*60; break; + case VALUEGRAPH_PERIOD_1W: t-=7*24*60*60; break; + case VALUEGRAPH_PERIOD_1M: t-=30*24*60*60; break; + case VALUEGRAPH_PERIOD_6M: t-=182*24*60*60; break; + case VALUEGRAPH_PERIOD_12M: t-=365*24*60*60; break; + default: t-=24*60*60; break; } return (uint64_t) t; @@ -351,11 +363,13 @@ const char *_getModifiersForPeriod(int period) { /* period */ switch(period) { - case VALUEGRAPH_PERIOD_4H: return "La5"; - case VALUEGRAPH_PERIOD_1D: return "La30"; - case VALUEGRAPH_PERIOD_1W: return "La240"; - case VALUEGRAPH_PERIOD_1M: return "La480"; - default: return "La15"; + case VALUEGRAPH_PERIOD_4H: return "La5"; + case VALUEGRAPH_PERIOD_1D: return "La30"; + case VALUEGRAPH_PERIOD_1W: return "La240"; + case VALUEGRAPH_PERIOD_1M: return "La480"; + case VALUEGRAPH_PERIOD_6M: return "La720"; + case VALUEGRAPH_PERIOD_12M: return "La1440"; + default: return "La30"; } } diff --git a/aqhome/dataclient/client.c b/aqhome/dataclient/client.c index 7d94c39..c335a8b 100644 --- a/aqhome/dataclient/client.c +++ b/aqhome/dataclient/client.c @@ -379,6 +379,24 @@ int AQH_DataClient_UpdateData(AQH_DATACLIENT *dc, const AQH_VALUE *v, uint64_t t +int AQH_DataClient_ModDevice(AQH_DATACLIENT *dc, const AQH_DEVICE *d) +{ + if (dc) { + AQH_MESSAGE *msgOut; + uint32_t msgId; + + msgId=++(dc->lastMsgId); + msgOut=AQH_IpcdMessageDevices_newForOneDevice(AQH_MSGTYPE_IPC_DATA_MODDEVICE_REQ, msgId, 0, AQH_MSGDATA_DEVICES_FLAGS_LASTMSG, d); + AQH_Endpoint_AddMsgOut(dc->ipcEndpoint, msgOut); + + return _handleResult(dc, msgId); + } + + return GWEN_ERROR_INVALID; +} + + + diff --git a/aqhome/dataclient/client.h b/aqhome/dataclient/client.h index f6071ac..99f8266 100644 --- a/aqhome/dataclient/client.h +++ b/aqhome/dataclient/client.h @@ -45,6 +45,7 @@ AQHOME_API uint64_t AQH_DataClient_GetPeriodData(AQH_DATACLIENT *dc, const char AQHOME_API int AQH_DataClient_SetData(AQH_DATACLIENT *dc, const AQH_VALUE *v, double data); AQHOME_API int AQH_DataClient_UpdateData(AQH_DATACLIENT *dc, const AQH_VALUE *v, uint64_t timeStamp, double dataPoint); +AQHOME_API int AQH_DataClient_ModDevice(AQH_DATACLIENT *dc, const AQH_DEVICE *d); AQHOME_API int AQH_DataClient_ReadLocalArgs(AQH_DATACLIENT *dc,
"); + _addGraphLink(sDeviceName, sValueName, "4h", dbuf, 0); + GBAS(dbuf, ""); + _addGraphLink(sDeviceName, sValueName, "1d", dbuf, 0); + GBAS(dbuf, "
"); + _addGraphLink(sDeviceName, sValueName, "1w", dbuf, 0); + GBAS(dbuf, ""); + _addGraphLink(sDeviceName, sValueName, "12m", dbuf, 0); + GBAS(dbuf, "
"); - _addGraphLink(sDeviceName, sValueName, "1d", dbuf); + _addGraphLink(sDeviceName, sValueName, "1d", dbuf, 1); GBAS(dbuf, ""); - _addGraphLink(sDeviceName, sValueName, "1w", dbuf); + _addGraphLink(sDeviceName, sValueName, "1w", dbuf, 1); GBAS(dbuf, "