Device synchronization method, apparatus, device, and storage medium
By calculating and transmitting the delay value of the clock module count between the master and slave devices, the device synchronization problem is solved, enabling time-consistent device control and task execution.
Patent Information
- Application Number
- CN202411619570.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-13
- Publication Date
- 2025-12-12
- Estimated Expiration
- 2044-11-13
AI Technical Summary
The lack of a reasonable device synchronization mechanism between the master and slave devices results in the inability to maintain time consistency in device control and task execution.
By acquiring the clock module count values of the master and slave devices, calculating the delay value, and sending it to the slave device to update the slave device's clock module count value, the slave device's time is synchronized with the master device.
It achieves time synchronization between master and slave devices, ensuring time consistency in device control and task execution.
Smart Images

Figure CN119576071B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] Embodiments of the present application relate to the technical field of device communication, and in particular to a device synchronization method and device, apparatus, and storage medium. BACKGROUND
[0002] At present, multi-device collaborative work is increasingly widely applied in various industries. Among them, the multi-device can include a master device and a slave device. For example, the master device needs to control multiple slave devices to work in sequence to ensure smooth and efficient production processes. For another example, the master device needs to work with multiple slave devices at the same time to complete data output in a specific scenario.
[0003] However, in the related art, there is a lack of reasonable device synchronization mechanism between the master device and the slave device, which cannot guarantee the synchronization communication between the devices, and the device control and task execution between the master device and the slave device cannot be kept consistent in time, which needs to be improved. SUMMARY
[0004] Embodiments of the present application provide a device synchronization method, device, apparatus, and storage medium, which solve the problem of lack of reasonable device synchronization mechanism between the master device and the slave device in the related art, which cannot guarantee the synchronization communication between the devices, and the device control and task execution between the master device and the slave device cannot be kept consistent in time, realize the time synchronization between the master device and the slave device, guarantee the synchronization communication between the devices, and make the device control and task execution between the master device and the slave device consistent in time.
[0005] In a first aspect, embodiments of the present application provide a device synchronization method applied to a master device, which includes:
[0006] obtaining a first count value currently recorded by a set first clock module, the first clock module starts counting at a preset time interval after the master device is powered on;
[0007] sending a synchronization calibration request to a slave device to make the slave device feedback a confirmation message;
[0008] in the case of receiving the confirmation message, obtaining a second count value currently recorded by the first clock module, and calculating a delay value based on the second count value and the first count value;
[0009] sending the second count value and the delay value to the slave device to make the slave device add the second count value and the delay value to obtain a reference count value, and update a count value currently recorded by a set second clock module to the reference count value, the second clock module starts counting at the preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization job based on the reference count value.
[0010] In a second aspect, the embodiments of the present application further provide a device synchronization method, applied to a slave device, the method comprising:
[0011] In a case where the synchronization calibration request sent by the master device is received, a confirmation message is sent to the master device, so that the master device, in a case where the confirmation message is received, acquires a second count value currently recorded by a first clock module, calculates a delay value based on the second count value and a first count value currently recorded by the first clock module when the synchronization calibration request is sent, and sends the second count value and the delay value;
[0012] In a case where the second count value and the delay value sent by the master device are received, the second count value and the delay value are added to obtain a reference count value, and a count value currently recorded by a second clock module set on the slave device is updated to the reference count value, the second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0013] In a third aspect, the embodiments of the present application further provide a device synchronization apparatus, comprising:
[0014] The obtaining module is configured to obtain a first count value currently recorded by a first clock module set, the first clock module starts counting at a preset time interval after the master device is powered on;
[0015] The request sending module is configured to send a synchronization calibration request to a slave device, so that the slave device feeds back a confirmation message;
[0016] The delay calculating module is configured to, in a case where the confirmation message is received, acquire a second count value currently recorded by the first clock module, and calculate a delay value based on the second count value and the first count value;
[0017] The clock synchronization module is configured to send the second count value and the delay value to the slave device, so that the slave device adds the second count value and the delay value to obtain a reference count value, and updates a count value currently recorded by a second clock module set to the reference count value, the second clock module starts counting at the preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0018] In a fourth aspect, the embodiments of the present application further provide a device synchronization apparatus, comprising:
[0019] The confirmation message sending module is configured to, in a case where the synchronization calibration request sent by the master device is received, send a confirmation message to the master device, so that the master device, in a case where the confirmation message is received, acquires a second count value currently recorded by the first clock module, calculates a delay value based on the second count value and a first count value currently recorded by the first clock module when the synchronization calibration request is sent, and sends the second count value and the delay value.
[0020] The clock synchronization module is configured to, in a case where the second count value and the delay value sent by the master device are received, add the second count value and the delay value to obtain a reference count value, and update a count value currently recorded by the second clock module to the reference count value, the second clock module starting to count at a preset time interval after the slave device is powered on, and being used for the slave device to perform a synchronization operation based on the reference count value.
[0021] In a fifth aspect, an electronic device is provided, and the device includes:
[0022] One or more processors;
[0023] A storage device configured to store one or more programs,
[0024] When the one or more programs are executed by the one or more processors, the one or more processors implement the device synchronization method provided in the embodiments of the present application.
[0025] In a sixth aspect, a nonvolatile storage medium storing computer executable instructions is provided, and the computer executable instructions, when executed by a computer processor, are configured to perform the device synchronization method provided in the embodiments of the present application.
[0026] In the embodiment of the present application, the first clock module currently records a first count value by being set, and starts counting according to a preset time interval after the master device is powered on; a synchronization calibration request is sent to the slave device to make the slave device feedback a confirmation message; in the case of receiving the confirmation message, a second count value currently recorded by the first clock module is obtained, and a delay value is calculated based on the second count value and the first count value; the second count value and the delay value are sent to the slave device to make the slave device add the second count value and the delay value to obtain a reference count value, and update a count value currently recorded by the second clock module set as the reference count value, and the second clock module starts counting according to a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value. In the above scheme, the master device can effectively measure the communication delay time between the master device and the slave device by sending the synchronization calibration request to the slave device and subtracting the second count value from the first count value to obtain the delay value in the case of receiving the confirmation message, and the master device can provide the slave device with a reference time and a communication delay time by sending the second count value and the delay value to the slave device, so as to update the reference time of the slave device, complete the time synchronization with the master device, guarantee the synchronization communication between the devices, and perform a synchronization operation based on the reference count value, so that the device control and task execution between the master device and the slave device can be kept consistent in time. BRIEF DESCRIPTION OF DRAWINGS
[0027] Figure 1 A flowchart of a device synchronization method provided by the embodiment of the present application;
[0028] Figure 2 A flowchart of a device synchronization method provided by the embodiment of the present application, which includes a specific process of notifying the slave device to execute a first target task event;
[0029] Figure 3 A flowchart of a device synchronization method provided by the embodiment of the present application, which includes a specific process of issuing a control instruction to the slave device;
[0030] Figure 4 A flowchart of a device synchronization method provided by the embodiment of the present application, which includes a specific process of synchronizing a target data output rate;
[0031] Figure 5 A flowchart of a device synchronization method provided by the embodiment of the present application, which includes a specific process of comparing a delay value with a preset delay threshold;
[0032] Figure 6 A flowchart of another device synchronization method provided by the embodiment of the present application;
[0033] Figure 7A structural block diagram of a device synchronization apparatus provided by an embodiment of the present application is shown in FIG. 1.
[0034] Figure 8 A structural block diagram of another device synchronization apparatus provided by an embodiment of the present application is shown in FIG. 2.
[0035] Figure 9 A structural schematic diagram of an electronic device provided by an embodiment of the present application is shown in FIG. 3. DETAILED DESCRIPTION
[0036] The embodiments of the present application will be further described below in conjunction with the accompanying drawings and embodiments. It can be understood that the specific embodiments described herein are only used to explain the embodiments of the present application, but not to limit the embodiments of the present application. In addition, it should be noted that, for the convenience of description, only the parts related to the embodiments of the present application are shown in the drawings, but not all the structures.
[0037] The terms "first", "second", and the like in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the data used in this way can be exchanged under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than that illustrated or described herein, and the objects distinguished by "first", "second", etc. are usually a class, not limited to the number of objects, for example, the first object can be one or more. In addition, "and / or" in the specification and claims means at least one of the connected objects, and the character " / ", generally represents a "or" relationship between the front and rear associated objects.
[0038] The device synchronization method provided by the embodiments of the present application is used for time synchronization between multiple devices, so that the device control and task execution between the master device and the slave device can be kept time consistent. The specific application scenarios can include industrial automation, smart home, etc. Taking industrial automation as an example, the master device can be a controller, and the slave device can be an executor. The controller can control multiple executors to complete specific actions or operations in sequence. Taking smart home as an example, the master device and the slave device can be a first smart speaker and a second smart speaker matched with each other. The first smart speaker and the second smart speaker can execute the same audio output at the same time node. Of course, the foregoing several application scenarios are only exemplary and explanatory, and in actual application, the device synchronization method can also be used in device synchronization in other scenarios, and the embodiments of the present application do not limit this. The present application aims to provide a device synchronization method, to solve the problem that in the related art, there is a lack of reasonable device synchronization mechanism between the master device and the slave device, which cannot guarantee the synchronization communication between the devices, and the device control and task execution between the master device and the slave device cannot be kept time consistent.
[0039] The execution subject of each step of the device synchronization method provided in the embodiments of the present application can be a master device, which refers to an electronic device with data calculation, processing and storage capabilities and with initiative and control rights in a communication or control system, and can actively initiate a communication request or a control instruction and manage a slave device to complete a corresponding task. The embodiments of the present application do not limit this.
[0040] Figure 1 A flowchart of a device synchronization method provided in the embodiments of the present application is shown in FIG. 1. The device synchronization method can be implemented with a master device as an execution subject. As shown in FIG. 1, the device synchronization method specifically includes the following steps. Figure 1
[0041] Step S101: Obtain a first count value currently recorded by a first clock module. The first clock module starts counting at a preset time interval after the master device is powered on.
[0042] The first clock module is arranged in the master device and starts counting at a preset time interval after the master device is powered on, and is used to provide a real-time reference time of the master device after the master device is powered on. For example, the preset time interval is 1 microsecond, the first clock module starts counting after the master device is powered on, if the first count value currently recorded by the first clock module is 1000, the current reference time of the master device is 1 millisecond, if the second count value currently recorded by the first clock module is 2000, the current reference time of the master device is 2 milliseconds. It can be understood that the current reference time is the time accumulated with respect to the initial time of the master device being powered on. Of course, the value of the specific preset time interval can be adaptively set by a developer according to the time accuracy requirement of an actual application scenario, which is not limited herein.
[0043] Step S102: Send a synchronization calibration request to a slave device, so that the slave device feeds back a confirmation message.
[0044] After the master device and the slave device are connected based on a device communication protocol, the master device can send a synchronization calibration request to the slave device, to inform the slave device to perform time synchronization calibration. The synchronization calibration request can include a slave device identifier and a synchronization calibration identifier. Optionally, the number of slave devices can be one or more. After receiving the synchronization calibration request, the slave device can feed back a confirmation message to the master device, to respond to the synchronization calibration request sent by the master device, which is equivalent to informing the master device to enter a synchronization calibration phase.
[0045] Step S103: In the case of receiving the confirmation message, obtain a second count value currently recorded by the first clock module, and calculate a delay value based on the second count value and the first count value.
[0046] If the master device receives the confirmation message, it can be considered that the slave device enters the synchronization calibration phase normally. By obtaining the second count value recorded by the first clock module at present, the master device can obtain the current reference time when the confirmation message is received, and combine the corresponding first count value when the synchronization calibration request is sent to calculate the delay value of the communication between the master device and the slave device. For example, the preset time interval is 1 microsecond, the first count value is 2000, and the second count value is 7000. The interval value 5000 can be obtained by subtracting the first count value from the second count value, which is equivalent to the time interval of 5 milliseconds from the master device sending the synchronization calibration request to the slave device feeding back the confirmation message. Considering that the time interval is the bidirectional transmission process of information between the master device and the slave device, the interval value can be divided by 2 to obtain the delay value 2500, which is used to estimate the delay time from the master device starting to send the synchronization calibration request to the slave device receiving the synchronization calibration request, i.e. 2.5 milliseconds. Thus, based on the delay value calculated based on the second count value and the first count value, the communication delay between the master device and the slave device can be reasonably determined. Optionally, in the case that the number of slave devices is multiple, the master device can obtain different second count values according to the confirmation messages fed back by each slave device, and calculate the delay value corresponding to each slave device based on the second count value and the first count value corresponding to each slave device.
[0047] In step S104, the second count value and the delay value are sent to the slave device, so that the slave device adds the second count value and the delay value to obtain a reference count value, and updates the count value recorded by the second clock module at present as the reference count value. The second clock module starts counting according to the preset time interval after the slave device is powered on, and is used for the slave device to perform synchronization work based on the reference count value.
[0048] In the initialization phase of the device, due to the difference in the boot-up time of the master device and the slave device, the slave device may be powered on earlier than the master device or the master device may be powered on earlier than the slave device, so that the counting of the first clock module and the second clock module may be out of synchronization, causing the real-time reference time of the two to be different, so that the device control and task execution between the master device and the slave device cannot be kept in time. For example, the current counting value of the first clock module built-in the master device is a1, and the current counting value of the second clock module built-in the slave device is a2, if they agree to execute the same task at the counting value a3, due to the difference between a3-a2 and a3-a1, the master device and the slave device execute the task at different times, which may cause an abnormal situation of out-of-synchronization. Therefore, the master device can send the second counting value and the delay value to the slave device, which is used to adjust the real-time reference time between the two devices to be synchronized. It is worth noting that the second counting value represents the data sending time of the master device, that is, the current reference time when the master device sends data, and the delay value represents the delay time of the data sent by the master device to reach the slave device. The reference counting value obtained by adding the second counting value and the delay value represents the current reference time of the master device when the data reaches the slave device, so that the slave device updates the currently recorded counting value of the second clock module to the reference counting value, which is equivalent to adjusting to the same reference time as the master device. The second clock module is set in the slave device and starts counting at the same preset time interval as the master device after the slave device is powered on, which is used to provide the real-time reference time of the device after the slave device is powered on. The first clock module and the second clock module keep the same preset time interval for counting, which can eliminate the counting error caused by the difference in the preset time interval, guarantee the consistency of the counting time granularity, and is conducive to the synchronization of the devices. For example, the second counting value obtained by the master device is b1, the corresponding current reference time is t1, and the calculated delay value is d1. The master device sends the second counting value and the delay value to the slave device at the current reference time t1, so that the current counting value of the master device should be updated to b1+d1 and the corresponding current reference time is t2 when the slave device receives the second counting value and the delay value due to the communication delay. Then, the slave device can obtain the reference counting value b1+d1 by adding the received second counting value and the delay value, which is consistent with the current counting value of the master device, so that the slave device can update the currently recorded counting value of the second clock module to the reference counting value b1+d1, which is equivalent to changing its current reference time to t2, keeping consistent with the master device, achieving the purpose of time synchronization. Optionally, in the case of multiple slave devices, the master device can send the corresponding second counting value and delay value to each slave device, so that multiple slave devices can update the currently recorded counting value of the second clock module to the reference counting value, keeping the reference time consistent with the master device.
[0049] The first clock module starts counting at a preset time interval after the master device is powered on, and the first count value recorded by the first clock module is obtained. A synchronization calibration request is sent to the slave device to enable the slave device to feed back a confirmation message. When the confirmation message is received, the second count value recorded by the first clock module is obtained, and the delay value is calculated based on the second count value and the first count value. The second count value and the delay value are sent to the slave device to enable the slave device to add the second count value and the delay value to obtain a reference count value, and the count value recorded by the second clock module is updated to the reference count value. The second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value. In the scheme, the master device can effectively measure the communication delay time between the master device and the slave device by sending the synchronization calibration request to the slave device and subtracting the second count value from the first count value to obtain the delay value when the confirmation message is received. The master device can provide the slave device with the reference time and the communication delay time by sending the second count value and the delay value to the slave device, so that the slave device can update the reference time, complete the time synchronization with the master device, ensure the synchronization communication between the devices, and perform the synchronization operation based on the reference count value, so that the device control and task execution between the master device and the slave device can be kept consistent in time.
[0050] Figure 2 A flowchart of a device synchronization method provided by the embodiment of the application and containing a specific process of notifying the slave device to execute the first target task event is shown in FIG. 2. Figure 2 The device synchronization method specifically includes the following steps.
[0051] In step S201, the first count value recorded by the first clock module is obtained. The first clock module starts counting at a preset time interval after the master device is powered on.
[0052] In step S202, a synchronization calibration request is sent to the slave device to enable the slave device to feed back a confirmation message.
[0053] In step S203, when the confirmation message is received, the second count value recorded by the first clock module is obtained, and the delay value is calculated based on the second count value and the first count value.
[0054] In step S204, the second count value and the delay value are sent to the slave device to enable the slave device to add the second count value and the delay value to obtain a reference count value, and the count value recorded by the second clock module is updated to the reference count value. The second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0055] Step S205, in the case of receiving the first target task information sent by the external terminal, a third count value currently recorded by the first clock module is obtained, and the first target task information includes a first target task event and a first execution waiting time.
[0056] The external terminal can be a host computer, a user terminal, or a background server connected to the master device, which can issue a target task to the master device. If the master device receives the first target task information sent by the external terminal, the third count value currently recorded by the first clock module can be obtained, which is equivalent to determining the current reference time when the first target task information is received. The first target task event can be a specific action or data output operation that the master device and the slave device need to execute simultaneously, for example, the master device and the slave device are a paired car audio, which needs to play the same audio simultaneously, and for example, the master device and the slave device are an advertising screen, which needs to play the same video synchronously. The first execution waiting time can be the buffering time before the execution of the first target task event, for example, the first execution waiting time is 5 minutes, which can be regarded as the master device and the slave device both need to wait for 5 minutes after the current reference time to execute the first target task event.
[0057] Step S206, determining a first target count value according to the first execution waiting time, the preset time interval, and the third count value.
[0058] In one embodiment, the specific implementation steps of determining the first target count value according to the first execution waiting time, the preset time interval, and the third count value are as follows:
[0059] Converting the first execution waiting time into a first incremental count value based on the preset time interval;
[0060] Adding the first incremental count value and the third count value to obtain the first target count value.
[0061] Since the master device determines the current reference time through the count value of the first clock module, the first execution waiting time needs to be converted into a count value form, and the target count value is calculated. Specifically, the preset time interval is the unit time required for the count value to increase by 1, so the number of preset time intervals contained in the first execution waiting time can be determined, and then the first incremental count value is determined, and the first incremental count value is added to the third count value to obtain the first target count value, which can represent the target reference time of executing the first target task event.
[0062] In one specific embodiment, the first execution waiting time is the same as the time unit of the preset time interval, and the first increment count value can be obtained by dividing the first execution waiting time by the preset time interval. For example, the first execution waiting time is 20 microseconds, the preset time interval is 2 microseconds, and the third count value is 100. Then, the first increment count value can be calculated as 20 ÷ 2 = 10, and the first target count value is 100 + 10 = 110, which means that the master device or the slave device needs to execute the first target task event when the clock module counts to 110.
[0063] In another specific embodiment, the time unit of the first execution waiting time is different from that of the preset time interval. The first execution waiting time needs to be converted into the time unit of the preset time interval first, and then the first increment count value can be obtained by dividing the converted first execution waiting time by the preset time interval. For example, the first execution waiting time is 2 milliseconds, the preset time interval is 2 microseconds, and the third count value is 1000. Then, the converted first execution waiting time is 2000 microseconds, and the first increment count value can be calculated as 2000 ÷ 2 = 1000. Thus, the first target count value is 1000 + 1000 = 2000, which means that the master device or the slave device needs to execute the first target task event when the clock module counts to 2000.
[0064] In step S207, the first target task event and the first target count value are sent to the slave device, so that the slave device executes the first target task event when the second clock module counts to the first target count value.
[0065] Since the master device and the slave device complete time synchronization through steps 201-204, the real-time count values of the first clock module and the second clock module are consistent. Therefore, for the master device and the slave device, the first target count value corresponds to the same target reference time, and there is no deviation in task execution time.
[0066] As described above, the master device determines the first target count value according to the first execution waiting time, the preset time interval, and the third count value, which can accurately convert the first execution waiting time into a count value representing the reference time after the time synchronization is completed. By sending the first target task event and the first target count value to the slave device, the slave device can execute the first target task event after the first execution waiting time, which is beneficial to the synchronous execution of the first target task event by the master device and the slave device.
[0067] Figure 3 A flowchart of a device synchronization method according to an embodiment of the present application is shown in FIG. 1, which includes the following steps: Figure 3
[0068] In step S301, a first count value currently recorded by a first clock module is obtained. The first clock module starts counting at a preset time interval after the master device is powered on.
[0069] In step S302, a synchronization calibration request is sent to the slave device, so that the slave device feeds back a confirmation message.
[0070] In step S303, in a case where the confirmation message is received, a second count value currently recorded by the first clock module is obtained, and a delay value is calculated based on the second count value and the first count value.
[0071] In step S304, the second count value and the delay value are sent to the slave device, so that the slave device adds the second count value and the delay value to obtain a reference count value, and updates a count value currently recorded by a second clock module as the reference count value. The second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0072] In step S305, in a case where the second target task information sent by the external terminal is received, a fourth count value currently recorded by the first clock module is obtained. The second target task information includes a second target task event and a second execution waiting time.
[0073] If the master device receives the second target task information sent by the external terminal, the fourth count value currently recorded by the first clock module can be obtained, which is equivalent to determining the current reference time when the second target task information is received. The second target task event can be that the master device needs to control the slave device to perform a specific action or operation. For example, the master device is a controller, the slave device is a mechanical arm, and the master device needs to issue a control instruction at a specific time to control the mechanical arm to move. The second execution waiting time can be a buffer time before the execution of the second target task event. For example, the second execution waiting time is 1 minute, which can be regarded as that the master device needs to wait for 1 minute after the current reference time to send a control instruction corresponding to the second target task event to the slave device.
[0074] In step S306, a control instruction corresponding to the slave device is generated according to the second target task event, and a second target count value is determined according to the second execution waiting time, the preset time interval, the delay value, and the fourth count value.
[0075] The master device can generate the control instruction corresponding to the slave device according to the second target task event. The control instruction is control information recognizable by the slave device, and is used to notify the slave device to perform a specific action or operation.
[0076] In one embodiment, the specific implementation steps of determining the second target count value according to the second execution waiting time, the preset time interval, the delay value, and the fourth count value are as follows:
[0077] convert the second execution waiting time into a second incremental count value based on a preset time interval;
[0078] subtract the second incremental count value from a delay value to obtain a target incremental count value;
[0079] add the target incremental count value to the fourth count value to obtain a second target count value.
[0080] In the example, the second execution waiting time is 50 microseconds, the preset time interval is 1 microsecond, the delay value is 5, and the fourth count value is 100. The second incremental count value is calculated to be 50. If the master device sends the control instruction to the slave device when the count value reaches 100+50=150, the slave device actually receives the control instruction when the count value reaches 150+5=155 due to the communication delay between the master device and the slave device, and a control delay occurs. Thus, after the second incremental count value is calculated, the second incremental count value is subtracted from the delay value to obtain the target incremental count value 45. The second target count value is 100+45=145. The master device sends the control instruction to the slave device when the second target count value 145 is reached. Considering the communication delay, the slave device actually receives the control instruction when the count value reaches 150, which satisfies the requirement that the master device can accurately control the slave device at the time node corresponding to the second execution waiting time (50 microseconds).
[0081] In a specific embodiment, the second execution waiting time is the same as the time unit of the preset time interval, and the second execution waiting time can be divided by the preset time interval to obtain the second incremental count value. In another specific embodiment, the second execution waiting time is not the same as the time unit of the preset time interval, and the second execution waiting time needs to be converted into the time unit first, and then divided by the preset time interval to obtain the second incremental count value.
[0082] Step S307, in the case that the first clock module timing reaches the second target count value, a control instruction is sent to the slave device.
[0083] The master device determines the second target count value according to the second execution waiting time, the preset time interval, the delay value and the fourth count value, which can effectively consider the communication delay of both sides, accurately convert the second execution waiting time into the count value representing the reference time after both sides complete time synchronization, and send a control instruction to the slave device when the second target count value is reached, which can accurately meet the control timing requirements of the target task to control the slave device, and avoid the time deviation of the control effect of the master device on the slave device.
[0084] Figure 4 A flowchart of a device synchronization method provided by the embodiment of the application is shown in FIG. 1, which includes the following steps: Figure 4
[0085] Step S401, a first count value recorded by a first clock module is obtained, and the first clock module starts counting according to a preset time interval after the master device is powered on.
[0086] Step S402, a synchronization calibration request is sent to the slave device to make the slave device feedback a confirmation message.
[0087] Step S403, in the case that the confirmation message is received, a second count value recorded by the first clock module is obtained, and a delay value is calculated based on the second count value and the first count value.
[0088] Step S404, the second count value and the delay value are sent to the slave device to make the slave device add the second count value and the delay value to obtain a reference count value, and update a count value recorded by a second clock module to the reference count value, the second clock module starts counting according to the preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0089] Step S405, a target data output rate is obtained, and the target data output rate is sent to the slave device to make the slave device update a current data output rate to the target data output rate.
[0090] The synchronization calibration process of the master device and the slave device can synchronize the target data output rate in addition to synchronizing the time, so that the master device and the slave device can achieve the purpose of synchronously outputting data. The master device can send the currently set target data output rate to the slave device, so that the slave device can update the currently set data output rate to the target data output rate. Thus, the master device and the slave device can keep the same data output rate for related work. For example, the master device and the slave device can be paired smart speakers. If the audio data output rates of the two are different, the phenomenon of asynchronous music playing will occur, affecting the user experience. Thus, the slave device updates the audio data output rate to the currently set target audio data output rate of the master device, which can ensure that the two perform synchronous music playing. For another example, the master device and the slave device can be smart panels distributed at different positions in the same place and need to play the same promotional video at the same time. If the video data output rates of the two are different, the phenomenon of asynchronous video playing will occur, affecting the promotional effect.
[0091] The master device can keep the data output rate of the slave device consistent with that of itself by sending the target data output rate to the slave device, so as to ensure that the two perform synchronous data output and guarantee the effect of synchronous work.
[0092] Figure 5 A flowchart of a device synchronization method provided by an embodiment of the present application is shown in FIG. 5. The device synchronization method specifically includes the following steps: Figure 5
[0093] Step S501: Obtain a first count value currently recorded by a first clock module. The first clock module starts counting at a preset time interval after the master device is powered on.
[0094] Step S502: Send a synchronization calibration request to the slave device, so that the slave device feeds back a confirmation message.
[0095] Step S503: In the case of receiving the confirmation message, obtain a second count value currently recorded by the first clock module. Calculate a delay value based on the second count value and the first count value.
[0096] Step S504: Compare the delay value with a preset delay threshold.
[0097] If the network condition abnormally fluctuates or the slave device state is abnormal, the master device can calculate a large delay value, which cannot correctly represent the communication delay between the master device and the slave device. If time synchronization is performed based on the delay value, subsequent synchronization operations can be abnormal. Therefore, a preset delay threshold value can be set according to experience data of an actual application scenario. If the delay value is within a range from 0 to the preset delay threshold value, the delay value can be regarded as a normal value. If the delay value is outside the range defined by the preset delay threshold value, the delay value can be regarded as an abnormal value.
[0098] In step S505, if the delay value is greater than or equal to the preset delay threshold value, the master device re-sends the synchronization calibration request to the slave device, so that the slave device re-feeds back the confirmation message.
[0099] If the delay value is greater than or equal to the preset delay threshold value, the delay value can be regarded as abnormal. The master device can attempt to re-send the synchronization calibration request to the slave device, so that the slave device re-feeds back the confirmation message. If the network condition or the slave device state returns to normal, the re-calculated delay value is within the range defined by the preset delay threshold value. The second count value and the delay value can be sent to the slave device. If the network condition or the slave device state cannot return to normal, the calculated delay value is still outside the range defined by the preset delay threshold value. The master device can output an abnormal message to a system background or a user terminal, to remind relevant personnel to perform abnormal troubleshooting.
[0100] In step S506, if the delay value is less than the preset delay threshold value, the second count value and the delay value are sent to the slave device, so that the slave device adds the second count value and the delay value to obtain a reference count value. The count value currently recorded by the set second clock module is updated to the reference count value. The second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform synchronization operations based on the reference count value.
[0101] By comparing the delay value with the preset delay threshold value, it can be determined whether the delay value is within a normal value range. If the delay value is greater than or equal to the preset delay threshold value, the delay value can be regarded as abnormal, and the synchronization calibration request is re-sent to the slave device to re-determine the delay value. If the delay value is less than the preset delay threshold value, the communication delay information of both sides can be calculated normally, to ensure that the slave device accurately performs time synchronization subsequently.
[0102] Figure 6 Another device synchronization method provided by the embodiment of the application is provided. The device synchronization method can be implemented by taking the slave device as an execution subject. As shown in Figure 6 The device synchronization method specifically includes the following steps:
[0103] Step S601, in a case where the synchronization calibration request sent by the master device is received, a confirmation message is sent to the master device, so that the master device, in a case where the confirmation message is received, acquires a second count value currently recorded by the first clock module, calculates a delay value based on the second count value and a first count value currently recorded by the first clock module acquired when the synchronization calibration request is sent, and sends the second count value and the delay value.
[0104] Step S602, in a case where the second count value and the delay value sent by the master device are received, a reference count value is obtained by adding the second count value and the delay value, and a count value currently recorded by the second clock module set is updated as the reference count value. The second clock module starts counting at a preset time interval after the slave device is powered on, and is used for synchronization work based on the reference count value.
[0105] In the above scheme, the slave device can obtain the reference reference time and the communication delay time for device time synchronization by receiving the second count value and the delay value sent by the master device. By updating the count value currently recorded by the second clock module set as the reference count value, the reference reference time of the slave device is updated, the time synchronization with the master device is completed, the synchronization communication between devices is guaranteed, and the subsequent synchronization work based on the reference count value is facilitated, so that the device control and task execution between the master device and the slave device can be kept consistent in time.
[0106] In one embodiment, in a case where the master device sends a synchronization calibration request, the slave device sends a confirmation message to the master device. Figure 6 The embodiment shown provides a device synchronization method, which further includes the following steps:
[0107] In a case where the master device sends a first target task event and a first target count value, the first target task event is executed when the second clock module reaches the first target count value.
[0108] In one embodiment, in a case where the master device sends a synchronization calibration request, the slave device sends a confirmation message to the master device. Figure 6 The embodiment shown provides a device synchronization method, which further includes the following steps:
[0109] In a case where the master device sends a target data output rate, the current set data output rate is updated as the target data output rate.
[0110] Figure 7 A structural block diagram of a device synchronization device provided by an embodiment of the present application is shown. The device is configured to execute the device synchronization method provided by the above-mentioned embodiments, and has the function modules and beneficial effects corresponding to the execution method. As shown in the figure, the device specifically includes: Figure 7
[0111] The acquisition module 101 is configured to acquire a first count value currently recorded by a first clock module set, the first clock module starting counting at a preset time interval after the master device is powered on;
[0112] The request sending module 102 is configured to send a synchronization calibration request to the slave device, so that the slave device feeds back a confirmation message;
[0113] The delay calculation module 103 is configured to acquire a second count value currently recorded by the first clock module in the case that the confirmation message is received, and calculate a delay value based on the second count value and the first count value;
[0114] The clock synchronization module 104 is configured to send the second count value and the delay value to the slave device, so that the slave device adds the second count value and the delay value to obtain a reference count value, and updates a count value currently recorded by a second clock module set to the reference count value, the second clock module starting counting at a preset time interval after the slave device is powered on, and being used for the slave device to perform a synchronization operation based on the reference count value.
[0115] In the above scheme, the master device sends a synchronization calibration request to the slave device, and subtracts the second count value from the first count value to obtain a delay value in the case that the confirmation message is received, so that the communication delay time between the master device and the slave device can be effectively measured. The master device sends the second count value and the delay value to the slave device, so that the slave device can be provided with a reference time and a communication delay time, and the reference time of the slave device can be updated, the time synchronization with the master device can be completed, the synchronous communication between devices can be guaranteed, and the synchronization operation can be performed based on the reference count value, so that the device control and task execution between the master device and the slave device can be kept consistent in time.
[0116] In one possible embodiment, the first synchronization operation module is further configured to:
[0117] In a case where the first target task information sent by the external terminal is received, a third count value currently recorded by the first clock module is acquired, and the first target task information includes a first target task event and a first execution waiting time;
[0118] The first target count value is determined according to the first execution waiting time, the preset time interval and the third count value;
[0119] The first target task event and the first target count value are sent to the slave device, so that the slave device executes the first target task event when the second clock module counts to the first target count value.
[0120] In a possible embodiment, the first synchronization job module is further configured to:
[0121] The first execution waiting time is converted into a first incremental count value based on the preset time interval;
[0122] The first incremental count value is added to the third count value to obtain the first target count value.
[0123] In a possible embodiment, the method further comprises a second synchronization job module configured to:
[0124] In a case where the second target task information sent by the external terminal is received, a fourth count value currently recorded by the first clock module is acquired, and the second target task information includes a second target task event and a second execution waiting time;
[0125] The control instruction corresponding to the slave device is generated according to the second target task event, and a second target count value is determined according to the second execution waiting time, the preset time interval, a delay value and the fourth count value;
[0126] In a case where the first clock module counts to the second target count value, the control instruction is sent to the slave device.
[0127] In a possible embodiment, the second synchronization job module is further configured to:
[0128] The second execution waiting time is converted into a second incremental count value based on the preset time interval;
[0129] The target incremental count value is obtained by subtracting the delay value from the second incremental count value;
[0130] The second target count value is obtained by adding the target incremental count value to the fourth count value.
[0131] In a possible embodiment, the method further comprises a data output rate synchronization module configured to:
[0132] obtaining a target data output rate, sending the target data output rate to the slave device, so that the slave device updates the currently set data output rate to the target data output rate.
[0133] In one possible embodiment, further comprising a delay value comparison module configured to:
[0134] compare the delay value with a preset delay threshold value;
[0135] a re-calibration module configured to:
[0136] in the case that the delay value is greater than or equal to the preset delay threshold value, re-sending a synchronization calibration request to the slave device, so that the slave device re-feeds back a confirmation message.
[0137] Correspondingly, the clock synchronization module 104 is further configured to:
[0138] in the case that the delay value is less than the preset delay threshold value, sending the second count value and the delay value to the slave device.
[0139] Figure 8 Another device synchronization apparatus provided by the embodiments of the present application is provided with a structure block diagram, which is configured to execute the device synchronization method provided by the above-mentioned embodiments, and has the function modules and beneficial effects corresponding to the execution method. As shown in Figure 8 The apparatus specifically includes:
[0140] The confirmation message sending module 201 is configured to, in the case that the synchronization calibration request sent by the master device is received, send a confirmation message to the master device, so that the master device, in the case that the confirmation message is received, obtains the second count value currently recorded by the first clock module, calculates a delay value based on the second count value and the first count value currently recorded by the first clock module when the synchronization calibration request is sent, and sends the second count value and the delay value.
[0141] The clock synchronization module 202 is configured to, in the case that the second count value and the delay value sent by the master device are received, add the second count value and the delay value to obtain a reference count value, and update the count value currently recorded by the second clock module to the reference count value. The second clock module starts counting according to a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0142] From the device, by receiving the second count value and the delay value sent by the master device, the reference time for device time synchronization and the communication delay time can be obtained, by updating the current record count value of the set second clock module to the reference count value, the update of the reference time of the device itself is realized, the time synchronization with the master device is completed, the synchronous communication between devices is guaranteed, which is beneficial to subsequent synchronous operation based on the reference count value, so that the device control and task execution between the master device and the slave device can be kept time consistent.
[0143] In one possible embodiment, further comprising a task event execution module configured to:
[0144] In the case of receiving the first target task event and the first target count value sent by the master device, when the second clock module reaches the first target count value, the first target task event is executed.
[0145] In one possible embodiment, further comprising an output rate updating module configured to:
[0146] In the case of receiving the target data output rate sent by the master device, the current set data output rate is updated to the target data output rate.
[0147] Figure 9 A structural schematic diagram of an electronic device provided in an embodiment of the present application is shown in Figure 9 The device includes a processor 301, a memory 302, an input device 303 and an output device 304; the number of processors 301 in the device can be one or more, Figure 9 and the processor 301 is taken as an example; the processor 301, the memory 302, the input device 303 and the output device 304 in the device can be connected through a bus or other means, Figure 9 and the connection through the bus is taken as an example. The memory 302 as a kind of computer readable storage medium, can be configured to store software programs, computer executable programs and modules, such as the program instructions / modules of the device synchronization method in the embodiment of the present application. The processor 301 executes the software programs, instructions and modules stored in the memory 302, thereby performing various functional applications and data processing of the device, i.e. realizing the device synchronization method described above. The input device 303 can be configured to receive input digital or character information, and generate key signal input related to user settings and function control of the device. The output device 304 can include display devices such as display screens.
[0148] The electronic device provided above can be used to execute the device synchronization method provided in any of the above embodiments, with the corresponding functions and advantages.
[0149] The embodiment of the present application further provides a nonvolatile storage medium containing computer executable instructions, which are configured to execute the device synchronization method described in the above embodiment when executed by a computer processor, and the method comprises the following steps: obtaining a first count value recorded by a first clock module currently set, the first clock module starts counting at a preset time interval after the main device is powered on; sending a synchronization calibration request to a slave device to enable the slave device to feed back a confirmation message; obtaining a second count value recorded by the first clock module currently set in the case that the confirmation message is received, and calculating a delay value based on the second count value and the first count value; sending the second count value and the delay value to the slave device to enable the slave device to add the second count value and the delay value to obtain a reference count value, and update a count value recorded by a second clock module currently set to the reference count value, the second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value.
[0150] Storage medium - any of various types of memory devices or storage devices. The term "storage medium" is intended to include an installation medium, e.g., a CD-ROM, floppy disks, or tape device; computer system memory or random access memory such as DRAM, DDR RAM, SRAM, EDO RAM, Rambus RAM, etc.; or a non-volatile memory such as a magnetic medium, e.g., a hard drive, or optical storage. The storage medium can further include other types of storage. For instance, a storage medium can also include a local or a remote file server, a server on a world-wide network, such as the Internet, or storage elements in any computer system. Additionally, the storage medium can be located in a first computer system in which the program is executed, or can be located in a second different computer system which connects to the first computer system over a network, such as the Internet. The second computer system can provide program instructions to the first computer for execution. The term "storage medium" can include two or more storage mediums which reside in different places, e.g., in different computer systems that are connected over a network. The storage medium can store a program of instructions which can be executed by one or more processors.
[0151] Of course, the storage medium containing computer executable instructions provided by the embodiment of the present application is not limited to the device synchronization method as above, and can also execute the related operations in the device synchronization method provided by any embodiment of the present application.
[0152] It is worth noting that, in the embodiment of the above device synchronization apparatus, each unit and module included is only divided according to the function logic, but is not limited to the above division, as long as the corresponding function can be realized; in addition, the specific name of each functional unit is only for the convenience of mutual distinction, and does not configure to limit the protection scope of the embodiment of the present application.
[0153] It should be noted that the numbering of the steps in the present scheme is only used to describe the overall design framework of the present scheme, and does not indicate the inevitable sequence between the steps. As long as the overall implementation process conforms to the overall design framework of the present scheme, it belongs to the protection scope of the present scheme, and the sequence in the description is not an exclusive limitation on the specific implementation process of the present scheme. Those skilled in the art should understand that the embodiments of the present application can be provided as a method, a system, or a computer program product. In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory. The memory can include non-persistent memory in a computer readable medium, random access memory (RAM), and / or non-volatile memory such as read-only memory (ROM) or flash memory (flash RAM). The memory is an example of a computer readable medium.
[0154] It should also be noted that the terms "comprising", "including", or any other variation thereof are intended to cover non-exclusive inclusions, so that a process, method, article, or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or includes elements inherent to such a process, method, article, or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article, or device including the element.
[0155] Note that the above is only the preferred embodiment of the present application and the technical principles applied. Those skilled in the art will understand that the present application is not limited to the specific embodiments herein, and those skilled in the art can make various obvious changes, readjustments and substitutions without departing from the scope of the present application. Therefore, although the present application has been described in more detail through the above embodiments, the present application is not limited to the above embodiments, and can include more other equivalent embodiments without departing from the concept of the present application, and the scope of the present application is determined by the scope of the appended claims.
Claims
1. A device synchronization method applied to a master device, the method comprising: The method comprises the following steps: acquiring a first count value recorded by a first clock module currently set, the first clock module starts counting at a preset time interval after the main device is powered on; sending a synchronization calibration request to a slave device to make the slave device feedback a confirmation message; acquiring a second count value recorded by the first clock module currently set in the case of receiving the confirmation message, and calculating a delay value based on the second count value and the first count value; sending the second count value and the delay value to the slave device to make the slave device add the second count value and the delay value to obtain a reference count value, and update a count value recorded by a second clock module currently set to the reference count value, the second clock module starts counting at the preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value; acquiring a target data output rate set, and sending the target data output rate to the slave device to make the slave device update a current set data output rate to the target data output rate.
2. The device synchronization method of claim 1, wherein, After the second count value and the delay value are sent to the slave device, the method further comprises the following steps: acquiring a third count value recorded by the first clock module currently set in the case of receiving first target task information sent by an external terminal, the first target task information comprising a first target task event and a first execution waiting time; determining a first target count value according to the first execution waiting time, the preset time interval and the third count value; sending the first target task event and the first target count value to the slave device to make the slave device execute the first target task event when the second clock module counts to the first target count value.
3. The device synchronization method of claim 2, wherein, The step of determining the first target count value according to the first execution waiting time, the preset time interval and the third count value comprises the following steps: converting the first execution waiting time into a first incremental count value based on the preset time interval; adding the first incremental count value and the third count value to obtain the first target count value.
4. The device synchronization method of claim 1, wherein, After the second count value and the delay value are sent to the slave device, the method further comprises the following steps: acquiring a fourth count value recorded by the first clock module currently set in the case of receiving second target task information sent by an external terminal, the second target task information comprising a second target task event and a second execution waiting time; generating a control instruction corresponding to the slave device according to the second target task event, and determining a second target count value according to the second execution waiting time, the preset time interval, the delay value and the fourth count value; sending the control instruction to the slave device in the case of the first clock module counting to the second target count value.
5. The device synchronization method of claim 4, wherein, The step of determining the second target count value according to the second execution waiting time, the preset time interval, the delay value and the fourth count value comprises the following steps: converting the second execution waiting time into a second incremental count value based on the preset time interval; Subtracting the second increment count value from the delay value to obtain a target increment count value; Adding the target increment count value to the fourth count value to obtain a second target count value.
6. The device synchronization method of claim 1, wherein, Before the sending of the second count value and the delay value to the slave device, the method further comprises: Comparing the delay value with a preset delay threshold value; In the case that the delay value is greater than or equal to the preset delay threshold value, re-sending a synchronization calibration request to the slave device to make the slave device re-feedback a confirmation message; Correspondingly, the sending of the second count value and the delay value to the slave device comprises: In the case that the delay value is less than the preset delay threshold value, sending the second count value and the delay value to the slave device.
7. A device synchronization method applied to a slave device, comprising: In the case that the master device sends a synchronization calibration request, sending a confirmation message to the master device to make the master device, in the case that the confirmation message is received, acquire a second count value currently recorded by a first clock module, calculate a delay value based on the second count value and a first count value currently recorded by the first clock module when the synchronization calibration request is sent, and send the second count value and the delay value; In the case that the master device sends the second count value and the delay value, adding the second count value and the delay value to obtain a reference count value, and updating a count value currently recorded by a second clock module set on the slave device to the reference count value, the second clock module starts counting at a preset time interval after the slave device is powered on, and is used for the slave device to perform a synchronization operation based on the reference count value; In the case that the master device sends a target data output rate, updating a currently set data output rate to the target data output rate. The method further comprises:
8. The device synchronization method of claim 7, wherein, In the case that the master device sends a first target task event and a first target count value, executing the first target task event when the second clock module reaches the first target count value. The method comprises:
9. An apparatus synchronization device, characterized by An acquisition module configured to acquire a first count value currently recorded by a first clock module set, the first clock module starting counting at a preset time interval after a master device is powered on; A request sending module configured to send a synchronization calibration request to a slave device to make the slave device feedback a confirmation message; A delay calculation module configured to, in the case that the confirmation message is received, acquire a second count value currently recorded by the first clock module, and calculate a delay value based on the second count value and the first count value; A clock synchronization module configured to send the second count value and the delay value to the slave device to make the slave device add the second count value and the delay value to obtain a reference count value, and update a count value currently recorded by a second clock module set to the reference count value, the second clock module starting counting at the preset time interval after the slave device is powered on, and being used for the slave device to perform a synchronization operation based on the reference count value; and A data output rate updating module configured to, in the case that the master device sends a target data output rate, update a currently set data output rate to the target data output rate. The data output rate synchronization module is configured to obtain a set target data output rate, send the target data output rate to the slave device, and cause the slave device to update a currently set data output rate to the target data output rate.
10. An apparatus synchronization device, characterized by The method comprises the following steps: The confirmation message sending module is configured to, in a case where the synchronization calibration request sent by the master device is received, send a confirmation message to the master device, so that the master device, in a case where the confirmation message is received, obtains a second count value currently recorded by the first clock module, calculates a delay value based on the second count value and a first count value currently recorded by the first clock module when the synchronization calibration request is sent, and sends the second count value and the delay value. The clock synchronization module is configured to, in a case where the second count value and the delay value sent by the master device are received, add the second count value and the delay value to obtain a reference count value, and update a count value currently recorded by a set second clock module to the reference count value, the second clock module starting to count at a preset time interval after the slave device is powered on, and being used for the slave device to perform a synchronization operation based on the reference count value. The output rate updating module is configured to, in a case where the target data output rate sent by the master device is received, update the currently set data output rate to the target data output rate.
11. An electronic device, the device comprising: One or more processors; The storage device is configured to store one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the device synchronization method in any one of claims 1-8.
12. A non-volatile storage medium storing computer executable instructions which, when executed by a computer processor, are configured to perform the device synchronization method in any one of claims 1-8.
Citation Information
Patent Citations
Time synchronization for clocks separated by a communication link
CN112041829A
Systems and methods for improving clock synchronization between master and slave devices
US9760114B1