aqhome-tool: use refMsgId when waiting for response.
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
|
||||
|
||||
static int _doGetDataPoints(GWEN_DB_NODE *dbArgs);
|
||||
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean, int printDiff);
|
||||
static int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds, int printMean, int printDiff);
|
||||
static void _handleDataResponse(GWEN_MSG *msg, int printMean, int printDiff);
|
||||
static uint64_t _getTimeStampFromString(const char *s);
|
||||
|
||||
@@ -234,6 +234,7 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
int printMean;
|
||||
int printDiff;
|
||||
int rv;
|
||||
uint32_t msgId;
|
||||
|
||||
printMean=GWEN_DB_GetIntValue(dbArgs, "printMean", 0, 0);
|
||||
printDiff=GWEN_DB_GetIntValue(dbArgs, "printDiff", 0, 0);
|
||||
@@ -257,13 +258,11 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*fprintf(stdout, "Sending GetDataPoints request\n");*/
|
||||
msgOut=AQH_GetDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_REQ,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
||||
valueName, tsBegin, tsEnd, num);
|
||||
msgId=GWEN_MsgEndpoint_GetNextMessageId(epTcp);
|
||||
msgOut=AQH_GetDataDataIpcMsg_new(AQH_MSGTYPE_IPC_DATA_GETDATA_REQ, msgId, 0, valueName, tsBegin, tsEnd, num);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
|
||||
rv=_awaitAndCalcAndPrintResponse(epTcp, timeoutInSeconds, printMean?1:0, printDiff?1:0);
|
||||
rv=_awaitAndCalcAndPrintResponse(epTcp, msgId, timeoutInSeconds, printMean?1:0, printDiff?1:0);
|
||||
if (rv!=0) {
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return rv;
|
||||
@@ -275,35 +274,38 @@ int _doGetDataPoints(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
|
||||
|
||||
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds, int printMean, int printDiff)
|
||||
int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds, int printMean, int printDiff)
|
||||
{
|
||||
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) {
|
||||
_handleDataResponse(msg, printMean, printDiff);
|
||||
GWEN_Msg_free(msg);
|
||||
return 0;
|
||||
}
|
||||
else if (code==AQH_MSGTYPE_IPC_DATA_RESULT) {
|
||||
uint32_t resultCode;
|
||||
msg=Utils_WaitForResponse(epTcp, msgId, timeoutInSeconds);
|
||||
if (msg) {
|
||||
uint16_t code;
|
||||
|
||||
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
|
||||
fprintf(stderr, "ERROR: %d\n", resultCode);
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETDATA_RSP) {
|
||||
_handleDataResponse(msg, printMean, printDiff);
|
||||
GWEN_Msg_free(msg);
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
DBG_ERROR(NULL, "No response received");
|
||||
return 2;
|
||||
}
|
||||
} /* for */
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user