[go: up one dir, main page]

CN102780705B - Ethernet-(controller area network) CAN protocol converter - Google Patents

Ethernet-(controller area network) CAN protocol converter Download PDF

Info

Publication number
CN102780705B
CN102780705B CN201210283964.2A CN201210283964A CN102780705B CN 102780705 B CN102780705 B CN 102780705B CN 201210283964 A CN201210283964 A CN 201210283964A CN 102780705 B CN102780705 B CN 102780705B
Authority
CN
China
Prior art keywords
data
ethernet
protocol
tcp
module
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201210283964.2A
Other languages
Chinese (zh)
Other versions
CN102780705A (en
Inventor
余世明
王宝宝
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang University of Technology ZJUT
Original Assignee
Zhejiang University of Technology ZJUT
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang University of Technology ZJUT filed Critical Zhejiang University of Technology ZJUT
Priority to CN201210283964.2A priority Critical patent/CN102780705B/en
Publication of CN102780705A publication Critical patent/CN102780705A/en
Application granted granted Critical
Publication of CN102780705B publication Critical patent/CN102780705B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Communication Control (AREA)

Abstract

The invention discloses an Ethernet-(controller area network) CAN protocol converter which is composed of a microcontroller (1), a peripheral circuit (2), a CAN module (3) and an Ethernet module (4). The microcontroller (1) is connected with the peripheral circuit (2), the CAN module (3) and the Ethernet module (4) respectively. The Ethernet-CAN protocol converter can achieve the conversion from CAN protocol data to Ethernet frames and from Ethernet frames to CAN protocol data. The Ethernet-CAN protocol converter solves the mutual conversion problem of two formats of data of CAN protocol data and Ethernet frames. Directed at problems that short frames waste bandwidth and is prone to cause network congestion and the like, the Ethernet-CAN protocol converter achieves Nagle algorithm in a transmission control protocol (TCP), reduces the number of short frames greatly, and saves the bandwidth.

Description

Ethernet-CAN协议转换器Ethernet-CAN Protocol Converter

技术领域 technical field

本发明涉及工业控制领域,特别涉及一种实现基于TCP/IP技术的工业以太网和CAN总线之间相互通信的协议转换器。 The invention relates to the field of industrial control, in particular to a protocol converter for realizing mutual communication between industrial Ethernet and CAN bus based on TCP/IP technology.

背景技术 Background technique

 以太网技术在上世纪90年代初进入工业控制领域,以其开放性高、兼容性好、扩展灵活等特点,取得了长足的发展。现场总线技术实时性强、可靠性高,但未能实现跨区域的网络连接。因此以太网-现场总线相结合的模式已经成为工业控制发展的重点。 Ethernet technology entered the field of industrial control in the early 1990s, and has achieved considerable development due to its high openness, good compatibility, and flexible expansion. Fieldbus technology has strong real-time performance and high reliability, but it fails to realize cross-regional network connection. Therefore, the combination mode of Ethernet-Fieldbus has become the focus of industrial control development.

 CAN总线是当今现场总线的典型代表。 CAN bus is a typical representative of today's field bus.

 TCP/IP技术具有良好的实用性和开发性,基于TCP/IP技术的以太网已经广泛应用于工业通信中。 TCP/IP technology has good practicability and development, and Ethernet based on TCP/IP technology has been widely used in industrial communication.

 工业现场中大量存在短帧数据报(1-4字节),使得带宽利用率极低,拥塞发生的可能性也增大。Nagle算法作为TCP拥塞控制的标准,可以很好的解决短帧泛滥问题,但下位机 Nagle算法和上位机延迟确认策略(Delayed Ack)进行交互时,很容易产生暂时性“死锁”(“deadlock”)现象,导致数据不能实时传输。针对暂时性“死锁”现象,现在一般有两种解决办法:一种是关闭Nagle算法,但是以牺牲带宽为代价;另一种是采用改进的Nagle算法,相对来说比较复杂、实施比较困难且通用性不强。 There are a large number of short-frame datagrams (1-4 bytes) in industrial sites, which makes the bandwidth utilization rate extremely low and the possibility of congestion also increases. As the standard of TCP congestion control, the Nagle algorithm can well solve the problem of short frame flooding, but when the Nagle algorithm of the lower computer interacts with the delayed acknowledgment policy (Delayed Ack) of the upper computer, it is easy to generate temporary "deadlock" ("deadlock"). ”) phenomenon, resulting in data not being transmitted in real time. For the temporary "deadlock" phenomenon, there are generally two solutions: one is to turn off the Nagle algorithm, but at the expense of bandwidth; the other is to use the improved Nagle algorithm, which is relatively complicated and difficult to implement And the versatility is not strong.

发明内容 Contents of the invention

 为了解决现有技术中的上述技术问题,本发明提供一种体积小、结构简单坚固、成本低廉、可靠性高、能够满足工业控制实时性需要的Ethernet-CAN协议转换器。 In order to solve the above-mentioned technical problems in the prior art, the present invention provides an Ethernet-CAN protocol converter with small size, simple and firm structure, low cost, high reliability, and can meet the real-time requirements of industrial control.

