CN117714553A - Data transmission method, device, equipment and medium - Google Patents

Data transmission method, device, equipment and medium Download PDF

Info

Publication number
CN117714553A
CN117714553A CN202311707359.8A CN202311707359A CN117714553A CN 117714553 A CN117714553 A CN 117714553A CN 202311707359 A CN202311707359 A CN 202311707359A CN 117714553 A CN117714553 A CN 117714553A
Authority
CN
China
Prior art keywords
data
message
length
check code
initiator
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
CN202311707359.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.)
Hebei Plant Biotechnology Co ltd
Original Assignee
Hebei Plant Biotechnology 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 Hebei Plant Biotechnology Co ltd filed Critical Hebei Plant Biotechnology Co ltd
Priority to CN202311707359.8A priority Critical patent/CN117714553A/en
Publication of CN117714553A publication Critical patent/CN117714553A/en
Pending legal-status Critical Current

Links

Abstract

The present disclosure relates to the field of data communications technologies, and in particular, to a data transmission method, apparatus, device, and medium. The method comprises the following steps: receiving data, and determining whether a initiator, a protocol version and a message ID in the data are in compliance; if the initiator, the protocol version and the message ID are all in compliance, the message length of the data is obtained, and the residual data length in the data is determined according to a preset communication protocol and is used for representing the length corresponding to the message body in the data; comparing the message length with the residual data length, and if the message length is not greater than the residual data length, acquiring a message body from the data; acquiring a check code from the data, and verifying the integrity of the data according to the check code; and if the data is complete, sending a response signal corresponding to the message body to the sending equipment. The method and the device can analyze accurate and effective content from the received data, and improve the accuracy of data transmission and acquisition.

Description

