From 83918bc76ff99a8042706fc8cc1b75a33775a401 Mon Sep 17 00:00:00 2001 From: Vitalii Kozhukhivskyi Date: Thu, 9 Mar 2017 14:33:27 -0800 Subject: [PATCH] Add timeout parameter to NodeAPI's ping function (#1440) * Added timeout variable to API's ping function (WIN only). --- examples/drivers/windows/include/otNode.h | 2 +- examples/drivers/windows/otNodeApi/otNodeApi.cpp | 5 +++-- tests/scripts/thread-cert/node.py | 4 ++-- tests/scripts/thread-cert/node_api.py | 8 +++++--- tests/scripts/thread-cert/node_cli.py | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/examples/drivers/windows/include/otNode.h b/examples/drivers/windows/include/otNode.h index b08a4eaca..8b8a95bae 100644 --- a/examples/drivers/windows/include/otNode.h +++ b/examples/drivers/windows/include/otNode.h @@ -328,7 +328,7 @@ OTNODEAPI const char* OTCALL otNodeScan(otNode* aNode); /** * Performs an scan for the node */ -OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t aSize, uint32_t aMinReplies); +OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t aSize, uint32_t aMinReplies, uint16_t aTimeout); /** * Sets the router selection jitter value for a node diff --git a/examples/drivers/windows/otNodeApi/otNodeApi.cpp b/examples/drivers/windows/otNodeApi/otNodeApi.cpp index 1fed85d57..d9b000734 100644 --- a/examples/drivers/windows/otNodeApi/otNodeApi.cpp +++ b/examples/drivers/windows/otNodeApi/otNodeApi.cpp @@ -1728,7 +1728,7 @@ OTNODEAPI const char* OTCALL otNodeScan(otNode* aNode) return nullptr; } -OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t aSize, uint32_t aMinReplies) +OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t aSize, uint32_t aMinReplies, uint16_t aTimeout) { otLogFuncEntryMsg("[%d] %s (%d bytes)", aNode->mId, aAddr, aSize); printf("%d: ping %s (%d bytes)\r\n", aNode->mId, aAddr, aSize); @@ -1846,7 +1846,8 @@ OTNODEAPI uint32_t OTCALL otNodePing(otNode* aNode, const char *aAddr, uint16_t { //printf("waiting for completion event...\r\n"); // Wait for the receive to complete - result = WSAWaitForMultipleEvents(1, &Overlapped.hEvent, TRUE, (DWORD)(5000 - (GetTickCount64() - StartTick)), TRUE); + ULONGLONG elapsed = (GetTickCount64() - StartTick); + result = WSAWaitForMultipleEvents(1, &Overlapped.hEvent, TRUE, (DWORD)(aTimeout - min(aTimeout, elapsed)), TRUE); if (result == WSA_WAIT_TIMEOUT) { //printf("recv timeout\r\n"); diff --git a/tests/scripts/thread-cert/node.py b/tests/scripts/thread-cert/node.py index d5954890f..436d6e475 100755 --- a/tests/scripts/thread-cert/node.py +++ b/tests/scripts/thread-cert/node.py @@ -217,8 +217,8 @@ class Node: def scan(self): return self.interface.scan() - def ping(self, ipaddr, num_responses=1, size=None): - return self.interface.ping(ipaddr, num_responses, size) + def ping(self, ipaddr, num_responses=1, size=None, timeout=5000): + return self.interface.ping(ipaddr, num_responses, size, timeout) def set_router_selection_jitter(self, jitter): self.interface.set_router_selection_jitter(jitter) diff --git a/tests/scripts/thread-cert/node_api.py b/tests/scripts/thread-cert/node_api.py index 298403725..9202ae015 100644 --- a/tests/scripts/thread-cert/node_api.py +++ b/tests/scripts/thread-cert/node_api.py @@ -235,10 +235,11 @@ class otApi: def scan(self): return self.Api.otNodeScan(self.otNode).decode("utf-8").split("\n") - def ping(self, ipaddr, num_responses=1, size=None): + def ping(self, ipaddr, num_responses=1, size=None, timeout=5000): if size == None: size = 100 - numberOfResponders = self.Api.otNodePing(self.otNode, ipaddr.encode('utf-8'), ctypes.c_ushort(size), ctypes.c_uint(num_responses)) + numberOfResponders = self.Api.otNodePing(self.otNode, ipaddr.encode('utf-8'), ctypes.c_ushort(size), + ctypes.c_uint(num_responses), ctypes.c_uint16(timeout)) return numberOfResponders >= num_responses def set_router_selection_jitter(self, jitter): @@ -533,7 +534,8 @@ class otApi: self.Api.otNodePing.argtypes = [ctypes.c_void_p, ctypes.c_char_p, ctypes.c_ushort, - ctypes.c_uint] + ctypes.c_uint, + ctypes.c_uint16] self.Api.otNodePing.restype = ctypes.c_uint self.Api.otNodeSetRouterSelectionJitter.argtypes = [ctypes.c_void_p, diff --git a/tests/scripts/thread-cert/node_cli.py b/tests/scripts/thread-cert/node_cli.py index 598d73d96..ce4cea93d 100644 --- a/tests/scripts/thread-cert/node_cli.py +++ b/tests/scripts/thread-cert/node_cli.py @@ -429,7 +429,7 @@ class otCli: return results - def ping(self, ipaddr, num_responses=1, size=None): + def ping(self, ipaddr, num_responses=1, size=None, timeout=5000): cmd = 'ping ' + ipaddr if size != None: cmd += ' ' + str(size)