CN112437064A - Data transmission method, data reading method, device, equipment and storage medium - Google Patents

Data transmission method, data reading method, device, equipment and storage medium Download PDF

Info

Publication number
CN112437064A
CN112437064A CN202011258022.XA CN202011258022A CN112437064A CN 112437064 A CN112437064 A CN 112437064A CN 202011258022 A CN202011258022 A CN 202011258022A CN 112437064 A CN112437064 A CN 112437064A
Authority
CN
China
Prior art keywords
data
bit mask
bit
frame
sensor
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.)
Granted
Application number
CN202011258022.XA
Other languages
Chinese (zh)
Other versions
CN112437064B (en
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.)
Shenzhen Silver Star Intelligent Technology Co Ltd
Original Assignee
Shenzhen Silver Star Intelligent Technology 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 Shenzhen Silver Star Intelligent Technology Co Ltd filed Critical Shenzhen Silver Star Intelligent Technology Co Ltd
Priority to CN202011258022.XA priority Critical patent/CN112437064B/en
Publication of CN112437064A publication Critical patent/CN112437064A/en
Application granted granted Critical
Publication of CN112437064B publication Critical patent/CN112437064B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • 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/06Notations for structuring of protocol data, e.g. abstract syntax notation one [ASN.1]
    • 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/46Interconnection of networks
    • H04L12/4633Interconnection of networks using encapsulation techniques, e.g. tunneling
    • 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/03Protocol definition or specification 

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Health & Medical Sciences (AREA)
  • Computing Systems (AREA)
  • General Health & Medical Sciences (AREA)
  • Medical Informatics (AREA)
  • Communication Control (AREA)

Abstract

The invention relates to the technical field of communication, and discloses a data transmission method, a data reading method, a device, equipment and a storage medium, wherein a bit mask is constructed according to effective data of acquired sensor data of a sensor, the sensor data to be transmitted is packaged into a frame structure based on the bit mask to form a data packet, and the bit mask is used for indicating the effectiveness of the sensor data, namely the effectiveness of the sensor data is identified by adding the bit mask in a protocol frame, so that the free expansion control of a data segment in the protocol frame is realized, and the expandability of the protocol is greatly improved; meanwhile, the protocol frame is used for transmitting data, a communication protocol does not need to be changed, the occupation of invalid data on bandwidth resources can be reduced due to the arrangement of the flag bit in the data identification field, the resources of the communication bandwidth are greatly saved, the utilization rate of the resources is improved, and the expansion capability of the protocol frame is improved.

Description

