A method, system, and medium for dynamic parsing and fault tolerance of multiple serial ports and multiple protocols.

By establishing a dynamic binding relationship between physical serial ports and protocol types in the microcontroller, using a circular buffer and state machine for frame parsing, and independently maintaining the protocol context, the problems of high interrupt load and data loss in multi-serial-port multi-protocol communication are solved, achieving efficient data parsing and anomaly recovery.

CN123123479APending Publication Date: 2026-11-17CHENGDUSCEON TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611245656.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-17
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing microcontrollers suffer from high interrupt handling load, severe multi-protocol coupling, and difficulty in expansion in multi-serial communication, and are prone to losing valid data in case of data anomalies.

Method used

By establishing a dynamic binding relationship between physical serial ports and protocol types, using a circular buffer and state machine for frame parsing, independently maintaining the protocol parsing context, and performing rollback processing in abnormal situations, interrupt services and protocol parsing tasks are separated.

Benefits of technology

It reduces interrupt handling load, improves system stability and data parsing continuity, adapts to multi-protocol communication scenarios, and reduces the risk of data loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123479A_ABST
    Figure CN123123479A_ABST
Patent Text Reader

Abstract

This invention discloses a multi-serial-port, multi-protocol dynamic parsing fault-tolerant method, system, and medium, relating to the field of embedded communication data processing technology. The method includes: acquiring serial port data and writing it to a corresponding circular buffer; establishing a dynamic protocol parsing mapping relationship based on physical serial port identifiers and protocol type identifiers, creating an independent protocol parsing context for each physical serial port and protocol type combination; reading serial port data from the circular buffer and performing parsing according to a state machine; when an anomaly is detected, performing a rollback process on the current protocol parsing context and re-identifying the frame; after completing data frame parsing, distributing service data according to the mapping relationship between frame identifiers and service processing functions. This invention achieves flexible configuration, reliable parsing, and anomaly recovery in multi-serial-port, multi-protocol communication processes of microcontrollers, improving the real-time performance, scalability, and stability of embedded communication systems.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of embedded communication data processing technology, specifically to a multi-serial-port multi-protocol dynamic parsing fault-tolerant method, system, and medium. Background Technology

[0002] With the development of industrial control, smart terminals, and embedded devices, microcontrollers need to connect to multiple external devices simultaneously and interact with them. In practical applications, a single microcontroller is typically configured with multiple serial communication interfaces, such as multiple UART interfaces, to meet the data transmission needs between different devices. Furthermore, different external devices may use different data communication protocols, including binary frame protocols, ASCII protocols, and device manufacturer-defined protocols. Therefore, microcontrollers need to have the ability to receive, parse, and process data from multiple serial ports and multiple protocols in real time.

[0003] Existing multi-serial port communication solutions typically involve directly executing data parsing within the serial port interrupt routine, or developing separate parsing routines for different communication protocols. In these solutions, when the serial port data reception rate is high or the parsing process is complex, the interrupt handling process consumes significant processing resources, easily leading to untimely data reception and data loss. Furthermore, the protocol parsing logic is coupled with specific business processing logic; adding or modifying a protocol requires adjustments to the underlying program, resulting in low system scalability and maintenance efficiency.

[0004] Furthermore, during continuous data stream transmission, factors such as communication interference, data packet fragmentation, and data packet merging can lead to issues like abnormal frame headers or tails, incorrect frame lengths or content, or failed verification. Existing parsing methods typically recover from these anomalies by clearing the buffer or reinitializing the parsing state, which can easily result in the loss of subsequent valid data frames. This is especially problematic when a serial port supports multiple protocol types; improper handling of a single data packet can cause protocol parsing chaos or continuous packet loss, reducing the system's data processing reliability in complex communication environments.

[0005] Therefore, how to achieve flexible configuration and dynamic parsing of multi-serial-port and multi-protocol data in a resource-constrained microcontroller environment, while reducing interrupt handling load and improving parsing continuity and system reliability under abnormal data conditions, has become a technical problem that urgently needs to be solved in this field. Summary of the Invention

