CN116366574A - Protocol conversion method based on double buffer areas - Google Patents

Protocol conversion method based on double buffer areas Download PDF

Info

Publication number
CN116366574A
CN116366574A CN202310268415.6A CN202310268415A CN116366574A CN 116366574 A CN116366574 A CN 116366574A CN 202310268415 A CN202310268415 A CN 202310268415A CN 116366574 A CN116366574 A CN 116366574A
Authority
CN
China
Prior art keywords
data
queue
serial port
message
buffer area
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.)
Pending
Application number
CN202310268415.6A
Other languages
Chinese (zh)
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.)
SUZHOU SHIHLIN ELECTRIC CO Ltd
Nanjing University of Science and Technology
Original Assignee
SUZHOU SHIHLIN ELECTRIC CO Ltd
Nanjing University of Science and Technology
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 SUZHOU SHIHLIN ELECTRIC CO Ltd, Nanjing University of Science and Technology filed Critical SUZHOU SHIHLIN ELECTRIC CO Ltd
Priority to CN202310268415.6A priority Critical patent/CN116366574A/en
Publication of CN116366574A publication Critical patent/CN116366574A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/50Queue scheduling
    • H04L47/62Queue scheduling characterised by scheduling criteria
    • H04L47/622Queue service order
    • H04L47/6225Fixed service order, e.g. Round Robin
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L47/00Traffic control in data switching networks
    • H04L47/50Queue scheduling
    • H04L47/62Queue scheduling characterised by scheduling criteria
    • H04L47/625Queue scheduling characterised by scheduling criteria for service slots or service orders
    • H04L47/6275Queue scheduling characterised by scheduling criteria for service slots or service orders based on priority
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/08Protocols for interworking; Protocol conversion
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Abstract

The invention discloses a protocol conversion method based on double buffer areas, and provides a method for combining a priority queue and a ring buffer area based on a weighted round robin algorithm, aiming at the phenomenon that a high priority message is lost when the ring buffer area is used in a serial port, the method comprises the following steps: the priority queue based on the weighted round robin algorithm is configured at the serial port, the ring buffer is configured at the serial port, and the message is sent or received through the double buffer. The welding robot and the gateway are connected by using a network cable, the gateway and the welding machine are connected by using a serial port cable, a process field network (Process Field Net, PROFINET) is used between the welding robot and the gateway, a MODBUS protocol is used between the gateway and the welding machine, and protocol conversion is realized by the gateway, so that the welding robot can operate the welding machine. The invention adopts a method of combining the priority queue and the ring buffer based on the weighted round robin algorithm, reduces the loss of the high priority message and improves the stability of the gateway system.

Description

