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:
Martin Preuss
2023-10-21 02:19:16 +02:00
parent b818065b9b
commit 62abfd56e9
3 changed files with 80 additions and 16 deletions

View File

@@ -137,9 +137,7 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp,
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
while( (msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp)) ) {
if (GWEN_IpcMsg_GetCode(msg)==AQH_MSGTYPE_IPC_NODES_FORWARD) {
GWEN_MSG *nodeMsg;
@@ -160,12 +158,13 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp,
DBG_INFO(NULL, "Received IPC message %d, ignoring", GWEN_IpcMsg_GetCode(msg));
}
GWEN_Msg_free(msg);
}
} /* while */
now=time(NULL);
if (now-startTime>timeoutInSeconds) {
DBG_INFO(NULL, "Timeout");
break;
}
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
}
return NULL;
@@ -415,6 +414,42 @@ void Utils_PrintMeanData(const uint64_t *dataPoints, uint32_t numValues, const c
void Utils_PrintDiffData(const uint64_t *dataPoints, uint32_t numValues, const char *valueUnits)
{
if (numValues) {
if (numValues>1) {
uint64_t timestamp=0;
double valueFirst=0.0;
double valueLast=0.0;
double valueDiff=0.0;
union {double f; uint64_t i;} u;
/* ignore timestamp of first datapoint */
u.i=dataPoints[1];
valueFirst=u.f;
timestamp=dataPoints[(numValues-1)*2];
u.i=dataPoints[((numValues-1)*2)+1];
valueLast=u.f;
valueDiff=valueLast-valueFirst;
Utils_PrintSingleDataPoint(timestamp, valueDiff, valueUnits);
}
else {
uint64_t timestamp;
union {double f; uint64_t i;} u;
timestamp=dataPoints[0];
u.i=dataPoints[1];
Utils_PrintSingleDataPoint(timestamp, u.f, valueUnits);
}
}
}
void Utils_PrintDevice(const AQH_DEVICE *device, int printHeader)
{
GWEN_TIMESTAMP *ts;