Multi-machine communication data processing method and multi-machine communication system implemented based on serial port

By using hardware and software flow control mechanisms, DMA channels and ring queues in multi-computer communication systems, the problems of low data reception and processing efficiency, stick packet problems and difficulty in identification of codes in serial communications are solved, and efficient, real-time and reliable multi-computer communication data processing is achieved.

CN119201805BActive Publication Date: 2025-06-13BLUE STAR OPTICAL (SHANGHAI) AEROSPACE TECH CO LTD +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411689494.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-06-13
Estimated Expiration
2044-11-25

AI Technical Summary

Technical Problem

In multi-computer communication, how to use the serial port as a communication interface to receive and summarize data asynchronously, and ensure the real-time, accuracy of the data and avoid packet sticking problems, especially in case of errors in code or packet loss, quickly distinguish transmission errors.

Method used

By using the flow control mechanism of hardware and software in the server device to manage the serial port transmission stream, an error detection and correction mechanism is introduced, and data reception and processing efficiency is improved by using DMA channels and serial port idle interrupts, periodic pulses trigger the controlled device to send data, and the calculation results are saved in the ring queue.

Benefits of technology

It improves the efficiency of data reception and processing, reduces CPU intervention and processing delays, ensures the regularity and synchronization of data acquisition, avoids packet sticking problems, and quickly identify transmission errors in case of code errors or packet loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119201805B_ABST
    Figure CN119201805B_ABST
Patent Text Reader

Abstract

An embodiment of the present disclosure provides a multi-machine communication data processing method and a multi-machine communication system implemented based on a serial port. The method includes: configuring a corresponding DMA channel for each serial port and registering a receive idle interrupt, creating a circular queue to save the calculation results after summarizing and processing the collected data of the controlled devices received in each cycle; starting the system tick clock for periodic timing, sending a pulse at the start of each timing cycle to notify each controlled device to start sending data; after receiving the data sent by the controlled device, parsing the data in the corresponding receive idle interrupt handling function and saving the parsed data in the circular queue; after waiting for a specified time in each timing cycle, summarizing and calculating the data collected by each controlled device, and sending the calculation results to the client upper computer through the serial port in DMA mode. This solution realizes efficient and real-time periodic multi-machine data communication only with the system tick clock and the serial port.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of communication technologies, and particularly to a multi-machine communication data processing method, a multi-machine communication system, a server device, and a storage medium implemented based on a serial port. Background Art

[0002] Multi-machine communication is a process of data exchange and communication between multiple devices. Such communication can occur between different types of devices, such as computers, embedded systems, sensors, etc., with the aim of achieving data sharing, collaborative work, or information transmission. Although in today's high-speed development of communication technologies, multi-machine communication is no longer limited to using serial ports, but uses physical buses with higher rates such as SPI, IIC, network cables, optical fibers, etc. to achieve, but due to cost and wiring difficulty considerations, using multiple serial ports, that is, UART for multi-machine communication is still a common method in the embedded and communication fields. Especially for the aerospace field, the volume design of the aircraft will inevitably consider the wiring difficulty, and the volume directly affects the weight of the aircraft. Therefore, for short-distance multi-machine communication, using UART with only three wires (Tx, Rx, GND) is one of the best choices.

[0003] However, how to asynchronously receive and aggregate multi-machine communication data and perform calculation processing only using a serial port as the communication interface, how to ensure the real-time performance and accuracy of periodic multi-machine data communication, how to ensure that the serial port communication receiver can avoid or solve the problem of packet adhesion of the received data stream in the receive buffer to improve the unpacking efficiency, and how to quickly distinguish between transmission errors and packet adhesion and packet breakage phenomena in the case of serial port communication transmission error codes or packet loss are still important technical requirements and performance issues in the field of communication technologies. Summary of the Invention

[0004] In view of the above problems, the present solution proposes a multi-machine communication data processing method and a multi-machine communication system implemented based on a serial port, using hardware and software flow control mechanisms to manage the serial port transmission flow and avoid conflicts, and introducing an error detection and correction mechanism to improve the reliability of communication.

[0005] According to a first aspect of the present invention, there is provided a multi-machine communication data processing method implemented based on a serial port, implemented based on a server device. The server device communicates with a client host computer and one or more controlled devices through serial ports respectively. The server device is used to periodically send pulses to trigger one or more controlled devices to send the collected data, and in each period, aggregate and calculate the data received from the controlled devices and then send it to the client host computer. The method includes:

[0006] The server device and each controlled device perform power-on initialization and handshake synchronization. The power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, binding the transmit channel and receive channel of each serial port to a transmission stream of a unique DMA channel respectively, registering a receive idle interrupt for each serial port, and creating a circular queue for storing the calculation results after summarizing and processing the collected data of the controlled devices received in each period. The queue elements of the circular queue include at least packet ID, packet assembly timestamp, calculation result, and the collected data valid flag bits of each controlled device;

[0007] Start the system tick clock for periodic timing, and send a pulse or trigger an interrupt at the start of each timing period to notify each controlled device to start sending data;

[0008] After receiving the data sent by the controlled device from the transmission stream of the DMA channel corresponding to each serial port, enter the corresponding receive idle interrupt handling function. In the interrupt handling function, parse the received data and save the parsed data in the circular queue;

[0009] After waiting for a specified time in each timing period, summarize and calculate the collected data of each controlled device received, and send the calculation result to the client host computer through the serial port in DMA mode.

[0010] Through the above technical solution, using DMA and serial port idle interrupt improves the efficiency of data reception and processing, and reduces the intervention and processing delay of the CPU. Triggering the controlled device to send data through periodic pulses ensures the regularity and synchronization of data acquisition.

[0011] Optionally, in the multi-machine communication data processing method based on serial ports provided by the present invention, after the power-on initialization of the controlled device is completed, a convention value is written to a specified register; after the power-on initialization of the server device is completed, the specified register is cyclically read until the convention value is read out, then the handshake between the server device and the controlled device is successful. When the server device successfully shakes hands with all controlled devices respectively, the handshake synchronization is completed.

[0012] Through the above technical solution, handshake is performed through the register after power-on initialization, which simplifies the complexity of communication initialization and avoids additional handshake protocols.

[0013] Optionally, in the multi - machine communication data processing method based on serial port implemented in the present invention, set the reload value of the system tick clock according to the system tick clock frequency, so that the time of each reload cycle of the system tick clock is equal to the periodic notification time required by the server; clear the counter value of the system tick clock and start the system tick clock timer, repeatedly read the status register of the system tick clock until the value of the reload flag bit COUNTFLAG in the read status register of the system tick clock is 1, then clear the system tick clock counter value and send pulse - triggered GPIO interrupts to each controlled device respectively to notify each controlled device to send data. The COUNTFLAG flag bit is automatically set to 1 by hardware when the count value decreases to 0, and the COUNTFLAG flag bit is automatically cleared by hardware when it is read.

