【STM32F429】第12章 RL-TCPnet V7.X之TCP客户端

资讯 2024-06-25 阅读:24 评论:0
美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

最新教程下载:http://www.armbbs.cn/forum.php?mod=viewthread&tid=95243

Recent tutorial download: :

本章节为大家讲解RL-TCPnet的TCP客户端实现,学习本章节前,务必要优先学习第10章TCP传输控制协议基础知识。有了这些基础知识之后,再搞本章节会有事半功倍的效果。

This chapter is intended for the TCP client of RL-TCPnet. Before learning about this chapter, priority must be given to learning the basics of chapter 10 TCP transfer control protocols.

12.1 初学者重要提示

12.1 Important reminder for beginners

12.2 TCP客户端API函数

12.2 TCP Client API Function

12.3 系统配置说明(Net_Config.c)

12.3 System Configuration Description (Net_Config.c)

12.4 TCP配置说明(Net_Config_TCP.h)

12.4 TCP Configuration Description (Net_Config_TCP.h)

12.5 以太网配置说明(Net_Config_ETH.h)

12.5 Ethernet Configuration Description (Net_Config_ETH.h)

12.6 网络调试说明(Net_Debug.c)

12.6 Network debugging instructions (Net_Debug.c)

12.7 TCP客户端的实现方法

12.7 TCP client implementation approach

12.8 网络调试助手和板子的调试操作步骤

12.8 Debugging steps for network debugging assistants and panels

12.9 实验例程说明(RTX5)

12.9 Experimental Practice Description (RTX5)

12.10 实验例程说明(FreeRTOS)

12.10 Experimental Practice Description (FreeRTOS)

12.11 总结

12.11 Summary

  1. ? 学习本章节前,务必保证已经学习了第10章的基础知识。
  2. ? 相比上一个章节的TCP服务器,TCP客户端的测试要稍麻烦些,例子中默认访问的TCP服务器端IP地址是192.168.1.2,端口号1001。大家测试时要根据自己电脑的实际IP地址设置app_tcpnet_lib.c文件中远程IP和端口。具体测试方法详看本章节的12.8小节。
  3. ? 本章要掌握的函数稍多,可以先学会基本的使用,然后再深入了解这些函数使用时的注意事项,争取能够熟练使用。

使用如下几个函数可以实现RL-TCPnet的TCP通信:

The TCP communication of RL-TCPnet is performed using the following functions:

关于这几个函数的讲解及其使用方法可以看教程第 3 章 3.4 小节里面说的参考资料文件:

The description of these functions and the way in which they are used can be seen in the reference documents referred to in chapter 3 of the curriculum, subsection 3.4:

关于这些函数注意以下两点:

For these functions, note the following two points:

12.2.1 函数netTCP_cb_t

函数原型:

function prototype:

函数描述:

function description:

供TCP Socket使用的回调函数,每个TCP Socket都可以定制自己的回调函数。

The echo function for TCP Socket, each TCP Socket can customize its own echo function.

函数参数:

function parameter:

使用举例:

Use examples:

12.2.2 函数netTCP_GetSocket

函数原型:

function prototype:

int32_t netTCP_GetSocket(netTCP_cb_t cb_func) ? ?

函数描述:

function description:

函数netTCP_GetSocket用于获取一个TCP Socket,并设置相关状态变量到默认状态。

function netTCP_GetSocket is used to get a TCP Socket and set the relevant status variable to the default status.

注意事项:

Attention:

  1. 调用TCP Socket任何其它函数前,务必要优先调用此函数。
  2. 如果用于服务器模式,要调用监听函数netTCP_Listen进行设置。

使用举例:

Use examples:

12.2.3 函数netTCP_Listen

函数原型:

function prototype:

函数描述:

function description:

函数netTCP_Listen用于设置TCP服务器的监听端口。

function netTCP_Listen is used to set the listening port for the TCP server.

函数参数:

function parameter:

注意事项:

Attention:

  1. 端口号不允许设置为0,因为这个是系统保留的。
  2. RL-TCPnet服务器类应用,比如Telnet Server,HTTP Server,务必要打开一个TCP Socket用于监听。

使用举例:

Use examples:

12.2.4 函数netTCP_SendReady

函数原型:

function prototype:

bool netTCP_SendReady(int32_t socket) ?

函数描述:

function description:

函数netTCP_SendReady用于检测是否可以发送数据。此函数通过检测TCP连接是否建立以及上次发送的数据是否接收到远程机器的应答来判断是否可以发送数据。

The function netTCP_SendReady is used to detect whether data can be sent. The function determines whether data can be sent by checking whether TCP connections are created and whether the last data sent is received by the remote machine.

函数参数:

function parameter:

使用举例:

Use examples:

12.2.5 函数netTCP_GetMaxSegmentSize

函数原型:

function prototype:

uint32_t netTCP_GetMaxSegmentSize(int32_t socket)?

函数描述:

function description:

函数netTCP_GetMaxSegmentSize用于获得当前可以发送的最大报文长度(MSS,Maximum Segment Size)。在配置向导中,默认配置的MSS是1440字节,然而在实际建立连接后,此值会被动态调整,但一定是小于等于1440字节的。

The function netTCP_GetMaxSegmentSize is used to get the maximum length of the current message that you can send (MSS, Maximum SecuritySize). In the configuration wizard, the default configuration is 1440 bytes, but this value is dynamically adjusted when the connection is actually created, but it must be less than 1440 bytes.

函数参数:

function parameter:

注意事项:

