cc3200 卡死在sl_recv
时间:10-02
整理:3721RD
点击:
int BsdTcpClient(unsigned short usPort) {SlSockAddrIn_t sAddr; SlSockAddrIn_t sLocalAddr; int iCounter; int iAddrSize; int iSockID; int iStatus; int iNewSockID; long lLoopCount = 0; long lNonBlocking = 1; int iTestBufLen; // filling the buffer for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++) { g_cBsdBuf[iCounter] = (char)(iCounter % 10); } iTestBufLen = BUF_SIZE; //filling the TCP server socket address sLocalAddr.sin_family = SL_AF_INET; sLocalAddr.sin_port = sl_Htons((unsigned short)usPort); sLocalAddr.sin_addr.s_addr = 0; // creating a TCP socket iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0); if( iSockID < 0 ) { // error ASSERT_ON_ERROR(SOCKET_CREATE_ERROR); } iAddrSize = sizeof(SlSockAddrIn_t); // binding the TCP socket to the TCP server address iStatus = sl_Bind(iSockID, (SlSockAddr_t *)&sLocalAddr, iAddrSize); if( iStatus < 0 ) { // error sl_Close(iSockID); ASSERT_ON_ERROR(BIND_ERROR); } // putting the socket for listening to the incoming TCP connection iStatus = sl_Listen(iSockID, 0); if( iStatus < 0 ) { sl_Close(iSockID); ASSERT_ON_ERROR(LISTEN_ERROR); } // setting socket option to make the socket as non blocking iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &lNonBlocking, sizeof(lNonBlocking)); if( iStatus < 0 ) { sl_Close(iSockID); ASSERT_ON_ERROR(SOCKET_OPT_ERROR); } iNewSockID = SL_EAGAIN; // waiting for an incoming TCP connection while( iNewSockID < 0 ) { // accepts a connection form a TCP client, if there is any // otherwise returns SL_EAGAIN iNewSockID = sl_Accept(iSockID, ( struct SlSockAddr_t *)&sAddr, (SlSocklen_t*)&iAddrSize); if( iNewSockID == SL_EAGAIN ) { MAP_UtilsDelay(10000); } else if( iNewSockID < 0 ) { // error sl_Close(iNewSockID); sl_Close(iSockID); ASSERT_ON_ERROR(ACCEPT_ERROR); } } iStatus = sl_SetSockOpt(iSockID, SL_SOL_SOCKET, SL_SO_NONBLOCKING, &lNonBlocking, sizeof(lNonBlocking)); if( iStatus < 0 ) { sl_Close(iSockID); ASSERT_ON_ERROR(SOCKET_OPT_ERROR); } //wireless UART transfer iStatus = WuartTransfer(UARTA0_BASE, iSockID); if(iStatus < 0) { UART_PRINT("WUART Transfer failed\n\r"); } iStatus = sl_Close(iSockID); //closing the socket after sending 1000 packets ASSERT_ON_ERROR(iStatus); return SUCCESS;} int WuartTransfer(unsigned long ulBase, int iSockID) { char cRxBuf[100]; int iStatus; SlSockAddrIn_t sAddr; int iAddrSize; UART_PRINT("Start Receiving..."); while(1) {iStatus = sl_Recv(iSockID, cRxBuf, 100, 0); if(iStatus > 0) { if(cRxBuf[iStatus-2] == 0x0d) { cRxBuf[iStatus]=0; UART_PRINT("\r\n接收:"); Message(cRxBuf); UART_PRINT("Receive Successfully"); } else break; } } return(iStatus); }
以上是我的主要函数部分 测试的时候 能连接上开发板 但是发送数据收不到 一直卡在sl_recv 这是为什么呢?
你应该在socket iNewSockID上调用sl_Recv, 有客户端连上你会产生新的套接字,你需要在这个新的套接字上收发数据。
- CC3200连接到远程,程序死在了sl_Socket()处
- 求助!CC3100移植到自己MCU平台后死在establishConnectionWithAP()里读取同步字时的N2H_SYNC_PATTERN_MATCH(pBuf, g_pCB->TxSeqNum)。
- 从station模式切换到AP模式,程序卡死在sl_Start里面
- cc3200 芯片运行 lMode = sl_Start(0, 0, 0);会经常挂死在这里,第一次上电是可以运行过去的,iar在线调试复位都不行,可能什么原因
- 在带Free_RTOS下程序卡死在lRetVal = HTTPCli_getResponseStatus(httpClient);没有返回值
- CC3200 sl_Recv() 函数阻塞