A kind of general analytic method of serial communication information protocol
Technical field
The present invention relates to product test, analysis and assessment software field more particularly to a kind of serial communication information protocol solutions
Analysis method.
Background technique
During product test, since the communication protocol of different product is not often identical, it is therefore desirable to for difference
The corresponding analysis software of product edition, and the protocol contents of conventional protocol analysis software are readable poor, are not easy to modify, greatly
The working efficiency of test assignment when reducing product development greatly.
Summary of the invention
In order to solve product communication protocol disunity existing in the prior art, need constantly to modify test software, software
It is readable to protocol contents poor, it is not easy to modify, the problems such as test job inefficiency, the invention proposes a kind of serial communication letters
Cease the general analytic method of agreement.
In order to solve the above-mentioned technical problem, technical scheme is as follows:
A kind of general analytic method of serial communication information protocol, includes the following steps:
Step 1: filling in configuration parameter file according to communication message protocol;The configuration parameter include protocol byte length,
Frame head mark, verification mode, variable characteristic parameter, the characteristic parameter of variable includes variable declaration, varying byte length, variable
Zoom factor, types of variables, multibyte variable transmitting-receiving sequence;
Step 2: searching frame head mark;
Step 3: judging whether to find frame head mark;
When finding frame head mark, step 4 is skipped to, otherwise judges whether it is communications information data ending, if being judged as YES,
Parsing terminates, otherwise return step two;
Step 4: since frame head identify start intercept communication information protocol byte length, judgement frame head be identified to it is to be resolved
Whether the byte number of the end of data is less than protocol byte length;
If the byte number that frame head is identified to the end of data to be resolved is less than protocol byte length, parsing terminates, otherwise,
It skips to step 5;
Step 5: carrying out verification judgement to communication message protocol;
If check results are incorrect, the byte and return step two for abandoning frame head identification length in step 2 is held again
Row;Otherwise step 6 is skipped to;
Step 6: reading i-th of variable, sequence parses the characteristic parameter of i-th of variable, and i=1 ... n, n are variable number;
Step 7: judging whether i-th of variable is the last one variable information;
If so, return step two begins looking for frame head mark again, otherwise, return step six reads next variable.
Further, in the step 6, the characteristic parameter that sequence parses i-th of variable further comprises:
1. reading variable declaration;
2. reading varying byte length;
3. rearranging varying byte data sequence according to multibyte variable transmitting-receiving sequence;
4. varying byte data conversion is switched to decimal number according to types of variables;
5. restoring actual physical information divided by variable zoom coefficient.
Advantageous effects of the invention:
In the present invention, by using the general analytic method of serial communication information protocol, according to the byte length of information protocol,
The characteristic parameter of frame head mark, verification mode and variable fills in the information protocol configuration parameter file of different product, opens in product
Begin first to load the configuration parameter file of the product before test, can be realized real time parsing is carried out to output of products information, it can be achieved that
The online data of product shows, analyzes and assesses;In addition, product information agreement can be read and be modified by configuration file, increase
The readability and alterability of agreement, therefore different information protocols can be adapted to by modification configuration file;For those
For client development provide test, assess software enterprise propose a kind of solution of general parsing of information protocol, no longer need to
For the different software communication interfaces of every kind of product customization, the versatility of test software is significantly improved.
Detailed description of the invention
Fig. 1 is a kind of configuration parameter file template of serial communication information protocol proposed by the present invention;
Fig. 2 is a kind of flow chart of the general parsing of serial communication information protocol proposed by the present invention.
Specific embodiment
The present invention is described in further detail below in conjunction with the accompanying drawings.
Compared with conventional analytic method, a kind of general analytic method of serial communication information protocol mainly believes serial communication
Breath agreement is refined and uniformly, and is opened in the form of configuration file to parsing person, so that analytic method of the invention can be with
Protocol analysis suitable for nearly all serial communication information.In order to reach the general purpose of protocol analysis, need to solve a variety of
Serial communication messaging protocol format is unified or general problem is arranged.
The present invention is realized for serial communication information protocol to be unified for and be expressed by configuration parameter.Referring to Fig.1, serial
In the profile template of communication message protocol, the configuration parameter of communication protocol first include protocol byte length, frame head mark,
The characteristic parameter of verification mode, variable;Protocol byte length is the length of a cycle transmission in communication, and unit is byte
Number;The frame head of agreement identifies, with hexadecimal mark, using space as blank character between multiple bytes;The verification of protocol information
Mode, the method for calibration in characterization information transmission process.
Secondly the characteristic parameter description of the variable of communication protocol includes variable declaration, varying byte length, types of variables, change
Measure zoom factor, multibyte variable transmitting-receiving sequence;Variable declaration, that is, variable name is for showing;Varying byte length is divided into 1~8
Eight kinds of byte;Types of variables is divided into unsigned int (U), has symbol integer (I), single-precision floating point (F) and double-precision floating point (D)
Four kinds;Variable zoom coefficient is used to describe the multiple restored when amplification or variable receive when variable is sent, and variable zoom coefficient is
Can mixed decimal decimal number;Multibyte variable transmitting-receiving sequence is divided into first low rear high (LH) and two kinds of from low to high (HL).
Referring to Fig. 2, a kind of general analytic method of serial communication information protocol provided by the invention includes the following steps:
Step 1: filling in configuration parameter file according to communication message protocol;The configuration parameter include protocol byte length,
Frame head mark, transmission cycle, verification mode, variable characteristic parameter, the characteristic parameter of variable includes variable declaration, varying byte
Length, variable zoom coefficient, types of variables, multibyte variable transmitting-receiving sequence.
Step 2: searching frame head mark;
Step 3: judging whether to find frame head mark;
When finding frame head mark, step 4 is skipped to, otherwise judges whether it is communications information data ending, if being judged as YES,
Parsing terminates, otherwise return step two;
Step 4: since frame head identify start intercept communication information protocol byte length, judgement frame head be identified to it is to be resolved
Whether the byte number of the end of data is less than protocol byte length;
If the byte number that frame head is identified to the end of data to be resolved is less than protocol byte length, parsing terminates, otherwise,
It skips to step 5;
Step 5: carrying out verification judgement to communication message protocol;
If check results are incorrect, the byte and return step two for abandoning frame head identification length in step 2 is held again
Row;Otherwise step 6 is skipped to;
Step 6: reading i-th of variable, sequence parses the characteristic parameter of i-th of variable, and i=1 ... n, n are variable number;
It is specific as follows:
6.1 read variable declaration;
6.2 read varying byte length;
6.3 rearrange varying byte data sequence according to variable transmitting-receiving sequence;
Varying byte data conversion is switched to decimal number according to types of variables by 6.4;
6.5 restore actual physical information divided by variable zoom coefficient;
Step 7: judging whether i-th of variable is the last one variable information;
If so, return step two begins looking for frame head mark again, otherwise, return step six reads next variable.
The foregoing is only a preferred embodiment of the present invention, but scope of protection of the present invention is not limited thereto,
Anyone skilled in the art in the technical scope disclosed by the present invention, according to the technique and scheme of the present invention and its
Inventive concept is subject to equivalent substitution or change, should be covered by the protection scope of the present invention.