Attention:

  1. 这个函数只能在调用了函数netTCP_Listen或netTCP_Connect后,才可以使用。

使用举例:

Use examples:

12.2.6 函数netTCP_GetBuffer

函数原型:

function prototype:

uint8_t * netTCP_GetBuffer(uint32_t size )?

函数描述:

function description:

函数netTCP_GetBuffer用于获取TCP发送缓冲区,用户将要发送的数据存到这个缓冲区中,然后通过函数netTCP_Send发送。发送完毕后要等待远程主机的应答,收到应答后,会在函数netTCP_Send中释放申请的发送缓冲区。

The function netTCP_GetBuffer is used to obtain the buffer zone from which the user will send the data into the buffer zone and then send it through the function netTCP_Send. After sending, you wait for the answer from the remote host, and when you receive the answer, release the application in the function netTCP_Send.

函数参数:

function parameter:

注意事项:

Attention:

  1. 每次发送都需要调用此函数获取发送缓冲区地址。
  2. 申请的发送缓冲区大小不可超过最大报文长度(MSS,Maximum Segment Size),即1440字节。
  3. 操作缓冲区的时候,切不可超过申请的缓冲区大小。

使用举例:

Use examples:

12.2.7 函数netTCP_Send

函数原型:

function prototype:

函数描述:

function description:

函数netTCP_Send用于数据包发送。

function netTCP_Send is used to send data packages.

函数参数:

function parameter:

注意事项:

Attention:

  1. 不管函数netTCP_Send发送成功还是失败,都会释放通过函数netTCP_GetBuffer获取的缓冲区。
  2. 以下两种情况不可使用函数netTCP_Send发送数据包: (1)? TCP连接还未建立。 (2)? 发送给远程机器的数据包还未收到应答。
  3. 调用函数netTCP_Send前务必要调用函数netTCP_GetBuffer获得缓冲区。
  4. 申请的发送缓冲区大小不可超过最大报文长度(MSS,Maximum Segment Size),即1440字节。
  5. netTCP_Send不会发送长度为0的数据包,如果用户设置为0,可以用来释放缓冲区。
  6. 操作缓冲区的时候,切不可超过申请的缓冲区大小。
  7. 不可以在TCP Socket的回调函数里面调用netTCP_Send。

使用举例:

Use examples:

12.2.8 函数netTCP_GetState

函数原型:

function prototype:

netTCP_State netTCP_GetState(int32_t socket)?

函数描述:

function description:

函数netTCP_GetState用于获取TCP Socket的当前状态。用户应用程序可以通过此函数监控TCP Socket的连接、断开等状态。最有用的状态值是netTCP_StateCLOSED, netTCP_StateLISTEN和netTCP_StateESTABLISHED。

The most useful status values are NetTCP_StateCLOSED, NetTCP_StateLISTEN and NetTCP_StateESTABLISHED.

使用举例:

Use examples:

12.2.9 函数netTCP_Abort

函数原型:

function prototype:

netStatus netTCP_Abort(int32_t ? socket)?

函数描述:

function description:

用于立即终止TCP通信。此函数通过发送带RESET标志的TCP帧给远程设备来关闭连接。

This function closes the connection by sending a TCP frame with the RESET sign to a remote device.

函数参数:

function parameter:

注意事项:

Attention:

  1. 当远程客户端终止了连接,TCP Socket才会调用监听回调函数。如果是自己调用的终止连接,那么不会调用回调函数。

使用举例:

Use examples:

12.2.10 函数netTCP_Close

函数原型:

function prototype:

netStatus netTCP_Close( int32_t socket)

函数描述:

function description:

用于关闭TCP通信,完成关闭需要一点时间。

It will take some time to close TCP communications and to complete them.

函数参数:

function parameter:

注意事项:

Attention:

  1. 当远程客户端关闭了连接,TCP Socket才会调用监听回调函数。如果是自己调用的关闭连接,那么不会调用回调函数。
  2. 如果调用了监听函数netTCP_Listen,那么首次调用函数netTCP_Close并不会关闭连接,只会关闭当前处于连接状态的TCP,关闭后依然可以监听新的连接。要真正关闭,需要用户再次调用netTCP_Close。
  3. 调用了函数netTCP_Close后,还没有释放TCP Socket占用的空间,需要大家调用函数netTCP_ReleaseSocket来释放。

使用举例:

Use examples:

12.2.11 函数netTCP_GetPeer

函数原型:

function prototype:

函数描述:

function description:

用于获取远程客户端的IP和端口号。

Use to get IP and port numbers from a remote client.

函数参数:

function parameter:

使用举例:

Use examples:

12.2.12 函数netTCP_GetTimer

函数原型:

function prototype:

uint32_t netTCP_GetTimer(int32_t socket)?

函数描述:

function description:

用于获取TCP连接的溢出时间或者当前的保活值(keep alive),如果溢出时间到了,协议栈会关闭连接或者发送一个keep-alive值。

The spill time used to get a TCP connection or the current active value, if the spill time arrives, will close the connection or send a key-alive value.

函数参数:

function parameter:

使用举例:

Use examples:

12.2.13 函数netTCP_ReleaseSocket

函数原型:

function prototype:

netStatus netTCP_ReleaseSocket(int32_t socket)?

函数描述:

function description:

用于释放创建TCP Socket时申请的内容空间。

To release the content space that was requested when TCP Socket was created.

函数参数:

function parameter:

注意事项:

Attention:

  1. 如果不再使用TCP Socket了,务必记得调用此函数释放TCP Socket占用的空间。
  2. 释放后,还在再次申请使用。

