Disclosure of Invention
The invention mainly aims to provide a data transmission method, a transmitting device, a receiving device and a computer readable storage medium, aiming at limiting time slots of a transmitting party and a receiving party, thereby staggering the transmitting time of each party, avoiding data interference in the data transmission process and improving the reliability of data transmission.
In order to achieve the above object, the present invention provides a data transmission method, including the steps of:
when a sender acquires communication data to be sent, judging whether the current time slot is the time slot of the sender;
and when the current time slot is the time slot of the sender, sending the communication data to a receiver, wherein when the receiver receives the communication data, the receiver returns response information to the sender in the time slot of the receiver.
Optionally, when the current time slot is the time slot of the sender, the step of sending the communication data to the receiver includes:
when the current time slot is the time slot of the sender, generating a first random factor;
and sending the communication data to the receiver in the time slot of the sender according to the first random factor, wherein the receiver generates a second random factor when receiving the communication data, and returns the response information to the sender in the time slot of the receiver according to the second random factor.
Optionally, the data transmission method further includes:
generating a third random factor when a sender acquires communication data to be sent;
and sending the communication data to the receiving party according to the third random factor, wherein the receiving party generates a fourth random factor when receiving the communication data, and returns the response information to the sending party according to the fourth random factor.
Optionally, after the step of sending the communication data to the receiver when the current time slot is the time slot of the sender, the method further includes:
when the response information returned by the receiver is not received within the preset time length, judging whether the current time slot is the time slot of the sender;
and when the current time slot is the time slot of the sender, sending the communication data to the receiver again, wherein the preset time length is less than or equal to the time slot of the receiver.
In order to achieve the above object, the present invention further provides a data transmission method, where the data transmission method includes the following steps:
when a receiver receives communication data sent by a sender, judging whether the current time slot is the time slot of the receiver;
and when the current time slot is the time slot of the receiving party, returning response information to the sending party.
Optionally, the step of returning response information to the sender when the current time slot is the time slot of the receiver includes:
and when the current time slot is the time slot of the receiver, generating a second random factor, and returning the response information to the sender in the time slot of the receiver according to the second random factor.
Optionally, the data transmission method further includes:
and the receiver generates a fourth random factor when receiving the communication data, and returns the response information to the sender according to the fourth random factor.
In order to achieve the above object, the present invention also provides a transmission apparatus, including:
the data transmission method comprises a memory, a processor and a data transmission program which is stored on the memory and can run on the processor, wherein the data transmission program realizes the steps of the data transmission method when being executed by the processor.
In order to achieve the above object, the present invention also provides a receiving apparatus, including:
the data transmission method comprises a memory, a processor and a data transmission program which is stored on the memory and can run on the processor, wherein the data transmission program realizes the steps of the data transmission method when being executed by the processor.
To achieve the above object, the present invention further provides a computer-readable storage medium having a data transmission program stored thereon, where the data transmission program is executed by a processor to implement the steps of the data transmission method.
According to the data transmission method, the sending device, the receiving device and the computer readable storage medium, when the sender acquires communication data to be sent and the current time slot is the time slot of the sender, the communication data is sent to the receiver, and when the receiver receives the communication data, response information is returned to the sender in the time slot of the receiver. The invention limits the time slots of the sender and the receiver, thereby staggering the sending time of each party, avoiding the data interference in the data transmission process and improving the reliability of data transmission.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The invention provides a data transmission method, which staggers the sending time of each party by limiting the time slots of a sending party and a receiving party, avoids data interference in the data transmission process and improves the reliability of data transmission.
As shown in fig. 1, fig. 1 is a schematic diagram of a hardware operating environment of a terminal according to an embodiment of the present invention.
The terminal in the embodiment of the invention is a terminal with a communication function, such as a sensor, a host, a household appliance and the like. As shown in fig. 1, the terminal may include: aprocessor 1001, such as a CPU, acommunication bus 1002, and amemory 1003. Wherein acommunication bus 1002 is used to enable connective communication between these components. Thememory 1003 may alternatively be a storage device separate from theprocessor 1001.
Those skilled in the art will appreciate that the configuration of the terminal shown in fig. 1 is not intended to be limiting and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
As shown in fig. 1, thememory 1003, which is a kind of computer storage medium, may include therein an operating system and a data transfer program.
In the terminal shown in fig. 1, theprocessor 1001 may be configured to call a data transmission program stored in thememory 1003, and perform the following operations:
when a sender acquires communication data to be sent, judging whether the current time slot is the time slot of the sender;
and when the current time slot is the time slot of the sender, sending the communication data to a receiver, wherein when the receiver receives the communication data, the receiver returns response information to the sender in the time slot of the receiver.
Further, theprocessor 1001 may call the data transmission program stored in thememory 1003, and further perform the following operations:
when the current time slot is the time slot of the sender, generating a first random factor;
and sending the communication data to the receiver in the time slot of the sender according to the first random factor, wherein the receiver generates a second random factor when receiving the communication data, and returns the response information to the sender in the time slot of the receiver according to the second random factor.
Further, theprocessor 1001 may call the data transmission program stored in thememory 1003, and further perform the following operations:
generating a third random factor when a sender acquires communication data to be sent;
and sending the communication data to the receiving party according to the third random factor, wherein the receiving party generates a fourth random factor when receiving the communication data, and returns the response information to the sending party according to the fourth random factor.
Further, theprocessor 1001 may call the data transmission program stored in thememory 1003, and further perform the following operations:
when the response information returned by the receiver is not received within the preset time length, judging whether the current time slot is the time slot of the sender;
and when the current time slot is the time slot of the sender, sending the communication data to the receiver again, wherein the preset time length is less than or equal to the time slot of the receiver.
Further, theprocessor 1001 may call the data transmission program stored in thememory 1003, and further perform the following operations:
when a receiver receives communication data sent by a sender, judging whether the current time slot is the time slot of the receiver;
and when the current time slot is the time slot of the receiving party, returning response information to the sending party.
Further, theprocessor 1001 may call the data transmission program stored in thememory 1003, and further perform the following operations:
and when the current time slot is the time slot of the receiving party, generating a second random factor, and returning the response information to the sending party in the time slot of the receiving party according to the second random factor.
Further, theprocessor 1001 may call the data transmission program stored in thememory 1003, and further perform the following operations:
and when receiving the communication data, the receiver generates a fourth random factor and returns the response information to the sender according to the fourth random factor.
Referring to fig. 2, in an embodiment, the data transmission method includes:
step S11, when a sender acquires communication data to be sent, judging whether the current time slot is the time slot of the sender;
and step S12, when the current time slot is the time slot of the sender, sending the communication data to a receiver, wherein when the receiver receives the communication data, the receiver returns response information to the sender in the time slot of the receiver.
In the prior art, a sender sends communication data to a receiver, and the receiver sends response information to the sender after receiving the communication data. In this embodiment, a time slot of a sender and a time slot of a receiver are defined, where the time slot of the sender refers to that only the sender sends data in the time slot, and the time slot of the receiver refers to that only the receiver sends data in the time slot, so that sending time of each party is staggered, and the situation that the sender and the receiver occupy the same frequency band resource is avoided.
The sender and the receiver constitute a communication system that is applicable to various scenarios, such as communication between a sensor and a host, communication between a plurality of home appliances, communication between a control device and a home appliance, and the like.
The time slot of the sender and the time slot of the receiver may be the same or different, and optionally, as shown in fig. 5, both the time slot of the sender and the time slot of the receiver are 100ms.
As shown in fig. 5, the arrangement of the time slots of the transmitting side and the receiving side may be: one sender time slot is followed by one receiver time slot, and one receiver time slot is followed by one sender time slot.
In the time slot of the sending party and the time slot of the receiving party, the sending times can be set according to practical application, and optionally, the sending times in the time slot of the sending party and the time slot of the receiving party are respectively 3 times.
Further, in the same time slot of the sender or the same time slot of the receiver, the time interval between the sending times is determined by a random factor, the random factor is generated by the sender or the receiver, in the time slot of the sender, the sender generates a first random factor, and in the time slot of the receiver, the receiver generates a second random number factor. The step of sending the communication data to the receiver when the current time slot is the time slot of the sender comprises: when the current time slot is the time slot of the sender, generating a first random factor; and sending the communication data to the receiver in the time slot of the sender according to the first random factor, wherein the receiver generates a second random factor when receiving the communication data, and returns the response information to the sender in the time slot of the receiver according to the second random factor.
The generation mode of the random factor can be set according to practical application. Optionally, taking a time slot of a sender as an example, setting the time slot of the sender as T, sending times in the time slot as 3 times, and time consumed for sending data each time as N, where the first random factor generated for the first time is: x1= T-3*N, the first random factor generated for the second time is: x2= T-2*N-X1, the first random factor generated for the third time is: x3= T-X1-X2.
If there are multiple senders initiating transmission simultaneously, multiple senders and receivers may overlap in sending data, so as to interfere with each other, but according to the technical scheme provided by this embodiment, the probability of data overlapping is greatly reduced by the random interval of multiple retransmissions. And, through the inspection of the practical application system, at least once retransmission data is not interfered in a large probability, and the reliability of data transmission is ensured. Namely, under the scene that a plurality of sensors simultaneously acquire signals for data transmission, a receiving party can also respectively receive the signals of the sensors and make correct response.
After the step of sending the communication data to the receiver when the current time slot is the time slot of the sender, the method further includes: when the response information returned by the receiver is not received within the preset time length, judging whether the current time slot is the time slot of the sender; and when the current time slot is the time slot of the sender, sending the communication data to the receiver again, wherein the preset time length is less than or equal to the time slot of the receiver. For example, the sender sends communication data to the receiver in the time slot of the sender, and if no response is received when the time slot of the next sender arrives, packet loss is determined, and the communication data is resent to the receiver.
In the technical scheme disclosed in this embodiment, when the sender acquires communication data to be sent and the current time slot is the time slot of the sender, the communication data is sent to the receiver, wherein when the receiver receives the communication data, the receiver returns response information to the sender in the time slot of the receiver. Therefore, the time slots of the sender and the receiver are limited, so that the sending time of each party is staggered, the data interference in the data transmission process is avoided, and the reliability of data transmission is improved.
In another embodiment, as shown in fig. 3, based on the embodiment shown in fig. 2, the data transmission method further includes:
s13, generating a third random factor when a sender acquires communication data to be sent;
and step S14, sending the communication data to the receiving party according to the third random factor, wherein the receiving party generates a fourth random factor when receiving the communication data, and returns the response information to the sending party according to the fourth random factor.
In the prior art, a sender sends communication data to a receiver, and the receiver sends response information to the sender after receiving the communication data. In this embodiment, the time interval between the transmission of data by the transmission side and the reception side is limited, and the transmission times of the respective sides are greatly staggered.
The time interval of sending data by the sender and the receiver is determined by a random factor, the random factor is generated by the sender or the receiver, the sender generates a third random factor, the communication data is sent to the receiver according to the third random factor, the receiver generates a fourth random number factor, response information is returned to the sender according to the fourth random factor, and the third random factor and the fourth random factor can be the same or different.
The generation mode of the random factor can be set according to practical application. Optionally, for example, a time slot is taken as an example, the time slot is set to be t, the number of times of transmission in the time slot is 3, and the time consumed for transmitting data each time is n, then the first generated third random factor is: x1= t-3*n, and the third random factor generated for the second time is: x2= t-2*n-x1, and the third random factor generated for the third time is: x3= t-x1-x2.
In the technical scheme disclosed in this embodiment, when the sender acquires communication data to be sent, a third random factor is generated, and the communication data is sent to the receiver according to the third random factor. Therefore, by limiting the time interval of sending data by the sender and the receiver, the sending time of each party is staggered with great probability, the data interference in the data transmission process is avoided, and the reliability of data transmission is improved.
In another embodiment, as shown in fig. 4, based on the embodiment shown in any one of fig. 2 to fig. 3, the data transmission method includes the following steps:
step S21, when the receiver receives the communication data sent by the sender, judging whether the current time slot is the time slot of the receiver;
and step S22, when the current time slot is the time slot of the receiving party, response information is returned to the sending party.
In the prior art, a sender sends communication data to a receiver, and the receiver sends response information to the sender after receiving the communication data. In this embodiment, a time slot of a sender and a time slot of a receiver are defined, where the time slot of the sender refers to that only the sender sends data in the time slot, and the time slot of the receiver refers to that only the receiver sends data in the time slot, so that sending time of each party is staggered, and the situation that the sender and the receiver occupy the same frequency band resource is avoided.
The sender and the receiver constitute a communication system that is applicable to various scenarios, such as communication between a sensor and a host, communication between a plurality of home appliances, communication between a control device and a home appliance, and the like.
The time slot of the sender and the time slot of the receiver may be the same or different, and optionally, as shown in fig. 5, both the time slot of the sender and the time slot of the receiver are 100ms.
As shown in fig. 5, the arrangement of the time slots of the transmitting side and the receiving side may be: one sender time slot is followed by one receiver time slot, and one receiver time slot is followed by one sender time slot.
In the time slot of the sending party and the time slot of the receiving party, the sending times can be set according to practical application, and optionally, the sending times in the time slot of the sending party and the time slot of the receiving party are respectively 3 times.
Further, in the same time slot of the sender or the same time slot of the receiver, the time interval between the sending times is determined by a random factor, the random factor is generated by the sender or the receiver, in the time slot of the sender, the sender generates a first random factor, and in the time slot of the receiver, the receiver generates a second random number factor. The step of sending the communication data to the receiver when the current time slot is the time slot of the sender comprises: when the current time slot is the time slot of the sender, generating a first random factor; and sending the communication data to the receiver in the time slot of the sender according to the first random factor, wherein the receiver generates a second random factor when receiving the communication data, and returns the response information to the sender in the time slot of the receiver according to the second random factor.
The generation mode of the random factor can be set according to practical application. Optionally, taking a time slot of a sending party as an example, setting the time slot of the sending party as T, where the sending times in the time slot is 3 times, and the time consumed for sending data each time is N, then the first random factor generated for the first time is: x1= T-3*N, the first random factor generated for the second time is: x2= T-2*N-X1, the first random factor generated for the third time is: x3= T-X1-X2.
If there are multiple sending parties initiating transmission at the same time, multiple sending parties and receiving parties may overlap in sending data, so as to interfere with each other. And, through the inspection of the practical application system, at least once retransmission data is not interfered in a large probability, and the reliability of data transmission is ensured. Namely, under the scene that a plurality of sensors simultaneously acquire signals for data transmission, a receiving party can also respectively receive the signals of the sensors and make correct response.
After the step of sending the communication data to the receiver when the current time slot is the time slot of the sender, the method further includes: when the response information returned by the receiver is not received within the preset time length, judging whether the current time slot is the time slot of the sender; and when the current time slot is the time slot of the sender, sending the communication data to the receiver again, wherein the preset time length is less than or equal to the time slot of the receiver. For example, the sender sends communication data to the receiver in the time slot of the sender, and if no response is received when the time slot of the next sender arrives, the sender determines that packet is lost, and resends the communication data to the receiver.
In the technical scheme disclosed in this embodiment, when the receiver receives the communication data sent by the sender and the current time slot is the time slot of the receiver, the response information is returned to the sender, so that the sending time of each party is staggered by limiting the time slots of the sender and the receiver, the data interference in the data transmission process is avoided, and the reliability of data transmission is improved.
In a further embodiment, based on the embodiment shown in any one of fig. 2 to fig. 4, the data transmission method further includes:
and the receiver generates a fourth random factor when receiving the communication data, and returns the response information to the sender according to the fourth random factor.
In the prior art, a sender sends communication data to a receiver, and the receiver sends response information to the sender after receiving the communication data. In this embodiment, the time interval between the transmission of data by the transmission side and the reception side is limited, and the transmission times of the respective sides are greatly staggered with a probability.
The time interval of sending data by the sender and the receiver is determined by a random factor, the random factor is generated by the sender or the receiver, the sender generates a third random factor, the communication data is sent to the receiver according to the third random factor, the receiver generates a fourth random number factor, response information is returned to the sender according to the fourth random factor, and the third random factor and the fourth random factor can be the same or different.
The generation mode of the random factor can be set according to practical application. Optionally, for example, a time slot is taken as an example, the time slot is set to be t, the number of times of transmission in the time slot is 3, and the time consumed for transmitting data each time is n, then the fourth random factor generated for the first time is: x1= t-3*n, and the fourth random factor generated for the second time is: x2= t-2*n-x1, and the fourth random factor generated for the third time is: x3= t-x1-x2.
In the technical solution disclosed in this embodiment, when receiving communication data, the receiving side generates a second random factor, and returns response information to the sending side according to the second random factor. Therefore, by limiting the time interval for sending data by the sender and the receiver, the sending time of each party is staggered with great probability, data interference in the data transmission process is avoided, and the reliability of data transmission is improved.
The invention also provides a sending device, which comprises a memory, a processor and a data transmission program stored on the memory and capable of running on the processor, wherein the data transmission program is configured to realize the steps of the data transmission method under the execution main body of the sending device.
The invention also provides a receiving device, which comprises a memory, a processor and a data transmission program which is stored on the memory and can run on the processor, wherein the data transmission program is configured to realize the steps of the data transmission method under the execution main body of the receiving device.
An embodiment of the present invention further provides a computer-readable storage medium, where a data transmission program is stored on the computer-readable storage medium, and the data transmission program is executed by a processor to implement the data transmission method mainly executed by the sending apparatus or the receiving apparatus.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. 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 (e.g., ROM/RAM, magnetic disk, optical disk) as described above and includes instructions for enabling a terminal device (e.g., a television, a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.