【cc3200】Wuart

来源:互联网 发布:twrp备份文件提取数据 编辑:程序博客网 时间:2024/05/22 11:41

参考郭书军老师的《CC3200应用》
这里写图片描述
每次发完,以16进制发送1b退出,然后再进行新的收发循环

int BsdTcpClient(unsigned short usPort){    SlSockAddrIn_t  sAddr;    int             iAddrSize;    int             iSockID;    int             iStatus;    //filling the TCP server socket address    sAddr.sin_family = SL_AF_INET;    sAddr.sin_port = sl_Htons((unsigned short)usPort);    sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp);    iAddrSize = sizeof(SlSockAddrIn_t);    // creating a TCP socket    iSockID = sl_Socket(SL_AF_INET,SL_SOCK_STREAM, 0);    if( iSockID < 0 )    {        ASSERT_ON_ERROR(SOCKET_CREATE_ERROR);    }    // connecting to TCP server    iStatus = sl_Connect(iSockID, ( SlSockAddr_t *)&sAddr, iAddrSize);    if( iStatus < 0 )    {        // error        sl_Close(iSockID);               ASSERT_ON_ERROR(CONNECT_ERROR);    }    //设置非阻塞模式    long lNonBlocking=1;    iStatus=sl_SetSockOpt(iSockID,SL_SOL_SOCKET,SL_SO_NONBLOCKING,&lNonBlocking,sizeof(lNonBlocking));    if(iStatus<0){        sl_Close(iSockID);    }    iStatus=WuartTransfer(UARTA0_BASE,iSockID);    iStatus = sl_Close(iSockID);    //closing the socket after sending 1000 packets    ASSERT_ON_ERROR(iStatus);    return SUCCESS;}
int WuartTransfer(unsigned long ulBase,int iSockID){    UART_PRINT("进入WuartTransfer\n\r\n\r");    int iStatus=0;    char cTxBuf[100];    char cRxBuf[100];    char cGetChar;    char iCounter=0;    while(1){        cGetChar=MAP_UARTCharGetNonBlocking(ulBase);        if(cGetChar!=0xff){            MAP_UARTCharPut(ulBase,cGetChar);            cTxBuf[iCounter++]=cGetChar;            //0x0d回车Enter,0x1b退出Esc            if(cGetChar==0x0d||cGetChar==0x1b){                UART_PRINT("当检测到回车或退出时进入这里\n\r\n\r");                cTxBuf[iCounter++]=0x0a;                iStatus=sl_Send(iSockID,cTxBuf,iCounter,0);//发送给服务端                if(iStatus<=0){                        ASSERT_ON_ERROR(sl_Close(iSockID));                        UART_PRINT("发送数据失败\n\r\n\r");                        break;                }                //判断输入的到底是哪个                if(cGetChar==0x0d){                    iCounter=0;                }else{                    break;                }            }//if(cGetChar==0x0d||cGetChar==0x1b)        }//if(cGetChar!=0xff)        iStatus=sl_Recv(iSockID,cRxBuf,100,0);        if(iStatus>0){            if( cRxBuf[iStatus-2]==0x0d ){                cRxBuf[iStatus]=0;                UART_PRINT("\r\n\r\nsl_Recv方法执行成功,iStatus=%d,接收到的数据为\r\n\r\n",iStatus);                UART_PRINT("\r\n\r\n%s\r\n\r\n",cRxBuf);            }else{                break;            }        }//if(iStatus>0)    }//while(1)    return iStatus;}
原创粉丝点击