使用举例:

Use examples:

12.2.14 函数netTCP_ResetReceiveWindow

函数原型:

function prototype:

netStatus netTCP_ResetReceiveWindow(int32_t socket)?

函数描述:

function description:

用于复位TCP接收窗口大小到默认值。默认值是由Net_Config_TCP.h文件里面TCP_RECEIVE_WIN_SIZE定义的。

The default value is defined by the TCP_RECEIVE_WIN_SIZE in the Net_Config_TCP.h file.

函数参数:

function parameter:

注意事项:

Attention:

  1. 此函数只能用在使能了TCP流控制的Socket上。
  2. 通过函数netTCP_SetOption的netTCP_OptionFlowControl参数来使能流控制,这样以来,接收的时候就可以使用滑动窗口协议了。
  3. 在流控制模式下,每个接收到一次数据包,都将调整接收窗口大小,即减去接收到的数据包字节数, 直到窗口大小变得很小或为0,此时远程主机停止发送数据,并等待窗口更新。处理完接收到的数据后,我们可以调用netTCP_ResetReceiveWindow函数来重新打开接收窗口,继续接收数据。
  4. 根据用户调用此函数的上下文,调用此函数有如下几种效果

使用举例:

Use examples:

12.2.15 函数netTCP_GetLocalPort

函数原型:

function prototype:

uint16_t netTCP_GetLocalPort(int32_t socket)?

函数描述:

function description:

用于获取TCP Socket的端口号。如果用户在使用netTCP_Connect时,未指定端口,将使用系统自动分配的,可以使用此函数获取。

The port number used to get TCP Socket. If the user uses netTCP_Connect, the port is not specified, the system will be used to automatically assign it, and this function can be used to obtain it.

函数参数:

function parameter:

使用举例:

Use examples:

12.2.16 函数netTCP_SetOption

函数原型:

function prototype:

函数描述:

function description:

用于TCP Socket的一些选项配置。

Some options configuration for TCP Socket.

函数参数:

function parameter:

使用举例:

Use examples:

12.2.17 函数netTCP_Connect

函数原型:

function prototype:

函数描述:

function description:

用于连接远程服务器。

To connect to a remote server.

函数参数:

function parameter:

使用举例:

Use examples:

RL-TCPnet的系统配置工作是通过文件Net_Config.c实现。在MDK工程中打开文件Net_Config.c,可以看到下图所示的工程配置向导:

The system configuration of RL-TCPnet is done through the file Net_Config.c. Opens the file Net_Config.c in the MDK project to see the project configuration wizard shown in the following graph:

Network System Settings

局域网域名。

LAN domain name.

这里起名为armfly,使用局域网域名限制为15个字符。

The name is Armfly and the local area name is limited to 15 characters.

参数范围1536-262144字节。

The parameters range 1536-262144 bytes.

内存池大小配置,单位字节。

Memory pool size configuration, bytes.

开启系统服务。如果使能了此选项(打上对勾表示使能),系统将自动开启系统服务,比如HTTP, FTP, TFTP server等。如果没有使能,需要用户调用专门的API使能。

Enables the system service. If this option is enabled (by ticking on the tick), the system will automatically open the system services, such as HTTP, FTP, TFTP server, etc. If not, the user will be required to call a dedicated API enabler.

RL-TCPnet内核任务需要的栈大小,单位字节,范围512到65535。

RL-TCPnet kernel size, unit bytes, range 512 to 65535.

RL-TCPnet内核任务的优先级。

Priority for nuclear tasks in RL-TCPnet.

这个选择在配置向导里面没有展示,需要大家点击上图左下角的Text Editor按钮查看宏定义修改。

This option is not displayed in the configuration wizard and requires you to click on the Text Editor button at the lower left corner of the top graph to see the macro definition changes.

TCP配置文件:

TCP profile:

TCP Sockets

范围1-20。

Scope 1-20.

用于配置可创建的TCP Sockets数量。

Configures the number of TCP Sockets that you can create.

范围0-20。

Scope 0-20.

用于配置重试次数,TCP数据传输时,如果在设置的重试时间内得不到应答,算一次重试失败,这里就是配置的最大重试次数。

This is the maximum number of retries of the configuration if, at the time of transmission of TCP data, no answer is given during the set time of retries, counting the failure of a retries.

范围1-10,单位秒。

Range 1-10, unit second.

重试时间。如果发送的数据在时间内得不到应答,将重新发送数据。

time. If the data sent is not answered within the time frame, the data is retransmitted.

范围1-600,单位秒。

Range 1-600, unit second.

用于配置默认的保持连接时间,即我们常说的Keep Alive时间,如果时间到了将断开连接。常用于HTTP Server,Telnet Server等。

This is used to configure the default retention time, which is what we usually call the Keep Alive time, when the time comes. It is often used for HTTP Server, Telnet Server, etc.

范围536-1440,单位字节。

536-1440, bytes.

MSS定义了TCP数据包能够传输的最大数据分段。

The MSS defines the maximum data segment that a TCP data package can transmit.

范围536-65535,单位字节。

536-65535, bytes.

TCP接收窗口大小。

TCP receives window size.

以太网涉及到的配置选项比较多:

There are more configuration options involved in the Ethernet:

Ethernet Network Interface 0

? Connect to hardware via Driver_ETH#

用于指定驱动号,这个一般不需要用户去设置,比如RTE创建的文件名是Net_Config_ETH_0.h,就会自动将此参数设置为0。