[0006] This invention aims to solve the problems of high interrupt handling load, severe coupling between multiple communication protocols, difficulty in protocol expansion and dynamic switching, and easy loss of subsequent valid data in the case of data packet merging, packet breakage or verification anomalies in the existing microcontroller multi-serial port communication process. It provides a multi-serial port multi-protocol dynamic parsing fault-tolerant method, system and medium to realize efficient data reception, independent parsing, anomaly recovery and reliable distribution of business data in multi-protocol communication scenarios.

[0007] This invention is achieved through the following technical solution:

[0008] A multi-serial-port, multi-protocol dynamic parsing fault-tolerant method includes:

[0009] Acquire serial data received from multiple physical serial ports and write the serial data received from each physical serial port into the corresponding circular buffer.

[0010] Establish a dynamic binding relationship between physical serial ports and protocol types, and construct a protocol parsing mapping table based on physical serial port identifiers and protocol type identifiers. The protocol parsing mapping table stores the protocol parsing function pointers corresponding to each protocol type.

[0011] According to the protocol parsing mapping table, a corresponding protocol parsing context is established for each combination of physical serial port and each protocol type. The protocol parsing context includes at least a data buffer, status information for recording the current protocol parsing status, the length of data received in the buffer, and the length of parsed data in the buffer.

[0012] Serial port data is read from the circular buffer corresponding to each physical serial port, and the serial port data is input into the protocol parsing context of the corresponding protocol type for frame parsing according to the dynamic binding relationship.

[0013] In the protocol parsing context, the serial port data is analyzed based on a state machine to identify the frame header, frame tail, frame type, and verification information, thereby obtaining the parsing result.

[0014] When the parsing result indicates that the current frame data to be parsed is abnormal or the verification fails, a rollback process is performed on the data to be parsed in the current protocol parsing context, and the data after the start position of the current candidate frame is used as the new search starting point to re-identify the frame header.

[0015] When the complete data frame parsing is completed, the frame identifier and frame length in the complete data frame are extracted, and the parsed data is sent to the corresponding business processing function for processing according to the preset mapping relationship between the frame identifier, frame length and business processing function.

[0016] Furthermore, the acquisition of serial port data received from multiple physical serial ports includes:

[0017] The serial port interrupt service routine only performs hardware data register read operations, data write to the circular buffer operations, and write position update operations.

[0018] The serial port interrupt service routine does not perform protocol parsing, state machine transitions, or business processing operations.

[0019] Furthermore, the circular buffer includes a data buffer area, a write pointer, and a read pointer, each corresponding to a physical serial port;

[0020] The write pointer records the position where data is written by the serial port interrupt, the read pointer records the position where data is read by the protocol parsing task, and the amount of data to be parsed is determined based on the positional relationship between the write pointer and the read pointer.

[0021] Furthermore, the protocol parsing mapping table is a two-dimensional mapping table;

[0022] The two-dimensional mapping table uses the physical serial port identifier as the first dimension index and the protocol type identifier as the second dimension index, and configures the protocol parsing function supported by the current serial port through the corresponding table entries;

[0023] By modifying the entries in the two-dimensional mapping table, the protocol type of the corresponding physical serial port can be added, deleted, or switched.

[0024] Furthermore, the protocol parsing context is established according to the combination of physical serial port and protocol type;

[0025] Independent parsing status information is maintained between different physical serial ports and between different protocol types corresponding to the same physical serial port, so that abnormal states in the parsing context of any protocol do not affect the parsing context of other protocols.

[0026] Furthermore, the state machine includes a frame header search state, a frame tail search length detection state, a data content parsing state, and a verification state.

[0027] When the state machine finds the corresponding content in the state, it automatically sets the state machine to the next search state;

[0028] When the verification state detects an abnormal length, an incorrect checksum, or an abnormal frame tail, invalid data corresponding to the start position of the current candidate frame is deleted, subsequent unparsed data is retained, and the current protocol parsing context is switched to the re-search frame header state.

[0029] Furthermore, the mapping relationship between the frame identifier and the service processing function includes at least the frame identifier, the service processing function, and the corresponding data length information;

[0030] After completing the data frame parsing, the corresponding service processing function is queried based on the frame identifier, and the parsed payload is sent to the service processing function.

[0031] Furthermore, the operating system generates a task scheduling signal based on the preset priority level of the task. The task scheduling signal is used to control the execution cycle of the protocol parsing task and avoid the protocol parsing task occupying processing resources for a long time.