[0014] According to the above - mentioned technical solution, by setting the reload value of the system tick clock so that its period is equal to the notification period required by the server, accurate periodic triggering is ensured and time deviation is reduced. The automatic clearing of the system tick clock counter and the automatic management of the COUNTFLAG flag bit simplify the use of the timer, reduce software intervention, and lower the possibility of errors.

[0015] Optionally, in the multi - machine communication data processing method based on serial port implemented in the present invention, the packet - forming timestamp of the queue element is calculated by the system tick clock counter value read during packet - forming and the number of reloads. The calculation method of the packet - forming timestamp is as follows:

[0016] time_us = [loadCnt+(load + 1 - val) / (load + 1)] * TRIG_PERIOD, where time_us is the packet - forming timestamp, TRIG_PERIOD is the notification period of the server, loadCnt is the number of reloads during packet - forming, and load is the reload count value of the system tick clock.

[0017] Optionally, in the multi-machine communication data processing method implemented based on the serial port provided by the present invention, after the handshake synchronization is completed between the server device and each controlled device, a DMA receive buffer is set for each serial port, DMA reception is enabled, and the specified receive start address is set to the start address of the DMA receive buffer, and the specified receive length is set to the buffer length; when a serial port receive idle interrupt occurs, the reception of the transmission stream of the DMA channel of the serial port is stopped, and according to the specified receive length size and the number of remaining data units HAL_DMA_GET_COUNTER of the current DMA stream transmission, the actual receive data length rxLen of the serial port is calculated, where rxLen = size - HAL_DMA_GET_COUNTER; the data stream with a length of rxLen starting from the start address of the DMA receive buffer is parsed according to the protocol format predetermined with the sender, and the parsing result is saved in a global variable; DMA reception is enabled again, and the start address of the DMA receive buffer and the specified receive length are reconfigured to continue receiving subsequent data, and the specified receive length is greater than the estimated maximum length of a single packet received from the serial port.

[0018] Optionally, in the multi-machine communication data processing method implemented based on the serial port provided by the present invention, when parsing the transmission stream with a length of the actual receive data length received in the DMA receive buffer during a serial port receive idle interrupt, if errors such as missing buffer packet format and missing packet length are detected, the data with parsing failure is discarded and the next DMA reception is directly enabled.

[0019] Optionally, in the multi-machine communication data processing method implemented based on the serial port provided by the present invention, wait for a specified time within the current timing cycle. If all the data sent by the controlled devices is successfully received and parsed within the specified time, the data collected by each controlled device is aggregated and calculated, and then a new queue element is generated and inserted into the circular queue. The head element of the circular queue is sent to the client host computer through the serial port in the DMA manner. The queue element includes a packet ID, a packet assembly timestamp, a data calculation result, and a valid flag bit of the data collected by the controlled device.

[0020] If all the data collected by the controlled devices is not received within the specified time, a new queue element is generated and inserted into the tail of the circular queue. The values of each member of the new queue element are the same as those of the previous queue element. The valid flag bit of the data collected by the controlled device that has not received data is cleared, and then the packet ID is updated. The head element of the circular queue is sent to the client host computer through the serial port in the DMA manner; wait for the end of the timing cycle and continue to receive and process data in the next timing cycle.

[0021] Optionally, in the multi - machine communication data processing method based on serial ports provided by the present invention, at the server side, after triggering a GPIO interrupt to notify the controlled device, the system tick clock is immediately read and local variables are created to save the initial count value of the system tick clock and the initial reload count;

[0022] The current count value of the system tick clock and the current reload count are repeatedly read until the time interval between the calculated current time and the notification time is greater than or equal to the specified waiting time. Here, the specified waiting time is the periodic notification time minus the maximum estimated time required to receive, summarize, and calculate the processed data of each serial port acquisition. The time interval between the current time and the notification time is:

[0023] dTime = [(val1 - val2) / (load + 1)+loadCnt2 - loadCnt1]*TRIG_PERIOD, where load is the reload count value, TRIG_PERIOD is the notification period of the server side, val1 is the initial count value of the system tick clock, val2 is the current count value of the system tick clock, loadCnt1 is the initial reload count, and loadCnt2 is the current reload count.

[0024] Optionally, in the multi - machine communication data processing method based on serial ports provided by the present invention, the circular queue is a first - in - first - out data structure. When writing to the queue, the queue element is inserted into the queue space indicated by the tail position serial number and the tail position serial number is updated to WrId=(WrId + 1)%MAX. When reading from the queue, the queue element indicated by the head position serial number is read first and the head position serial number is updated to RdId=(RdId + 1)%MAX, where MAX is the maximum number of queue elements that the circular queue can accommodate;

[0025] When the main thread still has not received all the data collected by the controlled devices within the current timing cycle after waiting for the specified time, the queue elements saved by summarizing and calculating in the previous timing cycle are found through the tail position serial number. The packet ID of the queue elements sent to the client upper computer through the serial port within each timing cycle is always equal to the head position serial number, so as to ensure that the client upper computer checks whether there is a packet loss phenomenon during the transmission process by checking whether the received packet IDs are continuous.

[0026] According to the above technical solution, the read and write operations of the circular queue only involve the update of the serial number of the position, without complex operations, ensuring the high efficiency of data processing. Through the continuity check of the packet ID, even in the case of incomplete data reception, the lost data can be recovered through the saved historical data, ensuring the integrity of data transmission and enabling timely detection and handling of packet loss phenomena.

[0027] According to a second aspect of the present invention, a multi-machine communication system implemented based on a serial port is provided, including: a client host computer, a server device, a plurality of controlled devices, and a UART interface for multi-machine communication; the client host computer runs a user interaction interface program for graphically displaying the data or signals after summary calculation and processing; the controlled devices are embedded computers or other devices for collecting data or signals, and the controlled devices have serial ports for collecting data in real time and sending it to the server device through the serial ports after receiving a notification from the server device; the server device is provided with a plurality of serial ports, and each serial port is respectively used for communicating with the client host computer or a unique controlled device.

[0028] The server device runs server software for periodically sending pulses to trigger one or more controlled devices to send the real-time collected data, and summarizing and calculating the data received from the controlled devices in each cycle and then sending it to the client host computer, including:

[0029] The server device and each controlled device perform power-on initialization and handshake synchronization. The power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, binding the sending channel and receiving channel of each serial port to a unique DMA channel respectively, registering a receive idle interrupt for each serial port respectively, and creating a circular queue for storing the calculation results after summarizing and processing the collected data of the controlled devices received in each cycle. The queue elements of the circular queue at least include packet ID, packet assembly timestamp, calculation result, and the acquisition data valid flag bits of each controlled device; waiting for the handshake to complete after all controlled devices have successfully completed power-on initialization;

[0030] Start the system tick clock for periodic timing, and send a pulse or trigger an interrupt at the start of each timing cycle to notify each controlled device to start sending data;

[0031] After receiving the data sent by the controlled device from the DMA channel corresponding to each serial port, enter the corresponding receive idle interrupt handling function, parse the received data in the interrupt handling function, and save the parsed data in the circular queue;

