aqhome-tool: add Utils_WaitForResponse()

This commit is contained in:
Martin Preuss
2024-10-01 22:34:55 +02:00
parent 8f6291ef02
commit d2ac801223
2 changed files with 41 additions and 0 deletions

View File

@@ -215,6 +215,45 @@ GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp,
GWEN_MSG *Utils_WaitForResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds)
{
time_t startTime;
startTime=time(NULL);
for (;;) {
GWEN_MSG *msg;
time_t now;
GWEN_MsgEndpoint_IoLoop(epTcp, 2000); /* 2000 ms */
msg=GWEN_MsgEndpoint_TakeFirstReceivedMessage(epTcp);
if (msg) {
if (GWEN_IpcMsg_GetRefMsgId(msg)==msgId) {
DBG_INFO(NULL, "Received expected IPC message");
return msg;
}
else {
uint16_t code;
code=GWEN_IpcMsg_GetCode(msg);
DBG_ERROR(NULL,
"Received unexpected message %d (%x) [msgId=%d, refMsgId=%d]",
code, code, GWEN_IpcMsg_GetMsgId(msg), GWEN_IpcMsg_GetRefMsgId(msg));
}
GWEN_Msg_free(msg);
}
now=time(NULL);
if (now-startTime>timeoutInSeconds) {
DBG_ERROR(NULL, "Timeout");
break;
}
}
return NULL;
}
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds)
{
time_t startTime;

View File

@@ -31,6 +31,8 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode
GWEN_MSG *Utils_WaitForSpecificIpcMessage(GWEN_MSG_ENDPOINT *epTcp, int msgCode, int timeoutInSeconds);
GWEN_MSG *Utils_WaitForResponse(GWEN_MSG_ENDPOINT *epTcp, uint32_t msgId, int timeoutInSeconds);
int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds);
int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);