[0032] When the serial port parsing task is triggered and there is cached data in the corresponding serial port buffer, the protocol parsing task is triggered to perform data reading, protocol parsing, and business routing processing.

[0033] When sending business data, the data to be sent is written into the sending buffer and the data is sent in a non-blocking manner.

[0034] This invention also provides a multi-serial-port multi-protocol dynamic parsing fault-tolerant system, comprising:

[0035] The data receiving module is used to acquire serial port data received from multiple physical serial ports and write the serial port data into the corresponding circular buffer.

[0036] The dynamic binding module is used to establish a protocol parsing mapping table based on the physical serial port identifier and the protocol type identifier, and to determine the corresponding protocol parsing function based on the protocol parsing mapping table;

[0037] The context management module is used to establish an independent protocol parsing context and state machine for each physical serial port and protocol type combination. This management module can retain the protocol parsing state of the current protocol type when the task is switched, and continue execution in the next execution.

[0038] The protocol parsing module is used to process the serial port data read by the serial port task in the circular buffer, and to set the protocol parsing context and state machine state in the context management module based on the state machine state.

[0039] The fault tolerance module is used to perform a rollback to the current protocol parsing context when protocol parsing fails.

[0040] The routing and distribution module is used to call the corresponding business processing function based on the frame identifier obtained through parsing.

[0041] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the multi-serial-port multi-protocol dynamic parsing fault-tolerant method as described above.

[0042] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the multi-serial-port multi-protocol dynamic parsing fault-tolerant method as described above.

[0043] Compared with the prior art, the present invention has the following advantages and beneficial effects:

[0044] This invention separates the serial port interrupt service routine from the protocol parsing process. The interrupt service routine only performs serial port data reading, circular buffer writing, and pointer update operations, transferring the time-consuming data parsing task to an independent parsing task. This reduces interrupt time and lowers the risk of data reception anomalies caused by interrupt handling blockage. A dynamic protocol parsing mapping relationship is constructed based on the physical serial port identifier and the protocol type identifier, decoupling the physical serial port from the specific protocol parsing logic. Protocol types can be added, deleted, or switched by adjusting the protocol parsing mapping relationship without modifying the underlying serial port driver, adapting to multi-device, multi-protocol communication scenarios.

[0045] This invention establishes independent protocol parsing contexts for different combinations of physical serial ports and protocol types, enabling different serial ports and different protocol parsing processes on the same serial port to maintain independent state information. When an anomaly occurs during the parsing process of a certain protocol type, only the parsing context corresponding to the current serial port is affected, without affecting the parsing processes of other protocol types, thereby improving the overall stability of the system. When data frame parsing fails, instead of clearing the entire buffer or resetting the entire parsing state, a rollback process is performed in the current protocol parsing context, and frame header identification is re-performed based on a new search starting point, allowing subsequent valid data frames to continue to be detected and parsed. This improves the system's adaptability to communication anomalies such as packet fragmentation, packet breakage, and verification failures.

[0046] This invention extracts the frame identifier and frame length from the complete data frame and distributes services based on the mapping relationship between the frame identifier and the service processing function. This allows the protocol parsing module to be only responsible for data frame identification and data extraction, while the service processing module independently completes the specific business logic processing. This is beneficial for improving the modularity of the software and the ability to expand its functions in the future. Attached Figure Description

[0047] To more clearly illustrate the technical solutions of the exemplary embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly described below. It should be understood that the following drawings only show some embodiments of the present invention and should not be considered as a limitation of the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort. In the drawings:

[0048] Figure 1This is a schematic diagram of the overall framework of a multi-serial-port, multi-protocol dynamic parsing fault-tolerant system.

[0049] Figure 2 Diagram illustrating the working principle of interrupt isolation and circular buffer;

[0050] Figure 3 A diagram showing the structure of a binding mapping table for dynamic protocols;

[0051] Figure 4 A flowchart for analyzing the rollback state machine;

[0052] Figure 5 This is a schematic diagram of a two-layer routing distribution. Detailed Implementation

[0053] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the embodiments and accompanying drawings. The illustrative embodiments and descriptions of the present invention are only used to explain the present invention and are not intended to limit the present invention.