Data transmission method, data reading method, device, equipment and storage medium
Technical Field
The present invention relates to the field of communications technologies, and in particular, to a data transmission method, a data reading method, an apparatus, a device, and a storage medium.
Background
With the development of communication technology, especially, the control of data transmission of small devices by adopting a control chip and an acquisition chip has become a basic implementation of communication. For example, in a cleaning robot, the acquisition chip is used for acquiring data acquired by each sensor, and the control chip is used for interacting with the acquisition chip and further processing the data of each sensor. When the control chip and the acquisition chip are interacted, when the acquisition chip uploads data to the control chip every time, part of the sensors may not have data, and therefore the data of all the sensors are not necessarily uploaded.
In the prior art, in the protocol of chip interaction on the same model, the protocol frame length is fixed. If only part of the sensors have data and other sensors have no data, invalid data with fixed length can be added to the data frames of the sensors without data in the interactive data packets, so that the fixed frame length is maintained. When the control chip receives the data packet, the invalid data also needs to be analyzed, which wastes bandwidth and the computing power of the chip.
If the protocol is extended to other types, when the number and the type of the sensors are changed, the length of the protocol needs to be changed, and the length of effective data is adjusted on the original protocol frame. Therefore, the frame structure in the existing communication protocol has poor expansion capability.
Disclosure of Invention
The invention mainly aims to solve the technical problem of low utilization rate of bandwidth resources when data is transmitted due to poor expansibility of a protocol frame structure set in the existing interactive protocol.
The invention provides a data transmission method based on a protocol frame, which is applied to a self-moving robot, and comprises the following steps:
the method comprises the steps of collecting sensor data generated by each sensor, and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
identifying validity of sensor data in the data transmission sequence and generating bit mask content based on the validity;
and extracting corresponding sensor data from the data transmission sequence according to the bit mask content, packaging the extracted sensor data and the bit mask content into a data frame structure together to form a data packet, and transmitting the data packet to a receiving device.
Optionally, in a first implementation manner of the first aspect of the present invention, the identifying validity of the sensor data in the data transmission sequence, and generating a bit mask content based on the validity includes:
calculating the data volume of each data block in the data transmission sequence, and judging whether the data volume meets the transmission condition;
marking the corresponding data block according to the judgment result to obtain a marking sequence, wherein the marking comprises an effective marking and an ineffective marking;
and constructing bit mask content according to the mark sequence.
Optionally, in a second implementation manner of the first aspect of the present invention, the constructing of the bit mask content according to the tag sequence includes:
extracting effective marks and ineffective marks in the mark sequence, converting the effective marks into non-empty zone bits, and converting the ineffective marks into empty zone bits to obtain a binary sequence;
calculating a total length of the bit mask based on the binary sequence;
and constructing the bit mask content according to the total length and the value of each flag bit in the binary sequence.
Optionally, in a third implementation manner of the first aspect of the present invention, the constructing the bit mask content according to the total length and the value of each flag in the binary sequence includes:
judging whether the total length is larger than the length of one byte or not;
if the total length is greater than the length of one byte, calculating the total byte number N of the binary sequence, wherein N is greater than or equal to 2;
according to the total byte number N, creating a bit mask field with the total byte number equal to N;
setting the highest flag bit of the first N-1 bytes in the bit mask field to be non-null, and setting the values of other flag bits except the highest flag bit in the bit mask field based on the value of the flag bit in the binary sequence to obtain the bit mask content;
and if the total length is not greater than the length of one byte, setting a first flag bit in the bit mask field to be null, and setting the values of other flag bits except the highest flag bit in the first byte based on the value of the flag bit in the binary sequence to obtain the bit mask content.
Optionally, in a fourth implementation manner of the first aspect of the present invention, the data frame structure includes a frame header, a frame body, and a frame trailer, where the extracting, according to the bit mask content, corresponding sensor data from the data transmission sequence, and encapsulating the extracted sensor data and the bit mask content into a data frame structure together to form a data packet includes:
extracting sensor data at locations in the bitmask content where non-empty flag bits correspond to the data transmission sequence;
inquiring the field content of the command word set by the bit mask content, and setting the command word in the frame header as the field content;
and sequentially packaging the bit mask content and the extracted sensor data into a data section of a frame body in the data frame structure, and forming a data packet with the frame head and the frame tail.
Optionally, in a fifth implementation manner of the first aspect of the present invention, the sequentially encapsulating the bit mask content and the extracted sensor data into a data segment of a frame body in the data frame structure, and forming a data packet with the frame header and the frame trailer includes:
expanding a bit mask field in the data section of the frame body according to the field content of the command word;
assigning values to the bit mask fields based on the bit mask content to obtain bit masks;
and determining the encapsulation position of the sensor data according to the non-empty flag bit in the bit mask, encapsulating the sensor data of the corresponding sensor to the encapsulation position, and forming a data packet with the frame head and the frame tail.
The second aspect of the present invention provides a data reading method based on a protocol frame, which is applied to a self-moving robot, and the data reading method based on the protocol frame includes:
receiving a data packet sent by sensor data acquisition equipment, wherein the data packet is obtained by encapsulating sensor data to be transmitted by the protocol frame-based data transmission method;
and extracting a bit mask in the data packet, and reading the sensor data packaged in the data packet data section based on the bit mask.
Optionally, in a first implementation manner of the second aspect of the present invention, the extracting a bit mask in the data packet, and reading the sensor data encapsulated in the data packet segment based on the bit mask includes:
identifying a frame body in the data packet and extracting a bit mask in the frame body;
identifying the highest flag bit of the first byte in the bit mask, and judging whether the highest flag bit is empty or not;
if so, determining the length of the bit mask to be the length of a single byte, sequentially reading the values of the zone bits except the highest zone bit in the bit mask, extracting the position of the zone bit with a non-empty value, and reading the sensor data corresponding to the position according to the corresponding relation between the position and the storage position of the sensor data in the data section of the frame body;
and if not, identifying the highest marker bit of the next byte in the bit mask, sequentially reading the values of the marker bits except the highest marker bit of each byte in the bit mask until the highest marker bit is identified to be null, extracting the positions of the marker bits with non-null values, and reading the sensor data corresponding to the positions according to the corresponding relation between the positions and the storage positions of the sensor data in the data section of the frame body.
A third aspect of the present invention provides a data transmission apparatus based on a protocol frame, including:
the acquisition module is used for acquiring sensor data generated by each sensor and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
a bit mask generation module for identifying the validity of the sensor data in the data transmission sequence and generating bit mask content based on the validity;
the packaging module is used for extracting corresponding sensor data from the data transmission sequence according to the bit mask content, and packaging the extracted sensor data and the bit mask content into a data frame structure to form a data packet;
and the transmission module is used for transmitting the data packet to the receiving equipment.
Optionally, in a first implementation manner of the third aspect of the present invention, the bit mask generating module includes:
a calculating unit, configured to calculate a data amount of each data block in the data transmission sequence;
a first judgment unit configured to judge whether the data amount satisfies a transmission condition;
the marking unit is used for marking the corresponding data block according to the judgment result to obtain a marking sequence, wherein the marking comprises an effective marking and an ineffective marking;
and the constructing unit is used for constructing the bit mask content according to the marking sequence.
Optionally, in a second implementation manner of the third aspect of the present invention, the constructing unit is specifically configured to:
extracting effective marks and ineffective marks in the mark sequence, converting the effective marks into non-empty zone bits, and converting the ineffective marks into empty zone bits to obtain a binary sequence;
calculating a total length of the bit mask based on the binary sequence;
and constructing the bit mask content according to the total length and the value of each flag bit in the binary sequence.
Optionally, in a third implementation manner of the third aspect of the present invention, the constructing unit is specifically configured to:
judging whether the total length is larger than the length of one byte or not;
if the total length is greater than the length of one byte, calculating the total byte number N of the binary sequence, wherein N is greater than or equal to 2;
according to the total byte number N, creating a bit mask field with the total byte number equal to N;
setting the highest flag bit of the first N-1 bytes in the bit mask field to be non-null, and setting the values of other flag bits except the highest flag bit in the bit mask field based on the value of the flag bit in the binary sequence to obtain the bit mask content;
and if the total length is not greater than the length of one byte, setting a first flag bit in the bit mask field to be null, and setting the values of other flag bits except the highest flag bit in the first byte based on the value of the flag bit in the binary sequence to obtain the bit mask content.
Optionally, in a fourth implementation manner of the third aspect of the present invention, the encapsulation module includes:
an extraction unit configured to extract sensor data at a position in the bit mask content where a non-empty flag bit corresponds to the data transmission sequence;
a configuration unit, configured to query the field content of the command word set by the bit mask content, and set the command word in the frame header as the field content;
and the packaging unit is used for sequentially packaging the bit mask content and the extracted sensor data into a data section of a frame body in the data frame structure and forming a data packet with the frame head and the frame tail.
Optionally, in a fifth implementation manner of the third aspect of the present invention, the encapsulation unit is specifically configured to:
expanding a bit mask field in the data section of the frame body according to the field content of the command word;
assigning values to the bit mask fields based on the bit mask content to obtain bit masks;
and determining the encapsulation position of the sensor data according to the non-empty flag bit in the bit mask, encapsulating the sensor data of the corresponding sensor to the encapsulation position, and forming a data packet with the frame head and the frame tail.
A fourth aspect of the present invention provides a data reading apparatus based on a protocol frame, including:
the receiving module is used for receiving a data packet sent by the sensor data acquisition equipment, wherein the data packet is obtained by encapsulating the sensor data to be transmitted through the data transmission device based on the protocol frame;
and the reading module is used for extracting the bit mask in the data packet and reading the sensor data packaged in the data packet data section based on the bit mask.
Optionally, in a first implementation manner of the fourth aspect of the present invention, the reading module includes:
the first identification unit is used for identifying a frame body in the data packet and extracting a bit mask in the frame body; and identifying a highest-order flag bit of a first byte in the bit mask;
a second judging unit, configured to judge whether the highest flag bit is empty;
the reading unit is used for determining that the length of the bit mask is a single byte length when the highest flag bit is judged to be empty, sequentially reading the values of the flag bits except the highest flag bit in the bit mask, extracting the positions of the flag bits with non-empty values, and reading the sensor data corresponding to the positions according to the corresponding relation between the positions and the storage positions of the sensor data in the data section of the frame body;
and the system is used for identifying the highest marker bit of the next byte in the bit mask when the highest marker bit is judged not to be empty, sequentially reading the values of the marker bits except the highest marker bit of each byte in the bit mask until the highest marker bit is identified to be empty, extracting the positions of the marker bits with the non-empty values, and reading the sensor data corresponding to the positions according to the corresponding relation between the positions and the storage positions of the sensor data in the data section of the frame body.
A fifth aspect of the present invention provides a self-moving robot comprising: a memory having instructions stored therein and at least one processor, the memory and the at least one processor interconnected by a line;
the at least one processor invoking the instructions in the memory to cause the self-moving robot to perform the steps of the protocol frame-based data transmission method described above;
alternatively, the at least one processor invokes the instructions in the memory to cause the self-moving robot to perform the steps of the protocol frame-based data reading method described above.
A sixth aspect of the present invention provides a computer-readable storage medium having stored therein instructions, which, when run on a computer, cause the computer to perform the steps of the above-described protocol frame-based data transmission method or the steps of the above-described protocol frame-based data reading method.
According to the technical scheme provided by the invention, a bit mask is constructed according to the collected effective data of the sensor, the sensor data to be transmitted is packaged into a frame structure based on the bit mask to form a data packet, and the bit mask is used for indicating the effectiveness of the sensor data, namely the bit mask is added into a protocol frame to mark the effectiveness of the sensor data, so that the free expansion control of a data section in the protocol frame is realized, and the expandability of the protocol is greatly improved; meanwhile, the protocol frame is used for transmitting data, a communication protocol does not need to be changed, the occupation of invalid data on bandwidth resources can be reduced due to the arrangement of the flag bit in the data identification field, the resources of the communication bandwidth are greatly saved, the utilization rate of the resources is improved, and the expansion capability of the protocol frame is improved.
Drawings
Fig. 1 is a flowchart of a first embodiment of a data transmission method based on protocol frames according to the present invention;
fig. 2 is a flowchart of a second embodiment of a data transmission method based on protocol frames according to the present invention;
fig. 3 is a flowchart of a third embodiment of a data transmission method based on protocol frames according to the present invention;
fig. 4 is a flowchart of a fourth embodiment of a data transmission method based on protocol frames according to the present invention;
fig. 5 is a flowchart of a first embodiment of a data transmission method based on protocol frames according to the present invention;
FIG. 6 is a flow chart of step 502 provided by the present invention;
fig. 7 is a schematic structural diagram of a data transmission apparatus based on protocol frames according to an embodiment of the present invention;
fig. 8 is another schematic structural diagram of a data transmission apparatus based on protocol frames according to an embodiment of the present invention;
FIG. 9 is a schematic structural diagram of a data reading apparatus based on protocol frames according to an embodiment of the present invention;
fig. 10 is a schematic diagram of an embodiment of a self-moving robot in the embodiment of the present invention.
Detailed Description
The embodiment of the invention provides a data transmission method, a data reading method, a device, equipment and a storage medium, particularly, the expandability is increased by introducing bit mask operation into a protocol frame, and when the protocol frame with the bit mask is used for data transmission of a sensor, the bit mask mark is set to be null or non-null according to the validity of data in the sensor to cancel the data transmission of the corresponding sensor, so that the expandability of a protocol is improved. Furthermore, the bit mask length can be increased by setting the highest bit of the bit mask, so that a large amount of data of the sensor can be added, the setting mode does not influence the analysis of the protocol, and the utilization rate of the protocol frame to the communication bandwidth is improved.
The terms "first," "second," "third," "fourth," and the like in the description and in the claims, as well as in the drawings, if any, are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It will be appreciated that the data so used may be interchanged under appropriate circumstances such that the embodiments described herein may be practiced otherwise than as specifically illustrated or described herein. Furthermore, the terms "comprises," "comprising," or "having," and any variations thereof, are intended to cover non-exclusive inclusions, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
For convenience of understanding, a specific flow of the embodiment of the present invention is described below, and referring to fig. 1, an embodiment of the data transmission method based on a protocol frame in the embodiment of the present invention includes:
101. collecting sensor data generated by each sensor, and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
it is understood that the executing subject of the present invention may be a data transmission device based on a protocol frame, and may also be a terminal, a robot, or a sweeping robot, which is not limited herein. The embodiment of the invention takes the data acquisition device in the floor sweeping robot as an execution subject for explanation.
In this embodiment, the sensors refer to various sensors on the sweeping robot, such as a collision sensor, a ground detection sensor, a gyroscope, a odometer, and the like, and data of the sensors is acquired by controlling the sensors through an acquisition chip in the sweeping robot, and then the data in all the sensors is preprocessed to form a data sequence, where the preprocessing may be specifically understood as splicing the data of the sensors according to the serial number of the sensors.
Further, the method comprises the steps of collecting sensor data generated by each sensor, specifically, monitoring the sensor of the sweeping robot through a data collecting device on the sweeping robot to collect the sensor data, collecting the data generated in the sensor when the sensor is triggered to obtain the sensor data, and distinguishing the types of all the triggered monitored sensors.
In practical application, when the sensors are arranged, in order to facilitate control, a serial number is set for each sensor and is controlled according to the serial numbers, and meanwhile, the data collected by the sensors are also sequenced according to the sequence of the serial numbers to obtain a data transmission sequence; further, after the data transmission sequence is obtained, a corresponding relationship, specifically a positional relationship, between each data in the data transmission sequence and the corresponding sensor is established.
102. Identifying validity of sensor data in a data transmission sequence and generating bit mask content based on the validity;
in the step, whether data exists in each byte in the data transmission sequence is detected, a data flag bit of each byte in the data transmission sequence is generated according to the detection result, all the data flag bits are connected in series according to the byte sequence of the data transmission sequence to obtain a flag sequence corresponding to the data transmission sequence, and bit mask content is generated based on the flag sequence.
In practical applications, when acquiring sensor data, the device may acquire all sensors, but only part of the monitored sensor data may need to be transmitted, and for this, the method further includes setting a transmission tag when acquiring the sensor data, determining a type of the sensor data to be transmitted based on the identification of the transmission tag, and generating bitmask content based on the type.
103. Extracting corresponding sensor data from the data transmission sequence according to the bit mask content, packaging the extracted sensor data and the bit mask content into a data frame structure together to form a data packet, and transmitting the data packet to a receiving device.
In this step, when transmitting the data packet to the receiving device, specifically, the data packet is sent to the receiving device through the current communication protocol.
In this embodiment, the current communication protocol is a data transmission protocol generated by handshaking between a device (e.g., a sweeping robot) where the sensor is located and the receiving device, a frame structure obtained based on the data transmission protocol is a protocol frame that can be adjusted in frame structure, specifically, the frame structure is selected and adjusted by the field command, and the adjusted protocol frame is transmitted by the data transmission protocol obtained by handshaking, for example, the data on the charging sensor is transmitted to the charging dock by the data transmission protocol, and then the charging dock can control the sweeping robot to return to charging according to the received data.
In this embodiment, before generating the bit mask, the method further includes determining a specific data frame structure, where the data frame structure is obtained by detecting whether the currently used sensor data is the same as the type of the sensor at the last transmission time or whether a new sensor is added, and if so, data content needs to be added, the method needs to select to package the data by means of the bit mask for transmission, specifically, by determining a command word, a field command based on the command word is an incoming bit mask command, adjusting a frame body in the protocol frame based on the bit mask command, and introducing the bit mask, where a flag bit in the incoming bit mask is specifically set by a data flag bit in a transmission parameter, for example, a sensor position corresponding to valid data of a flag in the data bit, setting a flag bit of the bit mask based on a byte correspondence relationship between the sensor and a data segment in the frame body, thereby obtaining a specific frame body and finally outputting a corresponding data frame structure.
And packaging the sensor data into corresponding bytes based on the data frame structure and the flag bits in the bit mask so as to obtain a data frame, and sending the data frame to a receiving device to finish data transmission.
In this embodiment, the transmission of the sensor data is specifically performed according to actual requirements of the device, where a corresponding protocol format may be selected through device specification information carried in the transmission parameters, and the protocol format corresponds to a frame structure of a protocol frame, specifically, when the sensor data to be transmitted on the device is less, that is, the number of sensors is not large, the frame structure of a conventional protocol frame specified by the communication protocol may be directly used to transmit the data, but if the device has a special requirement, the frame structure of the protocol frame needs to be adaptively modified, and the modification may specifically be performed by selecting a corresponding frame structure type from a frame structure list according to the transmission parameters, and then selecting a corresponding frame structure, and further including determining a corresponding modification policy according to the frame structure, and modifying the protocol frame based on the modification policy.
For example, if the field command is 0x0301, it refers to a protocol frame in which a protocol frame carries a bit mask, and creates field contents of a corresponding command word according to the field command, and then introduces the field contents into the command word in the protocol frame.
In practical applications, the structure of a protocol frame generally includes the following parts, as shown in table 1:
table 1 is a protocol frame structure
Figure BDA0002773693280000071
Figure BDA0002773693280000081
The data frame structure specifically includes: when generating a data frame structure matched with transmission parameters, specifically, after determining a field command through a frame structure type, modifying field content in the frame header by the field command, further, selecting a corresponding frame modification mode according to the field content in the frame header, adding a generated bit mask into a frame body in a protocol frame, finally splicing the frame header, the frame body and the frame tail together, outputting a new protocol frame, and taking the new protocol frame as the data frame structure matched with the transmission parameters.
In the embodiment of the invention, effective data in the sensor data is identified by adding the bit mask in the protocol frame, so that the free expansion control of the data segment in the protocol frame is realized, and the expandability of the protocol is greatly improved; meanwhile, the protocol frame is used for transmitting data, a communication protocol does not need to be changed, the occupation of invalid data on bandwidth resources can be reduced due to the arrangement of the flag bit in the data identification field, the resources of the communication bandwidth are greatly saved, the utilization rate of the resources is improved, and the expansion capability of the protocol frame is improved.
Referring to fig. 2, a second embodiment of the data transmission method based on the protocol frame in the embodiment of the present invention is an improvement of a sensor data transmission method based on an existing sweeping robot, and specifically, the data transmission method is obtained by adjusting a frame structure of a protocol frame for transmitting data, and the method specifically includes the following steps:
201. collecting sensor data generated by each sensor, and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
acquiring data to be transmitted in each sensor to form a sensor data set, extracting effective data and invalid data in the sensor data set, and generating a data transmission sequence based on the effective data and the invalid data;
in the step, data in the sensor data set is extracted through a data extraction algorithm, content in each byte in the sensor data set is extracted, whether the content is empty or not is judged, if the content is not empty, a non-empty data flag bit is generated, and if the content is empty, an empty data flag bit (namely an empty flag) is generated, until all bytes in the sensor data set are extracted and judged, all the non-empty data flag bits and the empty flag bits are sequenced and connected in series according to byte sequencing in the sensor data set, so that a flag bit string is formed, and a data transmission sequence is obtained.
202. Calculating the data volume of each data block in the data transmission sequence, and judging whether the data volume meets the transmission condition;
in this step, the transmission condition may be understood as a bit value, and when calculating the data amount of each data block, the method further includes identifying a transmission flag in the data block, determining whether to calculate the data amount based on the transmission flag, and determining whether the data amount satisfies the transmission condition.
203. Marking the corresponding data block according to the judgment result to obtain a marking sequence;
wherein the mark comprises a valid mark and an invalid mark;
204. constructing bit mask content according to the marker sequence;
in this step, in the process of constructing the bit mask content, the method is specifically realized by the following steps:
extracting effective marks and ineffective marks in the mark sequence, converting the effective marks into non-empty zone bits, and converting the ineffective marks into empty zone bits to obtain a binary sequence;
calculating a total length of the bit mask based on the binary sequence;
and constructing the bit mask content according to the total length and the value of each flag bit in the binary sequence.
Further, constructing the bit mask content according to the total length and the value of each flag bit in the binary sequence includes:
judging whether the total length is larger than the length of one byte or not;
if the total length is greater than the length of one byte, calculating the total byte number N of the binary sequence, wherein N is greater than or equal to 2;
according to the total byte number N, creating a bit mask field with the total byte number equal to N;
setting the highest flag bit of the first N-1 bytes in the bit mask field to be non-null, and setting the values of other flag bits except the highest flag bit in the bit mask field based on the value of the flag bit in the binary sequence to obtain the bit mask content;
further, if the total length is not greater than the length of one byte, setting a first flag bit in the bit mask field to be null, and setting values of flag bits other than the highest flag bit in the first byte based on the value of the flag bit in the binary sequence to obtain the bit mask content.
In practical application, when the bit mask field is one byte long, and when the bit mask is created or set in the data frame structure, the highest flag bit in the first byte of the data segment portion of the frame body in the data frame structure is directly set to be null, and other bits are correspondingly set according to the value of the flag bit in the binary sequence. When the highest bit in the first byte in the data segment is detected to be empty when the data is read, the second byte and the bytes after the second byte are both determined to be sensor data.
205. Extracting corresponding sensor data from the data transmission sequence according to the bit mask content, packaging the extracted sensor data and the bit mask content into a data frame structure together to form a data packet, and transmitting the data packet to a receiving device.
In practical application, the data frame structure is specifically determined according to data requirements for transmission, and transmission of some sensor data can also guarantee data transmission without using a frame structure with a bit mask, but when the frame structure needs to be expanded when the amount of some sensor data is large, encapsulation transmission of data is performed by using a frame structure with a bit mask, and specifically, the data frame structure can be determined in the following manner:
acquiring sensor data to be transmitted, extracting effective data and invalid data in the sensor data, and generating mark information based on the effective data and the invalid data, wherein the mark information comprises a blank mark and a non-blank mark;
inquiring command words corresponding to the blanking marks from a preset command word relation table according to the blanking marks in the mark information;
in this embodiment, a protocol frame specified in a communication protocol is a protocol frame structure that can be freely expanded, and a corresponding frame structure needs to be selected according to actual flag information in actual data transmission, specifically, it is first determined whether a blanking flag exists in the flag information, and if so, it is determined that the blanking flag needs to be set in the used protocol frame for data transmission, and at this time, a corresponding command word is selected from a command word relationship table of the protocol frame according to the blanking flag, where the command word relationship table includes modification command words of frame structures of protocol frames used in various situations, and the command word of the blanking flag refers to flag setting that a bit mask is introduced into the protocol frame to enable or disable transmitted data.
Determining a first protocol format for transmitting sensor data according to the command word;
determining a frame structure type corresponding to the first protocol format based on the corresponding relationship between the protocol format and the frame structure type;
in this embodiment, after the command word is determined, a corresponding first protocol format is queried from a preset command word table according to the command word, where the first protocol format may be understood as a frame structure of a protocol frame, and if the device needs to shield data transmission of some sensor modules at a certain time, the device needs to select the corresponding frame structure by selecting the shielded command word, specifically, a data storage field in the protocol frame is set by the command word, that is, a frame structure capable of setting the data storage field is selected to transmit data at the time.
If the command word is a command word for introducing the bit mask, determining the setting position of the bit mask in the protocol frame and the byte length of the bit mask based on the frame structure type;
in this step, the determining of the setting position of the bit mask in the protocol frame and the byte length of the bit mask is to specifically query a modification policy of the corresponding protocol frame by introducing a bit mask command word, and the modification policy may also be understood as an extension manner of the protocol frame, and the setting position (i.e., the byte position) of the bit mask to be introduced in the protocol frame corresponding to the frame structure type is determined based on the extension manner, for example, the bit mask is set in a byte section of a frame body in the protocol frame.
Further, the byte length of the bit mask is specifically determined according to the transmission parameter, preferably according to the length of the flag bit string of the transmission parameter, and the quotient of the flag bit string and the single byte length is calculated to determine the byte length.
In practical applications, if the byte length of the bit mask is two bytes or more, the most significant bits of all bytes before the last byte are set to be non-null, and the most significant bit of the last byte is set to be null.
Acquiring a protocol frame in a current communication protocol, and analyzing a frame head, a frame body and a frame tail of the protocol frame;
in this embodiment, the structure of the protocol frame specifically includes a frame header, a frame body, and a frame trailer, where the frame header is at least provided with the following types of field start codes, frame lengths, frame sequence numbers, and command words, the frame body at least includes a data segment type field, and the frame trailer is at least provided with the following types of fields: a check code and an end code.
Specifically, when the header of the protocol frame is parsed, the contents of the fields of the command words in the header are parsed and extracted, and then the information of the first N bytes of the data segment in the frame body is parsed according to the contents of the fields of the command words.
Setting the field of the command word in the frame header as an incoming bit mask command word, and extracting the byte structure of the data segment in the frame body;
a command word determined based on the frame structure type (an incoming bit mask command word) is substituted for the contents of the fields of the command word in the frame header to obtain a new frame header, and then the byte structure in the data segment in the frame body is extracted according to the incoming bit mask command word in the new frame header, which should be understood as the byte structure of a specific position (set position) in the data segment specified in the incoming bit mask command word, such as the first byte or the first N bytes.
Intercepting bytes with the length equal to the byte length of the bit mask in the byte structure by taking the set position as a starting point to be set as bit mask bytes, and generating a data frame structure matched with the mark information;
in this embodiment, the setting position is generally selected as a starting setting position where a first byte in a byte structure in the data segment is a bit mask, then the byte structure is intercepted according to the determined byte length of the bit mask to form a field of a bit mask byte, a new frame body is output, finally, a new frame header, a new frame body and a frame tail are spliced together to form a new protocol frame, and a structure corresponding to the protocol frame is output as a data frame structure.
In practical application, if the setting position is the first byte in the byte structure and the byte length of the bit mask is one byte length, setting the attribute of the field of the first byte in the byte structure as the bit mask attribute when setting the byte structure of the data segment of the frame body; and adjusting the content of a field in the first byte according to the bit mask information to generate a data frame structure matched with the transmission parameters.
Specifically, the first byte in the data segment is set as a bit mask, for example, b10100101, where the highest bit can be set, and when the highest bit is set to 1, it indicates that the next byte is also the bit mask, and by analogy, the bit mask can expand the length of the bit mask, so as to expand the output transmission of the sensor; if the highest bit is set to 0, it indicates that the next data byte after the bit mask is the valid data of the sensor, and several flag bits after the highest bit is removed in the bit mask are 1, it indicates that several valid data segments recorded in the byte after the bit mask byte is removed in the subsequent data segment are available, such as collision sensors, ground detection sensors, gyroscopes, odometers, etc., that is, the flag bit corresponding to the sensor in the bit mask is set to 1, that is, the bit mask is represented by four bits, if the current device to transmit data does not need the sensor, the data of the sensor can be set to invalid by setting the bit corresponding to the bit mask to 0, thereby realizing that the data segment only needs to transmit valid data, avoiding the occupation of bandwidth by transmitting null data, saving bandwidth, and saving the calculation capability of analysis; furthermore, if a new sensor is required to be added, for example, the electric quantity only needs to be represented by adding one bit in the bit mask segment, and the electric quantity data is added in the effective data segment, so that even if the device is changed, as long as the device still uses the protocol frame to transmit data, the communication protocol is not influenced, and the development efficiency of different devices in data transmission is greatly saved.
Based on the mark information, packaging the sensor data set into a data frame structure to obtain a data frame;
and sending the data frame to the receiving device through the current communication protocol.
In the embodiment of the invention, the data transmission method realizes the setting of the non-fixed length of the protocol, introduces bit mask operation, increases the expandability, only needs to set the bit mask to 0 when a certain module is not needed to cancel the module, only needs to add the bit mask of one bit to complete the addition of the module when the bit mask needs to be added, and greatly improves the expandability of the protocol.
Furthermore, the bit mask length can be increased by setting the highest bit of the bit mask, so that a large number of modules can be added without influencing the analysis of the protocol, and the performance of the product is improved.
Referring to fig. 3, a third embodiment of a data transmission method based on a protocol frame according to the embodiment of the present invention includes:
301. collecting sensor data generated by each sensor, and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
302. calculating the data volume of each data block in the data transmission sequence, and judging whether the data volume meets the transmission condition;
303. marking the corresponding data block according to the judgment result to obtain a marking sequence;
wherein the mark comprises a valid mark and an invalid mark;
304. constructing bit mask content according to the marker sequence;
in this step, the mark sequence refers to a numerical value consisting of 0 and 1 digits in a binary system, each digit represents data validity and invalidity of a sensor or a class of sensors, the validity refers to sensor data needing to be transmitted in the sweeping robot, and the invalidity refers to no sensor data being transmitted.
In practical applications, the bit mask content is at least one byte in size, and when it has only one byte, it indicates that the number of sensors transmitted in the data packet is only one byte in size, and each bit represents data of one sensor, and when it is 0, it indicates that the data of the sensor corresponding to the position does not need to be transmitted or the sensor has been removed, and when it is 1, it indicates that the data of the sensor corresponding to the position needs to be transmitted or the sensor is a newly added sensor.
When there are multiple bytes, it indicates that there are more sensor data to be transmitted, and the most significant bit of the first byte in the bit mask should be set to 1, which indicates that the second byte in the following bit mask also belongs to the setting of the bit mask.
305. Extracting sensor data at positions in the bit mask content where non-empty flag bits correspond to a data transmission sequence;
in this step, when extracting sensor data based on a bit mask, it is first necessary to identify whether the highest bit in the bit mask is 1, if not, continue to read the value of the second highest bit in the bit mask, if 1, read the data of the sensor at the corresponding position according to the position corresponding relationship between each flag bit in the bit mask and the sensor, until each flag bit of the bit mask identifies the completion position, and form a sensor data set.
306. Inquiring field content of the command word set by the bit mask content, and setting the command word in the frame header as the field content;
after determining the bit mask content and the sensor data, performing data encapsulation, specifically, also including determining a data frame structure, the data frame structure inquires the setting field information of the corresponding data frame structure according to the setting of the bit mask, in particular to command words, namely the field content in the frame header is the command words, in practical applications, the command word in the data frame structure that can set the bit mask is 0x0301, after setting the command word, extracting a frame body structure in the data frame structure, and then, starting from the first byte in the data section in the frame body structure, setting a bit mask according to the bit mask content, after the bit mask is set, the sensor data is packaged in the data section after the bit mask according to the value of each flag bit in the bit mask to form a finished frame body structure, and finally, a data packet is generated by combining a frame head and a frame tail.
307. Expanding a bit mask field in a data segment of the frame body according to the field content of the command word;
in this embodiment, when expanding a bit mask field, specifically, setting an attribute of a field of a first byte in the data segment as a bit mask attribute;
and adjusting the content of the field in the first byte according to the bit mask content to generate a matched data frame structure.
In practical application, judging whether the length of the bit mask content is greater than the length of one byte or not;
if the bit mask content is larger than the preset bit mask content, calculating the total number N of bytes occupied by the bit mask content, wherein N is larger than or equal to 2;
and setting the highest flag bit of the first N-1 bytes in the data segment to be non-null and the highest bit of the Nth byte to be 0 according to the total number of the bytes to obtain a bit mask field.
308. Assigning a bit mask field based on the bit mask content to obtain a bit mask;
309. determining the encapsulation position of the sensor data according to the non-empty flag bit in the bit mask, encapsulating the sensor data of the corresponding sensor to the encapsulation position, and forming a data packet with the frame head and the frame tail;
in practical application, according to a non-empty flag bit in a bit mask in the data segment, determining a byte position of an effective data segment of a field after the bit mask in the data segment;
packaging the sensor data into corresponding byte positions to obtain data frames to be transmitted;
and adjusting the data frame to be transmitted according to the empty flag bit in the bit mask field in the data frame to obtain a data packet.
310. The data packet is transmitted to a receiving device.
In this embodiment, when the data of the sensor of the sweeping robot is encapsulated and transmitted by the method, a specific application may be the following implementation procedure, please refer to fig. 4, and a fourth embodiment of the data transmission method based on the protocol frame in the embodiment of the present invention includes:
401. acquiring a sensor data set to be transmitted, extracting effective data and invalid data in the sensor data set, and generating transmission parameters based on the effective data and the invalid data;
402. inquiring a command word corresponding to the blanking mark from a preset command word relation table according to the blanking mark in the transmission parameter;
403. determining a first protocol format for transmitting the sensor data set according to the command word;
404. determining a frame structure type corresponding to the first protocol format based on the corresponding relationship between the protocol format and the frame structure type;
405. if the command word is a command word for introducing the bit mask, determining the setting position of the bit mask in the protocol frame and the byte length of the bit mask based on the frame structure type;
406. acquiring a protocol frame in a current communication protocol, and analyzing a frame head, a frame body and a frame tail of the protocol frame;
in this embodiment, the structure of the protocol frame specifically includes a frame header, a frame body, and a frame trailer, where the frame header is at least provided with the following types of field start codes, frame lengths, frame sequence numbers, and command words, the frame body at least includes a data segment type field, and the frame trailer is at least provided with the following types of fields: a check code and an end code.
Specifically, when the header of the protocol frame is parsed, the contents of the fields of the command words in the header are parsed and extracted, and then the information of the first N bytes of the data segment in the frame body is parsed according to the contents of the fields of the command words.
Wherein, the start code: fixed as 0xAA,0xA5, for identifying the start of message frame, where the start code is double-byte, greatly reducing the possibility of appearing in the effective data area;
frame length: here set to 2 bytes, of type fluid 16, defined as: the sum of all lengths of the frame length, the frame serial number, the command code, the data segment and the check code, and the error of the frame length can cause the error of message frame analysis;
frame number: is a unique ID of the message frame for identifying this data frame;
command word: the identification is a specific command type, and the content of the data segment corresponding to different commands is different;
active frame: setting a frame ID, wherein the frame ID needs to be self-increased;
response frame: use of active frame numbers, otherwise parsing may be erroneous;
and (3) data segment: it describes the data carried by different command words, and for commands without parameters, the data field may be empty. A bit mask operation is introduced at a particular "command word". The first byte of the data segment represents the first BIT mask and the most significant BIT7 of each BIT mask may determine whether the next byte is a BIT mask and cycle through. Each bit of the bit mask represents a field, and if the corresponding bit is 1, the following data segment has data. A value of 0 indicates that this data segment is not present. Therefore, the bandwidth can be greatly saved, and the expandability is increased;
end code (may not be used): fixed to 0x55,0x5A, for identifying the end of the message frame;
and (4) checking codes: the check algorithm used by the protocol is a CRC16 check algorithm, and in the calculated range message frame: frame length-data segment, specifically using CRC16 algorithm.
407. Setting the field of the command word in the frame header as an incoming bit mask command word, and extracting the byte structure of the data segment in the frame body;
408. analyzing the ranking information of the sensor corresponding to the null sign in the transmission parameter;
409. establishing a corresponding position relation according to the ranking information and the bit mask, setting the mark position corresponding to the empty mark in the bit mask to be empty, and setting other mark positions to be non-empty to obtain bit mask information corresponding to the sensor data set;
in this step, the flag position of the blanking flag and the other flag bits do not include the highest flag bit in the bit mask;
410. judging whether the length of the bit mask information is greater than the length of one byte or not;
411. if so, calculating the total number N of bytes occupied by the bit mask information;
412. according to the total number of bytes, setting the highest flag bit of the first N-1 bytes in the bit mask information to be non-null to obtain new bit mask information;
specifically, firstly, according to the total number N of bytes, starting the byte structure in the data segment from the first byte, selecting N bytes as a bit mask field, and then setting the first byte in the data segment as a bit mask, such as b10100101, where the highest bit is 1, which indicates that the next byte is also a bit mask, and so on, the bit mask can expand the length of the bit mask until the highest bit of the N-1 th byte is set to 1, and the highest bit of the N-th byte is set to 0, ending the expansion setting of the bit mask field, and the bytes of the data segment after the N-th byte represent that the valid data of the sensor is stored;
further, after the most significant bit of the bit mask is set, the flag bit of the bit mask after the most significant bit is removed is set according to the data flag bit in the transmission parameter, specifically, if the data flag bit is 1, the flag bit corresponding to the bit mask is also set to 1, and the others are set to 0, where several bits in the bit mask are set to 1, which indicates that there are several valid data segments recorded in the byte after the bit mask byte is removed in the subsequent data segment.
413. Intercepting bytes with the length equal to the byte length of the bit mask in the byte structure by taking the set position as a starting point to be set as bit mask bytes, and generating a data frame structure matched with the transmission parameters;
414. determining the byte position of an effective data segment in a byte structure according to a non-empty flag bit in a bit mask byte in a data frame;
415. packaging data of effective sensors in the sensor data set into corresponding byte positions to obtain data frames to be transmitted;
416. adjusting the data frame to be transmitted according to the empty flag bit in the bit mask field in the data frame to obtain the data frame;
417. and sending the data frame to the receiving device through the current communication protocol.
In conclusion, effective data in a transmission data set is identified by adding a data identification field in a protocol frame, so that free expansion control of a data segment in the protocol frame is realized, and the expandability of the protocol is greatly improved; meanwhile, the protocol frame is used for transmitting data, a communication protocol does not need to be changed, the occupation of invalid data on bandwidth resources can be reduced due to the arrangement of the flag bit in the data identification field, the resources of the communication bandwidth are greatly saved, the utilization rate of the resources is improved, and the expansion capability of the protocol frame is improved.
Furthermore, a double-byte frame header is used, so that the probability of the effective data is reduced, and too much bandwidth cannot be wasted; by setting the highest bit of the bit mask, the bit mask length can be increased, so that a large number of modules can be added without influencing the resolution of the protocol.
Referring to fig. 5, an embodiment of the data reading method based on the protocol frame in the embodiment of the present invention includes:
501. receiving a data packet sent by sensor data acquisition equipment;
the data packet is obtained by encapsulating the sensor data to be transmitted by the data transmission method based on the protocol frame provided by the above embodiment.
Specifically, the implementation of forming the data packet in the encapsulation is as follows:
the method comprises the steps of collecting sensor data generated by each sensor, and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
calculating the data volume of each data block in the data transmission sequence, and judging whether the data volume meets the transmission condition;
marking the corresponding data block according to the judgment result to obtain a marking sequence, wherein the marking comprises an effective marking and an ineffective marking;
extracting effective marks and ineffective marks in the mark sequence, converting the effective marks into non-empty zone bits, and converting the ineffective marks into empty zone bits to obtain a binary sequence;
calculating a total length of the bitmask based on a length of each byte and the binary sequence;
judging whether the total length is larger than the length of one byte or not;
if so, calculating the total byte number N of the binary sequence;
creating a bit mask field with the total number of bytes equal to N according to the total number of bytes;
setting the highest flag bit of the first N-1 bytes in the bit mask field to be non-null, and setting the values of other flag bits except the highest flag bit in the bit mask field based on the value of the flag bit in the binary sequence to obtain the bit mask content;
extracting sensor data at locations in the bitmask content where non-empty flag bits correspond to the data transmission sequence;
inquiring the field content of the command word set by the bit mask content, and setting the command word in the frame header as the field content;
expanding a bit mask field in the data section of the frame body according to the field content of the command word;
assigning values to the bit mask fields based on the bit mask content to obtain bit masks;
and determining the encapsulation position of the sensor data according to the non-empty flag bit in the bit mask, encapsulating the sensor data of the corresponding sensor to the encapsulation position, and forming a data packet with the frame head and the frame tail.
502. And extracting a bit mask in the data packet, and reading the sensor data packaged in the data packet data section based on the bit mask.
In this embodiment, specifically, the parsing is performed on the data packet first, and the parsing specifically includes parsing a frame header, a frame body, and a frame tail, then identifying the content of the command word in the frame header, and determining whether the content is the structure of the frame body that performs data encapsulation based on the bit mask, if so, parsing the specific content of the data segment in the frame body, specifically identifying the content of the bit mask field and the data field, and its specific implementation steps are shown in fig. 6:
601. identifying a frame body in the data packet and extracting a bit mask in the frame body;
602. identifying the highest flag bit of the first byte in the bit mask, and judging whether the highest flag bit is empty or not;
603. if so, determining the length of the bit mask as the length of a single byte, sequentially reading the values of the zone bits except the highest zone bit in the bit mask, extracting the position of the zone bit with a non-empty value, and reading the sensor data corresponding to the position according to the corresponding relation between the position and the storage position of the sensor data in the data section of the frame body;
604. and if not, identifying the highest marker bit of the next byte in the bit mask, reading the values of the marker bits except the highest marker bit of each byte in the bit mask in sequence until the highest marker bit is identified to be empty, extracting the positions of the marker bits with non-empty values, and reading the sensor data corresponding to the positions according to the corresponding relation between the positions and the storage positions of the sensor data in the data section of the frame body.
In practical application, the highest bit of the first byte of the data segment in the frame body is firstly identified, if the highest bit is 0, only the numerical value in each flag bit in the first byte needs to be read continuously, and the data of which sensors are transmitted is selected according to the numerical value, so that the positions of the sensors are determined, and the data of the data sensors are read from the data segment after the first byte.
If the highest bit is 1, continuously identifying the highest bit of the next byte, judging whether the highest bit is 1 or not, stopping identification until the highest bit in a certain byte is identified to be not 1, determining the byte with the highest bit not being 1 and the previous byte as bit masks, calculating the length of the bit masks, sequentially reading the numerical value of the mark bit except the highest bit in each byte in the bit masks, reading the sensor data in the data segment after the bit masks, and determining which sensors correspond to each following sensor data based on the numerical value of the mark bit, thereby finishing reading the sensor data.
In summary, by introducing a bit mask operation into a protocol frame, scalability is increased, and when data transmission of a sensor is performed by using the protocol frame with the bit mask, data transmission of the corresponding sensor is cancelled by setting a flag of the bit mask to be null or non-null according to validity of data in the sensor, thereby improving scalability of the protocol. Furthermore, the bit mask length can be increased by setting the highest bit of the bit mask, so that a large amount of data of the sensor can be added, the setting mode does not influence the analysis of the protocol, and the utilization rate of the protocol frame to the communication bandwidth is improved.
With reference to fig. 7, the data transmission method based on the protocol frame in the embodiment of the present invention is described above, and a data transmission device based on the protocol frame in the embodiment of the present invention is described below, where an embodiment of the data transmission device based on the protocol frame in the embodiment of the present invention includes:
the acquisition module 701 is used for acquiring sensor data generated by each sensor and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
a bit mask generation module 702 configured to identify validity of sensor data in the data transmission sequence and generate bit mask content based on the validity;
a packaging module 703, configured to extract corresponding sensor data from the data transmission sequence according to the bit mask content, and package the extracted sensor data and the bit mask content together into a data frame structure to form a data packet;
a transmitting module 704, configured to transmit the data packet to a receiving device.
In the embodiment of the invention, a bit mask is constructed according to the collected effective data of the sensor, the sensor data to be transmitted is packaged into a frame structure based on the bit mask to form a data packet, and the bit mask is used for indicating the effectiveness of the sensor data, namely the effectiveness of the sensor data is identified by adding the bit mask in a protocol frame, so that the free expansion control of a data segment in the protocol frame is realized, and the expandability of the protocol is greatly improved; meanwhile, the protocol frame is used for transmitting data, a communication protocol does not need to be changed, the occupation of invalid data on bandwidth resources can be reduced due to the arrangement of the flag bit in the data identification field, the resources of the communication bandwidth are greatly saved, the utilization rate of the resources is improved, and the expansion capability of the protocol frame is improved.
Referring to fig. 8, another embodiment of the data transmission apparatus based on protocol frames according to the embodiment of the present invention includes:
the acquisition module 701 is used for acquiring sensor data generated by each sensor and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
a bit mask generation module 702 configured to identify validity of sensor data in the data transmission sequence and generate bit mask content based on the validity;
a packaging module 703, configured to extract corresponding sensor data from the data transmission sequence according to the bit mask content, and package the extracted sensor data and the bit mask content together into a data frame structure to form a data packet;
a transmitting module 704, configured to transmit the data packet to a receiving device.
Wherein the bit mask generating module 702 comprises:
a calculating unit 7021, configured to calculate a data amount of each data block in the data transmission sequence;
a first determining unit 7022, configured to determine whether the data amount satisfies a transmission condition;
a marking unit 7023, configured to mark the corresponding data block according to a judgment result to obtain a marking sequence, where the marking includes an effective marking and an invalid marking;
a constructing unit 7024, configured to construct bit mask content according to the marker sequence.
Optionally, the constructing unit 7023 is specifically configured to:
extracting effective marks and ineffective marks in the mark sequence, converting the effective marks into non-empty zone bits, and converting the ineffective marks into empty zone bits to obtain a binary sequence;
calculating a total length of the bit mask based on the binary sequence;
and constructing the bit mask content according to the total length and the value of each flag bit in the binary sequence.
Optionally, the constructing unit 7023 is specifically configured to:
judging whether the total length is larger than the length of one byte or not;
if the total length is greater than the length of one byte, calculating the total byte number N of the binary sequence, wherein N is greater than or equal to 2;
according to the total byte number N, creating a bit mask field with the total byte number equal to N;
setting the highest flag bit of the first N-1 bytes in the bit mask field to be non-null, and setting the values of other flag bits except the highest flag bit in the bit mask field based on the value of the flag bit in the binary sequence to obtain the bit mask content;
and if the total length is not greater than the length of one byte, setting a first flag bit in the bit mask field to be null, and setting the values of other flag bits except the highest flag bit in the first byte based on the value of the flag bit in the binary sequence to obtain the bit mask content.
Wherein the encapsulation module 703 includes:
an extracting unit 7031, configured to extract sensor data at a position where a non-empty flag bit in the bit mask content corresponds to the data transmission sequence;
a configuration unit 7032, configured to query field contents of the command word set in the bit mask content, and set the command word in the frame header as the field contents;
a packaging unit 7033, configured to sequentially package the bit mask content and the extracted sensor data into a data segment of a frame body in the data frame structure, and form a data packet with the frame header and the frame trailer.
Optionally, the encapsulating unit 7033 is specifically configured to:
expanding a bit mask field in the data section of the frame body according to the field content of the command word;
assigning values to the bit mask fields based on the bit mask content to obtain bit masks;
and determining the encapsulation position of the sensor data according to the non-empty flag bit in the bit mask, encapsulating the sensor data of the corresponding sensor to the encapsulation position, and forming a data packet with the frame head and the frame tail.
Referring to fig. 9, the data reading apparatus based on protocol frame according to the embodiment of the present invention includes:
a receiving module 901, configured to receive a data packet sent by a sensor data acquisition device, where the data packet is obtained by encapsulating sensor data to be transmitted through the data transmission device based on a protocol frame as described above;
a reading module 902, configured to extract a bit mask in the data packet, and read the sensor data encapsulated in the data packet data segment based on the bit mask.
Wherein the reading module 902 comprises:
a first identifying unit 9021, configured to identify a frame body in the data packet, and extract a bit mask in the frame body; and identifying a highest-order flag bit of a first byte in the bit mask;
a second determining unit 9022, configured to determine whether the highest flag bit is empty;
a reading unit 9023, configured to determine that the length of the bit mask is a single-byte length when it is determined that the highest flag bit is empty, sequentially read the values of flag bits other than the highest flag bit in the bit mask, extract the position of a flag bit whose value is not empty, and read sensor data corresponding to the position according to a correspondence between the position and a storage position of the sensor data in the data segment of the frame body;
and the system is used for identifying the highest marker bit of the next byte in the bit mask when the highest marker bit is judged not to be empty, sequentially reading the values of the marker bits except the highest marker bit of each byte in the bit mask until the highest marker bit is identified to be empty, extracting the positions of the marker bits with the non-empty values, and reading the sensor data corresponding to the positions according to the corresponding relation between the positions and the storage positions of the sensor data in the data section of the frame body.
Fig. 7 to 9 describe the protocol frame-based data transmission device and the data reading device in detail in the embodiment of the present invention from the perspective of the modular functional entity, and the self-moving robot in the embodiment of the present invention is described in detail in the following from the perspective of hardware processing.
Fig. 10 is a schematic structural diagram of a self-moving robot according to an embodiment of the present invention, where the self-moving robot 1000 may have a relatively large difference due to different configurations or performances, and may include one or more processors (CPUs) 1010 (e.g., one or more processors) and a memory 1020, one or more storage media 1030 (e.g., one or more mass storage devices) storing an application program 1033 or data 1032. Memory 1020 and storage media 1030 may be, among other things, transient or persistent storage. The program stored in the storage medium 1030 may include one or more modules (not shown), each of which may include a series of instruction operations for the self-moving robot 1000. Still further, the processor 1010 may be configured to communicate with the storage medium 1030 to execute a series of instruction operations in the storage medium 1030 on the self-moving robot 1000.
The self-moving robot 1000 may also include one or more power sources 1040, one or more wired or wireless network interfaces 1050, one or more input-output interfaces 1060, and/or one or more operating systems 1031, such as Windows service, Mac OS X, Unix, Linux, FreeBSD, and the like. Those skilled in the art will appreciate that the self-moving robot configuration shown in fig. 10 does not constitute a limitation of the self-moving robot and may include more or fewer components than shown, or some components in combination, or a different arrangement of components.
The present invention also provides a self-moving robot, where the computer device includes a memory and a processor, and the memory stores computer readable instructions, and the computer readable instructions, when executed by the processor, cause the processor to perform the steps of the protocol frame-based data transmission method in the embodiments described above, or the steps of the protocol frame-based data reading method in the embodiments described above.
The present invention also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium, and may also be a volatile computer-readable storage medium, where instructions are stored, and when the instructions are executed on a computer, the instructions cause the computer to execute the steps of the protocol frame-based data transmission method or the steps of the protocol frame-based data reading method in the foregoing embodiments.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. 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 above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (12)

