CN111342945A - Master-slave communication method and device - Google Patents
Master-slave communication method and device Download PDFInfo
- Publication number
- CN111342945A CN111342945A CN202010102451.1A CN202010102451A CN111342945A CN 111342945 A CN111342945 A CN 111342945A CN 202010102451 A CN202010102451 A CN 202010102451A CN 111342945 A CN111342945 A CN 111342945A
- Authority
- CN
- China
- Prior art keywords
- slave
- data packet
- time interval
- sent
- preset time
- 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
Links
- 238000000034 method Methods 0.000 title claims abstract description 47
- 230000006854 communication Effects 0.000 title claims abstract description 44
- 238000004891 communication Methods 0.000 title claims abstract description 43
- 230000001360 synchronised effect Effects 0.000 claims abstract description 134
- 230000004048 modification Effects 0.000 claims description 25
- 238000012986 modification Methods 0.000 claims description 25
- 230000008859 change Effects 0.000 claims description 17
- 238000001514 detection method Methods 0.000 claims description 4
- 230000003993 interaction Effects 0.000 abstract description 13
- 238000010586 diagram Methods 0.000 description 12
- 230000005540 biological transmission Effects 0.000 description 10
- 230000006870 function Effects 0.000 description 6
- 238000009529 body temperature measurement Methods 0.000 description 4
- 238000012545 processing Methods 0.000 description 4
- 230000000875 corresponding effect Effects 0.000 description 3
- 230000008878 coupling Effects 0.000 description 3
- 238000010168 coupling process Methods 0.000 description 3
- 238000005859 coupling reaction Methods 0.000 description 3
- 230000008569 process Effects 0.000 description 3
- 101100368149 Mus musculus Sync gene Proteins 0.000 description 2
- 238000005259 measurement Methods 0.000 description 2
- 230000003044 adaptive effect Effects 0.000 description 1
- 238000012790 confirmation Methods 0.000 description 1
- 230000001186 cumulative effect Effects 0.000 description 1
- 230000007423 decrease Effects 0.000 description 1
- 238000011161 development Methods 0.000 description 1
- 230000002452 interceptive effect Effects 0.000 description 1
- 230000007246 mechanism Effects 0.000 description 1
- 230000003287 optical effect Effects 0.000 description 1
- 238000004904 shortening Methods 0.000 description 1
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L5/00—Arrangements affording multiple use of the transmission path
- H04L5/003—Arrangements for allocating sub-channels of the transmission path
- H04L5/0078—Timing of allocation
- H04L5/0082—Timing of allocation at predetermined intervals
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L5/00—Arrangements affording multiple use of the transmission path
- H04L5/003—Arrangements for allocating sub-channels of the transmission path
- H04L5/0053—Allocation of signaling, i.e. of overhead other than pilot signals
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L5/00—Arrangements affording multiple use of the transmission path
- H04L5/003—Arrangements for allocating sub-channels of the transmission path
- H04L5/0078—Timing of allocation
- H04L5/0087—Timing of allocation when data requirements change
Landscapes
- Engineering & Computer Science (AREA)
- Signal Processing (AREA)
- Computer Networks & Wireless Communication (AREA)
- Data Exchanges In Wide-Area Networks (AREA)
Abstract
The embodiment of the application discloses a master-slave communication method and a master-slave communication device, which are used for data packet interaction between a master machine and a slave machine. The method in the embodiment of the application comprises the following steps: the method comprises the steps that a main host determines a first preset time interval for sending a synchronous data packet; the master machine sends a synchronous data packet to the slave machine according to the first preset time interval; the master machine receives a return packet of the synchronous data packet sent by the slave machine; after receiving a packet back of the synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval, wherein the second preset time interval is smaller than the first preset time interval; and if the host receives a new data packet within the second preset time interval, determining that the new data packet is an asynchronous data packet.
Description
Technical Field
The embodiment of the application relates to the field of communication, in particular to a master-slave communication method and device.
Background
With the diversified development of electronic products, the functions of the electronic products are continuously increased, and higher requirements are put forward on hardware systems. In the current electronic products, a plurality of microprocessors are often required to be installed for cooperation, so that operations with more expansibility can be performed.
In the communication process of a plurality of microprocessors, the processors are generally divided into a master processor and a slave processor, which are also called a master and a slave. Two communication modes of synchronous data interaction and asynchronous data interaction exist between the host and the slave. Synchronous data interaction means that when a host needs to send an instruction or data to a slave, a synchronous data packet is sent, the slave receives the synchronous data packet and then analyzes and makes a corresponding action, the host does not act at the moment, the slave waits for the slave to quickly return to a loopback packet, and the host sends the next synchronous data packet after receiving the loopback packet of the slave. If the slave machine can reply the processing result after a period of time for the command issued by the host machine, the slave machine can send the processing result to the host machine in the form of an asynchronous data packet after a period of time; if the slave needs to actively send some data to the slave, the slave will also actively send to the master in the form of asynchronous packets, and the master cannot determine when the slave sends an asynchronous packet.
In the existing mechanism, when the master sends a synchronous data packet to the slave, the slave also quickly returns a packet of the synchronous data packet. If the slave sends an asynchronous data packet immediately after the master sends a synchronous data packet and then sends a packet back of the synchronous data packet, the master cannot confirm whether the received data packet is the asynchronous data packet, the data packet is checked to be wrong, the two sides need to send the data packet again, and normal communication between the master and the slave is affected.
Disclosure of Invention
The embodiment of the application provides a master-slave communication method, which can overcome the problem that data packets need to be retransmitted due to error check in master-slave communication.
A first aspect of the present application provides a master-slave communication method, applied to a host, including:
the host determines a first preset time interval for sending the synchronous data packet;
the master machine sends a synchronous data packet to the slave machine according to the first preset time interval;
the master machine receives a return packet of the synchronous data packet sent by the slave machine;
after receiving a packet back of the synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval, wherein the second preset time interval is smaller than the first preset time interval;
and if the host receives a new data packet within the second preset time interval, determining that the new data packet is an asynchronous data packet. Based on the first aspect, an embodiment of the present application further provides a first implementation manner of the first aspect:
the method also comprises the following steps:
the host counts the number of the synchronous data packets to be sent;
the host judges whether the first preset time interval needs to be shortened or not according to the number of the synchronous data packets to be sent;
and if so, the host modifies the first preset time interval according to the number of the synchronous data packets to be sent.
Based on the first aspect or the first implementation manner of the first aspect, embodiments of the present application further provide a second implementation manner of the first aspect:
the method also comprises the following steps:
the host receives a modification request sent by the slave, wherein the modification request is generated when the slave monitors that the data quantity change condition of the asynchronous data packet to be sent meets a preset condition;
and the host modifies the first preset time interval according to the modification request.
Based on the first aspect or the first implementation manner of the first aspect, embodiments of the present application further provide a third implementation manner of the first aspect:
the method also comprises the following steps:
the host receives the quantity information of the asynchronous data packets to be sent by the slave;
the host judges whether the first preset time interval needs to be shortened or not according to the number of the asynchronous data packets to be sent;
and if so, the host modifies the first preset time interval according to the number of the asynchronous data packets to be sent.
Based on the first aspect, or the first implementation manner of the first aspect, or the second implementation manner of the first aspect, the present application provides an example of a third implementation manner of the first aspect:
the method also comprises the following steps:
and the master machine sends the back packet of the asynchronous data packet to the slave machine, and the back packet of the asynchronous data packet is used for informing the slave machine that the asynchronous data packet is successfully sent.
A second aspect of the present application provides a master-slave communication method, applied to a slave, including:
the slave machine obtains an asynchronous data packet to be sent;
the slave machine receives a synchronous data packet sent by the host machine;
the slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
and the slave machine sends the asynchronous data packet to the host machine within a second preset time interval after sending the return packet of the synchronous data packet.
Based on the second aspect, the embodiments of the present application further provide a first implementation manner of the second aspect:
after the slave sends the packet return, the method further includes:
the slave machine acquires a first preset time interval;
the slave computer counts the number of the asynchronous data packets to be sent;
the slave machine judges whether the first preset time interval needs to be shortened or not according to the number of the asynchronous data packets to be sent;
if necessary; and the slave machine sends a modification request to the master machine, wherein the modification request is used for modifying the first preset time interval.
Based on the second aspect or the first implementation manner of the second aspect, the present application provides a second implementation manner of the second aspect:
the method also comprises the following steps:
the slave computer counts the number of the asynchronous data packets to be sent;
and the slave machine sends the quantity information of the asynchronous data packets to be sent to the host machine so that the host machine modifies the first time interval according to the quantity information of the asynchronous data packets to be sent.
Based on the second aspect, or the first implementation manner of the second aspect, or the second implementation manner of the second aspect, the present application also provides a third implementation manner of the second aspect:
after the slave sends the asynchronous data packet to the master, the method further includes:
the slave machine receives a back packet of the asynchronous data packet sent by the master machine;
and the slave machine confirms that the asynchronous data packet is successfully sent.
The third aspect of the present application further provides a host, including:
a determining unit, configured to determine a first preset time interval for sending a synchronization packet;
the sending unit is used for sending a synchronous data packet to the slave according to the first preset time interval;
the receiving unit is used for receiving the return packet of the synchronous data packet sent by the slave by the master;
the sending unit is further configured to detect whether a new data packet sent by the slave is received within a second preset time interval after receiving a packet return of the synchronous data packet sent by the slave, where the second preset time interval is smaller than the first preset time interval;
the determining unit is further configured to determine that a new data packet is an asynchronous data packet when the host receives the new data packet within the second preset time interval.
Based on the third aspect of the present application, in the first implementation manner of the third aspect of the present application, the host further includes:
the statistical unit is used for counting the number of synchronous data packets to be sent;
a determining unit, configured to determine whether the first preset time interval needs to be shortened according to the number of the synchronous data packets to be sent;
and the modifying unit is used for modifying the first preset time interval according to the number of the synchronous data packets to be sent.
Preferably, the receiving unit is further configured to receive a modification request sent by the slave, where the modification request is generated when the slave monitors that a change condition of a data amount of an asynchronous data packet to be sent meets a preset condition;
the host further comprises a modification unit for modifying the first preset time interval according to the modification request.
Preferably, the receiving unit is further configured to receive quantity information of the asynchronous data packets to be sent, which are sent by the slave;
the host further comprises a judging unit, which is used for judging whether the first preset time interval needs to be shortened according to the number of the asynchronous data packets to be sent;
and the modifying unit is used for modifying the first preset time interval according to the number of the asynchronous data packets to be sent when the judging unit end is yes.
Preferably, the sending unit is further configured to send a back packet of the asynchronous data packet to the slave, where the back packet of the asynchronous data packet is used to inform the slave that the asynchronous data packet is successfully sent.
The fourth aspect of the present application further provides a slave, including:
the device comprises an acquisition unit, a sending unit and a receiving unit, wherein the acquisition unit is used for acquiring an asynchronous data packet to be sent;
the receiving unit is used for receiving the synchronous data packet sent by the host;
the sending unit is used for sending the return packet of the synchronous data packet to the host according to a first preset time interval;
the sending unit is further configured to send the asynchronous data packet to the host within a second preset time interval after sending the return packet of the synchronous data packet.
Preferably, the acquiring unit is further configured to acquire a first preset time interval;
the slave machine also comprises a counting unit used for counting the number of the asynchronous data packets to be sent;
the slave machine further comprises a judging unit, which is used for judging whether the first preset time interval needs to be shortened according to the number of the asynchronous data packets to be sent;
the sending unit is further configured to send a modification request to the host when the determining unit determines that the time interval is greater than the first preset time interval, where the modification request is used to modify the first preset time interval.
Preferably, the receiving unit is further configured to receive a loopback packet of the asynchronous data packet sent by the master from the slave;
the slave machine also comprises a confirmation unit used for confirming that the asynchronous data packet is successfully sent.
Preferably, the slave further includes a counting unit, configured to count the number of the asynchronous data packets to be sent;
the sending unit is further configured to send the quantity information of the asynchronous data packets to be sent to a host, so that the host modifies the first preset time interval according to the quantity information of the asynchronous data packets to be sent.
According to the technical scheme, the embodiment of the application has the following advantages: when the slave generates an event and needs to send an asynchronous data packet, the slave firstly keeps the data packet not to be sent, and then sends the asynchronous data packet after the slave sends a return packet of a synchronous data packet, so that the situation that the master receives the asynchronous data packet sent by the slave after sending the synchronous data packet is avoided, the master can clearly distinguish whether the data packet being received is the asynchronous data packet according to the time for receiving the data packet, and the stability of data transmission between the master and the slave is improved.
Drawings
FIG. 1 is a schematic diagram of a network framework for master-slave communications;
fig. 2 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
fig. 3 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
fig. 4 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
fig. 5 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
fig. 6 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
fig. 7 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
FIG. 8 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
fig. 9 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
FIG. 10 is a schematic diagram of an embodiment of a master-slave communication method according to an embodiment of the present application;
FIG. 11 is a schematic diagram of an embodiment of a host according to an embodiment of the present application;
fig. 12 is a schematic diagram of an embodiment of a slave according to an embodiment of the present application.
Detailed Description
The embodiment of the application provides a master-slave communication method and device and provides a concept of a synchronization sequence pair. A synchronization sequence pair at least comprises a master sending a synchronization data packet and a slave sending a return packet of the synchronization data packet. A synchronous sequence pair may also include an asynchronous packet sent by a slave, if any. The period from the beginning of sending a synchronous data packet by the host to the end of sending the next synchronous data packet by the host is defined as the period of a synchronous sequence pair, and the period is the same as the sending interval of the synchronous data packet sent by the host. In the scheme of the embodiment of the application, the host and the slave communicate through the synchronous sequence pairs, and in the period of each synchronous sequence pair, the slave always sends the asynchronous data packet after sending the return packet of the synchronous data packet to the host, so that the host can accurately distinguish the asynchronous data packet.
The embodiment of the present application can be applied to a master-slave communication environment as shown in fig. 1, in which the master and the slave may be separate devices, or may be different microprocessors in the same device, and the master may be connected to one or more slaves. The connection mode between the master and the slave may be a physical line connection or a wireless communication connection. The master sends commands and data to the slaves at regular intervals. The data packet sent from the slave to the master is a synchronous data packet and may be an asynchronous data packet.
Specifically, as shown in fig. 2, the master-slave communication method according to the embodiment of the present application includes:
201. the slave machine obtains an asynchronous data packet to be sent;
the slave retrieves one or more asynchronous data packets, temporarily stores them in memory or other storage, and waits for transmission. The asynchronous data packet sent from the slave to the master may be a result of processing a previous synchronous data packet by the master, or may be a new event generated by the slave, requiring the master to actively report to the slave. The slave generates asynchronous data packets, which are not sent temporarily, but are stored until the asynchronous data packets are received and then are acquired and sent out.
202. The host determines a first preset time interval for sending the synchronous data packet;
the host computer sets an initial first predetermined time interval as the period of a complete synchronization sequence pair. The host determines the transmission interval of each transmission of the sync packet as the period of one sync sequence pair. In each synchronization sequence pair, the host only sends one synchronous data packet and receives at most one asynchronous data packet, and the interval time of each synchronous data packet sent by the host is the same.
203. The master machine sends a synchronous data packet to the slave machine according to a first preset time interval;
the master sends a synchronous data packet to the slave at a first preset time interval of 50ms every 50ms, waits for the slave to reply, and the slave receives the synchronous data packet.
204. The slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
in a cycle of a synchronization sequence pair, after receiving a synchronization data packet sent by a host, the slave correspondingly replies a packet back of the synchronization data packet to the host. Wherein each packet return interval of the slave replies corresponds to the interval of sending the synchronous data packet by the master, and is also 50 ms.
205. The slave machine sends an asynchronous data packet to the host machine within a second preset time interval after sending the back packet of the synchronous data packet;
in a cycle of a synchronous sequence pair, after the slave sends the back packet of the synchronous data packet, the slave sends an asynchronous data packet next to the back packet of the synchronous data packet. The packet return transmission interval of the asynchronous data packet and the synchronous data packet is less than a second preset time interval. The second predetermined time interval should be at least smaller than the first predetermined time interval, but is typically much smaller than the first predetermined time interval, and may be set to 5 ms.
206. After receiving a return packet of a synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval;
in the current mode, if the slave sends an asynchronous data packet, the master receives the asynchronous data packet only after receiving a packet back of the synchronous data packet of the slave in one synchronous sequence pair. And the slave is in a synchronous sequence pair, and the interval between the return packet of the sent synchronous data packet and the asynchronous data packet is less than 5 ms. Therefore, after the host receives the repackage of the synchronous data packet sent by the slave, a detection function is added to detect whether a new data packet is received within a preset time interval after the repackage of the synchronous data packet sent by the slave is received, so as to distinguish the synchronous or asynchronous data packet. And the time size of the detection window set by the host computer is 5ms with reference to a second preset time interval.
207. And if the host receives a new data packet within a second preset time interval, determining the new data packet as an asynchronous data packet.
If the slave does send the asynchronous data packet, the host receives a new data packet within 5ms after receiving the return packet of the synchronous data packet, and the host judges that the data packet is the asynchronous data packet. The host thus clearly recognizes that after sending a synchronous packet, the first received packet is a synchronous packet and the second received packet is an asynchronous packet.
It can be seen that in the master-slave communication method provided in the embodiment of the present application, the slave device fixes the sending time of the asynchronous data packet, and if the slave device needs to send the asynchronous data packet, the slave device always sends the asynchronous data packet after the synchronous packet in one synchronous sequence pair, so that the master device can clearly identify the asynchronous data packet. In a synchronous sequence pair, the situation that the host receives an asynchronous data packet first and then receives a synchronous data packet and then returns the synchronous data packet does not occur, and the host can accurately identify the asynchronous data packet.
The present invention can be applied to half-duplex or full-duplex communication modes, and specific application scenarios can be seen in fig. 3 to 6. In the figure, ack represents a return packet of a synchronous data packet, data represents a synchronous data packet, asyn represents an asynchronous data packet, and null represents no data.
Taking the case that the first preset time interval is 50ms as an example, fig. 3 shows the case that when the present invention is applied in the half-duplex communication mode, the slave computer temporarily has no asynchronous data packet to send; fig. 4 shows the situation where the slave is asynchronous and needs to send data packets when the present invention is applied in the half-duplex communication mode. In half-duplex mode, the master and slave cannot send data packets simultaneously.
Taking the case that the first preset time interval is 50ms as an example, fig. 5 shows the case that when the present invention is applied in the full duplex communication mode, the slave computer temporarily has no asynchronous data packet to send; fig. 6 shows the situation that the slave is asynchronous and needs to send data packets when the present invention is applied in the half-duplex communication mode. In full duplex mode, the master and slave may send data packets simultaneously.
In the above embodiment, the present invention is described by taking only 50ms as the first preset time interval and 5ms as the second preset time interval. According to different requirements of the host and the slave, a larger or smaller value can be set as a first preset time interval and a second preset time interval, but the second preset time interval must be smaller than the first preset time interval, so that the asynchronous data packets sent by the slave can be accurately detected and distinguished after the host receives the return packets of the synchronous data packets.
Preferably, referring to fig. 7, the present application further provides another embodiment, where a function of determining success of sending an asynchronous packet is added to a slave, where the embodiment includes:
701. the slave machine obtains an asynchronous data packet to be sent;
702. the host determines a first preset time interval for sending the synchronous data packet;
703. the master machine sends a synchronous data packet to the slave machine according to a first preset time interval;
704. the slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
705. the slave machine sends an asynchronous data packet to the host machine within a second preset time interval after sending the back packet of the synchronous data packet;
706. after receiving a return packet of a synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval;
707. if the host receives a new data packet within a second preset time interval, determining the new data packet as an asynchronous data packet;
wherein steps 701 to 707 are similar to steps 201 to 207 of the embodiment shown in fig. 2, and are not repeated here.
708. The master sends the back packet of the asynchronous data packet to the slave;
the master can send a corresponding back packet of the asynchronous data packet to the slave after receiving the asynchronous data packet each time, and the slave is informed that the asynchronous data packet is successfully sent.
709. The slave machine confirms that the asynchronous data packet is successfully sent.
And after the slave machine receives the return packet of the asynchronous data packet sent by the host machine, judging that the host machine has successfully received the asynchronous data packet and the asynchronous data packet is successfully sent.
In some cases, the master may need to transmit a large amount of data to the slave through a synchronization packet, and it is difficult to change the size of the packet, so that it is necessary to shorten the transmission frequency. Under the condition that the number of data packets needing to be sent by the host is small, the host and the slave still carry out interaction of interactive data packets at a high frequency, and certain data transmission capacity is wasted. Therefore, the present application further provides another embodiment, which can modify the first preset time interval for sending the synchronous data packet of the master according to the amount of the traffic, thereby adjusting the data packet interaction frequency of the master and the slave and reducing the power consumption.
801. The slave machine obtains an asynchronous data packet to be sent;
the slave retrieves one or more asynchronous data packets, temporarily stores them in memory or other storage, and waits for transmission.
802. The host determines a first preset time interval for sending the synchronous data packet;
803. the master machine sends a synchronous data packet to the slave machine according to a first preset time interval;
804. the slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
805. the slave machine sends an asynchronous data packet to the host machine within a second preset time interval after sending the back packet of the synchronous data packet;
806. after receiving a return packet of a synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval;
807. and if the host receives a new data packet within a second preset time interval, determining the new data packet as an asynchronous data packet.
Steps 801 to 807 are similar to steps 201 to 208 of the embodiment shown in fig. 2, and are not repeated here.
808. The host counts the number of synchronous data packets to be sent;
the master counts the number of isochronous packets that the master needs to send to the slaves during the next period of time.
809. The host judges whether the first preset time interval needs to be modified or not according to the number of the synchronous data packets to be sent;
if more data is required to be sent to the slave machine by the host machine through the synchronous data packets, the number of the synchronous data packets to be sent is larger than a certain larger preset value, or the number of the synchronous data packets required to be sent to the slave machine by the host machine is less than a certain smaller preset value, the host machine judges that the first preset time interval needs to be modified. If the number of the synchronous data packets to be sent by the host computer is moderate and is adaptive to the current sending speed, the first preset time interval is judged not to be required to be modified, and the original master-slave interaction frequency is maintained.
810. If necessary, the first predetermined time interval is modified according to the number of the synchronization packets.
If the host determines that the first predetermined time interval needs to be modified, the host modifies the first predetermined time interval according to the number of the synchronous packets to be transmitted in the next period of time. If the host has more synchronous data packets to be sent next, the host modifies the first preset time interval to a larger value so that the host can send the synchronous data packets to the host at a faster speed. If the number of the synchronous data packets to be sent next by the master is less, the frequency of sending the first synchronous data packet by the master can be properly reduced, so that the master and the slave interact with each other in a lower power consumption mode, and the power consumption of the master and the slave is reduced.
It should be noted that the host should not modify the first preset time interval to an excessively small value, on one hand, the power consumption of the host and the slave is increased and the data packet transmission is more prone to errors when the first preset time interval is excessively small, and on the other hand, the modified first preset time interval of the host should be at least greater than the second preset time interval, so as to ensure that the detection in steps 806 and 807 is performed normally. The master cannot modify the first predetermined time interval to an excessively large value in order to avoid an excessively slow interaction between the master and the slave.
Referring to fig. 9, in a more specific embodiment, taking a temperature measurer as an example, the slave may also implement the function of adjusting the master-slave packet interaction frequency similar to the embodiment shown in fig. 8. In the embodiment, the temperature measuring module is used as a slave machine for collecting temperature data; the main processor is used as a host computer to display the temperature and process various temperature data.
The embodiment comprises the following steps:
901. the slave machine obtains an asynchronous data packet to be sent;
902. the host determines a first preset time interval for sending the synchronous data packet;
903. the master machine sends a synchronous data packet to the slave machine according to a first preset time interval;
904. the slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
905. the slave machine sends an asynchronous data packet to the host machine within a second preset time interval after sending the back packet of the synchronous data packet;
906. after receiving a return packet of a synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval;
907. if the host receives a new data packet within a second preset time interval, determining the new data packet as an asynchronous data packet;
908. the slave computer acquires a first preset time interval;
the temperature measurement module obtains the interval of the synchronous data packet sent by the host at present, and the obtaining mode can be that the host processor informs through the data in the synchronous data packet sent, or the temperature measurement module calculates the interval of the synchronous data packet sent by the host.
909. The slave computer counts the number of asynchronous data packets to be sent;
the slave computer counts the amount of the asynchronous data packets to be sent, and particularly under the condition of temperature measurement, the amount of the asynchronous data packets to be sent can be counted through the speed of temperature change. If the temperature changes rapidly, it is indicated that the temperature measurement module needs to send temperature information to the main processor at a high speed, so that the temperature information obtained by the main processor is more accurate and timely.
910. The slave machine judges whether the first preset time interval needs to be shortened or not according to the number of the asynchronous data packets to be sent;
the temperature measuring module judges whether the first preset time interval needs to be shortened according to the speed of the currently acquired temperature change so as to adjust the sending speed of the asynchronous data packet. If the change speed is adapted to the speed of the current master-slave interaction data packet, the speed of sending the asynchronous data packet from the slave is not needed. If the current temperature change speed is basically unchanged or the change speed is extremely high, the slave machine judges that the first preset time interval needs to be modified.
911. If necessary, the slave sends a modification request to the master.
If the slave machine judges that the current temperature change speed is very high, the slave machine can send a modification request to the host machine according to the temperature change speed, and the host machine is requested to change the first preset time interval. If the temperature change speed is higher than 1 ℃ per second, the slave machine sends a modification request to require shortening a first preset time interval; if the temperature change speed is extremely small, for example, the cumulative temperature change for ten seconds is less than 1 ℃, the slave machine sends a modification request to request the master machine to increase the first preset time interval.
It is understood that the present embodiment uses only the measurement of the temperature change as a specific example to help those skilled in the art understand the present invention. In practical application, according to different application scenarios and specific functions of the slave, different modes can be set for the slave to help the slave to determine the number of asynchronous data packets to be sent in the next period of time. For example, in the case where the light measurement module is used as a slave, it is considered that the faster the light intensity changes, the more data packets will be sent from the slave in the next period of time.
Referring to fig. 10, in another embodiment, the slave may only send the number information of the asynchronous data packets to be sent to the master, and the master determines whether to modify the first predetermined time interval. The embodiment comprises the following steps:
1001. the slave machine obtains an asynchronous data packet to be sent;
1002. the host determines a first preset time interval for sending the synchronous data packet;
1003. the master machine sends a synchronous data packet to the slave machine according to a first preset time interval;
1004. the slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
1005. the slave machine sends an asynchronous data packet to the host machine within a second preset time interval after sending the back packet of the synchronous data packet;
1006. after receiving a return packet of a synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval;
1007. if the host receives a new data packet within a second preset time interval, determining the new data packet as an asynchronous data packet;
steps 1001 to 1007 are similar to steps 201 to 207 of the embodiment shown in fig. 2, and are not described herein again.
1008. The slave computer counts the number of asynchronous data packets to be sent;
the slave machine counts how many asynchronous data packets to be sent currently exist, and generates the quantity information of the asynchronous data packets to be sent according to the quantity information.
1009. The slave computer sends the quantity information of the asynchronous data packets to be sent to the host computer;
the slave machine sends the counted number information of the asynchronous data packets to be sent to the host machine, and the specific sending mode can be that the asynchronous data packets are sent to the host machine through the return packets of the synchronous data packets, or the asynchronous data packets are sent to the host machine through the asynchronous data packets, so that the host machine can know the number of the asynchronous data packets to be sent on the slave machine. If other data interaction modes exist between the master and the slave, the quantity information may also be sent to the master in other modes, which is not limited herein.
1010. The host judges whether the first preset time interval needs to be modified or not according to the number of the asynchronous data packets to be sent;
the host machine knows the number of the asynchronous data packets to be sent on the slave machine according to the received number information of the asynchronous data packets to be sent, judges whether the first preset time interval needs to be modified according to the number of the asynchronous data packets to be sent, and changes the sending frequency of the synchronous data packets of the host machine.
1011. If necessary, the host modifies the first preset time interval according to the number of the asynchronous data packets to be sent;
the host increases or decreases the first preset time interval according to the number of the asynchronous data packets to be sent on the slave to control the speed of sending the asynchronous data packets by the slave. If the slave does not transmit any asynchronous data packet for a long time or the number of asynchronous data packets to be transmitted is small, the host may increase the first preset time interval as appropriate according to the number of asynchronous data packets to be transmitted, so as to reduce the power consumption of the host and the slave. Meanwhile, the master and the slave may have a function of modifying the first preset time interval at the same time, and at this time, the extension of the first preset time interval should be allowed only when the extension of the first preset time interval is required by both the master and the slave. When one of the host or the slave requires to shorten the first preset time interval, the first preset time interval is allowed to be shortened, so that the performance requirement of the host and the slave for data packet interaction is preferentially met, and the speed of the master-slave interaction is ensured.
Referring to fig. 11, an embodiment of the present application further provides a host, including:
a determining unit 1101 configured to determine a first preset time interval for transmitting the synchronization packet;
a sending unit 1102, configured to send a synchronization packet to a slave according to a first preset time interval;
a receiving unit 1103, configured to receive a packet back of a synchronization packet sent from a slave;
the detecting unit 1104 is configured to detect whether a new data packet sent by the slave is received within a second preset time interval after a return packet of a synchronous data packet sent by the slave is received, where the second preset time interval is smaller than the first preset time interval;
the determining unit 1101 is further configured to determine that the new data packet is an asynchronous data packet when the receiving unit receives the new data packet within a second preset time interval.
Preferably, the host may further include: a counting unit 1105, configured to count the number of synchronous data packets to be sent; a determining unit 1106, configured to determine whether to shorten the first preset time interval according to the number of synchronous data packets to be sent; a modifying unit 1107 is configured to modify the first preset time interval according to the number of the synchronization packets to be transmitted.
Preferably, the receiving unit 1103 is further configured to receive information about the number of asynchronous data packets to be sent from the slave;
the host further comprises: a determining unit 1106, configured to determine whether the first preset time interval needs to be shortened according to the number of the asynchronous data packets to be sent;
a modifying unit 1107, configured to modify the first preset time interval according to the number of the to-be-sent asynchronous data packets when the determining unit end is yes.
Preferably, the receiving unit 1103 is further configured to receive a modification request sent by the slave, where the modification request is generated when the slave monitors that a change condition of the data amount of the asynchronous data packet to be sent meets a preset condition; the modification unit 1107 may also be used to modify the request, modifying the first preset time interval.
Preferably, the sending unit 1102 is further configured to send a loopback packet of the asynchronous data packet to the slave, where the loopback packet of the asynchronous data packet is used to inform the slave that the asynchronous data packet is successfully sent.
In this embodiment, the flow executed by each unit in the host is similar to the method flow described in the embodiments shown in fig. 2, fig. 7, fig. 8, or fig. 9, and is not repeated here.
Referring to fig. 12, an embodiment of the present application further provides a slave, including:
an obtaining unit 1201, configured to obtain an asynchronous data packet to be sent;
a receiving unit 1202, configured to receive a synchronization packet sent by a host;
a sending unit 1203, configured to send a packet of the synchronous data packet to the host at a first preset time interval; and sending the asynchronous data packet to the host within a second preset time interval after the back packet of the synchronous data packet is sent.
Preferably, the obtaining unit 1201 is further configured to obtain a first preset time interval; the slave further comprises a counting unit 1204, configured to count the number of asynchronous data packets to be sent; a determining unit 1205, configured to determine whether to shorten the first preset time interval according to the number of the asynchronous data packets to be sent; the sending unit 1203 is further configured to send a modification request to the host, where the modification request is used to modify the first preset time interval.
Preferably, the receiving unit 1202 is further configured to receive a packet of an asynchronous data packet sent by the host; the slave further comprises an acknowledgement unit 1206 for acknowledging the successful transmission of the asynchronous data packet.
Preferably, the slave device further includes a counting unit 1204, configured to count the number of the asynchronous data packets to be sent;
the sending unit 1203 is further configured to send the quantity information of the asynchronous data packets to be sent to a host, so that the host modifies the first preset time interval according to the quantity information of the asynchronous data packets to be sent.
In this embodiment, the flow executed by each unit in the slave is similar to the method flow described in the embodiments shown in fig. 2, fig. 7, fig. 8, or fig. 9, and is not described again here.
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.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
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 application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in 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 application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and various other media capable of storing program codes.
Claims (11)
1. A method of master-slave communication, the method comprising:
the host determines a first preset time interval for sending the synchronous data packet;
the master machine sends a synchronous data packet to the slave machine according to the first preset time interval;
the master machine receives a return packet of the synchronous data packet sent by the slave machine; after receiving a packet back of the synchronous data packet sent by the slave, the host detects whether a new data packet sent by the slave is received within a second preset time interval, wherein the second preset time interval is smaller than the first preset time interval;
and if the host receives a new data packet within the second preset time interval, determining that the new data packet is an asynchronous data packet.
2. The master-slave communication method according to claim 1, further comprising:
the host counts the number of the synchronous data packets to be sent;
the host judges whether the first preset time interval needs to be shortened or not according to the number of the synchronous data packets to be sent;
and if so, the host modifies the first preset time interval according to the number of the synchronous data packets to be sent.
3. The master-slave communication method according to claim 1, further comprising:
the host receives a modification request sent by the slave, wherein the modification request is generated when the slave monitors that the data quantity change condition of the asynchronous data packet to be sent meets a preset condition;
and the host modifies the first preset time interval according to the modification request.
4. The master-slave communication method according to claim 1, further comprising:
the host receives the quantity information of the asynchronous data packets to be sent by the slave;
the host judges whether the first preset time interval needs to be shortened or not according to the number of the asynchronous data packets to be sent;
and if so, the host modifies the first preset time interval according to the number of the asynchronous data packets to be sent.
5. The master-slave communication method according to any one of claims 1 to 4, further comprising:
and the master machine sends the back packet of the asynchronous data packet to the slave machine, and the back packet of the asynchronous data packet is used for informing the slave machine that the asynchronous data packet is successfully sent.
6. A master-slave communication method, comprising:
the slave machine obtains an asynchronous data packet to be sent;
the slave machine receives a synchronous data packet sent by the host machine;
the slave machine sends a return packet of the synchronous data packet to the host machine according to a first preset time interval;
and the slave machine sends the asynchronous data packet to the host machine within a second preset time interval after sending the return packet of the synchronous data packet.
7. The master-slave communication method according to claim 6, further comprising:
the slave machine acquires a first preset time interval;
the slave computer counts the number of the asynchronous data packets to be sent;
the slave machine judges whether the first preset time interval needs to be shortened or not according to the number of the asynchronous data packets to be sent;
if necessary; and the slave machine sends a modification request to the master machine, wherein the modification request is used for modifying the first preset time interval.
8. The master-slave communication method according to claim 6 or 7, wherein after the slave sends the asynchronous data packet to the master, the method further comprises:
the slave machine receives a back packet of the asynchronous data packet sent by the master machine;
and the slave machine confirms that the asynchronous data packet is successfully sent.
9. The master-slave communication method according to claim 6, further comprising:
the slave computer counts the number of the asynchronous data packets to be sent;
and the slave machine sends the quantity information of the asynchronous data packets to be sent to the host machine so that the host machine modifies the first preset time interval according to the quantity information of the asynchronous data packets to be sent.
10. A host, comprising:
a determining unit, configured to determine a first preset time interval for sending a synchronization packet;
the sending unit is used for sending a synchronous data packet to the slave according to the first preset time interval;
a receiving unit, configured to receive a loopback packet of the synchronous data packet sent by the slave;
the detection unit is used for detecting whether a new data packet sent by the slave is received within a second preset time interval after a return packet of the synchronous data packet sent by the slave is received, wherein the second preset time interval is smaller than the first preset time interval;
the determining unit is further configured to determine that a new data packet is an asynchronous data packet when the receiving unit receives the new data packet within the second preset time interval.
11. A slave, comprising:
the device comprises an acquisition unit, a sending unit and a receiving unit, wherein the acquisition unit is used for acquiring an asynchronous data packet to be sent;
the receiving unit is used for receiving the synchronous data packet sent by the host;
the sending unit is used for sending the return packet of the synchronous data packet to the host according to a first preset time interval;
the sending unit is further configured to send the asynchronous data packet to the host within a second preset time interval after sending the return packet of the synchronous data packet.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010102451.1A CN111342945B (en) | 2020-02-19 | 2020-02-19 | Master-slave communication method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202010102451.1A CN111342945B (en) | 2020-02-19 | 2020-02-19 | Master-slave communication method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN111342945A true CN111342945A (en) | 2020-06-26 |
CN111342945B CN111342945B (en) | 2022-09-27 |
Family
ID=71187813
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202010102451.1A Active CN111342945B (en) | 2020-02-19 | 2020-02-19 | Master-slave communication method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN111342945B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113068167A (en) * | 2021-03-17 | 2021-07-02 | 上海物骐微电子有限公司 | High-reliability Bluetooth data transmission system and method |
CN116450555A (en) * | 2023-06-16 | 2023-07-18 | 瀚博创芯半导体(上海)有限公司 | Method and device for communication through serial peripheral interface |
Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101917455A (en) * | 2010-06-23 | 2010-12-15 | 福州星网视易信息系统有限公司 | Method for synchronously ordering songs by a plurality of song-ordering machines in same box |
EP2341411A1 (en) * | 2008-09-02 | 2011-07-06 | ZTE Corporation | Time synchronization method and system for multicore system |
CN103107831A (en) * | 2011-11-11 | 2013-05-15 | 中国科学院声学研究所 | Data two-way transmission method based on 2.4G one-way wireless communication protocol |
US8819161B1 (en) * | 2010-01-18 | 2014-08-26 | Marvell International Ltd. | Auto-syntonization and time-of-day synchronization for master-slave physical layer devices |
CN104615016A (en) * | 2014-12-08 | 2015-05-13 | 广东欧珀移动通信有限公司 | Low-power-consumption Bluetooth technology based host control method and device |
CN104767591A (en) * | 2015-04-29 | 2015-07-08 | 北京奇艺世纪科技有限公司 | Data transmitting method and device |
CN107104867A (en) * | 2017-04-24 | 2017-08-29 | 珠海格力电器股份有限公司 | Communication method of master-slave system and master-slave system |
CN107676987A (en) * | 2017-08-31 | 2018-02-09 | 广东华美骏达电器有限公司 | Fully-automatic thermostatic heater operation's plate communication system |
CN108650296A (en) * | 2018-03-30 | 2018-10-12 | 深圳阿凡达智控有限公司 | The means of communication, device and system |
CN109684410A (en) * | 2018-12-24 | 2019-04-26 | 浙江大华技术股份有限公司 | A kind of system, method and the storage medium of determining master-slave database synchronization delayed time |
CN110691120A (en) * | 2019-09-10 | 2020-01-14 | 威富通科技有限公司 | Timing task state detection method, server and detection system |
-
2020
- 2020-02-19 CN CN202010102451.1A patent/CN111342945B/en active Active
Patent Citations (11)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
EP2341411A1 (en) * | 2008-09-02 | 2011-07-06 | ZTE Corporation | Time synchronization method and system for multicore system |
US8819161B1 (en) * | 2010-01-18 | 2014-08-26 | Marvell International Ltd. | Auto-syntonization and time-of-day synchronization for master-slave physical layer devices |
CN101917455A (en) * | 2010-06-23 | 2010-12-15 | 福州星网视易信息系统有限公司 | Method for synchronously ordering songs by a plurality of song-ordering machines in same box |
CN103107831A (en) * | 2011-11-11 | 2013-05-15 | 中国科学院声学研究所 | Data two-way transmission method based on 2.4G one-way wireless communication protocol |
CN104615016A (en) * | 2014-12-08 | 2015-05-13 | 广东欧珀移动通信有限公司 | Low-power-consumption Bluetooth technology based host control method and device |
CN104767591A (en) * | 2015-04-29 | 2015-07-08 | 北京奇艺世纪科技有限公司 | Data transmitting method and device |
CN107104867A (en) * | 2017-04-24 | 2017-08-29 | 珠海格力电器股份有限公司 | Communication method of master-slave system and master-slave system |
CN107676987A (en) * | 2017-08-31 | 2018-02-09 | 广东华美骏达电器有限公司 | Fully-automatic thermostatic heater operation's plate communication system |
CN108650296A (en) * | 2018-03-30 | 2018-10-12 | 深圳阿凡达智控有限公司 | The means of communication, device and system |
CN109684410A (en) * | 2018-12-24 | 2019-04-26 | 浙江大华技术股份有限公司 | A kind of system, method and the storage medium of determining master-slave database synchronization delayed time |
CN110691120A (en) * | 2019-09-10 | 2020-01-14 | 威富通科技有限公司 | Timing task state detection method, server and detection system |
Non-Patent Citations (4)
Title |
---|
JAMES AWEYA: "Technique for Differential Timing Transfer Over Packet Networks", 《IEEE》 * |
杨朝红等: "基于主从异步复制技术的容灾实时系统研究与实现", 《计算机研究与发展》 * |
陈涛: "机车无线同步操作系统的研究", 《中国优秀硕士学位论文全文数据库工程科技Ⅱ辑》 * |
陈玉花等: "IPTV测试仪网络层测试的设计与实现", 《电子技术应用》 * |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113068167A (en) * | 2021-03-17 | 2021-07-02 | 上海物骐微电子有限公司 | High-reliability Bluetooth data transmission system and method |
CN116450555A (en) * | 2023-06-16 | 2023-07-18 | 瀚博创芯半导体(上海)有限公司 | Method and device for communication through serial peripheral interface |
CN116450555B (en) * | 2023-06-16 | 2023-08-22 | 瀚博创芯半导体(上海)有限公司 | Method and device for communication through serial peripheral interface |
Also Published As
Publication number | Publication date |
---|---|
CN111342945B (en) | 2022-09-27 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN100366029C (en) | Communication controller, host-side controller, communication equipment, communication system and method | |
US4581734A (en) | Multipriority communication system | |
US4677612A (en) | Communication system with subdivided transmission cycles | |
US4570257A (en) | Communication system with slot time error detection | |
EP1681814B1 (en) | Wireless identification protocol with confirmation of successful transmission | |
CN111342945B (en) | Master-slave communication method and device | |
CN109495215B (en) | Communication method, system and device of half-duplex bus and readable storage medium | |
CN105786666B (en) | A kind of fault handling method and system for storage system with multiple controllers | |
Tokoro et al. | Acknowledging ethernet | |
CN109743242A (en) | CAN bus message control system and its control method | |
CN110912805B (en) | Message reading state synchronization method, terminal, server and system | |
CN104852825A (en) | Bus communication test method and system | |
EP2985955A1 (en) | Controller area network (can) device and method for emulating classic can error management | |
KR101334017B1 (en) | Apparatus of checking a validity of message on network for a vehicle and method of thereof | |
CN107947906B (en) | Slave device | |
CN112486112A (en) | EtherCAT master station control system and control method thereof | |
CN114826812B (en) | Implementation method and system for RS485 communication multi-master station | |
CN114007209B (en) | BLE-based data transmission method and device and BLE master device | |
CA2145755C (en) | Communication bus system and station for use in such system | |
CN113556210A (en) | Upper computer and method for establishing communication connection | |
WO1985003826A1 (en) | Multipriority communication system | |
CN114090493B (en) | Data transmission control method based on RS485 bus and related device | |
JP5088003B2 (en) | Communication control device, method and program, and inter-vehicle communication device | |
CN117149678A (en) | RS485 bus arbitration system and method with multiple masters and multiple slaves | |
CN108024350B (en) | Dynamic time allocation method and device |
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 | ||
GR01 | Patent grant | ||
GR01 | Patent grant |