CN115622986A - Sensor communication protocol analysis method, system, storage medium and electronic equipment - Google Patents

Sensor communication protocol analysis method, system, storage medium and electronic equipment Download PDF

Info

Publication number
CN115622986A
CN115622986A CN202211156537.8A CN202211156537A CN115622986A CN 115622986 A CN115622986 A CN 115622986A CN 202211156537 A CN202211156537 A CN 202211156537A CN 115622986 A CN115622986 A CN 115622986A
Authority
CN
China
Prior art keywords
data
sensor
communication protocol
template
program
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.)
Pending
Application number
CN202211156537.8A
Other languages
Chinese (zh)
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.)
Kingsun Optoelectronic Co ltd
Original Assignee
Kingsun Optoelectronic 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 Kingsun Optoelectronic Co ltd filed Critical Kingsun Optoelectronic Co ltd
Priority to CN202211156537.8A priority Critical patent/CN115622986A/en
Publication of CN115622986A publication Critical patent/CN115622986A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/02Protocols based on web technology, e.g. hypertext transfer protocol [HTTP]
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/12Protocols specially adapted for proprietary or special-purpose networking environments, e.g. medical networks, sensor networks, networks in vehicles or remote metering networks
    • 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
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L12/00Data switching networks
    • H04L12/28Data switching networks characterised by path configuration, e.g. LAN [Local Area Networks] or WAN [Wide Area Networks]
    • H04L12/40Bus networks
    • H04L2012/40208Bus networks characterized by the use of a particular bus standard
    • H04L2012/40228Modbus

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)
  • Computer Security & Cryptography (AREA)
  • Arrangements For Transmission Of Measured Signals (AREA)

Abstract

The invention relates to the technical field of sensor communication, in particular to a sensor communication protocol analysis method, which is characterized in that type data of a sensor is uniformly stored, a JSON structure is adopted to design a communication protocol analysis template of the sensor, when sensor information is updated, the sensor type data only needs to be managed on a management platform, operations such as addition, deletion, query and the like are carried out, the updated sensor type data is issued through an MQTT communication protocol or the updated sensor type data is downloaded through an HTTP communication protocol, a dynamic ring monitoring program does not need to be updated, so that the updating work of the sensed data is simpler, the program does not need to be updated, the efficiency is high, and the operation and maintenance cost can be reduced.

Description