所述Ethernet-CAN协议转换器,由微控制器、外围电路、CAN模块和Ethernet模块组成,所述微控制器分别与外围电路、CAN模块和Ethernet模块相连,所述CAN模块由CAN收发器和CAN接口组成,所述Ethernet模块由以太网PHY收发器和集成网络隔离变压器的RJ45插座组成,所述Ethernet-CAN协议转换器能够实现从CAN协议数据到Ethernet帧的转换,和从Ethernet帧到CAN协议数据的转换。 Described Ethernet-CAN protocol converter is made up of microcontroller, peripheral circuit, CAN module and Ethernet module, and described microcontroller is connected with peripheral circuit, CAN module and Ethernet module respectively, and described CAN module is composed of CAN transceiver and CAN interface, the Ethernet module is composed of an Ethernet PHY transceiver and an RJ45 socket with an integrated network isolation transformer, and the Ethernet-CAN protocol converter can realize the conversion from CAN protocol data to Ethernet frames, and from Ethernet frames to CAN Conversion of protocol data.

进一步的,所述的Ethernet-CAN协议转换器嵌入了TCP/IP协议栈,来实现TCP、IP、ARP、ICMP协议。 Further, the Ethernet-CAN protocol converter is embedded with a TCP/IP protocol stack to implement TCP, IP, ARP, and ICMP protocols.

进一步的,在其应用层使用自定义协议,所述自定义协议的数据格式包括:代表数据流向Flag字段,代表CAN节点ID的CAN_ID字段和代表数据的CAN_DATA字段。 Further, a custom protocol is used in its application layer, and the data format of the custom protocol includes: a Flag field representing data flow direction, a CAN_ID field representing a CAN node ID, and a CAN_DATA field representing data.

进一步的,在TCP协议中使用Nagle算法,工作流程为:TCP发送端接收应用层产生的数据,如果此时满足两个条件:接收到上个数据包的确认或者TCP数据长度已达到最大报文段长度(MSS),立即发送TCP数据;否则将TCP接收到的数据组块,直至触发上述两个条件。 Further, the Nagle algorithm is used in the TCP protocol. The workflow is: the TCP sender receives the data generated by the application layer. If two conditions are met at this time: the confirmation of the last data packet is received or the TCP data length has reached the maximum message Segment length (MSS), send TCP data immediately; otherwise, block the data received by TCP until the above two conditions are triggered.

进一步的,根据数据信号对实时性要求和数据类型不同,将数据信号分为高、中、低三个优先级。 Further, according to different real-time requirements and data types of the data signals, the data signals are divided into three priorities: high, medium, and low.

进一步的,对于应用层数据采取优先级处理机制,工作流程为:对高优先级数据采取填充缓冲区的处理方式,即如果TCP接收到应用层产生的高优先级数据,立即将该数据填充到最大报文段长度,触发Nagle算法的发送数据条件,立即发送数据而不必等待确认的到来;对中优先级数据采取提高采样频率的处理方式,即提高该类数据采样频率,使得其在200ms内产生一个等于MSS的报文,从而打破“死锁”机制;对于低优先级数据信号,即能容忍200ms传输时延的信号,不做处理。 Furthermore, a priority processing mechanism is adopted for application layer data, and the workflow is as follows: high priority data is processed by filling the buffer, that is, if TCP receives high priority data generated by the application layer, it immediately fills the data into the The maximum message segment length triggers the sending data condition of the Nagle algorithm, and the data is sent immediately without waiting for the confirmation; the middle priority data is processed by increasing the sampling frequency, that is, the sampling frequency of this type of data is increased so that it is within 200ms A message equal to MSS is generated to break the "deadlock" mechanism; for low-priority data signals, that is, signals that can tolerate 200ms transmission delay, no processing is performed.

进一步的,所述从CAN协议数据到Ethernet帧的转换过程为: Further, the conversion process from CAN protocol data to Ethernet frame is:

①启动CAN模块接收数据; ① Start the CAN module to receive data;

②如果接收到数据,保存到应用层缓冲区;如果未接收到数据,返回步骤①; ②If the data is received, save it to the application layer buffer; if the data is not received, return to step ①;

③对应用层缓冲区中的数据采取优先级机制处理; ③A priority mechanism is used to process the data in the application layer buffer;

④如果此时满足Nagle算法发送数据条件,对应用层缓冲区数据进行TCP/IP封包并立即发送,返回步骤①;如果此时不满足Nagle算法发送数据条件,返回步骤①。 ④If the data sending condition of Nagle algorithm is met at this time, perform TCP/IP packet on the application layer buffer data and send it immediately, return to step ①; if the sending data condition of Nagle algorithm is not satisfied at this time, return to step ①.

进一步的,所述从CAN协议数据到Ethernet帧的转换过程为: Further, the conversion process from CAN protocol data to Ethernet frame is:

①启动Ethernet模块接收数据; ① Start the Ethernet module to receive data;

②如果Ethernet模块接收缓冲区有数据,判断网络层协议类型;如果Ethernet模块接收缓冲区没有数据,返回步骤①; ② If there is data in the receiving buffer of the Ethernet module, judge the network layer protocol type; if there is no data in the receiving buffer of the Ethernet module, return to step ①;

③如果步骤②中网络层协议类型为ARP协议,处理ARP报文,返回步骤①;如果步骤②中网络层协议类型为IP协议,处理IP报文; 3. if the network layer protocol type is the ARP protocol in step 2., process the ARP message, and return to step 1; if the network layer protocol type is the IP protocol in the step 2., process the IP message;

