Disclosure of Invention
The purpose of the application is to provide a communication protocol with high confidentiality and high communication efficiency.
In order to solve the above technical problem, the present application provides a communication protocol based on the HEX format, which is applied to a host for master-slave communication, and includes:
constructing a data protocol framework based on the HEX format;
writing the function codes and the number corresponding to the data to be sent into the data protocol framework, wherein the number of the data to be sent is multiple;
writing the identity information, the parameter types and the parameters of the data to be sent into the data protocol framework to generate a data packet; wherein the identity information of the data to be transmitted may not be continuous;
and sending the data packet to the slave.
Preferably, in the HEX format-based communication protocol, the writing the identity information, the parameter type, and the parameter of the plurality of data to be sent into the data protocol framework to generate a data packet includes:
and writing the identity information, the parameter types and the parameters of the data to be sent and the check of a preset frame into the data protocol frame to generate the data packet.
Preferably, the HEX format-based communication protocol, the data protocol framework includes: frame header, frame length, frame number, slave equipment address and programmable data stream; wherein the function code, the number, the identity information, the parameter type, and the parameter are written into the programmable data stream.
In order to solve the above technical problem, the present application further provides a communication protocol based on the HEX format, which is applied to a slave device for master-slave communication, and includes:
receiving a data packet sent by a host; wherein the host constructs a data protocol framework based on the HEX format; writing the function codes and the number corresponding to the data to be sent into the data protocol framework, wherein the number of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of the data to be sent into the data protocol framework to generate the data packet; wherein the identity information of the data to be sent may be discontinuous;
and analyzing the data packet.
Preferably, the above mentioned communication protocol based on HEX format, after receiving the data packet sent by the host, includes:
judging whether the information of the data packet is complete or not;
if the data packet is complete, the analyzing the data packet includes: verifying whether the information contained in the trial data packet conforms to a decoding rule; and analyzing the identity information, the parameter type and the parameter of the data to be sent in sequence according to the function code.
Preferably, after parsing the data packet, the HEX format-based communication protocol further includes:
sending a reply frame back to the host.
In order to solve the above technical problem, the present application further provides a communication device based on a HEX format communication protocol, which is applied to a host, and includes:
the constructing module is used for constructing a data protocol framework based on the HEX format;
the writing module is used for writing the function codes and the quantity corresponding to the data to be sent into the data protocol framework, wherein the quantity of the data to be sent is multiple;
the generating module is used for writing the identity information, the parameter types and the parameters of the data to be sent into the data protocol framework to generate a data packet; wherein the identity information of the data to be transmitted may not be continuous;
and the sending module is used for sending the data packet to a slave.
In order to solve the above technical problem, the present application further provides a communication device based on a HEX format communication protocol, which is applied to a slave, and includes:
the receiving module is used for receiving a data packet sent by the host; wherein the host constructs a data protocol framework based on the HEX format; writing the function codes and the number corresponding to the data to be sent into the data protocol framework, wherein the number of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of the data to be sent into the data protocol framework to generate the data packet; wherein the identity information of the data to be transmitted may not be continuous;
and the analysis module is used for analyzing the data packet.
In order to solve the above technical problem, the present application further provides a communication device based on a HEX format communication protocol, including:
a memory for storing a computer program;
a processor for implementing the steps of the HEX format-based communication protocol when executing the computer program.
In order to solve the above technical problem, the present application further provides a computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the steps of the HEX format-based communication protocol method.
The HEX format-based communication protocol provided by the present application, applied to a host, includes: constructing a data protocol framework based on the HEX format; writing the function codes and the number corresponding to the data to be sent into a data protocol framework, wherein the number of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of a plurality of data to be sent into a data protocol framework to generate a data packet; wherein, the identity information of the data to be sent may be discontinuous; and sending the data packet to the slave. The HEX format has an encryption attribute, so that both communication parties can decrypt communication contents, and the identity information of data to be sent in a sent data packet can be discontinuous, namely the data packet contains data information of any address, and the data packet does not need to send data information of continuous addresses, so that the communication efficiency is improved.
In addition, the application also provides a device and a medium, which correspond to the communication protocol based on the HEX format and have the same effects.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all the embodiments. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments in the present application without any creative effort belong to the protection scope of the present application.
The core of the application is to provide a communication protocol based on the HEX format.
In order that those skilled in the art will better understand the disclosure, the following detailed description will be given with reference to the accompanying drawings.
A communication protocol refers to the rules and conventions that must be followed by two entities to complete a communication or service. Data communication systems in a plurality of different geographical locations interconnected by communication channels and devices must have a common language between them to enable their co-operation for information exchange and resource sharing. What, how and when to communicate must follow certain mutually acceptable rules. This rule is the communication protocol. In computer communication, a communication protocol is used for realizing the standard between a computer and a network connection, and if the network does not have a uniform communication protocol, information transmission between the computers cannot be identified. The communication protocol refers to a communication rule stipulated in advance by the communication parties, and can be simply understood as a common language used for mutual conversation among computers. The two computers must use a communication protocol when communicating. The SCPI protocol is a communication protocol based on ASCII data format, through which instruments can be remotely interacted, such as configuring instrument parameters, obtaining instrument data, etc. All commands in the SCPI exist in the form of ASCII code character strings, after a user sends character strings to an instrument, data returned by the instrument is also the character strings, and then the user needs to analyze the meanings of the returned character strings by himself. The security of the communication content is not high due to the ASCII as a readable character; moreover, the SCPI itself has no check mechanism, and is applied to a bus with unreliable transmission, which may have a risk of frame error. Modbus is a serial communication protocol, needs to operate the slave according to a register address and a coil address, and only supports continuous transmission of continuous addresses, which causes reduction of communication speed if multiple instructions need to be transmitted. Therefore, the present application provides a communication protocol based on the HEX format with high security and high communication efficiency, the communication protocol provided by the present application is implemented based on the RS232/RS422/RS485 serial bus technology, fig. 1 is a schematic flow diagram of the communication protocol based on the HEX format provided by the embodiment of the present application, and the communication protocol is applied to a host, and includes:
step S11: constructing a data protocol framework based on the HEX format;
step S12: writing the function codes and the number corresponding to the data to be sent into a data protocol framework, wherein the number of the data to be sent is multiple;
step S13: writing the identity information, the parameter types and the parameters of a plurality of data to be sent into a data protocol framework to generate a data packet; the identity information of the data to be sent may be discontinuous;
step S14: and sending the data packet to the slave.
In this embodiment, the data protocol framework is constructed based on the HEX format, that is, the data protocol framework is constructed according to a preset requirement, so as to fill the data information to be sent, which includes fixed data information, for example, a fixed frame header when the host sends the data information. HEX is known collectively as Intel HEX and such files are commonly used to transfer programs and data to be stored in ROM or EPROM. A Hex file is an ASCII text file made up of a line of text conforming to the Intel Hex file format. In the Intel HEX file, each row contains one HEX record. These records consist of hexadecimal-coded numbers corresponding to machine language code and/or constant data.
The function codes mentioned in this embodiment refer to different preset data codes corresponding to different instructions, and the corresponding function codes are written into a data protocol framework according to the instruction type corresponding to the data to be sent.
The identity information of the data to be sent mentioned in this embodiment may be ID information, a source address, and the like of the data to be sent, and the parameter type and the parameter may be an instruction object, a specific instruction, and the like. After the data packet is generated, the data packet based on the HEX format is sent to the slave
The communication protocol based on the HEX format is applied to a host, after a data protocol framework is constructed based on the HEX format, functional codes and quantity corresponding to data to be sent are written into the data protocol framework, wherein the quantity of the data to be sent is multiple, identity information, parameter types and parameters of the multiple data to be sent are written into the data protocol framework, and a data packet is generated, wherein the identity information of the data to be sent can be discontinuous, and the data packet is sent to a slave. The HEX format has an encryption attribute, effective data can be obtained only by analyzing the data packet according to a set rule by both communication parties, and the identity information of data to be sent in the sent data packet can be discontinuous, namely the data packet contains data information of any address.
According to the above embodiment, step S13 writes the identity information, the parameter type, and the parameter of the multiple data to be sent into the data protocol framework, and generates a data packet, including:
and verifying and writing the identity information, the parameter types and the parameters of the data to be sent and the preset frame into a data protocol frame to generate a data packet.
The default frame check mentioned in this embodiment is one of the most commonly used error checking methods in the field of data communication. A frame of data is treated as a long binary number (for example, a piece of 128-byte information is treated as a 1024-bit binary number), then the data is processed by a specified method, a specific number is obtained as a processing result, finally the specific number is attached to an information code as a check code and then transmitted (or stored) together as a frame, the same processing is carried out when receiving (or reading) is carried out, and whether the specific number and the check code obtained by the check processing are the same or not can be found whether an error occurs in the transmission (or storage) process.
The embodiment provides a preferred solution, and the data protocol framework includes: frame header, frame length, frame number, slave equipment address and programmable data stream; wherein, the function code, number, identity information, parameter type and parameter are written into the programmable data stream.
The data protocol framework provided by the embodiment comprises: frame head, frame length, frame number and slave equipment address, wherein the four data information are unified data information of data to be sent, functional codes, quantity, identity information, parameter types and parameters are written into a programmable data stream, and the functional codes, the quantity, the identity information, the parameter types and the parameters of the data to be sent are written into the programmable data stream according to the specific data information of the data to be sent.
Fig. 2 is a schematic flowchart of a communication protocol based on the HEX format according to an embodiment of the present application, which is applied to a slave, and as shown in fig. 2, a communication protocol based on the HEX format includes:
s21: receiving a data packet sent by a host; the host constructs a data protocol framework based on the HEX format; writing the function codes and the number corresponding to the data to be sent into a data protocol framework, wherein the number of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of a plurality of data to be sent into a data protocol framework to generate a data packet; the identity information of the data to be sent may be discontinuous;
s22: and analyzing the data packet.
The slave computer receives a data packet sent by the host computer and constructs a data protocol framework for the host computer based on the HEX format; writing the function codes and the quantity corresponding to the data to be sent into a data protocol framework, wherein the quantity of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of a plurality of data to be sent into a data protocol framework to generate a data packet; wherein, the identity information of the data to be transmitted may not be continuous.
And the slave machine analyzes the data contained in the data packet after receiving the data packet so as to obtain the instruction information sent by the host machine. Because the HEX format has an encryption attribute, both communication parties can decrypt the communication content, and the identity information of the data to be sent in the sent data packet can be discontinuous, that is, the data packet contains data information of any address, and it is not necessary to send data information of continuous addresses. The communication protocol based on the HEX format has good confidentiality and high communication efficiency.
According to the above embodiment, after receiving the data packet sent by the host in step S21, the method includes:
judging whether the information of the data packet is complete or not;
if complete, the data packet is analyzed, including: and analyzing the identity information, the parameter type and the parameter of the data to be sent in sequence according to the function code.
And judging whether the data packet sent by the host is complete or not, if not, sending error information to the host, and if so, analyzing the data packet, and sequentially analyzing the identity information, the parameter type and the parameters of the data to be sent according to the function code. The function code refers to different preset data codes corresponding to different instructions, and the corresponding function code is written into the data protocol framework according to the instruction type corresponding to the data to be sent.
According to the above embodiment, after parsing the data packet in step S11, the method further includes:
sending the reply frame back to the host.
The slave unit parses the data packet and sends a reply frame back to the host unit, and the embodiment does not limit the specific data information contained in the reply frame, and the slave unit is designed according to actual needs. For example, the operation result corresponding to the data to be sent in the data packet, the information of successfully receiving the data packet, and the like.
In the above embodiments, the detailed description is made on the communication protocol based on the HEX format, and the present application also provides embodiments corresponding to the communication device based on the communication protocol based on the HEX format. It should be noted that the present application describes the embodiments of the apparatus portion from two perspectives, one from the perspective of the function module and the other from the perspective of the hardware.
Fig. 3 is a schematic diagram of a communication device based on a HEX format communication protocol according to an embodiment of the present application, which is applied to a host, and as shown in fig. 3, the communication device includes:
a construction module 31 for constructing a data protocol framework based on the HEX format;
a writing module 32, configured to write the function codes and the number corresponding to the data to be sent into a data protocol framework, where the number of the data to be sent is multiple;
a generating module 33, configured to write the identity information, the parameter types, and the parameters of the multiple pieces of data to be sent into a data protocol framework, and generate a data packet; wherein, the identity information of the data to be sent may be discontinuous;
and a sending module 34, configured to send the data packet to the slave.
Specifically, the constructing module 31 constructs a data protocol framework based on the HEX format; the writing module 32 writes the function codes and the number corresponding to the data to be sent into the data protocol framework, wherein the number of the data to be sent is multiple; the generating module 33 writes the identity information, the parameter types and the parameters of the plurality of data to be sent into the data protocol framework to generate a data packet; wherein, the identity information of the data to be sent may be discontinuous; the sending module 34 sends the data packet to the slave.
In the communication device based on the communication protocol in the HEX format according to this embodiment, because the HEX format has an encryption attribute, both communication parties can analyze the data packet according to a predetermined rule to obtain valid data, and the identity information of the data to be sent in the sent data packet may be discontinuous, that is, the data packet includes data information of any address.
Fig. 4 is a schematic diagram of a communication device based on a HEX format communication protocol according to an embodiment of the present application, which is applied to a slave, as shown in fig. 4, and includes:
a receiving module 41, configured to receive a data packet sent by a host; the host constructs a data protocol framework based on the HEX format; writing the function codes and the number corresponding to the data to be sent into a data protocol framework, wherein the number of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of a plurality of data to be sent into a data protocol framework to generate a data packet; wherein, the identity information of the data to be sent may be discontinuous;
and the parsing module 41 is configured to parse the data packet.
Specifically, the receiving module 41 receives a data packet sent by the host; the host constructs a data protocol framework based on the HEX format; writing the function codes and the number corresponding to the data to be sent into a data protocol framework, wherein the number of the data to be sent is multiple; writing the identity information, the parameter types and the parameters of a plurality of data to be sent into a data protocol framework to generate a data packet; the identity information of the data to be sent may be discontinuous; the parsing module 41 parses the data packet.
And the slave machine analyzes the data contained in the data packet after receiving the data packet so as to obtain the instruction information sent by the host machine. Because the HEX format has an encryption attribute, the two communication parties can analyze the data packet according to a set rule to obtain effective data, and the identity information of the data to be sent in the sent data packet can be discontinuous, that is, the data packet contains data information of any address.
Since the embodiment of the apparatus portion and the embodiment of the method portion correspond to each other, please refer to the description of the embodiment of the method portion for the embodiment of the apparatus portion, and details are not repeated here.
Fig. 5 is a block diagram of another communication apparatus based on a HEX format communication protocol according to an embodiment of the present application, and as shown in fig. 5, the communication apparatus based on the HEX format communication protocol includes: a memory 50 for storing a computer program;
a processor 51 for implementing the steps of the above embodiments of the communication protocol based on the HEX format when executing the computer program.
The communication device based on the HEX format communication protocol provided in this embodiment may include, but is not limited to, a smart phone, a tablet computer, a notebook computer, or a desktop computer.
The processor 51 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like. The Processor 51 may be implemented in at least one hardware form of a Digital Signal Processor (DSP), a Field-Programmable Gate Array (FPGA), and a Programmable Logic Array (PLA). The processor 51 may also include a main processor and a coprocessor, where the main processor is a processor for Processing data in a wake state, and is also called a Central Processing Unit (CPU); a coprocessor is a low power processor for processing data in a standby state. In some embodiments, the processor 51 may be integrated with a Graphics Processing Unit (GPU) which is responsible for rendering and drawing the content required to be displayed on the display screen. In some embodiments, the processor 51 may further include an Artificial Intelligence (AI) processor for processing computational operations related to machine learning.
Memory 50 may include one or more computer-readable storage media, which may be non-transitory. Memory 50 may also include high speed random access memory, as well as non-volatile memory, such as one or more magnetic disk storage devices, flash memory storage devices. In this embodiment, the memory 50 is at least used for storing the following computer program 501, wherein after being loaded and executed by the processor 51, the computer program can implement the relevant steps of the HEX format-based communication protocol disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 50 may also include an operating system 502, data 503, and the like, and the storage manner may be a transient storage manner or a permanent storage manner. Operating system 502 may include Windows, Unix, Linux, and the like. Data 503 may include, but is not limited to, data involved in implementing a HEX format based communication protocol, and the like.
In some embodiments, the communication device based on the HEX format communication protocol may further include a display screen 52, an input/output interface 53, a communication interface 54, a power supply 55, and a communication bus 56.
Those skilled in the art will appreciate that the configuration shown in fig. 5 does not constitute a limitation of a communication device based on a communication protocol of the HEX format and may include more or less components than those shown.
The communication device based on the HEX format communication protocol provided in the embodiment of the present application includes a memory and a processor, and when the processor executes a program stored in the memory, the processor can implement: a communication protocol based on the HEX format. Because the HEX format has an encryption attribute, both communication parties can analyze the data packet according to a set rule to obtain effective data, and the identity information of data to be sent in the sent data packet can be discontinuous, that is, the data packet contains data information of any address.
Finally, the application also provides a corresponding embodiment of the computer readable storage medium. The computer readable storage medium has stored thereon a computer program which, when executed by a processor, performs the steps as described in the HEX format based communication protocol embodiment above.
It is understood that, if the method in the above embodiments is implemented in the form of software functional units and sold or used as a stand-alone product, it can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which is stored in a storage medium and executes all or part of the steps of the methods described in the embodiments of the present application, or all or part of the technical solutions. And the aforementioned storage medium includes: various media capable of storing program codes, such as a usb disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk.
The present embodiment provides a computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements: based on the communication protocol of the HEX format, because the HEX format has an encryption attribute, both communication parties can analyze the data packet according to a set rule to obtain effective data, and the identity information of data to be sent in the sent data packet can be discontinuous, that is, the data packet contains data information of any address.
The HEX format-based communication protocol, the communication device, and the medium provided by the present application are described in detail above. The embodiments are described in a progressive manner in the specification, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description. It should be noted that, for those skilled in the art, it is possible to make several improvements and modifications to the present application without departing from the principle of the present application, and such improvements and modifications also fall within the scope of the claims of the present application.
It is further noted that, in the present specification, relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.