Added functionality to print a value difference.
Also call GWEN_MsgEndpoint_IoLoop() only after checking all messages in the endpoint's list.
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#define I18S(msg) msg
|
||||
@@ -35,8 +36,8 @@
|
||||
|
||||
|
||||
static int _doGetDataPoints(GWEN_DB_NODE *dbArgs);
|
||||
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean);
|
||||
static void _handleDataResponse(GWEN_MSG *msg, int printMean);
|
||||
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean, int printDiff);
|
||||
static void _handleDataResponse(GWEN_MSG *msg, int printMean, int printDiff);
|
||||
static uint64_t _getTimeStampFromString(const char *s);
|
||||
|
||||
|
||||
@@ -135,6 +136,17 @@ int AQH_Tool_GetDataPoints(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
I18S("Print mean value of data received"),
|
||||
I18S("Print mean value of data received")
|
||||
},
|
||||
{
|
||||
0, /* flags */
|
||||
GWEN_ArgsType_Int, /* type */
|
||||
"printDiff", /* name */
|
||||
0, /* minnum */
|
||||
1, /* maxnum */
|
||||
"D", /* short option */
|
||||
"diff", /* long option */
|
||||
I18S("Print difference between last and first datapoint received"),
|
||||
I18S("Print difference between last and first datapoint received")
|
||||
},
|
||||
{
|
||||
GWEN_ARGS_FLAGS_HAS_ARGUMENT, /* flags */
|
||||
GWEN_ArgsType_Char, /* type */
|
||||
@@ -220,9 +232,11 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
uint64_t num;
|
||||
GWEN_MSG *msgOut;
|
||||
int printMean;
|
||||
int printDiff;
|
||||
int rv;
|
||||
|
||||
printMean=GWEN_DB_GetIntValue(dbArgs, "printMean", 0, 0);
|
||||
printDiff=GWEN_DB_GetIntValue(dbArgs, "printDiff", 0, 0);
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
valueName=GWEN_DB_GetCharValue(dbArgs, "valueName", 0, NULL);
|
||||
num=GWEN_DB_GetIntValue(dbArgs, "numOfLastDatapoints", 0, 0);
|
||||
@@ -247,7 +261,7 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
msgOut=AQH_GetDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_REQ, valueName, tsBegin, tsEnd, num);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
|
||||
rv=_awaitAndCalcAndPrintResponse(epTcp, timeoutInSeconds, printMean?1:0);
|
||||
rv=_awaitAndCalcAndPrintResponse(epTcp, timeoutInSeconds, printMean?1:0, printDiff?1:0);
|
||||
if (rv!=0) {
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return rv;
|
||||
@@ -259,7 +273,7 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
|
||||
|
||||
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean)
|
||||
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean, int printDiff)
|
||||
{
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
@@ -272,7 +286,7 @@ int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds
|
||||
}
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETDATA_RSP) {
|
||||
_handleDataResponse(msg, printMean);
|
||||
_handleDataResponse(msg, printMean, printDiff);
|
||||
GWEN_Msg_free(msg);
|
||||
return 0;
|
||||
}
|
||||
@@ -295,7 +309,7 @@ int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds
|
||||
|
||||
|
||||
|
||||
void _handleDataResponse(GWEN_MSG *msg, int printMean)
|
||||
void _handleDataResponse(GWEN_MSG *msg, int printMean, int printDiff)
|
||||
{
|
||||
AQH_VALUE *value;
|
||||
const GWEN_TAG16 *tag;
|
||||
@@ -313,6 +327,8 @@ void _handleDataResponse(GWEN_MSG *msg, int printMean)
|
||||
if (numberOfPoints>0 && dataPoints) {
|
||||
if (printMean)
|
||||
Utils_PrintMeanData(dataPoints, numberOfPoints, valueUnits);
|
||||
else if (printDiff)
|
||||
Utils_PrintDiffData(dataPoints, numberOfPoints, valueUnits);
|
||||
else
|
||||
Utils_PrintDataPoints(dataPoints, numberOfPoints, valueUnits);
|
||||
}
|
||||
@@ -326,15 +342,27 @@ uint64_t _getTimeStampFromString(const char *s)
|
||||
{
|
||||
if (s && *s) {
|
||||
if (*s=='-') {
|
||||
unsigned long int x;
|
||||
unsigned long int now=time(NULL);
|
||||
uint64_t x=0;
|
||||
uint64_t now=time(NULL);
|
||||
|
||||
s++;
|
||||
if (1!=sscanf(s, "%lu", &x)) {
|
||||
DBG_ERROR(NULL, "ERROR: Invalid timestamp");
|
||||
return (uint64_t) (-1);
|
||||
while(*s && isdigit(*s)) {
|
||||
unsigned int i;
|
||||
|
||||
i=*(s++)-'0';
|
||||
x*=10;
|
||||
x+=i;
|
||||
}
|
||||
return (uint64_t) (now-x);
|
||||
if (*s) {
|
||||
switch(*s) {
|
||||
case 0:
|
||||
case 'm': x*=60; break;
|
||||
case 'h': x*=(60*60); break;
|
||||
case 'd': x*=(60*60*24); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
return (now-x);
|
||||
}
|
||||
else {
|
||||
unsigned long int x;
|
||||
|
||||
Reference in New Issue
Block a user