A protocol decoding method and device based on a general description of a communication protocol

By using a method based on a general description of communication protocols to dynamically decode communication messages, the problems of code redundancy and maintenance difficulties in existing technologies are solved. This enables rapid identification and decoding of multiple protocols, improving development efficiency and scalability.

CN115955516BActive Publication Date: 2026-02-24SHANDONG TAIHUA LIGHTING TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202211662716.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-12-23
Publication Date
2026-02-24
Estimated Expiration
2042-12-23

AI Technical Summary

Technical Problem

Existing communication protocol decoding methods require the development of dedicated code for each communication protocol, resulting in code redundancy, maintenance difficulties, and limited reusability, failing to meet the requirements for versatility and scalability.

Method used

It adopts a method based on the general description of communication protocols, obtains and verifies the general description file, parses and transforms the protocol matching items and data items, dynamically matches and decodes communication message data, and supports the rapid identification and decoding of multiple protocols.

Benefits of technology

It provides a universal description of standard and proprietary protocols, reducing development workload and costs, improving system development efficiency, supporting mixed access and fast decoding of multiple protocol versions, and possessing scalability and flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115955516B_ABST
    Figure CN115955516B_ABST
Patent Text Reader

Abstract

The application belongs to the technical field of communication protocols, and provides a protocol decoding method and device based on general description of communication protocols. The protocol decoding method based on general description of communication protocols performs protocol matching and protocol decoding on communication protocol data messages based on a description file of a description method. The protocol matching performs protocol matching on a communication original message based on a protocol matching item, and obtains a protocol ID after successful matching. The protocol decoding loads a protocol data item to perform automatic decoding according to the protocol ID obtained through protocol matching, and decodes output object instances or json format data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of communication protocol technology, and in particular relates to a protocol decoding method and apparatus based on a general description of communication protocols. Background Technology

[0002] The statements in this section are merely background information related to the present invention and do not necessarily constitute prior art.

[0003] In IoT and internet communication, communication protocols are widely used in device communication, including standard protocols and proprietary protocols. Especially in the absence of relevant standards, device manufacturers often use proprietary protocols specified internally by their companies. Regardless of whether it is a standard protocol or a proprietary protocol, decoding (also known as parsing) the protocol running on these devices requires a significant amount of development and maintenance work.

[0004] The inventors discovered that existing communication protocol decoding methods typically employ a "hard-coded" approach. For each communication protocol, a dedicated set of code needs to be developed to parse the protocol data, resulting in a large workload and significant time commitment. Furthermore, due to bug fixes or changing requirements, even if the protocol structure is the same, different data requires repeated coding, leading to code redundancy, maintenance difficulties, and limited code reuse. Summary of the Invention

[0005] To address the technical problems existing in the background art, the present invention provides a protocol decoding method and apparatus based on a general description of communication protocols, which can satisfy both universality and customization of private protocols, improve system or device development efficiency, and reduce workload and cost.

[0006] To achieve the above objectives, the present invention adopts the following technical solution:

[0007] The first aspect of the present invention provides a protocol decoding method based on a general description of communication protocols.

[0008] A protocol decoding method based on a general description of communication protocols, comprising:

[0009] Obtain the general description file of the communication protocol, verify the format of the general description file, and parse the elements in the description file;

[0010] Convert the protocol matching items and related elements and attributes in the communication protocol description file into communication protocol matching objects, and convert the protocol data items and related elements and attributes in the communication protocol description file into communication protocol data objects;

[0011] Communication interception to obtain raw communication message data;

[0012] The original communication message data is matched against the protocol based on the protocol matching items.

[0013] Based on the protocol matching result, perform protocol decoding and output object instances or JSON format data;

[0014] The general description file of the communication protocol describes each communication protocol instruction in three parts: general description items, protocol matching items, and protocol data items.

[0015] The general protocol description item is used to define a general description of the protocol; the protocol matching item is used to define the matching conditions for the software system to automatically match protocol instructions; and the protocol data item is used to define the constituent elements of the protocol.

[0016] In one implementation, the general description items of the protocol include a unique ID definition for the protocol instruction, a class name definition for storing the protocol instruction parsing or encoding result, a verification item definition, a verification data area definition, a message data area length item definition, and a message data area definition.

[0017] In one implementation, the protocol matching item includes a byte condition item and a bit condition item.

[0018] In one implementation, the protocol data item includes byte items, bit items, repeat items, tag items, sub-protocol items, and encryption blocks.

[0019] As one implementation method, in the process of performing protocol matching on the original communication message data based on protocol matching items:

[0020] The protocol message data and the protocol matching object set are used as input items. According to the definition in the protocol matching object set, the message data at the specified position is obtained, converted according to type, and the converted value is compared with the value in the description file according to the operator in the description file.

[0021] When the logical operation result is true, the matching condition is met, and the verification of the next matching condition continues until all matching conditions of this protocol instruction are met. Then, the message data is considered to have successfully matched this protocol instruction, and the protocol ID is output.

[0022] As one implementation method, in the process of performing protocol matching on the original communication message data based on protocol matching items:

[0023] If any condition of this protocol instruction fails to match, the comparison and matching of the matching objects of this protocol instruction will end, and the comparison and matching of the matching object set of the next protocol instruction description file will begin.

[0024] If all matching objects for all protocol instructions fail to match, it indicates that the protocol message data does not match the protocol description file. Log the error and end the processing.

[0025] A second aspect of the present invention provides a protocol decoding apparatus based on a general description of communication protocols.

[0026] A protocol decoding device based on a general description of communication protocols, comprising:

[0027] The element parsing module is used to obtain the general description file of the communication protocol, verify the format of the general description file, and parse the elements in the description file;

[0028] The element conversion module is used to convert the protocol matching item related elements and attributes in the communication protocol description file into communication protocol matching objects, and to convert the protocol data item related elements and attributes in the communication protocol description file into communication protocol data objects.

[0029] The communication listening module is used to listen for and acquire raw communication message data.

[0030] The protocol matching module is used to perform protocol matching on the original communication message data based on the protocol matching items.

[0031] The protocol decoding module is used to decode the protocol based on the protocol matching result and output object instances or JSON format data.

[0032] The general description file of the communication protocol describes each communication protocol instruction in three parts: general description items, protocol matching items, and protocol data items.

[0033] The general protocol description item is used to define a general description of the protocol; the protocol matching item is used to define the matching conditions for the software system to automatically match protocol instructions; and the protocol data item is used to define the constituent elements of the protocol.

[0034] The general description items of the protocol include the unique ID definition of the protocol instruction, the corresponding class name definition for storing the protocol instruction parsing or encoding result, the verification item definition, the verification data area definition, the message data area length item definition, and the message data area definition.

[0035] A third aspect of the present invention provides a computer-readable storage medium.

[0036] In one or more embodiments, a computer-readable storage medium is provided having a computer program stored thereon that, when executed by a processor, implements the steps of the protocol decoding method based on the general description of communication protocols described above.

[0037] A fourth aspect of the present invention provides a computer device.

[0038] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the program to implement the steps of the protocol decoding method based on the general description of communication protocols as described above.

[0039] Compared with the prior art, the beneficial effects of the present invention are:

[0040] (1) The general description method for communication protocols of the present invention provides a general and standardized description method for standard protocols and private protocols used in the communication process. The description is simple and has complete and powerful description capabilities. In the implementation of encoding and decoding program code, dynamic encoding and decoding can be achieved based on the protocol description itself. The general description method supports descriptions that identify and match protocols, definitions of data items that constitute protocols according to bytes and bits, descriptions of unsigned numbers, different byte orders of protocol items, descriptions of string encoding formats, variable-length strings, sub-protocols, flexible nesting of multi-level protocol items, variable-length repeating items, especially widely used TLV encoded repeating items, expressions describing whether a protocol item appears in the message, expressions for converting protocol item values, descriptions of protocol integrity verification and protocol encryption, and descriptions of built-in and custom methods (functions) for decoding, encoding, verification, encryption, and decryption.

[0041] (2) The protocol decoding method based on the general description of communication protocols can achieve universal and dynamic decoding of communication protocols in most cases, satisfying both universality and extensibility. The protocol matching method supports mixed access of communication protocols from multiple products and multiple protocol versions, and can dynamically identify protocols and quickly and accurately match protocol description files. The protocol decoding method covers the vast majority of communication decoding needs, enabling dynamic decoding of new protocols without re-encoding. Even for extremely rare special customized protocols, custom decoding, verification, and decryption can be implemented by writing custom classes that inherit from the base class, thus possessing extensibility. Therefore, the method achieves fast protocol decoding through universality and extensibility, resulting in higher development efficiency and reduced development costs.

[0042] Advantages of additional aspects of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description

[0043] The accompanying drawings, which form part of this invention, are used to provide a further understanding of the invention. The illustrative embodiments of the invention and their descriptions are used to explain the invention and do not constitute an improper limitation of the invention.

[0044] Figure 1 This is a general description of the communication protocol in the embodiments of the present invention;

[0045] Figure 2 This is the protocol matching and decoding process according to an embodiment of the present invention;

[0046] Figure 3 This is a flowchart of the protocol decoding program according to an embodiment of the present invention;

[0047] Figure 4(a) is a decoding example 1 of an embodiment of the present invention;

[0048] Figure 4(b) is a decoding example 2 of an embodiment of the present invention. Detailed Implementation

[0049] The present invention will be further described below with reference to the accompanying drawings and embodiments.

[0050] It should be noted that the following detailed description is illustrative and intended to provide further explanation of the invention. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.

[0051] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of exemplary embodiments according to the invention. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.

[0052] Terminology Explanation:

[0053] TLV encoding: ASN.1 is an ISO / ITU-T standard, one of its encoding methods, BER (Basic Encoding Rules), is simple and easy to use. It uses triple encoding, which consists of a data message composed of the data type (Tag, L), the data length (L), and the data value (V). TLV is based on binary encoding, encoding data as a byte array in TLV form; that is, TLV is a byte stream data transmission protocol. It specifies that the first byte or several bytes of a data frame represent the data type, followed by one or several bytes representing the data length, and finally the data content.

[0054] TTLV stands for Tag, Type, Length, Value. It adds Type to the TLV encoding to indicate the data type, which facilitates protocol self-description.

[0055] Example 1

[0056] Reference Figure 2This embodiment provides a protocol decoding method based on the general description method of communication protocols as described above, which includes:

[0057] Step 1: Obtain the general description file of the communication protocol, verify the format of the general description file, and parse the elements in the description file;

[0058] Step 2: Convert the protocol matching items and related elements and attributes in the communication protocol description file into communication protocol matching objects, and convert the protocol data items and related elements and attributes in the communication protocol description file into communication protocol data objects;

[0059] Specifically, the converted communication protocol matching object and the communication protocol data object are both placed in memory or cache.

[0060] Step 3: Obtain raw communication message data through communication monitoring;

[0061] Specifically, enable local serial communication or network communication listening.

[0062] Step 4: Perform protocol matching on the original communication message data based on the protocol matching items;

[0063] In step 4, during the process of performing protocol matching on the original communication message data based on protocol matching items:

[0064] The protocol message data and the protocol matching object set are used as input items. According to the definition in the protocol matching object set, the message data at the specified position is obtained, converted according to type, and the converted value is compared with the value in the description file according to the operator in the description file.

[0065] When the logical operation result is true, the matching condition is met, and the verification of the next matching condition continues until all matching conditions of this protocol instruction are met. Then, the message data is considered to have successfully matched this protocol instruction, and the protocol ID is output.

[0066] In the process of matching the original communication message data based on protocol matching items:

[0067] If any condition of this protocol instruction fails to match, the comparison and matching of the matching objects of this protocol instruction will end, and the comparison and matching of the matching object set of the next protocol instruction description file will begin.

[0068] If all matching objects for all protocol instructions fail to match, it indicates that the protocol message data does not match the protocol description file. Log the error and end the processing.

[0069] Step 5: Based on the protocol matching result, perform protocol decoding and output object instances or JSON format data.

[0070] Reference Figure 1 A general method for describing communication protocols, which divides each communication protocol instruction into a general description item, a matching item, and a data item.

[0071] Among them, the general protocol description item is used to define the general description of the protocol;

[0072] Protocol matching items are used to define the matching conditions for automated matching protocol instructions in the software system;

[0073] Protocol data items are used to define the constituent elements of a protocol.

[0074] A communication protocol can consist of multiple instructions. The same protocol uses the same or similar protocol frame structure, but the data portion structures of different protocol instructions differ; a general description method for communication protocols provides a general description for each protocol instruction.

[0075] The protocol instructions consist of a set of general protocol description items, a set of protocol matching items, and a set of protocol definition items.

[0076] The protocol general description item set contains multiple protocol general description items. A protocol general description item is a general description item of the protocol, defining the unique ID of the protocol instruction, the corresponding class name for storing the protocol instruction parsing or encoding result, the definition of the verification item, the definition of the verification data area, the definition of the message data area length item, and the definition of the message data area.

[0077] The protocol matching item set defines the matching conditions for the software system's automated matching protocol instructions. The system compares and matches data packets based on these conditions. If all conditions are met, the match is successful, and the packet can be parsed using the protocol data items in the protocol instruction configuration file. There are mainly two types: byte condition items and bit condition items.