Protocol conversion method based on double buffer areas
Technical Field
The invention relates to the technical field of protocol conversion protocols, in particular to a protocol conversion method based on double buffer areas.
Background
In recent years, the development of new energy automobiles has promoted the rapid development of the lithium battery industry. The most critical welding technology of the lithium battery manufacturing process is higher and higher in automation degree, and along with the intelligent development of industrial field automation, the advantages of the Ethernet technology applied in the industrial automation field are displayed, and the PROFINET technology based on the Ethernet technology is gradually changed into a mainstream protocol conversion technology among various industrial devices. With the gradual rise of PROFINET technology, welding robots based on PROFINET protocol are successively introduced, and as traditional welding equipment is also a common MODBUS protocol, the two can not be directly connected.
The gateway is subject to various interferences in the industrial field when actually operating, and the driving circuit between the two protocol conversion boards of the gateway is possibly damaged due to the interferences, which can seriously lead to paralysis of the whole gateway system.
When there are a large number of messages in the PROFINET protocol conversion gateway serial port, the messages will be lost due to untimely processing, especially the principle followed when using the ring buffer is first in first out, so when a message with higher priority enters the buffer later, it must be processed after the front message is processed, if the front message has more data volume, the processing of the message will be seriously affected, and when the buffer is full, the buffer will be emptied to ensure the entry of the following messages, which will cause the message with higher priority not to be processed in time and lost, this situation will probably cause serious loss to the equipment.
Disclosure of Invention
The invention aims to provide a protocol conversion method based on double buffer areas, which is used for solving the problem of losing serial port high priority messages so as to improve the reliability and stability of a gateway system.
The technical scheme for realizing the purpose of the invention is as follows: in a first aspect, the present invention provides a protocol conversion method based on double buffers, including the steps of:
step 1, configuring a priority queue based on a weighted round robin algorithm at a serial port, wherein the weighted round robin algorithm allocates bandwidth according to weights W0 and W1 configured by each queue, and calculates the value of a counter of each queue to determine whether to continue the round robin;
step 2, configuring an annular buffer area at a serial port, using a head pointer and a tail pointer, performing read-write operation on data of the buffer area by moving the two pointers, calculating the residual length Lenth of the buffer area, when Lenth=0, indicating that the buffer area is full, resetting the buffer area at the moment, and storing new data;
and 3, sending or receiving the message through the double buffer areas, arranging and scheduling the message according to weights W0 and W1 by utilizing the priority queue set in the serial port in the step 1, sequentially entering the annular buffer area for storage, simultaneously calculating the values of count and Lenth to ensure smooth scheduling and storage, and finally carrying out receiving and transmitting operation on the message by moving two pointers of the annular buffer area.
In a second aspect, the present invention provides a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the steps of the method of the first aspect when the program is executed.
In a third aspect, the present invention provides a computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of the method of the first aspect.
In a fourth aspect, the invention provides a computer program product comprising a computer program which, when executed by a processor, implements the steps of the method of the first aspect.
Compared with the prior art, the invention has the remarkable advantages that: the invention combines the priority queue and the ring buffer zone based on the weighted round robin algorithm, further reduces the loss of the high priority message and improves the stability of the gateway system on the basis of improving the packet loss rate.
The invention is further described below with reference to the detailed description and the accompanying drawings.
Drawings
Fig. 1 is a schematic diagram of a hardware circuit of a protocol conversion gateway with high stability in an embodiment of the present invention.
Fig. 2 is a general block diagram of a software design of a highly stable protocol conversion gateway in an embodiment of the present invention.
Fig. 3 is a scheduling schematic diagram of a weighted round robin algorithm.
Fig. 4 is a schematic diagram of a ring buffer.
Fig. 5 is a diagram of a message scenario when a modified buffer is used.
Detailed Description
The protocol conversion gateway of the welding robot and the welding machine with high stability is designed to be combined with a priority queue and a ring buffer zone based on a weighted round robin algorithm, a hardware circuit schematic diagram is shown in figure 1, and a software design overall structure diagram is shown in figure 2.
The invention provides a protocol conversion method based on double buffer areas, which comprises the following steps:
step 1, configuring a priority queue based on a weighted round robin algorithm at a serial port, wherein the weighted round robin algorithm equally allocates bandwidth according to weights W0 and W1 configured by each queue, and calculates the value of a counter of each queue to determine whether to continue the round robin;
step 2, configuring an annular buffer area at a serial port, using a head pointer and a tail pointer, performing read-write operation on data of the buffer area by moving the two pointers, calculating the residual length Lenth of the buffer area, when Lenth=0, indicating that the buffer area is full, resetting the buffer area at the moment, and then storing new data, thereby reducing the time of frequently releasing channels of a common queue;
and 3, sending or receiving the message through the double buffer areas, arranging and scheduling the message according to weights W0 and W1 by utilizing the priority queue set in the serial port in the step 1, sequentially entering the annular buffer area for storage, simultaneously calculating the values of count and Lenth to ensure smooth scheduling and storage, and finally carrying out receiving and transmitting operation on the message by moving two pointers of the annular buffer area.
Further, the specific process of configuring the priority queue based on the weighted round robin algorithm in the serial port in the step 1 is as follows:
the priority queues based on the weighted round robin algorithm, namely the queues can be scheduled in turn, so that each queue can be guaranteed to be served, and compared with the strict priority algorithm, the weighted round robin algorithm enables the scheduling of the queues to be relatively fair, and particularly for messages with low priority, the weighted round robin algorithm guarantees that the messages are not lost due to buffer fullness to the greatest extent.
The weighting circulation algorithm is realized by setting a message counter for each queue of a port, counting according to the set weight, outputting a message by the queue when each round-robin arrives at the queue, reducing the message counter of the queue by 1, stopping scheduling the queue until the message counter is reduced to 0, and re-calculating according to the weight when the message counter of all the queues is reduced to 0, and starting circulation scheduling.
The weighted round robin algorithm uses 2 FIFO channels, and weights W0 and W1 are respectively configured for the two channels, where the number of messages in the first channel is N and the number of messages in the second channel is M. In the first polling, W0 messages are taken out from a first channel, W1 messages are taken out from a second channel, at the moment, the counter count-1 of the two channels is equal to the counter count-1 of the two channels, then the second polling is started, when the counter count=0 in one channel exists, only messages are taken out from the other channel, and when the counter counts of the two channels are equal to 0, the polling is ended.
Further, the specific process of configuring the ring buffer in the serial port in the step 2 is as follows:
the design of the ring buffer is accomplished using two pointers, one pointer Head to the Head of the queue and one pointer Tail to the Tail of the queue. The principle is that before data comes in, the ring buffer is initialized, and the head and tail of the queue point to 0; when data comes in, the Head points to "0", the Tail points to the next storage space "1", and the data is stored at an address "0"; when there is more data in, the Head points to "1", the Tail points to the next memory space "2", the data is stored at address "1", and so on. When data is processed, the data with the address of 0 is processed first, and then the next data is processed in sequence, so that the reading and writing of the annular buffer area are realized. When the head and the tail of the queue overlap again, the annular buffer area is full, the subsequent data can not be accessed, the annular buffer area is emptied at the moment, the data which are not analyzed for a long time are removed, and the subsequent latest data are reserved.
And the annular buffer area is provided with a buffer area residual length of Lenth, the buffer area length of S, the Lenth is increased by 1 when data are read, and the Lenth is decreased by 1 when the data are stored. When Lenth=0, the buffer is full at this time, and when Lenth=S, the buffer is empty at this time. When Lenth=0, the buffer is emptied, and when Lenth+.0, writing to the buffer is allowed.
Further, the specific process of sending or receiving the message in the step 3 through the double buffer area is as follows:
the double buffer area sends or receives, when polling is carried out for the first time, W0 messages are taken out from the first channel, W1 messages are taken out from the second channel and then sent into the annular buffer area, and at the moment, the residual length of the annular buffer area is Lenth=S-W0-W1; then carrying out second polling, and sending the W0+W1 messages to a ring buffer area, wherein the residual length of the ring buffer area is Lenth=S-2 (W0+W1); then, the next polling is performed, when the count=0 of the two FIFO channels, the polling is finished, and if the Lenth=0, the ring buffer is emptied for the entry of the subsequent message.
After the steps 1 and 2 are completed, the message is sent to the ring buffer area according to the dispatching result after passing through the priority queue, and then the message is sent or received according to the following steps. Firstly defining a serial port structure body, wherein the serial port baud rate is set to 115.2Kbps, 8-bit data are used for transmission, 1-bit stop bits are used for odd-even enabling and hardware enabling, receiving and transmitting modes are set, a serial port register is initialized according to parameters, and serial port interruption and serial port peripheral are enabled; then defining serial port receiving and transmitting, obtaining a transmitting state bit or a receiving state bit by calling a function, and determining whether to transmit or receive data according to a return value; and finally, defining serial port interrupt transceiving data, reading interrupt flag bits after defining a variable to store received data, clearing the interrupt flag bits, storing received characters into an array, and finally, transmitting or receiving the data through a serial port.
Examples
The protocol conversion gateway of the welding robot and the welding machine is designed as follows: the serial peripheral interface (Serial Peripheral Interface, SPI) conversion rate is set to 18Mbps, the RS-232 protocol conversion rate is set to 115.2Kbps, a coding switch is used for selecting which driving circuit is selected, four pins 32, 33, 35 and 52 are respectively corresponding to OM 0-0M 3, one of the three modes can be selected when the circuit board is in use, and the level of the three modes is required to be selected before the circuit board is RESET, and the level of the three modes can be sampled at the rising edge of the RESET pin of the protocol conversion board, so that the protocol conversion mode between the protocol conversion board and the application board is determined. Dividing the priority channel into two queues, wherein the channel priority queue2 is a queue with high priority, the priority queue1 is a queue with low priority, the weight of the queue2 is 4, the weight of the queue1 is 2, and according to the algorithm scheduling principle, 1 message should be acquired from the queue according to the following sequence: 2-1-2-2-1-2,
in order to verify that the protocol conversion gateway uses a double-buffer mode of a priority queue and a ring buffer area based on a weighted round robin algorithm, the loss of a high-priority message can be reduced compared with the method of using only the ring buffer area, programming software is firstly used for verifying the design of the priority queue, then the Wireshark software is used for monitoring PROFINET IO message information, and the loss condition of the message is observed and compared through an IO table under two modes of comparison and analysis:
fig. 3 is a scheduling schematic diagram of a weighted round robin algorithm, fig. 4 is a schematic diagram of a ring buffer, and fig. 5 is a message scenario when a modified buffer is used.
The test of the priority queue based on the weighted round robin algorithm can be seen from the experimental results that the queue schedule is according to the weight ratio of 4:2, outputting the result of 1-0-1-1-0-1, and dispatching according to the set weight ratio circularly until the message in the queue is output, and verifying the success of the design of the priority algorithm.
Fig. 5 shows the situation of using the modified buffer, and it can be seen from the figure that the error information of the PROFINET message is still not found after the system runs for a long time by using the modified buffer, which indicates that the situation of losing the message is reduced and the stability of the gateway system is improved after using the modified buffer.
In summary, the protocol conversion gateway based on the double buffer areas solves the problem of losing the serial port high-priority message, and greatly improves the reliability and stability of the gateway system.