To specify a driver, this does not normally require the user to set it, for example, the file name created by RTE is Net_Config_ETH_0.h, which automatically sets this parameter to zero.

? VLAN

虚拟局域网。

Virtual local area network.

VLAN的ID号,12bit数值,范围1到4093。

VLAN ID, value 12bit, range 1 to 4093.

? MAC Address

局域网内可以随意配置,只要不跟局域网内其它设备的MAC地址冲突即可。

The local area network can be configured at will, provided that it does not conflict with the MAC address of other devices in the local area network.

注意,MAC地址的第1个字节的最后一个bit一定要是0。

Note that the last bit of the first byte of the MAC address must be zero.

? IP Address

IP地址。

IP address.

? Subnet mask

子网掩码。

Subnet mask.

? Default Gateway

默认网关。

Default gateway.

? Primary DNS Server

首选DNS服务器地址。

Prefer to the DNS server address.

? Secondary DNS Server

备选DNS服务器地址。

Option DNS server address.

? IP Fragmentation

使用发送IP报文的分片处理和接收IP报文的重组。

Reorganization of the processing and receipt of IP messages using sub-distributions to send IP messages.

范围576-1500字节。

Scope 576-1500 bytes.

最大的传输单元。

Maximum transmission unit.

? ARP Address Resolution

地址解析协议

Cannot initialise Evolution's mail component.

ARP Cache表大小。

ARP Cache table size.

Cache表超时时间。

Cache forms are timed out.

尝试解析IP地址的次数

Number of attempts to parse IP addresses

每次解析请求的时间间隔。

The interval between each parsing request.

启用此选项后,嵌入式主机将在启动时或设备IP地址已更改时发送ARP通知。

When this option is enabled, the embedded host will send an ARP notification on start-up or when the device's IP address has been changed.

? IGMP Group Management

IGMP分组管理。

IGMP Group Management.

此主机可以加入的分组数。

The number of groups that this host can add.

? NetBIOS Name Service

NetBIOS局域网域名服务,这里打上对勾就使能了。这样我们就可以通过Net_Config.c文件配置的Local Host Name局域网域名进行访问,而不需要通过IP地址访问了。

NetBIOS Local Area Network (LAN) Domain Name (LAN) service, which is enabled by a pairing here. This allows us to access the Local Host Name Domain (LAN) domain name of the Net_Config.c file configuration instead of the IP address.

? Dynaminc Host Configuration

即DHCP,这里打上对勾就使能了。使能了DHCP后,RL-TCPnet就可以从外接的路由器上获得动态IP地址。

That's DHCP, which makes it possible to match. With DHCP, RL-TCPnet can get a dynamic IP address from an external router.

厂商ID,如果设置了的话,会将其加到DHCP的请求消息中,用于识别网络设备的不同厂商。

Vendor ID, if installed, will add it to the DHCP request message to identify the different manufacturers of the network equipment.

从DHCP 服务器获取的引导文件名。

The lead filename from the DHCP server.

从DCHP服务器获得NTP服务器列表。

Gets the list of NTP servers from the DCHP server.

RL-TCPnet的调试功能是通过配置文件Net_Debug.c实现。在MDK工程中打开文件Net_Debug.c,可以看到如下图所示的工程配置向导:

The debug function of RL-TCPnet is performed by configuring the file Net_Debug.c. Opens the file Net_Debug.c in the MDK project to see the project configuration wizard as shown in the following graphs:

Print Time Stamp

勾选了此选项的话,打印消息时,前面会附带时间信息。

If this option is ticked, the message will be printed with time information.

其它所有的选项

All other options

默认情况下,所有的调试选项都是关闭的,每个选项有三个调试级别可选择,这里我们以Memory Management为例,点击下拉列表,可以看到里面有Off,Errors only和Full debug三个调试级别可供选择,每个调试选项里面都是这三个级别。

By default, all debugging options are closed and each option has three debugging levels to choose. Here, for example, we click on Memory Management and click on the drop-down list to see that there are three debugging levels available in Off, Errors only and Full debug. Each debugging option contains three levels.

Off:表示关闭此选项的调试功能。

Off: is the debug function that closes this option.

Errors only:表示仅在此选项出错时,将其错误打印出来。

Errors only: indicates that you print the error only if you have made an error in this option.

Full debug:表示此选项的全功能调试。

Full debug: represents the full function debug of this option.

具体测试,我们这里就不做了,大家可以按照第9章讲解的调试方法进行测试。

Specific tests, which we will not do here, can be tested in accordance with the debugging methods described in chapter 9.

有了本章前面小节的配置后,剩下的问题就是TCP客户端的创建和TCP客户端数据收发的实现。

With the configuration of the preceding subsections of this chapter, the remaining problems are the creation of the TCP client and the realization of the TCP client data.

12.7.1 创建TCP客户端

TCP客户端的创建比较简单,调用函数netTCP_GetSocket即可,此函数的使用和注意事项在本章的12.2.2小节有讲解:

The creation of the TCP client is relatively simple and the call function netTCP_GetSocket is sufficient. The use and attention of this function is explained in subsection 12.2.2 of this chapter:

12.7.2 TCP数据发送

TCP Socket的数据发送一定要注意各个函数调用顺序和使用方法,非常重要!否则,数据发送很容易失败。数据发送所用到函数的使用方法和注意事项在本章节的12.2小节有讲解。下面的代码中对数据发送专门做了处理,支持任意字节大小的数据发送,仅需修改计数变量iCount的初始值即可,初始值是多少,就是发送多少字节。下面的代码是测试发送8字节,1024字节和5MB:

