Detailed Description
In order to make the objects, features and advantages of the present invention more obvious and understandable, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present invention, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flow chart illustrating an implementation of a data parsing method according to an embodiment of the present invention; as shown in fig. 1.
One aspect of the present invention provides a data parsing method, including:
step 101: a data message is acquired.
Step 102: and decomposing the data message into a plurality of single-frame data according to frames.
Step 103: and extracting data bytes of each of the plurality of single-frame data one by one.
Step 104: and carrying out the binary conversion on the extracted data bytes of each single frame data.
The data analysis method in the embodiment of the present invention first obtains the data packet according to step 101, where the data packet may have multiple source channels, for example, may be obtained from a device with a serial communication function. The data message is generally long serial and multi-frame data, and each frame of data sequentially includes a frame header byte, a data byte and a frame tail byte, wherein the frame header byte is fixed, the number of bytes of the frame tail byte is fixed, and the number of bytes of the data byte is also fixed.
Then, the data message is decomposed into a plurality of single frame data by frame through step 102, specifically: firstly, judging whether a frame header byte exists in a data message, and if so, decomposing the data message into a plurality of single-frame data by taking the previous byte of the frame header byte as a segmentation point.
Then, the data bytes in the single frame data are extracted one by one through step 103.
Finally, the extracted data bytes are subjected to binary conversion through step 104, and the data bytes with the first binary format are converted into the data bytes with the second binary format, wherein the data bytes with the second binary format are data required by an engineer, and the engineer can know data transmission information of the current equipment according to the data, so that the maintenance is facilitated.
Through the steps, the data message is divided into a plurality of single-frame data according to the frame, the data bytes are extracted from each single-frame data, and the data bytes are subjected to the binary conversion, so that the required data can be obtained.
In one implementation, the data message is hexadecimal characters; correspondingly, the data bytes of each extracted single frame data are subjected to the binary conversion, and the binary conversion comprises the following steps: and converting the extracted data bytes of each single frame of data from hexadecimal characters into decimal characters.
In the data analysis method in the embodiment of the present invention, the data packet is in a hexadecimal format, so that when the data packet is converted in step 104, the hexadecimal data bytes are converted into decimal data bytes, so that an engineer can analyze the data.
In one embodiment, extracting data bytes of each of the plurality of single frame data one by one includes: and removing the header bytes and the trailer bytes in the single frame data to obtain the data bytes of the single frame data aiming at each of the plurality of single frame data.
In the data analysis method in the embodiment of the present invention, the specific steps in step 103 are: after acquiring a plurality of single frame data, sequentially removing the frame header byte and the frame tail byte in each single frame data, and only keeping the data byte in the single frame data.
In an implementation manner, removing the header bytes in the single frame data specifically includes: acquiring a frame header byte set value; judging whether the frame header of the single frame data contains a frame header byte set value; and if the frame header of the single frame data contains the frame header byte set value, removing the frame header byte.
In the data analysis method in the embodiment of the invention, the setting values of the frame header bytes are different according to different communication protocols, different communication protocols correspond to different frame header bytes, and the setting values of the frame header bytes corresponding to each communication protocol are fixed. The specific steps of removing the header bytes in the single frame data in step 103 are as follows: firstly, acquiring a frame header byte set value corresponding to a communication protocol, judging whether a frame header byte of each single frame data contains the frame header byte set value, and if the frame header byte of each single frame data contains the frame header byte set value, removing the frame header byte in the single frame data.
In an implementation manner, removing the tail bytes in the single frame data specifically includes: acquiring the number of bytes at the tail of the frame; and removing the frame tail bytes of the single frame data according to the number of the tail bytes.
In the data analysis method in the embodiment of the present invention, since the number of bytes at the end of the frame in each single frame of data is fixed, the specific step of removing the bytes at the end of the frame in the single frame of data in step 103 is as follows: firstly, acquiring the number of bytes at the tail of a frame in a corresponding communication protocol, and then removing the number of bytes which is the same as the number of bytes at the tail of the frame from the tail end of single-frame data so as to acquire the data bytes.
In an implementation manner, the binary conversion of the data bytes of each extracted single frame data specifically includes: acquiring the number of bytes of data; dividing the extracted data bytes of each single frame of data into a plurality of single data bytes according to the number of data bytes; and carrying out binary conversion on a plurality of single data bytes one by one.
According to the data analysis method in the embodiment of the invention, the data bytes in each single frame of data are obtained according to the steps, the general data bytes comprise a plurality of data, and the number of bytes occupied by each data is fixed. Therefore, the specific steps of step 104 are: acquiring the number of bytes occupied by each single data in a corresponding communication protocol, dividing the acquired data bytes according to the number of data bytes to obtain a plurality of single data bytes, carrying out binary conversion on each single data byte, converting the data with the first binary format into the data with the second binary format, wherein the data with the second binary format is the finally obtained required data, and an engineer knows the data transmission information of the current equipment of the equipment according to the finally obtained data to facilitate maintenance.
Fig. 2 is a diagram illustrating an application example of a data parsing method according to an embodiment of the present invention.
The method comprises the following steps: referring to fig. 2, in step 201, a data packet of a certain communication protocol is first obtained, where the data packet is composed of a long series of hexadecimal data, and a header byte of the communication protocol is "1102", a tail byte is 2 bytes, and each data byte is 2 bytes.
Step 202, determining whether the data packet contains a header byte "1102" from the data packet, and if the data packet contains the header byte "1102", decomposing the data packet into a plurality of single frames of data beginning with "1102" by using a previous byte of the header byte as a segmentation point.
Step 203, then, for each single frame of data, "1102" in the single frame of data and the last two bytes in the single frame of data are removed, that is, the pillow byte and the frame tail byte in each single frame of data are removed, so as to obtain the data byte, and then the data byte is divided to generate a plurality of single data bytes.
And step 204, finally, carrying out binary conversion on each single data byte, and converting the single data byte with hexadecimal into a decimal single data byte, wherein the decimal single data byte is the required byte.
Fig. 3 is a schematic structural diagram of a data analysis device according to an embodiment of the present invention, as shown in fig. 3.
Based on the above mentioned data parsing method, another aspect of the present invention provides a data parsing apparatus, which includes:
an acquisition module 301; for obtaining data packets.
A decomposition module 302; for decomposing the data message into a plurality of single frame data by frame.
An extraction module 303; the method is used for extracting data bytes of each of a plurality of single-frame data one by one.
A conversion module 304; for carrying out the binary conversion on the data bytes of each extracted single frame data.
The data analysis apparatus in the embodiment of the present invention first obtains a data packet through the obtaining module 301, where the data packet may have multiple source channels, for example, the data packet may be obtained from a device with a serial communication function. The data message is generally long serial and multi-frame data, and each frame of data sequentially includes a frame header byte, a data byte and a frame tail byte, wherein the frame header byte is fixed, the number of bytes of the frame tail byte is fixed, and the number of bytes of the data byte is also fixed.
The data packet is decomposed into a plurality of single frame data by a decomposition module 302, specifically: firstly, judging whether a frame header byte exists in a data message, and if so, decomposing the data message into a plurality of single-frame data by taking the previous byte of the frame header byte as a segmentation point.
Then, the data bytes in the single frame data are extracted one by the extracting module 303.
Finally, the extracted data bytes are subjected to binary conversion through the conversion module 304, and the data bytes with the first binary format are converted into the data bytes with the second binary format, wherein the data bytes with the second binary format are data required by an engineer, and the engineer can know data transmission information of the current equipment according to the data, so that the maintenance is facilitated.
Through the steps, the data message is divided into a plurality of single-frame data according to the frame, the data bytes are extracted from each single-frame data, and the data bytes are subjected to the binary conversion, so that the required data can be obtained.
Further, the data message is hexadecimal characters; correspondingly, the data bytes of each extracted single frame data are subjected to the binary conversion, and the binary conversion comprises the following steps: and converting the extracted data bytes of each single frame of data from hexadecimal characters into decimal characters.
In the data analysis device in the embodiment of the present invention, the data packet is in a hexadecimal format, so that when the conversion module 304 performs the binary conversion, the hexadecimal data bytes are converted into decimal data bytes, so that an engineer can read the data.
In an implementation manner, the extracting module 303 is specifically configured to: and removing the header bytes and the trailer bytes in the single frame data to obtain the data bytes of the single frame data aiming at each of the plurality of single frame data.
According to the data analysis device in the embodiment of the invention, after a plurality of single-frame data are obtained, the frame header byte and the frame tail byte in each single-frame data are sequentially removed, and only the data byte in the single-frame data is reserved.
In an implementation manner, the extracting module 303 is further specifically configured to: acquiring a frame header byte set value; judging whether the frame header of the single frame data contains a frame header byte set value; and if the frame header of the single frame of data contains the frame header byte set value, removing the frame header byte set value.
In the data analysis device in the embodiment of the invention, the setting values of the frame header bytes are different according to different communication protocols, different communication protocols correspond to different frame header bytes, and the setting values of the frame header bytes corresponding to each communication protocol are fixed. Therefore, the specific steps of the extracting module 303 in removing the header byte in the single frame data are as follows: firstly, acquiring a frame header byte set value corresponding to a communication protocol, judging whether a frame header byte of each single frame data contains the frame header byte set value, and if the frame header byte of each single frame data contains the frame header byte set value, removing the frame header byte in the single frame data.
Further, the extracting module 303 is further specifically configured to: acquiring the number of bytes at the tail of the frame; and removing the frame tail bytes in the single frame data according to the number of the tail bytes.
In the data analysis device in the embodiment of the present invention, since the number of bytes at the end of a frame in each single frame of data is fixed, the specific steps of the extraction module 303 for removing the bytes at the end of a frame in the single frame of data are as follows: firstly, acquiring the number of bytes at the tail of a frame in a corresponding communication protocol, and then removing the number of bytes which is the same as the number of bytes at the tail of the frame from the tail end of single-frame data so as to acquire the data bytes.
Further, the conversion module 304 is further specifically configured to: acquiring the number of bytes of single data; dividing the extracted data bytes of each single frame of data into a plurality of single data bytes according to the number of data bytes; and carrying out binary conversion on a plurality of single data bytes one by one.
According to the data analysis device in the embodiment of the invention, the data bytes in each single frame of data are obtained according to the modules, the general data bytes comprise a plurality of data, and the number of bytes occupied by each data is fixed. Therefore, the specific steps of the conversion module 304 are: acquiring the number of bytes occupied by each single data in a corresponding communication protocol, dividing the acquired data bytes according to the number of data bytes to obtain a plurality of single data bytes, carrying out binary conversion on each single data byte, converting the data with the first binary format into the data with the second binary format, wherein the data with the second binary format is the finally obtained required data, and an engineer knows the data transmission information of the current equipment of the equipment according to the finally obtained data to facilitate maintenance.
The device processes the whole process: the method comprises the steps of firstly obtaining a data message, segmenting the data message into a plurality of single-frame data, then removing a frame header byte and a frame tail byte in each single-frame data to obtain a data byte, then segmenting the data byte to generate a plurality of single data bytes, finally carrying out binary conversion on each single data byte, converting the single data byte with a first binary format into the single data byte with a second binary format, wherein the single data byte with the second binary format is a required byte, and the scheme can efficiently analyze the data message.
Based on the above-provided data parsing method, another aspect of the present invention provides a computer-readable storage medium, the storage medium comprising a set of computer-executable instructions, which when executed, are configured to:
firstly, acquiring a data message; and then judging whether the data message has a frame header byte or not, and if so, decomposing the data message into a plurality of single-frame data by taking the previous byte of the frame header byte as a segmentation point.
Then acquiring a frame header byte set value, and judging whether the frame header of each single frame of data contains the frame header byte set value; and if the frame header of the single-frame data contains the frame header byte set value, removing the frame header byte in the single-frame data.
Then acquiring the number of bytes at the tail of the frame in the corresponding communication protocol, and removing the number of bytes which is the same as the number of bytes at the tail of the frame from the tail end of the single-frame data so as to acquire the data bytes.
And acquiring the number of bytes occupied by each single data in the corresponding communication protocol, and dividing the acquired data bytes according to the number of data bytes to obtain a plurality of single data bytes.
And finally, carrying out binary conversion on each single data byte, converting the data with the first binary format into the data with the second binary format, wherein the data with the second binary format is the finally obtained required data, and an engineer knows the data transmission information of the current equipment of the equipment according to the finally obtained data so as to facilitate maintenance.
The computer instructions implement a process: the method comprises the steps of firstly obtaining a data message, segmenting the data message into a plurality of single-frame data, then removing a frame header byte and a frame tail byte in each single-frame data to obtain a data byte, then segmenting the data byte to generate a plurality of single data bytes, finally carrying out binary conversion on each single data byte, converting the single data byte with a first binary format into the single data byte with a second binary format, wherein the single data byte with the second binary format is a required byte, and the scheme can efficiently analyze the data message.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present invention, "a plurality" means two or more unless specifically defined otherwise.
The above description is only for the specific embodiments of the present invention, but the scope of the present invention is not limited thereto, and any person skilled in the art can easily conceive of the changes or substitutions within the technical scope of the present invention, and the changes or substitutions should be covered within the scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.