Read config file for fallback when no command line arguments are given.
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "./init.h"
|
||||
#include "./aqhome_data_p.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
|
||||
#include <gwenhywfar/gwenhywfar.h>
|
||||
@@ -83,6 +84,8 @@ int AqHomeData_Init(AQHOME_DATA *aqh, int argc, char **argv)
|
||||
DBG_ERROR(NULL, "Error reading args (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
AQH_MergeConfigFileIntoConfig(dbArgs, "ConfigFile");
|
||||
|
||||
aqh->dbArgs=dbArgs;
|
||||
|
||||
aqh->timeout=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 0);
|
||||
@@ -145,9 +148,14 @@ void _setupIpc(AQHOME_DATA *aqh, GWEN_DB_NODE *dbArgs)
|
||||
int tcpPort;
|
||||
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "tcpAddress", 0, NULL);
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, AQHOME_DATA_DEFAULT_IPC_PORT);
|
||||
if (!(tcpAddress && *tcpAddress))
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/brokerAddress", 0, NULL);
|
||||
|
||||
if (tcpAddress && *tcpAddress && tcpPort) {
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, -1);
|
||||
if (tcpPort<0)
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/brokerPort", 0, AQHOME_DATA_DEFAULT_IPC_PORT);
|
||||
|
||||
if (tcpAddress && *tcpAddress && tcpPort>0) {
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
|
||||
DBG_INFO(NULL, "Starting TCP service on \"%s\":%d", tcpAddress, tcpPort);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "./aqhomed_p.h"
|
||||
#include "./tty_log.h"
|
||||
|
||||
#include "aqhome/aqhome.h"
|
||||
#include "aqhome/msg/endpoint_tty.h"
|
||||
#include "aqhome/ipc/endpoint_ipc.h"
|
||||
#include "aqhome/ipc/endpoint_ipcclient.h"
|
||||
@@ -87,6 +88,7 @@ int AqHomed_Init(AQHOMED *aqh, int argc, char **argv)
|
||||
DBG_ERROR(NULL, "Error reading args (%d)", rv);
|
||||
return rv;
|
||||
}
|
||||
AQH_MergeConfigFileIntoConfig(dbArgs, "ConfigFile");
|
||||
aqh->dbArgs=dbArgs;
|
||||
|
||||
s=GWEN_DB_GetCharValue(dbArgs, "pidfile", 0, AQHOMED_DEFAULT_PIDFILE);
|
||||
@@ -150,7 +152,12 @@ void _setupIpcd(AQHOMED *aqh, GWEN_DB_NODE *dbArgs)
|
||||
int tcpPort;
|
||||
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "tcpAddress", 0, NULL);
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, AQHOMED_DEFAULT_IPC_PORT);
|
||||
if (!(tcpAddress && *tcpAddress))
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "ConfigFile/nodesAddress", 0, NULL);
|
||||
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, -1);
|
||||
if (tcpPort<0)
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "ConfigFile/nodesPort", 0, AQHOMED_DEFAULT_IPC_PORT);
|
||||
|
||||
if (tcpAddress && *tcpAddress && tcpPort) {
|
||||
GWEN_MSG_ENDPOINT *ep;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "./adddata.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"
|
||||
@@ -188,6 +189,8 @@ int AQH_Tool_AddDataPoint(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doAddData(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -242,7 +245,7 @@ int _doAddData(GWEN_DB_NODE *dbArgs)
|
||||
/*fprintf(stdout, "Sending AddData request\n");*/
|
||||
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#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_datapoints.h"
|
||||
@@ -190,6 +191,8 @@ int AQH_Tool_GetDataPoints(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doGetDataPoints(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -220,7 +223,7 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
return 2;
|
||||
}
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "./getdevices.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_devices.h"
|
||||
@@ -154,6 +155,8 @@ int AQH_Tool_GetDevices(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doGetDevices(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -169,7 +172,7 @@ int _doGetDevices(GWEN_DB_NODE *dbArgs)
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
printHeader=GWEN_DB_GetIntValue(dbArgs, "printHeader", 0, 0);
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "./getlastdatapoint.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_getdata.h"
|
||||
@@ -167,6 +168,8 @@ int AQH_Tool_GetLastDataPoint(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doGetLastDataPoint(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -182,7 +185,7 @@ int _doGetLastDataPoint(GWEN_DB_NODE *dbArgs)
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
valueName=GWEN_DB_GetCharValue(dbArgs, "valueName", 0, NULL);
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "./getvalues.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_values.h"
|
||||
@@ -143,6 +144,8 @@ int AQH_Tool_GetValues(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doGetValues(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -156,7 +159,7 @@ int _doGetValues(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "./moddevice.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_devices.h"
|
||||
@@ -198,6 +199,8 @@ int AQH_Tool_ModDevice(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doModDevice(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -213,7 +216,7 @@ int _doModDevice(GWEN_DB_NODE *dbArgs)
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
device=Utils_DeviceFromArgs(dbArgs);
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "./setdata.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"
|
||||
@@ -176,6 +177,8 @@ int AQH_Tool_SetData(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbLocalArgs, "ConfigFile");
|
||||
|
||||
return _doSetData(dbLocalArgs);
|
||||
}
|
||||
|
||||
@@ -215,7 +218,7 @@ int _doSetData(GWEN_DB_NODE *dbArgs)
|
||||
/*fprintf(stdout, "Sending SetData request\n");*/
|
||||
|
||||
|
||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||
epTcp=Utils_OpenBrokerConnection(dbArgs, 0, timeoutInSeconds);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -140,6 +140,8 @@ int main(int argc, char **argv)
|
||||
argv+=rv-1;
|
||||
}
|
||||
|
||||
AQH_MergeConfigFileIntoConfig(dbArgs, "ConfigFile");
|
||||
|
||||
s=GWEN_DB_GetCharValue(dbArgs, "charset", 0, NULL);
|
||||
if (s && *s)
|
||||
GWEN_Gui_SetCharSet(gui, s);
|
||||
@@ -169,3 +171,4 @@ int main(int argc, char **argv)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -212,7 +212,7 @@ int _doFlash(GWEN_DB_NODE *dbArgs)
|
||||
}
|
||||
|
||||
/* setup client connection */
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 3;
|
||||
|
||||
@@ -122,7 +122,7 @@ int _doGetNodes(GWEN_DB_NODE *dbArgs)
|
||||
int rv;
|
||||
int timeoutInSeconds;
|
||||
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -135,7 +135,7 @@ int _doPing(GWEN_DB_NODE *dbArgs)
|
||||
int timeoutInSeconds;
|
||||
GWEN_MSG *msg;
|
||||
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
epTcp=Utils_SetupNodesClientEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return 2;
|
||||
|
||||
@@ -32,15 +32,39 @@
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
return Utils_SetupIpcEndpoint(dbArgs, "tcpAddress", "tcpPort", "ConfigFile/brokerAddress", "ConfigFile/brokerPort", 1899);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupNodesClientEndpoint(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
return Utils_SetupIpcEndpoint(dbArgs, "tcpAddress", "tcpPort", "ConfigFile/nodesAddress", "ConfigFile/nodesPort", 45454);
|
||||
}
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs,
|
||||
const char *varNameAddr,
|
||||
const char *varNamePort,
|
||||
const char *fileVarNameAddr,
|
||||
const char *fileVarNamePort,
|
||||
int defaultPort)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
const char *tcpAddress;
|
||||
int tcpPort;
|
||||
int rv;
|
||||
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, "tcpAddress", 0, "127.0.0.1");
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, "tcpPort", 0, 45454);
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, varNameAddr, 0, NULL);
|
||||
if (!(tcpAddress && *tcpAddress))
|
||||
tcpAddress=GWEN_DB_GetCharValue(dbArgs, fileVarNameAddr, 0, "127.0.0.1");
|
||||
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, varNamePort, 0, -1);
|
||||
if (tcpPort<0)
|
||||
tcpPort=GWEN_DB_GetIntValue(dbArgs, fileVarNamePort, 0, defaultPort);
|
||||
|
||||
DBG_INFO(NULL, "Setup tcp client endpoint to %s:%d", tcpAddress, tcpPort);
|
||||
epTcp=AQH_IpcEndpoint_CreateIpcTcpClient(tcpAddress, tcpPort, "aqhome-tool-IPC", 0);
|
||||
@@ -190,7 +214,7 @@ int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups)
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_OpenConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, int timeoutInSeconds)
|
||||
GWEN_MSG_ENDPOINT *Utils_OpenBrokerConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, int timeoutInSeconds)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
GWEN_MSG *msgOut;
|
||||
@@ -204,7 +228,7 @@ GWEN_MSG_ENDPOINT *Utils_OpenConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, in
|
||||
userId=GWEN_DB_GetCharValue(dbArgs, "userId", 0, NULL);
|
||||
password=GWEN_DB_GetCharValue(dbArgs, "password", 0, NULL);
|
||||
|
||||
epTcp=Utils_SetupIpcEndpoint(dbArgs);
|
||||
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
return NULL;
|
||||
|
||||
@@ -18,7 +18,14 @@
|
||||
|
||||
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupIpcEndpoint(GWEN_DB_NODE *dbArgs,
|
||||
const char *varNameAddr,
|
||||
const char *varNamePort,
|
||||
const char *fileVarNameAddr,
|
||||
const char *fileVarNamePort,
|
||||
int defaultPort);
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupBrokerClientEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
GWEN_MSG_ENDPOINT *Utils_SetupNodesClientEndpoint(GWEN_DB_NODE *dbArgs);
|
||||
|
||||
GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int nodeAddr, int timeoutInSeconds);
|
||||
|
||||
@@ -28,7 +35,7 @@ int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||
|
||||
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);
|
||||
|
||||
GWEN_MSG_ENDPOINT *Utils_OpenConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, int timeoutInSeconds);
|
||||
GWEN_MSG_ENDPOINT *Utils_OpenBrokerConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, int timeoutInSeconds);
|
||||
|
||||
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
||||
void Utils_PrintSingleDataPoint(uint64_t timestamp, double data, const char *valueUnits);
|
||||
|
||||
Reference in New Issue
Block a user