more work on mdevices module.

This commit is contained in:
Martin Preuss
2025-10-25 16:36:24 +02:00
parent 0fa4c6c8b5
commit 7c320b210f
12 changed files with 471 additions and 36 deletions

View File

@@ -59,6 +59,8 @@
mdevices_value.h
mdevices_setdata.h
mdevices_vgraph.h
mdevices_device.h
mdevices_setdevice.h
</headers>
@@ -77,6 +79,8 @@
mdevices_value.c
mdevices_setdata.c
mdevices_vgraph.c
mdevices_device.c
mdevices_setdevice.c
</sources>

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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 <config.h>
#endif
#include "./mdevices_device.h"
#include "aqhome-cgi/service/module.h"
#include "aqhome-cgi/modules/mdataclient.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/timestamp.h>
#include <gwenhywfar/text.h>
/* ------------------------------------------------------------------------------------------------
* 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:"<empty>");
GBAA(dbuf,"<h1>Device %s</h1>\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,"<form action=\"device.html\" method=\"post\">\n");
GBAA(dbuf, "<input type=\"hidden\" name=\"device\" value=\"%s\">\n", sDeviceName);
GBAS(dbuf,"<table>\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,"</table>\n");
GBAS(dbuf,"<br>\n");
GBAS(dbuf,"<input type=\"submit\" name=\"action\" value=\"Send\"/>");
GBAS(dbuf, "</form>\n\n");
}
void _addFieldToForm(const char *sFieldTitle, const char *sFieldName, const char *sFieldContent, GWEN_BUFFER *dbuf)
{
GBAS(dbuf, "<tr>");
GBAA(dbuf, "<td><label for=\"%s\">%s</label></td>", sFieldName, sFieldTitle);
GBAA(dbuf, "<td><input type=\"text\" name=\"%s\" value=\"%s\"/></td>", sFieldName, sFieldContent?sFieldContent:"");
GBAS(dbuf, "</tr>");
}

View File

@@ -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 <aqcgi/request.h>
#include <gwenhywfar/buffer.h>
void AQH_ModDevices_RunDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
#endif

View File

@@ -66,6 +66,7 @@ void AQH_ModDevices_RunIndex(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *sess
"<thead>\n"
"<tr>"
"<th>Name For System</th>"
"<th>Name For GUI</th>"
"<th>Room</th>"
"<th>Location</th>"
"<th>Description</th>"
@@ -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,"<td>%s</td>", sDevice?sDevice:"");
/* nameForGui */
s=AQH_Device_GetNameForGui(device);
GBAA(dbuf, "<td>%s</td>", s?s:"");
/* room */
s=AQH_Device_GetRoomName(device);
GBAA(dbuf, "<td>%s</td>", 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, "</td>");
GBAA(dbuf, "</tr>");
@@ -118,7 +126,7 @@ void _addLinkForDevice(const char *page, const char *sDevice, const char *action
GBAA(dbuf,"<a href=\"%s?device=", page);
GWEN_Text_EscapeToBufferTolerant(sDevice, dbuf);
GBAS(dbuf,"\">");
GBAA(dbuf,"<img src=\"%s\" alt=\"action\" />", imgName);
GBAA(dbuf,"<img src=\"%s\" alt=\"%s\" title=\"%s\" />", imgName, action, action);
GBAS(dbuf,"</a>");
}

View File

@@ -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 <config.h>
#endif
#include "./mdevices_setdevice.h"
#include "aqhome-cgi/service/module.h"
#include "aqhome-cgi/modules/mdataclient.h"
#include <gwenhywfar/debug.h>
#include <gwenhywfar/timestamp.h>
#include <gwenhywfar/text.h>
/* ------------------------------------------------------------------------------------------------
* 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));
}

View File

@@ -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 <aqcgi/request.h>
#include <gwenhywfar/buffer.h>
void AQH_ModDevices_RunSetDevice(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSION *session, AQH_DATACLIENT *dc, GWEN_BUFFER *dbuf);
#endif

View File

@@ -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);
@@ -57,6 +58,21 @@ void AQH_ModDevices_RunValuesAsGraph(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSI
sDeviceName=GWEN_DB_GetCharValue(dbQuery, "device", 0, NULL);
if (!(sDeviceName && *sDeviceName))
AQH_ModDevices_RunIndex(m, rq, session, dc, dbuf);
else {
const char *sValueName;
sValueName=GWEN_DB_GetCharValue(dbQuery, "value", 0, NULL);
if (sValueName && *sValueName) {
AQH_VALUE *value;
GBAA(dbuf,"<h1>Value %s/%s</h1>\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 {
AQH_VALUE_LIST *valueList;
@@ -71,8 +87,30 @@ void AQH_ModDevices_RunValuesAsGraph(AQH_MODULE *m, AQCGI_REQUEST *rq, AQH_SESSI
GBAS(dbuf,"<p>No values.</p>\n");
}
AQH_Value_List_free(valueList);
AQCGI_Request_AddResponseHeaderData(rq, "Refresh: 305");
}
}
}
void _writeValueToDetailedTable(const char *sDeviceName, const AQH_VALUE *value, GWEN_BUFFER *dbuf)
{
const char *sValueName;
GBAS(dbuf, "<table>\n");
sValueName=AQH_Value_GetName(value);
GBAS(dbuf, "<tr><td>");
_addGraphLink(sDeviceName, sValueName, "4h", dbuf, 0);
GBAS(dbuf, "</td><td>");
_addGraphLink(sDeviceName, sValueName, "1d", dbuf, 0);
GBAS(dbuf, "</td></tr><tr><td>");
_addGraphLink(sDeviceName, sValueName, "1w", dbuf, 0);
GBAS(dbuf, "</td><td>");
_addGraphLink(sDeviceName, sValueName, "12m", dbuf, 0);
GBAS(dbuf, "</td></tr>\n");
}
@@ -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, "<tr><td>");
_addGraphLink(sDeviceName, sValueName, "1d", dbuf);
_addGraphLink(sDeviceName, sValueName, "1d", dbuf, 1);
GBAS(dbuf, "</td><td>");
_addGraphLink(sDeviceName, sValueName, "1w", dbuf);
_addGraphLink(sDeviceName, sValueName, "1w", dbuf, 1);
GBAS(dbuf, "</td></tr>\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, "<a href=\"vgraph.html?device=");
GWEN_Text_EscapeToBufferTolerant(sDeviceName, dbuf);
GBAS(dbuf, "&value=");
GWEN_Text_EscapeToBufferTolerant(sValueName, dbuf);
GBAS(dbuf, "\">");
}
GBAS(dbuf, "<img src=\"graph.html?device=");
GWEN_Text_EscapeToBufferTolerant(sDeviceName, dbuf);
GBAS(dbuf, "&value=");
@@ -119,6 +165,10 @@ void _addGraphLink(const char *sDeviceName, const char *sValueName, const char *
GBAA(dbuf, "&period=%s\"", sPeriod);
GBAA(dbuf, " alt=\"%s\" width=\"%d\" height=\"%d\"", sValueName, AQH_MODDEVICES_GRAPH_WIDTH, AQH_MODDEVICES_GRAPH_HEIGHT);
GBAS(dbuf, "/>");
if (withLink) {
GBAS(dbuf, "</a>");
}
}

View File

@@ -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,
};
@@ -272,6 +274,8 @@ AQDG_GRAPH *_mkGraphObjectWithTitle(const char *graphTitle, int period, int prec
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;
}
@@ -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;
}
@@ -319,6 +327,8 @@ void _mkPathForValueAndPeriod(AQH_MODULE *m, const AQH_VALUE *v, int period, GWE
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;
}
@@ -339,6 +349,8 @@ uint64_t _getStartTimeForPeriod(int period)
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;
}
@@ -355,7 +367,9 @@ const char *_getModifiersForPeriod(int period)
case VALUEGRAPH_PERIOD_1D: return "La30";
case VALUEGRAPH_PERIOD_1W: return "La240";
case VALUEGRAPH_PERIOD_1M: return "La480";
default: return "La15";
case VALUEGRAPH_PERIOD_6M: return "La720";
case VALUEGRAPH_PERIOD_12M: return "La1440";
default: return "La30";
}
}

View File

@@ -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;
}

View File

@@ -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,