Sensor communication protocol analysis method, system, storage medium and electronic equipment
Technical Field
The present invention relates to the field of sensor communication technologies, and in particular, to a method and a system for analyzing a sensor communication protocol, a storage medium, and an electronic device.
Background
In the power environment monitoring system, various sensors are needed, such as a temperature sensor for monitoring the temperature of the case, a humidity sensor for monitoring the humidity of the case, an intelligent electric meter for monitoring the voltage, current and energy consumption of the case, a water leakage sensor for monitoring whether the case leaks water, a leakage sensor for monitoring whether the case leaks electricity, and the like. The sensors have the common characteristic that the protocol frames are all based on Modbus protocol protocols, and although manufacturers can design equipment communication protocols based on the Modbus protocol protocols, the definitions of the functions and the data formats of the sensors by each manufacturer are different, so that each manufacturer basically has a set of protocols which are only suitable for the sensors of the manufacturer based on the function design. Even with sensors of the same function, the protocols of different manufacturers may differ.
This causes a problem that if a sensor of each manufacturer needs a dedicated analysis logic, the protocol analysis work becomes heavy and is not easy to expand, for example, if a sensor of a manufacturer needs to be newly added, a protocol analysis program needs to be updated to add a new protocol, and if a supplier needs to be replaced in a later period, the program needs to be updated, which causes the analysis work to be busy, the development efficiency is slow, and the operation and maintenance cost is high.
Disclosure of Invention
The invention provides a sensor communication protocol analysis method aiming at the problems in the prior art, which only needs to manage sensor type data on a management platform, then sends updated sensor type data through an MQTT communication protocol or downloads the updated sensor type data through an HTTP communication protocol, and does not need to update a dynamic loop monitoring program, so that the update work of the sensed data is simpler, the program does not need to be updated, the efficiency is high, and the operation and maintenance cost can be reduced.
In order to solve the technical problem, the invention discloses a sensor communication protocol analysis method on one hand, which comprises the following steps:
setting and storing sensor information: for each sensor, adopting a JSON structure and defining a communication protocol analysis template of the sensor according to a Modbus protocol; storing information of each sensor and a communication protocol analysis template thereof in a data memory;
sensor updating: the sensor is connected with a dynamic loop monitoring program which comprises a serial port communication program, a communication protocol analysis program and a network communication program; a user updates sensor information through a management platform, wherein the sensor information comprises addition, modification and deletion of a sensor; the management platform issues the update data to the dynamic ring monitoring program through an MQTT communication protocol, or the dynamic ring monitoring program actively requests the update data through an HTTP communication protocol;
analyzing an issued instruction of the management platform: acquiring basic information of a target sensor to be analyzed from a data storage, wherein the basic information comprises a serial port ID, type data, an actual equipment address of the sensor, an equipment address acquired from a communication protocol analysis template and an instruction template to be issued to the sensor; replacing the acquired equipment address with the actual equipment address of the target sensor, performing CRC (cyclic redundancy check) to obtain a new instruction template to be issued to the sensor, and sending the new instruction template to the target sensor through a serial port;
and (3) analyzing the response data of the sensor: and acquiring response data sent by the target sensor, comparing the response data with a response data template of the target sensor in the data storage, if the comparison result is consistent, the response data is valid, and otherwise, discarding the response data for re-acquisition.
Preferably, the information of the sensor is set as a sensor type table, wherein the information of the sensor includes a sensor type ID, a name, a manufacturer, a type, and a communication protocol resolution template.
Preferably, the device address obtained from the communication protocol resolution template is obtained from a device address starting position and a device address length in the communication protocol resolution template of the target sensor.
Preferably, the analysis of the issued command of the management platform further includes the following steps:
converting the instruction template into a 16-system array;
and intercepting the device address from the instruction template converted into the 16-system array according to the device address starting position and the device address length, and replacing the device address with the actual device address to obtain a new instruction template.
Preferably, the analysis of the issued instruction of the management platform further includes the following steps:
thread locking is carried out on the new instruction template obtained after CRC checking, and thread lock timeout time is set;
sending a new instruction template obtained after CRC to the obtained serial port ID of the target sensor;
if the serial port ID of the target sensor receives the signal, the thread lock is cancelled, and the analysis of the sensor response data is entered;
and if the serial port ID of the target sensor does not receive the signal and is overtime, the thread lock is cancelled.
Preferably, the analysis of the sensor response data includes the following steps:
acquiring response data in a 16-system array format sent by a target sensor through a serial port;
acquiring the sensor type of a target sensor and an issued instruction of a user;
acquiring a response data instruction template in a communication protocol analysis template of the target sensor according to the issued instruction, and converting the response data instruction template into a 16-system array;
comparing the length of the response data instruction template with the length of the response data; if the lengths are not consistent, the flow is stopped, and if the lengths are consistent, the CRC value of the response data of the target sensor is compared with the CRC value of the response data instruction template;
if the CRC check values are different, the process is stopped; if the CRC checks are the same, traversing a response data set in a response data instruction template in the issued instruction, and obtaining the position of the data and the length of the data from the response data set;
intercepting the data content according to the position of the data and the length of the data;
acquiring a data conversion category from the response data set, and performing corresponding data conversion on data contents;
and acquiring an additional operation type, an additional operation value and a data type from the response data set, performing additional operation on the converted data content, and returning the data type and the additionally operated data content.
Preferably, the management platform issues instruction data to the dynamic ring monitoring program through an MQTT communication protocol, and the dynamic ring monitoring program reports the data to the user through the MQTT communication protocol or an HTTP communication protocol; the MQTT communication method comprises the following steps:
1) The management platform issues data to the dynamic ring monitoring program through MQTT:
the dynamic loop monitoring program is connected to a designated MQTT proxy server through a user name and a password, and issues a data theme to an MQTT proxy server subscription management platform;
the data processor is connected to a designated MQTT proxy server through a user name and a password; the management platform issues data content, and the data content is delivered to the data processor for processing through the data interface device; the data processor issues data subject issue content to the MQTT proxy server;
the target dynamic loop monitoring program receives data content transmitted by a management platform and forwarded by an MQTT proxy server;
2) The dynamic ring monitoring program uploads data to the data processor:
the data processor is connected to a designated MQTT proxy server through a user name and a password, and subscribes to receive a data reporting topic from the MQTT proxy server;
the dynamic loop monitoring program is connected to a designated MQTT proxy server through a user name and a password, and reports subject release contents to the MQTT proxy server;
and the data processor receives the reported data content.
The invention discloses a sensor communication protocol analysis system in a second aspect, which comprises a management platform, a service layer, an intermediate layer and a dynamic ring monitoring host;
the management platform is used for user operation management;
the service layer comprises a data interface device, a data processor and a data memory; the data interface device is used for receiving a data request of the management platform and a data reporting request of the dynamic ring monitoring host; the data processor is used for communicating with the data memory to realize the addition, deletion, inquiry, modification and storage of data; the data storage is stored with a sensor type table, the sensor type table comprises sensor information of different manufacturers and different functions and a communication protocol analysis template of the sensor, and the communication protocol analysis template is defined by combining a JSON structure with a communication protocol of each sensor according to a Modbus protocol;
the management platform issues the update data of the sensor to the dynamic ring monitoring host through the MQTT communication protocol, and the dynamic ring monitoring host requests the data interface unit to download the update data of the sensor through the HTTP communication protocol;
the dynamic ring monitoring host comprises a sensor and a dynamic ring monitoring program, the dynamic ring monitoring program comprises a serial port communication program, a communication protocol analysis program and a network communication program, the serial port communication program is used for communicating with the sensor through a serial port, the communication protocol analysis program is used for uniformly analyzing communication protocols of various sensors, and the network communication program is used for communicating with a service layer through an MQTT communication protocol and an HTTP communication protocol.
A third aspect of the present invention discloses a computer storage medium storing computer instructions for executing a sensor communication protocol parsing method as described above when the computer instructions are invoked.
The fourth aspect of the present invention discloses an electronic device, wherein the electronic device includes:
a processor; and the number of the first and second groups,
a memory arranged to store computer executable instructions that, when executed, cause the processor to perform a sensor communication protocol parsing method as described above. The invention has the beneficial effects that:
according to the sensor communication protocol analysis method provided by the invention, the type data of the sensor is uniformly stored, the JSON structure is adopted to design the communication protocol analysis template of the sensor, when the information of the sensor is updated, the management platform is only required to manage the type data of the sensor, the operations such as addition, deletion, query and the like are carried out, the updated type data of the sensor is issued through the MQTT communication protocol or the updated type data of the sensor is downloaded through the HTTP communication protocol, and the dynamic loop monitoring program is not required to be updated, so that the updating work of the sensed data is simpler, the program is not required to be updated, the efficiency is high, and the operation and maintenance cost can be reduced.
Drawings
FIG. 1 is a block diagram of the system architecture of the present invention;
FIG. 2 is a flow chart of the present invention for sending data of the latest sensor type to the dynamic loop monitoring program through MQTT communication;
FIG. 3 is a flow chart of downloading the latest sensor type data through the data interface device of the HTTP communication request service layer according to the present invention;
FIG. 4 is a flow chart of the issue instruction resolution of the present invention;
fig. 5 is a flow chart illustrating the analysis of the response data of the sensor according to the present invention.
Detailed Description
In order to facilitate understanding of those skilled in the art, the present invention is further described below with reference to the following examples and the accompanying drawings, which are not intended to limit the present invention. The present invention is described in detail below with reference to the attached drawings.
The first embodiment is as follows:
the sensor communication protocol analysis method provided by the embodiment comprises the following steps:
s1, setting and storing sensor information:
for each sensor, adopting a JSON structure and defining a communication protocol analysis template of the sensor according to a Modbus protocol; storing the information of each sensor and the communication protocol analysis template thereof in a data memory; preferably, the information of the sensor is set into a sensor type table, wherein the information of the sensor comprises a sensor type ID, a name, a manufacturer, a type and a communication protocol analysis template, and the communication protocol analysis template is shown in table 2 and comprises an instruction set and function descriptions of each function instruction, and is used for a subsequent analysis management platform to issue an instruction and query application for analyzing response data of the sensor;
s2, sensor updating:
the sensor is connected with a dynamic loop monitoring program which comprises a serial port communication program, a communication protocol analysis program and a network communication program;
a user updates sensor information through a management platform, wherein the sensor information comprises the addition, modification, inquiry and deletion of a sensor;
the management platform issues the update data to the dynamic ring monitoring program through the MQTT communication protocol, or the dynamic ring monitoring program actively requests the update data through the HTTP communication protocol;
the MQTT communication protocol is based on TCP, and is responsible for actively reporting data to a service layer by an upward industrial control program of the dynamic ring, and is responsible for issuing instructions to the industrial control program of the dynamic ring by a downward management platform through an interface. The HTTP communication protocol is used for taking charge of the dynamic ring industrial control program to actively report data to the service layer. The MQTT communication protocol can completely meet the upward and downward communication requirements, the HTTP communication protocol can only report data upwards, and the intermediate layer supports the HTTP communication protocol because the number of sensors in the dynamic ring monitoring host is small, only a dynamic ring monitoring program is needed to report data regularly, and the intermediate layer directly communicates with the data interface device through the HTTP communication protocol without active query or control, so that the data can be uploaded without erecting an MQTT communication protocol server, and the resources of a service layer are saved.
S3, analysis of an issued instruction of the management platform:
acquiring basic information of a target sensor to be analyzed from a data storage, wherein the basic information comprises a serial port ID, type data, an actual equipment address of the sensor, an equipment address acquired from a communication protocol analysis template and an instruction template to be issued to the sensor;
and after replacing the acquired equipment address with the actual equipment address of the target sensor, performing CRC (cyclic redundancy check) to obtain a new instruction template to be issued to the sensor, and sending the new instruction template to the target sensor through a serial port.
Optionally, the device address obtained from the communication protocol parsing template is obtained from a device address starting position and a device address length in the communication protocol parsing template of the target sensor, specifically, as illustrated in the explanation of the function instruction of the instruction set in the communication protocol parsing template shown in table 2, description of the device address starting position: because serial port communication is bus type communication, an upper computer (such as a management platform) issues an instruction to a serial port, and in order to ensure that a target sensor accurately receives the instruction, a unique equipment address in a serial port bus needs to be defined in a protocol, and the unique equipment address is the same as the equipment address defined in sensor firmware; length of device address: the identification device address has several bytes, and the location of the "device address" in the instruction template is obtained in cooperation with the "device address start location", and this field is used to identify that the device address of the sensor is the several bytes in the instruction template. Therefore, in the actual resolution, the device address obtained from the communication protocol resolution template needs to be replaced with the actual device address.
S4, analyzing response data of the sensor:
and acquiring response data sent by the target sensor, comparing the response data with a response data template of the target sensor in the data memory, if the comparison result is consistent, the response data is valid, and otherwise, discarding the response data for re-acquisition.
In the embodiment, the type data of the sensor is uniformly stored, and the JSON structure is adopted to design the communication protocol analysis template of the sensor, so that when the sensor information is updated, the sensor type data only needs to be managed on the management platform, the operations such as addition, deletion, query and the like are performed, the updated sensor type data is issued through the MQTT communication protocol or the updated sensor type data is downloaded through the HTTP communication protocol, a dynamic ring monitoring program does not need to be updated, the sensed data updating work is simpler, the program does not need to be updated, the efficiency is high, and the operation and maintenance cost can be reduced.
The specific work of the sensor communication protocol analysis method of the embodiment includes:
1. as shown in table 1 (sensor type table) and table 2 (communication protocol analysis template configuration table of sensors), a sensor type table is defined first, and a communication protocol analysis template thereof is designed.
TABLE 1
Figure BDA0003858993160000101
TABLE 2
Figure BDA0003858993160000102
Figure BDA0003858993160000111
Figure BDA0003858993160000121
2. After the sensor type table is defined, the management platform performs management operations such as adding, deleting, modifying and the like on the sensor types through a data interface device provided by the service layer, and the received data parameter definition of the newly added sensor type interface, the received parameter definition of the modified sensor type interface and the received data parameter definition of the deleted sensor type interface are respectively shown in table 3 (the received data parameter configuration table of the newly added sensor type interface), table 4 (the received data parameter configuration table of the modified sensor type interface) and table 5 (the received data parameter configuration table of the deleted sensor type interface).
TABLE 3
Figure BDA0003858993160000122
Figure BDA0003858993160000131
TABLE 4
Figure BDA0003858993160000132
TABLE 5
Field(s) Type (B) Whether it is necessary or not Description of the invention
SensorSid Character string Is that Unique identification of the sensor in the data sheet
3. Setting MQTT communication, including the design of MQTT communication theme, the step of sending data through MQTT communication and the step setting of uploading data through MQTT communication:
3.1, MQTT theme design:
the data reporting theme of the dynamic ring monitoring program is as follows: the system is used for reporting data to a service layer by a dynamic ring monitoring program, wherein the theme is a three-layer theme, the first layer is a project name, the second layer is a fixed value 'Box', and the third layer is a local dynamic ring monitoring program identification serial number;
the management platform issues a data theme: the system comprises a management platform, a dynamic ring monitoring program and a dynamic ring monitoring program, wherein the management platform is used for issuing data to the dynamic ring monitoring program, the theme is a three-layer theme, the first layer is a project name, the second layer is a fixed value 'Plate', and the third layer is an identification serial number of a target dynamic ring monitoring program;
the service layer receives the data reporting theme: the system comprises a service layer, a dynamic ring monitoring program and a dynamic ring monitoring program, wherein the service layer receives data reported by all dynamic ring monitoring programs, the theme is a three-layer theme, the first layer is a project name, the second layer is a fixed value 'Box', and the third layer is a wildcard (#);
3.2, the management platform sends data to the dynamic ring monitoring program through MQTT:
the dynamic loop monitoring program is connected to a designated MQTT proxy server through a user name and a password, and issues a data theme to an MQTT proxy server subscription management platform;
the data processor is connected to a designated MQTT proxy server through a user name and a password; the management platform issues data content, and the data content is delivered to the data processor for processing through the data interface device; the data processor issues data subject issue content to the MQTT proxy server;
the target dynamic loop monitoring program receives data content transmitted by a management platform and forwarded by an MQTT proxy server;
3.3, the dynamic ring monitoring program uploads data to the data processor:
the data processor is connected to a designated MQTT proxy server through a user name and a password, and subscribes to receive a data reporting theme from the MQTT proxy server;
the dynamic loop monitoring program is connected to a designated MQTT proxy server through a user name and a password, and reports subject release contents to the MQTT proxy server;
and the data processor receives the reported data content.
4. The HTTP communication is prior art, and the dynamic ring monitoring program directly requests data from the data interface device of the service layer or reports data, and the specific process is prior art, which is not described in detail in this embodiment.
5. The working mode of the dynamic loop monitoring program for updating the latest data of the sensor types is as follows:
5.1, transmitting the latest sensor type data to the dynamic ring monitoring program through MQTT, as shown in figure 2, the mode can transmit the latest sensor type data in real time, after the management platform manages the sensor types, the latest sensor type data is transmitted to the dynamic ring monitoring program through MQTT communication, and the data transmitting process is described in the step process of the MQTT communication, so that the supported communication protocol is updated in time;
5.2, downloading the latest sensor type data through a data interface device of the HTTP request service layer, as shown in fig. 3, in order to prevent the latest sensor type data from being unsuccessfully issued due to network or other problems when data are issued in MQTT communication, starting a timing program by the dynamic ring monitoring program to regularly check whether the sensor type data of the dynamic ring monitoring program is the latest, and downloading the latest sensor data through the data interface device of the service layer if the sensor type data of the dynamic ring monitoring program is not the latest.
6. The dynamic loop monitoring program configures the serial port information of the sensor:
the serial communication is bus communication, and when the moving loop monitoring program sends an instruction to the sensor through the serial port, the moving loop monitoring program needs to know the serial port of the host and the equipment address written in the sensor firmware. The serial port ID and the equipment address of each sensor connected to the serial port of the dynamic ring monitoring host are persistently stored locally, and the dynamic ring monitoring program can conveniently obtain the serial port ID and the equipment address of a certain sensor when sending an instruction to the sensor.
7. The dynamic loop monitoring program analyzes the communication protocol of the sensor:
7.1, as shown in fig. 4, the analysis flow of the issued instruction includes:
7.1.1, acquiring a serial port ID and an equipment address (an actual equipment address) of a target sensor for issuing an instruction from a local place, and acquiring the configuration of the serial port information of the sensor in the mode of the working mode 6;
7.1.2, acquiring sensor type data of the target sensor, wherein the sensor type data is acquired through MQTT communication or HTTP communication in the working mode 5;
7.1.3, selecting one instruction from an instruction set of target sensor type data, namely table 2;
7.1.4, converting the instruction template data obtained from the instruction set into a 16-system array;
7.1.5, obtaining the starting position and length of the device address from the instruction set;
7.1.6, intercepting the device address from the instruction template data converted into the 16-system array according to the device address start position and length, and replacing the device address with the actual device address obtained in step 7.1.1 to obtain new instruction template data (16-system array);
7.1.7, obtaining CRC check bits and CRC check length from the instruction set and obtaining CRC configuration data of the sensor from sensor type data;
7.1.8, according to the CRC check bit, the CRC check length and the CRC configuration data, performing CRC check on the instruction template data to obtain an actual CRC check value (16-system array);
7.1.9 obtaining the starting position and length of the CRC check value from the instruction set;
7.1.10, intercepting the CRC value from the template data according to the CRC value start position and length, and replacing the CRC value with the actual CRC value obtained in step 7.1.9 to obtain new instruction template data (16-system array);
7.1.11, and a pair line Cheng Jiasuo, setting a thread lock timeout time; (threads are prior art)
7.1.12, sending new instruction template data (data generated in step 7.1.10) to a serial port connected with the device (obtained in step 7.1.1);
7.1.13 storing target sensor type data and issued instructions in a current thread;
7.1.14, when the sensor receives the message, cancels the thread lock, enters the response data analysis process, if the message is not received and the time is out, cancels the thread lock.
7.2 as shown in fig. 5, the workflow of sensor response data analysis includes:
7.2.1, monitoring the serial port by the dynamic loop monitoring host, and receiving response data 1 in a 16-system array format sent by the sensor through the serial port;
7.2.2, acquiring sensor type data of the target sensor and a transmitted instruction from the thread;
7.2.3, obtaining response data 2 from the issued instruction, and converting the response data into a 16-system array;
7.2.4, comparing the length of the response data 2 obtained in step 7.2.3 with the length of the response data 1 obtained in step 7.2.1;
7.2.5, if the lengths are not consistent, stopping the process;
7.2.6, if the lengths are the same, the position and length of CRC value are obtained from the response data 2 of the issued command;
7.2.7, and truncating the CRC check value of the response data 1 obtained in step 7.2.1 according to the position and length of the CRC check value;
7.2.8, obtaining the position and the length of the CRC check bit of the response data from the response data 2 of the issued command;
7.2.9, obtaining the CRC check configuration of the sensor from the sensor type data;
7.2.10, checking the response data according to the position and length of the CRC check bit and the CRC check configuration to obtain an actual CRC check value;
7.2.11, comparing the CRC check value of the response data (step 7.2.7) and the actual CRC check value (step 7.2.10);
7.2.12, if the CRC check values are different, the flow is stopped;
7.2.13, which is the same as CRC check, traverses the response data set in the response data 2 in the issued command;
7.2.14, obtaining the position and length of data from the response data set of the issued command;
7.2.15, intercepting the data content (16-system array) from the response data 1 (step 7.2.1) according to the position and length of the data;
7.2.16, obtaining data conversion type from the response data set of the issued command, and performing corresponding data conversion on the data content;
7.2.17 obtaining extra operation type and extra operation value from response data set of issued instruction, and performing extra operation on converted data content
7.2.18, obtaining the data type from the response data set of the issued command, and returning the data type and the data content after additional operation.
The method for analyzing the sensor communication protocol can quickly support or remove the protocol analysis supporting a certain sensor, when the protocol analysis supporting a certain sensor needs to be newly added or does not support the certain sensor any more, the sensor type data only needs to be managed through the management platform, and then the sensor type data is issued to the dynamic ring monitoring program through the MQTT or the dynamic ring monitoring program actively requests the service layer for updating the data through the HTTP, and the dynamic ring monitoring program does not need to be updated. In addition, the development efficiency can be improved, and a template-based protocol analysis method enables developers to analyze the sensor protocols supported by all projects without paying attention to a specific protocol of a certain sensor and only developing one method. The operation and maintenance cost can be reduced, the protocol is updated without updating programs, repeated upgrading of client application programs is avoided, and only data updating on the management platform is needed.
Example two:
the sensor communication protocol parsing system provided in this embodiment, as shown in fig. 1, includes a management platform, a service layer, an intermediate layer, and a dynamic ring monitoring host.
Specifically, the functions of the respective structures are:
the management platform is used for the user to operate and manage.
The service layer comprises a data interface device, a data processor and a data memory; the data interface device is used for receiving a data request of the management platform and receiving a data reporting request of the dynamic ring monitoring host; the data processor is used for communicating with the data memory to realize the addition, deletion, inquiry, modification and storage of data; the data storage stores a sensor type table, the sensor type table comprises sensor information of different manufacturers and different functions and a communication protocol analysis template of the sensor, and the communication protocol analysis template is defined according to a Modbus protocol by combining a JSON structure with a communication protocol of each sensor.
The middle layer is provided with an MQTT communication protocol and an HTTP communication protocol, the management platform issues the update data of the sensor to the dynamic ring monitoring host through the MQTT communication protocol, and the dynamic ring monitoring host requests the data interface unit to download the update data of the sensor through the HTTP communication protocol.
The dynamic loop monitoring host comprises a sensor and a dynamic loop monitoring program, the dynamic loop monitoring program comprises a serial port communication program, a communication protocol analysis program and a network communication program, the serial port communication program is used for communicating with the sensor through a serial port, the communication protocol analysis program is used for uniformly analyzing communication protocols of various sensors, and the network communication program is used for communicating with a service layer through an MQTT communication protocol and an HTTP communication protocol.
In the embodiment, the sensor type table is stored in the data storage, and the JSON structure is adopted for designing the communication protocol analysis template of the sensor, so that the updating through MQTT communication and HTTP communication is facilitated, the dynamic loop monitoring program does not need to be changed repeatedly, the development and management efficiency of workers is improved, and the operation and maintenance cost is reduced.
Example three:
the present embodiment discloses a computer-readable storage medium storing a computer program for electronic data exchange, wherein the computer program causes a computer to execute the steps of the sensor communication protocol parsing method described in the first embodiment.
Example four:
the present embodiment discloses a computer program product comprising a non-transitory computer readable storage medium storing a computer program, and the computer program is operable to cause a computer to perform some or all of the steps of the sensor communication protocol parsing method described in the first embodiment.
Example five:
the electronic device disclosed in this embodiment, wherein the electronic device includes:
a processor; and a memory arranged to store computer executable instructions (program code), which may be an electronic memory such as a flash memory, an EEPROM (electrically erasable programmable read only memory), an EPROM, a hard disk, or a ROM. The memory has a memory space for storing program code for performing any of the method steps in the embodiments. For example, the memory space for the program code may comprise respective program codes for implementing the respective steps in the above method, respectively. The program code can be read from and written to one or more computer program products. These computer program products comprise a program code carrier such as a hard disk, a Compact Disc (CD), a memory card or a floppy disk. Such a computer program product is typically the computer-readable storage medium of embodiment four. The computer-readable storage medium may have storage sections, storage spaces, and the like storage units arranged similarly to the memory in the electronic device of the present embodiment. The program code may be compressed, for example, in a suitable form. In general, the memory unit stores program code for performing the steps of the method according to the invention, i.e. program code readable by a processor such as the like, which, when run by an electronic device, causes the electronic device to perform the individual steps of the method described above.
Although the present invention has been described with reference to the preferred embodiments, it should be understood that various changes, substitutions and alterations can be made herein without departing from the spirit and scope of the invention as defined by the appended claims.

Claims (10)

1. A sensor communication protocol analysis method is characterized by comprising the following steps:
setting and storing sensor information:
for each sensor, adopting a JSON structure and defining a communication protocol analysis template of the sensor according to a Modbus protocol; storing information of each sensor and a communication protocol analysis template thereof in a data memory;
sensor updating:
the sensor is connected with a dynamic loop monitoring program which comprises a serial port communication program, a communication protocol analysis program and a network communication program;
a user updates sensor information through a management platform, wherein the sensor information comprises addition, modification and deletion of a sensor; the management platform issues the update data to the dynamic ring monitoring program through the MQTT communication protocol, or the dynamic ring monitoring program actively requests the update data through the HTTP communication protocol;
analyzing an issued instruction of the management platform:
acquiring basic information of a target sensor to be analyzed from a data storage, wherein the basic information comprises a serial port ID, type data, an actual equipment address of the sensor, an equipment address acquired from a communication protocol analysis template and an instruction template to be issued to the sensor;
replacing the acquired equipment address with the actual equipment address of the target sensor, performing CRC (cyclic redundancy check) to obtain a new instruction template to be issued to the sensor, and sending the new instruction template to the target sensor through a serial port;
and (3) analyzing the response data of the sensor:
and acquiring response data sent by the target sensor, comparing the response data with a response data template of the target sensor in the data storage, if the comparison result is consistent, the response data is valid, and otherwise, discarding the response data for re-acquisition.
2. The method of claim 1, wherein the method further comprises: and setting the information of the sensor into a sensor type table, wherein the information of the sensor comprises a sensor type ID, a name, a manufacturer, a type and a communication protocol analysis template.
3. The sensor communication protocol parsing method of claim 1, wherein the device address obtained from the communication protocol parsing template is obtained from a device address starting position and a device address length in the communication protocol parsing template of the target sensor.
4. The method for analyzing the sensor communication protocol according to claim 3, wherein the analysis of the command issued by the management platform further comprises the following steps:
converting the instruction template into a 16-system array;
and intercepting the device address from the instruction template converted into the 16-system array according to the device address starting position and the device address length, and replacing the device address with the actual device address to obtain a new instruction template.
5. The method according to claim 1, wherein the step of analyzing the command issued by the management platform further comprises the steps of:
performing thread locking on a new instruction template obtained after CRC checking, and setting thread lock timeout time;
sending a new instruction template obtained after CRC to the obtained serial port ID of the target sensor;
if the serial port ID of the target sensor receives the signal, the thread lock is cancelled, and the analysis of the sensor response data is entered;
and if the serial port ID of the target sensor does not receive the signal and is overtime, the thread lock is cancelled.
6. The method of claim 1, wherein the step of parsing the sensor response data comprises the steps of:
acquiring response data in a 16-system array format sent by a target sensor through a serial port;
acquiring the sensor type of a target sensor and an issued instruction of a user;
acquiring a response data instruction template in a communication protocol analysis template of the target sensor according to the issued instruction, and converting the response data instruction template into a 16-system array;
comparing the length of the response data instruction template with the length of the response data; if the lengths are not consistent, the flow is stopped, and if the lengths are consistent, the CRC value of the response data of the target sensor is compared with the CRC value of the response data instruction template;
if the CRC check values are different, the process is stopped; if the CRC checks are the same, traversing a response data set in a response data instruction template in the issued instruction, and obtaining the position of the data and the length of the data from the response data set;
intercepting data content according to the position of the data and the length of the data; (16 system array)
Acquiring a data conversion category from the response data set, and performing corresponding data conversion on data contents;
and acquiring an additional operation type, an additional operation value and a data type from the response data set, performing additional operation on the converted data content, and returning the data type and the additionally operated data content.
7. The method for parsing a sensor communication protocol according to claim 1, wherein: the management platform issues instruction data to the dynamic ring monitoring program through an MQTT communication protocol, and the dynamic ring monitoring program reports the data to a user through the MQTT communication protocol or an HTTP communication protocol; the MQTT communication method comprises the following steps:
1) The management platform sends data to the dynamic ring monitoring program through MQTT:
the dynamic loop monitoring program is connected to a designated MQTT proxy server through a user name and a password, and issues a data theme to an MQTT proxy server subscription management platform;
the data processor is connected to a designated MQTT proxy server through a user name and a password; the management platform issues data content, and the data content is delivered to the data processor for processing through the data interface device; the data processor issues data subject issue content to the MQTT proxy server;
the target dynamic loop monitoring program receives data contents transmitted by a management platform and forwarded by an MQTT proxy server;
2) The dynamic ring monitoring program uploads data to the data processor:
the data processor is connected to a designated MQTT proxy server through a user name and a password, and subscribes to receive a data reporting topic from the MQTT proxy server;
the dynamic loop monitoring program is connected to a designated MQTT proxy server through a user name and a password, and reports subject release contents to the MQTT proxy server;
and the data processor receives the reported data content.
8. A sensor communication protocol analysis system is characterized in that: the system comprises a management platform, a service layer, a middle layer and a dynamic ring monitoring host;
the management platform is used for user operation management;
the service layer comprises a data interface device, a data processor and a data memory; the data interface device is used for receiving a data request of the management platform and receiving a data reporting request of the dynamic ring monitoring host; the data processor is used for communicating with the data memory to realize the addition, deletion, inquiry, modification and storage of data; the data storage is stored with a sensor type table, the sensor type table comprises sensor information of different manufacturers and different functions and a communication protocol analysis template of the sensor, and the communication protocol analysis template is defined by combining a JSON structure with a communication protocol of each sensor according to a Modbus protocol;
the management platform issues the update data of the sensor to the dynamic ring monitoring host through the MQTT communication protocol, and the dynamic ring monitoring host requests the data interface unit to download the update data of the sensor through the HTTP communication protocol;
the dynamic ring monitoring host comprises a sensor and a dynamic ring monitoring program, the dynamic ring monitoring program comprises a serial port communication program, a communication protocol analysis program and a network communication program, the serial port communication program is used for communicating with the sensor through a serial port, the communication protocol analysis program is used for uniformly analyzing communication protocols of various sensors, and the network communication program is used for communicating with a service layer through an MQTT communication protocol and an HTTP communication protocol.
9. A computer storage medium storing computer instructions which, when invoked, perform a sensor communication protocol parsing method according to any one of claims 1-7.
10. An electronic device, wherein the electronic device comprises:
a processor; and the number of the first and second groups,
a memory arranged to store computer executable instructions that when executed cause the processor to perform a sensor communication protocol parsing method of any one of claims 1-7.
CN202211156537.8A 2022-09-22 2022-09-22 Sensor communication protocol analysis method, system, storage medium and electronic equipment Pending CN115622986A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211156537.8A CN115622986A (en) 2022-09-22 2022-09-22 Sensor communication protocol analysis method, system, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211156537.8A CN115622986A (en) 2022-09-22 2022-09-22 Sensor communication protocol analysis method, system, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN115622986A true CN115622986A (en) 2023-01-17

Family

ID=84858551

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211156537.8A Pending CN115622986A (en) 2022-09-22 2022-09-22 Sensor communication protocol analysis method, system, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN115622986A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116319487A (en) * 2023-03-24 2023-06-23 广州市易鸿智能装备有限公司 Industrial protocol dynamic analysis method and system
CN117636521A (en) * 2024-01-25 2024-03-01 苏州琨山通用锁具有限公司 AI-based intelligent lockset and data center interaction method and intelligent lockset production method

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116319487A (en) * 2023-03-24 2023-06-23 广州市易鸿智能装备有限公司 Industrial protocol dynamic analysis method and system
CN116319487B (en) * 2023-03-24 2023-09-29 广州市易鸿智能装备有限公司 Industrial protocol dynamic analysis method and system
CN117636521A (en) * 2024-01-25 2024-03-01 苏州琨山通用锁具有限公司 AI-based intelligent lockset and data center interaction method and intelligent lockset production method
CN117636521B (en) * 2024-01-25 2024-04-05 苏州琨山通用锁具有限公司 AI-based intelligent lockset and data center interaction method and intelligent lockset production method

Similar Documents

Publication Publication Date Title
CN115622986A (en) Sensor communication protocol analysis method, system, storage medium and electronic equipment
CN102298365B (en) Method for automatically identifying and managing spaceflight measurement and control earth station device change
US7275236B1 (en) Method for programming a multiple device control system using object sharing
US11870658B2 (en) Method and apparatus for updating gateway resource, and IOT control platform
CN104104674A (en) Multiprotocol distributed data acquisition control system of equipment sensor and method thereof
CN110569250B (en) Management method and device for analysis library of Internet of things network element
CN110912782B (en) Data acquisition method, device and storage medium
CN109117158A (en) Firmware update and device
CN112311742A (en) Method, device and system for adapting field gateway data
CN112764874B (en) Virtual machine server information acquisition method based on CMDB configuration management system
CN104468274A (en) Cluster monitor and management method and system
CN108877188B (en) Environment-friendly data concurrent acquisition and multi-network publishing method and device
CN105245582A (en) Data center monitoring method and device
AU2017305172B2 (en) Systems and methods for discovering configurations of legacy control systems
CN113141269B (en) Data acquisition method, device and system
CN113285841B (en) Configuration method of industrial gateway data transmission protocol
JP2010128597A (en) Information processor and method of operating the same
CN113190286B (en) MES system, loading method, terminal and medium for dynamically and remotely loading functional plug-ins
CN112612672B (en) Embedded software real-time running state monitoring method
CN114661569B (en) Dynamic buried point acquisition method for user behavior data
CN115314518A (en) Internet of things management method and system and computer readable storage medium
CN113676353A (en) Control method and device for equipment, storage medium and electronic device
CN211454276U (en) Protocol library docking execution device suitable for Internet of things
CN102185379B (en) Method for exchanging information between distribution measuring and controlling device and upper computer
US11507582B2 (en) Event-driven internet of things (IoT) abstraction using rules

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