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,17 +274,15 @@ 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;
|
||||
|
||||
msg=Utils_WaitForResponse(epTcp, msgId, timeoutInSeconds);
|
||||
if (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);
|
||||
@@ -305,6 +302,11 @@ int _awaitAndCalcAndPrintResponse(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
else {
|
||||
DBG_ERROR(NULL, "No response received");
|
||||
return 2;
|
||||
}
|
||||
} /* for */
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
|
||||
|
||||
static int _doGetValues(GWEN_DB_NODE *dbArgs);
|
||||
static void _sendCommand(GWEN_MSG_ENDPOINT *epTcp);
|
||||
static uint32_t _sendRequest(GWEN_MSG_ENDPOINT *epTcp);
|
||||
static int _handleResponses(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds);
|
||||
|
||||
|
||||
|
||||
@@ -155,7 +156,8 @@ int _doGetValues(GWEN_DB_NODE *dbArgs)
|
||||
{
|
||||
GWEN_MSG_ENDPOINT *epTcp;
|
||||
int timeoutInSeconds;
|
||||
GWEN_MSG *msg;
|
||||
uint32_t msgId;
|
||||
int rv;
|
||||
|
||||
timeoutInSeconds=GWEN_DB_GetIntValue(dbArgs, "timeout", 0, 5);
|
||||
|
||||
@@ -165,18 +167,41 @@ int _doGetValues(GWEN_DB_NODE *dbArgs)
|
||||
return 2;
|
||||
}
|
||||
|
||||
/*fprintf(stdout, "Sending GetValues request\n");*/
|
||||
msgId=_sendRequest(epTcp);
|
||||
rv=_handleResponses(epTcp, msgId, timeoutInSeconds);
|
||||
if (rv!=0) {
|
||||
DBG_ERROR(NULL, "here (%d)", rv);
|
||||
}
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return rv;
|
||||
}
|
||||
|
||||
_sendCommand(epTcp);
|
||||
|
||||
|
||||
uint32_t _sendRequest(GWEN_MSG_ENDPOINT *epTcp)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
uint32_t msgId;
|
||||
|
||||
msgId=GWEN_MsgEndpoint_GetNextMessageId(epTcp);
|
||||
msgOut=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ,
|
||||
msgId, 0,
|
||||
0, NULL);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
return msgId;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int _handleResponses(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds)
|
||||
{
|
||||
for (;;) {
|
||||
GWEN_MSG *msg;
|
||||
|
||||
msg=Utils_WaitForResponse(epTcp, msgId, timeoutInSeconds);
|
||||
if (msg) {
|
||||
uint16_t code;
|
||||
|
||||
msg=Utils_WaitForSpecificIpcMessage(epTcp, AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP, timeoutInSeconds);
|
||||
if (msg==NULL) {
|
||||
DBG_ERROR(NULL, "No response received");
|
||||
return 2;
|
||||
}
|
||||
code=GWEN_IpcMsg_GetCode(msg);
|
||||
if (code==AQH_MSGTYPE_IPC_DATA_GETVALUES_RSP) {
|
||||
AQH_VALUE_LIST *valueList;
|
||||
@@ -208,6 +233,7 @@ int _doGetValues(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
if (AQH_ValuesDataIpcMsg_GetFlags(msg) & AQH_MSGDATA_VALUES_FLAGS_LASTMSG) {
|
||||
DBG_INFO(NULL, "Last message received");
|
||||
GWEN_Msg_free(msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -216,34 +242,24 @@ int _doGetValues(GWEN_DB_NODE *dbArgs)
|
||||
|
||||
resultCode=AQH_ResultIpcMsg_GetResultCode(msg);
|
||||
fprintf(stderr, "ERROR: %d\n", resultCode);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
else {
|
||||
DBG_INFO(NULL, "Unexpected message \"%d\"", code);
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
GWEN_Msg_free(msg);
|
||||
return 3;
|
||||
}
|
||||
} /* if msg */
|
||||
else {
|
||||
DBG_ERROR(NULL, "No response received");
|
||||
return 2;
|
||||
}
|
||||
} /* for */
|
||||
|
||||
GWEN_MsgEndpoint_free(epTcp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void _sendCommand(GWEN_MSG_ENDPOINT *epTcp)
|
||||
{
|
||||
GWEN_MSG *msgOut;
|
||||
|
||||
msgOut=GWEN_IpcMsg_new(AQH_IPC_PROTOCOL_DATA_ID, AQH_IPC_PROTOCOL_DATA_VERSION, AQH_MSGTYPE_IPC_DATA_GETVALUES_REQ,
|
||||
GWEN_MsgEndpoint_GetNextMessageId(epTcp), 0,
|
||||
0, NULL);
|
||||
GWEN_MsgEndpoint_AddSendMessage(epTcp, msgOut);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,12 +32,21 @@
|
||||
#define I18N(msg) GWEN_I18N_Translate(PACKAGE, msg)
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* forward declarations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
static int _doSetData(GWEN_DB_NODE *dbArgs);
|
||||
static uint32_t _sendRequest(GWEN_MSG_ENDPOINT *epTcp, const char *valueName, const char *valueUnits, const char *valueData);
|
||||
static int _awaitResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds);
|
||||
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------
|
||||
* implementations
|
||||
* ------------------------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
int AQH_Tool_SetData(GWEN_DB_NODE *dbGlobalArgs, int argc, char **argv)
|
||||
{
|
||||
@@ -209,9 +218,6 @@ int _doSetData(GWEN_DB_NODE *dbArgs)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*fprintf(stdout, "Sending SetData request\n");*/
|
||||
|
||||
|
||||
epTcp=Utils_SetupBrokerClientEndpoint(dbArgs, 0);
|
||||
if (epTcp==NULL) {
|
||||
DBG_ERROR(NULL, "ERROR creating TCP connection");
|
||||
|
||||
Reference in New Issue
Block a user