1. A data transmission method based on a protocol frame is applied to a self-moving robot, and is characterized by comprising the following steps:
the method comprises the steps of collecting sensor data generated by each sensor, and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
identifying validity of sensor data in the data transmission sequence and generating bit mask content based on the validity;
and extracting corresponding sensor data from the data transmission sequence according to the bit mask content, packaging the extracted sensor data and the bit mask content into a data frame structure together to form a data packet, and transmitting the data packet to a receiving device.
2. The method of claim 1, wherein identifying validity of sensor data in the data transmission sequence and generating bitmask content based on the validity comprises:
calculating the data volume of each data block in the data transmission sequence, and judging whether the data volume meets the transmission condition;
marking the corresponding data block according to the judgment result to obtain a marking sequence, wherein the marking comprises an effective marking and an ineffective marking;
and constructing bit mask content according to the mark sequence.
3. The method for data transmission based on protocol frames according to claim 2, wherein said constructing bit mask content according to said tag sequence comprises:
extracting effective marks and ineffective marks in the mark sequence, converting the effective marks into non-empty zone bits, and converting the ineffective marks into empty zone bits to obtain a binary sequence;
calculating a total length of the bit mask based on the binary sequence;
and constructing the bit mask content according to the total length and the value of each flag bit in the binary sequence.
4. The method according to claim 3, wherein the constructing the bit mask content according to the total length and the value of each flag in the binary sequence comprises:
judging whether the total length is larger than the length of one byte or not;
if the total length is greater than the length of one byte, calculating the total byte number N of the binary sequence, wherein N is greater than or equal to 2;
according to the total byte number N, creating a bit mask field with the total byte number equal to N;
setting the highest flag bit of the first N-1 bytes in the bit mask field to be non-null, and setting the values of other flag bits except the highest flag bit in the bit mask field based on the value of the flag bit in the binary sequence to obtain the bit mask content;
and if the total length is not greater than the length of one byte, setting a first flag bit in the bit mask field to be null, and setting the values of other flag bits except the highest flag bit in the first byte based on the value of the flag bit in the binary sequence to obtain the bit mask content.
5. The method according to claim 3, wherein the data frame structure comprises a header, a body and a trailer, the extracting corresponding sensor data from the data transmission sequence according to the bit mask content, and the encapsulating the extracted sensor data with the bit mask content into the data frame structure to form a data packet comprises:
extracting sensor data at locations in the bitmask content where non-empty flag bits correspond to the data transmission sequence;
inquiring the field content of the command word set by the bit mask content, and setting the command word in the frame header as the field content;
and sequentially packaging the bit mask content and the extracted sensor data into a data section of a frame body in the data frame structure, and forming a data packet with the frame head and the frame tail.
6. The method according to claim 5, wherein said sequentially encapsulating the bit mask content and the extracted sensor data into a data segment of a frame body in the data frame structure, and forming a data packet with the frame header and the frame trailer comprises:
expanding a bit mask field in the data section of the frame body according to the field content of the command word;
assigning values to the bit mask fields based on the bit mask content to obtain bit masks;
and determining the encapsulation position of the sensor data according to the non-empty flag bit in the bit mask, encapsulating the sensor data of the corresponding sensor to the encapsulation position, and forming a data packet with the frame head and the frame tail.
7. A data reading method based on a protocol frame is applied to a self-moving robot, and is characterized by comprising the following steps:
receiving a data packet sent by sensor data acquisition equipment, wherein the data packet is obtained by encapsulating sensor data to be transmitted by the protocol frame-based data transmission method according to any one of claims 1 to 6;
and extracting a bit mask in the data packet, and reading the sensor data packaged in the data packet data section based on the bit mask.
8. The method according to claim 7, wherein the extracting a bit mask from the packet and reading the sensor data encapsulated in the packet data segment based on the bit mask comprises:
identifying a frame body in the data packet and extracting a bit mask in the frame body;
identifying the highest flag bit of the first byte in the bit mask, and judging whether the highest flag bit is empty or not;
if so, determining the length of the bit mask to be the length of a single byte, sequentially reading the values of the zone bits except the highest zone bit in the bit mask, extracting the position of the zone bit with a non-empty value, and reading the sensor data corresponding to the position according to the corresponding relation between the position and the storage position of the sensor data in the data section of the frame body;
and if not, identifying the highest marker bit of the next byte in the bit mask, sequentially reading the values of the marker bits except the highest marker bit of each byte in the bit mask until the highest marker bit is identified to be null, extracting the positions of the marker bits with non-null values, and reading the sensor data corresponding to the positions according to the corresponding relation between the positions and the storage positions of the sensor data in the data section of the frame body.
9. A data transmission device based on protocol frame, characterized in that the data transmission device based on protocol frame comprises:
the acquisition module is used for acquiring sensor data generated by each sensor and sequencing the sensor data according to the sequencing of each sensor to form a data transmission sequence;
a bit mask generation module for identifying the validity of the sensor data in the data transmission sequence and generating bit mask content based on the validity;
the packaging module is used for extracting corresponding sensor data from the data transmission sequence according to the bit mask content, and packaging the extracted sensor data and the bit mask content into a data frame structure to form a data packet;
and the transmission module is used for transmitting the data packet to the receiving equipment.
10. A data reading apparatus based on protocol frame, characterized in that the data reading apparatus based on protocol frame comprises:
a receiving module, configured to receive a data packet sent by a sensor data acquisition device, where the data packet is obtained by encapsulating sensor data to be transmitted by the data transmission device based on a protocol frame according to claim 9;
and the reading module is used for extracting the bit mask in the data packet and reading the sensor data packaged in the data packet data section based on the bit mask.
11. A self-moving robot, characterized by comprising: a memory having instructions stored therein and at least one processor, the memory and the at least one processor interconnected by a line;
the at least one processor invoking the instructions in the memory to cause the self-moving robot to perform the steps of the protocol frame based data transmission method of any of claims 1-6;
alternatively, the first and second electrodes may be,
the at least one processor invoking the instructions in the memory to cause the self-moving robot to perform the steps of the protocol frame based data reading method of claim 7 or 8.
12. A computer readable storage medium having stored thereon instructions, which when executed by a processor, implement the steps of the protocol frame based data transmission method according to any one of claims 1 to 6 or the steps of the protocol frame based data reading method according to claim 7 or 8.
CN202011258022.XA 2020-11-12 2020-11-12 Data transmission method, data reading method, device, equipment and storage medium Active CN112437064B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011258022.XA CN112437064B (en) 2020-11-12 2020-11-12 Data transmission method, data reading method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011258022.XA CN112437064B (en) 2020-11-12 2020-11-12 Data transmission method, data reading method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN112437064A true CN112437064A (en) 2021-03-02
CN112437064B CN112437064B (en) 2023-01-17

