CN117687939A - Universal serial port data sliding window system - Google Patents
Universal serial port data sliding window system Download PDFInfo
- Publication number
- CN117687939A CN117687939A CN202311716317.0A CN202311716317A CN117687939A CN 117687939 A CN117687939 A CN 117687939A CN 202311716317 A CN202311716317 A CN 202311716317A CN 117687939 A CN117687939 A CN 117687939A
- Authority
- CN
- China
- Prior art keywords
- data
- frame
- module
- data buffer
- serial
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000004891 communication Methods 0.000 claims abstract description 14
- 238000000605 extraction Methods 0.000 claims description 9
- 238000012545 processing Methods 0.000 claims description 9
- 238000000034 method Methods 0.000 claims description 8
- 230000005540 biological transmission Effects 0.000 claims description 6
- 230000001960 triggered effect Effects 0.000 claims description 3
- 238000013524 data verification Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000004883 computer application Methods 0.000 description 1
- 238000007405 data analysis Methods 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 238000010586 diagram Methods 0.000 description 1
- 238000012795 verification Methods 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/14—Handling requests for interconnection or transfer
- G06F13/16—Handling requests for interconnection or transfer for access to memory bus
- G06F13/1668—Details of memory controller
- G06F13/1673—Details of memory controller using buffers
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F13/00—Interconnection of, or transfer of information or other signals between, memories, input/output devices or central processing units
- G06F13/38—Information transfer, e.g. on bus
- G06F13/42—Bus transfer protocol, e.g. handshake; Synchronisation
- G06F13/4282—Bus transfer protocol, e.g. handshake; Synchronisation on a serial bus, e.g. I2C bus, SPI bus
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Communication Control (AREA)
Abstract
The invention relates to a universal serial port data sliding window system, and belongs to the technical field of serial port communication. The system has clear logic and simple code realization, can completely and accurately extract various data frames from complex serial port data, and improves the reliability and the universality of the system.
Description
Technical Field
The invention belongs to the technical field of serial port communication, and particularly relates to a universal serial port data sliding window system.
Background
The serial interface is a common data interface of a computer application system, has a simple serial communication line, is particularly suitable for long-distance communication, and is widely applied. Because of weak anti-interference capability, the general communication parties can formulate corresponding serial port protocols when transmitting effective data. The protocol content comprises a frame head, an effective data length, effective data, data verification and a frame tail, wherein the frame head is usually used for indicating the type of the serial data frame of the packet, and the data verification and the frame tail are used for ensuring the accuracy and the completeness of the serial data frame. Because the serial port transmission mode is in a unit of single byte, the serial port data which is received and processed at one time is usually combined by multiple packets of data, and because of the error code of transmission, sliding window processing is required to be carried out on the received serial port data, and effective serial port data is extracted from the received serial port data.
At present, various methods for analyzing serial data exist, and serial data frames with different types and the same effective data length and the same frame header length can be well analyzed. However, for a plurality of serial data frames, under the condition that the effective data length and the frame header length of the serial data frames are different, the programming logic is complex, the fault-tolerant mechanism is incomplete, and the defect that the effective data frames cannot be accurately analyzed exists. And most are specific to a particular serial port protocol, and therefore have no versatility.
Disclosure of Invention
First, the technical problem to be solved
The invention aims to solve the technical problems that: the universal serial port data sliding window system can completely and accurately extract various types of data frames from complex serial port data, and improves the reliability and universality of the system.
(II) technical scheme
In order to solve the technical problem, the present invention provides a universal serial port data sliding window system, including:
the initialization module is used for initializing a receiving data buffer zone recvDataBuff, a data buffer zone to be processed dealDataBuff, an effective data buffer zone dataBuff and an effective data length MessLen, and macro definition is carried out on frame heads, frame lengths and frame tails of serial port protocols formulated by two communication parties in a header file;
the storage module is used for setting a data processing period, reading all serial data through the serial port module when the data processing period is up, storing the serial data in the received data buffer, copying the data in the effective data buffer to the data buffer to be processed, and then additionally copying the data in the received data buffer to the data buffer to be processed;
the extraction module is used for extracting data from the pos data in the data cache area to be processed to the effective data cache area and extracting one byte;
the frame head judging module is used for judging whether a frame head exists in the effective data buffer area, if the frame head does not exist, after the first byte in the effective data buffer area is removed, the positions of other bytes in the effective data buffer area are all moved forward by one position, and the posDeal is added with 1, the extracting module is triggered to continuously extract a single byte until the frame head is found, and the continuous extracting module is executed;
the continuous extraction module is used for obtaining the frame length from the frame header, continuously extracting data from the data buffer area to be processed into the effective data buffer area until the data length in the effective data buffer is equal to the frame length, and executing the frame tail judgment module;
the frame tail judging module is used for judging whether the frame tail in the effective data buffer area is correct or not, if so, executing the eliminating module, and if so, executing the frame checking module;
the eliminating module is used for eliminating the first byte of the effective data buffer area when the frame tail or the frame check error is found, moving the front framHeadLen-1 data of the rest bytes in the effective data buffer area forward by one position, assigning a value of framHeadLen-1 to the effective data length at the moment, assigning a value of posDeal-framLen+framHeadLen to the posDeal, and triggering the frame head judging module to search the frame head again;
the frame checking module is used for carrying out frame checking on the data frames in the effective data buffer area, judging whether the frame checking in the effective data buffer area is correct or not, if the frame checking is wrong, executing the rejecting module, and if the frame checking is correct, executing the emptying module;
and the emptying module is used for confirming that the data in the effective data buffer area is a complete and accurate serial data frame when the frame is checked to be correct, and at the moment, after the serial data frame is processed according to service requirements, the effective data buffer area is emptied, the effective data length is assigned to be 0, and the extraction module is re-executed to search the next frame of data.
The invention also provides a serial port data analysis method based on the system.
The invention also provides a serial port transmission method realized based on the system.
The invention also provides a serial port communication method realized based on the system.
(III) beneficial effects
1. The received data and the data to be processed are stored separately by setting the received data cache area and the data to be processed cache area, so that the integrity of data receiving can be ensured;
2. effective data can be accurately extracted from complex data through joint judgment of frame head, effective length, frame tail and verification.
Drawings
FIG. 1 is a schematic diagram of a universal serial data sliding window system implementation of the present invention;
fig. 2a and 2b are flowcharts of a detailed implementation of a universal serial data sliding window system according to the present invention.
Detailed Description
To make the objects, contents and advantages of the present invention more apparent, the following detailed description of the present invention will be given with reference to the accompanying drawings and examples.
Since serial data transmission is in the form of a single byte stream, serial buffered data received at one time may be composed of multi-frame data, and incomplete frames or frames with transmission errors often occur. And thus a complete and accurate serial data frame needs to be extracted therefrom for actual service use. The serial port data frame format is: frame header + frame length + valid data + check + frame trailer. Firstly judging whether the frame head is correct or not, then extracting a packet of data frame according to the frame length, and judging whether the frame tail and the check value are correct or not. When the frame head, the frame tail and the check are all correct, a packet of serial data frame is completely extracted at the moment, and if any one of the three is wrong, sliding window processing is needed. The invention provides a universal serial data sliding window system which can process serial data frames of different types and different lengths.
Referring to fig. 1, fig. 2a, and fig. 2b, the present invention proposes a general serial data sliding window system, so that it can extract different types of serial messages from a group of complex data through serial protocols, specifically:
the initialization module is used for initializing a receiving data buffer zone recvDataBuff, a data buffer zone to be processed dealDataBuff, an effective data buffer zone dataBuff and an effective data length MessLen, and macro definition is carried out on frame heads, frame lengths and frame tails of serial port protocols formulated by two communication parties in a header file;
in a serial communication protocol established by the known communication parties, the maximum value of serial frame data is Lmax, and the length of a data buffer area in the serial module is ComLmax. Therefore, in order to avoid the crossing of the array, the length of the receiving data buffer area is initialized to ComLmax, the length of the effective data buffer area is initialized to Lmax, and the length of the data buffer area to be processed is initialized to comlmax+lmax. To cope with a frame in which the serial data received in one data cycle is not complete, the effective data buffer and the effective data length must be initialized to global variables. The macro definition has the advantage that after the serial port protocol is changed conveniently, only the header file needs to be modified.
And the storage module is used for setting the data processing period to be 12.5ms, and reading all serial data through the serial module and storing the serial data in the received data buffer area when the processing period is up. Firstly, copying the data in the effective data buffer area to the data buffer area to be processed, and then additionally copying the data in the receiving data buffer area to the data buffer area to be processed.
At this time, the valid data which is not processed in the last data period and all serial port data acquired at this time are stored in the data buffer area to be processed.
And the extraction module is used for extracting data from the posDeal data in the data cache area to be processed to the effective data cache area and extracting one byte. The serial port data format is: frame header + frame length + valid data + check + frame trailer.
Since the data buffer area to be processed contains the valid data which is not processed in the last data period and all serial data acquired this time, in order to improve the algorithm efficiency, only one byte is extracted from the posDeal data in the data buffer area to be processed each time to the valid data buffer area, wherein the initial value of the posDeal is equal to MessLen.
The frame head judging module is used for judging whether a frame head exists in the effective data buffer area, if the frame head does not exist, after the first byte in the effective data buffer area is removed, the positions of other bytes in the effective data buffer area are all moved forward by one position, and the posDeal=posDeal+1 is caused, the extracting module is triggered to continuously extract a single byte until the frame head is found, and the continuous extracting module is executed.
And the continuous extraction module is used for obtaining the frame length from the frame header, continuously extracting data from the data buffer area to be processed into the effective data buffer area, and executing the frame tail judgment module after the data length in the effective data buffer is equal to the frame length.
The frame tail judging module is used for judging whether the frame tail in the effective data buffer area is correct or not, if the frame tail is wrong, executing the eliminating module, and if the frame tail is correct, executing the frame checking module.
For a frame header correct (serial port) data frame, the frame length of the data frame is known as framLen according to the protocol, and the frame header length is framHeadLen.
And the rejecting module is used for forwardly moving the front framHeadLen-1 data of the residual bytes in the effective data buffer by one position after rejecting the first byte in the effective data buffer when the frame tail or the frame check error is found. The effective data length is assigned a framHeadLen-1 at this time. And assigning posDeal-framLen+frameHeadLen to posDeal, and triggering a frame header judging module to search the frame header again.
The frame checking module is used for carrying out frame checking on the data frames in the effective data buffer area, judging whether the frame checking in the effective data buffer area is correct or not, if the frame checking is wrong, executing the rejecting module, and if the frame checking is correct, executing the emptying module.
And the emptying module is used for confirming that the data in the effective data buffer area is a complete and accurate serial data frame when the frame is checked to be correct, and at the moment, after the serial data frame is processed according to service requirements, the effective data buffer area is emptied, the effective data length is assigned to be 0, and the extraction module is re-executed to search the next frame of data.
It can be seen that the invention provides a universal serial port data sliding window system, the system has clear logic and simple code realization, can completely and accurately extract various data frames from complex serial port data, and improves the reliability and the universality of the system.
The foregoing is merely a preferred embodiment of the present invention, and it should be noted that modifications and variations could be made by those skilled in the art without departing from the technical principles of the present invention, and such modifications and variations should also be regarded as being within the scope of the invention.
Claims (10)
1. A universal serial port data sliding window system, comprising:
the initialization module is used for initializing a receiving data buffer zone recvDataBuff, a data buffer zone to be processed dealDataBuff, an effective data buffer zone dataBuff and an effective data length MessLen, and macro definition is carried out on frame heads, frame lengths and frame tails of serial port protocols formulated by two communication parties in a header file;
the storage module is used for setting a data processing period, reading all serial data through the serial port module when the data processing period is up, storing the serial data in the received data buffer, copying the data in the effective data buffer to the data buffer to be processed, and then additionally copying the data in the received data buffer to the data buffer to be processed;
the extraction module is used for extracting data from the pos data in the data cache area to be processed to the effective data cache area and extracting one byte;
the frame head judging module is used for judging whether a frame head exists in the effective data buffer area, if the frame head does not exist, after the first byte in the effective data buffer area is removed, the positions of other bytes in the effective data buffer area are all moved forward by one position, and the posDeal is added with 1, the extracting module is triggered to continuously extract a single byte until the frame head is found, and the continuous extracting module is executed;
the continuous extraction module is used for obtaining the frame length from the frame header, continuously extracting data from the data buffer area to be processed into the effective data buffer area until the data length in the effective data buffer is equal to the frame length, and executing the frame tail judgment module;
the frame tail judging module is used for judging whether the frame tail in the effective data buffer area is correct or not, if so, executing the eliminating module, and if so, executing the frame checking module;
the eliminating module is used for eliminating the first byte of the effective data buffer area when the frame tail or the frame check error is found, moving the front framHeadLen-1 data of the rest bytes in the effective data buffer area forward by one position, assigning a value of framHeadLen-1 to the effective data length at the moment, assigning a value of posDeal-framLen+framHeadLen to the posDeal, and triggering the frame head judging module to search the frame head again;
the frame checking module is used for carrying out frame checking on the data frames in the effective data buffer area, judging whether the frame checking in the effective data buffer area is correct or not, if the frame checking is wrong, executing the rejecting module, and if the frame checking is correct, executing the emptying module;
and the emptying module is used for confirming that the data in the effective data buffer area is a complete and accurate serial data frame when the frame is checked to be correct, and at the moment, after the serial data frame is processed according to service requirements, the effective data buffer area is emptied, the effective data length is assigned to be 0, and the extraction module is re-executed to search the next frame of data.
2. The system of claim 1 wherein the initialization module knows in advance that in serial communication protocols established by both communication parties, the maximum value of serial frame data is Lmax, the length of the data buffer in the serial module is ComLmax, the length of the received data buffer is ComLmax, the length of the effective data buffer is Lmax, and the length of the data buffer to be processed is comlmax+lmax.
3. The system of claim 2, wherein the initialization module initializes the valid data cache to a global variable.
4. The system of claim 3, the initialization module initializes the valid data length to a global variable.
5. The system of claim 2, wherein the memory module sets the data processing period to 12.5ms.
6. The system of claim 2, wherein the serial data format is: frame header + frame length + valid data + check + frame trailer.
7. The system of claim 2, wherein the posDeal initial value is equal to MessLen.
8. A serial data parsing method implemented based on the system of any one of claims 1 to 7.
9. A serial transmission method implemented on the basis of the system of any one of claims 1 to 7.
10. A serial communication method implemented based on the system of any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311716317.0A CN117687939A (en) | 2023-12-14 | 2023-12-14 | Universal serial port data sliding window system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202311716317.0A CN117687939A (en) | 2023-12-14 | 2023-12-14 | Universal serial port data sliding window system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN117687939A true CN117687939A (en) | 2024-03-12 |
Family
ID=90133261
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202311716317.0A Pending CN117687939A (en) | 2023-12-14 | 2023-12-14 | Universal serial port data sliding window system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN117687939A (en) |
-
2023
- 2023-12-14 CN CN202311716317.0A patent/CN117687939A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN102510323A (en) | Frame identifying method for serial data | |
CN110704356A (en) | Universal serial port data analyzing method | |
CN111010253B (en) | HIMAC frame splitting system and method based on HINOC protocol | |
CN108306835B (en) | Input caching and data forwarding method of Ethernet switch | |
CN107395565B (en) | Serial port receiving preprocessing method under fixed-length single byte format message protocol | |
CN103916252A (en) | High-bandwidth Ethernet IP core based on FPGA | |
CN110059042B (en) | Data DMA transmission method of UART equipment | |
CN114710224A (en) | Frame synchronization method and device, computer readable medium and electronic device | |
CN112187789A (en) | Data link protocol conversion system | |
CN109902055B (en) | SLIP coding data stream transmission method suitable for narrow-band data network | |
US20080301537A1 (en) | Packet transmission device and packet transmission method | |
US6862283B2 (en) | Method and apparatus for maintaining packet ordering with error recovery among multiple outstanding packets between two devices | |
CN117687939A (en) | Universal serial port data sliding window system | |
US20050144339A1 (en) | Speculative processing of transaction layer packets | |
CN117131091A (en) | Universal serial port data sliding window method | |
CN102111401B (en) | Protocol recognition method and device as well as equipment | |
US9559857B2 (en) | Preprocessing unit for network data | |
CN101764669A (en) | CRC code check method in data receiving process | |
CN110597482A (en) | Method for searching valid data packet in FIFO (first in first out) by serial port | |
CN113726755B (en) | SLIP protocol data processing method | |
CN113222764A (en) | Market local processing system supporting double-path optimization | |
US6987761B2 (en) | Inbound data stream controller with pre-recognition of frame sequence | |
CN111937353B (en) | Method for operating network participant and network participant | |
CN117978325A (en) | Method, equipment and medium for detecting effective data frame of transmission data between signal systems | |
US20040117717A1 (en) | Apparatus and method for a flush procedure in an interrupted trace stream |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication |