aqhome-tool: added command to watch values changed on the server.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
#include "./c_getdatapoints.h"
|
||||
#include "./aqhome_data_p.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/data/msg_data_datapoints.h"
|
||||
#include "aqhome/ipc/data/msg_data_multidata.h"
|
||||
#include "aqhome/ipc/data/msg_data_getdata.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
@@ -102,11 +102,7 @@ int _getAndSendDataPoints(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const AQH_VAL
|
||||
|
||||
numTableEntries=(int)(tablePtr[0]);
|
||||
numDataPoints=numTableEntries/2;
|
||||
outMsg=AQH_DataPointsDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG,
|
||||
valueId,
|
||||
AQH_Value_GetNameForSystem(value),
|
||||
AQH_Value_GetValueUnits(value),
|
||||
&(tablePtr[1]), numDataPoints);
|
||||
outMsg=AQH_MultiDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, value, &(tablePtr[1]), numDataPoints);
|
||||
GWEN_MsgEndpoint_AddSendMessage(ep, outMsg);
|
||||
free(tablePtr);
|
||||
return AQH_MSG_IPC_SUCCESS;
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
getlastdatapoint.h
|
||||
setdata.h
|
||||
moddevice.h
|
||||
watch.h
|
||||
</headers>
|
||||
|
||||
<sources>
|
||||
@@ -52,6 +53,7 @@
|
||||
getlastdatapoint.c
|
||||
setdata.c
|
||||
moddevice.c
|
||||
watch.c
|
||||
</sources>
|
||||
|
||||
<useTargets>
|
||||
|
||||
@@ -16,9 +16,10 @@
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
#include "aqhome/ipc/data/msg_data_datapoints.h"
|
||||
#include "aqhome/ipc/data/msg_data_multidata.h"
|
||||
#include "aqhome/ipc/data/msg_data_getdata.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/msg_ipc_tag16.h"
|
||||
|
||||
#include <gwenhywfar/args.h>
|
||||
#include <gwenhywfar/i18n.h>
|
||||
@@ -34,8 +35,8 @@
|
||||
|
||||
|
||||
static int _doGetDataPoints(GWEN_DB_NODE *dbArgs);
|
||||
static int _awaitAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean);
|
||||
static void _handleDataResponse(GWEN_MSG *msg, int printMean);
|
||||
static uint64_t _getTimeStampFromString(const char *s);
|
||||
|
||||
|
||||
@@ -234,7 +235,7 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
msgOut=AQH_GetDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_REQ, valueName, tsBegin, tsEnd);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
|
||||
rv=printMean?_awaitAndCalcAndPrintResponse(epTcp, timeoutInSeconds):_awaitAndPrintResponse(epTcp, timeoutInSeconds);
|
||||
rv=_awaitAndCalcAndPrintResponse(epTcp, timeoutInSeconds, printMean?1:0);
|
||||
if (rv!=0) {
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return rv;
|
||||
@@ -246,7 +247,7 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
|
||||
|
||||
int _awaitAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean)
|
||||
{
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
@@ -259,22 +260,9 @@ int _awaitAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
}
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETDATA_RSP) {
|
||||
if (AQH_DataPointsDataIpcMsg_IsValid(msg)) {
|
||||
Utils_PrintDataPoints(AQH_DataPointsDataIpcMsg_GetDataPoints(msg),
|
||||
AQH_DataPointsDataIpcMsg_GetNumValues(msg),
|
||||
AQH_DataPointsDataIpcMsg_GetUnits(msg));
|
||||
if (AQH_DataPointsDataIpcMsg_GetFlags(msg) & AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG) {
|
||||
DBG_INFO(NULL, "Last message received");
|
||||
GWEN_Msg_free(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Invalid message received");
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
_handleDataResponse(msg, printMean);
|
||||
GWEN_Msg_free(msg);
|
||||
return 0;
|
||||
}
|
||||
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||
uint32_t resultCode;
|
||||
@@ -295,47 +283,29 @@ int _awaitAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
|
||||
|
||||
|
||||
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||
void _handleDataResponse(GWEN_MSG *msg, int printMean)
|
||||
{
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
uint16_t code;
|
||||
AQH_VALUE *value;
|
||||
const GWEN_TAG16 *tag;
|
||||
const char *valueUnits;
|
||||
unsigned int numberOfPoints;
|
||||
const uint64_t *dataPoints;
|
||||
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_ERROR(NULL, "No response received");
|
||||
return 2;
|
||||
}
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETDATA_RSP) {
|
||||
if (AQH_DataPointsDataIpcMsg_IsValid(msg)) {
|
||||
Utils_PrintMeanData(AQH_DataPointsDataIpcMsg_GetDataPoints(msg),
|
||||
AQH_DataPointsDataIpcMsg_GetNumValues(msg),
|
||||
AQH_DataPointsDataIpcMsg_GetUnits(msg));
|
||||
GWEN_Msg_free(msg);
|
||||
break;
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "Invalid message received");
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||
uint32_t resultCode;
|
||||
AQH_MultiDataDataIpcMsg_Parse(msg, 0);
|
||||
value=AQH_MultiDataDataIpcMsg_ReadValue(msg);
|
||||
valueUnits=value?AQH_Value_GetValueUnits(value):NULL;
|
||||
|
||||
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
|
||||
fprintf(stderr, "ERROR: %d\n", resultCode);
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
} /* for */
|
||||
return 0;
|
||||
tag=AQH_Tag16IpcMsg_FindFirstTagByType(msg, AQH_MSGDATA_MULTIDATA_TAGS_DATA);
|
||||
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
|
||||
dataPoints=tag?((const uint64_t*) GWEN_Tag16_GetTagData(tag)):NULL;
|
||||
if (numberOfPoints>0 && dataPoints) {
|
||||
if (printMean)
|
||||
Utils_PrintMeanData(dataPoints, numberOfPoints, valueUnits);
|
||||
else
|
||||
Utils_PrintDataPoints(dataPoints, numberOfPoints, valueUnits);
|
||||
}
|
||||
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
248
apps/aqhome-tool/data/watch.c
Normal file
248
apps/aqhome-tool/data/watch.c
Normal file
@@ -0,0 +1,248 @@
|
||||
/****************************************************************************
|
||||
* 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 "./getdatapoints.h"
|
||||
#include "../utils.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/msg/msg_node.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
#include "aqhome/ipc/data/msg_data_multidata.h"
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/msg_ipc_tag16.h"
|
||||
|
||||
#include <gwenhywfar/args.h>
|
||||
#include <gwenhywfar/i18n.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/text.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#define I18S(msg) msg
|
||||
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
||||
|
||||
|
||||
|
||||
static int _doWatch(GWEN_DB_NODE *dbArgs);
|
||||
static void _awaitAndPrintChanges(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, const char *tmpl);
|
||||
static void _handleDataResponse(GWEN_MSG *msg, const char *tmpl);
|
||||
|
||||
|
||||
|
||||
int AQH_Tool_Watch(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
{
|
||||
GWEN_DB_NODE *dbLocalArgs;
|
||||
int rv;
|
||||
const GWEN_ARGS args[]= {
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Char, /* type */
|
||||
"tcpAddress", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"t", /* short option */
|
||||
"tcpaddress", /* long option */
|
||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)"),
|
||||
I18S("Specify TCP address to connect to (defaults to 127.0.0.1)")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Int, /* type */
|
||||
"tcpPort", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"P", /* short option */
|
||||
"tcpport", /* long option */
|
||||
I18S("Specify the TCP port to listen on"),
|
||||
I18S("Specify the TCP port to listen on")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Int, /* type */
|
||||
"timeout", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"T", /* short option */
|
||||
NULL, /* long option */
|
||||
I18S("Specify timeout in seconds for response"),
|
||||
I18S("Specify timeout in seconds for response")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Char, /* type */
|
||||
"clientId", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"c", /* short option */
|
||||
"clientid", /* long option */
|
||||
I18S("Specify CLIENTID"),
|
||||
I18S("Specify CLIENTID")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Char, /* type */
|
||||
"userId", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"u", /* short option */
|
||||
"userid", /* long option */
|
||||
I18S("Specify user id"),
|
||||
I18S("Specify user id")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Char, /* type */
|
||||
"password", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"p", /* short option */
|
||||
"password", /* long option */
|
||||
I18S("Specify service password"),
|
||||
I18S("Specify service password")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Char, /* type */
|
||||
"template", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
NULL, /* short option */
|
||||
"tmpl", /* long option */
|
||||
I18S("Specify template for output"),
|
||||
I18S("Specify template for output")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HELP | GWEN_ARGS_FLAGS_LAST, /* flags */
|
||||
GWEN_ArgsType_Int, /* type */
|
||||
"help", /* name */
|
||||
0, /* minnum */
|
||||
0, /* maxnum */
|
||||
"h", /* short option */
|
||||
"help", /* long option */
|
||||
"Show this help screen", /* short description */
|
||||
"Show this help screen" /* long description */
|
||||
}
|
||||
};
|
||||
|
||||
dbLocalArgs=GWEN_DB_GetGroup(dbGlobalArgs, GWEN_DB_FLAGS_DEFAULT, "local");
|
||||
rv=GWEN_Args_Check(argc, argv, 1,
|
||||
GWEN_ARGS_MODE_ALLOW_FREEPARAM,
|
||||
args,
|
||||
dbLocalArgs);
|
||||
if (rv==GWEN_ARGS_RESULT_ERROR) {
|
||||
fprintf(stderr, "ERROR: Could not parse arguments\n");
|
||||
return 1;
|
||||
}
|
||||
else if (rv==GWEN_ARGS_RESULT_HELP) {
|
||||
GWEN_BUFFER *ubuf;
|
||||
|
||||
ubuf=GWEN_Buffer_new(0, 1024, 0, 1);
|
||||
if (GWEN_Args_Usage(args, ubuf, GWEN_ArgsOutType_Txt)) {
|
||||
fprintf(stderr, "ERROR: Could not create help string\n");
|
||||
return 1;
|
||||
}
|
||||
fprintf(stderr, "%s\n", GWEN_Buffer_GetStart(ubuf));
|
||||
GWEN_Buffer_free(ubuf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doWatch(dbLocalArgs);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _doWatch(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
int timeoutInSeconds;
|
||||
const char *tmpl;
|
||||
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
tmpl=GWEN_DB_GetCharValue(dbArgs, "template", 0, "$(datapoint/timestampAsDate)\t$(datapoint/datapoint)\t$(value/nameForSystem)");
|
||||
|
||||
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs, AQH_IPCENDPOINT_FLAGS_WANTUPDATES);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
}
|
||||
|
||||
_awaitAndPrintChanges(epTcp, timeoutInSeconds, tmpl);
|
||||
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _awaitAndPrintChanges(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, const char *tmpl)
|
||||
{
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_DATACHANGED, timeoutInSeconds);
|
||||
if (msg) {
|
||||
uint16_t code;
|
||||
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_DATACHANGED) {
|
||||
_handleDataResponse(msg, tmpl);
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||
GWEN_Msg_free(msg);
|
||||
}
|
||||
}
|
||||
} /* for */
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _handleDataResponse(GWEN_MSG *msg, const char *tmpl)
|
||||
{
|
||||
AQH_VALUE *value;
|
||||
const GWEN_TAG16 *tag;
|
||||
unsigned int numberOfPoints;
|
||||
const uint64_t *dataPoints;
|
||||
|
||||
AQH_MultiDataDataIpcMsg_Parse(msg, 0);
|
||||
value=AQH_MultiDataDataIpcMsg_ReadValue(msg);
|
||||
|
||||
tag=AQH_Tag16IpcMsg_FindFirstTagByType(msg, AQH_MSGDATA_MULTIDATA_TAGS_DATA);
|
||||
numberOfPoints=(tag?GWEN_Tag16_GetTagLength(tag):0)/(2*sizeof(uint64_t));
|
||||
dataPoints=tag?((const uint64_t*) GWEN_Tag16_GetTagData(tag)):NULL;
|
||||
if (numberOfPoints>0 && dataPoints) {
|
||||
uint32_t i;
|
||||
|
||||
for(i=0; i<numberOfPoints; i++) {
|
||||
uint64_t timestamp;
|
||||
union {double f; uint64_t i;} u;
|
||||
|
||||
timestamp=*(dataPoints++);
|
||||
u.i=*(dataPoints++);
|
||||
Utils_PrintFormattedSingleDataPoint(value, timestamp, u.f, tmpl);
|
||||
}
|
||||
}
|
||||
AQH_Value_free(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
21
apps/aqhome-tool/data/watch.h
Normal file
21
apps/aqhome-tool/data/watch.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/****************************************************************************
|
||||
* 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 AQHOME_TOOL_WATCH_H
|
||||
#define AQHOME_TOOL_WATCH_H
|
||||
|
||||
|
||||
#include <gwenhywfar/db.h>
|
||||
|
||||
|
||||
|
||||
int AQH_Tool_Watch(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include "./data/getlastdatapoint.h"
|
||||
#include "./data/setdata.h"
|
||||
#include "./data/moddevice.h"
|
||||
#include "./data/watch.h"
|
||||
|
||||
#include <aqhome/api.h>
|
||||
#include <aqhome/aqhome.h>
|
||||
@@ -83,6 +84,7 @@ int main(int argc, char **argv)
|
||||
GWEN_FE_DAH("getlastdata", AQH_Tool_GetLastDataPoint, I18N("Request last datapoint for a value on the data server")),
|
||||
GWEN_FE_DAH("setdata", AQH_Tool_SetData, I18N("Set data for a value on the data server (e.g. a switch or thermostat)")),
|
||||
GWEN_FE_DAH("moddevice", AQH_Tool_ModDevice, I18N("Modify a device on the data server")),
|
||||
GWEN_FE_DAH("watch", AQH_Tool_Watch, I18N("Watch and print changes of values on the data server")),
|
||||
GWEN_FE_END(),
|
||||
};
|
||||
const GWEN_FUNCS *func;
|
||||
@@ -165,7 +167,6 @@ int main(int argc, char **argv)
|
||||
AQH_Fini();
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,10 +19,13 @@
|
||||
#include "aqhome/ipc/data/ipc_data.h"
|
||||
#include "aqhome/ipc/data/msg_data_connect.h"
|
||||
#include "aqhome/ipc/msg_ipc_result.h"
|
||||
#include "aqhome/ipc/endpoint_ipcclient.h"
|
||||
|
||||
#include <gwenhywfar/endpoint_tcpc.h>
|
||||
#include <gwenhywfar/endpoint_multilayer.h>
|
||||
#include <gwenhywfar/debug.h>
|
||||
#include <gwenhywfar/timestamp.h>
|
||||
#include <gwenhywfar/db.h>
|
||||
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
@@ -32,9 +35,45 @@
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs, uint32_t flags)
|
||||
{
|
||||
return Utils_SetupIpcEndpoint(dbArgs, "tcpAddress", "tcpPort", "ConfigFile/brokerAddress", "ConfigFile/brokerPort", 1899);
|
||||
const char *brokerAddress;
|
||||
int brokerPort;
|
||||
const char *brokerClientId;
|
||||
|
||||
brokerAddress=GWEN_DB_GetCharValue(dbArgs, "brokerAddress", 0, NULL);
|
||||
if (!(brokerAddress && *brokerAddress))
|
||||
brokerAddress=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/brokerAddress", 0, "127.0.0.1");
|
||||
|
||||
brokerPort=GWEN_DB_GetIntValue(dbArgs, "brokerPort", 0, -1);
|
||||
if (brokerPort<0)
|
||||
brokerPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/brokerPort", 0, 45456);
|
||||
|
||||
brokerClientId=GWEN_DB_GetCharValue(dbArgs, "brokerClientId", 0, "aqhome-tool");
|
||||
|
||||
if (brokerAddress && *brokerAddress && brokerPort) {
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
GWEN_MSG_ENDPOINT *ipcBaseEndpoint;
|
||||
int rv;
|
||||
|
||||
ep=AQH_ClientIpcEndpoint_new("brokerIpcClient", 0);
|
||||
GWEN_MsgEndpoint_AddFlags(ep, flags);
|
||||
|
||||
ipcBaseEndpoint=AQH_IpcEndpoint_CreateIpcTcpClient(brokerAddress, brokerPort, "brokerPhysEndpoint", 0);
|
||||
AQH_IpcEndpoint_SetServiceName(ipcBaseEndpoint, brokerClientId);
|
||||
GWEN_MsgEndpoint_Tree2_AddChild(ep, ipcBaseEndpoint);
|
||||
|
||||
rv=GWEN_MultilayerEndpoint_StartConnect(ep);
|
||||
if (rv<0 && rv!=GWEN_ERROR_IN_PROGRESS) {
|
||||
DBG_ERROR(NULL, "Error connecting to broker server %s:%d (%d), will retry later", brokerAddress, brokerPort, rv);
|
||||
GWEN_MsgEndpoint_free(ep);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ep;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
@@ -228,7 +267,7 @@ GWEN_MSG_ENDPOINT *Utils_OpenBrokerConnection(GWEN_DB_NODE *dbArgs, uint32_t fla
|
||||
userId=GWEN_DB_GetCharValue(dbArgs, "userId", 0, NULL);
|
||||
password=GWEN_DB_GetCharValue(dbArgs, "password", 0, NULL);
|
||||
|
||||
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs);
|
||||
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs, 0);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return NULL;
|
||||
@@ -301,6 +340,60 @@ void Utils_PrintSingleDataPoint(uint64_t timestamp, double data, const char *val
|
||||
|
||||
|
||||
|
||||
void Utils_PrintFormattedSingleDataPoint(const AQH_VALUE *v, uint64_t timestamp, double data, const char *tmpl)
|
||||
{
|
||||
GWEN_DB_NODE *dbData;
|
||||
GWEN_TIMESTAMP *ts;
|
||||
|
||||
dbData=GWEN_DB_Group_new("data");
|
||||
if (v) {
|
||||
GWEN_DB_NODE *dbValue;
|
||||
|
||||
dbValue=GWEN_DB_Group_new("value");
|
||||
AQH_Value_toDb(v, dbValue);
|
||||
GWEN_DB_AddGroup(dbData, dbValue);
|
||||
}
|
||||
|
||||
ts=GWEN_Timestamp_fromLocalTime((time_t) timestamp);
|
||||
if (ts) {
|
||||
GWEN_BUFFER *buf;
|
||||
GWEN_DB_NODE *dbDataPoint;
|
||||
|
||||
dbDataPoint=GWEN_DB_Group_new("dataPoint");
|
||||
|
||||
buf=GWEN_Buffer_new(0, 256, 0, 1);
|
||||
GWEN_Buffer_AppendArgs(buf, "%04d/%02d/%02d-%02d:%02d:%02d",
|
||||
GWEN_Timestamp_GetYear(ts),
|
||||
GWEN_Timestamp_GetMonth(ts),
|
||||
GWEN_Timestamp_GetDay(ts),
|
||||
GWEN_Timestamp_GetHour(ts),
|
||||
GWEN_Timestamp_GetMinute(ts),
|
||||
GWEN_Timestamp_GetSecond(ts));
|
||||
GWEN_DB_SetCharValue(dbDataPoint, GWEN_DB_FLAGS_OVERWRITE_VARS, "timestampAsDate", GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Timestamp_free(ts);
|
||||
|
||||
GWEN_Buffer_Reset(buf);
|
||||
GWEN_Buffer_AppendArgs(buf, "%lu", (unsigned long int) timestamp);
|
||||
GWEN_DB_SetCharValue(dbDataPoint, GWEN_DB_FLAGS_OVERWRITE_VARS, "timestampAsInt", GWEN_Buffer_GetStart(buf));
|
||||
|
||||
GWEN_Buffer_Reset(buf);
|
||||
GWEN_Buffer_AppendArgs(buf, "%f", data);
|
||||
GWEN_DB_SetCharValue(dbDataPoint, GWEN_DB_FLAGS_OVERWRITE_VARS, "datapoint", GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_Reset(buf);
|
||||
|
||||
GWEN_DB_AddGroup(dbData, dbDataPoint);
|
||||
|
||||
GWEN_Buffer_Reset(buf);
|
||||
GWEN_DB_ReplaceVars(dbData, tmpl, buf);
|
||||
fprintf(stdout, "%s\n", GWEN_Buffer_GetStart(buf));
|
||||
GWEN_Buffer_free(buf);
|
||||
}
|
||||
|
||||
GWEN_DB_Group_free(dbData);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits)
|
||||
{
|
||||
if (numValues) {
|
||||
|
||||
@@ -24,7 +24,7 @@ GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs,
|
||||
const char *fileVarNameAddr,
|
||||
const char *fileVarNamePort,
|
||||
int defaultPort);
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs, uint32_t flags);
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupNodesClientEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int nodeAddr, int timeoutInSeconds);
|
||||
@@ -40,6 +40,7 @@ GWEN_MSG_ENDPOINT *Utils_OpenBrokerConnection(GWEN_DB_NODE *dbArgs, uint32_t fla
|
||||
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
||||
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_PrintFormattedSingleDataPoint(const AQH_VALUE *v, uint64_t timestamp, double data, const char *tmpl);
|
||||
|
||||
void Utils_PrintDevice(const AQH_DEVICE *device, int printHeader);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user