Claims (7)

1. The protocol conversion method based on the double buffer areas is characterized by comprising the following steps:
step 1, configuring a priority queue based on a weighted round robin algorithm at a serial port, wherein the weighted round robin algorithm allocates bandwidth according to weights W0 and W1 configured by each queue, and calculates the value of a counter of each queue to determine whether to continue the round robin;
step 2, configuring an annular buffer area at a serial port, using a head pointer and a tail pointer, performing read-write operation on data of the buffer area by moving the two pointers, calculating the residual length Lenth of the buffer area, when Lenth=0, indicating that the buffer area is full, resetting the buffer area at the moment, and storing new data;
and 3, sending or receiving the message through the double buffer areas, arranging and scheduling the message according to weights W0 and W1 by utilizing the priority queue set in the serial port in the step 1, sequentially entering the annular buffer area for storage, simultaneously calculating the values of count and Lenth to ensure smooth scheduling and storage, and finally carrying out receiving and transmitting operation on the message by moving two pointers of the annular buffer area.
2. The method according to claim 1, wherein in the step 1, the weighted round robin algorithm is implemented by setting a message counter for each queue of the port, counting according to the set weight, when each round robin arrives at the queue, the queue outputs a message and the message counter of the queue is decremented by 1 until the message counter of the queue is decremented by 0, and when the message counter of all queues is decremented by 0, re-calculating according to the weight, and starting round robin scheduling;
the weighted circulation algorithm uses 2 FIFO channels, and respectively configures weights W0 and W1 for the two channels, wherein the number of messages of the first channel is N, and the number of messages of the second channel is M; in the first polling, W0 messages are taken out from a first channel, W1 messages are taken out from a second channel, at the moment, the counter count-1 of the two channels is equal to the counter count-1 of the two channels, then the second polling is started, when the counter count=0 in one channel exists, only messages are taken out from the other channel, and when the counter counts of the two channels are equal to 0, the polling is ended.
3. The protocol conversion method based on double buffers according to claim 1, wherein in the step 2, the specific process of configuring the ring buffer in the serial port is:
the design of the ring buffer is completed by using two pointers, namely a pointer Head pointing to the Head of the queue and a pointer Tail pointing to the Tail of the queue; the principle is that before data comes in, the ring buffer is initialized, and the head and tail of the queue point to 0; when data comes in, the Head points to "0", the Tail points to the next storage space "1", and the data is stored at an address "0"; when data comes in again, the Head points to "1", the Tail points to the next storage space "2", and the data is stored at address "1"; when data is processed, firstly processing the data with the address of 0, and then sequentially processing the next data to realize the reading and writing of the annular buffer area; when the head and the tail of the queue overlap again, the annular buffer area is full, the subsequent data cannot enter, and the annular buffer area is emptied at the moment, so that the subsequent latest data are reserved;
the annular buffer zone is provided with a buffer zone residual length of Lenth, the buffer zone length of S, the Lenth is added with 1 when data are read, and the Lenth is subtracted by 1 when the data are stored; when Lenth=0, the buffer is full at this time, and when Lenth=S, the buffer is empty at this time; when Lenth=0, the buffer is emptied, and when Lenth+.0, writing to the buffer is allowed.
4. The protocol conversion method based on double buffers according to claim 1, wherein in the step 3, the specific process of sending or receiving the message through the double buffers is as follows:
in the first polling, W0 messages are taken out from a first channel, W1 messages are taken out from a second channel and then sent into a ring buffer, and the residual length of the ring buffer is Lenth=S-W0-W1; then carrying out second polling, and sending the W0+W1 messages to a ring buffer area, wherein the residual length of the ring buffer area is Lenth=S-2 (W0+W1); then, carrying out next polling, ending polling when the count=0 of the two FIFO channels, and emptying the annular buffer area if the Lenth=0 so as to facilitate the entry of the subsequent messages;
after the steps 1 and 2 are completed, the message is sent to the annular buffer area according to the dispatching result after passing through the priority queue, and then the message is sent or received according to the following steps; firstly, defining a serial port structure body, setting the serial port baud rate to 115.2Kbps, transmitting 8-bit data, using 1-bit stop bit, performing odd-even enabling and hardware enabling, setting receiving and transmitting modes, initializing a serial port register according to parameters, and enabling serial port interruption and serial port peripheral equipment; then defining serial port receiving and transmitting, obtaining a transmitting state bit or a receiving state bit by calling a function, and determining whether to transmit or receive data according to a return value; and finally, defining serial port interrupt transceiving data, reading interrupt flag bits after defining a variable to store received data, clearing the interrupt flag bits, storing received characters into an array, and finally, transmitting or receiving the data through a serial port.
5. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method according to any of claims 1-4 when the program is executed.
6. A computer readable storage medium, on which a computer program is stored, characterized in that the program, when being executed by a processor, implements the steps of the method according to any of claims 1-4.
7. A computer program product comprising a computer program, characterized in that the computer program, when being executed by a processor, implements the steps of the method of any of claims 1-4.
CN202310268415.6A 2023-03-17 2023-03-17 Protocol conversion method based on double buffer areas Pending CN116366574A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310268415.6A CN116366574A (en) 2023-03-17 2023-03-17 Protocol conversion method based on double buffer areas

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310268415.6A CN116366574A (en) 2023-03-17 2023-03-17 Protocol conversion method based on double buffer areas

Publications (1)

Publication Number Publication Date
CN116366574A true CN116366574A (en) 2023-06-30

Family

ID=86913038

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310268415.6A Pending CN116366574A (en) 2023-03-17 2023-03-17 Protocol conversion method based on double buffer areas

Country Status (1)

Country Link
CN (1) CN116366574A (en)

Similar Documents

Publication Publication Date Title
US5838904A (en) Random number generating apparatus for an interface unit of a carrier sense with multiple access and collision detect (CSMA/CD) ethernet data network
CN113138801B (en) Command distribution device, method, chip, computer device and storage medium
EP1199641A2 (en) Data processing device used in serial communication system
CN115002047B (en) Remote direct data access method, device, equipment and storage medium
CN111930666A (en) High-speed configurable industrial protocol converter
CN115242726A (en) Queue scheduling method and device and electronic equipment
CN112328523B (en) Method, device and system for transmitting double-rate signal
CN109905331B (en) Queue scheduling method and device, communication equipment and storage medium
CN116366574A (en) Protocol conversion method based on double buffer areas
CN113946480A (en) Detection device and method for I2C bus
US9544401B2 (en) Device and method for data communication using a transmission ring buffer
CN111405534B (en) Information transmission method, first terminal and computer storage medium
CN113676386A (en) FC-AE-1553 bus protocol message communication system
CN117097679A (en) Aggregation method and device for network interruption and network communication equipment
CN112147918B (en) Asynchronous data interaction method and system based on ARM + FPGA + DSP architecture
CN111464386A (en) Communication conversion method and device for data transmission and communication system
CN115955441A (en) Management scheduling method and device based on TSN queue
KR101794761B1 (en) Digital Data Communication Module and its Data Simulator
CN109862044B (en) Conversion device, network equipment and data transmission method
CN114979022A (en) Method, device, adapter and storage medium for realizing remote direct data access
CN112559404A (en) Data scheduling device and method and accelerated processing chip
CN117349214B (en) AXI protocol-to-serial communication protocol conversion bridge with unpacking and packing capacity
CN218772135U (en) Sampling value message sending device based on Linux system
CN108255770B (en) Processing method based on 1394 bus event message response mechanism
CN110505038B (en) Data transmission method and related device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination