Serial port instruction intelligent processing method and device based on multi-frame cache and storage medium
Through multi-level cache pool and priority scheduling technology, the cache overflow, loss and interference problems in serial port communication in underground coal mines are solved, and efficient and reliable instruction processing and response are achieved.
Patent Information
- Application Number
- CN202510585973.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-08
- Publication Date
- 2025-09-19
AI Technical Summary
In serial communication underground in coal mines, the traditional single-frame processing mode causes hardware buffer overflow and instruction loss, insufficient real-time processing capabilities, inability to distinguish the priority of critical instructions from ordinary instructions, and unreliable communication in high-interference environments.
It adopts multi-level cache pool technology, priority instruction scheduling and protocol-enhanced frame recognition to build a virtual cache queue, expand cache capacity, dynamically divide instruction levels, ensure that key instructions are processed first, and correct errors through fuzzy matching algorithms.
It significantly reduces the command loss rate and bit error rate, improves the response time and parsing success rate of key commands, and ensures communication reliability and real-time performance in high-interference environments.
Smart Images

Figure CN120675944A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of coal mine communication technology, and in particular to a method, device and storage medium for intelligent processing of serial port instructions based on multi-frame buffering. Background Art
[0002] In underground coal mine industrial communication systems, serial ports (UART / RS-485) are one of the primary methods for data exchange between devices. Because underground equipment typically uses the AT command set to query control domain status, the high frequency of command transmission and the complex underground environment lead to the following problems with the traditional single-frame processing mode:
[0003] (1) Hardware buffer overflow leads to instruction loss: The serial port hardware buffer of most embedded devices only supports single-frame buffering. When the instruction sending rate exceeds the processing capacity, the new data will overwrite the unprocessed old data. With the trend of intelligent coal mining, the communication frequency of equipment has increased significantly (for example, 5G coal mining machines send dozens of instructions per second), and the hardware buffer cannot meet the demand.
[0004] (2) Insufficient real-time processing capability leads to command loss: The traditional single-frame processing mode requires extremely high MCU configuration. Once the MCU load is too high and the process processing capability is insufficient, AT commands will be frequently lost. In addition, the polling mode cannot adapt to burst traffic (such as sudden emergency commands for mine earthquakes), resulting in the blocking of key commands.
[0005] (3) Lack of a priority scheduling mechanism impacts safety-critical instructions: The Coal Mine Safety Regulations (AQ1029-2019) require that critical instructions such as gas alarms and emergency stop controls must be responded to within 50ms, while ordinary instructions (such as equipment status queries) are allowed a 200ms delay. Traditional FIFO queues cannot distinguish priorities, resulting in a backlog of critical instructions.
[0006] (4) Unreliable communication in high-interference environments underground: There are strong electromagnetic interference, vibration and other harsh conditions underground in coal mines, which lead to command frame breakage or sticking, and the traditional verification method has insufficient error correction capabilities. Summary of the Invention
[0007] The traditional single-frame processing mode of serial communication in coal mines has obvious shortcomings. When the transmission frequency exceeds the processing capacity, the hardware buffer is limited or the processing capacity is insufficient, which easily leads to instruction loss. Traditional technology cannot distinguish between the real-time requirements of critical instructions and ordinary instructions. In the harsh conditions of high interference in coal mines, communication reliability is low.
[0008] To address the above problems, the present invention proposes a multi-frame cache-based intelligent serial port instruction processing method, device and storage medium for coal mines, which adopts core technologies such as multi-level cache pool, priority instruction scheduling, and protocol-enhanced frame recognition.
[0009] The present invention adopts multi-level cache pool technology to build a virtual cache queue at the software layer, expand the equivalent cache capacity, and avoid hardware buffer overflow or instruction loss due to insufficient process processing capability; introduces a priority instruction scheduling algorithm to dynamically divide instruction levels to ensure that key instructions are processed first, solving the problem that the traditional single-frame mode cannot respond in time when the MCU is highly loaded; and at the same time realizes enhanced frame recognition of the protocol to solve the problem of insufficient error correction capability of the traditional method.
[0010] In order to achieve the above objectives, the present invention is implemented through the following technical solutions:
[0011] The present invention provides a method for intelligently processing serial port instructions based on multi-frame buffering, comprising the following steps:
[0012] S1, the process starts from the start node and the system is initialized;
[0013] S2, open the serial port interrupt to prepare to receive external AT commands. When the serial port receives the AT command, the AT command is saved in the original data buffer;
[0014] S3, the system will perform complete command analysis on the received AT command;
[0015] S4, after the parsing is completed, the AT commands are further classified and assigned to different processing queues according to the urgency or processing priority;
[0016] S5, after the instructions are classified and stored in the corresponding queue, the system uses a priority scheduling algorithm to decide which instruction to process first;
[0017] S6, the system performs corresponding operations according to the specific content of the instruction.
[0018] Furthermore, in step S2, the initial configuration of the raw data buffer is preferably 2KB in capacity. This capacity has been rigorously tested and verified to provide the best balance between performance and memory usage under normal communication loads (approximately 200 instructions / second); when the cache filling of the raw data buffer reaches 80% of the capacity, the system dynamically expands the capacity, and the expansion step size is intelligently adjusted each time according to the real-time traffic pattern.
[0019] Furthermore, in step S3, the complete instruction parsing has three working modes, including standard mode, fast mode and repair mode;
[0020] In standard mode, the five-state parsing process of idle → preamble → length → data → CRC is fully executed;
[0021] Fast mode simplifies the verification process and is dedicated to processing the highest priority instructions such as emergency stop;
[0022] Repair mode activates the fuzzy matching engine to intelligently repair abnormal data.
[0023] Furthermore, in step S3, when the system encounters an instruction in an incorrect format, it uses a fuzzy matching algorithm to correct the error until it can be successfully identified.
[0024] Furthermore, in step S4, the processing queue includes an emergency queue, a security queue, and a normal queue. The emergency queue is used to store instructions that need to be processed immediately, the security queue is used to store instructions that require special security processing, and the normal queue is used to store regular instructions.
[0025] Specifically, the emergency queue uses an intelligent fuse mechanism. When the queue depth reaches 90% of capacity, it triggers system-level priority processing, automatically suspends non-core functions to release resources, and returns to normal when the load is below 30% for three consecutive cycles;
[0026] The security queue adopts a flexible partitioning design, dividing the 200-frame capacity into 60-frame security zones, and achieving optimal resource allocation through dynamic boundary adjustment;
[0027] The common queue stores other common instructions and processes them in batches when the system load is lower than 10%.
[0028] Furthermore, in step S6, after the instruction processing is completed, when the cache filling capacity drops below 10%, the system performs dynamic capacity reduction.
[0029] The present invention also provides a serial port instruction intelligent processing device, comprising:
[0030] Physical layer driver module, used to connect to the UART / RS-485 hardware interface to realize raw data reception;
[0031] The virtual buffer management layer module is used to build a multi-level cache pool to complete instruction parsing and classified storage;
[0032] The intelligent scheduling engine module is used to dynamically allocate and process parsed and classified instructions based on priority and system load.
[0033] Furthermore, the intelligent scheduling engine module has a built-in simulation prediction module, which can predict resource conflicts 100ms in advance and actively perform load balancing.
[0034] The present invention also provides a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the above-mentioned method for intelligent processing of serial port instructions based on multi-frame buffering.
[0035] The beneficial effects of the present invention are:
[0036] (1) Improvement of instruction processing reliability
[0037] Optimization of instruction loss rate: In the traditional single-frame processing mode, the average loss rate is 8.7% (measured data) under a flow rate of 500 instructions per second, and the peak loss rate is 63% under burst flow (mine earthquake simulation test). After adopting the multi-level cache technology of the present invention, the loss rate under continuous flow is 0.02% (a reduction of 99.77%), and the loss rate under burst flow is 0.2% (a reduction of 99.68%); 10 -6
[0038] Enhanced error correction capability:
[0039] Test conditions Bit error rate of traditional solution The bit error rate of the present invention Improvement Interference-free environment <![CDATA[10 -6 ]]> <![CDATA[10 -8 ]]> 100 times Strong electromagnetic interference <![CDATA[10 -3 ]]> <![CDATA[10 -6 ]]> 1000 times
[0040] (2) Real-time improvement effect
[0041] Key command response time: Traditional solutions have a delay time of approximately 200ms for the emergency stop command (P0), gas alarm (P1), and general command (P3). The priority scheduling algorithm of the present invention can shorten the delay time of the emergency stop command (P0) to within 22ms, the delay time of the gas alarm (P1) to within 45ms, and the delay time of the general command (P2) to 200ms.
[0042] (3) Improvement of instruction parsing effect
[0043] The improved fuzzy matching algorithm is used to increase the instruction parsing success rate from the traditional 90% to 99.9%. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 Flowchart of the method for intelligently processing serial port instructions based on multi-frame buffering of the present invention;
[0045] Figure 2 A schematic diagram of a multi-level cache of a serial port instruction intelligent processing method based on multi-frame cache of the present invention;
[0046] Figure 3 It is a structural diagram of the serial port instruction intelligent processing device of the present invention. DETAILED DESCRIPTION
[0047] The following will be combined with the embodiments of the present invention and the accompanying drawings to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. The following description of at least one exemplary embodiment is actually only illustrative and is in no way intended to limit the present invention and its application or use. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0048] Unless otherwise specifically stated, the numerical value set forth in these embodiments does not limit the scope of the present invention. Technology and methods known to those of ordinary skill in the relevant art may not be discussed in detail, but in appropriate cases, the technology and methods should be considered as a part of the specification. In all examples shown and discussed here, any specific value should be interpreted as merely exemplary, rather than as a limitation. Therefore, other examples of exemplary embodiments can have different values.
[0049] Example 1
[0050] like Figure 1 The method for intelligently processing serial port commands based on multi-frame buffering shown in the figure specifically includes the following steps:
[0051] S1, first, the process starts from the start node and the system is initialized;
[0052] S2, then, opens the serial port interrupt to prepare for receiving external AT commands. When the serial port receives the AT command, the AT command is saved in the original data buffer. When the cache filling of the original data buffer reaches 80% of the capacity, the system dynamically expands the capacity.
[0053] S3, then the system will perform complete command parsing on these received AT commands to understand their specific meaning. When the system encounters a command with an incorrect format, it uses a fuzzy matching algorithm to correct the error until it can be successfully identified.
[0054] S4: After parsing, AT commands are further classified and assigned to different processing queues based on urgency or processing priority. There are three types of queues involved: emergency queue, security queue, and normal queue. The emergency queue is used to store commands that require immediate processing, the security queue is used to store commands that require special security processing, and the normal queue is used to store regular commands.
[0055] S5, after the instructions are classified and stored in the corresponding queue, the system uses a priority scheduling algorithm to decide which instruction should be processed first. This step ensures that the system can process instructions efficiently, especially those that are urgent or important.
[0056] S6: Next, the command processing phase begins. The system will perform corresponding operations based on the specific content of the command, including executing specific functions, adjusting system settings, or responding to external requests.
[0057] S7, after the instruction processing is completed, when the cache filling capacity drops below 10%, it means that the current task volume of the system is reduced, and the system performs dynamic capacity reduction.
[0058] In general, the above process shows a complete process from receiving serial port AT commands to command processing and then to system resource adjustment, which reflects the system's responsiveness to external commands and resource management capabilities.
[0059] In summary, the intelligent processing method of serial port commands based on multi-frame buffer adopts multi-level buffer pool technology, the first level is the original data buffer, the second level is the complete command parsing area, and the third level is the classification command queue, such as Figure 2 As shown;
[0060] Raw data buffer: The first-level cache of the present invention adopts a high-performance ring buffer structure, which is specially designed to cope with the high-frequency and high-interference serial port data reception scenarios in coal mines. The initial configuration of the buffer is 2KB capacity. This size has been rigorously tested and verified to provide the best performance and memory usage balance under normal communication loads (about 200 instructions / second). The buffer adopts a dynamic expansion mechanism. When the data fill volume reaches the 80% threshold (1.6KB), the system will automatically trigger the expansion process. The expansion step size is intelligently adjusted according to the real-time traffic pattern: a fixed 1KB capacity is added under stable communication conditions; when a traffic surge is detected (such as a mine earthquake emergency), the capacity is aggressively expanded according to the Fibonacci sequence of 1-2-3-5KB, and can be expanded to a maximum of 10KB to meet the needs of extreme situations.
[0061] Complete command parsing area: The core of the second-level cache is a multi-modal state machine engine, which is designed with three operating modes: standard mode fully executes the five-state parsing process of idle → preamble → length → data → CRC; fast mode simplifies the verification process and is dedicated to processing the highest priority instructions such as emergency stop; repair mode activates the fuzzy matching engine to intelligently repair abnormal data. Based on the state machine to parse AT commands, it supports protocol enhancements such as preamble detection, dynamic CRC check, and length field check. Among them, the preamble uses 0x55AA as the frame start mark, and each frame is appended with a 1-byte CRC-8 dynamic check, as well as a length field check to ensure data integrity (such as [0x55AA][length][AT+CMD=1][CRC]).
[0062] Classified instruction queue: The third-level cache adopts a classified queue design, and each queue has a unique management and control strategy. The emergency queue (P0) adopts an intelligent fuse mechanism: when the queue depth reaches 45 frames (90% capacity), it triggers system-level priority processing, automatically suspending non-core functions to release resources; it returns to normal when the load is less than 30% for three consecutive cycles. The security queue (P1) adopts an innovative elastic partitioning design, dividing the 200-frame capacity into a 60-frame guarantee area (absolute reservation) and a 140-frame elastic area (allocated on demand), and achieving optimal resource configuration through dynamic boundary adjustment. The normal queue (P2) stores other ordinary instructions and processes them in batches when the system load is less than 10%. To prevent low-priority instructions from starving, the system implements a dynamic quota system to ensure that each type of instruction can obtain the minimum guaranteed resources.
[0063] The above priority instruction scheduling algorithm assigns real-time weight to each instruction.
[0064] Weight calculation formula: W = (P x 0.6) + (L x 0.3) + (H x 0.1),
[0065] Where P: basic priority of instruction (0-100)
[0066] L: Current system load rate (0-100%)
[0067] H: Historical urgency (0-100)
[0068] Set the scheduling strategy: P0 instructions are preemptive processing instructions. Once such instructions are received, the current task execution is immediately interrupted; P1 instructions are bandwidth reservation instructions. Such instructions occupy at least 30% of the processing resources; P2 instructions are batch processing instructions. Such instructions are processed in batches when idle.
[0069] The fuzzy matching and fault-tolerant parsing system of the present invention adopts a three-level intelligent correction architecture: first, based on the improved Levenshtein distance algorithm, the similarity between the erroneous instruction and the standard instruction library is calculated, and the detection of three error types: insertion, deletion and replacement (such as the deletion operation of CMMD→CMD) is supported. The system has a built-in coal mine-specific AT instruction dictionary, which contains more than 200 standard instructions and their common error patterns. The matching process adopts dynamic threshold control, requiring a similarity of ≥90% under normal conditions, and relaxing it to ≥70% under strong interference. For multiple candidate results, the optimal solution is selected through context analysis: checking the parameter range (such as AT+VAL=256 is automatically corrected to AT+VAL=255) and verifying the legitimacy of the instruction syntax tree. In typical application scenarios, AT+ALAR=1 can be automatically completed to AT+ALARM=1, and AT+CMDD=1 can be corrected to AT+CMD=1, with a parsing accuracy of 99.3%. The system automatically updates the error pattern library every 24 hours to continuously optimize matching accuracy.
[0070] Example 2
[0071] This embodiment provides a serial port instruction intelligent processing device, which is used in the above-mentioned serial port instruction intelligent processing method based on multi-frame buffering to achieve closed-loop optimization from data reception, buffering to processing, such as Figure 3 As shown, including:
[0072] The physical layer driver module is used to connect to the UART / RS-485 hardware interface and realize the original data reception after anti-interference processing;
[0073] The virtual buffer management layer module is used to build a multi-level cache pool to complete instruction parsing and classified storage;
[0074] The intelligent scheduling engine module is used to dynamically allocate and process parsed and classified instructions based on priority and system load.
[0075] The intelligent scheduling engine module, with its built-in simulation and prediction module, can predict resource conflicts 100ms in advance and proactively balance loads. Field tests have shown that this solution stabilizes emergency stop command response time to under 25ms, gas alarm command latency to under 45ms, and increases the throughput of standard commands by 35%.
[0076] Example 3
[0077] The present invention also provides a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the above-mentioned method for intelligent processing of serial port instructions based on multi-frame buffering.
[0078] The above description is only a preferred specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any technician familiar with the technical field, within the technical scope disclosed by the present invention, who makes equivalent replacements or changes based on the technical solution and inventive concept of the present invention, should be covered by the scope of protection of the present invention.
Claims
1. A method for intelligent processing of serial port instructions based on multi-frame buffer, characterized in that: The steps include: S1, the process starts from the start node and the system is initialized; S2, open the serial port interrupt to prepare to receive external AT commands. When the serial port receives the AT command, the AT command is saved in the original data buffer; S3, the system will perform complete command analysis on the received AT command; S4, after the parsing is completed, the AT commands are further classified and assigned to different processing queues according to the urgency or processing priority; S5, after the instructions are classified and stored in the corresponding queue, the system uses a priority scheduling algorithm to decide which instruction to process first; S6, the system performs corresponding operations according to the specific content of the instruction.
2. The method for intelligently processing serial port instructions based on multi-frame buffering according to claim 1, wherein: In step S2, the original data buffer is initially configured with a capacity of 2 KB.
3. The method for intelligently processing serial port instructions based on multi-frame buffering according to claim 2, wherein: In step S2, when the cache filling of the original data buffer reaches 80% of the capacity, the system performs dynamic capacity expansion.
4. The method for intelligently processing serial port instructions based on multi-frame buffering according to claim 1, wherein: In step S3, the complete instruction parsing has three working modes, including standard mode, fast mode and repair mode; In standard mode, the five-state parsing process of idle → preamble → length → data → CRC is fully executed; Fast mode is used for the highest priority instructions; Repair mode activates the fuzzy matching engine to intelligently repair abnormal data.
5. The method for intelligently processing serial port instructions based on multi-frame buffering according to claim 4, characterized in that: In step S3, when the system encounters an instruction in an incorrect format, it uses a fuzzy matching algorithm to correct the error.
6. The method for intelligently processing serial port instructions based on multi-frame buffering according to claim 1, wherein: In step S4, the processing queue includes an emergency queue, a security queue and a normal queue. The emergency queue is used to store instructions that need to be processed immediately, the security queue is used to store instructions that require special security processing, and the normal queue is used to store regular instructions. The emergency queue uses an intelligent fuse mechanism. When the queue depth reaches 90% of capacity, it triggers system-level priority processing, automatically suspends non-core functions to release resources, and returns to normal after the load is below 30% for three consecutive cycles; The security queue adopts a flexible partitioning design, dividing the 200-frame capacity into 60-frame security zones, and achieving optimal resource allocation through dynamic boundary adjustment; The common queue stores other common instructions and processes them in batches when the system load is lower than 10%.
7. The method for intelligently processing serial port instructions based on multi-frame buffering according to claim 1, wherein: In step S6, after the instruction processing is completed, when the cache filling capacity drops below 10%, the system performs dynamic capacity reduction.
8. A serial port instruction intelligent processing device, characterized in that: include: Physical layer driver module, used to connect to the UART / RS-485 hardware interface to realize raw data reception; The virtual buffer management layer module is used to build a multi-level cache pool to complete instruction parsing and classified storage; The intelligent scheduling engine module is used to dynamically allocate and process parsed and classified instructions based on priority and system load.
9. The serial port instruction intelligent processing device according to claim 8, characterized in that: The intelligent scheduling engine module has a built-in simulation prediction module that can predict resource conflicts 100ms in advance and actively perform load balancing.
10. A storage medium, characterized in that: It stores a computer program, which, when executed by a processor, implements the intelligent serial port instruction processing method based on multi-frame buffering as described in any one of claims 1 to 7.
Citation Information
Cited By
Scanner control device and scanner
CN121409137A