Decreased verbosity.
This commit is contained in:
@@ -176,7 +176,7 @@ void _handleIpcMsg(AQHOME_DATA *aqh, GWEN_MSG_ENDPOINT *ep, const GWEN_MSG *msg)
|
|||||||
|
|
||||||
/* exec IPC message */
|
/* exec IPC message */
|
||||||
code=GWEN_IpcMsg_GetCode(msg);
|
code=GWEN_IpcMsg_GetCode(msg);
|
||||||
DBG_ERROR(AQH_LOGDOMAIN, "Received IPC packet %d (%x)", (int) code, code);
|
DBG_DEBUG(AQH_LOGDOMAIN, "Received IPC packet %d (%x)", (int) code, code);
|
||||||
switch(code) {
|
switch(code) {
|
||||||
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: AqHomeData_HandleConnect(aqh, ep, msg); break;
|
case AQH_MSGTYPE_IPC_DATA_CONNECT_REQ: AqHomeData_HandleConnect(aqh, ep, msg); break;
|
||||||
case AQH_MSGTYPE_IPC_DATA_UPDATEDATA: AqHomeData_HandleUpdateData(aqh, ep, msg); break;
|
case AQH_MSGTYPE_IPC_DATA_UPDATEDATA: AqHomeData_HandleUpdateData(aqh, ep, msg); break;
|
||||||
|
|||||||
@@ -239,7 +239,7 @@ int _doAddData(GWEN_DB_NODE *dbArgs)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "Sending AddData request\n");
|
/*fprintf(stdout, "Sending AddData request\n");*/
|
||||||
|
|
||||||
|
|
||||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||||
|
|||||||
@@ -33,7 +33,8 @@
|
|||||||
|
|
||||||
|
|
||||||
static int _doGetDataPoints(GWEN_DB_NODE *dbArgs);
|
static int _doGetDataPoints(GWEN_DB_NODE *dbArgs);
|
||||||
static void _sendCommand(GWEN_MSG_ENDPOINT *epTcp, const char *valueName, uint64_t tsBegin, uint64_t tsEnd);
|
static int _awaitAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||||
|
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
|
||||||
static uint64_t _getTimeStampFromString(const char *s);
|
static uint64_t _getTimeStampFromString(const char *s);
|
||||||
|
|
||||||
|
|
||||||
@@ -110,6 +111,17 @@ int AQH_Tool_GetDataPoints(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
|||||||
I18S("Get data up until this timestamp (latest timestamp if omitted)"),
|
I18S("Get data up until this timestamp (latest timestamp if omitted)"),
|
||||||
I18S("Get data up until this timestamp (latest timestamp if omitted)")
|
I18S("Get data up until this timestamp (latest timestamp if omitted)")
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
0, /* flags */
|
||||||
|
GWEN_ArgsType_Int, /* type */
|
||||||
|
"printMean", /* name */
|
||||||
|
0, /* minnum */
|
||||||
|
1, /* maxnum */
|
||||||
|
"M", /* short option */
|
||||||
|
"mean", /* long option */
|
||||||
|
I18S("Print mean value of data received"),
|
||||||
|
I18S("Print mean value of data received")
|
||||||
|
},
|
||||||
{
|
{
|
||||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||||
GWEN_ArgsType_Char, /* type */
|
GWEN_ArgsType_Char, /* type */
|
||||||
@@ -187,11 +199,14 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
|||||||
{
|
{
|
||||||
GWEN_MSG_ENDPOINT *epTcp;
|
GWEN_MSG_ENDPOINT *epTcp;
|
||||||
int timeoutInSeconds;
|
int timeoutInSeconds;
|
||||||
GWEN_MSG *msg;
|
|
||||||
const char *valueName;
|
const char *valueName;
|
||||||
uint64_t tsBegin;
|
uint64_t tsBegin;
|
||||||
uint64_t tsEnd;
|
uint64_t tsEnd;
|
||||||
|
GWEN_MSG *msgOut;
|
||||||
|
int printMean;
|
||||||
|
int rv;
|
||||||
|
|
||||||
|
printMean=GWEN_DB_GetIntValue(dbArgs, "printMean", 0, 0);
|
||||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||||
valueName=GWEN_DB_GetCharValue(dbArgs, "valueName", 0, NULL);
|
valueName=GWEN_DB_GetCharValue(dbArgs, "valueName", 0, NULL);
|
||||||
tsBegin=_getTimeStampFromString(GWEN_DB_GetCharValue(dbArgs, "tsBegin", 0, NULL));
|
tsBegin=_getTimeStampFromString(GWEN_DB_GetCharValue(dbArgs, "tsBegin", 0, NULL));
|
||||||
@@ -211,11 +226,27 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "Sending GetDataPoints request\n");
|
/*fprintf(stdout, "Sending GetDataPoints request\n");*/
|
||||||
|
|
||||||
_sendCommand(epTcp, valueName, tsBegin, tsEnd);
|
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);
|
||||||
|
if (rv!=0) {
|
||||||
|
GWEN_MsgEndpoint_free(epTcp);
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
|
GWEN_MsgEndpoint_free(epTcp);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _awaitAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||||
|
{
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
GWEN_MSG *msg;
|
||||||
uint16_t code;
|
uint16_t code;
|
||||||
|
|
||||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, timeoutInSeconds);
|
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_GETDATA_RSP, timeoutInSeconds);
|
||||||
@@ -231,12 +262,59 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
|||||||
AQH_DataPointsDataIpcMsg_GetUnits(msg));
|
AQH_DataPointsDataIpcMsg_GetUnits(msg));
|
||||||
if (AQH_DataPointsDataIpcMsg_GetFlags(msg) & AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG) {
|
if (AQH_DataPointsDataIpcMsg_GetFlags(msg) & AQH_MSGDATA_DATAPOINTS_FLAGS_LASTMSG) {
|
||||||
DBG_INFO(NULL, "Last message received");
|
DBG_INFO(NULL, "Last message received");
|
||||||
|
GWEN_Msg_free(msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_ERROR(NULL, "Invalid message received");
|
DBG_ERROR(NULL, "Invalid message received");
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
GWEN_Msg_free(msg);
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
GWEN_Msg_free(msg);
|
||||||
|
}
|
||||||
|
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||||
|
uint32_t resultCode;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
|
||||||
|
{
|
||||||
|
for (;;) {
|
||||||
|
GWEN_MSG *msg;
|
||||||
|
uint16_t code;
|
||||||
|
|
||||||
|
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;
|
return 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -245,43 +323,44 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
|||||||
|
|
||||||
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
|
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
|
||||||
fprintf(stderr, "ERROR: %d\n", resultCode);
|
fprintf(stderr, "ERROR: %d\n", resultCode);
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
GWEN_Msg_free(msg);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
GWEN_Msg_free(msg);
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
GWEN_MsgEndpoint_free(epTcp);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void _sendCommand(GWEN_MSG_ENDPOINT *epTcp, const char *valueName, uint64_t tsBegin, uint64_t tsEnd)
|
|
||||||
{
|
|
||||||
GWEN_MSG *msgOut;
|
|
||||||
|
|
||||||
msgOut=AQH_GetDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_REQ, valueName, tsBegin, tsEnd);
|
|
||||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t _getTimeStampFromString(const char *s)
|
uint64_t _getTimeStampFromString(const char *s)
|
||||||
{
|
{
|
||||||
if (s && *s) {
|
if (s && *s) {
|
||||||
|
if (*s=='-') {
|
||||||
|
unsigned long int x;
|
||||||
|
unsigned long int now=time(NULL);
|
||||||
|
|
||||||
|
s++;
|
||||||
|
if (1!=sscanf(s, "%lu", &x)) {
|
||||||
|
DBG_ERROR(NULL, "ERROR: Invalid timestamp");
|
||||||
|
return (uint64_t) (-1);
|
||||||
|
}
|
||||||
|
return (uint64_t) (now-x);
|
||||||
|
}
|
||||||
|
else {
|
||||||
unsigned long int x;
|
unsigned long int x;
|
||||||
|
|
||||||
if (1!=sscanf("%lu", s, &x)) {
|
if (1!=sscanf(s, "%lu", &x)) {
|
||||||
DBG_ERROR(NULL, "ERROR: Invalid timestamp");
|
DBG_ERROR(NULL, "ERROR: Invalid timestamp");
|
||||||
return (uint64_t) (-1);
|
return (uint64_t) (-1);
|
||||||
}
|
}
|
||||||
return (uint64_t) x;
|
return (uint64_t) x;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,7 +188,7 @@ int _doGetLastDataPoint(GWEN_DB_NODE *dbArgs)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "Sending GetLastDataPoint request (%s)\n", valueName);
|
/*fprintf(stdout, "Sending GetLastDataPoint request (%s)\n", valueName);*/
|
||||||
|
|
||||||
_sendCommand(epTcp, valueName);
|
_sendCommand(epTcp, valueName);
|
||||||
|
|
||||||
|
|||||||
@@ -162,7 +162,7 @@ int _doGetValues(GWEN_DB_NODE *dbArgs)
|
|||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "Sending GetValues request\n");
|
/*fprintf(stdout, "Sending GetValues request\n");*/
|
||||||
|
|
||||||
_sendCommand(epTcp);
|
_sendCommand(epTcp);
|
||||||
|
|
||||||
|
|||||||
@@ -212,7 +212,7 @@ int _doSetData(GWEN_DB_NODE *dbArgs)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "Sending SetData request\n");
|
/*fprintf(stdout, "Sending SetData request\n");*/
|
||||||
|
|
||||||
|
|
||||||
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
epTcp=Utils_OpenConnection(dbArgs, 0, timeoutInSeconds);
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
GWEN_Logger_Open(0, "aqhome-tool", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User);
|
GWEN_Logger_Open(0, "aqhome-tool", 0, GWEN_LoggerType_Console, GWEN_LoggerFacility_User);
|
||||||
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Notice);
|
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Notice);
|
||||||
GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);
|
/*GWEN_Logger_SetLevel(0, GWEN_LoggerLevel_Info);*/
|
||||||
|
|
||||||
rv=AQH_Init();
|
rv=AQH_Init();
|
||||||
if (rv<0) {
|
if (rv<0) {
|
||||||
|
|||||||
@@ -262,5 +262,26 @@ void Utils_PrintSingleDataPoint(uint64_t timestamp, double data, const char *val
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits)
|
||||||
|
{
|
||||||
|
if (numValues) {
|
||||||
|
uint32_t i;
|
||||||
|
uint64_t timestamp=0;
|
||||||
|
double total=0.0;
|
||||||
|
|
||||||
|
for(i=0; i<numValues; i++) {
|
||||||
|
union {double f; uint64_t i;} u;
|
||||||
|
|
||||||
|
timestamp=*(dataPoints++); /* use last timestamp encountered */
|
||||||
|
u.i=*(dataPoints++);
|
||||||
|
total+=u.f;
|
||||||
|
}
|
||||||
|
total=total/(double)numValues;
|
||||||
|
Utils_PrintSingleDataPoint(timestamp, total, valueUnits);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ GWEN_MSG_ENDPOINT *Utils_OpenConnection(GWEN_DB_NODE *dbArgs, uint32_t flags, in
|
|||||||
|
|
||||||
void Utils_PrintDataPoints(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
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_PrintSingleDataPoint(uint64_t timestamp, double data, const char *valueUnits);
|
||||||
|
void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
export AQHOME_LOGLEVEL=info
|
#export AQHOME_LOGLEVEL=info
|
||||||
export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH"
|
export LD_LIBRARY_PATH="0-build/aqhome/:$LD_LIBRARY_PATH"
|
||||||
|
|
||||||
# 0-build/apps/aqhome-tool/aqhome-tool ping -n 2 -T 5
|
# 0-build/apps/aqhome-tool/aqhome-tool ping -n 2 -T 5
|
||||||
|
|||||||
Reference in New Issue
Block a user