This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

【CC3200 评测】CC3200-LAUNCHXL开发板使用心得分享+TCP_socket

Other Parts Discussed in Thread: CC3200, UNIFLASH

继续研究CC3200 SDK里面的example, 今天试了TCP socket,感觉不错。

所需工具:

1.wifi路由器一台。

2.网络测试工具软件,我用的网络调试助手。

3.wifi 笔记本一台。

首先gcc编译tcp_socket, 然后用uniflash烧写到flash,并运行程序,串口输出log如下:

*************************************************
CC3200 TCP Socket Application
*************************************************

Host Driver Version: 1.0.1.13
Build Version 0.0.0.0.31.0.0.0.0.0.0.0.0
Device is configured in default state
Device started as STATION
Connecting to AP: FAST_5D04 ...
[WLAN EVENT] STA Connected to the AP: , BSSID: 0:0:0:0:0:0
[NETAPP EVENT] IP Acquired: IP=192.168.0.101 , Gateway=192.168.0.1
Connected to AP: FAST_5D04
Device IP: 192.168.0.101

Default settings: SSID Name: FAST_5D04, PORT = 5001, Packet Count = 1000, Destination IP: 192.168.0.100

Choose Options:
1. Send TCP packets.
2. Receive TCP packets.
3. Settings.
4. Exit
Enter the option to use: 3

Setting Options:
1. PORT
2. Packet Count
3. Destination IP
4. Main Menu
Enter the option to use: 2
Enter Packet Count: 1


Setting Options:
1. PORT
2. Packet Count
3. Destination IP
4. Main Menu
Enter the option to use: 4


Choose Options:
1. Send TCP packets.
2. Receive TCP packets.
3. Settings.
4. Exit
Enter the option to use: 2
Press Enter and run iperf command "iperf.exe -c 192.168.0.101 -i 1 -t 100000"
Receiving TCP packets...
Recieved 1 packets successfully

我先选择的是3. 修改测试参数,把测试的pack counts 从1000改为1, 这样数据量小一点,易于测试。

看源码就知道:

// 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++;
}

volatile unsigned long  g_ulPacketCount = TCP_PACKET_COUNT;

这个循环的次数就是由这个PACK COUNTS 控制的,所以先改这个。

然后选择2,开始接受数据,此时网络测试工具,选择TCP client. 如下图:

点击连接成功后,就可以发送数据了,发完一包数据自动断开,同时cc3200那边显示接收一包数据成功。

Receiving TCP packets...
Recieved 1 packets successfully

Choose Options:
1. Send TCP packets.
2. Receive TCP packets.
3. Settings.
4. Exit
Enter the option to use: 1
Run iperf command "iperf.exe -s -i 1 -t 100" and press Enter
Sending TCP packets...
Sent 1 packets successfully

回到主界面后,再选择1, 发送tcp 数据,网络调试工具选择tcp serer,并连接,如下:

Choose Options:
1. Send TCP packets.
2. Receive TCP packets.
3. Settings.
4. Exit
Enter the option to use: 1
Run iperf command "iperf.exe -s -i 1 -t 100" and press Enter

按回车发送一包数据,发完后, 测试工具接收如下:

一包接收了1400 字节,看代码就知道,

// filling the buffer
for (iCounter=0 ; iCounter<BUF_SIZE ; iCounter++)
{
g_cBsdBuf[iCounter] = (char)(iCounter % 10);
}

sTestBufLen = BUF_SIZE;

// 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++;
}

#define IP_ADDR 0xc0a80064 /* 192.168.0.100 */
#define PORT_NUM 5001
#define BUF_SIZE 1400
#define TCP_PACKET_COUNT 1000

那个BUF_SIZE 就是1400.

测试下来,结果和代码的实现完全一致,可以成功实现TCP_SOCKET的功能,也就是说,CC3200既可以做TCP_CLIENT, 发送数据,也可以做TCP_SERVER, 接收数据。

希望对大家有用,谢谢。