From 9275dcf0a3db631e3e3ea741d33cd7c46594752b Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 11 Nov 2020 14:26:28 +0100 Subject: [PATCH] tcpTest continued --- cube/User/Src/tcpTest.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/cube/User/Src/tcpTest.c b/cube/User/Src/tcpTest.c index 4280c13..cb937c7 100644 --- a/cube/User/Src/tcpTest.c +++ b/cube/User/Src/tcpTest.c @@ -9,20 +9,34 @@ #include #include +#include const uint8_t TCPTEST_SOCK; void tcpTestHandler(void *handle) { - coloredMsg(LOG_YELLOW, "tth"); + static bool socketInitialized = false; + + if (isNetworkAvailable()) { + if (! socketInitialized) { + coloredMsg(LOG_YELLOW, "tth, initializing socket"); + + int8_t res = socket(TCPTEST_SOCK, Sn_MR_TCP, 12345, SF_IO_NONBLOCK); + coloredMsg(LOG_YELLOW, "tth, socket returns %d", res); + + if (res == TCPTEST_SOCK) { + coloredMsg(LOG_YELLOW, "tth, socket is initialized"); + socketInitialized = true; + } + } else { + coloredMsg(LOG_YELLOW, "tth, doing something useful with the socket"); + } + } else { + colorMsg(LOG_YELLOW, "tth, network not yet ready"); + } } void tcpTestInit() { - int8_t res = socket(TCPTEST_SOCK, Sn_MR_TCP, 12345, SF_IO_NONBLOCK); - coloredMsg(LOG_RED, "tti, socket returns %d", res); - - if (res == TCPTEST_SOCK) { - schAdd(tcpTestHandler, NULL, 0, 100); - } + schAdd(tcpTestHandler, NULL, 0, 100); } \ No newline at end of file