The data sent by TCP Socket must be sensitive to the order and use of each function. Otherwise, the data sent can easily fail. The method of use of the data sent to the function is explained in subsection 12.2 of this chapter. Data sent is specifically processed in the code below to support data sent by any byte size, and only the initial value of the count variable iCount is modified. The code below is the 8 byte, 1024 byte and 5MB:

12.7.3 TCP数据接收

TCP数据接收主要是通过函数netTCP_GetSocket的回调函数实现(RTX5和FreeRTOS):

TCP data reception is mainly achieved by the function NetTCP_GetSocket echo function (RTX5 and FreeRTOS):

我们这里使用下面这款调试助手,任何其它网络调试助手均可,不限制:

We use the following debugging assistant here, any other network debugging assistant, without limitation:

?http://www.armbbs.cn/forum.php?mod=viewthread&tid=1568

12.8.1 获取板子IP地址

(说明,对于TCP客户端实验,这一步已经不需要了,不过大家还可以进行测试)

(Note that this step is no longer needed for TCP client experiments, but you can also test them)

首先,强烈推荐将网线接到路由器或者交换机上面测试,因为已经使能了DHCP,可以自动获取IP地址,而且在前面的配置中使能了局域网域名NetBIOS,用户只需在电脑端ping armfly就可以获得板子的IP地址。测试方法如下:

First, it is strongly recommended that the network be tested on routers or switchboards, since DHCP has been enabled to automatically access IP addresses, and LAN domain name NetBIOS has been enabled in the previous configuration, and users can get IP addresses on the plate only on the computer endping armfly. The test method is as follows:

  • ? WIN+R组合键打开“运行”窗口,输入cmd?
  • ? 弹出的命令窗口中,输入ping armfly。
  • ? 输入ping armfly后,回车。

获得IP地址是192.168.1.6。也许有读者会问,这里的响应时间为什么不是小于1ms的?这是因为我们还没有让板子跟电脑端的服务器建立连接,客户端一直在发SYN包尝试建立连接,所以占用了不少时间,从而导致响应时间不是小于1ms的,建立了连接后就好了。

The IP address is 192.168.1.6. Readers may ask why the response time is not less than 1 ms. Because we have not yet connected the board to the server on the computer end, the client has been sending the SYN package to try to build the connection, so it takes a lot of time, so the response time is not less than 1 ms, and it's better when the connection is established.

12.8.2 获取电脑的IP地址

获取电脑IP地址的方法很多,可以在网上邻居获取,也可以通过输入命令ipconfig获取,方法跟上面14.6.1小节中的方式一样。

There are many ways of obtaining a computer IP address that can be accessed by neighbours online or by entering an ipconfig command, the same way as in sub-section 14.6.1 above.

  • ? WIN+R组合键打开“运行”窗口,输入cmd。
  • ? 弹出的命令窗口中,输入ipconfig。
  • ? 输入ipconfig后,回车。

获得电脑的IP地址是192.168.1.2.

The IP address for the computer is 192.168.1.2.

12.8.3 在程序中配置要访问的远程IP地址和端口

根据前面本章12.8.2小节获取的电脑端IP地址,需要大家配置程序中app_tcpnet_lib.c文件开头的宏定义,其中IP地址填前面获取的192.168.1.2,大家要根据电脑实际的IP地址填写。而端口号,我们这里随意配置一个即可,配置为1001,后面电脑端使用网络调试助手创建TCP服务器时,务必要跟这个端口号统一:

Based on the IP-end addresses obtained in subsection 12.82 of the previous chapter, you are required to configure the macro definition of the beginning of the app_tcpnet_lib.c document, where the IP addresses fill in 192.168.1.2 obtained before, and you are required to fill them in according to the actual IP addresses of the computer. The port number, which is available here, is set to 1001, and when the network debugging assistant is used to create the TCP server on the back computer, it is important to align with this port number:

代码语言:javascript
复制

12.8.4 网络调试助手创建TCP服务器

  • ? 打开调试助手,点击左上角创建服务器:
  • ? 弹出如下界面,指定IP设置为192.168.1.2,一定要跟12.8.2小节中获得的电脑IP地址一致,端口号1001,最后点击确定:
  • ? 点击确定后的界面效果如下:
  • ? 然后点击启动服务器:

12.8.5 创建TCP客户端连接TCP服务器

如果开发板下载了TCP客户端的程序,并且开发板已经上电,按下摇杆的OK键,可以看到客户端连接已经加入:

If the development board downloads the TCP client program and the development panel has been powered, press the rock rod OK key to see that the client connection has been added:

跟我们在程序中设置的端口号,即app_tcpnet_lib.c文件开头的宏定义:

The macro is defined at the beginning of the application_tcpnet_lib.c with the port number that we set in the program:

#define LocalPort_NUM? 1024是一致的。IP地址也跟本章12.8.1小节中获取的IP地址也是一致的。

The IP address is also the same as the IP address obtained in subsection 12.8.1 of this chapter.

连接上后,串口软件也会打印出如下信息(波特率115200,数据位8,奇偶校验位无,停止位1):

When connected, serial port software will also print the following information (Port 115,200, data slot 8 and doll calibration not available, stop slot 1):

12.8.6 TCP客户端发送数据

板子和网络调试助手建立连接后就可以互相收发数据了。对于发送数据,程序中创建了三种大小的数据发送测试。