[0032] After waiting for a specified time in each timing cycle, summarize and calculate the data collected by each controlled device received, and send the calculation result to the client host computer through the serial port in DMA mode.

[0033] According to a third aspect of the present invention, a server device is provided, including: at least one processor; and a memory storing program instructions, wherein the program instructions are configured to be executed by at least one processor, and the program instructions include instructions for executing the multi-machine communication data processing method implemented based on a serial port according to the first aspect of the present invention.

[0034] According to a fourth aspect of the present invention, there is provided a readable storage medium storing program instructions, which, when read and executed by a server device, cause the server device to execute the multi-machine communication data processing method based on a serial port according to the first aspect of the present invention.

[0035] The multi-machine communication data processing method and multi-machine communication system based on a serial port according to the present invention can at least achieve the following beneficial effects:

[0036] (1) Binding the Tx and Rx channels of each serial port to a transmission stream of a unique DMA channel respectively ensures the independence of each serial port data channel and improves the serial port data transmission efficiency;

[0037] (2) Registering receive idle interrupts for each serial port respectively, calculating the single-packet length of the single receive buffer in the DMA buffer through the remaining length of the DMA channel transmission stream in the receive idle interrupt handling function, unpacking, and then restarting DMA reception, avoiding the problem of receive packet adhesion, improving the unpacking efficiency, and reducing the CPU occupation time during data transmission;

[0038] (3) On the premise of only using the non-interrupt timing method of the same system tick clock SysTick, a method for generating an accurate timing period for triggering an interrupt to notify the controlled device, a method for generating a fixed timeout specified time for waiting for packet reception within the timing period, and a method for generating an accurate timestamp during packet assembly and sending are provided simultaneously, ensuring the real-time and periodicity of the collected data received in a centralized manner;

[0039] (4) Using the queue head position ID of the circular queue as the packet ID, when all the collected data has not been received within the timeout period, the last packet sent recently can be quickly found from the circular queue, the data valid flag bit is cleared, and then it is given to the client host computer, ensuring the continuity of the graphical display of the client host computer and facilitating the client to quickly identify the packet loss and the error of not receiving the collected data.

[0040] Therefore, this solution can periodically notify the controlled device to collect data or signals, receive data sent by multiple controlled devices through the serial port in real time, and quickly and accurately summarize, calculate and process it and send it to the client host computer, solving the performance problem of multi-machine communication using the serial port.

[0041] The above description is only an overview of the technical solution of the present invention. In order to be able to understand the technical means of the present invention more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of the present invention more obvious and understandable, the specific embodiments of the present invention are given below. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for the purpose of illustrating the preferred embodiments and are not considered to be a limitation of the present invention. Also, throughout the drawings, the same reference numerals are used to denote the same components. In the drawings:

[0043] Figure 1 Shows a schematic structural diagram of a multi-machine communication system implemented based on a serial port according to an embodiment of the present invention;

[0044] Figure 2 Shows a schematic diagram of the software architecture of a server device according to an embodiment of the present invention;

[0045] Figure 3 Shows an example of the code implementation of the main thread of a server device according to an embodiment of the present invention;

[0046] Figure 4 Shows a schematic structural diagram of a server device 100 according to an embodiment of the present invention;

[0047] Figure 5 Shows a schematic flowchart of a multi-machine communication data processing method 500 implemented based on a serial port according to an embodiment of the present invention;

[0048] Figure 6 Shows an example of the code implementation of non-interrupt timing of a system tick clock and generating a timestamp according to an embodiment of the present invention;

[0049] Figure 7 Shows an example of the code of a serial port receive idle interrupt processing function according to an embodiment of the present invention. Detailed Embodiments

[0050] Multi-machine communication is a common requirement in various fields such as communication networks, aerospace, measurement and control, and industrial automation. Among them, the client / server architecture is one of the most common multi-machine communication architectures. For example, in the field of measurement and control, an embedded lower computer is used as the communication server, and other embedded devices for real-time collection of bus data are used as controlled devices. When the controlled device receives the notification signal from the server device, it transmits the real-time collected data to the communication server through the serial port. After the communication server aggregates and calculates the data collected by each controlled device, it is sent to the client upper computer through the serial port for display to the user through the interface. For the fields of industrial automation and aerospace, the server periodically receives and aggregates information such as temperature, humidity, and directional acceleration sent by each embedded device or sensor through the serial port, calculates and processes it into information such as average temperature, average humidity, and combined acceleration, and then sends it to the client upper computer through the serial port. Due to the advantages of low cost, low wiring difficulty, and small short-distance transmission delay of the serial interface, using multiple serial ports, that is, UARTs, for multi-machine communication is still a better choice in the embedded and communication fields.

[0051] However, how to use the serial port to receive, aggregate, and calculate and process multi-machine communication data more quickly, improve the real-time performance and periodicity of notifying each controlled device to send the collected data or signals, ensure that the serial port communication receiver can solve the problem of packet adhesion in the transmission stream to improve the unpacking efficiency, and quickly identify the transmission error in the case of serial port communication transmission error or packet loss is still a communication performance problem that needs to be solved in the embedded and communication fields.

[0052] In order to improve the performance of multi-machine communication using the serial port, this solution proposes a multi-machine communication data processing method based on the serial port, which can periodically and accurately notify the controlled device to collect data, receive the data sent by multiple controlled devices through the serial port in real time, and quickly aggregate, calculate, and process it and then send it to the client upper computer.

[0053] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided so that the present disclosure can be more thoroughly understood and the scope of the present disclosure can be fully conveyed to those skilled in the art.

[0054] Figure 1 The structural schematic diagram of a multi-machine communication system based on the serial port according to an embodiment of the present invention is shown. As Figure 1As shown in the figure, the system includes a client host computer, a server device, multiple controlled devices (Controlled Device 1, Controlled Device 2... Controlled Device n), and UART interfaces (UART0, UART1, UART2... UARTn) for multi-machine communication. Among them, the client host computer runs a user interface program for graphically displaying the data or signals after summary calculation and processing. The server device is provided with multiple serial ports, and each serial port is respectively used to communicate with the client host computer or a unique controlled device. The controlled device is an embedded computer or other device for collecting data or signals. Refer to Figure 1 As shown in the figure, the server device is communicatively connected to the client host computer through the serial port UART0, and is communicatively connected to Controlled Device 1, Controlled Device 2... Controlled Device n through the serial ports UART1, UART2... UARTn respectively.

[0055] The server device runs server software, which is used to periodically send pulses to trigger one or more controlled devices to send the real-time collected data, and summarize and calculate the data of the received controlled devices in each cycle and then send it to the client host computer. After receiving the notification from the server device, the controlled device collects data or signals in real time and sends them to the server device through the corresponding serial port.

