diff --git a/cube/User/Src/tcpTest.c b/cube/User/Src/tcpTest.c index 2d51357..d0a988b 100644 --- a/cube/User/Src/tcpTest.c +++ b/cube/User/Src/tcpTest.c @@ -33,17 +33,36 @@ void tcpTestHandler(void *handle) { if (res == TCPTEST_SOCK) { coloredMsg(LOG_YELLOW, "tth, socket is initialized"); state = 1; + } else { + state = 255; } break; + case 1: coloredMsg(LOG_YELLOW, "tth, connecting"); res = connect(TCPTEST_SOCK, remoteAddr, remotePort); coloredMsg(LOG_YELLOW, "tth, connect returns %d", res); - state = 255; - + if (res == SOCK_BUSY) { + coloredMsg(LOG_YELLOW, "tth, ok, waiting for established"); + state = 2; + } else { + state = 255; + } break; + + case 2: + coloredMsg(LOG_YELLOW, "tth, waiting for established"); + + uint8_t sockState = getSn_SR(TCPTEST_SOCK); + coloredMsg(LOG_YELLOW, "tth, socket state is %d", sockState); + + if (sockState == SOCK_ESTABLISHED) { + coloredMsg(LOG_YELLOW, "tth, connection is established"); + state = 255; + } + case 255: coloredMsg(LOG_YELLOW, "tth, error state, will stop here"); schDel(tcpTestHandler, NULL);