The board and the network debugging assistant are connected to each other to receive and send data. For sending data, the program creates three sizes of data distribution tests.

  • ? K1按键按下,发送了8个字符,从1到8。
  • ? K2按键按下,发送1024字节,每次发送数据包的前8个字节设置了字符a到字符h,后面都未做设置。
  • ? K3按键按下,发送5*1024*1024=5242880字节,即5MB。每次发送数据包的前8个字节设置了字符a到字符h,后面都未做设置。

12.8.7 TCP客户端接收数据

TCP服务器接收数据的测试也比较方便,我们这里通过网络调试助手给板子发送0到9,共10个字符:

The TCP server is also easier to test for receiving data, and we send 0 to 9 characters to the board through the network debugging assistant, for a total of 10 characters:

点击发送后,可以看到串口软件打印出接收到的10个字符:

After clicking on the send, you can see the serial software print out the 10 characters received:

测试也是没问题的。

It's okay to test it.

配套例子:

companion example:

V6-1008_RL-TCPnet V7.X实验_TCP客户端(RTX5)

V6-1008_RL-TCPnet V7.X Experiment_TCP Client (RTX5)

实验目的:

Experimental Purpose:

  1. 学习RL-TCPnet的TCP客户端创建和数据收发。

实验内容:

experimental content:

  1. 强烈推荐将网线接到路由器或者交换机上面测试,因为已经使能了DHCP,可以自动获取IP地址。
  2. 客户端的例子相比服务器的例子稍麻烦些,因为客户端的例子需要用户知道电脑端IP和端口号。并根据实际情况设置IP和端口号的宏定义,这个配置在文件app_tcpnet_lib.c开头,测试的时候板子要连接这个IP和端口(下面是默认配置,一定要根据实际情况重新配置,如果不会配置,看本例程对应的教程即可): #define IP1? 192 #define IP2? 168 #define IP3? 1 #define IP4? 2 #define PORT_NUM 1001
  3. 创建了一个TCP Client,而且使能了局域网域名NetBIOS,用户只需在电脑端ping armfly就可以获得板子的IP地址,本地端口被设置为1024。
  4. 用户可以在电脑端用网络调试软件创建TCP Server连接此客户端。
  5. 按键K1按下,发送8字节的数据给TCP Server。
  6. 按键K2按下,发送1024字节的数据给TCP Server。
  7. 按键K3按下,发送5MB字节的数据给TCP Server。
  8. 摇杆OK键按下,连接远程服务器。

实验操作:

experimental operation:

详见本章节12.8小节。

See subsection 12.8 of this chapter for details.

系统配置说明(Net_Config.c):

System Configuration Description (Net_Config.c):

详见本章节12.3小节。

See subsection 12.3 of this chapter for details.

TCP配置说明(Net_Config_TCP.h):

TCP Configuration Note (Net_Config_TCP.h):

详见本章节12.4小节。

See subsection 12.4 of this chapter for details.

以太网配置说明(Net_Config_ETH_0.h):

with Teennet Configuration Description (Net_Config_ETH_0.h):

详见本章节12.5小节。

See subsection 12.5 of this chapter for details.

网络调试说明(Net_Debug.c):

Net_Debug.c):

详见本章节12.6小节。

See subsection 12.6 of this chapter for details.

RTX5配置:

RTX5 configuration:

RTX5配置向导详情如下:

Details of the RTX5 configuration wizard are as follows:

? System Configuration

系统配置

System Configuration

  • ? Global Dynamic Memory size

全局动态内存大小,单位字节。

Global dynamic memory size, unit bytes.

当前配置为20480字节。

The current configuration is 20480 bytes.

  • ? Kernel Tick Frequency

内核滴答时钟频率。

kernel tick clock frequency.

当前配置为1KHz

Current configuration is 1KHz

  • ? Round-Robin Thread switching

使能时间片调度,并把时间片设置为5个,即5ms。

Time sheets are scheduled and set to five, i.e., 5ms.

  • ? OS_ISR_FIFO_QUEUE

中断服务程序里面调用RTX5的API,需要用到这个FIFO队列,当前FIFO大小设置为16个。

Call API in RTX5 in the service interruption program, using this FIFO queue, which is currently set to 16 sizes.

  • ? OS_ISR_FIFO_QUEUE

中断服务程序里面调用RTX

Call RTX in interrupt service program

? Thread Configuration

任务配置。

Task configuration.

  • ? Default Thread Stack size

默认的任务栈大小,单位字节。

Default task pad size, bytes.

  • ? Idle Thread Stack size

空闲任务栈大小,单位字节。

Free task pad size, bytes.

  • ? Idle Thread Stack size

空闲任务栈大小,单位字节。

Free task pad size, bytes.

  • ? Stack overrun checking

使能栈溢出检测。

Make it possible to overflow the detection.

  • ? Stack usage watermark

栈使用率。

Repository usage.

  • ? Privileged mode

使能特权模式。

A privileged model of empowerment.

RTX5任务调试信息:

RTX5 task debug information:

RL-TCPnet协议栈调试信息:

RL-TCPnet Debug Information:

程序设计:

program design:

任务分配:

task assignment:

AppTaskUserIF任务 : 按键消息处理。

AppTaskUserIF task: Keywork.

AppTaskLED任务? : LED闪烁。

The AppTaskLED mission?

AppTaskMsgPro任务 : TCPnet应用任务。

AppTaskMsgPro mission: TCPnet application task.

AppTaskEthCheck : 网线插拔状态检测。

AppTaskEthCheck: Network plug-in status test.

AppTaskStart任务? : 启动任务,也是最高优先级任务,这里用作BSP驱动包处理。

AppTaskStart mission? : Start-up task, also top priority task, is used here as a BSP driver package.

netCore_Thread任务? : TCPnet内核任务。

NetCore_Thread mission? : TPCPnet kernel task.

netEth0_Thread任务? : TCPnet以太网接口任务。

NetEth0_Thread mission? : TCPnet interface task.

osRtxTimerThread任务: 定时器任务,TCPnet时间基准。

OsRtxTimerThread mission: Timer task, TCPnet time frame.

系统栈大小分配:

Stock size distribution:

RTX5初始化

RTX5 Initialization

代码语言:javascript
复制

硬件外设初始化

hardware externalization initialization

硬件外设的初始化是在 bsp.c 文件实现:

The initialization of hardware externalities is achieved in bsp.c files:

代码语言:javascript
复制

RTX任务创建:

RTX job creation:

代码语言:javascript
复制

几个RTX任务的实现:

Achievement of several RTX missions:

代码语言:javascript
复制

RL-TCPnet功能测试

RL-TCPnet functional test

这里专门创建了一个app_tcpnet_lib.c文件用于RL-TCPnet功能的测试,主要功能是创建了一个TCP 客户端。

An app_tcpnet_lib.c file was created specifically for testing RL-TCPnet functions, the main feature being the creation of a TCP client.

代码语言:javascript
复制

配套例子:

companion example:

V6-1009_RL-TCPnet V7.X实验_TCP客户端(FreeRTOS)

V6-1009_RL-TCPnet V7.X Experiment_TCP Client (FreeRTOS)

实验目的:

Experimental Purpose:

  1. 学习RL-TCPnet的TCP客户端创建和数据收发。

实验内容:

experimental content:

  1. 强烈推荐将网线接到路由器或者交换机上面测试,因为已经使能了DHCP,可以自动获取IP地址。
  2. 客户端的例子相比服务器的例子稍麻烦些,因为客户端的例子需要用户知道电脑端IP和端口号。并根据实际情况设置IP和端口号的宏定义,这个配置在文件app_tcpnet_lib.c开头,测试的时候板子要连接这个IP和端口(下面是默认配置,一定要根据实际情况重新配置,如果不会配置,看本例程对应的教程即可): #define IP1? 192 #define IP2? 168 #define IP3? 1 #define IP4? 2 #define PORT_NUM 1001
  3. 创建了一个TCP Client,而且使能了局域网域名NetBIOS,用户只需在电脑端ping armfly就可以获得板子的IP地址,本地端口被设置为1024。
  4. 用户可以在电脑端用网络调试软件创建TCP Server连接此客户端。
  5. 按键K1按下,发送8字节的数据给TCP Server。
  6. 按键K2按下,发送1024字节的数据给TCP Server。
  7. 按键K3按下,发送5MB字节的数据给TCP Server。
  8. 摇杆OK键按下,连接远程服务器。

实验操作:

experimental operation:

详见本章节12.8小节。

See subsection 12.8 of this chapter for details.

系统配置说明(Net_Config.c):

System Configuration Description (Net_Config.c):

详见本章节12.3小节。

See subsection 12.3 of this chapter for details.

TCP配置说明(Net_Config_TCP.h):

TCP Configuration Note (Net_Config_TCP.h):

详见本章节12.4小节。

See subsection 12.4 of this chapter for details.

以太网配置说明(Net_Config_ETH_0.h):

with Teennet Configuration Description (Net_Config_ETH_0.h):

详见本章节12.5小节。

See subsection 12.5 of this chapter for details.

网络调试说明(Net_Debug.c):

Net_Debug.c):

详见本章节12.6小节。

See subsection 12.6 of this chapter for details.

FreeRTOS配置:

FreeRTOS configuration:

FreeRTOS配置向导详情如下:

The details of the FreeRTOS configuration wizard are as follows:

  • ? Minimal stack size

最小任务栈大小,主要是空闲任务,单位字(4个字节)。

Minimum task pad size, mainly free task, unit size (4 bytes).

当前设置的是512字节。

The current set is 512 bytes.

  • ? Total heap size

FreeRTOS总的堆大小,单位字节。

FreeRTOS total stack size, bytes.

当前设置的30960字节。

The currently set 30960 bytes.

  • ? Kernel tick frequency

FreeRTOS的系统时钟节拍。

FreeRTOS's system clock beat.

当前设置的是1KHz。

The current set-up is 1 kHz.

  • ? Timer task stack depth

定时器任务栈大小,单位字(4字节)。

Timer task pad size, unit size (4 bytes).

当前设置的2048字节。

The current set 2048 bytes.

  • ? Timer task priority

定时器任务优先级。

Timer task priority.

当前设置的48。

48 of the current settings.

  • ? Timer queue length

定时器消息队列大小。

Timer message queue size.

  • ? Use time slicing

使能时间片调度,这个选项非常重要,RL-TCPnet V7.X用于FreeRTOS版要用到。

This option is very important for making time sheets available for RL-TCPnet V7.X for FreeRTOS.

FreeRTOS任务调试信息:

FreeRTOS task debug information:

RL-TCPnet协议栈调试信息:

RL-TCPnet Debug Information:

程序设计:

program design:

任务分配:

task assignment:

AppTaskUserIF任务 : 按键消息处理。

AppTaskUserIF task: Keywork.

AppTaskLED任务? : LED闪烁。

The AppTaskLED mission?