④判断步骤③中IP报文所承载的上层协议类型,如果为ICMP协议,处理ICMP报文,返回步骤①;如果为TCP协议,处理TCP报文,返回步骤①; 4. determine the upper layer protocol type carried by the IP message in step 3. If it is the ICMP protocol, process the ICMP message and return to step 1; if it is the TCP protocol, process the TCP message and return to step 1;

⑤如果步骤④中TCP报文携带有CAN数据,发送CAN数据,返回步骤①;否则直接返回步骤①。 ⑤If the TCP message in step ④ carries CAN data, send the CAN data and return to step ①; otherwise, return to step ① directly.

 本发明所带来的效果是:实现TCP/IP协议和CAN协议之间的相互转换,能够实现Ethernet和CAN总线之间相互通信。针对大量短帧数据报,在TCP协议中实现Nagle算法,大幅度减少短帧数据包数量,节省网络带宽、降低网络拥塞发生的可能性。对实时性要求高的信号,在不修改Nagle算法的前提下,采用填充缓冲区或者提高采样频率的措施,消除暂时性“死锁”现象,保证数据传输的实时性。 The effect brought by the present invention is: realize mutual conversion between TCP/IP protocol and CAN protocol, and realize mutual communication between Ethernet and CAN bus. For a large number of short-frame datagrams, the Nagle algorithm is implemented in the TCP protocol, which greatly reduces the number of short-frame data packets, saves network bandwidth, and reduces the possibility of network congestion. For signals with high real-time requirements, without modifying the Nagle algorithm, the measures of filling the buffer or increasing the sampling frequency are adopted to eliminate the temporary "deadlock" phenomenon and ensure the real-time performance of data transmission.

附图说明 Description of drawings

  图1为Ethernet-CAN协议转换器实施方式示意图 Figure 1 is a schematic diagram of the implementation of the Ethernet-CAN protocol converter

图2为Ethernet-CAN协议转换器结构框图 Figure 2 is a block diagram of the Ethernet-CAN protocol converter

    图3为Ethernet-CAN协议转换器数据处理过程图 Figure 3 is a diagram of the data processing process of the Ethernet-CAN protocol converter

图4为Ethernet-CAN协议转换器协议流程图 Figure 4 is the protocol flow chart of the Ethernet-CAN protocol converter

图5为应用层自定义协议数据格式 Figure 5 is the application layer custom protocol data format

图6为Nagle算法工作流程图 Figure 6 is the workflow diagram of Nagle algorithm

图7为Nagle算法和延迟确认策略交互方式图 Figure 7 is a diagram of the interaction between the Nagle algorithm and the delayed confirmation strategy

图8为采样频率为1字节/ms RTT分布图 Figure 8 is a distribution diagram of RTT with a sampling frequency of 1 byte/ms

图9为采样频率为10字节/ms RTT分布图 Figure 9 is the distribution diagram of RTT with a sampling frequency of 10 bytes/ms

图10为优先级工作机制流程图 Figure 10 is a flowchart of the priority working mechanism

图11为Ethernet-CAN协议转换器工作流程图 Figure 11 is the working flow chart of the Ethernet-CAN protocol converter

具体实施方式 Detailed ways

