完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
// sending packet
iStatus = sl_Send(iSockID, g_cBsdBuf, sTestBufLen, 0 ); 发送函数 1000指的是1000包数据 程序部分了做备注,参考 //**************************************************************************** // //! brief Opening a TCP client side socket and sending data //! //! This function opens a TCP socket and tries to connect to a Server IP_ADDR //! waiting on port PORT_NUM. //! If the socket connection is successful then the function will send 1000 //! TCP packets to the server. //! //! param[in] port number on which the server will be listening on //! //! return 0 on success, -1 on Error. // //**************************************************************************** int BsdTcpClient(unsigned short usPort) [ int iCounter; short sTestBufLen; SlSockAddrIn_t sAddr; int iAddrSize; int iSockID; int iStatus; long lLoopCount = 0; // filling the buffer for (iCounter=0 ; iCounter g_cBsdBuf[iCounter] = (char)(iCounter % 10); ] sTestBufLen = BUF_SIZE; //filling the TCP server socket address sAddr.sin_family = SL_AF_INET; sAddr.sin_port = sl_Htons((unsigned short)usPort); //目的IP地址端口号 sAddr.sin_addr.s_addr = sl_Htonl((unsigned int)g_ulDestinationIp); //目的IP地址IP_ADDR-手机上连接USR软件后配置TCP Server设置端口号并查看本机IP地址 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); //<连接>目的IP地址及端口号 if( iStatus < 0 ) [ // error sl_Close(iSockID); ASSERT_ON_ERROR(CONNECT_ERROR); ] // sending multiple packets to the TCP server while (lLoopCount < g_ulPacketCount) [ // sending packet iStatus = sl_Send(iSockID, g_cBsdBuf, sTestBufLen, 0 ); if( iStatus < 0 ) [ // error sl_Close(iSockID); ASSERT_ON_ERROR(SEND_ERROR); ] lLoopCount++; ] Report("Sent %u packets successfullynr",g_ulPacketCount); iStatus = sl_Close(iSockID); //closing the socket after sending 1000 packets ASSERT_ON_ERROR(iStatus); return SUCCESS; ] //**************************************************************************** // //! brief Opening a TCP server side socket and receiving data //! //! This function opens a TCP socket in Listen mode and waits for an incoming //! TCP connection. //! If a socket connection is established then the function will try to read //! 1000 TCP packets from the connected client. //! //! param[in] port number on which the server will be listening on //! //! return 0 on success, -1 on error. //! //! note This function will wait for an incoming connection till //! one is established // //**************************************************************************** int BsdTcpServer(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 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); //仅用到本机IP的端口号即可 sLocalAddr.sin_addr.s_addr = 0; //建立TCP服务器时忽略本机IP地址 // 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); //绑定该TCP socket 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); //开始监听TCP连接 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); ] ] // waits for 1000 packets from the connected TCP client while (lLoopCount < g_ulPacketCount) [ iStatus = sl_Recv(iNewSockID, g_cBsdBuf, iTestBufLen, 0); if( iStatus <= 0 ) [ // error sl_Close(iNewSockID); sl_Close(iSockID); ASSERT_ON_ERROR(RECV_ERROR); ] lLoopCount++; ] Report("Recieved %u packets successfullynr",g_ulPacketCount); // close the connected socket after receiving from connected TCP client iStatus = sl_Close(iNewSockID); ASSERT_ON_ERROR(iStatus); // close the listening socket iStatus = sl_Close(iSockID); ASSERT_ON_ERROR(iStatus); return SUCCESS; ] //**************************************************************************** // //! brief Connecting to a WLAN Accesspoint //! //! This function connects to the required AP (SSID_NAME) with Security //! parameters specified in te form of macros at the top of this file //! //! param[in] None //! //! return Status value //! //! warning If the WLAN connection fails or we don't aquire an IP //! address, It will be stuck in this function forever. // //**************************************************************************** static long WlanConnect() [ SlSecParams_t secParams = [0]; long lRetVal = 0; secParams.Key = (signed char*)SECURITY_KEY; secParams.KeyLen = strlen(SECURITY_KEY); secParams.Type = SECURITY_TYPE; lRetVal = sl_WlanConnect((signed char*)SSID_NAME, strlen(SSID_NAME), 0, &secParams, 0); ASSERT_ON_ERROR(lRetVal); /* Wait */ while((!IS_CONNECTED(g_ulStatus)) || (!IS_IP_ACQUIRED(g_ulStatus))) //还是要在这等待网络事件产生! [ // Wait for WLAN Event #ifndef SL_PLATFORM_MULTI_THREADED _SlNonOsMainLoopTask(); #endif ] return SUCCESS; ] //***************************************************************************** // //! Application startup display on UART //! //! param none //! //! return none //! //***************************************************************************** static void DisplayBanner(char * AppName) [ Report("nnnr"); Report("tt *************************************************nr"); Report("tt CC3200 %s Application nr", AppName); Report("tt *************************************************nr"); Report("nnnr"); ] //***************************************************************************** // //! Board Initialization & Configuration //! //! param None //! //! return None // //***************************************************************************** static void BoardInit(void) [ /* In case of TI-RTOS vector table is initialize by OS itself */ #ifndef USE_TIRTOS // // Set vector table base // #if defined(ccs) || defined (gcc) MAP_IntVTableBaseSet((unsigned long)&g_pfnVectors[0]); #endif #if defined(ewarm) MAP_IntVTableBaseSet((unsigned long)&__vector_table); #endif #endif // // Enable Processor // MAP_IntMasterEnable(); MAP_IntEnable(FAULT_SYSTICK); PRCMCC3200MCUInit(); ] //**************************************************************************** // MAIN FUNCTION //**************************************************************************** void main() [ long lRetVal = -1; // // Board Initialization // BoardInit(); // // Initialize the uDMA // UDMAInit(); // // Configure the pinmux settings for the peripherals exercised // PinMuxConfig(); // // Configuring UART // InitTerm(); // // Display banner // DisplayBanner(APPLICATION_NAME); InitializeAppVariables(); // // Following function configure the device to default state by cleaning // the persistent settings stored in NVMEM (viz. connection profiles & // policies, power policy etc) // // Applications may choose to skip this step if the developer is sure // that the device is in its default state at start of applicaton // // Note that all profiles and persistent settings that were done on the // device will be lost // lRetVal = ConfigureSimpleLinkToDefaultState(); if(lRetVal < 0) [ if (DEVICE_NOT_IN_STATION_MODE == lRetVal) UART_PRINT("Failed to configure the device in its default state nr"); LOOP_FOREVER(); ] UART_PRINT("Device is configured in default state nr"); // // Asumption is that the device is configured in station mode already // and it is in its default state // lRetVal = sl_Start(0, 0, 0); if (lRetVal < 0) [ UART_PRINT("Failed to start the device nr"); LOOP_FOREVER(); ] UART_PRINT("Device started as STATION nr"); UART_PRINT("Connecting to AP: %s ...rn",SSID_NAME); // Connecting to WLAN AP - Set with static parameters defined at common.h // After this call we will be connected and have IP address lRetVal = WlanConnect(); if(lRetVal < 0) [ UART_PRINT("Connection to AP failed nr"); LOOP_FOREVER(); ] UART_PRINT("Connected to AP: %s nr",SSID_NAME); UART_PRINT("Device IP: %d.%d.%d.%dnrnr", SL_IPV4_BYTE(g_ulIpAddr,3), SL_IPV4_BYTE(g_ulIpAddr,2), SL_IPV4_BYTE(g_ulIpAddr,1), SL_IPV4_BYTE(g_ulIpAddr,0)); #ifdef USER_INPUT_ENABLE //定义了USER_INPUT_ENABLE lRetVal = UserInput(); if(lRetVal < 0) [ ERR_PRINT(lRetVal); LOOP_FOREVER(); ] #else //不执行 lRetVal = BsdTcpClient(PORT_NUM); //建立CC3200-TCP Client并向目的IP及端口号5001发送TCP数据 if(lRetVal < 0) [ UART_PRINT("TCP Client failednr"); LOOP_FOREVER(); ] lRetVal = BsdTcpServer(PORT_NUM); //建立TCP Server 等待连接并接收数据 if(lRetVal < 0) [ UART_PRINT("TCP Server failednr"); LOOP_FOREVER(); ] #endif UART_PRINT("Exiting Application ...nr"); // // power of the Network processor // lRetVal = sl_Stop(SL_STOP_TIMEOUT); while (1) [ _SlNonOsMainLoopTask(); ] ] |
|
|
|
asa1253 发表于 2018-6-7 06:08 谢谢你的回答! |
|
|
|
只有小组成员才能发言,加入小组>>
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
694 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
605 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1065 浏览 1 评论
757 浏览 0 评论
普中科技F28335开发板每次上电复位后数码管都会显示,如何熄灭它?
529 浏览 1 评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
171浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
133浏览 14评论
在使用3254进行录音的时候出现一个奇怪的现象,右声道有吱吱声,请教一下,是否是什么寄存器设置存在问题?
129浏览 13评论
TLV320芯片内部自带数字滤波功能,请问linein进来的模拟信号是否是先经过ADC的超采样?
126浏览 12评论
GD32F303RCT6配置PA4 ADC引脚,将PA2代替key功能,PA2连接时无法实现预期功能,为什么?
64浏览 10评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-29 06:24 , Processed in 0.820260 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号