[0056] Figure 2 The figure shows a schematic diagram of the software architecture of the server device according to an embodiment of the present invention. As Figure 2 shown, in the main thread, 1) the server device and each controlled device perform power-on initialization and handshake synchronization. Among them, the power-on initialization includes: configuring the period of the system tick clock and a transmission stream of the DMA channel corresponding to each serial port, binding the transmission channel and the reception channel of each serial port to a transmission stream of a unique DMA channel respectively, registering a reception idle interrupt for each serial port, and creating a circular queue for storing the calculation results after summarizing and processing the collected data of the controlled devices received in each cycle, and waiting for the handshake to be completed after all the controlled devices are successfully powered on and initialized. Among them, the queue elements of the circular queue at least include packet ID, packet assembly timestamp, calculation result, and the valid flag bits of the collected data of each controlled device;

[0057] 2) Start the system tick clock for periodic timing, and send Pulse 1 and Pulse 2 respectively at the start of each timing cycle to notify Controlled Device A and Controlled Device B to start sending the real-time collected data;

[0058] 3) The main thread waits for a specified time within each timing cycle. During this period, when it automatically receives data sent by the controlled devices from the DMA channels corresponding to each serial port, it enters the corresponding receive idle interrupt handling function. In the receive idle interrupt handling function, it first temporarily closes the DMA reception, then parses and saves the data in the DMA receive buffer, and then re - opens the DMA reception and specifies the receive length as the buffer length. To ensure that a whole packet of data is cached each time the idle interrupt is entered, the specified receive length should be much larger than the maximum length of a single packet expected to be received;

[0059] 4) After waiting for the specified time in each timing cycle, it checks whether the acquisition data of each controlled device has been received: If the acquisition data of all controlled devices has been received, after summarizing, calculating, and processing, a new queue element is generated and inserted into the circular queue, and then the queue element is sent to the client host computer through the serial port in DMA mode; On the contrary, if the acquisition data of all controlled devices has not been received after the timeout, the previous packet queue element in the circular queue is sent to the client host computer through the serial port in DMA mode;

[0060] 5) Return to step 3), and start the process of notifying the controlled devices to send acquisition data and receiving, summarizing, and processing in the next timing cycle.

[0061] Figure 3 Shows a code implementation example of the main thread of the server device according to an embodiment of the present invention. As Figure 3 shown, Acc1A, Acc1B, and Acc1C are three different controlled devices, which communicate with the server device through serial ports Uart5, Uart3, and Uart2 respectively.

[0062] When the main thread is powered on, it first initializes the serial ports, DMA, system tick clock SysTick, and other hardware. When initializing each serial port, it will register a serial port receive idle interrupt (IDEL interrupt) for each serial port, and bind the Tx and Rx of each serial port to a unique DMA transfer stream respectively.

[0063] After the initialization is completed, it synchronizes the power - on handshake with Acc1A, Acc1B, and Acc1C respectively. When the initialization of all controlled devices is completed, the handshake ends. After the handshake ends, it enables the receive idle interrupts of each serial port, and calls a function to specify the start of the first DMA reception of the DMA receive buffer of each serial port. At this time, the specified DMA receive length is the buffer length, and this length should be much larger than the maximum length of a single packet that may be received to ensure that there is no phenomenon of caching broken packets in the receive buffer.

[0064] Then it enables the system tick timer. In the example, the trigger notification timing cycle is 1 us, and the reload value of the system tick timer is set according to the system tick clock frequency.Figure 4 In it, TRIGPERIOD_ACC1_US is a macro value representing the trigger period. After the tick timer is enabled, it counts down. When the count value decreases to 0, it will automatically reload the set reload value, and the hardware will automatically set the COUNTFLAG bit in the status register of SysTick to 1.

[0065] Figure 3 The function WaitSysTimerEnd() in it essentially waits in a loop for the COUNTFLGA bit read from the status register of SysTick to change from 0 to 1. At this time, it represents the end of this round of timing cycle and the start of the next round of timing cycle. Since COUNTFLGA is automatically cleared by the hardware when it is read, as long as the flag bit is read as 1, it must represent that the tick timer has been reloaded again, that is, a timing cycle (1 us) has ended.

[0066] At the start of each timing cycle, the main thread sends pulses to the controlled devices Acc1A, Acc1B, and Acc1C respectively, notifying each controlled device to collect and send data in real time. At this time, when the CPU receives the collected data sent by any controlled device, it will enter the receive idle interrupt of the corresponding serial port to receive and parse the packet. After sending the pulse notification, the main thread will wait for a specified time. When the specified time is exceeded, it will call the function MakeGuiPkt() to aggregate and calculate the data collected by each controlled device to generate a new circular queue element, and in this function, it will send this queue element to the client host computer through the serial port in DMA mode.

[0067] It should be noted that if the data sent by all controlled devices is not received within the specified time, the previous queue element cached in the circular queue will be directly copied and inserted at the end of the queue and sent to the host computer. Before sending, its timestamp and packet ID will be modified. The timestamp is also obtained in the MakeGuiPkt function, and the packet ID is equal to the ID of the head position of the circular queue where the sent queue element is located. Then the main thread returns to the WaitSysTimerEnd() function to wait for the start of the next round of timing cycle.

[0068] Figure 4 shows a schematic structural diagram of a server device 100 according to an embodiment of the present invention. As Figure 4 shown, in the basic configuration 102, the server device 100 typically includes a memory 106 and one or more processors 104. The memory bus 108 can be used for communication between the processor 104 and the memory 106.

[0069] Depending on the desired configuration, processor 104 can be any type of processor, including but not limited to: microprocessor (µP), microcontroller (µC), digital information processor (DSP), or any combination thereof. Processor 104 can include one or more levels of cache such as level 1 cache 110 and level 2 cache 112, processor core 114, and registers 116. Example processor core 114 can include an arithmetic logic unit (ALU), a floating point unit (FPU), a digital signal processing core (DSP core), or any combination thereof. Example memory controller 118 can be used with processor 104, or in some implementations, memory controller 118 can be an internal part of processor 104.

[0070] Depending on the desired configuration, memory 106 can be any type of memory, including but not limited to: volatile memory (such as RAM), non-volatile memory (such as ROM, flash memory, etc.), or any combination thereof. Physical memory in the server device generally refers to volatile memory RAM, and data on the disk needs to be loaded into physical memory before it can be read by processor 104. Memory 106 can include operating system 120, one or more programs 122, and program data 124. In some embodiments, program 122 can be arranged to execute instructions on one or more processors 104 using program data 124 on the operating system. Operating system 120 can be, for example, Linux, Windows, etc., which includes program instructions for handling basic system services and performing hardware-dependent tasks. Program 122 includes program instructions for implementing various functions desired by users. Program 122 can be, for example, a browser, instant messaging software, software development tools (such as integrated development environment IDE, compiler, etc.), but is not limited thereto. When program 122 is installed in server device 100, a driver module can be added to operating system 120.

[0071] When server device 100 starts running, processor 104 reads and executes the program instructions of operating system 120 from memory 106. Program 122 runs on operating system 120 and uses the interfaces provided by operating system 120 and the underlying hardware to implement various functions desired by users. When the user starts program 122, program 122 is loaded into memory 106, and processor 104 reads and executes the program instructions of program 122 from memory 106.