[0078] The protocol data item set defines the constituent elements of the protocol—the protocol data items. Protocol data items include several types such as byte items, bit items, repeating items (including TLV-type repeating items and other types of repeating items), tag items, sub-protocol items, and cryptographic blocks.

[0079] The above protocol items are explained below according to their public and private attributes.

[0080] Description of public attributes of protocol items:

[0081] length: The length is measured in bytes, except in bitDefinition where the unit is bit.

[0082] lengthRef: Length reference, indicating that the length value is referenced from other property values.

[0083] shift: Offset, representing the offset in the definition.

[0084] objectType: Defines the data type in the object-oriented language (such as Java, C#) corresponding to the value of the item, including: Byte, Short, Integer, Long, Float, Double, HEXSTRING (hexadecimal string). When the data is a complex object, it can be a HashMap or a custom class.

[0085] property: The property name of the entity object in an object-oriented language (Java, C#, etc.) that defines the value of the item.

[0086] propertyName: The Chinese name of the property of the entity object in the object-oriented language corresponding to the defined item value.

[0087] ignore: Indicates whether to ignore this configuration item during parsing or encoding. The default value is false, which means not to ignore; true means to ignore, and there is no need to parse or encode.

[0088] showExp: Display expression, a logical expression indicating whether the message appears in the message. true indicates that the message appears, and false indicates that the message does not appear.

[0089] valueExp: A value expression where the property value comes from the result of an expression or a custom method (function) (the data type before the operation must be compatible with the data type of the result). For example, the expression "batteryVoltage / 1000" and the custom function "customFunction(cmd,studentsCount)".

[0090] encoding: encoding format. When Byte is String, it is the encoding format used by the string.

[0091] byteOrder: byte order, BIG_ENDIAN for big-endian and LITTLE_ENDIAN for little-endian. The default is big-endian if not configured.

[0092] General description of the protocol:

[0093] ID element: A unique ID for protocol instructions. It cannot be duplicated and is generally named according to the constraint of "product (model)-protocol version-instruction-encoding / decoding".

[0094] The `className` element is the class name corresponding to the protocol instruction data storage; it can be a custom class or a HashMap.

[0095] The byteOrder element specifies the byte order used for multi-byte values ​​in the protocol instruction. BIG_ENDIAN indicates big-endian or LITTLE_ENDIAN indicates little-endian.

[0096] The `checkCodeItem` element: Defines the checksum (e.g., CRC) for the message. `check` indicates whether message verification is performed. `checkType` is the name of the built-in checksum function, while `customFunction` is a user-defined extended checksum function with higher priority than the built-in function. `Shift` is the offset, which can be 0, positive, or negative. A negative number indicates an offset from the end of the message.

[0097] The `checkDataBlock` element defines the validation data area. The `begin` attribute specifies the start position of the validation message content within the message, and the `end` attribute specifies the end position. The values ​​of `begin` and `end` can be 0, positive, or negative.

[0098] The `dataLengthItem` element defines the length of the data area. `encode` indicates whether the length of the data area is calculated during protocol encoding. `shift` and `length` are the offset and length values ​​calculated in bytes, while `bitShift` and `bitLength` are the offset and length values ​​calculated in bits.

[0099] The dataBlock element defines the data area. The begin attribute is the starting position of the validation message content in the message, and the end attribute is the ending position. The values ​​of begin and end can be 0, positive, or negative.

[0100] The description element contains comments and explanations related to protocol instructions.

[0101] Protocol matching item description:

[0102] The `conditionByte` element defines the matching byte condition. `value` is the value to be compared, and `operator` is the operator (default is equal sign, but can be =, >, >=, <, <=, in, etc.). That is, the value of the length bytes starting from `shift` in the message is operated on with `value`. If the result is true, the matching element is successful.

[0103] The conditionBits element: A collection of conditionBit elements, which can only be the child elements of the conditionByte element and the parent element of the conditionBit element.

[0104] The `conditionBit` element defines the matching bit condition, `value` is the value to be compared, and `operator` is the operator. This element can only be defined within a sub-element of `conditionBits`.

[0105] Protocol data item description:

[0106] byteDef element: Protocol byte item definition, protocol item defined according to bytes.

[0107] The bitDefList element is a collection of protocol bit item definitions. It can only be a child element of the byteDef element and a parent element of the bitDef element.

[0108] The bitDef element defines protocol bit items, specifying data according to bits; this element can only be defined as a child element of the bitDefList element.

[0109] The `repeater` element represents the repeating item (array or collection) in the protocol item. `times` indicates a fixed number of repetitions. `timesRef` indicates a value that references another property for the number of repetitions. Only one of `times` or `timesRef` needs to be set; if both are set, the value of `timesRef` takes precedence. When a `timesRef` referenced property is found simultaneously at the same or different levels, the referenced property at the same level takes precedence. When a `timesRef` reference value spans multiple levels, the property must be identified using the format "abc" (e.g., `student.course.math`).

[0110] The repeater supports two types of repeating items: TLV-type (TLV and TTLV) repeating items and other repeating items (generally, a structure array). `itemType` takes the value of TLV, TTLV, or "". `TLV` indicates a TLV repeating item; `TTLV` indicates a TTLV repeating item. When `itemType` is TLV or TTLV, `tagFieldLength`, `typeFieldLength`, `lengthFieldOption`, and `lengthFieldLength` must be set, and the repeater's child elements can only be tag elements. When `itemType` is "", it indicates other repeating items, and no settings are needed; in this case, the repeater's child elements can be any protocol item element. `tagFieldLength` represents the length of the tag field in the protocol message, `typeFieldLength` represents the length corresponding to the data type field, `lengthFieldOption` indicates whether a length field needs to be configured, and `lengthFieldLength` represents the length of the field containing the value.

[0111] The `tagDef` element defines a tag in TLV encoding and can only be a child element of the `repeator` element. The `tag` attribute represents the tag ID, and the `length` attribute only needs to be explicitly configured during encoding, indicating the number of bytes to use to encode the V (value) in the TLV; it does not need to be configured during decoding. Child elements of the `tag` element can nest elements such as `byteDef`, `repeator`, `subProtocol`, and `encryptBlock`.

[0112] The `subProtocol` element is a subprotocol data item that defines the protocol corresponding to the data. The protocol definition comes from the embedded subprotocol instruction XML definition. `protocolId` is the protocol ID, and `protocolFileName` is the protocol file name. When the data corresponding to the subprotocol is a complex object (the subprotocol data contains multiple basic type attributes), the value of `objectType` can be a HashMap or a custom class.

[0113] The `encryptBlock` element represents an encrypted (data) block, indicating that the data portion of the protocol message is encrypted. Decoding requires decryption before decoding, and encoding requires encryption before encryption. `algorithm` specifies the built-in encryption algorithm, `customFunction` specifies a user-defined extended encryption algorithm (with higher priority than the built-in algorithm), and `key` is the encryption / decryption key.

[0114] Description method:

[0115] Create an XML file and create the root element protocol.

[0116] Based on the protocol content and the general description method attribute description, create protocol general description item elements under the root element and fill in the attribute content, including id, className, byteOrder, checkCodeItem, checkDataBlock, dataLengthItem, dataBlock, and description.

[0117] Based on the protocol content and general description method attribute description, create a protocol matching item collection element conditionItems under the root element and populate the attribute content. Configure elements according to the unique characteristics of the protocol instructions, including conditionByte, conditionBits, and conditionBit elements.

[0118] Based on the protocol content and general description method attributes, create a protocol data item collection element `definitionItems` under the root element, and define child elements. Define protocol items according to the protocol specification order, configure variable references, expressions, and custom methods, variable-length strings and string encoding, define loop items (TLV category and other categories) and nesting according to the array structure type, and configure encryption blocks, sub-protocols, etc.; the elements that need to be configured include `byteDef`, `bitDefList`, `bitDef`, `repeator`, `tagDef`, `encryptBlock`, and `subProtocol` elements.

[0119] The example protocol frame structure is shown in Table 1 below. Unless otherwise specified, this protocol uses little-endian mode to transmit multi-byte data.

[0120] Table 1 Data Frame Format

[0121]

[0122] Table 2 Frame Format Version Number + Data Field Length

[0123]

[0124] BIT0-BIT12: Data field length (the data field includes a fixed header, a variable header, and valid data), in bytes, with values ​​from 0 to 8191.

[0125] BIT13-BIT15: Frame format version number. The initial version must be 1, and the value increases in subsequent versions.

[0126] The frame serial number field is an INT32U type data field that represents the data frame sequence number, as shown in Table 2.

[0127] The control code is a data of type INT16U, and its format is shown in Table 3.

[0128] Table 3 Control Codes

[0129]

[0130] BIT0-BIT2: Format of valid data, value 0b001: Mask format.

[0131] BIT3-BIT7: cmd is the command code, and its possible values ​​are shown in Table 4.

[0132] Table 4 Command Codes

[0133] command code command name describe 0 FreeCmd Free command 1 GetDevInfo Obtain basic device information 2 ReportData Actively report data

[0134] IT8-BIT11: The number of Options in the variable header of the data field, ranging from 0 to 15. A value of 0 indicates that the data frame does not contain a variable header of the data field.

[0135] The variable header for the data field is an optional field, existing only when the Options field of the control code field is not 0. The variable header for the data field consists of multiple Options, each of which is a TLV structure. Each Option consists of a 1-byte Option number, a 1-byte Option data length, and N bytes of Option data. Options can appear in freely combined forms. Its basic form is shown in Table 5, Variable Headers for Data Fields.

[0136] Table 5 Variable Headers for Data Fields

[0137]

[0138]

[0139] The possible values ​​for the Options number are shown in Table 6.

[0140] Table 6. Values ​​for Options Numbers

[0141]

[0142] Valid data is the actual data that needs to be transmitted (such as data collected by sensors, configuration parameters, etc.). The format of parameters in valid data varies depending on the "command code". In the example XML below, the valid data portion uses RC4 encryption.

[0143] The CRC16 checksum is a data of type INT16U, representing the CRC16 checksum from "frame format version number + data field length" to the end of the data field.

[0144] The XML description file for one implementation method of the general description method of the communication protocol corresponding to the above protocol is as follows.

[0145]

[0146]

[0147]

[0148]

[0149]

[0150] The specific protocol decoding implementation flowchart is as follows: Figure 3 As shown, the main process steps are:

[0151] Step a: Obtain the protocol item definition corresponding to the general protocol description file based on the protocol ID obtained from a successful protocol match. Proceed to step b.

[0152] Step b: Verify the input protocol message data according to the verification method in the protocol description file. If a custom verification method is defined, the custom verification takes precedence; otherwise, use the built-in verification method. If the verification passes, proceed to step c; if the verification fails, proceed to step e.

[0153] Step c: Based on the className in the protocol general description item of the protocol general description file, create a class instance object to facilitate data storage after subsequent protocol parsing. Proceed to step d.

[0154] Step d: Protocol block decoding (parsing). The original protocol message data, the set of protocol data items, and a protocol storage class object instance are passed in, and the protocol block decoding (parsing) method is executed. The method in the thick box in the diagram is called the protocol block decoding (parsing) method, which can decode any set of protocol data items. Protocol block decoding includes the following steps and processes:

[0155] Step d1: The protocol block parsing method iterates through the protocol data item set internally, decoding the message according to the data item type. If the protocol data item is a byte item, proceed to step d2; if the protocol data item is a duplicate item, proceed to step d3; if the protocol data item is a sub-protocol item, proceed to step d4; if the protocol data item is an encrypted item, proceed to step d5; if the loop has ended, proceed to step d6.

[0156] Step d2: Byte Item Decoding Process: If the byte item does not contain a bit item, read the bytes according to the byte item definition. If the read bytes are multi-byte numeric message data and the byte order is little-endian, reverse the byte order and then convert the result according to the numeric type to obtain the attribute value. If the byte item contains a bit item, based on the byte item decoding, perform bitwise shift operations on the decoded byte item according to the bit item definition to obtain the conversion result. After the protocol item is decoded, the value is stored in the attribute of the corresponding class object instance according to the protocol definition.

[0157] Step d3: Duplicate Item Decoding Process: Based on the definition, obtain the loop count. Decode the protocol data items in the loop. Decoding involves two cases: First, if it's a TLV-type duplicate item, read and compare the Tag value corresponding to the message data according to the definition. Further, obtain the Length of the Tag's corresponding attribute Value, and then read the Value. If the TLV data item contains nested protocol data items, call the protocol block decoding function. Second, if it's another duplicate item, pass in the duplicate item definition, the message byte array, and the attribute value storage object. Call the protocol block decoding function to obtain the corresponding attribute value. The loop ends. After decoding, the protocol item value is stored in the attribute of the corresponding class object instance according to the protocol definition.

[0158] Step d4: Sub-protocol item decoding process: Obtain the sub-protocol template ID according to the definition, load the protocol data item set of the sub-protocol, and then decode its protocol block. After decoding, the value of the protocol item is stored in the attribute of the corresponding class object instance according to the protocol definition.

[0159] Step d5: Encryption Item Decoding Process: Extract the original protocol message array according to the protocol definition, perform calculations according to the decryption function to obtain the decrypted message array, and then decode the protocol block according to the protocol data item definition set inside the encrypted data item. The decoded protocol item value is stored in the attribute of the corresponding class object instance according to the protocol definition.

[0160] Step d6: After the traversal is complete, return the data storage object or convert the data storage object to JSON and return it. The program ends.

[0161] Step d7: During the protocol data item decoding process in steps d2-d5 above, if there are nested protocol data items within the protocol data item, the protocol block decoding method can be recursively called in order from the top layer to the bottom layer.

[0162] Step d8: During protocol decoding, if there is a valueExp expression or a custom decoding / decryption method, the custom method or expression will be used first; otherwise, the protocol's internal decoding or built-in decryption methods will be used. If an exception occurs, the error message will be logged, and decoding will end.

[0163] Step d9: Implementing custom decoding methods. Custom classes can inherit from a base decoding class, overriding the base class's decoding algorithm. The method can take the protocol message data and the decoded object as input, and can internally write custom decoding logic, returning the decoded object. Each custom decoding class implements only one custom decoding algorithm, configured via a configuration file to enable or disable loading, ensuring that only the necessary custom extension classes are loaded in the project.

[0164] Step e: Record the verification failure log (optional), return an empty value, and the program ends.

[0165] The protocol decoding example based on the protocol general description file takes hexadecimal data of the original message to be decoded as input, the program automatically matches the protocol ID, and outputs JSON data, as shown in the decoding examples in Figure 4(a) and Figure 4(b).

[0166] Example 2

[0167] This embodiment provides a protocol decoding device based on a general description of communication protocols, which includes:

[0168] The element parsing module is used to obtain the general description file of the communication protocol, verify the format of the general description file, and parse the elements in the description file;

[0169] The protocol conversion module is used to convert the protocol matching item related elements and attributes in the communication protocol description file into communication protocol matching objects, and to convert the protocol data item related elements and attributes in the communication protocol description file into communication protocol data objects.

[0170] The communication listening module is used to listen for and acquire raw communication message data.

[0171] The protocol matching module is used to perform protocol matching on the original communication message data based on the protocol matching items.

[0172] The protocol decoding module is used to decode the protocol based on the protocol matching results and output object instances or JSON format data.

[0173] It should be noted that each module in this embodiment corresponds one-to-one with each step in embodiment two, and their specific implementation processes are the same, so they will not be repeated here.

[0174] Example 3

[0175] This embodiment provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps in the protocol decoding method based on a general description of communication protocols as described in Embodiment 1 above.

[0176] Example 4

[0177] This embodiment provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, it implements the steps in the protocol decoding method based on the general description of communication protocols as described in Embodiment 1 above.

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

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

[0180] The above description is merely a preferred embodiment of the present invention and is not intended to limit the invention. Various modifications and variations can be made to the present invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention.

Claims

1. A protocol decoding method based on a general description of communication protocols, characterized in that, include: Obtain the general description file of the communication protocol, verify the format of the general description file, and parse the elements in the description file; Convert the protocol matching items and related elements and attributes in the communication protocol description file into communication protocol matching objects, and convert the protocol data items and related elements and attributes in the communication protocol description file into communication protocol data objects; The system acquires raw communication message data through communication interception; performs protocol matching on the raw communication message data based on protocol matching items; and performs protocol decoding based on the protocol matching results, outputting object instances or JSON format data. The general description file of the communication protocol describes each communication protocol instruction in three parts: general description items, protocol matching items, and protocol data items. The general protocol description item is used to define a general description of the protocol; the protocol matching item is used to define the matching conditions for the software system to automatically match protocol instructions; the protocol data item is used to define the constituent elements of the protocol. The protocol data items include byte items, bit items, repeat items, tag items, sub-protocol items, and encryption blocks; The protocol item's public property is `lengthRef`, which is a length reference that indicates the length value is referenced from other property values. showExp: Display expression, a logical expression indicating whether the message appears in the message. true indicates that the message appears, and false indicates that the message does not appear. valueExp: Value expression, the property value comes from the result of an expression or a custom method, and the data type before the operation must be compatible with the data type of the result after the operation; Protocol general description items: checkCodeItem is the message verification item definition. check indicates whether message verification is performed. checkType is the name of the built-in verification function. customFunction is the user-defined extended verification function, which has higher priority than the built-in function. Shift is the offset, which can be 0, a positive number, or a negative number. A negative number indicates that the offset starts from the end of the message. dataLengthItem: Defines the length of the data area. encode indicates whether the length of the data area is calculated during protocol encoding; shift and length are the offset and length values ​​calculated in bytes, and bitShift and bitLength are the offset and length values ​​calculated in bits. dataBlock: Defines the data block. The begin attribute is the starting position of the checksum message content in the message, and the end attribute is the ending position. The values ​​of begin and end can be 0, positive numbers, or negative numbers. Protocol data items: The repeater element represents the repeating item in the protocol item, supporting TLV-type repeating items; times indicates that the number of repetitions is a fixed value; timesRef indicates that the number of repetitions is a reference to the value of other attributes. Only one of times and timesRef needs to be set. If both are set, the value of timesRef takes precedence. When a timesRef reference property is found at the same or different levels, the reference property at the same level takes precedence; when a timesRef reference value crosses levels, the property is identified using the format a .b .c. encryptBlock: Indicates that the data part of the protocol message is an encrypted data block. Decoding requires decryption before decoding, and encoding requires encoding before encryption. algorithm is the built-in encryption algorithm, customFunction is the user-defined extended encryption algorithm, which has higher priority than the built-in encryption algorithm, and key is the encryption / decryption key.

2. The protocol decoding method based on a general description of communication protocols as described in claim 1, characterized in that, The general description items of the protocol include the unique ID definition of the protocol instruction, the corresponding class name definition for storing the protocol instruction parsing or encoding result, the verification item definition, the verification data area definition, the message data area length item definition, and the message data area definition.

3. The protocol decoding method based on a general description of communication protocols as described in claim 1, characterized in that, The protocol matching items include byte condition items and bit condition items.

4. The protocol decoding method based on a general description of communication protocols as described in claim 1, characterized in that, In the process of matching the original communication message data based on protocol matching items: The protocol message data and the protocol matching object set are used as input items. According to the definition in the protocol matching object set, the message data at the specified position is obtained, converted according to type, and the converted value is compared with the value in the description file according to the operator in the description file. When the logical operation result is true, the matching condition is met, and the verification of the next matching condition continues until all matching conditions of this protocol instruction are met. Then, the message data is considered to have successfully matched this protocol instruction, and the protocol ID is output.

5. The protocol decoding method based on a general description of communication protocols as described in claim 1, characterized in that, In the process of matching the original communication message data based on protocol matching items: If any condition of this protocol instruction fails to match, the comparison and matching of the matching objects of this protocol instruction will end, and the comparison and matching of the matching object set of the next protocol instruction description file will begin. If all matching objects for all protocol instructions fail to match, it indicates that the protocol message data does not match the protocol description file. Log the error and end the processing.

6. A protocol decoding apparatus based on a general description of communication protocols, employing the protocol decoding method based on a general description of communication protocols as described in any one of claims 1-5, characterized in that, include: The element parsing module is used to obtain the general description file of the communication protocol, verify the format of the general description file, and parse the elements in the description file; The element conversion module is used to convert the protocol matching item related elements and attributes in the communication protocol description file into communication protocol matching objects, and to convert the protocol data item related elements and attributes in the communication protocol description file into communication protocol data objects. The communication listening module is used to listen for and acquire raw communication message data. The protocol matching module is used to perform protocol matching on the original communication message data based on the protocol matching items. The protocol decoding module is used to decode the protocol based on the protocol matching result and output object instances or JSON format data. The general description file of the communication protocol describes each communication protocol instruction in three parts: general description items, protocol matching items, and protocol data items. The general protocol description item is used to define a general description of the protocol; the protocol matching item is used to define the matching conditions for the software system to automatically match protocol instructions; and the protocol data item is used to define the constituent elements of the protocol.

7. The protocol decoding device based on a general description of communication protocols as described in claim 6, characterized in that, The general description items of the protocol include the unique ID definition of the protocol instruction, the corresponding class name definition for storing the protocol instruction parsing or encoding result, the verification item definition, the verification data area definition, the message data area length item definition, and the message data area definition.

8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps in the protocol decoding method based on the general description of the communication protocol as described in any one of claims 1-5.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the program, it implements the steps in the protocol decoding method based on the general description of the communication protocol as described in any one of claims 1-5.

Citation Information

Patent Citations

  • General application layer network communication protocol application method for complicated system

    CN103780624A

  • Generalized data analysis method based on xml file

    CN110457526A