[0054] Example 1

[0055] This embodiment uses a microcontroller-based multi-serial communication system as an example for illustration. Figure 1 As shown, the system includes a microcontroller, multiple serial port peripherals, a memory, an interrupt handling module, and a software parsing module. The microcontroller connects to multiple external devices via multiple UART serial ports, with different external devices using different communication protocols for data exchange. The serial port receive interrupt module in the microcontroller receives data from each UART interface, and the software parsing module performs multi-protocol data parsing and service distribution. In this embodiment, the microcontroller can be a CS32F407 series microcontroller, but is not limited to this.

[0056] A multi-serial-port, multi-protocol dynamic parsing fault-tolerant method includes the following steps:

[0057] Acquire serial data received from multiple physical serial ports and write the serial data received from each physical serial port into the corresponding circular buffer.

[0058] Establish a dynamic binding relationship between physical serial ports and protocol types, and construct a protocol parsing mapping table based on physical serial port identifiers and protocol type identifiers. The protocol parsing mapping table stores the protocol parsing function pointers corresponding to each protocol type.

[0059] According to the protocol parsing mapping table, a corresponding protocol parsing context is established for each combination of physical serial port and each protocol type. The protocol parsing context includes at least a data buffer, status information for recording the current protocol parsing status, the length of data received in the buffer, and the length of parsed data in the buffer.

[0060] Serial port data is read from the circular buffer corresponding to each physical serial port, and the serial port data is input into the protocol parsing context of the corresponding protocol type for frame parsing according to the dynamic binding relationship.

[0061] In the protocol parsing context, the serial port data is analyzed based on a state machine to identify the frame header, frame tail, frame type, and verification information, thereby obtaining the parsing result.

[0062] When the parsing result indicates that the current frame data to be parsed is abnormal or the verification fails, a rollback process is performed on the data to be parsed in the current protocol parsing context, and the data after the start position of the current candidate frame is used as the new search starting point to re-identify the frame header.

[0063] When the complete data frame parsing is completed, the frame identifier and frame length in the complete data frame are extracted, and the parsed data is sent to the corresponding business processing function for processing according to the preset mapping relationship between the frame identifier, frame length and business processing function.

[0064] like Figure 1 As shown, the physical foundation of the entire system is the hardware layer. External data first enters the system through the UART serial port peripheral, while SRAM memory provides temporary storage space for the data. The TIM3 timer runs continuously as the system time base, and the NVIC interrupt controller manages various interrupt requests to achieve hardware event response control.

[0065] When data is received via the serial port, the USARTn_IRQHandler interrupt service routine in the interrupt layer is triggered. It reads the raw bytes from the serial peripheral's data receive register by calling USART_ReceiveData, then calls UART_SaveData to store the data in the buffer sio_recvr_fifo, and finally exits the interrupt routine to reduce interrupt latency. Simultaneously, the TIM3_IRQHandler interrupt periodically executes Cur1msCnt++ to maintain the system time counter, providing a time base for system time management and periodic task processing. Different UART interfaces correspond to independent data buffer areas to avoid data interference between different communication channels.

[0066] In the layered software architecture, multiple receiving tasks (tsk_Port1_Recvr to tsk_Portn_Recvr) in the task scheduling layer extract data from the sio_recvr_fifo of their respective serial ports and pass it to the dynamic binding layer. The data is then distributed to the corresponding processing functions according to a preset mapping relationship and managed within an independent context (raw_t). Subsequently, the data enters the parsing and routing layer via the raw_t. An outer state machine performs frame header identification, frame length determination, frame tail detection, and frame verification to determine the complete data frame. When an abnormal frame is detected, a rollback process is used to re-identify the frame, reducing the risk of data loss due to abnormal data. After the complete data frame is extracted, the inner routing logic selects the corresponding business processing path based on information such as the frame ID, and finally distributes the parsing result to the specific business module in the business application layer for processing.

[0067] In this embodiment, acquiring serial port data received from multiple physical serial ports includes:

[0068] The serial port interrupt service routine only performs hardware data register read operations, data write to the circular buffer operations, and write position update operations.

[0069] The serial port interrupt service routine does not perform protocol parsing (state machine transition, intelligent rollback) or business processing operations.