[0072] Server device 100 further includes storage device 132. Storage device 132 includes removable storage 136 and non-removable storage 138, and both removable storage 136 and non-removable storage 138 are connected to storage interface bus 134.

[0073] The server device 100 may further include an interface bus 140 that facilitates communication from various interface devices (e.g., output device 142, peripheral interface 144, and communication device 146) to the basic configuration 102 via the bus / interface controller 130. Example output devices 142 include a graphics processing unit 148 and an audio processing unit 150. They may be configured to facilitate communication with various external devices such as a display or speakers via one or more A / V ports 152. Example peripheral interfaces 144 may include a serial interface controller 154 and a parallel interface controller 156, which may be configured to facilitate communication with external devices such as input devices (e.g., keyboard, mouse, pen, voice input device, touch input device) or other peripherals (e.g., printer, scanner, etc.) via one or more I / O ports 158. Example communication device 146 may include a network controller 160, which may be arranged to facilitate communication with one or more other computing devices 162 via one or more communication ports 164 through a network communication link.

[0074] The network communication link may be an example of a communication medium. A communication medium generally may embody computer-readable instructions, data structures, program modules in a modulated data signal such as a carrier wave or other transport mechanism, and may include any information delivery medium. A "modulated data signal" may be a signal in which one or more of its data sets or its changes can encode information in the signal. As a non-limiting example, the communication medium may include wired media such as a wired network or a dedicated line network, and various wireless media such as sound, radio frequency (RF), microwave, infrared (IR), or other wireless media. The term computer-readable medium as used herein may include both storage media and communication media.

[0075] The server device 100 further includes a storage interface bus 134 connected to the interface controller 130. The storage interface bus 134 is connected to a storage device 132, and the storage device 132 is adapted for data storage. Example storage devices 132 may include removable storage 136 (e.g., CD, DVD, USB flash drive, removable hard disk, etc.) and non-removable storage 138 (e.g., hard disk drive HDD, etc.).

[0076] In the server device 100 according to the present invention, the program 122 includes instructions for executing the multi-machine communication data processing method 500 based on serial ports according to the present invention.

[0077] Figure 5 A flowchart showing the multi-machine communication data processing method 500 based on serial ports according to an embodiment of the present invention is shown. As Figure 5As shown, first in step S510, the server device and each controlled device perform power-on initialization and handshake synchronization. The power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, binding the transmission channel and the reception channel of each serial port to a unique DMA channel respectively, registering a reception idle interrupt for each serial port respectively, and creating a circular queue for storing the calculation results after summarizing and processing the collected data of the controlled devices received in each period. The queue elements of the circular queue include at least the packet ID, the packet assembly timestamp, the calculation result, and the valid flag bits of the collected data of each controlled device.

[0078] Setting the system tick clock SysTick can obtain a stable time reference for the system to synchronize the data transmission and processing cycles, and at the same time provides a trigger interrupt to notify the controlled device to generate an accurate timing cycle, ensuring the periodicity of receiving the collected data.

[0079] During the power-on initialization process, a unique reception idle interrupt is registered for each serial port respectively, and multiple DMA channels are applied for. The TX and RX channels of each serial port are respectively bound to the transmission stream of a unique DMA channel. That is, different serial port transmission streams are assigned to different DMA channels, which can make the data channels of each serial port independent, transfer the data transmission from CPU processing to the DMA (Direct Memory Access) controller, avoid the data transmission of one serial port affecting the transmission streams of other serial ports, and only use DMA to send or receive serial port data to improve the data sending and receiving efficiency and reduce the CPU occupancy time. Only when DMA receives a complete packet of data will it enter the reception idle interrupt processing function, reducing the number of interrupts during the data sending and receiving process.

[0080] The circular queue is used to store the data calculation results of each period so that the system can process the data at fixed time intervals and maintain the order of the data. Among them, the queue elements of the circular queue include at least: packet ID: the ID of the head position of the data packet that uniquely identifies the data packet, which is convenient for tracking and managing the data; packet assembly timestamp: records the time when the data packet is processed for time analysis or synchronization; calculation result: includes the summary and calculation results of the collected data of the controlled device; valid flag bit: indicates the validity of the data to ensure that the processed data meets the expectations.

[0081] Subsequently, in step S520, the system tick clock is started for periodic timing, and a pulse or a trigger interrupt is sent at the start of each timing cycle to notify each controlled device to start sending data.

[0082] After the server is powered on and initialized and the handshake is completed, the reload value of the system tick clock can be set according to the system tick clock frequency, so that the time of each reload cycle of the system tick clock is equal to the periodic notification time required by the server. The reload value of SysTick can be set according to the required timing accuracy. This reload value determines the length of the timing cycle. For example, if an interrupt needs to be generated every 1 millisecond, set the reload value to the system tick clock frequency divided by 1 millisecond.

[0083] If it is selected to notify the controlled device by sending a pulse, a GPIO output pin can be used to generate a pulse signal at the start of each SysTick timing cycle. The controlled device can listen for this pulse signal and start sending data when the pulse is received.

[0084] If it is selected to notify the controlled device by triggering an interrupt, the interrupt service routine (ISR) of SysTick will trigger an interrupt at the start of each timing cycle. The interrupt service routine can send instructions or data to the controlled device through the serial port or other communication methods to inform it to start data sending. After receiving the pulse or instruction generated by SysTick, the controlled device starts sending data. The server needs to configure the corresponding receiving mechanism to process the data sent from the controlled device.

[0085] In an embodiment of the present invention, the counter value of the system tick clock is cleared and the system tick clock timer is started. The status register of the system tick clock is repeatedly read until the value of the reload flag bit COUNTFLAG in the read status register of the system tick clock is 1. Then, the counter value of the system tick clock is cleared and a pulse is sent to each controlled device to trigger a GPIO interrupt to notify each controlled device to send data. The COUNTFLAG flag bit is automatically set to 1 by the hardware when the count value decreases to 0, and the COUNTFLAG flag bit is automatically cleared by the hardware when it is read.

[0086] By using the SysTick timer to synchronize the controlled devices, it is ensured that each device starts data sending at an accurate time point, thereby realizing the effective acquisition and processing of data. This method can improve the synchronization accuracy of the system and ensure the timeliness of data transmission.

[0087] Figure 6 Shows an example of the code implementation of non-interrupt timing and generating a timestamp of the system tick clock according to an embodiment of the present invention. As Figure 6 shown, the SysTimer_Start function calculates and sets the reload value of the system tick clock SysTick according to the incoming notification timing period us (this variable is in microseconds) and the clock frequency of the system, so as to ensure that the cycle time when each SysTick count is reduced to 0 and reloaded is exactly the set value us.

[0088] The WaitSysTimerEnd() function is used to wait for the end of the notification timing period. This function is implemented by querying whether the COUNTFLAG bit in the status register of SysTick is 1. In this example, bit 0 and bit 16 of SysTick->CTRL represent the start bit of the system tick timing and the COUNTFLAG bit respectively. After COUNTFLAG is read, it will be automatically cleared by the hardware.

[0089] For specific code implementation examples of the functions GetTicksNow and Calc_dSysTimeToNow_us, refer to Figure 3 As shown, by calling the function GetTicksNow(&stTime) at the start time of waiting and using the code while(Calc_dSysTimeToNow_us(&stTime)<WAIT_ACC1TX_US){} during the loop waiting, it is possible to generate a specified waiting time in a non-interrupt manner using the same SysTick as the notification timing. The reason for not using the interrupt timing method here is intentional because the data reception of each serial port is received in the idle interrupt in DMA mode, and the main thread indeed needs to wait for a specified time in a polling manner. Figure 6 The function GetTime_us shown provides a method of using SysTick to generate a timestamp of the current moment. The timestamp generated by this example function is in microseconds.

[0090] The packetization timestamp of the circular queue element is calculated from the system tick clock count value read during packetization and the reload count. That is, the calculation method of the packetization timestamp time_us is:

[0091] time_us = [loadCnt+(load+1-val) / (load+1)] * TRIG_PERIOD, where TRIG_PERIOD is the notification period of the server, loadCnt is the reload count during packetization, and load is the reload count value of the system tick clock.

[0092] Therefore, under the premise of only using the non-interrupt timing method of the same system tick clock SysTick, this solution provides a trigger interrupt to notify the controlled device to generate an accurate timing period, can generate a precise timestamp during packetization, and ensures the real-time and periodicity of the collected data received in summary.

[0093] Next, in step S530, after receiving the data sent by the controlled device from the transmission stream of the DMA channel corresponding to each serial port, it enters the corresponding receive idle interrupt handling function. In the interrupt handling function, the received data is parsed, and the parsed data is stored in the circular queue.

[0094] Specifically, after the server device completes the handshake synchronization with each controlled device, a DMA receive buffer is set for each serial port, DMA reception is enabled, and the specified receive start address is set to the start address of the DMA receive buffer, and the specified receive length is set to the buffer length size.

[0095] When a serial port receive idle interrupt occurs, the reception of the DMA channel of the serial port is stopped, and the actual received data length is calculated based on the remaining length of the buffer and the total length of the buffer. That is, when the server enters the serial port receive idle interrupt handling function, it immediately stops the reception of the DMA channel of the serial port, and then calculates the amount of data actually received through the serial port this time rxLen = size - remain based on the remaining length remain of the receive transmission stream of the DMA channel and the specified receive length size.

[0096] The transmission stream with a length equal to the actual received data length in the DMA receive buffer is parsed according to a predetermined format and saved in a global variable. The transmission stream with a length of rxLen in the DMA receive buffer can be parsed into the collected data according to the data format agreed with the controlled device from left to right and saved in the global variable.

[0097] DMA reception is enabled again, and the start address and specified receive length of the DMA receive buffer are reconfigured to continue receiving subsequent data. The specified receive length is greater than the maximum length of a single packet received from the serial port. Further, the specified receive length should be much greater than the maximum length of a single packet expected to be received.

[0098] In an embodiment of the present invention, when parsing the transmission stream with a length equal to the actual received data length in the DMA receive buffer during the serial port receive idle interrupt, if errors such as missing cache packet format and missing packet length are detected, the data for which the parsing fails is discarded and the next DMA reception is directly enabled. This can effectively handle errors in the received packet format and length and ensure that the system can continuously receive valid data.

[0099] The length of a single packet in the single receive cache in the DMA buffer is calculated based on the remaining length of the transmission stream of the DMA channel. After unpacking, DMA reception is enabled again, which not only avoids the problem of received packet sticking, improves the unpacking efficiency, but also reduces the CPU occupancy time during data transmission.

[0100] Figure 7Shows a code example of the serial port receive idle interrupt handling function according to an embodiment of the present invention. As Figure 7 shown, HAL_UARTEx_RxEventCallback is the serial port receive idle interrupt handling function, Figure 7 wherein devNO in it is the number of the controlled device, and an information handle gszhDev[devNO] is created for each controlled device respectively. When the server enters the serial port receive idle interrupt handling function, it first immediately stops the reception of the DMA channel of this serial port, and then calculates the actual data volume rxLen = size - remain received through the serial port this time according to the remaining length remain of the received transmission stream of this DMA channel and the specified reception length size. The transmission stream with a length of rxLen in the DMA receive buffer is parsed into the collected data from left to right according to the data format agreed with the controlled device and saved to the global variable, and then the DMA reception is enabled again and the specified reception start address is set to the start address of the DMA receive buffer, and the specified reception length is set to the buffer length size, where the specified reception length size should be much larger than the maximum length of a single packet that may be received from the serial port.

[0101] If the specified reception length size is large enough, theoretically it is impossible for this round of DMA to receive all the data with a length of size, and it will enter the serial port receive idle interrupt to stop the DMA reception, and start the next round of DMA reception after unpacking. Therefore, theoretically, even if the DMA reception completion interrupt is not implemented, it does not affect the implementation of the present invention. However, in order to prevent the situation where the pre-set size is not large enough, this callback function is still implemented.

[0102] Finally, step S540 is executed, waiting for a specified time in each timing cycle, aggregating and calculating the data collected by each controlled device received, and sending the calculation result to the client upper computer through the serial port in the DMA mode.

[0103] Among them, the specified time waited by the server in the timing cycle is the notification cycle time minus the maximum estimated time required to receive, aggregate and calculate the data collected by each serial port, that is, the specified time waited is less than the notification cycle.

[0104] Wait for a specified time within this timing cycle, specifically including: immediately read SysTick after the server notifies the controlled device by triggering a GPIO interrupt, and create local variables to save the tick count value val1 of SysTick and the reload count loadCnt1 of SysTick. Then, repeatedly read the tick count value val2 of SysTick at the current moment and the reload count loadCnt2 of SysTick until it is calculated that the time interval dTime between the current moment and the notification moment is greater than or equal to the specified waiting time. Among them, the specified waiting time is the cycle notification time minus the maximum estimated time required to receive, summarize, and calculate the data collected by each serial port. The time interval dTime between the current moment and the notification moment is:

[0105] dTime = [(val1 - val2) / (load + 1)+loadCnt2 - loadCnt1]*TRIG_PERIOD, where load is the reload count value, TRIG_PERIOD is the notification period of the server, val1 is the initial tick count value of the system tick clock, val2 is the current tick count value of the system tick clock, loadCnt1 is the initial reload count, and loadCnt2 is the current reload count.

[0106] The circular queue is a first-in-first-out data structure. When writing to the queue, the queue element is inserted into the queue space indicated by the tail position serial number, and the tail position serial number is updated to WrId = (WrId + 1)%MAX. When reading the queue, start reading from the queue element indicated by the head position serial number and update the head position serial number to RdId = (RdId + 1)%MAX, where MAX is the maximum number of queue elements that the circular queue can accommodate;

[0107] When the main thread has not received all the data collected by the controlled devices after waiting for the specified time within this timing cycle, then find the queue element saved by summarizing and calculating in the previous timing cycle through the tail position serial number. The packet ID of the queue element sent to the client host computer through the serial port in each timing cycle is always equal to the head position serial number RdId, so as to ensure that the client host computer checks whether there is packet loss during the transmission process by checking whether the received packet IDs are continuous.

[0108] By using a circular queue to cache the calculation results and using the head position ID as the packet ID for sending, when all the collected data has not been received after the timeout, the last packet sent recently can be quickly found, and the data valid flag bit is cleared and then sent to the client host computer, which not only ensures the continuity of the graphical display of the client host computer but also facilitates the client host computer to quickly identify errors such as packet loss during transmission and failure to receive the data collected by a certain controlled device.

[0109] In summary, the multi-machine communication data processing method and multi-machine communication system based on serial ports provided by the present invention can at least achieve the following beneficial effects:

[0110] (1) Binding the Tx and Rx channels of each serial port to a transmission stream of a unique DMA channel respectively ensures the independence of each serial port data channel and improves the serial port data transmission efficiency;

[0111] (2) Registering receive idle interrupts for each serial port respectively, calculating the single-packet length of the single receive buffer in the DMA buffer through the remaining length of the DMA channel transmission stream in the receive idle interrupt handling function, and restarting the DMA receive after unpacking, avoiding the problem of receive packet sticking, improving the unpacking efficiency, and reducing the CPU occupation time during data transmission;

[0112] (3) On the premise of only using the non-interrupt timing method of the same system tick clock SysTick, a method for generating an accurate timing period to trigger an interrupt to notify the controlled device, a method for generating a fixed timeout specified time for waiting for packet reception within the timing period, and a method for generating an accurate timestamp during packet assembly and sending are provided, ensuring the real-time and periodicity of the collected data received in a centralized manner;

[0113] (4) Using the queue head position ID of the circular queue as the packet ID, when all the collected data is not received within the timeout, the last packet sent recently can be quickly found from the circular queue, the data valid flag bit is cleared, and then sent to the client upper computer, ensuring the continuity of the graphical display of the client upper computer and facilitating the client to quickly identify the errors of lost packets and uncollected data.

[0114] Therefore, this solution can periodically notify the controlled device to collect data or signals, receive the data sent by multiple controlled devices through serial ports in real time, and quickly and accurately summarize, calculate and process the data and send it to the client upper computer, solving the performance problem of multi-machine communication using serial ports.

[0115] In the specification provided here, a large number of specific details are described. However, it can be understood that the embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and technologies are not shown in detail so as not to obscure the understanding of this specification.

[0116] Similarly, it should be understood that, for the purpose of streamlining the present disclosure and aiding in the understanding of one or more of the various inventive aspects, in the foregoing description of the exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together in a single embodiment, figure, or description thereof. However, the disclosed method should not be construed as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as reflected in the following claims, the inventive aspects lie in less than all of the features of the single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into the detailed description, with each claim standing on its own as a separate embodiment of the present invention.

[0117] Those skilled in the art should understand that the modules or units or components of the devices in the examples disclosed herein may be arranged in the devices as described in the embodiments, or alternatively may be located in one or more devices different from the devices in the examples. The modules in the foregoing examples may be combined into one module or further divided into multiple sub-modules.

[0118] Those skilled in the art can understand that the modules in the devices of the embodiments can be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments can be combined into one module or unit or component, and further can be divided into multiple sub-modules or sub-units or sub-components. Except that at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all the features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all the processes or units of any method or device so disclosed. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) can be replaced by an alternative feature that provides the same, equivalent, or similar purpose.

[0119] In addition, those skilled in the art can understand that, although some of the embodiments described herein include certain features included in other embodiments rather than other features, the combination of the features of different embodiments means that it is within the scope of the present invention and forms different embodiments. For example, in the following claims, any one of the claimed embodiments can be used in any combination.

[0120] In addition, some of the embodiments herein are described as methods or combinations of method elements that can be implemented by a processor of a computer system or by other devices performing functions. Therefore, a processor having the necessary instructions for implementing the method or method element forms an apparatus for implementing the method or method element. In addition, the elements described herein of the apparatus embodiments are examples of such apparatus: the apparatus for implementing the functions performed by the elements for the purpose of implementing the invention.

[0121] As used herein, unless otherwise specified, the use of ordinal numbers such as "first", "second", "third", etc. to describe ordinary objects only indicates different instances of similar objects and is not intended to imply that the objects so described must have a given order in terms of time, space, ranking, or in any other way.

[0122] Although the invention has been described in terms of a limited number of embodiments, those skilled in the art in this technical field will appreciate, from the foregoing description, that other embodiments can be contemplated within the scope of the invention as thus described. In addition, it should be noted that the language used in this specification has been principally selected for readability and instructional purposes and not for the purpose of explaining or limiting the subject matter of the invention. Thus, many modifications and variations will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the appended claims. For the scope of the invention, the disclosure of the invention is illustrative and not restrictive, and the scope of the invention is defined by the appended claims.

Claims

1. A multi-machine communication data processing method based on serial port, implemented based on a server device, wherein the server device communicates with a client host computer and one or more controlled devices through a serial port respectively, and the server device is used to periodically send pulses to trigger the one or more controlled devices to send collected data, and summarize and calculate the data received from the controlled devices in each cycle and then send them to the client host computer, characterized in that: The method comprises: The server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a transmission stream of a unique DMA channel, registering a receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, wherein the queue elements of the circular queue at least include the packet ID, the packet grouping timestamp, the calculation results and the valid flag of the collected data of each controlled device; Starting the system tick clock to perform periodic timing, sending the pulse or triggering an interrupt at the beginning of each timing cycle to notify each controlled device to start sending data; After receiving the data sent by the controlled device from the transmission stream of the DMA channel corresponding to each serial port, the corresponding receiving idle interrupt processing function is entered, the received data is parsed in the interrupt processing function, and the parsed data is stored in the ring queue; After waiting for a specified time in each timing cycle, the data collected by each controlled device is summarized and processed, and the calculation results are sent to the client host computer through the serial port in DMA mode; The step of starting the system tick clock to perform periodic timing and sending the pulse or triggering an interrupt to notify each controlled device to start sending data at the beginning of each timing cycle includes: Set the reload value of the system tick clock according to the system tick clock frequency, so that the reload cycle time of each round of the system tick clock is equal to the periodic notification time required by the server; The counter value of the system tick clock is cleared to zero and the system tick clock timer is started. The status register of the system tick clock is read repeatedly until the value of the reload flag bit COUNTFLAG in the status register of the system tick clock is 1. The count value of the system tick clock counter is cleared to zero and a pulse is sent to each controlled device to trigger a GPIO interrupt to notify each controlled device to send data. The COUNTFLAG flag bit is automatically set to 1 by hardware when the count value decreases to 0, and the COUNTFLAG flag bit is automatically cleared to zero by hardware when it is read; The packet assembly timestamp of the queue element is calculated by the system tick clock count value and the number of reloads read during packet assembly. The calculation method of the packet assembly timestamp is: time_us = [loadCnt+(load+1-val) / (load+1)] * TRIG_PERIOD, where time_us is the packet assembly timestamp, TRIG_PERIOD is the notification period of the server, loadCnt is the number of reloads during packet assembly, and load is the reload count value of the system tick clock.

