Embedded dynamic protocol data transmission and analysis system and protocol data analysis method
Through the embedded dynamic protocol data transmission analysis system, the matching state of the interrupt system and the protocol control unit is used to solve the problem of low protocol data analysis efficiency in the prior art, and parsing it when partial data is received, improving the data Processing efficiency.
Patent Information
- Application Number
- CN202411383002.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-01-07
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing receiving systems are less efficient when analyzing protocol data, and cannot effectively use idle time to analyze data, resulting in a long data processing time.
An embedded dynamic protocol data transmission analysis system is designed, including an interrupt system, a protocol data buffer and a protocol control unit. By matching elements such as the start flag, data length, application data, checksum end flag, etc., the protocol data unit is determined. Reception is completed, allowing parsing when part of the data is received.
Improves data processing efficiency, reduces data processing time, and can parse it immediately after receiving protocol data without waiting for all bytes to be received intact.
Smart Images

Figure CN119276961A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to an embedded dynamic protocol data transmission parsing system and a protocol data parsing method. Background Art
[0002] In embedded systems, serial devices such as SPI and serial ports are often used. Serial devices can transmit from one byte to several bytes at a time. Here, it is assumed that one byte is transmitted at a time. In some slightly complex scenarios, one transmission often cannot achieve our desired goal. Even if multiple bytes are transmitted at a time, we generally use a group of data containing multiple bytes of data to meet our needs. We will define the format of this group of data in advance. This format is called a protocol, and this group of data units is called a protocol data unit. The protocol data unit contains multiple bytes and needs to be transmitted multiple times. The sender sends it multiple times and the receiver receives it multiple times. For the sender, the total length of the protocol data, each byte of data, especially the first byte and the last byte, are all known information. For the receiver, when a byte of data is received at a certain moment, the receiver cannot immediately know the purpose of this data, whether it is the first byte or the last byte. The receiver needs to retain the data and make a judgment based on the protocol and the previously received data.
[0003] For the reception and analysis of protocol data, it is best that the first byte received is exactly the first byte defined by the protocol, and then the protocol data length is a fixed length. When the receiver receives a specific length, it can be considered that the transmission of this protocol data unit is completed, and the data can be transmitted to the data consumer. The next byte received is the first byte of the next protocol data unit.
[0004] For the existing receiving system, the data of the first frame received and processed must be the first byte specified by the protocol. A data misalignment will cause errors in all the data received subsequently. Before the data reception is completed, the system does not make good use of the idle time to effectively parse the received data, resulting in the low efficiency of the existing receiving system in parsing the protocol data. Summary of the invention
[0005] In view of this, it is necessary to provide an embedded dynamic protocol data transmission parsing system and a protocol data parsing method to solve the problem of low parsing efficiency of the existing receiving system.
[0006] In order to solve the above problems, the present invention provides an embedded dynamic protocol data transmission and parsing system, comprising: Interrupt system, protocol data buffer and protocol control unit; The interruption system is used to instruct the storage of received target protocol data when an interruption occurs in the protocol transmission; The protocol data buffer is used to store the target protocol data; The protocol control unit is used to determine that the protocol data unit reception is completed when all elements in the data to be parsed are matched based on the matching status; the data to be parsed is determined based on the target protocol data; the matching status includes: matching start flag, matching data length, matching application data, matching check and matching end flag.
[0007] In a possible implementation, the protocol control unit includes: A protocol data buffer management subunit, configured to determine data to be parsed in the target protocol data stored in the protocol data buffer; A start flag management subunit, used for matching a start flag in the data to be parsed; A data length management subunit, used for matching the data length in the data to be parsed; An upper layer data management subunit, used for matching application data in the data to be parsed; A data verification management subunit, used to verify the application data; An end mark management subunit, used for matching an end mark in the data to be parsed; The protocol data processing state management subunit is used to determine that the protocol data unit reception is completed when all elements in the data to be parsed are matched based on the matching state.
[0008] In a possible implementation, the protocol data buffer management subunit includes: An element buffer pointer, used to indicate the location information of the protocol data buffer; Element buffer size, used to store size information of the protocol data buffer; An element write pointer, used to indicate the location information where the target protocol data is stored; The element read pointer is used to indicate the location information of the data to be parsed.
[0009] In a possible implementation, the start flag management subunit includes: The element start mark length is used to set the length of the start mark; The element start mark matching index is used to indicate the position information of the matched start mark; The element start flag buffer is used to store the start flag.
[0010] In a possible implementation, the data length management subunit includes: A data length offset element is used to configure the offset of the data length relative to the start position of the protocol data unit; The data length size element is used to configure the number of bytes occupied by the data length in the protocol data unit; The data length encoding mode element is used to configure the big-endian and little-endian encoding mode of the data length in the protocol data unit.
[0011] In a possible implementation, the upper layer data management subunit includes: The upper layer data offset element is used to configure the offset of the upper layer data in the protocol data unit; The upper layer data length element is used to configure the length information of the upper layer data.
[0012] In a possible implementation, the data verification management subunit includes: The data check offset element is used to configure the offset of the data check relative to the start position of the protocol data unit; The data check size element is used to configure the number of bytes occupied by the data check in the protocol data unit.
[0013] In a possible implementation, the end mark management subunit includes: Element end mark length, used to set the length of the end mark; The element end mark matching index is used to indicate the position information of the matched end mark; The element end flag buffer is used to store the end flag.
[0014] In a possible implementation, the protocol data processing state management subunit includes: An element status, used to indicate the matching status; The element matching start pointer is used to indicate the location information of the first byte defined by the protocol; Element protocol frame reception notification pointer, used to indicate completion of protocol data unit reception.
[0015] The present invention also provides a protocol data parsing method, which is applied to any of the above-mentioned embedded dynamic protocol data transmission and parsing systems, comprising: When protocol transmission is interrupted, the received target protocol data is stored; When the position information indicated by the element read pointer lags behind the position information indicated by the element write pointer, determining the data to be parsed in the target protocol data; When all elements in the data to be parsed are matched based on the matching status, it is determined that the protocol data unit is received and completed; the matching status includes: a matching start flag, a matching data length, a matching application data, a matching check and a matching end flag.
[0016] The beneficial effects of the present invention are as follows: the embedded dynamic protocol data transmission and parsing system provided by the present invention comprises an interruption system, a protocol data buffer and a protocol control unit. The interruption system is used to instruct that the received target protocol data be stored in the protocol data buffer when the protocol transmission is interrupted. The protocol control unit can determine the data to be parsed in the protocol data buffer, and determine that the reception of the protocol data unit is completed when all elements in the data to be parsed are matched according to the matching status, that is, the protocol data can be parsed after the protocol data is received, and it is not necessary to wait for all bytes of the protocol data unit to be received completely before parsing all the data together. By utilizing the idle time to effectively process the data, the data processing time is reduced and the data processing efficiency is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0018] Figure 1 One of the structural schematic diagrams of an embodiment of the embedded dynamic protocol data transmission and parsing system provided by the present invention; Figure 2 A schematic diagram of a flow chart of an embodiment of a protocol data receiving method provided by the present invention; Figure 3 A second structural diagram of an embodiment of the embedded dynamic protocol data transmission and parsing system provided by the present invention; Figure 4 A schematic diagram of a flow chart of an embodiment of a matching method provided by the present invention; Figure 5 A schematic diagram of a flow chart of an embodiment of a protocol data parsing method provided by the present invention; Figure 6 A schematic structural diagram of an embodiment of an electronic device provided by the present invention. DETAILED DESCRIPTION
[0019] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0020] In the description of the embodiments of the present invention, unless otherwise specified, "multiple" means two or more than two. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" may mean: A exists alone, A and B exist at the same time, and B exists alone.
[0021] The descriptions of "first", "second", etc. involved in the embodiments of the present invention are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of the indicated technical features. Therefore, the technical features defined as "first" or "second" may explicitly or implicitly include at least one of the features.
[0022] Figure 1 One of the structural diagrams of an embodiment of the embedded dynamic protocol data transmission parsing system provided by the present invention is as follows Figure 1 As shown, the embedded dynamic protocol data transmission and parsing system includes: an interrupt system, a protocol data buffer and a protocol control unit.
[0023] An interrupt system 110, a protocol data buffer 120 and a protocol control unit 130; The interruption system 110 is used to instruct the received target protocol data to be stored when the protocol transmission is interrupted; The protocol data buffer 120 is used to store the target protocol data; The protocol control unit 130 is used to determine that the protocol data unit reception is completed when all elements in the data to be parsed are matched based on the matching status; the data to be parsed is determined based on the target protocol data; the matching status includes: matching start flag, matching data length, matching application data, matching check and matching end flag.
[0024] The interrupt system is the trigger of the entire data transmission parsing process. When the protocol transmission is interrupted due to external devices or internal state changes (such as receiving a new data packet, transmission error, etc.), the interrupt system will respond immediately and instruct the receiver to store the received target protocol data, thereby ensuring the real-time and integrity of data transmission, and can respond in time even under high load or complex environments.
[0025] The protocol data buffer is a temporary storage area for storing target protocol data. When the interrupt system indicates that the received protocol data needs to be stored, these data will be written into the buffer.
[0026] The protocol control unit is responsible for managing the entire process of protocol parsing. It is responsible for parsing the data to be parsed stored in the protocol data buffer according to the matching status. It can determine the integrity and correctness of the protocol data unit by matching key elements such as the start flag, data length, application data, checksum, and end flag. Once all elements are matched, the protocol data unit is considered to have been received and can then be further processed or forwarded.
[0027] Compared with the prior art, the embedded dynamic protocol data transmission and parsing system provided by the embodiment of the present invention includes an interrupt system, a protocol data buffer and a protocol control unit. The interrupt system is used to instruct the received target protocol data to be stored in the protocol data buffer when the protocol transmission is interrupted. The protocol control unit can determine the data to be parsed in the protocol data buffer, and determine that the reception of the protocol data unit is completed when all elements in the data to be parsed are matched according to the matching status. That is, the protocol data can be parsed after the protocol data is received, and there is no need to wait for all bytes of the protocol data unit to be received completely before parsing all the data together. By utilizing the idle time to effectively process the data, the data processing time is reduced and the data processing efficiency is improved.
[0028] For example, Figure 2 The present invention provides a flow chart of an embodiment of a method for receiving protocol data, wherein the method for receiving protocol data includes: S201, waiting for protocol data reception interruption; S202: Store the data into the protocol data buffer and update the write pointer position.
[0029] When the protocol data reception interrupt is triggered, it indicates that the data is ready and can proceed to the next step of processing. The received protocol data is accurately stored in the preset protocol data buffer, and the position of the write pointer is synchronously updated to ensure that subsequent data can be stored in an orderly and efficient manner.
[0030] In some embodiments of the present invention, the protocol control unit includes: A protocol data buffer management subunit, configured to determine data to be parsed in the target protocol data stored in the protocol data buffer; A start flag management subunit, used for matching a start flag in the data to be parsed; A data length management subunit, used for matching the data length in the data to be parsed; An upper layer data management subunit, used for matching application data in the data to be parsed; A data verification management subunit, used to verify the application data; An end mark management subunit, used for matching an end mark in the data to be parsed; The protocol data processing state management subunit is used to determine that the protocol data unit reception is completed when all elements in the data to be parsed are matched based on the matching state.
[0031] Figure 3 The second structural diagram of an embodiment of the embedded dynamic protocol data transmission parsing system provided by the present invention is as follows Figure 3 As shown, the protocol control unit is responsible for managing the entire process of protocol parsing. The protocol control unit can be subdivided into multiple subunits, including: protocol data buffer management subunit, start flag management subunit, data length management subunit, upper layer data management subunit, data verification management subunit, end flag management subunit and protocol data processing status management subunit.
[0032] The protocol data buffer management subunit can be used to manage the protocol data buffer, which is used to store protocol data received from the outside. The protocol data buffer management subunit can maintain the address, size, and position of the read and write pointers of the protocol data buffer. When new protocol data is received, the write pointer can be updated and the data can be put into the buffer. The read pointer is used to track the data that has been processed.
[0033] The start flag management subunit is responsible for identifying and processing the start flag of the protocol data. The start flag is a special sequence used to indicate the beginning of valid data. The start flag management subunit checks whether the received data contains this start flag and determines its position.
[0034] The data length management subunit is used to parse the length information of the data, which is very important to know when to stop reading the data, taking into account the offset, size and encoding method of the data length.
[0035] The upper layer data management subunit is responsible for processing the upper layer data part of the protocol data and determining the location and length of the upper layer data according to the information provided by the data length management subunit.
[0036] The data verification management subunit is responsible for data verification to ensure that the received data is error-free. It takes into account the offset and size of the verification information.
[0037] The end mark management subunit is similar to the start mark management subunit. The end mark management subunit is responsible for identifying and processing the end mark of the protocol data.
[0038] The protocol data processing status management subunit is used to track the current processing status, such as whether the start flag is being matched, the data length, etc. A function pointer can be saved, which is called when a complete protocol data unit is received.
[0039] In some embodiments of the present invention, the protocol data buffer management subunit includes: An element buffer pointer, used to indicate the location information of the protocol data buffer; Element buffer size, used to store size information of the protocol data buffer; An element write pointer, used to indicate the location information where the target protocol data is stored; The element read pointer is used to indicate the location information of the data to be parsed.
[0040] The protocol data buffer management subunit includes multiple elements, element buffer pointer, element buffer size, element write pointer and element read pointer.
[0041] The element buffer pointer stores the address position of the protocol data buffer, the element buffer size stores the buffer size information, the element write pointer stores the address position where the next received data is stored, and the element read pointer stores the address position information of the next processed data.
[0042] The working process of the protocol data buffer management subunit is as follows: During initialization, the element buffer pointer points to the starting address of the protocol data buffer, and the element buffer size is set to the protocol buffer size. The element read and write pointers both point to the starting address of the protocol buffer.
[0043] When a protocol transmission reception interrupt occurs, the received data is saved at the location specified by the element write pointer, and then the element write pointer is updated, and it is ensured that the location indicated by the element write pointer is correct.
[0044] When the protocol control unit periodic main task is called, the relative positions of the read pointer and the write pointer are compared. If the write pointer is in front and the read pointer is behind, it means that the data has been received but not yet processed. At this time, data processing can be performed and the existing data can be effectively processed while waiting for other data.
[0045] In some embodiments of the present invention, the start flag management subunit includes: The element start mark length is used to set the length of the start mark; The element start mark matching index is used to indicate the position information of the matched start mark; The element start flag buffer is used to store the start flag.
[0046] The start flag management subunit includes the element start flag length, the element start flag matching index and the element start flag buffer.
[0047] The element start flag is stored in the element start flag buffer. For example, the element start flag buffer size is 8, and the content is 0x11223344_00000000. The element start flag length sets the length information of the element start flag. For example, if it is set to 2, the element start flag is 0x1122. If it is set to 4, the element start flag is 0x11223344. The element flag length and value can be changed dynamically at runtime.
[0048] The element start flag matching index is used to indicate which position is matched when matching the start flag, such as whether it matches 0x11 or 0x22.
[0049] In some embodiments of the present invention, the end mark management subunit includes: Element end mark length, used to set the length of the end mark; The element end mark matching index is used to indicate the position information of the matched end mark; The element end flag buffer is used to store the end flag.
[0050] The end mark management subunit and the start mark management subunit have similar structures.
[0051] Likewise, the end mark management subunit includes an element end mark length, an element end mark matching index, and an element end mark buffer.
[0052] The element end flag is stored in the element end flag buffer.
[0053] The element end mark matching index is used to indicate the matching position when matching the end mark.
[0054] In some embodiments of the present invention, the data length management subunit includes: A data length offset element is used to configure the offset of the data length relative to the start position of the protocol data unit; The data length size element is used to configure the number of bytes occupied by the data length in the protocol data unit; The data length encoding mode element is used to configure the big-endian and little-endian encoding mode of the data length in the protocol data unit.
[0055] The data length management subunit includes a data length offset element, a data length size element and a data length encoding mode element.
[0056] The data length offset element configures the offset of the data length relative to the start position of the protocol data unit.
[0057] The data length size element configures how many bytes the data length information occupies in the protocol data unit.
[0058] The data length encoding mode element configures the big-endian and small-endian encoding mode of the data length information in the protocol data unit.
[0059] The data length management subunit can parse out the size information of the upper layer data.
[0060] In some embodiments of the present invention, the upper layer data management subunit includes: The upper layer data offset element is used to configure the offset of the upper layer data in the protocol data unit; The upper layer data length element is used to configure the length information of the upper layer data.
[0061] The upper layer data management subunit includes an upper layer data offset element and an upper layer data length element.
[0062] The upper layer data offset element configures the offset of the upper layer data in the protocol data unit relative to the starting position of the protocol data unit. The upper layer data length element configures the length information of the upper layer data.
[0063] When the data length management subunit configuration information is valid, the upper layer data length information will be parsed by the data length management subunit.
[0064] When the data length management subunit configuration is invalid, the upper layer data length information will be obtained by the upper layer data management subunit configuration, and at this time the upper layer data length information is generally fixed.
[0065] In some embodiments of the present invention, the data verification management subunit includes: The data check offset element is used to configure the offset of the data check relative to the start position of the protocol data unit; The data check size element is used to configure the number of bytes occupied by the data check in the protocol data unit.
[0066] The data verification management subunit includes a data verification offset element and a data verification size element.
[0067] Data check offset element, configure the offset of data check relative to the start position of the protocol data unit, The data check size element configures the number of bytes occupied by the data check in the protocol data unit.
[0068] In some embodiments of the present invention, the protocol data processing state management subunit includes: An element status, used to indicate the matching status; The element matching start pointer is used to indicate the location information of the first byte defined by the protocol; Element protocol frame reception notification pointer, used to indicate completion of protocol data unit reception.
[0069] The protocol data processing state management subunit includes multiple sub-elements, element state, element matching start pointer and element protocol frame reception notification pointer.
[0070] The element status indicates the stage of the current processing of the received data, for example, the matching start flag stage, the matching data length stage, the matching application data stage, the matching verification stage, the matching end flag stage, etc. Different states can be customized according to different protocols, which is easy to expand and transplant.
[0071] The element matches the start pointer and saves the position of the first byte specified by the protocol.
[0072] The element protocol frame reception notification pointer points to a function used to notify the user that a complete protocol data unit reception is completed. The function can obtain a complete frame of protocol data in the protocol data buffer according to the element matching start pointer and protocol data length.
[0073] The working process of the protocol data processing state management subunit is as follows: During initialization, the element state is set to the match start flag state, indicating the initialization match phase, the element match start pointer points to the position pointed to by the element write pointer, and the element protocol frame reception notification pointer is set to the protocol frame processing function written by the user.
[0074] When data is received, the position of the write pointer is updated, and the position of the read pointer lags behind the write pointer position, indicating that there is data to be processed. At this time, the protocol control unit periodic main task reads a data based on the position indicated by the read pointer, and updates the position of the read pointer, and processes the data based on the element status.
[0075] The element state is in the matching start flag state. Based on the configuration information of the start flag, the received data is matched. If the match is successful, it continues to wait for the received data to match until this state is completely matched successfully. Then the element state switches to the next state, such as the matching data length state. The matching process is similar to the matching start flag. If the match fails, the element state is updated to the matching start flag state, the element matching start pointer position is updated to the current pointer position, and the data length is correctly updated.
[0076] Optionally, Figure 4A flow chart of an embodiment of the matching method provided by the present invention is shown in FIG. Figure 4 As shown, the matching methods include: S401, determining whether the read pointer lags behind the write pointer; S402, read a byte for matching, and update the read pointer position; S403, matching the start flag based on the matching index; Figure 5 A flow chart of an embodiment of the protocol data parsing method provided by the present invention is as follows Figure 5 As shown, the protocol data parsing method includes: S501, when protocol transmission is interrupted, storing received target protocol data; S502, when the position information indicated by the element read pointer lags behind the position information indicated by the element write pointer, determining the data to be parsed in the target protocol data; S503. When all elements in the data to be parsed are matched based on the matching status, it is determined that the protocol data unit is received. The matching status includes: a matching start flag, a matching data length, a matching application data, a matching check, and a matching end flag.
[0077] The execution subject of the protocol data parsing method provided by the present invention may be the embedded dynamic protocol data transmission parsing system provided by the above embodiment.
[0078] Compared with the prior art, the protocol data parsing method provided by the embodiment of the present invention saves the currently received target protocol data into a buffer when an interruption occurs during the protocol transmission process, and uses a write pointer to indicate the position where the current data is written into the buffer and a read pointer to indicate the position where the data starts to be parsed. When the position of the write pointer exceeds the read pointer, it indicates that there is new data to be parsed, and thus the data segment to be parsed is extracted from the buffer according to the position difference between the write pointer and the read pointer. When all elements in the data to be parsed are matched according to the matching status, it is determined that the protocol data unit is received. The start flag is matched in the protocol data to confirm the start of the data packet, and the length of the entire data packet is determined according to the data length information provided in the starting part. The protocol specification parses and extracts application layer data, calculates the checksum of the parsed data and compares it with the checksum provided in the data packet to verify the integrity and correctness of the data, and checks whether the data packet ends with the correct end mark to confirm the integrity of the data packet. When all the above matching states are met, it can be considered that a complete protocol data unit has been successfully received and parsed, so that the data can be further processed according to application requirements, such as forwarding, storing or performing corresponding operations. After receiving the protocol data, the protocol data can be parsed without waiting for all bytes of the protocol data unit to be received completely before parsing all the data together. By using idle time to effectively process the data, the data processing time is reduced and the data processing efficiency is improved. The embedded dynamic protocol data transmission parsing system and the protocol data parsing method provided by the present invention are described in detail below in conjunction with specific embodiments. It is assumed that the protocol data unit includes: a 2-byte start flag, a 2-byte data length, followed by AppData, and then a 2-byte data check value, and no end flag.
[0079] Step 1: Build relevant data structures based on the system architecture diagram.
[0080] Step 1.1: Construct the protocol data buffer management subunit data structure as shown below: Typedef Struct{ Unsigend char* mBufferPtr; Unsigned long mBufferSize ; Unsigned char* mReadPtr; Unsigned char* mWritePtr; }BufferManagementDataType; Step 1.2: Construct the start flag management subunit data structure as shown below: Typedef struct{ Unsigned longmStartFlagFieldSize; Unsigned long mStartFlagMatchIndex; Unsigned char mStartFlagBuffer[8]; }StartFlagManagementDataType; Step 1.3: Construct the data length management subunit data structure as shown below: Typedef struct{ Unsigned long mDataSizeFieldOffset; Unsigned long mDataSizeFieldLength; Unsigned long mBigEndianLittleEndian; }DataSizeManagementDataType; Step 1.4: Construct the upper-level data management subunit data structure as shown below: Typedef struct{ Unsigned long mAppDataFieldOffset; Unsigned long mAppDataSize ; }AppDataManagementDataType; Step 1.5: Construct the data structure of the data verification management subunit, as shown below: Typedef struct{ Unsigned long mVerificationFieldOffset; Unsigned long mVerificationFieldSize; }VerificationManagementDataType; Step 1.6: Construct the end mark management subunit data structure as shown below: Typedef struct{ Unsigned long mStopFlagFieldSize; Unsigned long mStopFlagMatchIndex; Unsigned char mStopFlagBuffer[8]; }StopFlagManagementDataType; Step 1.7: Construct the state management subunit data structure as shown below: Typedef struct{ Unsigned long mState; Unsigned long mStartMatchIndex; Unsigned long (*OnProtocolDataUnitReceived)(unsigned longstartMatchIndex, unsigned long appDataSize); }StateManagementDataType; Step 2: Build the protocol parsing system data structure.
[0081] Typedef struct{ StateManagementDataTypemStateManager; BufferManagementDataType mBufferManager; StartFlagManagementDataType mStartFlagManager; DataSizeManagementDataType mDataSizeManager; AppDataManagementDataType mAppDataManager; VerificationManagementDataTypemVerificationManager; StopFlagManagementDataTypemStopFlagManager; }ProtocolParsingSystemDataType; Step 3: Define the protocol data buffer and protocol parsing system data instance.
[0082] #define PROTOCOL_DATA_UNIT_BUFFER_SIZE1024 Unsigned char gProtocolDataUnitBuffer[PROTOCOL_DATA_UNIT_BUFFER_SIZE]; ProtocolParsingSystemDataTypegProtocolParsingSystem; Step 4: Configure the protocol parsing system.
[0083] mStartFlagFieldSize is set to 2; mStartFlagMatchIndex is configured to 0; mStartFlagBuffer is filled with the specific value of the start flag, such as 0x1122; mDataSizeFieldOffset is set to 2; mDataSizeFieldLength is set to 2; mBigEndianLittleEndian is set based on the actual situation, here it is set to little endian; mAppDataFieldOffset is set to 4; mAppDataSize is determined by dynamic parsing of mDataSizeManager. When mDataSizeManager is not configured, mAppDataSize needs to be configured to determine the appData size.
[0084] Since mAppDataSize is dynamically parsed to determine the appData size, and data verification is placed after apData, it is meaningless to configure mVerificationFieldOffset here. Only mVerificationFieldSize is configured to 2.
[0085] mStopFlagFieldSize is configured to 0, indicating that there is no such element in the protocol data unit.
[0086] At this point, all the items that need to be configured have been configured.
[0087] Step 5: Initialize the protocol parsing system.
[0088] mBufferPtr points to the starting address of gProtocolDataUnitBuffer, mBufferSize is set to the size of ProtocolParsingSystemDataType, mReadPtr points to mBufferPtr, and mWritePtr points to mBufferPtr; mState is initialized to MatchStartFlag; OnProtocolDataUnitReceived is initialized as a protocol frame processing function written by the user.
[0089] (1) Write a data receiving function and call the data receiving function in the receiving interrupt.
[0090] The data receiving function saves the data at the location indicated by mWritePtr and updates the mWritePtr position correctly. The data receiving function ensures that mWritePtr points to the correct range.
[0091] (2) Write a matching failure processing function.
[0092] When the match fails, the match failure processing function is executed. The match failure processing function sets mState to the first processing state MatchStartFlag and updates various matching indexes, such as mStartFlagMatchIndex, mStopFlagMatchIndex, and mStartMatchIndex. The match failure indicates that the data matched this time does not conform to the format of a certain middle position of the protocol data unit. The data should also be matched with the first data of the protocol data unit to confirm whether the unmatched data conforms to the start of a new match. If it does not conform to the start of a new match, mStartFlagMatchIndex and mStopFlagMatchIndex are set to 0, and mStartMatchIndex is set to mReadPtr. If it conforms to the start of a new match, mStartFlagMatchIndex is set to 1, mStopFlagMatchIndex is set to 0, and mStartMatchIndex is set to the previous position of mReadPtr. Because when reading this data, mReadPtr points to the next data, but the data in the previous position of mReadPtr is the start position of the match.
[0093] (3) Write the matching main function.
[0094] The condition for matching to start is that the data received has not been processed, and the mReadPtr position lags behind the mWritePtr position. At this time, the data X at the mReadPtr position is read, and the mReadPtr is updated to start matching until the mReadPtr position is the same as the mWritePtr position, and the data processing is completed. The mState state is divided into MatchStartFlag, MatchDataSize, MatchAppData, MatchVerification, MatchStopFlag, etc., which are updated based on the actual situation.
[0095] Match different elements based on different states. First, match the start flag, compare the data X of this match with the mStartFlagBuffer data indicated by mStartFlagMatchIndex. If they are inconsistent, execute the match failure processing function. If they are consistent, mStartFlagMatchIndex is increased by 1, and this match is completed, waiting for the next match to start.
[0096] When the number of times mStartFlagMatchIndex increases is equal to mStartFlagFieldSize, it means that the received data and the start flag match successfully. At this time, you can match the next element, such as MatchDataSize, set mState to MatchDataSize, and start matching the next element. mStartMatchIndex should be mReadPtr position moved forward by mStartFlagFieldSize.
[0097] Then match the data length. After matching the start mark, the data read out in the next match may not necessarily belong to the data length. The position of the data length element is determined by mStartMatchIndex, mDataSizeFieldOffset, and mDataSizeFieldLength. If there are undefined elements in the protocol and the user does not need to pay attention to these data, these data may not affect the match. This is also a feature of the dynamic parsing of this system. In this instance, the data length and the start mark are adjacent. The data read out for the first time in the data length matching phase belongs to the data length range defined by mDataSizeFieldOffset and mDataSizeFieldLength. The first match is completed and waits for the next match to start.
[0098] Until all data lengths are matched. Based on mBigEndianLittleEndian, the data length information is parsed into mAppDataSize. After the data length is matched, mState is set to MatchAppData and the next element matching begins.
[0099] Then match appData. Matching appData mainly involves reading matching data X. If the position of data X exceeds the range of mStartMatchIndex plus mAppDataFieldOffset plus mAppDataSize, appData reading is completed. After appData reading is completed, set mState to MatchVerification and start matching the next element.
[0100] Finally, match the data verification. In this example, the data verification follows appData, and mVerificationFieldOffset has no effect. After matching appData, the next match is the data verification element. Read the matching data X, and when the read size is equal to mVerificationFieldSize, the data verification element is read.
[0101] At this point, all elements are matched, and OnProtocolDataUnitReceived is called, passing in mStartMatchIndex and the length of the protocol data to notify the user that the protocol data unit has been received. The user performs data verification on the protocol data unit, and then can use appData.
[0102] The embedded dynamic protocol data transmission and parsing system and protocol data parsing method provided by the embodiments of the present invention have the following advantages: (1) Data length information is dynamically configurable and can be fixed or dynamically obtained from the protocol data unit. The protocol data unit can carry data of different lengths.
[0103] (2) The data parsing protocol can be dynamically updated, such as the start flag, which can match multiple protocol data units.
[0104] (3) The data misalignment tolerance rate is high. Even if the current data is misaligned, it will not affect the subsequent protocol data unit parsing.
[0105] (4) Sub-units such as the end flag and data length can be selectively configured. They can be configured when needed and not configured when not needed.
[0106] (5) After receiving the data, the data can be parsed immediately in the main task. There is no need to wait for all bytes of the protocol data unit to be received before parsing the data together. The spare time can be used to effectively process the data, reducing the data processing time and improving the data processing efficiency.
[0107] (6) It has a wide range of applications and is easy to port. It can adapt to different work scenarios and tasks by simply modifying configuration parameters.
[0108] like Figure 6 As shown, the present invention also provides an electronic device 600. The electronic device 600 includes a processor 601, a memory 602 and a display 603. Figure 6 Only some components of the electronic device 600 are shown, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead.
[0109] In some embodiments, the processor 601 may be a central processing unit (CPU), a microprocessor or other data processing chip, used to run program codes or process data stored in the memory 602, such as the protocol data parsing method of the present invention.
[0110] In some embodiments, the processor 601 may be a single server or a server group. The server group may be centralized or distributed. In some embodiments, the processor 601 may be local or remote. In some embodiments, the processor 601 may be implemented in a cloud platform. In some embodiments, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an internal cloud, a multi-cloud, etc., or any combination thereof.
[0111] In some embodiments, the memory 602 may be an internal storage unit of the electronic device 600, such as a hard disk or memory of the electronic device 600. In other embodiments, the memory 602 may also be an external storage device of the electronic device 600, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc., equipped on the electronic device 600.
[0112] Furthermore, the memory 602 may include both an internal storage unit of the electronic device 600 and an external storage device. The memory 602 is used to store application software installed in the electronic device 600 and various data.
[0113] In some embodiments, the display 603 may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an organic light-emitting diode (OLED) touch device, etc. The display 603 is used to display information on the electronic device 600 and to display a visual user interface. The components 601-603 of the electronic device 600 communicate with each other via a system bus.
[0114] In one embodiment, when the processor 601 executes the protocol data parsing program in the memory 602, the following steps may be implemented: When protocol transmission is interrupted, the received target protocol data is stored; When the position information indicated by the element read pointer lags behind the position information indicated by the element write pointer, determining the data to be parsed in the target protocol data; When all elements in the data to be parsed are matched based on the matching status, it is determined that the protocol data unit is received and completed; the matching status includes: a matching start flag, a matching data length, a matching application data, a matching check and a matching end flag.
[0115] It should be understood that: when the processor 601 executes the protocol data parsing program in the memory 602, in addition to the above functions, other functions can also be implemented. For details, please refer to the description of the corresponding method embodiment above.
[0116] Furthermore, the embodiment of the present invention does not specifically limit the type of the electronic device 600 mentioned, and the electronic device 600 may be a portable electronic device such as a mobile phone, a tablet computer, a personal digital assistant (PDA), a wearable device, a laptop computer, etc. Exemplary embodiments of portable electronic devices include but are not limited to portable electronic devices equipped with IOS, Android, Microsoft or other operating systems. The above-mentioned portable electronic device may also be other portable electronic devices, such as a laptop computer with a touch-sensitive surface (e.g., a touch panel). It should also be understood that in some other embodiments of the present invention, the electronic device 600 may not be a portable electronic device, but a desktop computer with a touch-sensitive surface (e.g., a touch panel).
[0117] Correspondingly, an embodiment of the present invention also provides a computer-readable storage medium, which is used to store computer-readable programs or instructions. When the program or instructions are executed by a processor, the steps or functions in the protocol data parsing method provided in the above-mentioned method embodiments can be implemented.
[0118] Those skilled in the art will appreciate that all or part of the processes of the above-mentioned embodiments can be implemented by instructing related hardware (such as a processor, a controller, etc.) through a computer program, and the computer program can be stored in a computer-readable storage medium, wherein the computer-readable storage medium is a disk, an optical disk, a read-only storage memory, or a random access memory, etc.
[0119] The embedded dynamic protocol data transmission parsing system and protocol data parsing method provided by the present invention are introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. An embedded dynamic protocol data transmission and parsing system, characterized in that: include: Interrupt system, protocol data buffer and protocol control unit; The interruption system is used to instruct the storage of received target protocol data when an interruption occurs in the protocol transmission; The protocol data buffer is used to store the target protocol data; The protocol control unit is used to determine that the reception of the protocol data unit is completed when all elements in the data to be parsed are matched based on the matching status; The data to be parsed is determined based on the target protocol data; the matching status includes: a matching start flag, a matching data length, a matching application data, a matching check and a matching end flag.
2. The embedded dynamic protocol data transmission and parsing system according to claim 1, characterized in that: The protocol control unit comprises: A protocol data buffer management subunit, configured to determine data to be parsed in the target protocol data stored in the protocol data buffer; A start flag management subunit, used for matching a start flag in the data to be parsed; A data length management subunit, used for matching the data length in the data to be parsed; An upper layer data management subunit, used for matching application data in the data to be parsed; A data verification management subunit, used to verify the application data; An end mark management subunit, used for matching an end mark in the data to be parsed; The protocol data processing state management subunit is used to determine that the protocol data unit reception is completed when all elements in the data to be parsed are matched based on the matching state.
3. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The protocol data buffer management subunit includes: An element buffer pointer, used to indicate the location information of the protocol data buffer; Element buffer size, used to store size information of the protocol data buffer; An element write pointer, used to indicate the location information where the target protocol data is stored; The element read pointer is used to indicate the location information of the data to be parsed.
4. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The start flag management subunit includes: The element start mark length is used to set the length of the start mark; The element start mark matching index is used to indicate the position information of the matched start mark; The element start flag buffer is used to store the start flag.
5. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The data length management subunit comprises: A data length offset element is used to configure the offset of the data length relative to the starting position of the protocol data unit; The data length size element is used to configure the number of bytes occupied by the data length in the protocol data unit; The data length encoding mode element is used to configure the big-endian and little-endian encoding mode of the data length in the protocol data unit.
6. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The upper layer data management subunit comprises: The upper layer data offset element is used to configure the offset of the upper layer data in the protocol data unit; The upper layer data length element is used to configure the length information of the upper layer data.
7. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The data verification management subunit includes: The data check offset element is used to configure the offset of the data check relative to the start position of the protocol data unit; The data check size element is used to configure the number of bytes occupied by the data check in the protocol data unit.
8. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The end mark management subunit includes: Element end mark length, used to set the length of the end mark; The element end mark matching index is used to indicate the position information of the matched end mark; The element end flag buffer is used to store the end flag.
9. The embedded dynamic protocol data transmission and parsing system according to claim 2, characterized in that: The protocol data processing state management subunit includes: An element status, used to indicate the matching status; The element matching start pointer is used to indicate the location information of the first byte defined by the protocol; Element protocol frame reception notification pointer, used to indicate completion of protocol data unit reception.
10. A protocol data analysis method, characterized in that: The embedded dynamic protocol data transmission and parsing system applied to any one of claims 1 to 9 comprises: When protocol transmission is interrupted, the received target protocol data is stored; When the position information indicated by the element read pointer lags behind the position information indicated by the element write pointer, determining the data to be parsed in the target protocol data; When all elements in the data to be parsed are matched based on the matching status, it is determined that the protocol data unit is received and completed; the matching status includes: a matching start flag, a matching data length, a matching application data, a matching check and a matching end flag.
Citation Information
Patent Citations
Frame identifying method for serial data
CN102510323A
Smart card data receiving method and device
CN109240947A
Data transmission method and device, storage medium and electronic equipment
CN115441997A
Buffer management system in communication controller
JP1995170293A