[0070] In this embodiment, the circular buffer includes a data buffer area, a write pointer, and a read pointer that are set one-to-one with each physical serial port. The buffer area is defined by macros and the capacity is allocated according to the data throughput and the memory size of the microcontroller chip. In this example, the buffer size of each serial port is configured to be 1024 bytes.

[0071] In one specific implementation, the read pointer and write pointer are implemented using 32-bit integer variables to record the data read and write positions in the circular buffer.

[0072] The write pointer records the position where data is written by the serial port interrupt, the read pointer records the position where data is read by the protocol parsing task, and the amount of data to be parsed is determined based on the positional relationship between the write pointer and the read pointer.

[0073] Specifically, such as Figure 2 As shown, each UART interface is configured with a corresponding receive buffer, sio_recv_fifo. The serial port interrupt routine writes the received data into the buffer using the write pointer ptr_write and performs pointer wrap-around when the end of the buffer is reached. The protocol parsing task reads the buffered data using the read pointer ptr_read and determines whether there is data to be parsed in the current buffer based on the positional relationship between the read and write pointers.

[0074] When data to be parsed is detected, the parsing task reads the corresponding data and sends the read data to the dynamic binding layer for protocol matching.

[0075] In this embodiment, the protocol parsing mapping table is a two-dimensional mapping table;

[0076] The two-dimensional mapping table uses the physical serial port identifier as the first dimension index and the protocol type identifier as the second dimension index, and configures the protocol parsing function supported by the current serial port through the corresponding table entries;

[0077] By modifying the entries in the two-dimensional mapping table, the protocol type of the corresponding physical serial port can be added, deleted, or switched. For example, when a protocol configuration command is received during device operation, the mapping relationship between the corresponding physical serial port and the protocol type is modified according to the configuration command, thereby adding, deleting, or switching the protocol parsing function.

[0078] In this embodiment, the protocol parsing context is established according to the combination of physical serial port and protocol type;

[0079] Independent parsing status information is maintained between different physical serial ports and between different protocol types corresponding to the same physical serial port, so that abnormal states in the parsing context of any protocol do not affect the parsing context of other protocols.

[0080] Specifically, such as Figure 3 As shown, the system establishes a two-dimensional protocol parsing mapping table DealSerialPort[port][n], where the first dimension represents the physical serial port number and the second dimension represents the protocol type number. Each entry stores a pointer to the corresponding protocol parsing function. When a new protocol needs to be added to a serial port, the corresponding protocol parsing function pointer is written to the target entry; when a protocol needs to be closed, the corresponding entry is set to null.

[0081] In one specific implementation, when the device enters a specific communication mode, the unbinding of irrelevant protocol parsing relationships can be performed according to configuration requirements to avoid the processing of irrelevant protocols affecting the current communication process.

[0082] During the data parsing process, the system queries the corresponding table entry based on the current serial port number and protocol type number. When a valid parsing function exists in the table entry, the corresponding parsing function is called to execute the data parsing.

[0083] In this embodiment, the state machine includes a frame header search state, a frame tail search length detection state, a data content parsing state, and a verification state.

[0084] When the state machine finds the corresponding content in the state, it automatically sets the state machine to the next search state;

[0085] When the verification state detects an abnormal length, an incorrect checksum, or an abnormal frame tail, invalid data corresponding to the start position of the current candidate frame is deleted, subsequent unparsed data is retained, and the current protocol parsing context is switched to the re-search frame header state.

[0086] like Figure 4 As shown, when the received data enters the parsing buffer, the parsing task first determines whether the buffered data is complete; if the complete data reception is not completed, it continues to wait for subsequent data; if a frame header is detected, the current frame header position is recorded, and the frame tail and data integrity are further determined.

[0087] When a verification failure, abnormal frame length, or frame tail error is detected during frame parsing, the entire cached data is not cleared. Instead, the starting data corresponding to the current candidate frame is deleted, and the subsequent data is used as the data to be detected for frame header search.

[0088] By using the above method, we can avoid the inability to parse subsequent consecutive valid data frames due to a single abnormal frame.

[0089] In this embodiment, the mapping relationship between the frame identifier and the service processing function includes at least the frame identifier, the service processing function, and the corresponding data length information;