下面结合附图对本发明作进一步说明。 The present invention will be further described below in conjunction with accompanying drawing.

 如图1所示,图1为Ethernet-CAN协议转换器实施方式示意图。本发明的Ethernet-CAN协议转换器作为CAN总线和以太网之间的桥梁,实现CAN总线和以太网之间的相互通信。 As shown in Figure 1, Figure 1 is a schematic diagram of the implementation of the Ethernet-CAN protocol converter. The Ethernet-CAN protocol converter of the present invention is used as a bridge between the CAN bus and the Ethernet to realize mutual communication between the CAN bus and the Ethernet.

 图2为Ethernet-CAN协议转换器结构框图。所述Ethernet-CAN协议转换器在硬件设计上由微控制器1、外围电路2、CAN模块3、Ethernet模块4组成。所述CAN模块3由CAN收发器和CAN接口组成。所述Ethernet模块4由以太网PHY收发器和集成网络隔离变压器的RJ45插座组成。 Figure 2 is a block diagram of the Ethernet-CAN protocol converter. The Ethernet-CAN protocol converter is composed of a microcontroller 1, a peripheral circuit 2, a CAN module 3 and an Ethernet module 4 in terms of hardware design. The CAN module 3 is composed of a CAN transceiver and a CAN interface. The Ethernet module 4 is composed of an Ethernet PHY transceiver and an RJ45 socket integrating a network isolation transformer.

 所述微控制器1为所述Ethernet-CAN协议转换器的核心,分别与外围电路2、CAN模块3和Ethernet模块4相连,实现CAN协议数据和以太网帧这两种格式数据之间的相互转化。本发明选择飞利浦公司生产的ARM7系列芯片LPC2368作为微控制器1。 The microcontroller 1 is the core of the Ethernet-CAN protocol converter, and is connected with the peripheral circuit 2, the CAN module 3 and the Ethernet module 4 respectively, so as to realize the mutual exchange between CAN protocol data and Ethernet frame data. transform. The present invention selects the ARM7 series chip LPC2368 produced by Philips as the microcontroller 1 .

 所述外围电路2为所述微控制器1的最小系统电路,包括时钟电路、复位电路、电源电路和JTAG接口电路。需要说明的是,本发明采用的外部时钟晶振频率为11.0592MHz,采用的电源电路为5V-3.3V直流电源电路。 The peripheral circuit 2 is the minimum system circuit of the microcontroller 1, including a clock circuit, a reset circuit, a power supply circuit and a JTAG interface circuit. It should be noted that the frequency of the external clock crystal oscillator used in the present invention is 11.0592 MHz, and the power supply circuit used is a 5V-3.3V DC power supply circuit.

 所述CAN模块3由CAN收发器和CAN接口两部分组成。CAN收发器通过总线CANH和CANL分别发送和接收数据,CAN接口为总线CANH和CANL提供输入输出接口。本发明中采用TJA1040芯片作为CAN收发器。 The CAN module 3 is composed of CAN transceiver and CAN interface. The CAN transceiver sends and receives data respectively through the buses CANH and CANL, and the CAN interface provides input and output interfaces for the buses CANH and CANL. Adopt TJA1040 chip as CAN transceiver in the present invention.

 所述Ethernet模块4由以太网PHY收发器和集成网络隔离变压器的RJ45插座组成。以太网PHY收发器具有数据信号收发、曼彻斯特编解码以及冲突检测等功能。本发明采用DM9161AEP芯片作为以太网PHY收发器,选择J00-0061NL作为RJ45插座。该插座集成网络隔离变压器为一体,可以起到克制共模干扰、隔离线路和阻抗匹配的作用。 The Ethernet module 4 is composed of an Ethernet PHY transceiver and an RJ45 socket integrating a network isolation transformer. The Ethernet PHY transceiver has the functions of data signal transmission and reception, Manchester encoding and decoding, and conflict detection. The present invention adopts the DM9161AEP chip as the Ethernet PHY transceiver, and selects J00-0061NL as the RJ45 socket. The socket integrates a network isolation transformer as a whole, which can restrain common mode interference, isolate lines and match impedance.

 图3为Ethernet-CAN协议转换器数据处理过程图。方向1->2为CAN数据->以太网数据转换过程:CAN接口将接收到的数据信号发送到CAN总线的物理层,经过CAN总线物理层和数据链路层处理之后获取应用层数据。应用层数据依次经过以太网的传输层、网络层、数据链路层和物理层的处理之后转换为以太网数据信号并通过RJ45插座发送出去。方向2->1为以太网数据->CAN数据转换过程:RJ45插座将接收到的数据信号发送到以太网的物理层,依次经过以太网的物理层、数据链路层、网络层和传输层的处理之后,获取应用层数据。应用层数据依次经过CAN总线的数据链路层和物理层的处理转换为CAN数据信号并通过CAN接口发送出去。 Figure 3 is a diagram of the data processing process of the Ethernet-CAN protocol converter. Direction 1->2 is the CAN data->Ethernet data conversion process: the CAN interface sends the received data signal to the physical layer of the CAN bus, and obtains the application layer data after being processed by the CAN bus physical layer and data link layer. The application layer data is processed by the Ethernet transport layer, network layer, data link layer, and physical layer in turn, and then converted into Ethernet data signals and sent out through the RJ45 socket. Direction 2->1 is Ethernet data->CAN data conversion process: the RJ45 socket sends the received data signal to the physical layer of Ethernet, and then passes through the physical layer, data link layer, network layer and transport layer of Ethernet in turn After processing, the application layer data is obtained. The application layer data is converted into CAN data signals through the data link layer and physical layer of the CAN bus in turn and sent out through the CAN interface.

 图4为Ethernet-CAN协议转换器协议流程图。应用层协议为自定义协议,图5为应用层自定义协议数据格式。所述图5中Flag代表数据流向,长度为1字节,0xFF代表图3中方向1->2,0xFE代表图3中方向2->1。CAN_ID长度为2字节,代表CAN节点ID。CAN_DATA长度不限,一般为几个到几十个字节。这里只提供一种协议定义方式,用户可以根据实际需要自定义应用层协议,这里不再赘述。本发明在传输层实现TCP协议,在网络层实现IP、ICMP、ARP协议。至于CAN总线和以太网的物理层和数据链路层功能,均由相应的硬件和驱动程序来实现。 Figure 4 is the protocol flowchart of the Ethernet-CAN protocol converter. The application layer protocol is a custom protocol, and Figure 5 shows the data format of the application layer custom protocol. Flag in FIG. 5 represents the data flow direction, and the length is 1 byte. 0xFF represents the direction 1->2 in FIG. 3, and 0xFE represents the direction 2->1 in FIG. 3. CAN_ID is 2 bytes in length and represents the CAN node ID. The length of CAN_DATA is not limited, generally several to dozens of bytes. Only one protocol definition method is provided here, and users can customize the application layer protocol according to actual needs, which will not be repeated here. The invention realizes TCP protocol at the transmission layer, and realizes IP, ICMP and ARP protocols at the network layer. As for the physical layer and data link layer functions of CAN bus and Ethernet, they are all realized by corresponding hardware and drivers.

图6为Nagle算法工作流程图。由于CAN总线采用短帧结构,网络中大量的短帧数据包存在会导致带宽利用率降低和拥塞发生的可能性增大,因此本发明在TCP协议中实现Nagle算法。具体工作流程如图6所示:TCP发送端接收应用层产生的数据,如果此时接收到上个数据包的确认或者此时TCP数据长度已达到最大报文段长度(MSS),立即发送TCP数据。否则将TCP接收到的数据组块,直至触发上述两个条件。Nagle算法的实质是组块技术。本发明在TCP协议中嵌入Nagle算法,可以达到大幅度减少网络中短帧数据包数量、节省网络带宽的目的。 Figure 6 is a flowchart of the Nagle algorithm. Since the CAN bus adopts a short-frame structure, the existence of a large number of short-frame data packets in the network will reduce the bandwidth utilization rate and increase the possibility of congestion. Therefore, the present invention implements the Nagle algorithm in the TCP protocol. The specific workflow is shown in Figure 6: The TCP sender receives the data generated by the application layer. If the confirmation of the last data packet is received at this time or the TCP data length has reached the maximum message segment length (MSS), immediately send the TCP data. Otherwise, block the data received by TCP until the above two conditions are triggered. The essence of Nagle's algorithm is the block technology. The invention embeds the Nagle algorithm in the TCP protocol, which can greatly reduce the number of short-frame data packets in the network and save network bandwidth.

图7为Nagle算法和延迟确认策略交互方式图。方式一中,发送端发送data1给接收端,同时对应用层后续产生的数据进行组块;接收到数据后,接收端设定一个200-500ms(典型值为200ms)的定时器,超时之后,接收端立即产生确认包,发送端在收到data1的确认之后发送data2。方式二中,发送端发送data1之后,在接收端定时器超时之前,发送端生成了一个达到MSS的报文data2并立即发送,接收端在连续收到两条未确认的报文之后立即发送确认包,同时删除定时器。方式一在每一次数据交互过程中都会产生至少200ms的时延,也被称为暂时性“死锁”(“deadlock”)。如果系统实时性要求不高,在相同的应用层数据产生速率下,方式一的组块效果是最理想的,因为其延时时间最大。在实时性要求比较高的系统中,方式二要比方式一的效果更理想。本发明从数据信号类型入手,针对其优先级不同,选择不同的交互方式,确保数据信号的实时性要求。 Fig. 7 is a diagram of the interaction between the Nagle algorithm and the delayed confirmation strategy. In method 1, the sending end sends data1 to the receiving end, and at the same time blocks the subsequent data generated by the application layer; after receiving the data, the receiving end sets a timer of 200-500ms (typically 200ms), after timeout, The receiving end immediately generates an acknowledgment packet, and the sending end sends data2 after receiving the acknowledgment of data1. In method 2, after the sending end sends data1, before the receiving end timer times out, the sending end generates a message data2 that reaches the MSS and sends it immediately, and the receiving end immediately sends an acknowledgment after receiving two consecutive unacknowledged messages package, and delete the timer at the same time. Method 1 will generate a delay of at least 200ms during each data interaction, which is also called a temporary "deadlock" ("deadlock"). If the real-time requirements of the system are not high, at the same application layer data generation rate, the block effect of method 1 is the most ideal, because its delay time is the largest. In a system with high real-time requirements, the effect of the second method is more ideal than that of the first method. The present invention starts from the data signal type, and selects different interaction modes according to the different priorities thereof, so as to ensure the real-time requirement of the data signal.

表1为数据优先级分类以及相应处理方式示意图。本发明设置高、中、低三种优先级类型。 Table 1 is a schematic diagram of data priority classification and corresponding processing methods. The present invention sets three priority types: high, medium and low.

优先级priority 能否容忍0.2s时延Can you tolerate 0.2s delay 数据信号类型Data signal type 处理方式processing method high 不能cannot 随机信号random signal 填充缓冲区fill buffer middle 不能cannot 周期性信号periodic signal 提高采样频率Increase the sampling frequency Low able -- --

 表1 Table 1

高优先级数据需具备下列两个条件:①随机信号;②不能容忍200ms的传输时延。本发明对高优先级数据采取填充缓冲区的处理方式。即如果TCP接收到应用层产生的高优先级数据,立即将该数据填充到最大报文段长度,触发Nagle算法的发送数据条件,立即发送数据而不必等待确认的到来。 High-priority data must meet the following two conditions: ① random signal; ② transmission delay of 200ms cannot be tolerated. The present invention adopts the processing mode of filling the buffer zone for the high-priority data. That is, if TCP receives high-priority data generated by the application layer, it immediately fills the data to the maximum segment length, triggers the sending data condition of the Nagle algorithm, and sends the data immediately without waiting for the confirmation.

中优先级数据需具备下列两个条件:①周期性信号;②不能容忍200ms的传输时延。本发明对中优先级数据采取提高采样频率的处理方式。即提高该类数据采样频率,使得其在200ms内产生一个等于MSS的报文,从而打破“死锁”机制。图8和图9分别为采样频率为1字节/ms和10字节/ms的RTT对比,条件是MSS=1460字节。 Medium-priority data must meet the following two conditions: ① periodic signal; ② transmission delay of 200ms cannot be tolerated. The present invention adopts a processing method of increasing the sampling frequency for the medium priority data. That is, increase the sampling frequency of this type of data so that it generates a message equal to MSS within 200ms, thereby breaking the "deadlock" mechanism. Figure 8 and Figure 9 are the RTT comparisons with sampling frequencies of 1 byte/ms and 10 bytes/ms respectively, under the condition that MSS=1460 bytes.

 对于低优先级数据信号,能容忍200ms传输时延的信号,本发明不做处理,而且由于此时延迟时间最长,组块效果最好。图10为优先级工作机制流程图。 For low-priority data signals, signals that can tolerate 200ms transmission delay, the present invention does not process, and because the delay time is the longest at this time, the blocking effect is the best. Figure 10 is a flowchart of the priority working mechanism.

 图11为所述Ethernet-CAN协议转换器工作流程图。硬件初始化完成之后,分别按照图3中所示1->2方向和2->1方向处理数据。 Fig. 11 is the workflow diagram of the Ethernet-CAN protocol converter. After the hardware initialization is completed, process data according to the 1->2 direction and 2->1 direction shown in Figure 3 respectively.

1->2方向数据处理过程: 1->2 direction data processing process:

①启动CAN模块接收数据; ① Start the CAN module to receive data;

②如果接收到数据,保存到应用层缓冲区;如果未接收到数据,返回步骤①; ②If the data is received, save it to the application layer buffer; if the data is not received, return to step ①;

③对应用层缓冲区中的数据采取优先级机制处理; ③A priority mechanism is used to process the data in the application layer buffer;

④如果此时满足Nagle算法发送数据条件,对应用层缓冲区数据进行TCP/IP封包并立即发送,返回步骤①;如果此时不满足Nagle算法发送数据条件,返回步骤①。 ④If the data sending condition of Nagle algorithm is met at this time, perform TCP/IP packet on the application layer buffer data and send it immediately, return to step ①; if the sending data condition of Nagle algorithm is not satisfied at this time, return to step ①.

2->1方向数据处理过程: 2->1 direction data processing process:

①启动Ethernet模块接收数据; ① Start the Ethernet module to receive data;

②如果Ethernet接收缓冲区有数据,判断网络层协议类型;如果Ethernet接收缓冲区没有数据,返回步骤①; ② If there is data in the Ethernet receiving buffer, judge the network layer protocol type; if there is no data in the Ethernet receiving buffer, return to step ①;

③如果步骤②中网络层协议类型为ARP协议,处理ARP报文,返回步骤①;如果步骤②中网络层协议类型为IP协议,处理IP报文; 3. if the network layer protocol type is the ARP protocol in step 2., process the ARP message, and return to step 1; if the network layer protocol type is the IP protocol in the step 2., process the IP message;

④判断步骤③中IP报文所承载的上层协议类型,如果为ICMP协议,处理ICMP报文,返回步骤①;如果为TCP协议,处理TCP报文,返回步骤①; 4. determine the upper layer protocol type carried by the IP message in step 3. If it is the ICMP protocol, process the ICMP message and return to step 1; if it is the TCP protocol, process the TCP message and return to step 1;

⑤如果步骤④中TCP报文携带有CAN数据,发送CAN数据,返回步骤①;否则直接返回步骤①。 ⑤If the TCP message in step ④ carries CAN data, send the CAN data and return to step ①; otherwise, return to step ① directly.

 以上所述及图中所示的仅是本发明的优选实施方式。应当指出,对于本领域的普通技术人员来说,在不脱离本发明的原理的前提下,还可以作出若干变型和改进,这些也应视为属于本发明的保护范围。 What is described above and shown in the figure is only the preferred embodiment of the present invention. It should be pointed out that those skilled in the art can make some modifications and improvements without departing from the principle of the present invention, and these should also be regarded as belonging to the protection scope of the present invention.

Claims (6)

1.一种Ethernet-CAN协议转换器,由微控制器(1)、外围电路(2)、CAN模块(3)和Ethernet模块(4)组成,所述微控制器(1)分别与外围电路(2)、CAN模块(3)和Ethernet模块(4)相连,其特征在于:所述CAN模块(3)由CAN收发器和CAN接口组成,所述Ethernet模块(4)由以太网PHY收发器和集成网络隔离变压器的RJ45插座组成,所述Ethernet-CAN协议转换器能够实现从CAN协议数据到Ethernet帧的转换,和从Ethernet帧到CAN协议数据的转换; 1. An Ethernet-CAN protocol converter is composed of a microcontroller (1), a peripheral circuit (2), a CAN module (3) and an Ethernet module (4), and the microcontroller (1) is connected to the peripheral circuit respectively (2), the CAN module (3) is connected to the Ethernet module (4), characterized in that: the CAN module (3) is composed of a CAN transceiver and a CAN interface, and the Ethernet module (4) is composed of an Ethernet PHY transceiver Composed of an RJ45 socket with an integrated network isolation transformer, the Ethernet-CAN protocol converter can realize the conversion from CAN protocol data to Ethernet frame, and the conversion from Ethernet frame to CAN protocol data; 所述从Ethernet帧到CAN协议数据的转换过程为: The conversion process from Ethernet frame to CAN protocol data is: ①启动CAN模块(3)接收数据; ① Start the CAN module (3) to receive data; ②如果接收到数据,保存到应用层缓冲区;如果未接收到数据,返回步骤①; ②If the data is received, save it to the application layer buffer; if the data is not received, return to step ①; ③对应用层缓冲区中的数据采取优先级机制处理; ③A priority mechanism is used to process the data in the application layer buffer; ④如果此时满足Nagle算法发送数据条件,对应用层缓冲区数据进行TCP/IP封包并立即发送,返回步骤①;如果此时不满足Nagle算法发送数据条件,返回步骤①; ④If the conditions for sending data by the Nagle algorithm are met at this time, perform TCP/IP packets on the application layer buffer data and send them immediately, and return to step ①; if the conditions for sending data by the Nagle algorithm are not satisfied at this time, return to step ①; 所述从CAN协议数据到Ethernet帧的转换过程为: The conversion process from the CAN protocol data to the Ethernet frame is: 一.启动Ethernet模块(4)接收数据; one. Start the Ethernet module (4) to receive data; 二.如果Ethernet模块(4)接收缓冲区有数据,判断网络层协议类型;如果Ethernet模块(4)接收缓冲区没有数据,返回步骤一; two. If there is data in the receiving buffer of the Ethernet module (4), judge the network layer protocol type; if there is no data in the receiving buffer of the Ethernet module (4), return to step 1; 三.如果步骤二中网络层协议类型为ARP协议,处理ARP报文,返回步骤一;如果步骤二中网络层协议类型为IP协议,处理IP报文; three. If the network layer protocol type is the ARP protocol in step 2, process the ARP message and return to step 1; if the network layer protocol type in the step 2 is the IP protocol, process the IP message; 四.判断步骤三中IP报文所承载的上层协议类型,如果为ICMP协议,处理ICMP报文,返回步骤一;如果为TCP协议,处理TCP报文,返回步骤一; Four. Judge the upper layer protocol type carried by the IP message in step 3, if it is the ICMP protocol, process the ICMP message, and return to step one; if it is the TCP protocol, process the TCP message, and return to step one; 五.如果步骤四中TCP报文携带有CAN数据,发送CAN数据,返回步骤一;否则直接返回步骤一。 five. If the TCP message carries CAN data in step 4, send the CAN data and return to step 1; otherwise, return to step 1 directly. 2.根据权利要求1所述的Ethernet-CAN协议转换器,其特征在于:所述的Ethernet-CAN协议转换器嵌入了TCP/IP协议栈,来实现TCP、IP、ARP、ICMP协议。 2. Ethernet-CAN protocol converter according to claim 1, is characterized in that: described Ethernet-CAN protocol converter embeds TCP/IP protocol stack, realizes TCP, IP, ARP, ICMP agreement. 3.根据权利要求2所述的Ethernet-CAN协议转换器,其特征在于:在其应用层使用自定义协议,所述自定义协议的数据格式包括:代表数据流向Flag字段,代表CAN节点ID的CAN_ID字段和代表数据的CAN_DATA字段。 3. Ethernet-CAN protocol converter according to claim 2, is characterized in that: use self-defined agreement in its application layer, the data format of described self-defined agreement comprises: represent data flow to Flag field, represent CAN node ID A CAN_ID field and a CAN_DATA field representing data. 4.根据权利要求2所述的Ethernet-CAN协议转换器,其特征在于:在TCP协议中使用Nagle算法,工作流程为:TCP发送端接收应用层产生的数据,如果此时满足两个条件:接收到上个数据包的确认或者TCP数据长度已达到最大报文段长度(MSS),立即发送TCP数据;否则将TCP接收到的数据组块,直至触发上述两个条件。 4. Ethernet-CAN protocol converter according to claim 2, is characterized in that: use Nagle algorithm in TCP agreement, workflow is: the data that TCP sender receives application layer to produce, if satisfy two conditions now: Receive the acknowledgment of the last data packet or the TCP data length has reached the maximum segment length (MSS), send TCP data immediately; otherwise, block the data received by TCP until the above two conditions are triggered. 5.根据权利要求4所述的Ethernet-CAN协议转换器,其特征在于:根据数据信号对实时性要求和数据类型不同,将数据信号分为高、中、低三个优先级。 5. The Ethernet-CAN protocol converter according to claim 4, characterized in that: according to the data signal, the real-time requirements and data types are different, and the data signal is divided into three priorities: high, medium and low. 6.根据权利要求5所述的Ethernet-CAN协议转换器,其特征在于:对于应用层数据采取优先级处理机制,工作流程为:对高优先级数据采取填充缓冲区的处理方式,即如果TCP接收到应用层产生的高优先级数据,立即将该数据填充到最大报文段长度,触发Nagle算法的发送数据条件,立即发送数据而不必等待确认的到来;对中优先级数据采取提高采样频率的处理方式,即提高该类数据采样频率,使得其在200ms内产生一个等于MSS的报文,从而打破“死锁”机制;对于低优先级数据信号,即能容忍200ms传输时延的信号,不做处理。 6. Ethernet-CAN protocol converter according to claim 5, is characterized in that: take priority processing mechanism for application layer data, work flow is: take the processing mode of filling buffer to high priority data, promptly if TCP When receiving high-priority data generated by the application layer, immediately fill the data to the maximum segment length, trigger the sending data condition of the Nagle algorithm, and send the data immediately without waiting for the arrival of the confirmation; increase the sampling frequency for medium-priority data The processing method is to increase the sampling frequency of this type of data so that it generates a message equal to MSS within 200ms, thus breaking the "deadlock" mechanism; for low-priority data signals, that is, signals that can tolerate 200ms transmission delay, Do not deal with.
CN201210283964.2A 2012-08-10 2012-08-10 Ethernet-(controller area network) CAN protocol converter Active CN102780705B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201210283964.2A CN102780705B (en) 2012-08-10 2012-08-10 Ethernet-(controller area network) CAN protocol converter

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201210283964.2A CN102780705B (en) 2012-08-10 2012-08-10 Ethernet-(controller area network) CAN protocol converter

Publications (2)

Publication Number Publication Date
CN102780705A CN102780705A (en) 2012-11-14
CN102780705B true CN102780705B (en) 2015-05-27

Family

