From b9801b35ef117d48f5f1a8c1491570a60d4379c9 Mon Sep 17 00:00:00 2001 From: dumheter Date: Wed, 26 Feb 2014 11:10:25 +0100 Subject: [PATCH] Update ping_server.pde When client moves out of range previous code would cause the server to get stuck in an infinite loop trying to send. When the client were to move back in range the server would not respond because it was in the loop. I have added a small timeout code which prevents this, at the cost of performance. --- Mirf/examples/ping_server/ping_server.pde | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Mirf/examples/ping_server/ping_server.pde b/Mirf/examples/ping_server/ping_server.pde index 1138721..3cf635e 100755 --- a/Mirf/examples/ping_server/ping_server.pde +++ b/Mirf/examples/ping_server/ping_server.pde @@ -93,6 +93,20 @@ void loop(){ Mirf.send(data); + /* + * This code prevents the server from an infinit + * send loop if client moves out of reach. + */ + boolean flush_rx = true; + for(int count=0; count<100; count++){ + if(!Mirf.isSending()){ + flush_rx = false; + break; + } + delay(5); + } + if(flush_rx) Mirf.flushRx(); + /* * Wait untill sending has finished *