From 0add18eeb72817ee9244c89433b2920f981e67b3 Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sat, 22 Apr 2023 12:45:42 +0200 Subject: [PATCH] aqhome: added Utils_FlushOutMessageQueue --- apps/aqhome-tool/utils.c | 23 +++++++++++++++++++++++ apps/aqhome-tool/utils.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/apps/aqhome-tool/utils.c b/apps/aqhome-tool/utils.c index cdd69ad..173d668 100644 --- a/apps/aqhome-tool/utils.c +++ b/apps/aqhome-tool/utils.c @@ -93,6 +93,29 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG +int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds) +{ + time_t startTime; + + startTime=time(NULL); + + while(GWEN_MsgEndpoint_HaveMessageToSend(epTcp)) { + time_t now; + + GWEN_MsgEndpointMgr_RunAllEndpoints(emgr); + GWEN_MsgEndpointMgr_IoLoopOnce(emgr); + now=time(NULL); + if (now-startTime>timeoutInSeconds) { + DBG_INFO(NULL, "Timeout"); + return GWEN_ERROR_TIMEOUT; + } + } + + return 0; +} + + + int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups) { GWEN_MSG *msgOut; diff --git a/apps/aqhome-tool/utils.h b/apps/aqhome-tool/utils.h index de4d4d0..f33b611 100644 --- a/apps/aqhome-tool/utils.h +++ b/apps/aqhome-tool/utils.h @@ -22,6 +22,8 @@ GWEN_MSG *Utils_WaitForSpecificNodeMessage(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG int nodeAddr, int timeoutInSeconds); +int Utils_FlushOutMessageQueue(GWEN_MSG_ENDPOINT_MGR *emgr, GWEN_MSG_ENDPOINT *epTcp, int timeoutInSeconds); + int Utils_SendAcceptedMsgGroups(GWEN_MSG_ENDPOINT *epTcp, uint32_t groups);