2. The method for processing multi-machine communication data based on serial port according to claim 1, characterized in that: The steps of handshake synchronization include: After the controlled device is powered on and initialized, the agreed value is written to the specified register; After the server device is powered on and initialized, it cyclically reads the designated register until the agreed value is read out, and the server device shakes hands with the controlled device successfully. When the server device shakes hands with all controlled devices successfully, the handshake synchronization is completed.

3. The method for processing multi-machine communication data based on serial port according to claim 1, characterized in that: The step of parsing the received data in the interrupt processing function and storing the parsed data in the ring queue comprises: After the server device completes handshake synchronization with each controlled device, set up a DMA receive buffer for each serial port, start DMA reception, and specify the receiving first address as the DMA receive buffer first address and the receiving length as the buffer length; When the serial port receives an idle interrupt, the reception of the transmission stream of the serial port DMA channel is stopped, and the actual received data length rxLen of the serial port is calculated according to the specified receiving length size and the number of data units remaining in this DMA stream transmission HAL_DMA_GET_COUNTER, where rxLen=size-HAL_DMA_GET_COUNTER; Parse the data stream with the length rxLen starting from the first address of the DMA receiving buffer according to the protocol format predetermined with the sender, and save the parsing result to the global variable; The DMA receiving is enabled again, and the first address and the designated receiving length of the DMA receiving buffer are reconfigured to continue receiving subsequent data, wherein the designated receiving length is greater than the estimated maximum length of a single packet received from the serial port.

4. The method for processing multi-machine communication data based on serial port according to claim 3, characterized in that: When the serial port receiving idle interrupt receives and parses the transmission stream received in this DMA receiving buffer with a length equal to the actual received data length, if errors such as missing cache packet format and missing packet length are detected, the data whose parsing failed is abandoned and the next DMA reception is directly started.

5. The method for processing multi-machine communication data based on serial port according to claim 1, characterized in that: The steps of waiting for a specified time in each timing cycle, summarizing and calculating the data collected by each controlled device, and sending the calculation results to the client host computer through the serial port in DMA mode include: Wait for a specified time in this round of timing cycle. If the data sent by all controlled devices are successfully received and parsed within the specified time, the data collected by each controlled device is summarized and calculated and processed to generate a new queue element to be inserted into the circular queue. The head element of the circular queue is sent to the client host computer through the serial port in DMA mode. The queue element contains the packet ID, the packet group timestamp, the data calculation result and the valid flag bit of the data collected by the controlled device; If the data collected by all controlled devices are not received within the specified time, a new queue element is generated and inserted into the tail of the ring queue. The member values ​​of the new queue element are the same as those of the previous queue element. The valid flag of the collected data of the controlled device that has not received the data is cleared to zero, and the package ID is updated. The head element of the ring queue is sent to the client host computer through the serial port in DMA mode; Wait for the timing cycle to end and continue to receive and process data in the next timing cycle.

6. The method for processing multi-machine communication data based on serial ports according to claim 5, characterized in that: The step of waiting for a specified time in each timing cycle includes: On the server side, trigger a GPIO interrupt, notify the controlled device, and immediately read the system tick clock and create a local variable to save the initial count value of the system tick clock and the initial reload times; Repeatedly read the current count value of the system tick clock and the current reload count until the calculated time interval between the current moment and the notification moment is greater than or equal to the waiting specified time, wherein the waiting specified time is the periodic notification time minus the maximum estimated time required to receive, summarize and calculate and process the collected data of each serial port, and the time interval between the current moment and the notification moment is: dTime=[(val1-val2) / (load+1)+ loadCnt2-loadCnt1] * TRIG_PERIOD, where load is the reload count value, TRIG_PERIOD is the notification period of the server, val1 is the initial count value of the system tick clock, val2 is the current count value of the system tick clock, loadCnt1 is the initial reload count, and loadCnt2 is the current reload count.

7. The method for processing multi-machine communication data based on serial ports according to claim 1, characterized in that: The circular queue is a first-in-first-out data structure. When writing to the queue, the queue element is inserted into the queue space indicated by the tail position number and the tail position number is updated to WrId = (WrId +1) % MAX. When reading the queue, the queue element indicated by the head position number is read and the head position number is updated to RdId = (RdId +1) % MAX, where MAX is the maximum number of queue elements that the circular queue can accommodate. When the main thread has waited for the specified time within the current timing cycle and still has not received the data collected by all controlled devices, the queue element saved by the summary calculation of the previous timing cycle is found through the queue tail position number. The packet ID of the queue element sent to the client host computer through the serial port in each timing cycle is always equal to the queue head position number.

8. A multi-machine communication system based on serial port, characterized in that: A multi-stage communication data processing method comprising any one of claims 1 to 7, further comprising: a client host computer, a server device, a plurality of controlled devices, and a UART interface for multi-machine communication; The client host computer runs a user interface program for graphically displaying the data or signals after the summary calculation and processing; The controlled device is an embedded computer or a device for collecting data or signals. The controlled device has a serial port, which is used to collect data in real time and send it to the server device through the serial port after receiving a notification from the server device; The server device is provided with multiple serial ports, each of which is used to communicate with the client host computer or a unique controlled device. The server device runs server software, which is used to periodically send pulses to trigger one or more controlled devices to send real-time collected data, and summarize and calculate the data received from the controlled devices in each cycle and send them to the client host computer, specifically including: The server device and each controlled device perform power-on initialization and handshake synchronization, wherein the power-on initialization includes: configuring the period of the system tick clock and the DMA channel corresponding to each serial port, so that the sending channel and the receiving channel of each serial port are respectively bound to a unique DMA channel, registering a receiving idle interrupt for each serial port, and creating a circular queue for storing the calculation results of the collected data of the controlled devices received after the summary processing in each cycle, wherein the queue elements of the circular queue at least include the packet ID, the packet grouping timestamp, the calculation results and the valid flag of the collected data of each controlled device; waiting for all controlled devices to be successfully powered on and initialized before the handshake is completed; Starting the system tick clock to perform periodic timing, sending the pulse or triggering an interrupt at the beginning of each timing cycle to notify each controlled device to start sending data; After receiving the data sent by the controlled device from the DMA channel corresponding to each serial port, the corresponding receiving idle interrupt processing function is entered, the received data is parsed in the interrupt processing function, and the parsed data is stored in the ring queue; After waiting for a specified time in each timing cycle, the data collected by each controlled device is summarized and processed, and the calculation results are sent to the client host computer through the serial port in DMA mode.

Citation Information

Patent Citations

  • Data bus bridge and its working method

    CN101018179A

  • Multi-channel HDLC control system and data uploading method and data issuing method thereof

    CN116847007A