Data transmission method, device, equipment and medium
Technical Field
The present disclosure relates to the field of data communications technologies, and in particular, to a data transmission method, apparatus, device, and medium.
Background
The communication protocol is a series of standard rules agreed by both communication parties in order to correctly transfer and analyze information, so that both communication parties can accurately transfer and analyze information under the condition of conforming to the communication protocol.
In the related art, a receiver verifies the received data in a check code mode to determine whether the acquired data is complete or not, but the check code has a false detection condition, so that a message analyzed from the received data is inaccurate.
Disclosure of Invention
In order to solve the problem of low accuracy of analyzing messages from received data in the prior art, the application provides a data transmission method, a device, equipment and a medium.
In a first aspect, the present application provides a data transmission method, which adopts the following technical scheme:
a data transmission method performed by a receiving apparatus, comprising:
receiving data, and determining whether a initiator, a protocol version and a message ID in the data are compliant;
if the initiator, the protocol version and the message ID are all in compliance, acquiring the message length of the data, and determining the residual data length in the data according to a preset communication protocol, wherein the residual data length is used for representing the length corresponding to the message body in the data;
Comparing the message length with the residual data length, and if the message length is not greater than the residual data length, acquiring a message body from the data;
acquiring a check code from the data, and verifying the integrity of the data according to the check code;
and if the data is complete, transmitting a response signal corresponding to the message body to transmitting equipment.
By adopting the technical scheme, the data is received, the message length of the data is obtained under the condition that the initiator, the protocol version and the message ID are all compliant, the residual data length in the data can be determined according to the preset communication protocol, the message length and the residual data length are compared, the correct message body can be obtained from the data, the data integrity is verified through the check code in the data, so that the complete data is obtained, the received data can be found out in time when the data does not conform to the preset communication protocol through analysis and multiple times of verification, and therefore accurate and effective content is analyzed from the received data, and the accuracy of data transmission and acquisition is improved.
The present application may be further configured in a preferred example to: if the initiator, the protocol version and the message ID are all compliant, acquiring the message length of the data, including:
If the initiator, the protocol version and the message ID are all compliant, acquiring a message serial number from the data according to the length and the position of the message serial number defined in the preset communication protocol;
and acquiring the message length from the data according to the position and the length of the message length defined in the preset communication protocol.
By adopting the technical scheme, according to the length and the position of the message serial number defined in the preset communication protocol, the accurate message serial number can be obtained from the data, the message serial number can mark the data, the data tracking and searching are convenient, and the data management level is improved.
The present application may be further configured in a preferred example to: determining the length of the rest data in the data according to a preset communication protocol, wherein the method comprises the following steps:
determining the length sum of a start symbol, a protocol version, a message ID, a message serial number, a message length, a check code and an end symbol defined in the preset communication protocol;
determining the length of the data;
and determining the difference value between the length of the data and the sum of the lengths to obtain the length of the residual data.
By adopting the technical scheme, according to the lengths corresponding to the initiator, the protocol version, the message ID, the message serial number, the message length, the check code and the ending symbol which are defined in the preset communication protocol and the length of the received data, the length of the rest data in the data can be determined, and the accuracy of acquiring the message body based on the message length is improved.
The present application may be further configured in a preferred example to: determining whether the initiator, protocol version, and message ID in the data are compliant includes:
acquiring an initiator from the data according to the position and the length of the initiator defined in the preset communication protocol, and determining whether the initiator in the data is compliant according to the content of the initiator defined in the preset communication protocol;
if the start in the data accords with the rule, acquiring a protocol version from the data according to the position and the length of the protocol version defined in the preset communication protocol, and determining whether the protocol version in the data is compliant according to the content of the protocol version defined in the preset communication protocol;
and if the protocol version in the data is compliant, acquiring the message ID from the data according to the position and the length of the message ID defined in the preset communication protocol, and determining whether the message ID in the data is compliant.
By adopting the technical scheme, according to the positions and the lengths of the initiator, the protocol version and the message ID defined by the preset communication protocol, the initiator, the protocol version and the message ID can be sequentially acquired and compliance verification can be carried out, and when a certain item is not in compliance, error data are timely discarded, so that useless operation is avoided, and the data analysis efficiency is improved.
The present application may be further configured in a preferred example to: determining whether a message ID in the data is compliant includes:
comparing the message ID in the data with a preset data type, and determining whether the data type which accords with the message ID in the data exists in the preset data type;
if the preset data type contains a data type which is met by the message ID in the data, judging that the message ID in the data is compliant;
and if the data type which is consistent with the message ID in the data does not exist in the preset data type, judging that the message ID in the data is not compliant.
By adopting the technical scheme, the message ID in the data is compared with the preset data type, so that whether the message ID in the data is in compliance or not can be judged, the message ID represents the data type of the message body, and the accuracy of acquiring the message body can be improved.
The present application may be further configured in a preferred example to: obtaining a check code from the data, verifying the integrity of the data according to the check code, including:
acquiring a check code from the data according to the position and the length of the check code defined in the preset communication protocol;
Generating a target check code according to the protocol version, the message ID, the message serial number, the message length and the message body which are acquired from the data;
comparing the check code with the target check code, and judging whether the check code is successfully compared with the target check code or not;
and if the check code and the target check code can be successfully compared, judging that the data is complete.
By adopting the technical scheme, the target check code can be generated according to the protocol version, the message ID, the message serial number, the message length and the message body which are acquired from the data, the check code acquired from the data is compared with the target check code, the integrity of the data can be verified, and the accuracy of the data obtained by analysis is ensured.
The present application may be further configured in a preferred example to: the method further comprises the steps of:
and respectively defining the positions and lengths of the initiator, the protocol version, the message ID, the message serial number, the message length, the message body, the check code and the terminator in the data to be transmitted, and the contents of the initiator, the protocol version and the terminator to obtain a preset communication protocol.
By adopting the technical scheme, the receiving equipment can successfully identify and analyze the information to be expressed by the sending equipment based on the preset communication protocol, and the remote access of the sending equipment data and the control equipment action through the receiving equipment are realized.
In a second aspect, the present application provides a data transmission device, which adopts the following technical scheme:
a data transmission apparatus comprising:
the receiving module is used for receiving data and determining whether the initiator, the protocol version and the message ID in the data are in compliance or not;
the acquisition module is used for acquiring the message length of the data if the initiator, the protocol version and the message ID are all in compliance, and determining the residual data length in the data according to a preset communication protocol, wherein the residual data length is used for representing the length corresponding to the message body in the data;
the judging module is used for comparing the message length with the residual data length, and if the message length is not greater than the residual data length, the message body is obtained from the data;
the verification module is used for acquiring a check code from the data and verifying the integrity of the data according to the check code;
and the sending module is used for sending a response signal corresponding to the message body to the sending equipment if the data is complete.
In a third aspect, the present application provides a receiving apparatus, which adopts the following technical scheme:
one or more processors;
a memory;
At least one application program, wherein the at least one application program is stored in the memory and configured to be executed by the at least one processor, the at least one application program configured to: a data transmission method according to any one of the first aspects is performed.
In a fourth aspect, the present application provides a computer readable storage medium, which adopts the following technical scheme:
a computer readable storage medium having stored thereon a computer program which, when executed in a computer, causes the computer to perform the data transmission method according to any of the first aspects.
In summary, the present application includes the following beneficial technical effects:
according to the method and the device, the message length of the data is obtained under the condition that the initiator, the protocol version and the message ID are all compliant, the residual data length in the data can be determined according to the preset communication protocol, the message length and the residual data length are compared, the correct message body can be obtained from the data, the data integrity is verified through the check code in the data, so that complete data is obtained, the received data can be found out in time when the data does not accord with the preset communication protocol through analysis and repeated verification, accurate and effective content is analyzed from the received data, and the accuracy of data transmission and acquisition is improved.
Drawings
Fig. 1 is a schematic flow chart of a data transmission method according to an embodiment of the present application;
fig. 2 is a schematic format diagram of a preset communication protocol according to an embodiment of the present application;
fig. 3 is a data parsing flow chart of a data transmission method according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a data transmission device according to an embodiment of the present application;
fig. 5 is a schematic structural diagram of a receiving device according to an embodiment of the present application.
Detailed Description
The present application is described in further detail below in conjunction with fig. 1-5.
The present embodiment is merely illustrative of the present application and is not intended to be limiting, and those skilled in the art, after having read the present specification, may make modifications to the present embodiment without creative contribution as required, but is protected by patent laws within the scope of the claims of the present application.
For the purposes of making the objects, technical solutions and advantages of the embodiments of the present application more clear, the technical solutions of 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 apparent that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, are intended to be within the scope of the present application.
In addition, the term "and/or" herein is merely an association relationship describing an association object, and means that three relationships may exist, for example, a and/or B may mean: a exists alone, A and B exist together, and B exists alone. In this context, unless otherwise specified, the term "/" generally indicates that the associated object is an "or" relationship.
The embodiment of the application provides a data transmission method, as shown in fig. 1, where the method provided in the embodiment of the application is executed by a receiving device, where the receiving device may be a server or a terminal device, where the server may be an independent physical server, or may be a server cluster or a distributed system formed by a plurality of physical servers, or may be a cloud server that provides cloud computing service. The terminal device may be, but is not limited to, a smart phone, a tablet computer, a notebook computer, a desktop computer, etc., and the terminal device and the server may be directly or indirectly connected through wired or wireless communication, which is not limited herein, and the method includes steps S101-S105, where:
S101, receiving data, and determining whether the initiator, the protocol version and the message ID in the data are compliant.
In this embodiment, the sending device encapsulates data to be transmitted according to a preset communication protocol and sends the encapsulated data to the receiving device, where the encapsulation is to encapsulate the data according to a format specified by the preset communication protocol, so that the data can be correctly transmitted, the receiving device receives the data and decapsulates the data to obtain an initiator, a protocol version and a message ID contained in the data, and according to the preset communication protocol, whether the initiator, the protocol version and the message ID in the data are compliant or not can be determined.
The location and length of the initiator, protocol version and message ID, and the contents of the initiator and protocol version are defined in the preset communication protocol. Alternatively, the initiator may be set to 1 byte, the protocol version may be set to 2 bytes, the message ID may be set to 2 bytes, the initiator may be set to the header of the data during the data encapsulation, the initiator is followed by the protocol version indicating the version of the preset communication protocol used by the transmitted data, the protocol version is followed by the message ID indicating the data type of the transmitted message body. Further, when the receiving device decapsulates the data, the receiving device may use the content corresponding to the 1 st byte of the data as an initiator, the content of the 2 nd and 3 rd bytes of the data as a protocol version, and the content of the 4 th and 5 th bytes as a message ID, so as to obtain the initiator, the protocol version and the message ID in the data, and determine whether the initiator, the protocol version and the message ID are compliant.
S102, if the initiator, the protocol version and the message ID are all in compliance, the message length of the data is obtained, and the residual data length in the data is determined according to a preset communication protocol and is used for representing the length corresponding to the message body in the data.
Specifically, the position and the length of the message length in the data are defined in the preset communication protocol, alternatively, the message length can be set after the message ID, and occupies 2 bytes, the data received by the receiving device is in a binary format, and the binary value of the 2 bytes corresponding to the message length represents the length of the message body in the data. The data packaged based on the preset communication protocol further comprises a check code and an ending symbol, the lengths of the check code and the ending symbol are defined in the preset communication protocol, and the length of the rest data in the data received by the receiving equipment can be determined according to the lengths corresponding to the starting symbol, the protocol version, the message ID, the message length and the check code and the ending symbol. The remaining data length is used to represent the length corresponding to the message body in the data, and the message body is the effective content of the data transmission.
S103, comparing the message length with the residual data length, and if the message length is not greater than the residual data length, acquiring a message body from the data.
If the message length is not greater than the remaining data length, then the message body can be successfully acquired from the data. If the message length is greater than the remaining data length, the remaining data length is insufficient to acquire the message body corresponding to the message length, and the receiving device may send a message acquisition failure signal to the sending device, so as to prompt the sending device to resend the piece of data.
S104, acquiring a check code from the data, and verifying the integrity of the data according to the check code.
The receiving equipment acquires the check code from the received data, recalculates the check code according to the received data, compares the acquired check code with the calculated check code, if the acquired check code and the calculated check code are equal, the data transmission is correct, the received data is complete, if the acquired check code and the calculated check code are not matched, the received data is incomplete, and the receiving equipment can send a check failure signal to the sending equipment so as to prompt the sending equipment to resend the data.
And S105, if the data is complete, transmitting a response signal corresponding to the message body to the transmitting equipment.
The message body is the effective content of data transmission, when the transmitted data is complete, the receiving device can generate a response signal and send the response signal to the sending device, the response signal can contain a message serial number, the sending device stores the corresponding relation between the message serial number and the data, and the sending device can determine the successfully sent data according to the response message.
According to the embodiment of the application, the message length of the data is obtained under the condition that the initiator, the protocol version and the message ID are all compliant, the residual data length in the data can be determined according to the preset communication protocol, the message length and the residual data length are compared, the correct message body can be obtained from the data, the data integrity is verified through the check code in the data, so that complete data is obtained, the received data can be timely found when the data does not accord with the preset communication protocol through analysis and repeated verification, accurate and effective content is analyzed from the received data, and the accuracy of data transmission and acquisition is improved.
One possible implementation manner of the embodiment of the present application, the method further includes:
and respectively defining the position and the length of the initiator, the protocol version, the message ID, the message serial number, the message length, the message body, the check code and the terminator in the data to be transmitted, and the contents of the initiator, the protocol version and the terminator to obtain a preset communication protocol.
Fig. 2 shows a schematic format diagram of a preset communication protocol provided in this embodiment of the present application, where the positions and lengths of a start symbol, a protocol version, a message ID, a message serial number, a message length, a message body, a check code, and an end symbol in data are as shown in fig. 2, the start symbol occupies 1 byte, is set in the header of the message, the protocol version occupies 2 bytes, the message ID occupies 2 bytes after the start symbol is set, the message serial number is set in the protocol version, so as to facilitate data tracking, avoid data confusion, the message serial number occupies 2 bytes, the message length occupies 2 bytes after the message ID is set, the number of bytes corresponding to the message body matches with the number corresponding to the message length after the message serial number, the check code occupies 1 byte, the end symbol occupies 1 byte after the message body is set, and indicates that data transmission ends after the check code is set.
Further, the preset communication protocol also defines the contents of the initiator, the protocol version and the terminator, when different data are transmitted based on the preset communication protocol of the same protocol version, the contents of the initiator, the protocol version and the terminator which are analyzed from the received data by the receiving device are matched with the contents defined in the preset communication protocol, and if the contents are not matched, the data transmission errors are indicated.
According to the embodiment of the application, the data transmission is performed based on the preset communication protocol, the receiving equipment can successfully identify and analyze the information to be expressed by the sending equipment, and the data of the sending equipment and the actions of the control equipment are remotely accessed through receiving.
One possible implementation manner of the embodiment of the present application, determining whether the initiator, the protocol version and the message ID in the data are compliant includes:
acquiring an initiator from data according to the position and the length of the initiator defined in a preset communication protocol, and determining whether the initiator in the data is compliant according to the content of the initiator defined in the preset communication protocol;
if the start in the data accords with the rule, acquiring a protocol version from the data according to the position and the length of the protocol version defined in the preset communication protocol, and determining whether the protocol version in the data is compliant according to the content of the protocol version defined in the preset communication protocol;
If the protocol version in the data is compliant, the message ID is obtained from the data according to the position and the length of the message ID defined in the preset communication protocol, and whether the message ID in the data is compliant is determined.
In this embodiment, according to the position and length of the initiator defined by the preset communication protocol, the 1 st byte content of the data header can be obtained from the received data, so as to obtain the initiator in the data. Comparing the initiator obtained from the received data with the initiator defined by the preset communication protocol, and if the initiator obtained from the received data is the same as the initiator defined by the preset communication protocol, indicating that the initiator in the data accords with the rule; if the initiator obtained from the received data is different from the initiator defined by the preset communication protocol, the initiator in the data is not compliant, the receiving device can discard the data and send an initiator error signal to the sending device to prompt the sending device to resend the data.
According to the position and the length of the protocol version defined by the preset communication protocol, the content of the 2 nd byte and the 3 rd byte can be obtained from the received data, so that the protocol version in the data can be obtained. Comparing the protocol version obtained from the received data with the protocol version defined by the preset communication protocol, and if the protocol version obtained from the received data is the same as the protocol version defined by the preset communication protocol, indicating that the protocol version in the data is compliant; if the protocol version obtained from the received data is different from the protocol version defined by the preset communication protocol, the protocol version in the data is not compliant, the receiving device can discard the data and send a protocol version error signal to the sending device so as to prompt the sending device to resend the data.
According to the position and length of the message ID defined by the preset communication protocol, the content of the 4 th byte and the 5 th byte can be obtained from the received data, so that the message ID in the data is obtained, and the message ID is used for representing the data type of the message body in the data.
According to the embodiment of the application, according to the positions and the lengths of the initiator, the protocol version and the message ID defined by the preset communication protocol, the initiator, the protocol version and the message ID can be sequentially acquired and validated in compliance, and when a certain item is not in compliance, error data are timely discarded, so that useless operation is avoided, and the data analysis efficiency is improved.
One possible implementation manner of the embodiment of the present application, determining whether a message ID in data is compliant includes:
comparing the message ID in the data with a preset data type, and determining whether the data type which accords with the message ID in the data exists in the preset data type;
if the preset data type has the data type which accords with the message ID in the data, judging that the message ID in the data is compliant;
if the data type which is consistent with the message ID in the data does not exist in the preset data type, judging that the message ID in the data is not compliant.
In this embodiment, the preset data types include a device action execution result and a sensor data type, where the device action execution result may include a device response result and a device query result, and the sensor data may include a temperature, a humidity, and a PH value collected by a sensor.
According to the embodiment of the application, the message ID in the data is compared with the preset data type, so that whether the message ID in the data is compliant or not can be judged, the message ID represents the data type of the message body, and the accuracy of acquiring the message body can be improved.
In one possible implementation manner of the embodiment of the present application, if the initiator, the protocol version and the message ID are all compliant, acquiring the message length of the data includes:
if the initiator, the protocol version and the message ID are all compliant, the message serial number is obtained from the data according to the length and the position of the message serial number defined in the preset communication protocol;
and acquiring the message length from the data according to the position and the length of the message length defined in the preset communication protocol.
In this embodiment, according to the position and length of the message serial number defined by the preset communication protocol, the contents of the 6 th byte and the 7 th byte can be obtained from the received data, so as to obtain the message serial number in the data. Then according to the position and length of the message length defined by the preset communication protocol, the content of the 8 th byte and the 9 th byte can be obtained from the received data, so that the message length in the data is obtained.
According to the length and the position of the message serial number defined in the preset communication protocol, the accurate message serial number can be obtained from the data, the message serial number can mark the data, data tracking and searching are facilitated, and the data management level is improved.
One possible implementation manner of the embodiment of the present application, determining, according to a preset communication protocol, a remaining data length in data includes:
determining the length sum of a start symbol, a protocol version, a message ID, a message serial number, a message length, a check code and an end symbol which are defined in a preset communication protocol;
determining the length of the data;
and determining the length of the data and the difference value of the length sum to obtain the length of the residual data.
For example, when the length of the initiator is defined as 1 byte, the length of the protocol version is 2 bytes, the length of the message ID is 2 bytes, the length of the message serial number is 2 bytes, the length corresponding to the message length is 2 bytes, the length of the check code is 1 byte, the length of the terminator is 1 byte, and the calculated sum is 11 bytes in the preset communication protocol.
According to the method and the device for obtaining the message body, according to the lengths corresponding to the initiator, the protocol version, the message ID, the message serial number, the message length, the check code and the ending symbol and the length of the received data, which are defined in the preset communication protocol, the length of the remaining data in the data can be determined, and the accuracy of obtaining the message body based on the message length is improved.
One possible implementation manner of the embodiment of the present application obtains a check code from data, verifies the integrity of the data according to the check code, and includes:
acquiring a check code from data according to the position and the length of the check code defined in a preset communication protocol;
generating a target check code according to the protocol version, the message ID, the message serial number, the message length and the message body which are acquired from the data;
comparing the check code with the target check code, and judging whether the check code and the target check code are successfully compared;
if the check code and the target check code can be successfully compared, the data integrity is judged.
In this embodiment, the check code may be generated by a CRC check method, specifically, the transmitting device generates the check code according to the protocol version, the message ID, the message serial number, the message length and the message body of the data to be transmitted, sets the check code after the message body, and sets the ending symbol after the check code, thereby completing data encapsulation.
Specifically, the process of generating the check code according to the protocol version, the message ID, the message serial number, the message length and the message body is as follows: arranging protocol version, message ID, message serial number, message length and message body into a byte array according to the sequence defined by a preset communication protocol; initializing a CRC register to a state of all 0 s; starting from the first byte of the byte array, performing exclusive OR operation on each byte and the CRC register, shifting an operation result to the next position of the CRC register, performing exclusive OR operation on the next byte and the CRC register after shifting, repeating the process until all bytes in the byte array are processed, obtaining a new byte sequence, wherein the length of the new byte sequence is the same as that of the byte array, dividing the new byte sequence by a generating polynomial, and setting the obtained remainder as a check code after the message body. The length of the generating polynomial determines the length of the check code, the generating polynomial can adopt 8 bits, and the obtained check code occupies one byte.
According to the embodiment of the application, the target check code can be generated according to the protocol version, the message ID, the message serial number, the message length and the message body which are acquired from the data, the check code acquired from the data is compared with the target check code, the integrity of the data can be verified, and the accuracy of the data obtained through analysis is guaranteed.
Fig. 3 shows a data parsing flow chart of a data transmission method provided by the embodiment of the present application, where a receiving device receives data, i.e., communication protocol data, generated according to a preset communication protocol and sent by a sending device, acquires a initiator in the data, determines whether the initiator is compliant, if the initiator is not compliant, indicates that the initiator is wrong, discards the data, if the initiator is compliant, acquires a protocol version in the data, determines whether the protocol version is compliant, if the protocol version is not compliant, indicates that the protocol version is wrong, discards the data, if the protocol version is compliant, acquires a message ID in the data, determines whether the message ID is compliant, if the message ID is not compliant, indicates that the message ID is wrong, discards the data, if the message ID is compliant, records a message stream number and a message length, determines whether a message body can be acquired according to the message length, if the message body fails, sends a message body acquisition failure signal, if the message body acquisition is successful, acquires a protocol message body, then acquires a verification code in the data, verifies the integrity of the data, if the verification fails, and if the verification device verifies that the message body (receiving device) can successfully verify that the message body (receiving device) sends a message body) and the message, and the device verifies that the message body (receiving device) has been successfully.
The above embodiments describe a data transmission method from the viewpoint of a method flow, and the following embodiments describe a data transmission device from the viewpoint of a virtual module or a virtual unit, which are described in detail in the following embodiments.
An embodiment of the present application provides a data transmission device, as shown in fig. 4, the device may include:
a receiving module 401, configured to receive data, and determine whether an initiator, a protocol version, and a message ID in the data are compliant;
the acquiring module 402 is configured to acquire a message length of the data if the initiator, the protocol version and the message ID are all compliant, and determine a remaining data length in the data according to a preset communication protocol, where the remaining data length is used to represent a length corresponding to a message body in the data;
a determining module 403, configured to compare the message length with the remaining data length, and if the message length is not greater than the remaining data length, obtain a message body from the data;
the verification module 404 is configured to obtain a check code from the data, and verify the integrity of the data according to the check code;
and the sending module 405 is configured to send a response signal corresponding to the message body to the sending device if the data is complete.
The present application may be further configured in a preferred example to: the obtaining module 402 is specifically configured to, when executing the message length of the data if the initiator, the protocol version and the message ID are all compliant:
If the initiator, the protocol version and the message ID are all compliant, the message serial number is obtained from the data according to the length and the position of the message serial number defined in the preset communication protocol;
and acquiring the message length from the data according to the position and the length of the message length defined in the preset communication protocol.
The present application may be further configured in a preferred example to: the obtaining module 402 is specifically configured to, when executing determining the remaining data length in the data according to the preset communication protocol:
determining the length sum of a start symbol, a protocol version, a message ID, a message serial number, a message length, a check code and an end symbol which are defined in a preset communication protocol;
determining the length of the data;
and determining the length of the data and the difference value of the length sum to obtain the length of the residual data.
The present application may be further configured in a preferred example to: the receiving module 401, when executing determining whether the initiator, the protocol version and the message ID in the data are compliant, is specifically configured to:
acquiring an initiator from data according to the position and the length of the initiator defined in a preset communication protocol, and determining whether the initiator in the data is compliant according to the content of the initiator defined in the preset communication protocol;
If the start in the data accords with the rule, acquiring a protocol version from the data according to the position and the length of the protocol version defined in the preset communication protocol, and determining whether the protocol version in the data is compliant according to the content of the protocol version defined in the preset communication protocol;
if the protocol version in the data is compliant, the message ID is obtained from the data according to the position and the length of the message ID defined in the preset communication protocol, and whether the message ID in the data is compliant is determined.
The present application may be further configured in a preferred example to: the receiving module 401, when executing determining whether the message ID in the data is compliant, is specifically configured to:
comparing the message ID in the data with a preset data type, and determining whether the data type which accords with the message ID in the data exists in the preset data type;
if the preset data type has the data type which accords with the message ID in the data, judging that the message ID in the data is compliant;
if the data type which is consistent with the message ID in the data does not exist in the preset data type, judging that the message ID in the data is not compliant.
The present application may be further configured in a preferred example to: the verification module 404 is specifically configured to, when executing to obtain a check code from the data and verify the integrity of the data according to the check code:
Acquiring a check code from data according to the position and the length of the check code defined in a preset communication protocol;
generating a target check code according to the protocol version, the message ID, the message serial number, the message length and the message body which are acquired from the data;
comparing the check code with the target check code, and judging whether the check code and the target check code are successfully compared;
if the check code and the target check code can be successfully compared, the data integrity is judged.
The present application may be further configured in a preferred example to: the device further comprises a definition module, in particular for:
and respectively defining the position and the length of the initiator, the protocol version, the message ID, the message serial number, the message length, the message body, the check code and the terminator in the data to be transmitted, and the contents of the initiator, the protocol version and the terminator to obtain a preset communication protocol.
The data transmission device provided in the embodiment of the present application is applicable to the above method embodiment, and is not described herein again.
In an embodiment of the present application, as shown in fig. 5, a receiving apparatus 500 shown in fig. 5 includes: a processor 501 and a memory 503. The processor 501 is coupled to a memory 503, such as via a bus 502. Optionally, the receiving device 500 may also include a transceiver 504. It should be noted that, in practical applications, the transceiver 504 is not limited to one, and the structure of the receiving apparatus 500 is not limited to the embodiment of the present application.
The processor 501 may be a CPU (Central Processing Unit ), general purpose processor, DSP (Digital Signal Processor, data signal processor), ASIC (Application Specific Integrated Circuit ), FPGA (Field Programmable Gate Array, field programmable gate array) or other programmable logic device, transistor logic device, hardware components, or any combination thereof. Which may implement or perform the various exemplary logic blocks, modules, and circuits described in connection with this disclosure. The processor 501 may also be a combination that implements computing functionality, such as a combination comprising one or more microprocessors, a combination of a DSP and a microprocessor, and the like.
Bus 502 may include a path to transfer information between the components. Bus 502 may be a PCI (Peripheral Component Interconnect, peripheral component interconnect Standard) bus or an EISA (Extended Industry Standard Architecture ) bus, or the like. The bus 502 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in fig. 5, but not only one bus or type of bus.
The Memory 503 may be, but is not limited to, ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, RAM (Random Access Memory ) or other type of dynamic storage device that can store information and instructions, EEPROM (Electrically Erasable Programmable Read Only Memory ), CD-ROM (Compact Disc Read Only Memory, compact disc Read Only Memory) or other optical disk storage, optical disk storage (including compact discs, laser discs, optical discs, digital versatile discs, blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer.
The memory 503 is used to store application code for executing the present application and is controlled by the processor 501 for execution. The processor 501 is configured to execute the application code stored in the memory 503 to implement what has been described above for the data transmission method embodiment.
The receiving device shown in fig. 5 is only an example, and should not impose any limitation on the functions and the scope of use of the embodiments of the present application.
The present application provides a computer readable storage medium having a computer program stored thereon, which when run on a computer, causes the computer to perform the corresponding method embodiments described above.
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited in order and may be performed in other orders, unless explicitly stated herein. Moreover, at least some of the steps in the flowcharts of the figures may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, the order of their execution not necessarily being sequential, but may be performed in turn or alternately with other steps or at least a portion of the other steps or stages.
The foregoing is only a partial embodiment of the present application and it should be noted that, for a person skilled in the art, several improvements and modifications can be made without departing from the principle of the present application, and these improvements and modifications should also be considered as the protection scope of the present application.

Claims (10)

1. A data transmission method, performed by a receiving device, comprising:
receiving data, and determining whether a initiator, a protocol version and a message ID in the data are compliant;
if the initiator, the protocol version and the message ID are all in compliance, acquiring the message length of the data, and determining the residual data length in the data according to a preset communication protocol, wherein the residual data length is used for representing the length corresponding to the message body in the data;
comparing the message length with the residual data length, and if the message length is not greater than the residual data length, acquiring a message body from the data;
acquiring a check code from the data, and verifying the integrity of the data according to the check code;
and if the data is complete, transmitting a response signal corresponding to the message body to transmitting equipment.
2. The method according to claim 1, wherein if the initiator, protocol version and message ID are all compliant, obtaining the message length of the data comprises:
if the initiator, the protocol version and the message ID are all compliant, acquiring a message serial number from the data according to the length and the position of the message serial number defined in the preset communication protocol;
And acquiring the message length from the data according to the position and the length of the message length defined in the preset communication protocol.
3. The data transmission method according to claim 1, wherein determining the remaining data length in the data according to a preset communication protocol comprises:
determining the length sum of a start symbol, a protocol version, a message ID, a message serial number, a message length, a check code and an end symbol defined in the preset communication protocol;
determining the length of the data;
and determining the difference value between the length of the data and the sum of the lengths to obtain the length of the residual data.
4. The data transmission method according to claim 1, wherein determining whether the initiator, protocol version, and message ID in the data are compliant comprises:
acquiring an initiator from the data according to the position and the length of the initiator defined in the preset communication protocol, and determining whether the initiator in the data is compliant according to the content of the initiator defined in the preset communication protocol;
if the start in the data accords with the rule, acquiring a protocol version from the data according to the position and the length of the protocol version defined in the preset communication protocol, and determining whether the protocol version in the data is compliant according to the content of the protocol version defined in the preset communication protocol;
And if the protocol version in the data is compliant, acquiring the message ID from the data according to the position and the length of the message ID defined in the preset communication protocol, and determining whether the message ID in the data is compliant.
5. The data transmission method according to claim 4, wherein determining whether the message ID in the data is compliant comprises:
comparing the message ID in the data with a preset data type, and determining whether the data type which accords with the message ID in the data exists in the preset data type;
if the preset data type contains a data type which is met by the message ID in the data, judging that the message ID in the data is compliant;
and if the data type which is consistent with the message ID in the data does not exist in the preset data type, judging that the message ID in the data is not compliant.
6. The data transmission method according to claim 1, wherein obtaining a check code from the data, verifying the integrity of the data based on the check code, comprises:
acquiring a check code from the data according to the position and the length of the check code defined in the preset communication protocol;
Generating a target check code according to the protocol version, the message ID, the message serial number, the message length and the message body which are acquired from the data;
comparing the check code with the target check code, and judging whether the check code is successfully compared with the target check code or not;
and if the check code and the target check code can be successfully compared, judging that the data is complete.
7. The data transmission method according to claim 1, characterized in that the method further comprises:
and respectively defining the positions and lengths of the initiator, the protocol version, the message ID, the message serial number, the message length, the message body, the check code and the terminator in the data to be transmitted, and the contents of the initiator, the protocol version and the terminator to obtain a preset communication protocol.
8. A data transmission apparatus, comprising:
the receiving module is used for receiving data and determining whether the initiator, the protocol version and the message ID in the data are in compliance or not;
the acquisition module is used for acquiring the message length of the data if the initiator, the protocol version and the message ID are all in compliance, and determining the residual data length in the data according to a preset communication protocol, wherein the residual data length is used for representing the length corresponding to the message body in the data;
The judging module is used for comparing the message length with the residual data length, and if the message length is not greater than the residual data length, the message body is obtained from the data;
the verification module is used for acquiring a check code from the data and verifying the integrity of the data according to the check code;
and the sending module is used for sending a response signal corresponding to the message body to the sending equipment if the data is complete.
9. A receiving apparatus, comprising:
at least one processor;
a memory;
at least one application program, wherein the at least one application program is stored in the memory and configured to be executed by the at least one processor, the at least one application program configured to: a data transmission method as claimed in any one of claims 1 to 7.
10. A computer-readable storage medium, on which a computer program is stored, characterized in that the computer program, when executed in a computer, causes the computer to perform the data transmission method according to any one of claims 1-7.
CN202311707359.8A 2023-12-12 2023-12-12 Data transmission method, device, equipment and medium Pending CN117714553A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311707359.8A CN117714553A (en) 2023-12-12 2023-12-12 Data transmission method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311707359.8A CN117714553A (en) 2023-12-12 2023-12-12 Data transmission method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN117714553A true CN117714553A (en) 2024-03-15

Family

ID=90154695

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311707359.8A Pending CN117714553A (en) 2023-12-12 2023-12-12 Data transmission method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN117714553A (en)

Similar Documents

Publication Publication Date Title
CN108279910B (en) Program code programming method and device, computer equipment and storage medium
CN109964215B (en) Flow control in remote direct memory access data communications with ring buffer mirroring
CN114500690B (en) Interface data processing method and device, electronic equipment and storage medium
WO2022116088A1 (en) Firmware data processing method and apparatus
CN112380046B (en) Calculation result verification method, system, device, equipment and storage medium
CN111177060B (en) Serial port data sending method, serial port data receiving method, corresponding devices and terminal equipment
US8972838B2 (en) Data transmission detecting device, data transmission detecting method and electronic device thereof
CN113179216B (en) Remote configuration method of register, computer equipment and storage medium
CN114710224A (en) Frame synchronization method and device, computer readable medium and electronic device
WO2021134418A1 (en) Data checking method and apparatus
EP3065323B1 (en) Transmission method and device based on management data input/output multi-source agreements
CN117714553A (en) Data transmission method, device, equipment and medium
CN110618859B (en) Transaction pool design method supporting sequential packaging and electronic equipment
CN112422485B (en) Communication method and device of transmission control protocol
US7516393B2 (en) System and method of error detection for unordered data delivery
CN114390118B (en) Industrial control asset identification method and device, electronic equipment and storage medium
CN111369359B (en) Method and device for testing security transaction risk control hardware
CN115729879A (en) Data frame format, chip communication method and chip
CN113010114A (en) Data processing method and device, computer equipment and storage medium
CN117785782A (en) Data detection method, device, equipment and medium based on NVMe 2.0 protocol
CN114422970B (en) Short message tracing method, device and equipment
CN116028533A (en) Streaming data sending method and device and streaming data integrity checking method
CN116055350B (en) Json-based data communication quality detection method
CN112035890B (en) Data integrity verification method and device
CN117608915A (en) Data verification method, device, apparatus, storage medium and program product

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