[0090] After completing the data frame parsing, the corresponding service processing function is queried according to the frame identifier. If the frame length identifier is -1, indicating variable length, the frame length is not judged. The parsed payload is sent to the service processing function only if the frame ID and protocol frame length are consistent with the frame ID and frame length required by the protocol frame. Otherwise, it is discarded.

[0091] like Figure 5 As shown, the parsing layer first performs integrity checks on the received data frames, including checksum verification, frame ID identification, and frame length determination. If the data frame meets the parsing conditions, the parsed valid data is sent to the business layer; if any condition is not met, an exception handling process is returned.

[0092] In this embodiment, the operating system generates a task scheduling signal based on the preset priority level of the task. The task scheduling signal is used to control the execution cycle of the protocol parsing task and avoid the protocol parsing task occupying processing resources for a long time.

[0093] When the serial port parsing task is triggered and there is cached data in the corresponding serial port buffer, the protocol parsing task is triggered to perform data reading, protocol parsing, and business routing processing.

[0094] When sending business data, the data to be sent is written into the sending buffer and the data is sent in a non-blocking manner.

[0095] In one implementation, UART1 connects to device A and uses protocol A; UART2 connects to device B and uses protocol B; UART3 can switch between ASCII and binary protocol parsing functions based on dynamic binding relationships. During system operation, UART3 is bound to both ASCII and binary parsing functions via a dynamic binding table. When a mixed data stream is received, different protocol parsing contexts execute the parsing process separately. If one protocol fails to verify and enters a fallback process, it does not affect the data parsing of the other protocol.

[0096] Example 2

[0097] A multi-serial-port, multi-protocol dynamic parsing fault-tolerant system is provided to implement the multi-serial-port, multi-protocol dynamic parsing fault-tolerant method of Embodiment 1, comprising:

[0098] The data receiving module is used to acquire serial port data received from multiple physical serial ports and write the serial port data into the corresponding circular buffer.

[0099] The dynamic binding module is used to establish a protocol parsing mapping table based on the physical serial port identifier and the protocol type identifier, and to determine the corresponding protocol parsing function based on the protocol parsing mapping table;

[0100] The context management module is used to establish an independent protocol parsing context and state machine for each physical serial port and protocol type combination. This management module can retain the protocol parsing state of the current protocol type when the task is switched, and continue execution in the next execution.

[0101] The protocol parsing module is used to process the serial port data read by the serial port task in the circular buffer, and to set the protocol parsing context and state machine state in the context management module based on the state machine state.

[0102] The fault tolerance module is used to perform a rollback to the current protocol parsing context when protocol parsing fails.

[0103] The routing and distribution module is used to call the corresponding business processing function based on the frame identifier obtained through parsing.

[0104] Example 3

[0105] An electronic device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the multi-serial-port multi-protocol dynamic parsing fault-tolerant method as described in Embodiment 1.

[0106] Example 4

[0107] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the multi-serial-port multi-protocol dynamic parsing fault-tolerant method as described in Example 1.

[0108] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0109] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, as well as combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0110] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0111] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0112] Those skilled in the art will understand that all or part of the steps in the above method can be implemented by a program instructing related hardware. The program or the program described therein can be stored in a computer-readable storage medium. When the program is executed to implement the steps of the above multi-serial-port multi-protocol dynamic parsing fault-tolerant method, the storage medium can be ROM / RAM, magnetic disk, optical disk, etc.

[0113] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A multi-serial-port, multi-protocol dynamic parsing fault-tolerant method, characterized in that, include: Acquire serial data received from multiple physical serial ports and write the serial data received from each physical serial port into the corresponding circular buffer. Establish a dynamic binding relationship between physical serial ports and protocol types, and construct a protocol parsing mapping table based on physical serial port identifiers and protocol type identifiers. The protocol parsing mapping table stores the protocol parsing function pointers corresponding to each protocol type. According to the protocol parsing mapping table, a corresponding protocol parsing context is established for each combination of physical serial port and each protocol type. The protocol parsing context includes at least a data buffer, status information for recording the current protocol parsing status, the length of data received in the buffer, and the length of parsed data in the buffer. Serial port data is read from the circular buffer corresponding to each physical serial port, and the serial port data is input into the protocol parsing context of the corresponding protocol type for frame parsing according to the dynamic binding relationship. In the protocol parsing context, the serial port data is analyzed based on a state machine to identify the frame header, frame tail, frame type, and verification information, thereby obtaining the parsing result. When the parsing result indicates that the current frame data to be parsed is abnormal or the verification fails, a rollback process is performed on the data to be parsed in the current protocol parsing context, and the data after the start position of the current candidate frame is used as the new search starting point to re-identify the frame header. When the complete data frame parsing is completed, the frame identifier and frame length in the complete data frame are extracted, and the parsed data is sent to the corresponding business processing function for processing according to the preset mapping relationship between the frame identifier, frame length and business processing function.

2. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 1, characterized in that, The acquisition of serial port data received from multiple physical serial ports includes: The serial port interrupt service routine only performs hardware data register read operations, data write to the circular buffer operations, and write position update operations. The serial port interrupt service routine does not perform protocol parsing, state machine transitions, or business processing operations.

3. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 2, characterized in that, The circular buffer includes a data buffer area, a write pointer, and a read pointer, each corresponding to a physical serial port; The write pointer records the position where data is written by the serial port interrupt, the read pointer records the position where data is read by the protocol parsing task, and the amount of data to be parsed is determined based on the positional relationship between the write pointer and the read pointer.

4. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 1, characterized in that, The protocol parsing mapping table is a two-dimensional mapping table; The two-dimensional mapping table uses the physical serial port identifier as the first dimension index and the protocol type identifier as the second dimension index, and configures the protocol parsing function supported by the current serial port through the corresponding table entries; By modifying the entries in the two-dimensional mapping table, the protocol type of the corresponding physical serial port can be added, deleted, or switched.

5. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 1, characterized in that, The protocol parsing context is established according to the combination of physical serial port and protocol type; Independent parsing status information is maintained between different physical serial ports and between different protocol types corresponding to the same physical serial port, so that abnormal states in the parsing context of any protocol do not affect the parsing context of other protocols.

6. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 1, characterized in that, The state machine includes a frame header search state, a frame tail search length detection state, a data content parsing state, and a verification state. When the state machine finds the corresponding content in the state, it automatically sets the state machine to the next search state; When the verification state detects an abnormal length, an incorrect checksum, or an abnormal frame tail, invalid data corresponding to the start position of the current candidate frame is deleted, subsequent unparsed data is retained, and the current protocol parsing context is switched to the re-search frame header state.

7. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 1, characterized in that, The mapping relationship between the frame identifier and the service processing function includes at least the frame identifier, the service processing function, and the corresponding data length information; After completing the data frame parsing, the corresponding service processing function is queried based on the frame identifier, and the parsed payload is sent to the service processing function.

8. The multi-serial-port multi-protocol dynamic parsing fault-tolerant method according to claim 1, characterized in that, The operating system generates a task scheduling signal based on the preset priority level of the task. The task scheduling signal is used to control the execution cycle of the protocol parsing task and avoid the protocol parsing task occupying processing resources for a long time. When the serial port parsing task is triggered and there is cached data in the corresponding serial port buffer, the protocol parsing task is triggered to perform data reading, protocol parsing, and business routing processing.

9. A multi-serial-port, multi-protocol dynamic parsing fault-tolerant system, characterized in that, include: The data receiving module is used to acquire serial port data received from multiple physical serial ports and write the serial port data into the corresponding circular buffer. The dynamic binding module is used to establish a protocol parsing mapping table based on the physical serial port identifier and the protocol type identifier, and to determine the corresponding protocol parsing function based on the protocol parsing mapping table; The context management module is used to establish an independent protocol parsing context and state machine for each physical serial port and protocol type combination. This management module can retain the protocol parsing state of the current protocol type when the task is switched, and continue execution in the next execution. The protocol parsing module is used to process the serial port data read by the serial port task in the circular buffer, and to set the protocol parsing context and state machine state in the context management module based on the state machine state. The fault tolerance module is used to perform a rollback to the current protocol parsing context when protocol parsing fails. The routing and distribution module is used to call the corresponding business processing function based on the frame identifier obtained through parsing.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the multi-serial port multi-protocol dynamic parsing fault-tolerant method as described in any one of claims 1 to 8.