AppTaskMsgPro任务 : TCPnet应用任务。

AppTaskMsgPro mission: TCPnet application task.

AppTaskEthCheck : 网线插拔状态检测。

AppTaskEthCheck: Network plug-in status test.

AppTaskStart任务? : 启动任务,也是最高优先级任务,这里用作BSP驱动包处理。

AppTaskStart mission? : Start-up task, also top priority task, is used here as a BSP driver package.

netCore_Thread任务? : TCPnet内核任务。

NetCore_Thread mission? : TPCPnet kernel task.

netEth0_Thread任务? : TCPnet以太网接口任务。

NetEth0_Thread mission? : TCPnet interface task.

osRtxTimerThread任务: 定时器任务,TCPnet时间基准。

OsRtxTimerThread mission: Timer task, TCPnet time frame.

系统栈大小分配:

Stock size distribution:

FreeRTOS初始化

FreeRTOS Initialization

代码语言:javascript
复制

FreeRTOS任务创建:

FreeRTOS Task Creation:

代码语言:javascript
复制

几个FreeRTOS任务的实现:

Several FreeRTOS missions:

代码语言:javascript
复制

RL-TCPnet功能测试

RL-TCPnet functional test

这里专门创建了一个app_tcpnet_lib.c文件用于RL-TCPnet功能的测试,主要功能是创建了一个TCP 客户端。

An app_tcpnet_lib.c file was created specifically for testing RL-TCPnet functions, the main feature being the creation of a TCP client.

代码语言:javascript
复制

本章节就为大家讲解这么多,希望大家多做测试,争取可以熟练掌握这些API函数的使用。

So much for you in this section, I hope you'll test more to get a good grasp of the use of these API functions.

美化布局示例

欧易(OKX)最新版本

【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   全球官网 大陆官网

币安(Binance)最新版本

币安交易所app【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址

火币HTX最新版本

火币老牌交易所【遇到注册下载问题请加文章最下面的客服微信】永久享受返佣20%手续费!

APP下载   官网地址
文字格式和图片示例

注册有任何问题请添加 微信:MVIP619 拉你进入群

弹窗与图片大小一致 文章转载注明

分享:

扫一扫在手机阅读、分享本文

发表评论
平台列表
美化布局示例

欧易(OKX)

  全球官网 大陆官网

币安(Binance)

  官网

火币(HTX)

  官网

Gate.io

  官网

Bitget

  官网

deepcoin

  官网
热门文章
  • 0.00003374个比特币等于多少人民币/美金

    0.00003374个比特币等于多少人民币/美金
    0.00003374比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00003374比特币等于2.2826 1222美元/16.5261124728人民币。比特币(BTC)美元(USDT)人民币(CNY)0.00003374克洛克-0/22216.5261124728比特币对人民币的最新汇率为:489807.72 CNY(1比特币=489807.72人民币)(1美元=7.24人民币)(0.00003374USDT=0.0002442776 CNY)。汇率更新于2024...
  • 0.00006694个比特币等于多少人民币/美金

    0.00006694个比特币等于多少人民币/美金
    0.00006694比特币等于多少人民币?根据比特币对人民币的最新汇率,0.00006694比特币等于4.53424784美元/32.5436 16人民币。比特币(BTC)美元(USDT)人民币(CNY)0.000066944.53424784【比特币密码】32.82795436 16比特币对人民币的最新汇率为:490408.64 CNY(1比特币=490408.64人民币)(1美元=7.24人民币)(0.00006694USDT=0.0004846456 CNY)汇率更新时...
  • 0.00015693个比特币等于多少人民币/美金

    0.00015693个比特币等于多少人民币/美金
    0.000 15693比特币等于多少人民币?根据比特币对人民币的最新汇率,0.000 15693比特币等于10.6 1678529美元/76.86554996人民币。比特币(BTC)【比特币价格翻倍】美元(USDT)人民币(CNY)0.000/克洛克-0/5693【数字货币矿机】10.6 167852976.8655254996比特币对人民币的最新汇率为:489,807.72 CNY(1比特币= 489,807.72人民币)(1美元=7.24人民币)(0.00015693 U...
  • 币圈院士:5.20比特币(BTC)以太坊(ETH)行情分析

    币圈院士:5.20比特币(BTC)以太坊(ETH)行情分析
    利空出尽?华尔街多头坚信美股将摆脱泥潭 经济衰退风险被夸大A lot of people on Wall Street believe that beauty will escape the quagmire; the risk of recession is exaggerated. 从目前美国经济的情况加上美股先有的走势来判断,确信通胀已经或即将见顶,这为价格压力回落铺平了道路,这最终将使美联储得以放缓...
  • 2000年美国GDP占世界的304%,中国GDP仅占35%,现在呢?

    2000年美国GDP占世界的304%,中国GDP仅占35%,现在呢?
    GDP作为全球公认的实力基准,就像是一个大国实力的代言人,它是布雷顿森林体系下全球团结的声音。它不仅仅是数字的累积,更是大国综合实力的人格化,默默诉说着每个国家的辉煌与荣耀。虽然GDP不是衡量一个国家综合实力的唯一标准,但无疑是最关键的指标之一。作为一面镜子,它反映了国家的经济实力和发展水平,是国家综合实力的重要体现,不容忽视。2000年,中国GDP迈过/克洛克-0/万亿美元的重要门槛,达到/克洛克-0/。2/克洛克-0/万亿美元(折合人民币7。7万亿元)。然而,在全球经济的...
标签列表