Device switching method, device, electronic device and computer readable storage medium
By determining device switching based on the response information of the candidate device when the target device meets the preset conditions, the problem that the status of the standby device is not suitable to replace the faulty device is solved, ensuring the normal operation of the system and improving the stability and safety of device switching.
Patent Information
- Application Number
- CN202110798533.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-14
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-07-14
AI Technical Summary
When switching devices in the prior art, the status of the backup device cannot effectively replace the faulty device, causing the system to fail to operate normally. Especially when the server sends device switching information, the backup device may not be able to send information, and the status of the candidate device is not suitable to replace the original device. equipment.
By determining whether to switch to a new target device based on the number of responses and response time of the candidate device when the target device meets the preset conditions, this ensures normal operation of the system. Specific steps include the candidate device receiving the preset information and sending device switching information, deciding whether to switch based on the number of responses and time, and when the master device fails, selecting the device with a higher number of responses from the slave devices as the new master device. .
Ensure the normal operation of the system where the target equipment is located, ensure the stability and safety of linkage control, and avoid system interruption due to equipment failure.
Smart Images

Figure CN113505028B
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of computer technology, and in particular to a device switching method, apparatus, electronic device, and computer-readable storage medium. Background Art
[0002] In the prior art, when a device is operating normally or abnormal, due to various internal or external factors, it may be necessary to switch other devices to the device to replace the device to complete the functions it needs to complete. For example, after a device fails, it will not be able to continue to realize its original functions, which will cause the system where the device is located to fail to operate normally. By switching other devices to the failed device, the failed device can be replaced to continue to realize its functions, ensuring that the system where the device is located operates normally.
[0003] At present, the device switching information is usually sent by the switched device. When the switched device fails, it may not be able to send information. In addition, in the scenario where the server sends the device switching information, it often only uses a predetermined specific backup device to replace the switched device. However, the current status of the candidate device may not be suitable for replacing the switched device to realize its function. Summary of the invention
[0004] In view of this, in order to solve the technical problem of how to perform device switching to ensure the normal operation of the system where the target device is located, the embodiments of the present disclosure provide a device switching method, apparatus, electronic device and computer-readable storage medium.
[0005] In a first aspect, an embodiment of the present disclosure provides a device switching method, the method comprising:
[0006] In the case where it is determined that the target device satisfies the preset device switching condition, determining whether to switch the candidate device to a new target device based on the device switching information sent by the candidate device of the target device, wherein the candidate device sends the device switching information after receiving the preset information;
[0007] In the case where it is determined to switch the candidate device to the new target device, the candidate device is switched to the new target device.
[0008] Optionally, in the method of any embodiment of the present disclosure, the device switching information includes the number of responses of the candidate device; wherein the number of responses of the candidate device represents: when the target device satisfies the preset device switching condition, the number of times the candidate device performs a first preset response; and
[0009] The device switching information sent by the candidate device based on the target device, determining whether to switch the candidate device to a new target device, includes:
[0010] Based on the above-mentioned number of responses and response time, determine whether to switch the slave device to a new master device, wherein the above-mentioned response time represents: when the above-mentioned target device meets the above-mentioned preset device switching condition, the time for the above-mentioned candidate device to perform the above-mentioned first preset response.
[0011] Optionally, in the method of any embodiment of the present disclosure, the target device that meets the preset device switching condition is a master device in a master device group controlled by a target server; the candidate device is a slave device in a slave device group controlled by a failed master device; the preset device switching condition includes a master device failure; when it is determined that the master device fails, each slave device in the slave device group controlled by the master device sends device switching information including a response number; and
[0012] The above-mentioned determination of whether to switch from the slave device to the new master device based on the above-mentioned number of responses and response time includes:
[0013] According to the order of response time of the slave devices in the slave device group controlled by the above-mentioned master device, the following determination steps are performed in sequence based on the number of responses sent by the slave devices: based on the number of responses sent by the slave devices and the number of responses of each master device in the above-mentioned master device group, determine whether to switch the slave device to a new master device, wherein the number of responses of the master device represents: the number of times the master device performs a second preset response after the slave device sends the device switching information.
[0014] Optionally, in the method of any embodiment of the present disclosure, the method further includes:
[0015] In the case where it is determined not to switch the slave device to a new master device, the above determination step is continued based on the number of responses sent by the slave device that sends the next number of responses in the above slave device group.
[0016] Optionally, in the method of any embodiment of the present disclosure, the determining whether to switch the slave device to a new master device based on the number of responses sent by the slave device and the number of responses of each master device in the master device group includes:
[0017] Determine the master control devices that meet the preset selection condition from the master control device group, and use the determined number of master control devices as the first number, wherein the preset selection condition includes: the number of responses of the master control device is less than or equal to the number of responses sent by the slave device;
[0018] The number of master devices included in the master device group is taken as a second number, and based on the first number and the second number, it is determined whether to switch the slave device to a new master device.
[0019] Optionally, in the method of any embodiment of the present disclosure, the determining whether to switch the slave device to a new master device based on the first number and the second number includes:
[0020] Calculate the difference between the second number and a preset positive integer;
[0021] When it is determined that the product of the difference and the preset ratio is less than the first number, it is determined to switch the slave device to a new master device.
[0022] Optionally, in the method of any embodiment of the present disclosure, after the above-mentioned determination of whether to switch the slave device to a new master device, the above-mentioned determination step further includes:
[0023] For each master control device in the master control device group, when it is determined that the number of responses of the master control device is less than the number of responses sent by the slave device, the number of responses of the master control device is updated to the number of responses sent by the slave device.
[0024] In a second aspect, an embodiment of the present disclosure provides a device switching apparatus, the apparatus comprising:
[0025] a determining unit configured to determine whether to switch the candidate device to a new target device based on the device switching information sent by the candidate device of the target device when it is determined that the target device satisfies the preset device switching condition, wherein the candidate device sends the device switching information after receiving the preset information;
[0026] The switching unit is configured to switch the candidate device to the new target device when it is determined that the candidate device is to be switched to the new target device.
[0027] Optionally, in the apparatus of any embodiment of the present disclosure, the device switching information includes the number of responses of the candidate device; wherein the number of responses of the candidate device represents: the number of times the candidate device performs a first preset response when the target device satisfies the preset device switching condition; and
[0028] The above-mentioned determination unit comprises:
[0029] The determination subunit is configured to determine whether to switch the slave device to a new master device based on the above-mentioned number of responses and response time, wherein the above-mentioned response time represents: when the above-mentioned target device meets the above-mentioned preset device switching condition, the time for the above-mentioned candidate device to perform the above-mentioned first preset response.
[0030] Optionally, in the apparatus of any embodiment of the present disclosure, the target device satisfying the preset device switching condition is a master device in a master device group controlled by a target server; the candidate device is a slave device in a slave device group controlled by a failed master device; the preset device switching condition includes a master device failure; when it is determined that the master device fails, each slave device in the slave device group controlled by the master device sends device switching information including a response number; and
[0031] The above-mentioned determination subunit includes:
[0032] The determination module is configured to perform the following determination steps based on the number of responses sent by the slave devices in the slave device group controlled by the above-mentioned master device in the order of response time: based on the number of responses sent by the slave devices and the number of responses of each master device in the above-mentioned master device group, determine whether to switch the slave device to a new master device, wherein the number of responses of the master device represents: the number of times the master device performs a second preset response after the slave device sends device switching information.
[0033] Optionally, in the device of any embodiment of the present disclosure, the device further includes:
[0034] The execution unit is configured to continue to execute the above determination step based on the number of responses sent by the next slave device in the above slave device group that sends a response number when it is determined that the slave device is not to be switched to a new master device.
[0035] Optionally, in the device of any embodiment of the present disclosure, the determination module includes:
[0036] The first determination submodule is configured to determine the master control devices that meet the preset selection condition from the master control device group, and use the determined number of master control devices as the first number, wherein the preset selection condition includes: the number of responses of the master control device is less than or equal to the number of responses sent by the slave device;
[0037] The second determining submodule is configured to take the number of master devices included in the master device group as a second number, and determine whether to switch the slave device to a new master device based on the first number and the second number.
[0038] Optionally, in the device of any embodiment of the present disclosure, the second determining submodule is specifically configured to:
[0039] Calculate the difference between the second number and a preset positive integer;
[0040] When it is determined that the product of the difference and the preset ratio is less than the first number, it is determined to switch the slave device to a new master device.
[0041] Optionally, in the device of any embodiment of the present disclosure, the above-mentioned determining step further includes:
[0042] For each master control device in the master control device group, when it is determined that the number of responses of the master control device is less than the number of responses sent by the slave device, the number of responses of the master control device is updated to the number of responses sent by the slave device.
[0043] In a third aspect, an embodiment of the present disclosure provides an electronic device, including:
[0044] Memory for storing computer programs;
[0045] The processor is used to execute the computer program stored in the memory, and when the computer program is executed, the method of any embodiment of the device switching method of the first aspect of the present disclosure is implemented.
[0046] In a fourth aspect, an embodiment of the present disclosure provides a computer-readable medium, and when the computer program is executed by a processor, the method of any embodiment of the device switching method of the first aspect described above is implemented.
[0047] In a fifth aspect, an embodiment of the present disclosure provides a computer program, which includes a computer-readable code. When the computer-readable code runs on a device, the processor in the device executes instructions for implementing the steps in the method of any embodiment of the device switching method of the first aspect above.
[0048] Based on the device switching method provided by the above embodiment of the present disclosure, when it is determined that the target device meets the preset device switching conditions, based on the device switching information sent by the candidate device of the target device, it is determined whether to switch the candidate device to a new target device, wherein the candidate device sends the device switching information after receiving the preset information, and then, when it is determined that the candidate device is switched to the new target device, the candidate device is switched to the new target device. In this way, it is possible to determine whether to switch the candidate device to a new target device based on the device switching information actively sent by the candidate device of the target device, thereby ensuring the normal operation of the system where the target device is located, and in the scenario where the target device is a master device and the candidate device is a slave device controlled by the master device, it is possible to ensure that the linkage control is carried out normally.
[0049] The technical solution of the present disclosure is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Other features, objects and advantages of the present disclosure will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0051] Figure 1 is an exemplary system architecture diagram of a device switching method provided by an embodiment of the present disclosure;
[0052] Figure 2 is a flow chart of a device switching method provided by an embodiment of the present disclosure;
[0053] Figure 3A and Figure 3B It is for Figure 2 A schematic diagram of an application scenario of an embodiment of the present invention;
[0054] Figure 4A is a flow chart of another device switching method provided by an embodiment of the present disclosure;
[0055] Figure 4B It is for Figure 4A A schematic diagram of the response method of the master control device described in;
[0056] Figure 4C It is for Figure 4A A schematic diagram of the structure of the system in which the master control device described in the specification is located;
[0057] Figure 4D It is for Figure 4A Schematic diagram of the interaction process between the master device and the slave device described in;
[0058] Figure 5 is a structural schematic diagram of a device switching apparatus provided by an embodiment of the present disclosure;
[0059] Figure 6 It is a structural schematic diagram of an electronic device provided by an embodiment of the present disclosure. DETAILED DESCRIPTION
[0060] Various exemplary embodiments of the present disclosure will now be described in detail with reference to the accompanying drawings. It should be noted that the relative arrangement of components and steps, numerical expressions and numerical values set forth in these embodiments do not limit the scope of the present disclosure unless otherwise specifically stated.
[0061] Those skilled in the art will understand that the terms "first" and "second" in the embodiments of the present disclosure are only used to distinguish objects such as different steps, devices or modules, and do not represent any specific technical meanings, nor do they indicate the logical order between them.
[0062] It should also be understood that in the embodiments of the present disclosure, “plurality” may refer to two or more than two, and “at least one” may refer to one, two, or more than two.
[0063] It should also be understood that any component, data or structure mentioned in the embodiments of the present disclosure can generally be understood as one or more, unless explicitly limited or otherwise indicated in the context.
[0064] In addition, the term "and / or" in the present disclosure is only a description of the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in the present disclosure generally indicates that the associated objects before and after are in an "or" relationship.
[0065] It should also be understood that the description of the various embodiments in the present disclosure focuses on the differences between the various embodiments, and the same or similar aspects thereof can be referenced to each other, and for the sake of brevity, they will not be described one by one.
[0066] The following description of at least one exemplary embodiment is merely illustrative in nature and is in no way intended to limit the present disclosure, its application, or uses.
[0067] Technologies, methods, and equipment known to ordinary technicians in the relevant art may not be discussed in detail, but where appropriate, the technologies, methods, and equipment should be considered as part of the specification.
[0068] It should be noted that like reference numerals and letters refer to similar items in the following figures, and therefore, once an item is defined in one figure, it need not be further discussed in subsequent figures.
[0069] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present disclosure may be combined with each other. The present disclosure will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0070] Figure 1 It is an exemplary system architecture diagram of a device switching method provided in an embodiment of the present disclosure.
[0071] like Figure 1 As shown, system architecture 100 may include electronic devices 101, 102 and network 103, which may provide a medium for a communication link between electronic device 101 and electronic device 102. Network 103 may include various connection types, such as wired, wireless communication links, or fiber optic cables.
[0072] The electronic device 101 can interact with the electronic device 102 through the network 103 to receive or send data, etc. Here, at least one of the electronic device 101 and the electronic device 102 can be used as a server or a terminal. When the electronic device 101 and / or the electronic device 102 is used as a terminal, various communication client applications can be installed thereon. When the electronic device 101 and / or the electronic device 102 is used as a server, it can be a server that provides various services, such as a background server that performs corresponding processing on the instructions sent by the terminal. The background server can analyze the received data and perform other processing. As an example, the server can be a cloud server.
[0073] It should be noted that the device switching method provided in the embodiments of the present disclosure can be executed by, but not limited to, the above electronic devices. The execution subject of the device switching method provided in the embodiments of the present disclosure can be hardware or software, which is not specifically limited here.
[0074] As an example, electronic device 101 may be a master device, and electronic device 102 may be a slave device controlled by the master device. Optionally, the master device may forward the control instruction sent by the server to the slave device controlled by the master device. In this scenario, the execution subject of the device switching method provided in the embodiment of the present disclosure may be a master device, a slave device, the server, or other electronic devices other than the master device, slave device, and server. In addition, the execution subject of the device switching method provided in the embodiment of the present disclosure may be one or more electronic devices. For example, when the execution subject of the device switching method provided in the embodiment of the present disclosure is multiple electronic devices, the device switching method provided in the embodiment of the present disclosure may be executed by the server and the slave device in cooperation with each other.
[0075] It should be understood that Figure 1 The number of electronic devices and networks in the embodiment is only for illustration. Any number of electronic devices and networks may be provided according to implementation requirements.
[0076] Figure 2 A process 200 of a device switching method provided by an embodiment of the present disclosure is shown. The device switching method comprises the following steps:
[0077] Step 201: When it is determined that the target device satisfies a preset device switching condition, it is determined whether to switch the candidate device to a new target device based on device switching information sent by a candidate device of the target device.
[0078] In this embodiment, when it is determined that the target device meets the preset device switching condition, the execution subject of the device switching method (for example Figure 1The electronic device shown or other electronic devices) can determine whether to switch the above-mentioned candidate device to a new target device based on the device switching information sent by the candidate device of the above-mentioned target device.
[0079] The target device may be any electronic device. As an example, the target device may be a master device in a smart home system, which may forward the control instruction to at least one slave device controlled by the master device after receiving the control instruction sent by the server. Optionally, the target device may also be other electronic devices other than the master device in the smart home system, such as a temperature control device, an alarm device, etc.
[0080] The preset device switching condition may be a pre-set condition for determining whether the target device needs to be switched. As an example, the preset device switching condition may include at least one of the following: the target device fails (e.g., disconnected from the network, unable to respond, etc.); the temperature of the target device exceeds a preset temperature threshold; the operating time of the target device exceeds a preset time threshold, etc.
[0081] The candidate device may be any one or more electronic devices used to switch to the target device. As an example, when the target device is a master device, the candidate device may be a slave device controlled by the master device; when the target device is a temperature control device, the candidate device may be another temperature control device with a temperature control function.
[0082] Device switching information may be information actively sent by a candidate device to indicate the switching of a target device. However, it should be noted that in some cases, not every device switching information sent will produce the effect of switching the target device. For example, if candidate device A first sends device switching information to indicate that candidate device A is switched to a new target device; then, candidate device B sends device switching information to indicate that candidate device B is switched to a new target device, then the execution method may be one of the following:
[0083] Method 1: After the device switching information of switching candidate device A to the new target device is sent, the device switching information of switching candidate device B to the new target device is sent. That is, two switches are performed. In other words, in the above scenario, after each device switching information is sent, the effect of switching the target device is generated.
[0084] Method 2: Device switching information that switches candidate device A to a new target device. That is, only one switching is performed. In other words, in the above scenario, not every device switching information sent produces the effect of switching the target device.
[0085] Here, the execution subject of the above-mentioned determination that the target device meets the preset device switching condition may be the same as or different from the execution subject of the device switching method. When the two are different, the execution subject of the determination that the target device meets the preset device switching condition may send the first data to the execution subject of the device switching method. The first data may be used by the execution subject of the device switching method to determine whether to switch the candidate device to a new target device based on the device switching information sent by the candidate device of the target device.
[0086] In addition, after the candidate device receives the preset information, the candidate device can send device switching information. The execution subject of the above-mentioned determination that the target device meets the preset device switching condition can directly or indirectly send a message (that is, the above-mentioned preset information) to each slave device controlled by the failed master device. Among them, the message can be used to instruct each slave device to send device switching information, and can also be used to indicate that the target device meets the preset device switching condition.
[0087] As an example, the execution subject may determine whether to switch the candidate device to a new target device in the following manner:
[0088] If the device switching information sent by the candidate device of the target device indicates that the inoperative time of the candidate device is greater than the preset time threshold, it is determined to switch the candidate device to a new target device.
[0089] Step 202: When it is determined that the candidate device is to be switched to the new target device, the candidate device is switched to the new target device.
[0090] In this embodiment, when it is determined to switch the candidate device to the new target device, the execution subject may switch the candidate device to the new target device.
[0091] In some optional implementations of this embodiment, the target device may be a master device, the preset device switching condition may be a failure of the master device, and the candidate device may be a slave device in a slave device group controlled by the master device.
[0092] On this basis, the execution subject may perform step 201 in the following manner:
[0093] In the case where it is determined that the master device fails, it is determined whether to switch the slave device to a new master device based on device switching information sent by a slave device in the slave device group controlled by the master device.
[0094] Furthermore, the execution subject may perform step 202 in the following manner:
[0095] In the case where it is determined to switch the slave device to a new master device, the slave device is switched to the new master device to replace the failed master device.
[0096] Optionally, other slave devices controlled by the master device that failed before the switching may be switched to slave devices controlled by the new master device.
[0097] It can be understood that the above optional implementation method can switch the slave device to a new master device, so that the new master device is used to replace the failed master device, so that the linkage control can be guaranteed to be carried out normally.
[0098] In some optional implementations of this embodiment, the device switching information includes the number of responses of the candidate device. The number of responses of the candidate device represents: when the target device satisfies the preset device switching condition, the number of times the candidate device performs the first preset response. On this basis, the execution subject can adopt the following method to determine whether to switch the candidate device to the new target device based on the device switching information sent by the candidate device of the target device:
[0099] Based on the number of responses and the response time, it is determined whether to switch the slave device to a new master device. The response time represents the time it takes for the candidate device to perform the first preset response when the target device meets the preset device switching condition.
[0100] The first preset response may be the first response of the candidate device to the target device satisfying the preset device switching condition, or may be a response of the candidate device to the target device satisfying the preset device switching condition, containing preset information (eg, preset characters).
[0101] Here, each time a master device fails, the slave device controlled by the master device may respond once or multiple times, for example, by sending device switching information. Each time a response is made, the number of responses of the slave device may increase by a positive integer value, for example, 1.
[0102] As an example, the above-mentioned execution entity can set weights for the number of responses and response time in advance, so as to calculate the weighted sum of the number of responses, the weight of the number of responses, the response time, and the weight of the response time. If the result obtained is less than the preset threshold, it can be determined that the slave device will be switched to the new master device.
[0103] In some application scenarios of the above optional implementation methods, the target device that meets the above preset device switching conditions is the master device in the master device group controlled by the target server; the above candidate device is a slave device in the slave device group controlled by the failed master device; the above preset device switching conditions include the failure of the master device; when it is determined that the master device fails, each slave device in the slave device group controlled by the master device sends device switching information including the number of responses. On this basis, the above execution subject can determine whether to switch the slave device to a new master device based on the above number of responses and response time in the following manner:
[0104] According to the order of response time of the slave devices in the slave device group controlled by the above-mentioned master device, the following determination steps are performed in sequence based on the number of responses sent by the slave devices: based on the number of responses sent by the slave devices and the number of responses of each master device in the above-mentioned master device group, determine whether to switch the slave device to a new master device.
[0105] The number of responses of the master device represents the number of times the master device performs a second preset response after the slave device sends the device switching information. The second preset response may be the first response of the master device to the device switching information sent by the slave device, or may be a response of the master device to the device switching information sent by the slave device, which includes preset information (e.g., preset characters).
[0106] In practice, if the response conditions are met, the master device may respond by sending an ACK character, etc. The response conditions may include at least one of the following: the master device confirms receipt of the device switching information; the master device receives the device switching information for the first time within a preset time period; the slave device that sends the device switching information has the device switching authority, etc.
[0107] As an example, if the number of responses sent by the slave device is less than the average number of responses of the master devices in the master device group, it can be determined that the slave device is switched to a new master device.
[0108] It can be understood that in the above situation, whether to switch the slave device to a new master device can be determined based on the number of responses sent by the slave device and the number of responses of each master device in the above master device group. Thus, judging by the responses of multiple master devices can avoid malicious switching when the slave device has no device switching authority to a certain extent.
[0109] In some cases of the above application scenarios, when it is determined that the slave device will not be switched to a new master device, the above execution subject may also continue to execute the above determination step based on the number of responses sent by the next slave device in the above slave device group.
[0110] It can be understood that in the above example, if it is determined not to switch the slave device to a new master device, the above determination step can be continued based on the number of responses sent by the next slave device in the above slave device group until a new master device is selected from the slave device group.
[0111] In some cases of the above application scenarios, the determining whether to switch the slave device to a new master device based on the number of responses sent by the slave device and the number of responses of each master device in the above master device group includes:
[0112] First, from the above master control device group, master control devices that meet the preset selection conditions are determined, and the number of the determined master control devices is used as the first number. The above preset selection conditions include: the number of responses of the master control device is less than or equal to the number of responses received by the master control device and sent by the slave device.
[0113] Then, the number of master devices included in the master device group is taken as a second number, and based on the first number and the second number, it is determined whether to switch the slave device to a new master device.
[0114] Optionally, the determining whether to switch the slave device to a new master device based on the first number and the second number includes:
[0115] Calculate the difference between the second number and a preset positive integer (such as 1 or 2);
[0116] When it is determined that the product of the difference and a preset ratio (eg, 1 / 2) is smaller than the first number, it is determined that the slave device is switched to a new master device.
[0117] It can be understood that in the above implementation, whether to switch the slave device to a new master device is determined by judging whether the product of the second number and the preset ratio is less than the above first number, so that the slave device can be switched to the new master device only after obtaining responses from at least half of the master devices. This helps to ensure the security and stability of device switching.
[0118] Optionally, when it is determined that the quotient of the second number and a preset value is smaller than the first number, it is determined that the slave device is switched to a new master device.
[0119] It can be understood that in the above example, whether to switch the slave device to the new master device is determined based on the first number and the second number. Whether to switch the slave device to the new master device can be determined from two dimensions: the number of responses from the master devices and the number of master devices in the master device group.
[0120] Optionally, after the above determination of whether to switch the slave device to a new master device, the above determination step also includes: for each master device in the above master device group, when it is determined that the number of responses of the master device is less than the number of responses sent by the slave device, updating the number of responses of the master device to the number of responses sent by the slave device.
[0121] It can be understood that by adopting the method described in the above implementation method, the response times of the master control device are updated, which can ensure that the response times of each master control device are relatively close and gradually increase. After the value increases, the number of responses sent by the subsequent slave devices may be less than the increased value. Then, based on the changed response times of the master control device, the device switching information sent by the slave device to which the master control device needs to respond can be screened.
[0122] Optionally, the above switching from the slave device to the new master device includes:
[0123] The slave device is switched to a new master device, and the failed master device is switched to a slave device controlled by the new master device.
[0124] It can be understood that in the above situation, by switching the slave device to a new master device, and switching the failed master device to a slave device controlled by the new master device, the system where the master device is located can be less affected when the master device fails.
[0125] Optionally, the response times of the slave device are updated only once during a failure of a master device controlling the slave device.
[0126] Optionally, the number of responses of the slave device after each update may be 1 greater than the number of responses of the slave device before the update.
[0127] Optionally, the new master control device is used for forwarding the control instruction to each slave device in the slave device group controlled by the new master control device when receiving the control instruction sent by the target server.
[0128] It can be understood that in the above implementation, the system where the failed main control device and the new main control device are located can be used to implement linkage control. In this way, after the main control device fails, the linkage control can be guaranteed to be carried out normally.
[0129] Continue to see Figure 3Aand Figure 3B , Figure 3A and Figure 3B FIG. 1 is a schematic diagram of an application scenario of the device switching method according to this embodiment. Figure 3A In the case where it is determined that the target device 301 meets the preset device switching condition (for example, the target device 301 fails), the execution subject of the device switching method determines whether to switch the candidate device 303 to a new target device based on the device switching information sent by the candidate device 303 of the target device 301, wherein the candidate device sends the device switching information after receiving the preset information, and then, Figure 3B As shown, in the case where it is determined to switch the candidate device 303 to the new target device, the execution subject switches the candidate device 303 to the new target device. Figure 3A In the process of data transmission between the target device 301 and the electronic device 302, the target device 301 fails. Then, the execution subject determines to switch the candidate device 303 to a new target device based on the device switching information sent by the candidate device 303. Figure 3B As shown, the candidate device 303 replaces the target device 301 and continues to perform data transmission with the electronic device 302 .
[0130] The method provided by the above-mentioned embodiment of the present disclosure determines whether to switch the above-mentioned candidate device to a new target device based on the device switching information sent by the candidate device of the above-mentioned target device when it is determined that the target device satisfies the preset device switching condition, wherein the above-mentioned candidate device sends the above-mentioned device switching information after receiving the preset information, and then, when it is determined that the above-mentioned candidate device is switched to the above-mentioned new target device, the above-mentioned candidate device is switched to the above-mentioned new target device. In this way, it is possible to determine whether to switch the above-mentioned candidate device to a new target device based on the device switching information actively sent by the candidate device of the target device, thereby ensuring the normal operation of the system where the target device is located, and in the scenario where the target device is a master device and the candidate device is a slave device controlled by the master device, it is possible to ensure that the linkage control is carried out normally.
[0131] Further references Figure 4A , which shows a process 400 of another embodiment of a device switching method. The process 400 of the device switching method includes the following steps:
[0132] Step 401: Detect that a main control device fails.
[0133] Step 402, the version number X of the slave device is increased by 1. The version number X of the slave device can be obtained based on the number of responses of the slave device described above. The initial value of the version number X of each slave device and each master device can be a predetermined value, and the version number X of the slave device can be increased by 1 before each device switching information is sent. The version number X of the master device can update its own version number X to the version number sent by the slave device each time it receives a version number greater than or equal to the version number sent by the slave device.
[0134] Step 403: The slave device sends device switching information, wherein the device switching information includes a version number X of the slave device.
[0135] In step 404, the number of ACKs received by the slave device is recorded as N. The ACK is sent by the master device that meets the sending condition. The sending condition is: the version number of the master device is less than or equal to the version number sent by the slave device and received by the master device.
[0136] Here, the way the master device sends ACK can be referred to Figure 4B shown. Figure 4B It is for Figure 4A Schematic diagram of the response method of the master control device described in . Figure 4B In the process 410 of the master device's response method, that is, the master device sends an ACK method, includes the following sub-steps:
[0137] In sub-step 411, the master device receives the device switching information (including X of the slave device) sent by the slave device.
[0138] Sub-step 412: determining whether the version number X in the device switching information is greater than the version number X of the master device.
[0139] If greater than, execute step 413; if less than or equal to, execute step 414.
[0140] In sub-step 413, the master device sends an ACK in response, and updates the version number X of the master device to the version number X in the device switching information.
[0141] Sub-step 414: the master device does not respond.
[0142] As an example, suppose that after the master device 2 replies with an ACK, it receives a device switching message from another slave device. However, at this time, the X recorded by the master device 2 is no less than the X of the sender (i.e., the slave device), so it will not respond. After the slave device sends the device switching message, it starts to collect the received ACKs. When the ACKs received by a slave device are greater than half of the current number of normal master devices n, the device is successfully elected as the new master device and sends a broadcast to notify other devices: I have become the new master device.
[0143] Step 405, determine whether the following inequality holds: N>(n-1) / 2, where n represents the number of other master control devices in the master control device group except the master control device that has failed.
[0144] Afterwards, if the condition is met, execute step 406 ; if not, execute step 407 .
[0145] Step 406: switch the slave device to a new master device and send a broadcast.
[0146] Step 407, waiting for other slave devices to become new master devices.
[0147] In this embodiment, the specific execution method of the above steps 401 to 407 can refer to the above Figure 2 The relevant description of the corresponding embodiment is not repeated here. In addition, in addition to the above-mentioned contents, the embodiments of the present disclosure may also include Figure 2 The same or similar features and effects as those in the corresponding embodiments will not be described in detail here.
[0148] Please refer to the following Figure 4C , Figure 4C It is for Figure 4A A schematic diagram of the structure of the system where the master control device described in FIG. Figure 4C In the embodiment, the server can send instructions to the master control devices 1-n. After receiving the instructions sent by the server, each of the master control devices 1-n forwards the instructions to the slave devices 1-n controlled by the master control device, thereby realizing linkage control.
[0149] Please continue to refer to Figure 4D , Figure 4D It is for Figure 4A Schematic diagram of the interaction process between the master device and the slave device described in. Figure 4DIn the example, master device 1 fails, and each slave device in slave devices 1-n controlled by master device 1 first updates its own version number from X to X+1, and then sends device switching information containing the updated version number X+1 to all master devices. Master devices 1-n can all receive the device switching information sent by the slave devices, but due to the failure of master device 1, it cannot respond, while master device 2-n can respond by replying ACK. Among them, during the period from the failure of master device 1 to the switching of the slave device to the new master device, each master device in master devices 2-n responds only once.
[0150] The device switching method in this embodiment can be applied to smart home scenarios. In smart home scenarios, it can be achieved through linkage control between different smart devices (including master devices and slave devices). At this stage, the linkage control of smart homes is often controlled by the server issuing control instructions, and then the master device controls its slave devices, and there may be multiple master devices in one scene. If a master device fails, its slave device cannot be controlled and the linkage cannot be completed. By using the device switching method in the above embodiment, when the master device fails, a slave device can be elected as the new master device in time. The new master device can control the slave device to ensure the normal linkage control and improve fault tolerance.
[0151] Further references Figure 5 As an implementation of the methods shown in the above figures, the present disclosure provides an embodiment of a device switching device, and the device embodiment is Figure 2 Corresponding to the method embodiment shown in FIG. 1 , in addition to the features described below, the device embodiment may also include Figure 2 The same or corresponding features of the method embodiment shown, and the generation of Figure 2 The method embodiment shown has the same or corresponding effects. The device can be specifically applied to various electronic devices.
[0152] like Figure 5 As shown, the device switching device 500 of this embodiment. The above-mentioned device 500 includes: a determination unit 501 and a switching unit 502. Among them, the determination unit 501 is configured to determine whether to switch the above-mentioned candidate device to a new target device based on the device switching information sent by the candidate device of the above-mentioned target device when it is determined that the target device meets the preset device switching condition. After the above-mentioned candidate device receives the preset information, the candidate device can send the device switching information; the switching unit 502 is configured to switch the above-mentioned candidate device to the above-mentioned new target device when it is determined that the above-mentioned candidate device is switched to the above-mentioned new target device.
[0153] In this embodiment, the determination unit 501 of the device switching apparatus 500 can determine whether to switch the candidate device to a new target device based on the device switching information sent by the candidate device of the target device when it is determined that the target device meets the preset device switching condition. After the candidate device receives the preset information, the candidate device can send the device switching information.
[0154] In this embodiment, the switching unit 502 may switch the candidate device to the new target device when determining to switch the candidate device to the new target device.
[0155] In some optional implementations of this embodiment, the device switching information includes the number of responses of the candidate device; wherein the number of responses of the candidate device represents: the number of times the candidate device performs a first preset response when the target device satisfies the preset device switching condition; and
[0156] The determination unit 501 includes:
[0157] A determination subunit (not shown in the figure) is configured to determine whether to switch the slave device to a new master device based on the above-mentioned number of responses and response time, wherein the above-mentioned response time represents: when the above-mentioned target device meets the above-mentioned preset device switching condition, the time for the above-mentioned candidate device to perform the above-mentioned first preset response.
[0158] In some optional implementations of this embodiment, the target device that meets the preset device switching condition is a master device in a master device group controlled by a target server; the candidate device is a slave device in a slave device group controlled by a failed master device; the preset device switching condition includes a master device failure; when it is determined that the master device fails, each slave device in the slave device group controlled by the master device sends device switching information including a response number; and
[0159] The above-mentioned determination subunit includes:
[0160] A determination module (not shown in the figure) is configured to perform the following determination steps based on the number of responses sent by the slave devices in the slave device group controlled by the above-mentioned master device in the order of response time: based on the number of responses sent by the slave devices and the number of responses of each master device in the above-mentioned master device group, determine whether to switch the slave device to a new master device, wherein the number of responses of the master device represents: the number of times the master device performs a second preset response after the slave device sends the device switching information.
[0161] In some optional implementations of this embodiment, the above device further includes:
[0162] The execution unit (not shown in the figure) is configured to continue to execute the above determination step based on the number of responses sent by the next slave device in the above slave device group when it is determined that the slave device will not be switched to a new master device.
[0163] In some optional implementations of this embodiment, the above-mentioned determination module includes:
[0164] A first determination submodule (not shown in the figure) is configured to determine the master control devices that meet the preset selection condition from the master control device group, and use the determined number of master control devices as the first number, wherein the preset selection condition includes: the number of responses of the master control device is less than or equal to the number of responses sent by the slave device;
[0165] The second determining submodule (not shown in the figure) is configured to take the number of master devices included in the master device group as a second number, and determine whether to switch the slave device to a new master device based on the first number and the second number.
[0166] In some optional implementations of this embodiment, the second determining submodule is specifically configured as follows:
[0167] Calculate the difference between the second number and a preset positive integer;
[0168] When it is determined that the product of the difference and the preset ratio is less than the first number, it is determined to switch the slave device to a new master device.
[0169] In some optional implementations of this embodiment, the above-mentioned determining step further includes:
[0170] For each master control device in the master control device group, when it is determined that the number of responses of the master control device is less than the number of responses sent by the slave device, the number of responses of the master control device is updated to the number of responses sent by the slave device.
[0171] In the device 500 provided by the above embodiment of the present disclosure, the determination unit 501 is configured to determine whether to switch the candidate device to a new target device based on the device switching information sent by the candidate device of the target device when it is determined that the target device satisfies the preset device switching condition, wherein the candidate device sends the device switching information after receiving the preset information; the switching unit 502 is configured to switch the candidate device to the new target device when it is determined that the candidate device is switched to the new target device. Thus, whether to switch the candidate device to a new target device is determined by the device switching information actively sent by the candidate device of the target device, thereby ensuring the normal operation of the system where the target device is located, and in the scenario where the target device is a master device and the candidate device is a slave device controlled by the master device, the linkage control can be ensured to proceed normally.
[0172] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure is provided. Figure 6 The electronic device 600 shown includes: at least one processor 601, a memory 602, and at least one network interface 604 and other user interfaces 603. The various components in the electronic device 600 are coupled together via a bus system 605. It is understood that the bus system 605 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 605 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, the bus system 605 is not shown in FIG. Figure 6 Various buses are labeled as bus system 605 .
[0173] The user interface 603 may include a display, a keyboard, or a pointing device (eg, a mouse, a trackball, a touch pad, or a touch screen).
[0174] It can be understood that the memory 602 in the embodiment of the present disclosure can be a volatile memory or a non-volatile memory, or can include both volatile and non-volatile memories. Among them, the non-volatile memory can be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory can be a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct RAM bus random access memory (DRRAM). The memory 602 described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0175] In some implementations, the memory 602 stores the following elements, executable units or data structures, or a subset thereof, or an extended set thereof: an operating system 6021 and an application 6022 .
[0176] The operating system 6021 includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application 6022 includes various application programs, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. The program for implementing the method of the embodiment of the present disclosure can be included in the application 6022.
[0177] In the embodiment of the present disclosure, by calling the program or instructions stored in the memory 602, specifically, the program or instructions stored in the application 6022, the processor 601 is used to execute the method steps provided by each method embodiment, for example, including: when it is determined that the target device satisfies the preset device switching condition, based on the device switching information sent by the candidate device of the above-mentioned target device, determining whether to switch the above-mentioned candidate device to a new target device, wherein the above-mentioned candidate device sends the above-mentioned device switching information after receiving the preset information; when it is determined that the above-mentioned candidate device is switched to the above-mentioned new target device, switching the above-mentioned candidate device to the above-mentioned new target device.
[0178] The method disclosed in the above embodiment of the present disclosure can be applied to the processor 601, or implemented by the processor 601. The processor 601 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit in the processor 601 or the instruction in the form of software. The above processor 601 can be a general processor, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field programmable gate array (Field Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present disclosure can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in the embodiment of the present disclosure can be directly embodied as a hardware decoding processor to execute, or the hardware and software units in the decoding processor can be executed. The software unit can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 602, and the processor 601 reads the information in the memory 602 and completes the steps of the above method in combination with its hardware.
[0179] It is understood that the embodiments described herein may be implemented in hardware, software, firmware, middleware, microcode, or a combination thereof. For hardware implementation, the processing unit may be implemented in one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPDevice, DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), general purpose processors, controllers, microcontrollers, microprocessors, other electronic units for performing the functions described in the present application, or a combination thereof.
[0180] For software implementation, the technology described herein can be implemented by a unit that performs the functions described herein. The software code can be stored in a memory and executed by a processor. The memory can be implemented in the processor or outside the processor.
[0181] The electronic device provided in this embodiment may be Figure 6 The electronic device shown in FIG. 1 may perform the following steps: Figure 2 All steps of the device switching method in Figure 2 For details, please refer to the technical effect of the device switching method shown. Figure 2 For the sake of brevity, the relevant description is not repeated here.
[0182] The embodiments of the present disclosure also provide a storage medium (computer-readable storage medium). The storage medium here stores one or more programs. The storage medium may include a volatile memory, such as a random access memory; the memory may also include a non-volatile memory, such as a read-only memory, a flash memory, a hard disk or a solid-state drive; the memory may also include a combination of the above-mentioned types of memory.
[0183] When one or more programs in the storage medium can be executed by one or more processors, the device switching method executed on the electronic device side can be implemented.
[0184] The processor is used to execute the communication program stored in the memory to implement the following steps of the device switching method performed on the electronic device side: when it is determined that the target device meets the preset device switching condition, based on the device switching information sent by the candidate device of the above-mentioned target device, determine whether to switch the above-mentioned candidate device to a new target device, wherein the above-mentioned candidate device sends the above-mentioned device switching information after receiving the preset information; when it is determined that the above-mentioned candidate device is switched to the above-mentioned new target device, switch the above-mentioned candidate device to the above-mentioned new target device.
[0185] The professionals should further realize that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this disclosure.
[0186] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0187] The specific implementation methods described above further illustrate the objectives, technical solutions and beneficial effects of the present disclosure in detail. It should be understood that the above description is only the specific implementation methods of the present disclosure and is not intended to limit the protection scope of the present disclosure. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure should be included in the protection scope of the present disclosure.
Claims
1. A device switching method, characterized in that: The method comprises: In the case where it is determined that the target device meets the preset device switching condition, the following determination steps are performed in sequence based on the number of responses sent by the slave devices in the slave device group controlled by the master device: based on the number of responses sent by the slave device and the number of responses of each master device in the master device group, it is determined whether to switch the slave device to a new master device; wherein the number of responses of the master device represents: the number of times the master device performs a second preset response after the slave device sends the device switching information; the response time represents: the time for the candidate device to perform a first preset response in the case where the target device meets the preset device switching condition; the candidate device performs a first preset response after receiving the preset response; The device switching information is sent after the target device satisfies the preset device switching condition; the device switching information includes the number of responses of the candidate device; the number of responses of the candidate device represents: the number of times the candidate device performs a first preset response when the target device satisfies the preset device switching condition; the target device that satisfies the preset device switching condition is a master device in a master device group controlled by a target server; the candidate device is a slave device in a slave device group controlled by a master device that has failed; the preset device switching condition includes a master device failure; when it is determined that the master device fails, each slave device in the slave device group controlled by the master device sends the device switching information including the number of responses; In the case where it is determined to switch the candidate device to a new target device, the candidate device is switched to the new target device.
2. The method according to claim 1, characterized in that The method further comprises: In the case where it is determined not to switch the slave device to a new master device, the determining step is continued based on the number of responses sent by the slave device that sends the next number of responses in the slave device group.
3. The method according to claim 1, characterized in that The determining whether to switch the slave device to a new master device based on the number of responses sent by the slave device and the number of responses of each master device in the master device group includes: Determine, from the master control device group, a master control device that meets a preset selection condition, and use the determined number of master control devices as a first number, wherein the preset selection condition includes: the number of responses of the master control device is less than or equal to the number of responses sent by the slave device; The number of master devices included in the master device group is taken as a second number, and based on the first number and the second number, it is determined whether to switch a slave device to a new master device.
4. The method according to claim 3, characterized in that The determining whether to switch the slave device to a new master device based on the first number and the second number includes: Calculating the difference between the second number and a preset positive integer; When it is determined that the product of the difference and the preset ratio is less than the first number, it is determined to switch the slave device to a new master device.
5. The method according to claim 3 or 4, characterized in that: After determining whether to switch from the slave device to the new master device, the determining step further includes: For each master control device in the master control device group, when it is determined that the number of responses of the master control device is less than the number of responses sent by the slave device, the number of responses of the master control device is updated to the number of responses sent by the slave device.
6. A device switching device, characterized in that: The device comprises: A determination unit is configured to determine whether to switch the candidate device to a new target device based on the device switching information sent by the candidate device of the target device when it is determined that the target device satisfies a preset device switching condition, wherein the candidate device sends the device switching information after receiving the preset information; the device switching information includes the number of responses of the candidate device; the number of responses of the candidate device represents: the number of times the candidate device performs a first preset response when the target device satisfies the preset device switching condition; the target device that satisfies the preset device switching condition is a master device in a master device group controlled by a target server; the candidate device is a slave device in a slave device group controlled by a failed master device; the preset device switching condition includes a failure of the master device; when it is determined that the master device fails, each slave device in the slave device group controlled by the master device sends device switching information including the number of responses; a switching unit, configured to switch the candidate device to the new target device if it is determined that the candidate device is to be switched to the new target device; The determining unit comprises: A determination subunit is configured to determine whether to switch the slave device to a new master device based on the number of responses and the response time, wherein the response time represents: when the target device satisfies the preset device switching condition, the time for the candidate device to perform the first preset response; The determining subunit comprises: The determination module is configured to perform the following determination steps based on the number of responses sent by the slave devices in the slave device group controlled by the master device in the order of response time: based on the number of responses sent by the slave devices and the number of responses of each master device in the master device group, determine whether to switch the slave device to a new master device, wherein the number of responses of the master device represents: the number of times the master device performs a second preset response after the slave device sends device switching information.
7. An electronic device, characterized in that: include: Memory for storing computer programs; A processor, configured to execute a computer program stored in the memory, and when the computer program is executed, implement the method described in any one of claims 1 to 5.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method described in any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Input / output unit and control system
CA2818367A1
Methods, apparatuses and computer program products for providing an optimized handover preparation and execution operation
CN103718604A
Method and device for selecting master control equipment and equipment linkage system
CN110687809A
Cell switching method and device, storage medium, user equipment and base station equipment
CN112929936A
Cluster election processing method and device, equipment and storage medium
CN113014634A
