CN115242896A - Dynamic message analysis method and device, electronic equipment and computer readable storage medium - Google Patents

Dynamic message analysis method and device, electronic equipment and computer readable storage medium Download PDF

Info

Publication number
CN115242896A
CN115242896A CN202210906596.6A CN202210906596A CN115242896A CN 115242896 A CN115242896 A CN 115242896A CN 202210906596 A CN202210906596 A CN 202210906596A CN 115242896 A CN115242896 A CN 115242896A
Authority
CN
China
Prior art keywords
message
data
analyzed
dynamic
definition
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202210906596.6A
Other languages
Chinese (zh)
Other versions
CN115242896B (en
Inventor
陈节
冯丹荣
苟孟生
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Ningbo Sanxing Medical and Electric Co Ltd
Original Assignee
Ningbo Sanxing Medical and Electric Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Ningbo Sanxing Medical and Electric Co Ltd filed Critical Ningbo Sanxing Medical and Electric Co Ltd
Priority to CN202210906596.6A priority Critical patent/CN115242896B/en
Publication of CN115242896A publication Critical patent/CN115242896A/en
Application granted granted Critical
Publication of CN115242896B publication Critical patent/CN115242896B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L69/00Network arrangements, protocols or services independent of the application payload and not provided for in the other groups of this subclass
    • H04L69/22Parsing or analysis of headers
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/50Reducing energy consumption in communication networks in wire-line communication networks, e.g. low power modes or reduced link rate

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Communication Control (AREA)

Abstract

The embodiment of the invention provides a dynamic message analysis method, a dynamic message analysis device, electronic equipment and a computer readable storage medium, belonging to the field of data processing, wherein the method comprises the following steps: under the condition that the message to be analyzed is legal and belongs to the dynamic data type, the data type definition of the service type of the message to be analyzed and the structural body definition of the dynamic member are called from a prestored configuration file, so that the message to be analyzed is analyzed based on the message structure, the data type definition and the structural body definition of the dynamic member to obtain an analysis result, the analysis of the message with the data length being not fixed is realized, the message to be analyzed is suitable for analyzing the 698 message, and the analysis efficiency and the analysis accuracy are improved.

Description

Dynamic message analysis method and device, electronic equipment and computer readable storage medium
Technical Field
The present invention relates to the field of data processing, and in particular, to a dynamic packet parsing method, apparatus, electronic device, and computer-readable storage medium.
Background
698 the protocol is an object-oriented electricity consumption information data exchange protocol, and specifies a data transmission protocol with interoperability for an object, which is adopted among a master station, an acquisition terminal or an electric energy meter of an electric energy information acquisition and management system. 698 the protocol belongs to dynamic messaging, and the message content and hence the message length will vary according to the objects served.
The traditional fixed message analysis mode is not suitable for 698 message analysis, and the manual analysis mode of the 698 message has low efficiency and is easy to make mistakes.
Disclosure of Invention
In view of the above, the present invention provides a dynamic message parsing method, apparatus, electronic device and computer readable storage medium, which can parse 698 messages and improve parsing efficiency and parsing accuracy.
In order to achieve the above object, the embodiments of the present invention adopt the following technical solutions.
In a first aspect, an embodiment of the present invention provides a dynamic packet parsing method, where the method includes:
acquiring a message to be analyzed, and determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs under the condition that the message to be analyzed is legal;
if the service type belongs to the dynamic data type, calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file;
the first target definition is a data type definition of the service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length;
and analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
Further, after the step of determining the service type of the packet to be analyzed, the method further includes:
if the service type belongs to a fixed data type, calling a first target definition corresponding to the service type from a pre-stored configuration file;
and analyzing the message to be analyzed based on the message structure and the first target definition.
Further, the message to be analyzed comprises first inherent type data, service data and second inherent type data which are sequentially arranged;
the step of analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result includes:
according to the message structure, sequentially classifying and analyzing the first inherent type data and the second inherent type data to obtain description characteristics corresponding to each digit in the first inherent type data and the second inherent type data;
analyzing the service data by combining the first target definition and the second target definition to obtain the description characteristics corresponding to each number in the service data;
and performing association expression on each number of the message to be analyzed and the corresponding description characteristics to obtain an analysis result.
Further, the message to be analyzed comprises first inherent type data, service data and second inherent type data which are sequentially arranged;
the step of parsing the message to be parsed based on the message structure and the first target definition includes:
according to the message structure, sequentially classifying and analyzing the first inherent type data and the second inherent type data to obtain description characteristics corresponding to each digit in the first inherent type data and the second inherent type data;
analyzing the service data according to the first target definition to obtain the description characteristics corresponding to each number in the service data;
and carrying out associated representation on each number of the message to be analyzed and the corresponding description characteristics to obtain an analysis result.
Further, after the step of obtaining the message to be analyzed, and before the step of determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs, the method further includes:
and judging whether the message to be analyzed is legal or not based on the message structure of the protocol to which the message to be analyzed belongs.
Further, the step of determining whether the message to be analyzed is legal based on the message structure of the protocol to which the message to be analyzed belongs includes:
extracting initial characters of the message to be analyzed based on a target message structure of a preset target protocol;
judging whether the initial character accords with the message initial definition of the target protocol, if so, extracting a first check value of a frame header check bit from the message to be analyzed according to the target message structure, and checking data before the frame header check bit to obtain a second check value;
judging whether the first check value is consistent with the second check value, if so, extracting a third check value of a frame check bit from the message to be analyzed according to the target message structure, and checking data before the frame check bit to obtain a fourth check value;
and judging whether the third check value is consistent with the fourth check value, if so, judging that the message to be analyzed is legal.
Further, the step of determining whether the message to be analyzed is legal based on the message structure of the protocol to which the message to be analyzed belongs further includes:
and if the initial character does not accord with the message initial definition of the target protocol, the first check value is inconsistent with the second check value, or the third check value is inconsistent with the fourth check value, judging that the message to be analyzed is illegal.
In a second aspect, an embodiment of the present invention provides a dynamic packet parsing apparatus, including a preprocessing module, a calling module, and a parsing module;
the preprocessing module is used for acquiring a message to be analyzed, and determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs under the condition that the message to be analyzed is legal;
the calling module is used for calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file if the service type belongs to a dynamic data type;
the first target definition is a data type definition of the service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length;
and the analysis module is used for analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
In a third aspect, an embodiment of the present invention provides an electronic device, including a processor and a memory, where the memory stores a computer program that can be executed by the processor, and the processor can execute the computer program to implement the dynamic packet parsing method according to the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the dynamic packet parsing method according to the first aspect.
According to the dynamic message parsing method, the dynamic message parsing device, the electronic device and the computer-readable storage medium provided by the embodiment of the invention, under the condition that the message to be parsed is determined to be legal, the service type of the message to be parsed is determined, and if the service type belongs to a dynamic data type (namely the data length is not fixed), the message to be parsed is parsed to obtain a parsing result from a first target definition and a second target definition of a pre-stored configuration file cargo service type, so that the parsing of the message with the data length not fixed is realized by combining a message structure, the first target definition and the second target definition, and the parsing efficiency and the parsing accuracy are improved.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 shows one of block schematic diagrams of an electronic device provided by an embodiment of the present invention.
Fig. 2 is a flowchart illustrating one of the dynamic message parsing methods according to the embodiment of the present invention.
Fig. 3 is a second flowchart illustrating a dynamic message parsing method according to an embodiment of the present invention.
Fig. 4 shows a schematic flow diagram of part of the sub-steps of step S102 in fig. 3.
Fig. 5 is a schematic block diagram illustrating a dynamic packet parsing apparatus according to an embodiment of the present invention.
Fig. 6 shows a second block schematic diagram of the electronic device according to the embodiment of the present invention.
An icon: 100-an electronic device; 110-dynamic message parsing means; 120-a pre-processing module; 130-calling module; 140-resolution module.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present invention without making any creative effort, shall fall within the protection scope of the present invention.
It is noted that relational terms such as "first" and "second," and the like, may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrases "comprising a," "8230," "8230," or "comprising" does not exclude the presence of additional like elements in a process, method, article, or apparatus that comprises the element.
698 the protocol is an object-oriented electricity consumption information data exchange protocol, combining related data and methods into a whole view. The 698 protocol specifies the data transmission protocol with interoperability for the object between the master station and the collection terminal of the electric energy information collection and management system or the electric energy meter, and relates to services such as a communication architecture, a data link layer, an application layer, interface classes, object identifiers and the like.
698 the protocol belongs to dynamic messages, the content of which varies according to the objects served, and therefore the length of the message. 698 the protocol is far more complex than the 645 and 376 protocols. A message based on the 698 protocol is called a 698 message, the conventional fixed-length message analysis mode is not suitable for the 698 message analysis, and the manual analysis mode of the 698 message is time-consuming, labor-consuming, low in efficiency and easy to make mistakes.
Based on the above consideration, the embodiment of the present invention provides a dynamic message parsing scheme, which can provide a dynamic message parsing method suitable for 698 messages, and can solve the problems of time and labor consumption caused by manual parsing, low efficiency and easy error.
The dynamic message parsing method provided in the embodiment of the present invention may be applied to the electronic device 100 shown in fig. 1. The dynamic message parsing method provided by the embodiment of the present invention may be developed into an application program in a manner of combining python and a Qt tool, or in a manner of combining C + + and a Qt tool, and the application program is run on the electronic device 100. Also, the application may be a desktop application.
The memory of the electronic device 100 is also pre-stored with a configuration file, in which message structure definitions of various dynamic messages such as 698 messages, data type definitions of various service types of each message, and structure definitions of dynamic members of each service type are stored. The dynamic member is a member with variable data length.
For example, if the service type is a response for reading an attribute of an object, the object is a voltage, and the attribute is 2, the service type includes a value of the read voltage, where the value is a value with a non-fixed length, and at this time, the value of the voltage, that is, the result of the service type, is a dynamic member. The structural definition of the dynamic member describes the data composition of the read voltage values.
In more detail, the message of each protocol may correspond to a configuration file, and the configuration file records a message structure of the protocol, a data type definition of each service type of the message of the protocol, and a structure definition of a dynamic member of each service type.
When the electronic device 100 runs the application program, after the message to be analyzed is input into the electronic device 100, the service type of the message to be analyzed is determined under the condition that the message to be analyzed is determined to be legal, and if the service type belongs to the dynamic data type, the first target definition and the second target definition of the service type are obtained from the configuration file, so that the message to be analyzed is analyzed based on the message structure of the protocol to which the message to be analyzed belongs, the first target definition and the second target definition, and an analysis result is obtained.
Among them, the electronic device 100 may be, but is not limited to: personal computers, notebook computers, tablet computers, personal wearable devices.
In one embodiment, referring to fig. 2, the dynamic packet parsing method provided by the present invention may include the following steps. In this embodiment, the dynamic message parsing method is applied to the electronic device 100 in fig. 1 for example.
S101, obtaining a message to be analyzed.
The message to be analyzed may be manually input to the electronic device 100 by a worker, or may be directly transmitted to the electronic device 100 by a response device.
S103, under the condition that the message to be analyzed is legal, determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs.
When the message to be parsed is a message based on the 698 protocol, the service types may be, but are not limited to: pre-connection request, read response, setting request, reporting request, proxy request, time synchronization service and the like.
The read response may be a response to read a certain property of a certain object, such as a read voltage value, a current value, and power.
After the message to be analyzed is acquired, if it is determined that the message to be analyzed is legal, the electronic device 100 may determine the protocol to which the message to be analyzed belongs according to the initial character of the message, so as to acquire the message structure information of the message to be analyzed from the configuration file. It should be understood that the message structure is an overall structure of the protocol message, and includes information such as description characteristics and sequence of each data bit of the message.
For example, the initial characters of the 698 message are all 68. By looking up the initial character, the protocol to which the message to be analyzed belongs can be determined.
After the message structure of the protocol to which the message to be analyzed belongs is obtained, the service type can be determined according to the message to be analyzed.
For example, a message belonging to the 698 protocol includes first inherent type data, service data, and second inherent type data arranged in order. The first and second inherent type data are structures that any 698 message would have.
In the message of the 698 protocol, the first inherent type of data includes data bits of: start character, length, control field, server address, client address, and frame header check in sequence. The second intrinsic type includes data bits of: a sequentially arranged frame checksum terminator. The tail of the first inherent type data is connected with the head data bit of the service data, and the tail data bit of the service data is connected with the head data bit of the second inherent type data. The data length of each data bit of the first inherent type data and the second inherent type data is known.
The number of data bits and the order of the data bits in the service data are determined by the actual object-oriented. The first data bits of the service data are all of the service type, and the data length of the service type bits is also known.
Therefore, when the message to be analyzed is 698 message, the first data bit of the service data can be directly extracted to determine the service type.
And S105, if the service type belongs to the dynamic data type, calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file.
The first target definition is a data type definition of a service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length.
A specific byte (i.e., service type) in the message to be parsed identifies what class the message belongs to, and thus determines the first target definition. After the message class is determined, the overall structure of the message, i.e. the second object definition, can be determined. Each structural member in the second object definition is preceded by a type identifier from which the length of the member can be determined.
The electronic device 100 stores a configuration file for each transmission protocol, and the classification of each service type recorded with the protocol in the configuration file is a dynamic data type or a fixed data type. The fixed data type is that the length of each data bit of the service data is fixed, and the dynamic data type is that the length of at least one data bit of the service data is changed.
After the service type is determined, the classification of the service type is checked, and whether the service type belongs to a fixed data type or a dynamic data type can be determined.
And if the service type of the message to be analyzed belongs to the dynamic data type, extracting the data type definition of the service type from the configuration file as a first target definition, and extracting the structural body definition of the dynamic member in the data type definition as a second target definition.
And S107, analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
After the message structure, the first target definition and the second target definition of the message to be analyzed are determined, each data bit of the message to be analyzed can be analyzed in sequence to obtain an analysis result.
In the above dynamic message parsing method, when the message to be parsed is of a dynamic data type, the first target definition and the second target definition of the service data of the message to be parsed can be determined from the configuration file, and each data bit of the message to be parsed is sequentially parsed by combining the message structure of the overall structure of the protocol to which the message to be parsed belongs, so as to obtain a parsing result.
Compared with the existing fixed-length message analysis method, the dynamic message analysis method introduces the first target definition and the second target definition to analyze the dynamically changing data bits for the message of the dynamic data type, thereby realizing the analysis of the dynamic message and improving the accuracy of the dynamic message analysis. Compared with a method for manually analyzing the dynamic message, the dynamic message analyzing method can improve the analyzing efficiency.
In addition, the dynamic message analysis method provided by the invention can also analyze the message to be analyzed with fixed data type. Referring to fig. 3, the dynamic message parsing method further includes steps S104 and S106, where S104 is executed after step S103, and the message to be parsed with a fixed data type is parsed through steps S104 and S106.
And S104, if the service type belongs to the fixed data type, calling a first target definition corresponding to the service type from a pre-stored configuration file.
In fact, if the service type is a fixed data type, only the data type definition (which is a byte identifier) of the service type is defined in the configuration file, and the data type definition is used as the first target definition. There are several types of service types, with different service types having different definition target definitions. The type of the message can be determined according to the service type, and the messages of different service types correspond to different data structures.
And S106, analyzing the message to be analyzed based on the message structure and the first target definition.
The messages belonging to the fixed data type are messages with fixed length, and the structure of the messages with fixed length is fixed. The message can be parsed byte by byte according to the first target definition (i.e. the definition of the service type of the message protocol) and the structure of the protocol to which the message to be parsed belongs.
Through the steps S101 to S106, the message to be analyzed with the fixed data type can be quickly analyzed.
In order to determine whether the message to be analyzed is legal or not, the accuracy of analysis is improved. Referring to fig. 3, the dynamic message parsing method further includes step S102, where step S102 is executed after step S101 and before step S103.
S102, judging whether the message to be analyzed is legal or not based on the message structure of the protocol to which the message to be analyzed belongs.
Based on the above, the protocol to which the message to be analyzed belongs can be determined by the initial character of the message to be analyzed, and the message structure of the protocol can be further obtained, so that whether the message to be analyzed is legal or not can be judged based on the message structure.
It should be understood that messages of different protocols may have different ways to determine whether the message to be parsed is legal. The adaptive setting can be made according to the legal criteria of the actual protocol.
If the message to be analyzed is 698 message, in an embodiment, referring to fig. 4, the step S102 may be implemented by the following steps.
S1021, based on the target message structure of the preset target protocol, extracting the initial character of the message to be analyzed.
S1022, judge whether the initial character accords with the message initial definition of the target protocol. If yes, go to step S1023, otherwise go to step S1028.
For example, the target protocol is the 698 protocol and the start of the message is defined as 68. At this time, if the initial character of the message to be analyzed is 68, it is matched, if not, it is not matched.
S1023, according to the target message structure, extracting the first check value of the frame head check bit from the message to be analyzed, and checking the data before the frame head check bit to obtain a second check value.
As is known, when the protocol is 698, the first inherent type data of the 698 packet has a frame header check bit, and a value of the frame header check bit is a first check value. And performing ARC check on data before a frame header check bit of the message to be analyzed to obtain a second check value.
S1024, judging whether the first check value is consistent with the second check value. If so, go to step S1025, otherwise go to step S1028.
The first check value and the second check value are different, which means that the message to be analyzed may be in error.
S1025, extracting a third check value of the frame check bit from the message to be analyzed according to the target message structure, and checking data before the frame check bit to obtain a fourth check value.
As known, when the protocol is 698 protocol, the second inherent type data of 698 packet has a frame check bit, and the value of the frame header check bit is the third check value. And performing ARC check on the data before the frame check bit of the message to be analyzed to obtain a fourth check value.
And S1026, judging whether the third check value is consistent with the fourth check value. If so, perform step S1027, otherwise perform step S1028.
Similarly, if the third check value is not consistent with the fourth check value, it indicates that the message to be analyzed is incorrect.
S1027, judging whether the message to be analyzed is legal.
S1028, judging that the message to be analyzed is illegal.
If the initial character does not accord with the message initial definition of the target protocol, the first check value is inconsistent with the second check value, or the third check value is inconsistent with the fourth check value, it means that the message to be analyzed is wrong and illegal.
Through the steps S1021 to S1028, it can be determined whether the message to be analyzed is legal.
For a more detailed description of the process of obtaining the parsed result, for ease of understanding.
In one embodiment, the implementation logic of step S106 may be: the first inherent type data, the service data and the second inherent type data of the message to be analyzed can be distinguished according to the message structure, namely, the message to be analyzed is wholly divided based on the message structure. After the first inherent type data, the service data and the second inherent type data are divided, the data bits are analyzed in sequence by combining the first target definition.
The first inherent type data and the second inherent type data are respectively data with fixed byte length in a head area and a tail area of the message to be analyzed, and are determined by a protocol of the message. The service data is determined by the service type of the message to be analyzed, and is generally located between the first inherent type data and the second inherent type data, and whether the length of the service data is fixed is determined by whether the service type is dynamic data. For example, if the service type belongs to a dynamic data type, the length of the service data is not fixed, whereas the length of the service data is fixed.
Since the lengths of the respective data bits of the first inherent type data and the second inherent type data are fixed, the first inherent type data and the second inherent type data can be read out in sequence according to the lengths of the respective data bits. The first inherent type data and the second inherent type data are classified and analyzed in sequence according to the message structure, and description features corresponding to each digit in the first inherent type data and the second inherent type data are obtained.
Description features, that is, description objects of the respective data bits, include, but are not limited to: start character, length, control field, server address, client address, frame header check, type of service, frame check, and end character.
The first object definition, i.e. the data type definition of the service type, includes the order and length of the individual data bits of the service data. Therefore, according to the first target definition, the service data can be analyzed in sequence to obtain the description features corresponding to each number in the service data.
And finally, carrying out associated representation on each digit of the analysis message and the corresponding description characteristics to obtain an analysis result.
Taking 698 message as an example, when the message to be analyzed is a pre-connection request message, the pre-connection request message is: 68 1E 00 81 05 20 00 00 FB F9 01 00 00 3C 07 E6 01 0C 03 09 1C 2A 00 B7 10 C9 16. The service type of the pre-connection request message is a pre-connection request and belongs to a fixed data type.
The analysis of the pre-connection request message is performed by the method, and the obtained analysis result is shown in table 1.
TABLE 1
Figure BDA0003772703470000131
In one embodiment, the implementation logic of step S107 may be: and distinguishing the first inherent type data, the service data and the second inherent type data of the message to be analyzed according to the message structure, namely integrally dividing the message to be analyzed based on the message structure. After the first inherent type data, the service data and the second inherent type data are divided, the data bits are analyzed in sequence by combining the message structure, the first target definition and the second target definition.
And according to the message structure, sequentially classifying and analyzing the first inherent type data and the second inherent type data to obtain the description characteristics corresponding to each digit in the first inherent type data and the second inherent type data.
And for the service data in the message to be analyzed, sequentially analyzing each data bit in the service data by combining the first target definition and the second target definition to obtain the description characteristics corresponding to each digit in the service data.
In more detail, each data bit in the service data is divided by using the first target definition, if the data bit is not a dynamic member, the data bit is directly analyzed, and if the data bit is the dynamic member, the dynamic member in the service data is analyzed by using the second target definition to obtain the description characteristics corresponding to each number.
And finally, carrying out associated representation on each digit of the analysis message and the corresponding description characteristics to obtain an analysis result.
Taking 698 message as an example, when the message to be analyzed is a response message for reading an object attribute, the message is: 68 24 00 C3 05 75 50 00 00 11 B0 A1 35 85 3F 20 00 02 00 01 01 03 12 3D 12 00 00 12 00 00 00 00 00 00 00 C3 F5. The service type of the message for reading the response of one object attribute is a read response, and belongs to a dynamic data type. The data type definition of the response message reading an object attribute may be as shown in table 2.
TABLE 2
Figure BDA0003772703470000141
Figure BDA0003772703470000151
As can be seen from table 2, the data structure of the packet is "service number-priority-ACD" and "an object attribute and its result". The "service sequence number-priority-ACD" is a byte of data, and can be directly parsed. The data size of an "object attribute and its result" is variable and is determined according to the actual definition of the "object attribute descriptor". When "and its result" are 1 byte, it can be directly parsed. When "and its result" are "data", then the definition of the corresponding "object attribute descriptor" needs to be looked up in the configuration file.
When the "object attribute" is "attribute 2 of voltage", and "and its result" is "data", also "and its result" are dynamic members. At this time, the structure definition of the "object attribute descriptor" of "and result thereof" can be as shown in table 3.
TABLE 3
Figure BDA0003772703470000152
In the parsing process, the structure of the object attribute descriptor is found according to the object id and the attribute id in table 3. These two data are split from an "object attribute descriptor" (OAD), the upper 2 bytes of which are the object identification and the lower 2 bytes are the attribute number.
At parsing time, the "dataType" is translated (which is a specific definition of the object attribute descriptor), the attribute 2 of the voltage has only one member, and the data type is "long-signed". The "interface class object" for the voltage is 3 ("classId" in the structure). The definition of the interface class object 3 attribute 2 in table 3, i.e. the structure definition, can be as shown in table 4.
TABLE 4
Figure BDA0003772703470000161
As can be seen from Table 4, the "dataType" of the interface class object is an array, and the attributes 2 indicating the object identifiers belonging to the class object are all arrays, but the data type ("instance-specific") is uncertain and needs to be determined according to the specific definition in the "object attribute descriptor". The data type ("instaccnce-specific") of the structure corresponding to the property 2 of the voltage is defined as "long-signed".
Therefore, the above method is used to analyze the message of the response of reading an object attribute, and the final analysis result is shown in table 5.
TABLE 5
Figure BDA0003772703470000162
Figure BDA0003772703470000171
The concept of the dynamic message parsing method provided by the present invention is that a series of structural bodies and interface class objects in a transmission protocol (for example, a 698 protocol) to be parsed are defined in a configuration file (the format of the configuration file may be a json format, and the structural bodies and the interface class objects are all attributes, operation methods and setting methods of all defined object identifiers), when a message to be parsed is obtained, an overall structure of the message to be parsed is determined, and then a first target definition and a second target definition (or a first target definition) are determined according to whether the message is a dynamic data type, so as to perform detail parsing on the message to be parsed.
The dynamic message analysis method provided by the invention can be used for rapidly analyzing the dynamic messages such as 698 messages and the like, and can improve the efficiency and the accuracy. Moreover, the method has expandability and maintainability, and when a new structure body and a new class object exist, only the related configuration file needs to be modified. An application program of the dynamic message parsing method can be designed by combining python and QT tools (or C + + and QT tools), and the implementation of the application program can comprise a parsing result output interface which can be attractive and can define theme styles in a user-defined mode.
It should be understood that although the various steps in the flowcharts of fig. 2-4 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not limited to being performed in the exact order illustrated and, unless explicitly stated herein, may be performed in other orders.
Based on the concept of the above dynamic message parsing method, in one embodiment, referring to fig. 5, a dynamic message parsing apparatus 110 is provided, where the dynamic message parsing apparatus 110 includes a preprocessing module 120, a calling module 130, and a parsing module 140.
The preprocessing module 120 is configured to obtain a message to be parsed, and determine a service type of the message to be parsed according to a message structure of a protocol to which the message to be parsed belongs when the message to be parsed is legal.
The invoking module 130 is configured to, if the service type belongs to the dynamic data type, invoke a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file.
The first target definition is the data type definition of the service type, the second target definition is the structural body definition of the dynamic member of the service type, and the dynamic member is the member with variable data length.
The parsing module 140 is configured to parse the message to be parsed based on the message structure, the first target definition, and the second target definition, so as to obtain a parsing result.
In the above dynamic message parsing apparatus 110, when the preprocessing module 120 determines that the message to be parsed is legal and belongs to a dynamic data type, the calling module 130 parses the message to be parsed to obtain a parsing result from the first target definition and the second target definition of the pre-stored configuration file cargo service type, so that the parsing module 140 can parse the message to be parsed to obtain a parsing result in combination with the message structure, the first target definition, and the second target definition, thereby implementing parsing of the message with an unfixed data length. The dynamic message parsing device 110 is suitable for parsing 698 messages, and can improve parsing efficiency and parsing accuracy.
For the specific limitations of the dynamic packet parsing apparatus 110, reference may be made to the above limitations of the dynamic packet parsing method, which is not described herein again. All or part of the modules in the dynamic message parsing apparatus 110 may be implemented by software, hardware, or a combination thereof. The modules may be embedded in hardware or independent from the processor in the dynamic message analysis device 110, or may be stored in software in the memory in the dynamic message analysis device 110, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, an electronic device 100 is provided, the internal structure of which may be as shown in FIG. 6. The electronic device 100 includes a processor, a memory, a communication interface, a display screen, and an input device connected through a system bus. Wherein the processor of the electronic device 100 is configured to provide computing and control capabilities. The memory of the electronic device 100 includes a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the electronic device 100 is used for performing wired or wireless communication with an external terminal, and the wireless communication may be implemented through WIFI, an operator network, near Field Communication (NFC), or other technologies. The computer program is executed by a processor to implement a dynamic message parsing method.
Those skilled in the art will appreciate that the structure shown in fig. 6 is a block diagram of only a portion of the structure associated with the inventive arrangements, and does not constitute a limitation on the electronic device 100 to which the inventive arrangements are applied, and that a particular electronic device 100 may include more or less components than those shown in fig. 8, or may combine certain components, or have a different arrangement of components.
In one embodiment, the dynamic message parsing apparatus 110 provided by the present invention can be implemented in a form of a computer program, and the computer program can be run on the electronic device 100 shown in fig. 6. The memory of the electronic device 100 may store various program modules constituting the dynamic message parsing apparatus 110, such as the preprocessing module 120, the calling module 130 and the parsing module 140 shown in fig. 5. The computer program constituted by the respective program modules causes the processor to execute the steps in the dynamic message parsing method described in this specification.
For example, the electronic device 100 shown in fig. 6 may execute steps S101 and S103 through the preprocessing module 120 in the dynamic message parsing method shown in fig. 5. The electronic apparatus 100 may perform step S105 through the calling module 130. The electronic device 100 may perform step S107 through the parsing module 140.
In one embodiment, an electronic device 100 is provided comprising a memory storing a computer program and a processor implementing the following steps when the processor executes the computer program: acquiring a message to be analyzed, and determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs under the condition that the message to be analyzed is legal; if the service type belongs to the dynamic data type, calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file; the first target definition is a data type definition of a service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length; and analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of: acquiring a message to be analyzed, and determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs under the condition that the message to be analyzed is legal; if the service type belongs to the dynamic data type, calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file; the first target definition is a data type definition of a service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length; and analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
In the embodiments provided by the present invention, it should be understood that the disclosed apparatus and method may be implemented in other manners. The apparatus embodiments described above are merely illustrative and, for example, the flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present invention. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present invention may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
The functions may be stored in a computer-readable storage medium if they are implemented in the form of software functional modules and sold or used as separate products. Based on such understanding, the technical solution of the present invention or a part thereof which substantially contributes to the prior art may be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (10)

1. A dynamic message parsing method, the method comprising:
acquiring a message to be analyzed, and determining the service type of the message to be analyzed according to the message structure of a protocol to which the message to be analyzed belongs under the condition that the message to be analyzed is legal;
if the service type belongs to the dynamic data type, calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file;
the first target definition is a data type definition of the service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length;
and analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
2. The dynamic message parsing method of claim 1, wherein after the step of determining the service type of the message to be parsed, the method further comprises:
if the service type belongs to a fixed data type, calling a first target definition corresponding to the service type from a pre-stored configuration file;
and analyzing the message to be analyzed based on the message structure and the first target definition.
3. The dynamic message parsing method according to claim 1 or 2, wherein the message to be parsed includes a first inherent type data, a service data and a second inherent type data, which are sequentially arranged;
the step of analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result includes:
according to the message structure, sequentially classifying and analyzing the first inherent type data and the second inherent type data to obtain a description feature corresponding to each digit in the first inherent type data and the second inherent type data;
analyzing the service data by combining the first target definition and the second target definition to obtain the description characteristics corresponding to each number in the service data;
and carrying out associated representation on each number of the message to be analyzed and the corresponding description characteristics to obtain an analysis result.
4. The dynamic message parsing method according to claim 2, wherein the message to be parsed includes a first inherent type data, a service data and a second inherent type data, which are sequentially arranged;
the step of parsing the message to be parsed based on the message structure and the first target definition includes:
according to the message structure, sequentially classifying and analyzing the first inherent type data and the second inherent type data to obtain a description feature corresponding to each digit in the first inherent type data and the second inherent type data;
analyzing the service data according to the first target definition to obtain description characteristics corresponding to each number in the service data;
and performing association expression on each number of the message to be analyzed and the corresponding description characteristics to obtain an analysis result.
5. The dynamic message parsing method according to claim 1 or 2, wherein after the step of obtaining the message to be parsed, and before the step of determining the service type of the message to be parsed according to the message structure of the protocol to which the message to be parsed belongs, the method further comprises:
and judging whether the message to be analyzed is legal or not based on the message structure of the protocol to which the message to be analyzed belongs.
6. The dynamic message parsing method according to claim 5, wherein the step of determining whether the message to be parsed is legal based on the message structure of the protocol to which the message to be parsed belongs includes:
extracting initial characters of the message to be analyzed based on a target message structure of a preset target protocol;
judging whether the initial character accords with the message initial definition of the target protocol, if so, extracting a first check value of a frame header check bit from the message to be analyzed according to the target message structure, and checking data before the frame header check bit to obtain a second check value;
judging whether the first check value is consistent with the second check value, if so, extracting a third check value of a frame check bit from the message to be analyzed according to the target message structure, and checking data before the frame check bit to obtain a fourth check value;
and judging whether the third check value is consistent with the fourth check value, if so, judging that the message to be analyzed is legal.
7. The dynamic message parsing method according to claim 6, wherein the step of determining whether the message to be parsed is legal based on a message structure of a protocol to which the message to be parsed belongs further comprises:
and if the initial character does not accord with the message initial definition of the target protocol, the first check value is inconsistent with the second check value, or the third check value is inconsistent with the fourth check value, judging that the message to be analyzed is illegal.
8. A dynamic message analysis device is characterized by comprising a preprocessing module, a calling module and an analysis module;
the preprocessing module is used for acquiring a message to be analyzed, and determining the service type of the message to be analyzed according to the message structure of the protocol to which the message to be analyzed belongs under the condition that the message to be analyzed is legal;
the calling module is used for calling a first target definition and a second target definition corresponding to the service type from a pre-stored configuration file if the service type belongs to a dynamic data type;
the first target definition is a data type definition of the service type, the second target definition is a structural body definition of a dynamic member of the service type, and the dynamic member is a member with variable data length;
and the analysis module is used for analyzing the message to be analyzed based on the message structure, the first target definition and the second target definition to obtain an analysis result.
9. An electronic device comprising a processor and a memory, the memory storing a computer program executable by the processor, the processor being operable to execute the computer program to implement the dynamic message parsing method of any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out a dynamic message parsing method according to any one of claims 1 to 7.
CN202210906596.6A 2022-07-29 2022-07-29 Dynamic message parsing method and device, electronic equipment and computer readable storage medium Active CN115242896B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210906596.6A CN115242896B (en) 2022-07-29 2022-07-29 Dynamic message parsing method and device, electronic equipment and computer readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210906596.6A CN115242896B (en) 2022-07-29 2022-07-29 Dynamic message parsing method and device, electronic equipment and computer readable storage medium

Publications (2)

Publication Number Publication Date
CN115242896A true CN115242896A (en) 2022-10-25
CN115242896B CN115242896B (en) 2023-06-27

Family

ID=83676394

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210906596.6A Active CN115242896B (en) 2022-07-29 2022-07-29 Dynamic message parsing method and device, electronic equipment and computer readable storage medium

Country Status (1)

Country Link
CN (1) CN115242896B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115720243A (en) * 2022-11-22 2023-02-28 协鑫电港云科技(海南)有限公司 Battery replacement equipment state determination method and device, electronic equipment and storage medium
CN116016345A (en) * 2022-12-05 2023-04-25 四川大学 Network flow restoration method based on custom protocol description language
CN117472387A (en) * 2023-12-26 2024-01-30 深圳麦格米特电气股份有限公司 Method and device for dynamically analyzing data and cloud platform

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102508030A (en) * 2011-10-14 2012-06-20 中电普瑞科技有限公司 Data processing system and message method based on IPC (industrial personal computer) synchronized phasor measurement unit
CN106598581A (en) * 2016-12-06 2017-04-26 成都能通科技有限公司 ASTERIX message parsing code generation method based on XML
CN108243168A (en) * 2016-12-27 2018-07-03 比亚迪股份有限公司 Packet parsing, group packet method and apparatus and message handling system
CN109194617A (en) * 2018-08-01 2019-01-11 杭州电子科技大学 The automatically parsing of XML message, packaging method and device
US10310760B1 (en) * 2018-05-21 2019-06-04 Pure Storage, Inc. Layering communication fabric protocols
US20190379623A1 (en) * 2018-06-12 2019-12-12 Oracle Financial Services Software Limited Message recognition system and method configurable to define new message formats
WO2020087400A1 (en) * 2018-10-31 2020-05-07 华为技术有限公司 Header parsing apparatus and method
WO2020125650A1 (en) * 2018-12-17 2020-06-25 中兴通讯股份有限公司 Message sampling method and unpacking method, node, system and storage medium
CN111917753A (en) * 2020-07-24 2020-11-10 西安航空学院 Modbus TCP message analysis method based on bit field
KR20210044060A (en) * 2019-10-14 2021-04-22 한국전자기술연구원 Method for decoding message of user-defined
CN113905106A (en) * 2021-09-30 2022-01-07 上海浦东发展银行股份有限公司 Message parsing method, device, equipment and storage medium

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102508030A (en) * 2011-10-14 2012-06-20 中电普瑞科技有限公司 Data processing system and message method based on IPC (industrial personal computer) synchronized phasor measurement unit
CN106598581A (en) * 2016-12-06 2017-04-26 成都能通科技有限公司 ASTERIX message parsing code generation method based on XML
CN108243168A (en) * 2016-12-27 2018-07-03 比亚迪股份有限公司 Packet parsing, group packet method and apparatus and message handling system
US10310760B1 (en) * 2018-05-21 2019-06-04 Pure Storage, Inc. Layering communication fabric protocols
US20190379623A1 (en) * 2018-06-12 2019-12-12 Oracle Financial Services Software Limited Message recognition system and method configurable to define new message formats
CN109194617A (en) * 2018-08-01 2019-01-11 杭州电子科技大学 The automatically parsing of XML message, packaging method and device
WO2020087400A1 (en) * 2018-10-31 2020-05-07 华为技术有限公司 Header parsing apparatus and method
WO2020125650A1 (en) * 2018-12-17 2020-06-25 中兴通讯股份有限公司 Message sampling method and unpacking method, node, system and storage medium
KR20210044060A (en) * 2019-10-14 2021-04-22 한국전자기술연구원 Method for decoding message of user-defined
CN111917753A (en) * 2020-07-24 2020-11-10 西安航空学院 Modbus TCP message analysis method based on bit field
CN113905106A (en) * 2021-09-30 2022-01-07 上海浦东发展银行股份有限公司 Message parsing method, device, equipment and storage medium

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
吴建斌等: "基于XML的多协议报文解析的方法与实现", 电子测量技术 *
杨芳等: "可重构交换机报文解析器的设计", 南开大学学报(自然科学版) *

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115720243A (en) * 2022-11-22 2023-02-28 协鑫电港云科技(海南)有限公司 Battery replacement equipment state determination method and device, electronic equipment and storage medium
CN116016345A (en) * 2022-12-05 2023-04-25 四川大学 Network flow restoration method based on custom protocol description language
CN117472387A (en) * 2023-12-26 2024-01-30 深圳麦格米特电气股份有限公司 Method and device for dynamically analyzing data and cloud platform
CN117472387B (en) * 2023-12-26 2024-04-16 深圳麦格米特电气股份有限公司 Method and device for dynamically analyzing data and cloud platform

Also Published As

Publication number Publication date
CN115242896B (en) 2023-06-27

Similar Documents

Publication Publication Date Title
CN115242896B (en) Dynamic message parsing method and device, electronic equipment and computer readable storage medium
CN111683066B (en) Heterogeneous system integration method, heterogeneous system integration device, computer equipment and storage medium
CN109842629A (en) The implementation method of custom protocol based on protocol analysis frame
CN111061678B (en) Service data processing method, device, computer equipment and storage medium
CN102404306B (en) Protocol configuration method and device
CN112199331A (en) Automatic generation method, system, terminal and storage medium of interface document
CN109460220A (en) The predefined code generating method of message, device, electronic equipment and storage medium
CN110912803A (en) IM message transmission method and terminal
CN111240688A (en) excel file analysis method and device, computer equipment and storage medium
CN109861998B (en) Plug-in type dynamic analysis system and method based on Beidou short message protocol
CN112307369A (en) Short link processing method, device, terminal and storage medium
CN110830466B (en) Method and device for framing DL/T645 protocol message based on XML
CN112769738B (en) DetNet data packet processing method and device
CN117499380A (en) Custom protocol data acquisition method
CN112883088B (en) Data processing method, device, equipment and storage medium
CN113242254B (en) Communication message processing method, device, terminal equipment and storage medium
CN111049813B (en) Message assembling method, message analyzing method, message assembling device, message analyzing device and storage medium
CN112788078B (en) Data transmission method, receiving device, sending device and computer equipment
WO2021129849A1 (en) Log processing method, apparatus and device, and storage medium
CN111985186A (en) Dictionary entry conversion method, API gateway system, equipment and storage medium
KR20090056622A (en) Method and apparatus for analyzing binary data file and medium for storing for program for carrying out the method
CN113949640A (en) Service data processing method and device
US20230289354A1 (en) Endpoint scan and profile generation
CN115242691B (en) Protocol identification method based on protocol feature library
CN116483483B (en) Data query method and device and electronic equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant