CN116319487B - Industrial protocol dynamic analysis method and system - Google Patents
Industrial protocol dynamic analysis method and system Download PDFInfo
- Publication number
- CN116319487B CN116319487B CN202310300209.9A CN202310300209A CN116319487B CN 116319487 B CN116319487 B CN 116319487B CN 202310300209 A CN202310300209 A CN 202310300209A CN 116319487 B CN116319487 B CN 116319487B
- Authority
- CN
- China
- Prior art keywords
- protocol
- interpretation
- template
- received
- instruction
- 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.)
- Active
Links
- 238000004458 analytical method Methods 0.000 title claims abstract description 30
- 238000006243 chemical reaction Methods 0.000 claims description 35
- 238000000034 method Methods 0.000 claims description 30
- 230000005540 biological transmission Effects 0.000 claims description 15
- 230000000295 complement effect Effects 0.000 claims description 5
- 238000001914 filtration Methods 0.000 claims description 5
- 230000006870 function Effects 0.000 description 49
- 230000008569 process Effects 0.000 description 10
- 238000012545 processing Methods 0.000 description 9
- 238000010586 diagram Methods 0.000 description 8
- 238000004590 computer program Methods 0.000 description 7
- 238000011161 development Methods 0.000 description 7
- 238000012423 maintenance Methods 0.000 description 7
- 238000012986 modification Methods 0.000 description 5
- 230000004048 modification Effects 0.000 description 5
- 230000000739 chaotic effect Effects 0.000 description 2
- 238000005538 encapsulation Methods 0.000 description 2
- 230000002349 favourable effect Effects 0.000 description 2
- 230000003993 interaction Effects 0.000 description 2
- 238000000926 separation method Methods 0.000 description 2
- 238000004891 communication Methods 0.000 description 1
- 238000007405 data analysis Methods 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 230000007704 transition Effects 0.000 description 1
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L43/00—Arrangements for monitoring or testing data switching networks
- H04L43/18—Protocol analysers
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/12—Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
-
- Y—GENERAL 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
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02P—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN THE PRODUCTION OR PROCESSING OF GOODS
- Y02P90/00—Enabling technologies with a potential contribution to greenhouse gas [GHG] emissions mitigation
- Y02P90/02—Total factory control, e.g. smart factories, flexible manufacturing systems [FMS] or integrated manufacturing systems [IMS]
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Health & Medical Sciences (AREA)
- Computing Systems (AREA)
- General Health & Medical Sciences (AREA)
- Medical Informatics (AREA)
- Communication Control (AREA)
Abstract
The application discloses a dynamic analysis method and a system for an industrial protocol, comprising the following steps: according to the protocol, acquiring a receiving instruction, and according to a preset rule of receiving an interpretation character template, acquiring the receiving interpretation character template from the receiving instruction; according to each received interpretation character template, sequentially configuring a received instruction template to interpret the protocol until all received instructions are configured as corresponding received instruction templates; sequentially configuring the sending instruction templates corresponding to the receiving instruction templates until all the receiving instruction templates are correspondingly configured as the sending instruction templates, so that parameters in the corresponding receiving instruction templates are sent; according to each receiving instruction template and each sending instruction template, corresponding protocol interpretation classes are dynamically generated so that the service codes can directly call the protocol interpretation classes.
Description
Technical Field
The application relates to the technical field of industrial protocol data analysis, in particular to a dynamic industrial protocol analysis method and system.
Background
In industrial communication protocols, the TCP protocol is usually interacted in the form of specific character strings, and the existing upper computer TCP interpreters have the following characteristics: (1) The protocol interpretation and the business logic are mixed together, the code is chaotic, and if the protocol is modified in the later period, key points are difficult to be quickly found from the chaotic code structure for quick modification; (2) The service code contains a large number of character string interpretations, but the interpretation of the character string is easy to cause interpretation errors and the front and back codes are linked together because of careless misaddition or missubtraction of one character, and the later interpretation is difficult to find; (3) The protocol interpretation cannot be separated from the business code, and it is difficult for a handover person to understand the business logic in a short time when the code is handed over. Therefore, an industrial protocol data parsing method is needed to separate protocol interpretation from service logic, so as to facilitate understanding of service logic, avoid confusion caused by protocol interpretation and service logic connection, and facilitate development and maintenance of later applications.
Disclosure of Invention
The application aims to solve the problem of confusion caused by protocol interpretation and service logic connection, separate the protocol interpretation and the service logic, and facilitate understanding of the service logic and later application development and maintenance.
In a first aspect, the present application provides a method for dynamically parsing an industrial protocol, including:
according to a protocol, acquiring a receiving instruction, and according to a preset rule of receiving an interpretation character template, acquiring the receiving interpretation character template from the receiving instruction;
according to each received interpretation character template, sequentially configuring a received instruction template to interpret the protocol until all received instructions are configured as corresponding received instruction templates;
sequentially configuring the sending instruction templates corresponding to the receiving instruction templates until all the receiving instruction templates are correspondingly configured as the sending instruction templates, so that parameters in the corresponding receiving instruction templates are sent;
and dynamically generating a corresponding protocol interpretation class according to each receiving instruction template and each sending instruction template, so that the service codes directly call the protocol interpretation class.
According to the method, the receiving interpretation character templates are obtained from the receiving instruction according to the preset rule of the receiving interpretation character templates, the receiving instruction templates and the corresponding sending instruction templates are sequentially configured according to the receiving interpretation character templates, the generated receiving instruction templates are used for interpreting the protocol, the corresponding sending instruction templates are generated for sending the parameters in the receiving instruction templates, the service codes only need to call the protocol interpretation class generated by the receiving instruction templates and the sending instruction templates, the parameters in the protocol can be dynamically obtained, the protocol is not required to be resolved, the condition that the service codes cannot be adapted after the protocol is changed is avoided, namely, the protocol analysis and the separation of service logic are realized, the applicability of the protocol analysis can be improved, and the understanding and the later application development and the maintenance of the service logic are facilitated; according to each receiving instruction template and each sending instruction template, corresponding protocol interpretation classes are dynamically generated, so that service codes can directly call the protocol interpretation classes, corresponding dynamic encapsulation can be carried out on different receiving instructions, applicability of protocol analysis is further improved, different receiving instructions can be dynamically adapted, service codes do not need to know specific structures and data processing processes of protocol interpretation, data in a protocol are directly acquired through dynamic generation of the corresponding protocol interpretation classes, reading speed of the protocol can be improved, speed of executing corresponding functions according to the protocol is increased, and configurable protocol analysis performance is further improved.
Further, the dynamically generating a corresponding protocol interpretation class according to each received instruction template and each sent instruction template, so that the service code directly calls the protocol interpretation class, includes:
dynamically generating corresponding protocol interpretation class source codes according to each received instruction template and each transmitted instruction template;
circularly reading a received instruction template, correspondingly generating event class source codes in protocol interpretation class source codes, generating corresponding interpretation received instructions, and calling related event class source codes corresponding to the received instruction template;
generating a transmission function source code corresponding to the corresponding transmitted parameters according to the transmission instruction template corresponding to the reception instruction template, and adding the transmission function source code into the protocol interpretation class source code;
and until all the received instruction templates are circularly read, storing the corresponding event protocol class under a specified path and adding the event protocol class into the project, so that the service code directly calls the protocol interpretation class.
The application carries out the execution of the corresponding event according to the receiving instruction template, correspondingly generates the sending function source code by the corresponding sending instruction template of the receiving instruction template, adds the sending function source code into the protocol interpretation class source code, respectively configures the receiving instruction template and the sending instruction template, processes the data in the receiving interpretation character template by the receiving instruction template, can make clearer interpretation for the protocol, generates the sending function source code by the sending instruction template according to the corresponding sending instruction template, can send the data in the sending instruction template through the sending function source code, is favorable for the protocol interpretation class generated by the receiving instruction template and the sending instruction template to package the resolved protocol data, realizes the direct interaction of the data between the service logic and the protocol resolution, and is convenient for the understanding of the service logic and the development and maintenance of the later application.
Further, the generating the corresponding interpretation receiving instruction is specifically:
filtering invalid characters in the received instruction according to the configuration parameters, and selecting a received instruction template as an optimal received instruction template;
judging whether the optimal receiving instruction template is empty or not, and if the optimal receiving instruction template is not empty, calling a corresponding event according to the optimal receiving instruction template;
and carrying out instruction interception and conversion on the received instruction template to obtain a received interpretation packet containing the interpreted field names and the corresponding actual values.
After all the received instruction templates are circularly read, the method further comprises the following steps:
storing each receiving instruction template and each sending instruction template respectively, and generating a protocol type source code according to the stored receiving instruction templates and the sending instruction templates.
The application stores each receiving instruction template and each sending instruction template respectively, and generates the protocol source code according to the stored receiving instruction templates and sending instruction templates, thereby further accelerating the reading speed of the protocol, accelerating the speed of executing the corresponding function according to the protocol, and further improving the configurable protocol analysis performance.
Further, the step of sequentially configuring the received instruction templates to interpret the protocol according to each received interpretation character template until all received instructions are configured as corresponding received instruction templates includes:
sequentially judging whether variables exist in the received interpretation character template, and if the variables exist in the received interpretation character template, automatically setting the conversion type, the variable name or the complement character of the variables;
if the received interpretation character template does not have variables, generating a corresponding received instruction template directly according to the data in the received interpretation character template.
Further, the automatically setting the conversion type, variable name or patch of the variable includes:
judging whether the conversion type of the variable of the received interpretation character template has specified conversion, if so, adding automatic interpretation setting to perform specified conversion, returning to a corresponding limiting interface and generating a corresponding received instruction template;
or intercepting and appointed converting variables through the customized function to generate corresponding received instruction templates.
The automatic setting of the conversion type, variable name or patch of the variable further comprises:
and when the actual length of the variable in the received interpretation character template is smaller than the defined placeholder length, aligning through the filling characters, and converting the actual length into a value conforming to the placeholder length.
Further, after dynamically generating the corresponding protocol interpretation class, the method further comprises:
when the protocol is modified, the protocol class is regenerated once, and the attribute or the event of the modified protocol class is prompted.
The application adopts the modified protocol to prompt, can avoid the situation that the service code cannot be self-adaptive because the modification is manually ignored in the later period, and can actively prompt the modified protocol so as to prompt the service code to be modified so as to adapt to the modified protocol, thereby improving the execution efficiency of the service code and further improving the configurable protocol analysis performance.
Further, the dynamically generating a corresponding protocol interpretation class according to each received instruction template and each sent instruction template further includes: directly calling a MakeClassFile function to generate the protocol interpretation class under a specified path.
In a second aspect, the present application also provides an industrial protocol dynamic analysis system, including:
the receiving interpretation character template generation module is used for acquiring a receiving instruction according to a protocol and acquiring a receiving interpretation character template from the receiving instruction according to a preset rule of the receiving interpretation character template;
the received instruction template generation module is used for sequentially configuring received instruction templates to explain the protocol according to each received interpretation character template until all received instructions are configured as corresponding received instruction templates;
the transmission instruction template generation module is used for sequentially configuring transmission instruction templates corresponding to the reception instruction templates until all the reception instruction templates are correspondingly configured as transmission instruction templates so as to transmit parameters in the corresponding reception instruction templates;
and the protocol interpretation class generating module is used for dynamically generating a corresponding protocol interpretation class according to each receiving instruction template and each sending instruction template so that the service codes can directly call the protocol interpretation class.
Drawings
FIG. 1 is a schematic flow chart of dynamic analysis of an industrial protocol according to an embodiment of the present application;
FIG. 2 is a schematic flow chart of dynamic analysis of an industrial protocol according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of an industrial protocol dynamic analysis system according to an embodiment of the present application.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
Referring to fig. 1, a flow chart of dynamic analysis of an industrial protocol according to an embodiment of the present application includes steps S11 to S14, specifically:
step S11, acquiring a receiving instruction according to a protocol, and acquiring a receiving interpretation character template from the receiving instruction according to a preset rule of the receiving interpretation character template.
And step S12, according to each received interpretation character template, sequentially configuring a received instruction template to interpret the protocol until all received instructions are configured as corresponding received instruction templates.
Whether the variable exists in the received interpretation character template or not is sequentially judged, and if the variable exists in the received interpretation character template, the conversion type, the variable name or the complement character of the variable is automatically set; if the received interpretation character template does not have variables, generating a corresponding received instruction template directly according to the data in the received interpretation character template.
Specifically, automatically setting the conversion type, variable name or patch of the variable includes: judging whether the conversion type of the variable of the received interpretation character template has specified conversion, if so, adding automatic interpretation setting to perform specified conversion, returning to a corresponding limiting interface and generating a corresponding received instruction template; or intercepting and appointed converting variables through the customized function to generate corresponding received instruction templates.
Furthermore, the method further comprises: and when the actual length of the variable in the received interpretation character template is smaller than the defined placeholder length, aligning through the filling characters, and converting the actual length into a value conforming to the placeholder length.
The application judges whether the variable exists in the received interpretation character template, and uniformly processes the conversion type, variable name or the format of the complement character in the condition of the existence of the variable, so that the data in the protocol can be clearly interpreted, the consistency of the format of the parameters in the protocol obtained by the service code through the source code of the sending function can be ensured, the corresponding interpretation can be performed on different received interpretation character templates, the applicability of the protocol analysis is further improved, and the understanding and the later application development and maintenance of the service logic are facilitated.
Illustratively, a receiving interpretation character template is obtained, which includes the name of the protocol interpretation and the variable-length character string to be interpreted, wherein the name of the receiving interpretation character template is "Position", the variable-length character string to be interpreted is "Position { M } { PPPP } { xxxxx } { Y6} { Z6}000000END" being the variable-length character string to be interpreted, and the interpretation needs to be performed by the receiving instruction template.
According to a preset rule for receiving and interpreting a character template, a curly brace for dynamically variable content in data to be interpreted is included, if a variable and a placeholder thereof have two formats, the first bit in the curly brace is a variable Identification (ID), the variable ID is followed by the length of the placeholder, the second variable ID is repeated for a plurality of times, and the repetition number is the length of the placeholder of the variable ID.
Illustratively, in "POSITION { M } { PPPP } { xxxx } { Y6} { Z6}000000END", 5 variables are indicated to be included, respectively including a variable ID of M, 1 character occupied, a variable ID of P, 4 characters occupied, a variable ID of X, 6 characters occupied, a variable ID of Y, 6 characters occupied, a variable ID of Z, 6 characters occupied, "000000END" is an END identifier, and "POSITION" is a fully capitalized variable name.
Wherein, configuring a receiving instruction template for a receiving interpretation character template with a variable ID requires setting the type of the corresponding variable ID.
Illustratively, the interpretation of the valid data { M } { PPPP } { XXXX } { Y6} { Z6} "in the data to be interpreted may be expressed as:
AddVarExplain<CameraMode>('M',"mode").SetItem("2",
CameraMode._2D).SetItem("3",CameraMode._3D)
.AddVarExplain<int>('P',"position",'0')
.AddVarExplain<int>('X',"xpos",'0')
.AddVarExplain<int>('Y',"ypos",'0')
.AddVarExplain<int>('Z',"zpos",'0');
the addr varexplain function is used for explaining the variable, the camera mode is used for carrying out appointed conversion on the conversion type of the variable, the SetItem is used for presetting appointed conversion rules, and the method specifically comprises the following steps: when the first string in SetItem is "2", conversion to camelamode 2D is designated, and when it is "3", conversion to camelamode 3D is designated, and the addvarexplatin function is returned to a defined interface, the type of value that can be defined must be a camelamode type, and incorrect setting of a value can be prevented from being erroneously set.
By way of example, a special specified transition can also be set by the SetConvert function, in particular:
AddVarExplain<CTest>('K',"kk",'0').SetConvert((cmd)=>
{
string[]ss=cmd.Split(new char[]{','});
CTest ct=new CTest();
ct.Key1=double.Parse(ss[0]);
if(ss.Length>1)
ct.Key2=double.Parse(ss[1]);
if(ss.Length>2)
ct.Key3=double.Parse(ss[2]);
return ct;
})
it should be noted that, the setconversion function implements conversion from instruction to CTest type, and since the preset limited conversion result type is CTest type, the function is limited to be finally converted into CTest type, wherein the instruction (the instruction is a character string) is split according to characters, the Key1 attribute of CTest is the first character of split to double refinement, if the split character length is greater than 1, more than 2 character strings can be split, the Key2 attribute is the 2 nd split character string to double refinement, and the Key3 is similar, if the split character string has 3 or more, the Key3 is the 3 rd character string to double refinement.
Illustratively, when the variable is aligned by the padding character, the variable X is 6 characters, and when the actual value is 35, only 2 characters are occupied, so the padding character is required to fill the alignment, i.e., "000035".
And step S13, sequentially configuring the sending instruction templates corresponding to the receiving instruction templates until all the receiving instruction templates are correspondingly configured as the sending instruction templates, so that the parameters in the corresponding receiving instruction templates are sent.
Preferably, the send instruction templates corresponding to the addsendexplatin function configuration are set by rules configuring the receive instruction templates.
And step S14, dynamically generating a corresponding protocol interpretation class according to each received instruction template and each transmitted instruction template, so that the service codes directly call the protocol interpretation class.
It should be noted that the source code of the protocol interpretation class can be directly used in the project after being generated. The protocol interpretation class is directly interpreted with the protocol of the PLC, and is mainly used for business processing, namely the business processing can be separated from the protocol of the PLC, and the interpretation and conversion of the protocol do not need to be concerned too much in the business processing process, because the generated protocol interpretation class realizes the function.
Specifically, step S14 includes sub-steps S141 to S144, specifically:
and step S141, dynamically generating corresponding protocol interpretation class source codes according to each received instruction template and each transmitted instruction template.
And S142, circularly reading a received instruction template, correspondingly generating event class source codes in the protocol interpretation class source codes, generating corresponding interpretation received instructions, and calling related event class source codes corresponding to the received instruction template.
It should be noted that an event is a type of programming language, and after subscribing to a related event, when the system executes until the event is to be implemented, a function subscribing to the event is called. The received event source code is the source code generated by the system, wherein the received event is generated by the originally defined received templates, and the number of the received templates is initially defined, so that the event is generated by the code, and the received event source code is the event source code in the source code of the whole protocol interpretation class.
The method specifically comprises the steps of generating a corresponding interpretation receiving instruction to interpret, wherein the interpretation receiving instruction specifically comprises: filtering invalid characters in the received instruction according to the configuration parameters, and selecting a received instruction template as an optimal received instruction template; judging whether the optimal receiving instruction template is empty or not, and if the optimal receiving instruction template is not empty, calling a corresponding event according to the optimal receiving instruction template; and carrying out instruction interception and conversion on the received instruction template to obtain a received interpretation packet containing the interpreted field names and the corresponding actual values.
It should be noted that, filtering invalid characters in the received instruction according to the configuration parameters includes: some invalid characters are possibly generated due to the protocol writing capability of the PLC side; selecting an optimal receiving template according to the defined receiving instruction template, and calling an error event if no return is made and if the error event is subscribed; according to the rule of the received instruction template, a corresponding received interpretation package is obtained, which is actually a dictionary, and contains the interpreted field names and corresponding actual values, and the process is to interpret and convert the protocol.
And step S143, generating a transmission function source code corresponding to the corresponding transmitted parameters according to the transmission instruction template corresponding to the reception instruction template, and adding the transmission function source code into the protocol interpretation class source code.
It should be noted that, the sending function is a function that converts the corresponding sent parameter into a sending instruction (character string), the sending function is a sending template defined by the beginning, and the generated function defines how many sending templates will finally generate how many sending functions, the parameter in the sending function is also defined by the sending template, and the sending function is dynamically generated by the sending template. The method specifically comprises the following steps: the loop generates a send function source code according to the defined send instruction template and adds the send function source code to the protocol interpretation class.
And step S144, until all the received instruction templates are circularly read, storing the corresponding event protocol class under a specified path and adding the event protocol class into the project, so that the service code directly calls the protocol interpretation class.
It should be noted that, the event protocol class is generated according to the receiving templates, and defines how many receiving templates will dynamically generate how many event protocol classes, because there are two parameters in the defining function of the event, one is the object of the protocol interpretation class, and the other is the corresponding event protocol class, and the event protocol class includes the value of the parameter generated after interpreting the instruction, and this is a parameter type of the received event, including: and circularly acquiring all the received instruction templates, generating corresponding classes according to class names defining the received instruction templates, and circularly acquiring all field definitions under the received instruction templates to generate the attributes of the classes.
The application carries out the execution of the corresponding event according to the receiving instruction template, correspondingly generates the sending function source code by the corresponding sending instruction template of the receiving instruction template, adds the sending function source code into the protocol interpretation class source code, respectively configures the receiving instruction template and the sending instruction template, processes the data in the receiving interpretation character template by the receiving instruction template, can make clearer interpretation for the protocol, generates the sending function source code by the sending instruction template according to the corresponding sending instruction template, can send the data in the sending instruction template through the sending function source code, is favorable for the protocol interpretation class generated by the receiving instruction template and the sending instruction template to package the resolved protocol data, realizes the direct interaction of the data between the service logic and the protocol resolution, and is convenient for the understanding of the service logic and the development and maintenance of the later application.
In sub-step S144, after all received instruction templates are circularly read, further comprising: storing each receiving instruction template and each sending instruction template respectively, and generating a protocol type source code according to the stored receiving instruction templates and the sending instruction templates.
The application stores each receiving instruction template and each sending instruction template respectively, and generates the protocol source code according to the stored receiving instruction templates and sending instruction templates, thereby further accelerating the reading speed of the protocol, accelerating the speed of executing the corresponding function according to the protocol, and further improving the configurable protocol analysis performance.
In addition, after dynamically generating the corresponding protocol interpretation class, the method further comprises: when the protocol is modified, the protocol class is regenerated once, and the attribute or the event of the modified protocol class is prompted. And dynamically generating a corresponding protocol interpretation class according to each received instruction template and each transmitted instruction template, and generating the protocol interpretation class under a specified path by directly calling a MakeClassFile function.
The application adopts the modified protocol to prompt, can avoid the situation that the service code cannot be self-adaptive because the modification is manually ignored in the later period, and can actively prompt the modified protocol so as to prompt the service code to be modified so as to adapt to the modified protocol, thereby improving the execution efficiency of the service code and further improving the configurable protocol analysis performance.
The application also provides a complete flow chart of dynamic analysis of the industrial protocol, referring to fig. 2, which is a flow chart of dynamic analysis of the industrial protocol provided by the embodiment of the application, wherein the flow chart comprises a configuration process of receiving an instruction template and sending the instruction template and a calling process of service codes.
Referring to fig. 3, a schematic structural diagram of an industrial protocol dynamic analysis system according to an embodiment of the present application includes: the receiving interpretation character template generating module 31, the receiving instruction template generating module 32, the sending instruction template generating module 33 and the protocol interpretation class generating module 34 specifically are:
the received interpretation character template generating module 31 is configured to obtain a received instruction according to a protocol, and obtain a received interpretation character template from the received instruction according to a preset rule of the received interpretation character template.
The received instruction template generating module 32 is configured to sequentially configure received instruction templates to interpret the protocol according to each received interpretation character template until all received instructions are configured as corresponding received instruction templates.
Whether the variable exists in the received interpretation character template or not is sequentially judged, and if the variable exists in the received interpretation character template, the conversion type, the variable name or the complement character of the variable is automatically set; if the received interpretation character template does not have variables, generating a corresponding received instruction template directly according to the data in the received interpretation character template.
Specifically, automatically setting the conversion type, variable name or patch of the variable includes: judging whether the conversion type of the variable of the received interpretation character template has specified conversion, if so, adding automatic interpretation setting to perform specified conversion, returning to a corresponding limiting interface and generating a corresponding received instruction template; or intercepting and appointed converting variables through the customized function to generate corresponding received instruction templates.
Furthermore, the method further comprises: and when the actual length of the variable in the received interpretation character template is smaller than the defined placeholder length, aligning through the filling characters, and converting the actual length into a value conforming to the placeholder length.
And the sending instruction template generating module 33 is configured to sequentially configure sending instruction templates corresponding to the receiving instruction templates until all receiving instruction templates are correspondingly configured as sending instruction templates, so that parameters in the corresponding receiving instruction templates are sent.
And the protocol interpretation class generating module 34 is configured to dynamically generate a corresponding protocol interpretation class according to each received instruction template and each sent instruction template, so that the service code directly invokes the protocol interpretation class.
Specifically, the protocol interpretation class generation module 34 includes: the system comprises a protocol interpretation class source code generation sub-module, a reading and receiving instruction module sub-module, a sending function source code generation sub-module and a protocol interpretation class event addition sub-module, and specifically comprises the following components:
and the protocol interpretation class source code generation sub-module is used for dynamically generating corresponding protocol interpretation class source codes according to each received instruction template and each transmitted instruction template.
And the reading and receiving instruction template submodule is used for circularly reading and receiving instruction templates, correspondingly generating event class source codes in protocol interpretation class source codes, generating corresponding interpretation and receiving instructions, and calling related event class source codes corresponding to the receiving instruction templates.
And the sending function source code generation sub-module is used for correspondingly generating a sending function source code according to the sending instruction template corresponding to the receiving instruction template, and adding the sending function source code into the protocol interpretation class source code.
The method specifically comprises the steps of generating a corresponding interpretation receiving instruction to interpret, wherein the interpretation receiving instruction specifically comprises: filtering invalid characters in the received instruction according to the configuration parameters, and selecting a received instruction template as an optimal received instruction template; judging whether the optimal receiving instruction template is empty or not, and if the optimal receiving instruction template is not empty, calling a corresponding event according to the optimal receiving instruction template; and carrying out instruction interception and conversion on the received instruction template to obtain a received interpretation packet containing the interpreted field names and the corresponding actual values.
And the protocol interpretation class event adding sub-module is used for storing the corresponding event protocol class under a specified path and adding the event protocol class into the project until all the received instruction templates are circularly read, so that the service code directly calls the protocol interpretation class.
After all the received instruction templates are circularly read, the method further comprises the following steps: storing each receiving instruction template and each sending instruction template respectively, and generating a protocol type source code according to the stored receiving instruction templates and the sending instruction templates.
In addition, after dynamically generating the corresponding protocol interpretation class, the method further comprises: when the protocol is modified, the protocol class is regenerated once, and the attribute or the event of the modified protocol class is prompted. And dynamically generating a corresponding protocol interpretation class according to each received instruction template and each transmitted instruction template, and generating the protocol interpretation class under a specified path by directly calling a MakeClassFile function.
According to the method, the receiving interpretation character templates are obtained from the receiving instruction according to the preset rule of the receiving interpretation character templates, the receiving instruction templates and the corresponding sending instruction templates are sequentially configured according to the receiving interpretation character templates, the generated receiving instruction templates are used for interpreting the protocol, the corresponding sending instruction templates are generated for sending the parameters in the receiving instruction templates, the service codes only need to call the protocol interpretation class generated by the receiving instruction templates and the sending instruction templates, the parameters in the protocol can be dynamically obtained, the protocol is not required to be resolved, the condition that the service codes cannot be adapted after the protocol is changed is avoided, namely, the protocol analysis and the separation of service logic are realized, the applicability of the protocol analysis can be improved, and the understanding and the later application development and the maintenance of the service logic are facilitated; according to each receiving instruction template and each sending instruction template, corresponding protocol interpretation classes are dynamically generated, so that service codes can directly call the protocol interpretation classes, corresponding dynamic encapsulation can be carried out on different receiving instructions, applicability of protocol analysis is further improved, different receiving instructions can be dynamically adapted, service codes do not need to know specific structures and data processing processes of protocol interpretation, data in a protocol are directly acquired through dynamic generation of the corresponding protocol interpretation classes, reading speed of the protocol can be improved, speed of executing corresponding functions according to the protocol is increased, and configurable protocol analysis performance is further improved.
It will be appreciated by those skilled in the art that embodiments of the present application may also be provided including a computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may 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, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The foregoing is merely a preferred embodiment of the present application, and it should be noted that modifications and variations could be made by those skilled in the art without departing from the technical principles of the present application, and such modifications and variations should also be regarded as being within the scope of the application.
Claims (10)
1. An industrial protocol dynamic analysis method is characterized by comprising the following steps:
according to a protocol, acquiring a receiving instruction, and according to a preset rule of receiving an interpretation character template, acquiring the receiving interpretation character template from the receiving instruction;
according to each received interpretation character template, sequentially configuring a received instruction template to interpret the protocol until all received instructions are configured as corresponding received instruction templates;
sequentially configuring the sending instruction templates corresponding to the receiving instruction templates until all the receiving instruction templates are correspondingly configured as the sending instruction templates, so that parameters in the corresponding receiving instruction templates are sent;
and dynamically generating a corresponding protocol interpretation class according to each receiving instruction template and each sending instruction template, so that the service codes directly call the protocol interpretation class.
2. The industrial protocol dynamic analysis method according to claim 1, wherein dynamically generating a corresponding protocol interpretation class according to each received instruction template and each transmitted instruction template so that a service code directly invokes the protocol interpretation class comprises:
dynamically generating corresponding protocol interpretation class source codes according to each received instruction template and each transmitted instruction template;
circularly reading a received instruction template, correspondingly generating event class source codes in protocol interpretation class source codes, generating corresponding interpretation received instructions, and calling related event class source codes corresponding to the received instruction template;
generating a transmission function source code corresponding to the corresponding transmitted parameters according to the transmission instruction template corresponding to the reception instruction template, and adding the transmission function source code into the protocol interpretation class source code;
and until all the received instruction templates are circularly read, storing the corresponding event protocol class under a specified path and adding the event protocol class into the project, so that the service code directly calls the protocol interpretation class.
3. The industrial protocol dynamic analysis method according to claim 2, wherein the generating the corresponding interpretation receiving instruction interprets, specifically:
filtering invalid characters in the received instruction according to the configuration parameters, and selecting a received instruction template as an optimal received instruction template;
judging whether the optimal receiving instruction template is empty or not, and if the optimal receiving instruction template is not empty, calling a corresponding event according to the optimal receiving instruction template;
and carrying out instruction interception and conversion on the received instruction template to obtain a received interpretation packet containing the interpreted field names and the corresponding actual values.
4. The industrial protocol dynamic resolution method of claim 2, further comprising, after all received instruction templates are circularly read:
storing each receiving instruction template and each sending instruction template respectively, and generating a protocol type source code according to the stored receiving instruction templates and the sending instruction templates.
5. The industrial protocol dynamic analysis method according to claim 1, wherein the sequentially configuring the received command templates to interpret the protocol according to each received interpretation character template until all received commands are configured as corresponding received command templates comprises:
sequentially judging whether variables exist in the received interpretation character template, and if the variables exist in the received interpretation character template, automatically setting the conversion type, the variable name or the complement character of the variables;
if the received interpretation character template does not have variables, generating a corresponding received instruction template directly according to the data in the received interpretation character template.
6. The industrial protocol dynamic resolution method of claim 5, wherein the automatically setting the conversion type, variable name, or patch of the variable comprises:
judging whether the conversion type of the variable of the received interpretation character template has specified conversion, if so, adding automatic interpretation setting to perform specified conversion, returning to a corresponding limiting interface and generating a corresponding received instruction template;
or intercepting and appointed converting variables through the customized function to generate corresponding received instruction templates.
7. The industrial protocol dynamic resolution method of claim 5, wherein the automatically setting the conversion type, variable name, or patch of the variable further comprises:
and when the actual length of the variable in the received interpretation character template is smaller than the defined placeholder length, aligning through the filling characters, and converting the actual length into a value conforming to the placeholder length.
8. The industrial protocol dynamic parsing method of claim 1, further comprising, after dynamically generating the corresponding protocol interpretation class:
when the protocol is modified, the protocol class is regenerated once, and the attribute or the event of the modified protocol class is prompted.
9. The industrial protocol dynamic analysis method according to claim 1, wherein the dynamically generating the corresponding protocol interpretation class according to each received instruction template and each transmitted instruction template further comprises: directly calling a MakeClassFile function to generate the protocol interpretation class under a specified path.
10. An industrial protocol dynamic resolution system, comprising:
the receiving interpretation character template generation module is used for acquiring a receiving instruction according to a protocol and acquiring a receiving interpretation character template from the receiving instruction according to a preset rule of the receiving interpretation character template;
the received instruction template generation module is used for sequentially configuring received instruction templates to explain the protocol according to each received interpretation character template until all received instructions are configured as corresponding received instruction templates;
the transmission instruction template generation module is used for sequentially configuring transmission instruction templates corresponding to the reception instruction templates until all the reception instruction templates are correspondingly configured as transmission instruction templates so as to transmit parameters in the corresponding reception instruction templates;
and the protocol interpretation class generating module is used for dynamically generating a corresponding protocol interpretation class according to each receiving instruction template and each sending instruction template so that the service codes can directly call the protocol interpretation class.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310300209.9A CN116319487B (en) | 2023-03-24 | 2023-03-24 | Industrial protocol dynamic analysis method and system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310300209.9A CN116319487B (en) | 2023-03-24 | 2023-03-24 | Industrial protocol dynamic analysis method and system |
Publications (2)
Publication Number | Publication Date |
---|---|
CN116319487A CN116319487A (en) | 2023-06-23 |
CN116319487B true CN116319487B (en) | 2023-09-29 |
Family
ID=86834085
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310300209.9A Active CN116319487B (en) | 2023-03-24 | 2023-03-24 | Industrial protocol dynamic analysis method and system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116319487B (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102055770A (en) * | 2011-01-17 | 2011-05-11 | 西安电子科技大学 | Automatic secure protocol code implementation system based on extensive markup language (XML) description |
CN102365621A (en) * | 2009-03-27 | 2012-02-29 | 奥普塔姆软件股份有限公司 | Interpreter-based program language translator using embedded interpreter types and variables |
CN108040040A (en) * | 2017-11-30 | 2018-05-15 | 北京锐安科技有限公司 | A kind of automation analysis method and device of application protocol message |
CN115622986A (en) * | 2022-09-22 | 2023-01-17 | 勤上光电股份有限公司 | Sensor communication protocol analysis method, system, storage medium and electronic equipment |
-
2023
- 2023-03-24 CN CN202310300209.9A patent/CN116319487B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102365621A (en) * | 2009-03-27 | 2012-02-29 | 奥普塔姆软件股份有限公司 | Interpreter-based program language translator using embedded interpreter types and variables |
CN102055770A (en) * | 2011-01-17 | 2011-05-11 | 西安电子科技大学 | Automatic secure protocol code implementation system based on extensive markup language (XML) description |
CN108040040A (en) * | 2017-11-30 | 2018-05-15 | 北京锐安科技有限公司 | A kind of automation analysis method and device of application protocol message |
CN115622986A (en) * | 2022-09-22 | 2023-01-17 | 勤上光电股份有限公司 | Sensor communication protocol analysis method, system, storage medium and electronic equipment |
Also Published As
Publication number | Publication date |
---|---|
CN116319487A (en) | 2023-06-23 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7269602B2 (en) | Method and device for defining objects allowing establishment of a device management tree for mobile communication devices | |
CN110474794B (en) | Information conversion method and system of SDN framework | |
CN111010305A (en) | Configuration management system and method based on NETCONF protocol | |
CN108833565B (en) | Method and device for monitoring server, server and storage medium | |
CN112688952B (en) | Message processing method, device, radio remote unit and medium | |
CN113867732A (en) | Message information processing method, system and storage medium | |
WO2020207105A1 (en) | Destination message determination method and apparatus, storage medium and electronic apparatus | |
CN112988409B (en) | Interface calling method and device, computer equipment and storage medium | |
CN116319487B (en) | Industrial protocol dynamic analysis method and system | |
US7403606B1 (en) | General protocol for service control point | |
CN103945287A (en) | Method for processing message by interface machine and interface machine | |
CN112134900A (en) | Data message processing method and device | |
CN113051202A (en) | Interface adaptation method, device, electronic equipment and computer readable storage medium | |
CN115052054A (en) | Communication message configuration method, device, readable storage medium and equipment | |
CN113204492A (en) | Android application testing method and device | |
CN113448689A (en) | Dubbo protocol conversion device and method in operation period | |
CN112732551A (en) | Automatic test method and system for radio frequency indexes | |
CN110543371A (en) | Method and device for remotely calling interface, electronic equipment and storage medium | |
CN112448971B (en) | Data analysis platform, data analysis method and storage medium | |
CN112565041B (en) | Hardware information configuration method, device and medium of FF field bus system | |
CN117787989A (en) | Rule management platform, equipment and storage medium based on wind control verification of DPU | |
CN118113334A (en) | Method and system for calling open interface service setting | |
CN112887390A (en) | Network request method | |
CN117834741A (en) | Message processing system and vehicle | |
CN116112582A (en) | Configurable UDP protocol analysis method and system |
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 | ||
CP03 | Change of name, title or address |
Address after: 101-301, building 3, No.9, Huijiang Shinan 2nd Road, Dashi street, Panyu District, Guangzhou, Guangdong 511400 Patentee after: Guangzhou Yihong Intelligent Equipment Co.,Ltd. Country or region after: China Address before: 101-301, building 3, No.9, Huijiang Shinan 2nd Road, Dashi street, Panyu District, Guangzhou, Guangdong 511400 Patentee before: GUANGZHOU EHOLLY INTELLIGENT EQUIPMENT Co.,Ltd. Country or region before: China |
|
CP03 | Change of name, title or address |