ID=47125458

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201210283964.2A Active CN102780705B (en) 2012-08-10 2012-08-10 Ethernet-(controller area network) CAN protocol converter

Country Status (1)

Country Link
CN (1) CN102780705B (en)

Families Citing this family (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104683199B (en) * 2013-11-28 2018-01-09 中车大连电力牵引研发中心有限公司 CANopen Lwip gateways and train operation monitoring system
CN103728959B (en) * 2014-01-16 2017-01-11 从兴技术有限公司 Intelligent socket control method and intelligent socket controller
CN105099945A (en) * 2014-04-24 2015-11-25 比亚迪股份有限公司 CAN network system and packet transmission control method
CN105827647A (en) * 2016-05-18 2016-08-03 浙江京禾电子科技有限公司 Protocol converter
CN105933095B (en) * 2016-06-30 2020-01-21 北京东土军悦科技有限公司 Method and device for data communication with low-speed network equipment
US20180092115A1 (en) * 2016-09-29 2018-03-29 Qualcomm Incorporated Reliable wi-fi packet delivery using delayed/scheduled block acknowledgment mechanism
CN107171916B (en) * 2017-04-07 2020-08-18 浙江工业大学 Special 4G wireless intelligent network bridge for remote monitoring of industrial metering pump
CN107517225B (en) * 2017-09-30 2020-06-05 北京东土军悦科技有限公司 Protocol conversion method, gateway equipment and storage medium
CN108551423A (en) * 2018-04-11 2018-09-18 浙江工业大学 Industrial metering pump cluster remote monitoring dedicated multi-channel intelligent gateway
CN111385177A (en) * 2018-12-27 2020-07-07 比亚迪股份有限公司 Vehicle and communication system and method thereof
CN109818844B (en) * 2019-04-11 2020-12-29 西南交通大学 A communication gateway and method for converting automobile Ethernet bus to CAN bus
CN110336725B (en) * 2019-07-11 2020-11-10 珠海格力电器股份有限公司 Method and device for accurately positioning nodes in Controller Area Network (CAN) network
TWI731592B (en) * 2020-02-19 2021-06-21 台達電子工業股份有限公司 Cross-protocols control apparatus with apparatus-restoring function and method of restoring apparatus for cross-protocols thereof
US12184446B2 (en) * 2020-10-19 2024-12-31 Nissan Motor Co., Ltd. Relay device, communication network system, and communication control method
EP4221104A1 (en) 2022-01-28 2023-08-02 Nxp B.V. Network interface apparatus

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN201821380U (en) * 2010-06-21 2011-05-04 三一重机有限公司 Equipment for conversion among multiple protocols
CN102149225A (en) * 2011-04-28 2011-08-10 北京交通大学 Bullet train state monitoring system and multifunctional hybrid gateway thereof

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN201821380U (en) * 2010-06-21 2011-05-04 三一重机有限公司 Equipment for conversion among multiple protocols
CN102149225A (en) * 2011-04-28 2011-08-10 北京交通大学 Bullet train state monitoring system and multifunctional hybrid gateway thereof

Also Published As

Publication number Publication date
CN102780705A (en) 2012-11-14

Similar Documents

Publication Publication Date Title
CN102780705B (en) Ethernet-(controller area network) CAN protocol converter
CN204291023U (en) A kind of RS232, RS485 and CAN based on FPGA turns Ethernet device
CN103078895B (en) Multi-functional pair of serial server of a kind of EPA based on MCF52233 chip
CN106162528B (en) LoRa signal and Bluetooth signal conversion module, conversion method and sender unit
CN202190284U (en) Protocol converter for CAN bus and SpaceWire bus
CN107171916B (en) Special 4G wireless intelligent network bridge for remote monitoring of industrial metering pump
CN107579894B (en) FPGA-based EBR1553 bus protocol implementation device
CN104518852B (en) A kind of transmission feedback method
CN109922537B (en) Wireless module and implementation method thereof
CN105530245A (en) System for improving non-private network GOOSE message transmission reliability
CN113938443B (en) Wireless internet of things protocol switch
CN103716293A (en) Low voltage power line spread spectrum communication protocol employing time scale synchronization collision detection method
CN101833296B (en) Remote communication device of singlechip and method thereof
CN106330397B (en) method and device for realizing data interaction by ZigBee and Modbus RTU (remote terminal Unit) protocols
CN102790663B (en) Full-hardware network interface applied to very long baseline interferometry (VLBI) hardware related processor
CN104378778B (en) Method, system and the transfer gateway to communicate in Internet of Things between master-salve station
CN103401866A (en) Device for switching from PowerLink industrial Ethernet to Profibus-DP
CN102420734A (en) CAN bus topological structure implementation system
CN102438335B (en) A medium and long-distance wireless sensor network networking system
CN207625600U (en) Ethernet expanded circuit based on exchanger chip
CN202206412U (en) Full duplex RS485 bus communication device on basis of collision-free protocol
CN101296149B (en) Communication method and device for high-speed real-time bus
CN205195730U (en) Real -time ethernet etherCAT slave station system
CN204145528U (en) The how main real-time communication system of a kind of UART
Kuang et al. A Modbus Protocol Stack Compatible with RTU/TCP Frames and Embedded Application

Legal Events

Date Code Title Description
C06 Publication
PB01 Publication
C10 Entry into substantive examination
SE01 Entry into force of request for substantive examination
C14 Grant of patent or utility model
GR01 Patent grant