From d2ac8012235141b3acd1e3de839ae3dce7339275 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Tue, 1 Oct 2024 22:34:55 +0200 Subject: [PATCH] aqhome-tool: add Utils_WaitForResponse() --- apps/aqhome-tool/utils.c | 39 +++++++++++++++++++++++++++++++++++++++ apps/aqhome-tool/utils.h | 2 ++ 2 files changed, 41 insertions(+) diff --git a/apps/aqhome-tool/utils.c b/apps/aqhome-tool/utils.c index f59376e..f326c51 100644 --- a/apps/aqhome-tool/utils.c +++ b/apps/aqhome-tool/utils.c @@ -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; diff --git a/apps/aqhome-tool/utils.h b/apps/aqhome-tool/utils.h index e1451b4..f511065 100644 --- a/apps/aqhome-tool/utils.h +++ b/apps/aqhome-tool/utils.h @@ -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);