Family

ID=74700466

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011258022.XA Active CN112437064B (en) 2020-11-12 2020-11-12 Data transmission method, data reading method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN112437064B (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114157395A (en) * 2021-11-05 2022-03-08 在线途游(北京)科技有限公司 Data communication method, device and system based on variable length integer coding
CN114726932A (en) * 2022-05-12 2022-07-08 欧梯恩智能科技(苏州)有限公司 Data transmission method and device and electronic equipment
CN115079653A (en) * 2022-06-24 2022-09-20 山东浪潮科学研究院有限公司 Intelligent factory management system based on LoRa wireless communication technology

Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1790362A (en) * 2004-11-19 2006-06-21 Atmel德国有限公司 Method and device for data transmission
CN1855129A (en) * 2005-04-25 2006-11-01 日本电气株式会社 Wireless tag, wireless tag reader/writer, wireless tag information provision method, and wireless tag system
CN102026045A (en) * 2009-09-17 2011-04-20 华为技术有限公司 Method, device and system for transmitting and receiving data frames
CN103926036A (en) * 2014-05-08 2014-07-16 中国石油大学(华东) Movable pressure collecting ball based on bluetooth data transmission
US20140361906A1 (en) * 2013-06-06 2014-12-11 Zih Corp. Method, apparatus, and computer program product improving backhaul of sensor and other data to real time location system network
EP3144765A1 (en) * 2015-09-18 2017-03-22 Samsung Electronics Co., Ltd. Apparatus for localizing cleaning robot, cleaning robot, and controlling method of cleaning robot
CN108881112A (en) * 2017-05-10 2018-11-23 北京猎户星空科技有限公司 Generation, transmission, processing method, device and its system of sensor-based data
CN109167750A (en) * 2018-07-06 2019-01-08 北京金山安全软件有限公司 Data packet transmission method and device, electronic equipment and storage medium
CN110553652A (en) * 2019-10-12 2019-12-10 上海高仙自动化科技发展有限公司 robot multi-sensor fusion positioning method and application thereof
CN111556091A (en) * 2020-03-20 2020-08-18 中国水产科学研究院东海水产研究所 Data packing method capable of increasing and decreasing detection types, acquisition system and storage medium

Patent Citations (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1790362A (en) * 2004-11-19 2006-06-21 Atmel德国有限公司 Method and device for data transmission
CN1855129A (en) * 2005-04-25 2006-11-01 日本电气株式会社 Wireless tag, wireless tag reader/writer, wireless tag information provision method, and wireless tag system
CN102026045A (en) * 2009-09-17 2011-04-20 华为技术有限公司 Method, device and system for transmitting and receiving data frames
US20140361906A1 (en) * 2013-06-06 2014-12-11 Zih Corp. Method, apparatus, and computer program product improving backhaul of sensor and other data to real time location system network
CN103926036A (en) * 2014-05-08 2014-07-16 中国石油大学(华东) Movable pressure collecting ball based on bluetooth data transmission
EP3144765A1 (en) * 2015-09-18 2017-03-22 Samsung Electronics Co., Ltd. Apparatus for localizing cleaning robot, cleaning robot, and controlling method of cleaning robot
CN108881112A (en) * 2017-05-10 2018-11-23 北京猎户星空科技有限公司 Generation, transmission, processing method, device and its system of sensor-based data
CN109167750A (en) * 2018-07-06 2019-01-08 北京金山安全软件有限公司 Data packet transmission method and device, electronic equipment and storage medium
CN110553652A (en) * 2019-10-12 2019-12-10 上海高仙自动化科技发展有限公司 robot multi-sensor fusion positioning method and application thereof
CN111556091A (en) * 2020-03-20 2020-08-18 中国水产科学研究院东海水产研究所 Data packing method capable of increasing and decreasing detection types, acquisition system and storage medium

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114157395A (en) * 2021-11-05 2022-03-08 在线途游(北京)科技有限公司 Data communication method, device and system based on variable length integer coding
CN114157395B (en) * 2021-11-05 2023-08-08 在线途游(北京)科技有限公司 Data communication method, device and system based on variable-length integer codes
CN114726932A (en) * 2022-05-12 2022-07-08 欧梯恩智能科技(苏州)有限公司 Data transmission method and device and electronic equipment
CN115079653A (en) * 2022-06-24 2022-09-20 山东浪潮科学研究院有限公司 Intelligent factory management system based on LoRa wireless communication technology

Also Published As

Publication number Publication date
CN112437064B (en) 2023-01-17

Similar Documents

Publication Publication Date Title
CN112437064B (en) Data transmission method, data reading method, device, equipment and storage medium
CN110380970B (en) Self-adaptive data message forwarding method and device suitable for heterogeneous network
CN109981435B (en) Gateway and communication system based on CAN-ModBus to MQTT
CN108881251B (en) System and method for access analysis and standardization of any binary equipment
CN107547574B (en) Communication system and method based on universal protocol
CN110912782B (en) Data acquisition method, device and storage medium
CN105337991A (en) Integrated message flow searching and updating method
CN111683066A (en) Heterogeneous system integration method and device, computer equipment and storage medium
CN109861998B (en) Plug-in type dynamic analysis system and method based on Beidou short message protocol
CN107862074A (en) Big data quantity parameter rapid read-write method
CN114860437A (en) Data acquisition method, edge calculation host and computer-readable storage medium
CN108763127B (en) Method for realizing Modbus adapter capable of realizing interconversion of source data and target data
CN115543755B (en) Performance supervision method, device, system, equipment and medium
CN105793842B (en) Conversion method and device between serialized message
CN111294261B (en) Signal processing method, signal processing device, computer equipment and storage medium
CN112231320A (en) Web data acquisition method, system and storage medium based on MapReduce algorithm
JP7107046B2 (en) Control system, search device and search program
CN110581792A (en) Message transmission method and device
JP2003163712A (en) Network system and program
CN101764815A (en) Method and device for acquiring XML messages
CN107544928B (en) Direct memory access control device and method for operating the same
KR101748080B1 (en) System and method for transmitting and receiving data based on can-bus for marine iot platform
CN107247678B (en) Programming method of CAN-LonWorks protocol conversion logic
KR100779019B1 (en) Data mapping method in intelligent electronic device of substation
CN113381999B (en) Communication method and device and electronic equipment

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
CB02 Change of applicant information
CB02 Change of applicant information

Address after: 518110 1701, building 2, Yinxing Zhijie, No. 1301-72, sightseeing Road, Xinlan community, Guanlan street, Longhua District, Shenzhen, Guangdong Province

Applicant after: Shenzhen Yinxing Intelligent Group Co.,Ltd.

Address before: 518110 Building A1, Yinxing Hi-tech Industrial Park, Guanlan Street Sightseeing Road, Longhua District, Shenzhen City, Guangdong Province

Applicant before: Shenzhen Silver Star Intelligent Technology Co.,Ltd.

GR01 Patent grant
GR01 Patent grant