Master-slave switching method and earphone equipment

By cached the target data and historical data of the headphone device, and judged based on the cache occupation information, the master-slave switching is performed after the data transfer is completed, which solves the problem of data loss during switching of traditional TWS headphones, and improves the stability and normality of interactive functions.

CN120075672APending Publication Date: 2025-05-30ANKER INNOVATIONS TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311605101.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-11-28
Publication Date
2025-05-30

AI Technical Summary

Technical Problem

When switching between the master and slave, traditional TWS headsets lead to abnormal interaction functions between the smart mobile terminal and the headset and poor stability, mainly due to data loss.

Method used

By obtaining the master-slave switching instruction, the target data of the second headset is cached to the first cache space, and the historical data of the first headset is cached to the second cache space. According to the cache occupation information, the master-slave switching is performed and the target data is sent to the new master-slave headset.

Benefits of technology

It effectively avoids data loss, improves the stability of master-slave switching, and ensures the normal operation of the interactive function between the smart mobile terminal and the headset.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120075672A_ABST
    Figure CN120075672A_ABST
Patent Text Reader

Abstract

The invention relates to a master-slave switching method and earphone equipment. The method comprises the steps that a master-slave switching instruction is acquired, target data of a second earphone are cached to a first cache space, the master-slave switching instruction is used for indicating master-slave switching of a first earphone and the second earphone, and the target data are data needing to be sent to a master earphone; caching the historical data in the first earphone to a second cache space, and switching the second earphone to a main earphone according to cache occupation information of the historical data in the second cache space; and sending the target data in the first cache space to the main earphone. By adopting the method, data loss caused by change of a monitoring link in a data transfer process can be effectively avoided, and the stability of master-slave switching is further improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of wireless communication technologies, and in particular, to a master-slave switching method and a headset device. Background Art

[0002] In the scenario of using TWS headsets, especially in the scenario of interacting with an application (APP) of a smart mobile terminal through TWS headsets, there is a distinction between the master and slave TWS headsets. The specific working principle is that the smart mobile terminal connects to the master headset, and then the master headset quickly connects to the slave headset wirelessly to achieve true wireless separation and use of the left and right Bluetooth channels. Based on the working principle of TWS headsets, a corresponding listening link needs to be built between the TWS headsets and the smart mobile terminal.

[0003] However, in the traditional technical solution for realizing master-slave switching of TWS headsets through the listening link, the data in the master headset (Host) will be directly discarded. Due to the loss of data, the interaction function between the smart mobile terminal and the TWS headsets will be abnormal and the stability will be poor. Summary of the Invention

[0004] Based on this, it is necessary to provide a master-slave switching method and a headset device with strong stability for the above technical problems.

[0005] In a first aspect, this application provides a master-slave switching method applied to a headset device. The headset device includes a first headset and a second headset. The method includes:

[0006] Obtain a master-slave switching instruction, and cache the target data of the second headset into a first cache space. The master-slave switching instruction is used to indicate master-slave switching between the first headset and the second headset, and the target data is the data to be sent to the master headset;

[0007] Cache the historical data in the first headset into a second cache space, and switch the second headset to the master headset according to the cache occupancy information of the historical data in the second cache space;

[0008] Send the target data in the first cache space to the master headset.

[0009] In one embodiment, the caching of the target data of the second headset into the first cache space includes:

[0010] Generate a timer according to a preset data caching period;

[0011] If the timing of the timer is less than or equal to the data caching period, cache the target data through the first cache space.

[0012] In one embodiment, the method further includes:

[0013] If the timing of the timer is greater than the data caching period, obtain the cache occupancy information of the historical data in the second cache space.

[0014] In one embodiment, according to the cache occupancy information of the historical data in the second cache space, switching the second earphone to the main earphone includes:

[0015] Send the historical data in the second cache space to the mobile terminal;

[0016] According to the space capacity of the second cache space during the sending process, obtain the cache occupancy information of the historical data in the second cache space;

[0017] If it is determined according to the cache occupancy information that all the historical data in the second cache space has been sent to the mobile terminal, then switch the target device to the main earphone.

[0018] In one embodiment, the sending the target data in the first cache space to the main earphone includes:

[0019] Construct multiple Bluetooth communication links;

[0020] Send the target data in the first cache space to the main earphone through the multiple Bluetooth communication links.

[0021] In one embodiment, the sending the target data in the first cache space to the main earphone through the multiple Bluetooth communication links includes:

[0022] Obtain the communication control identifier carried in the target data, where the communication control identifier is used to determine the target link corresponding to the target data;

[0023] According to the communication control identifier, filter out the target link from the multiple Bluetooth communication links;

[0024] According to the mapping relationship between the communication control identifier and the data recipient, and the target link, send the target data in the first cache space to the main earphone.

[0025] In one embodiment, the first cache space is a message cache queue;

[0026] The caching the target data of the second earphone to the first cache space includes:

[0027] Construct a message cache queue;

[0028] Cache the target data to the message cache queue.

[0029] In a second aspect, the present application also provides a headphone device. The headphone device includes a first headphone and a second headphone, and further includes:

[0030] A first cache processing module, configured to obtain a master-slave switching instruction, cache target data of the second headphone into a first cache space, where the master-slave switching instruction is used to indicate a master-slave switch between the first headphone and the second headphone, and the target data is data to be sent to the master headphone;

[0031] A second cache processing module, configured to cache historical data of the first headphone into a second cache space, and switch the second headphone to the master headphone according to the cache occupancy information of the historical data in the second cache space;

[0032] A cache data transmission module, configured to send the target data in the first cache space to the master headphone.

[0033] In one embodiment, the first cache processing module is further configured to generate a timer according to a preset data caching period; if the timing of the timer is less than or equal to the data caching period, cache the target data through the first cache space.

[0034] In one embodiment, the first cache processing module is further configured to traverse the historical data cached in the second cache space when the timing of the timer is greater than the data caching period, and generate the cache occupancy information of the historical data.

[0035] In one embodiment, the second cache processing module is further configured to send the historical data in the second cache space to a mobile terminal; obtain the cache occupancy information of the historical data in the second cache space according to the space capacity of the second cache space during the sending process; if it is determined according to the cache occupancy information that all the historical data in the second cache space has been sent to the mobile terminal, switch the target device to the master headphone.

[0036] In one embodiment, the cache data transmission module is further configured to build a plurality of Bluetooth communication links; send the target data in the first cache space to the master headphone through the plurality of Bluetooth communication links.

[0037] In one embodiment, the cache data transmission module is further configured to obtain a communication control identifier carried in the target data, where the communication control identifier is used to determine a target link corresponding to the target data; screen a target link from the plurality of Bluetooth communication links according to the communication control identifier; and send the target data in the first cache space to the master headphone according to the mapping relationship between the communication control identifier and the data recipient and the target link.

[0038] In one embodiment, the first cache space is a message cache queue; the first cache processing module is further configured to build a message cache queue; and cache the target data into the message cache queue.

[0039] This application provides a master-slave switching method and a headset device. The solution first obtains a master-slave switching instruction, which is used to switch the second headset from the original slave headset to the master headset. Before the switching is completed, it is first necessary to cache the target data to be sent to the second headset through the first cache space. During the caching of the target data, the historical data when the first headset is the master headset is cached into the second cache space for subsequent processing. The data sent to the master headset is cached through the first cache space and then transmitted to the second master headset after the historical data has been migrated; the historical data generated before the master-slave switching is cached through the second cache space, replacing the direct clearing method, effectively avoiding data loss. The solution will judge whether the historical data of the current device has been transferred based on the cache occupancy information of the historical data in the second cache space, and then perform the master-slave switching, switch the second headset to the master headset, and send the target data in the first cache space to this master headset; by judging the cache occupancy information of the historical data in the second cache space, it is ensured that all the historical data in the first headset has been transferred, and after the transfer of the historical data is completed, the master-slave switching is performed to avoid data loss caused by a sudden change in the communication link during the data transfer process, further improving the stability of the master-slave switching. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is an application environment diagram of the master-slave switching method in one embodiment;

[0041] Figure 2 It is a flowchart of the master-slave switching method of a traditional technical solution;

[0042] Figure 3 It is a flowchart of the master-slave switching method in one embodiment;

[0043] Figure 4 It is a flowchart of the sub-steps of caching the target data in one embodiment;

[0044] Figure 5 It is a flowchart of the master-slave switching method in another embodiment;

[0045] Figure 6 It is a structural block diagram of the headset device in one embodiment;

[0046] Figure 7 It is an internal structure diagram of the headset device in one embodiment. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0047] In order to make the objectives, technical solutions, and advantages of the present application more clear and understandable, the present application will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0048] The master-slave switching method provided by the embodiments of the present application can be applied to an application environment as Figure 1 shown. In this application environment, the terminal 102 communicates and exchanges data with the TWS earphone 104 through the Bluetooth communication protocol. The TWS earphone 104 includes a left earphone 1041 and a right earphone 1042. Since the two earphones are separated independently, there are master-slave distinctions and implementation scenarios for master-slave switching. Among them, in the wearing and using scenario of the earphones, usually one side of the earphone is used as the master earphone to directly establish a communication link with the terminal 102 for data exchange. For example, when the left earphone 1041 is used as the master earphone and is connected to the terminal 102, the right earphone 1042 is used as the slave earphone. It does not directly communicate with the terminal 102, but first communicates with the master earphone, that is, the left earphone 1041, and transmits the data content generated by the right earphone 1042 in response to various interaction operations to the left earphone 1401 first, and then the left earphone 1041 transmits and exchanges data with the terminal 102. Similarly, for the audio data or other interaction operation data sent by the terminal to the right earphone 1042, it also needs to be sent to the left earphone 1401 first, and then the left earphone 1401 sends the data content to the right earphone 1402.

[0049] Based on the situation of master and slave earphones in the TWS earphone 104, in some relatively common scenarios, for example, when the left earphone 1401 has a low battery and it is necessary to use the right earphone 1402 alone, it is necessary to perform necessary master-slave switching so that the right earphone 1402 serves as the new master earphone and communicates with the terminal 102. In this application environment, the master-slave switching method adopted is that first, due to the event that the left earphone 1401 has a low battery and disconnects from the terminal 102, a master-slave switching instruction is triggered. This master-slave switching instruction is used to remove the master earphone status of the left earphone 1401 and make the right earphone 1402 the new master earphone.

[0050] However, since there may be a certain amount of data information in the cache space of the master earphone when the left earphone 1401 is the master earphone, in traditional technical solutions, as Figure 2 shown, for this type of data information, it is usually directly discarded, which may lead to the loss of data sent by the earphone to the mobile phone side, errors in the display status of the functions or operations being executed in the terminal 102, or abnormal operation of the application software.

[0051] To ensure that the data information can be retained and data loss is avoided, for the above application environment, the master-slave switching method proposed in this application first temporarily stores the data content to be sent to the new master earphone, i.e., the right earphone 1402, through the first buffer space. At the same time, the master earphone data generated when the left earphone 1401 is the master earphone, or the historical data cached in the left earphone 1401, is transferred to the second buffer space. In this application environment, the second buffer space refers to the host interface controller (HCI) layer in the Bluetooth low-level software stack. The HCI layer can store the master earphone data or historical data and further send the data to the terminal 102. After the transferred master earphone data or historical data is sent to the terminal 102 via the second buffer space, the terminal 102 receives and saves it. When the transferred master earphone data or historical data is sent through the second buffer space until there is no data cached in the buffer space of the second buffer space, it is determined that the master earphone data and historical data of the left earphone 1401 have been transferred. Further, the left earphone 1401 and the right earphone 1402 will respond to the master-slave switching instruction, clear the master earphone state of the left earphone 1401, determine the right earphone 1402 as the new master earphone, directly establish a communication link with the terminal 102, and based on the pre-set Bluetooth communication protocol, send the data content temporarily stored in the first buffer space that needs to be sent to the new master earphone to the right earphone 1402, thus completing the master-slave switching of the left and right earphones. It should be added that the terminal 102 in the above application environment can be but is not limited to various personal computers, laptop computers, smart phones, tablet computers, Internet of Things devices, and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart in-vehicle devices, etc. The portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 can be implemented by an independent server or a server cluster composed of multiple servers.

[0052] In one embodiment, as Figure 3 shown, a master-slave switching method is provided. Taking the left earphone 1041 of the TWS earphones applied to Figure 1 as an example, the method includes the following steps:

[0053] Step 302, obtain a master-slave switching instruction, and cache the target data of the second earphone in the first buffer space. The master-slave switching instruction is used to indicate the master-slave switching between the first earphone and the second earphone, and the target data is the data to be sent to the master earphone.

[0054] The first earphone and the second earphone in the embodiments may refer to the left earphone and the right earphone (or the right earphone and the left earphone). Exemplarily, in a scenario, before the master-slave switch, if the left earphone is the master earphone and the right earphone is the slave earphone, then the first earphone refers to the left earphone and the second earphone refers to the right earphone; after the switch is completed, the second earphone, that is, the right earphone, becomes the new master earphone. Or, in another scenario, before the master-slave switch, if the right earphone is the master earphone and the left earphone is the slave earphone, then the first earphone refers to the right earphone and the second earphone refers to the left earphone; after the switch is completed, the second earphone, that is, the left earphone, becomes the new master earphone.

[0055] Before the master-slave switch in the embodiments, due to the constraint of the master-slave relationship, the slave earphone communicates and exchanges data directly with the master earphone, and then the master earphone sends the data of the slave earphone it receives to the smart terminal. After the master-slave switch is completed, the new master earphone will directly establish a communication link with the smart terminal and perform data interaction based on this communication link. Further, for the master earphone in the embodiments, its communication or data interaction with the smart terminal can be connected and data-interacted through any wireless communication method. For example, the embodiments use the Bluetooth wireless communication protocol for communication, and based on the Bluetooth communication technology standard, it is used to perform data interaction with the mobile terminal at a short distance to form a personal area network (PAN). The first buffer space in the embodiments refers to a certain storage space reserved in the memory space of the device, and these storage spaces are used to buffer the input or output data. The device can be the current device that needs to perform the master-slave switch; or a device that maintains a communication connection with the current device and has a space capable of data caching in this device. In the embodiments, the target data may refer to the data content sent from the smart terminal to the master earphone during the data interaction process. It should be noted that the master earphone to which the target data is to be sent refers to the master earphone after the master-slave switch is completed, that is, the target device in the embodiments.

[0056] Exemplarily, taking the scenario of the master-slave switch of TWS earphones as an example, in this scenario, the embodiments preset a status monitoring program, which is used to monitor the working status of the TWS earphones. For example, in this offline scenario, when the left earphone is the master earphone and it is detected that the battery power of the left earphone is low and the communication connection with the smart terminal is about to be disconnected, a corresponding master-slave switch instruction will be triggered, so that the right earphone can be used as the new master earphone to continue to maintain the usage state of the TWS earphones. For example, in the usage scenario of watching videos through TWS earphones, when the battery power of the left earphone is low and it disconnects from the mobile phone, the right earphone should still maintain normal audio output. The specific statement content of this master-slave switch instruction is to assign the master earphone identifier of the left earphone to the right earphone, clear the master earphone status of the left earphone, and the master earphone data generated in the master earphone status.

[0057] To maintain the integrity and coherence of the user experience, after the left earphone disconnects due to low battery, the embodiment needs to continue to maintain data transmission and interaction between the smart terminal and the TWS earphones. For the data packets or data content that the smart terminal needs to send to the main earphone, they need to be temporarily stored in the form of a cache space. Specifically, in the embodiment, the cache space can be set in the application software (Application, App) layer of the smart terminal. According to the time sequence of the data packets generated by the smart terminal to maintain the corresponding operations or functions, the data packets are sent to the cache space for storage; after the master-slave switch is completed, the data packets in the cache space are then sent to the new main earphone, that is, the right earphone in the embodiment.

[0058] Step 304, cache the historical data in the first earphone into the second cache space, and switch the second earphone to the main earphone according to the cache occupancy information of the historical data in the second cache space.

[0059] Similarly, the second cache space also buffers the input or output data. In some embodiments, the host controller interface (HCI) layer of the main earphone can be used as the second cache space. The historical data in the embodiment refers to the response data formed based on the operation instructions or the data received from the smart terminal during the data interaction between the current device as the main earphone and the smart terminal. The aforementioned historical data can also be referred to as the main earphone data in the embodiment, and the main earphone data in the embodiment is cached in the storage space of the main earphone. The cache occupancy information in the embodiment is used to describe the cache information situation in the second cache space; for example, at a certain moment, it can be known through the cache occupancy information that the cache in the second cache space has been cleared, that is, there is no cache data.

[0060] Exemplarily, the second cache space in the embodiment can refer to the host controller interface (HCI) layer in the Bluetooth software service stack. The HCI layer is the interface between the main earphone (HOST) and the controller (Controller). The HCI layer defines a specific format to control the Bluetooth chip to perform corresponding actions, provides a unified interface for accessing the HCI controller for the upper layer of the Bluetooth low-level software stack, and its interface is a series of instructions and events.

[0061] For further illustration, taking the scenario of master-slave switching of TWS earphones as an example, after the master-slave switching instruction is triggered, the left earphone is the initial master earphone, and due to low battery, it is about to disconnect the communication connection with the smart terminal. However, in the HOST state machine of the left earphone, there is still some data content generated when the left earphone, as the master earphone, interacts with the terminal device; for example, during the process of the user wearing the TWS earphones to watch a video, through the intelligent operation gestures of the TWS earphones, the playback of the video is controlled, and this control instruction, due to the upcoming power-off disconnection of the left earphone, is stored in the HOST state machine. In view of the above situation, in the embodiment, the data of the master earphone retained in the HOST state machine will be sent to the HCI layer in the Bluetooth low-level software stack, and then through the interface defined by the HCI layer, data transmission will be carried out with the smart terminal. More specifically, when caching the historical data in the left earphone through the HCI layer in the Bluetooth low-level software stack, the HCI layer will send the historical data cached in the HCI layer to the corresponding smart terminal for storage according to the communication interface determined by the TWS earphones and the smart terminal. , Or it is transmitted to the specific functional components or software APP in the software layer of the smart terminal, so that the interaction operation process that was ongoing before the master-slave switching can continue to be maintained, or the software APP can run smoothly, avoiding the occurrence of interaction interruption or abnormal operation due to data loss during the master-slave switching process. For example, in the scenario of making a call through TWS earphones, under normal circumstances, the left earphone, as the master earphone, transmits call data to the mobile phone. The mobile phone sends the audio data generated by one party during the call to the left earphone, and the left earphone, as the master earphone, controls the right earphone, which is the slave earphone, to output the audio data; moreover, the left earphone will also collect the real-time voice of the other party during the call and convert it into audio data and return it to the mobile phone. However, when the left earphone is about to lose power and disconnect, the right earphone will switch to the new master earphone and maintain the audio data transmission with the mobile phone. For the audio data that was stored in the HOST layer of the master earphone before the disconnection of the left earphone or before removing the master earphone state and has not been sent to the mobile phone, it will be all cached in the HCI layer and then sent to the mobile phone by the HCI layer, which can avoid the loss of audio data during the call due to the master-slave switching. During the process of transmitting historical data, in the embodiment, the cached data in the HCI layer will also be monitored in real time to determine whether the HCI layer has sent all the historical data to the smart terminal, realizing the clearing of the cache space. After determining that the HCI layer has sent all the historical data cached by it, the master-slave switching in the TWS earphones will be formally carried out, the master earphone state of the left earphone will be cleared, and at the same time, the right earphone will be given the master earphone identifier and serve as the new master earphone to interact with the smart device.

[0062] Step 306, send the target data in the first cache space to the master earphone.

[0063] In the embodiment, the target data is sent to the main headset, and the data needs to be transmitted according to the communication protocol supported by both the main headset and the smart terminal. Taking the data transmission process of the Bluetooth protocol as an example, the Bluetooth communication protocol can be diverse, and the Bluetooth protocols that can be used include but are not limited to the Serial Port Profile (SPP) and the Generic Attribute Profile (GATT). Before realizing the communication connection between devices based on the Bluetooth communication protocol, it is necessary to build a corresponding communication channel based on the pre-selected Bluetooth communication protocol.

[0064] Exemplarily, the serial port protocol SPP is used in the embodiment to realize the Bluetooth communication connection. Since SPP defines how to establish a virtual serial port communication between two devices supporting the SPP Bluetooth protocol, in the embodiment, it is necessary to send the target data cached in the first cache space to the new master headset through the virtual serial port.

[0065] The master-slave switching method first obtains the slave switching instruction, and determines that the current device and the target device need to perform the master-slave switching according to the instruction content; then the target data to be sent to the new master earphone is cached through the first cache space. In the process of caching the target data, the method caches the historical data received and stored when the current device is used as the master earphone in the second cache space for subsequent processing. The method caches the data sent to the new master earphone through the first cache space, waits for the historical data to be transferred before transmitting it to the new master earphone, and the method caches the historical data generated before the master-slave switching through the second cache space, replacing the traditional method of directly clearing the historical data of the current device and sending the target data directly to the new master earphone, thereby avoiding data loss. The method will determine whether the historical data of the current device has been transferred based on the cache occupancy information of the historical data in the second cache space, and then perform the master-slave switching, and send the target data in the first cache space to the new master earphone, that is, the target device. The method judges the cache occupancy information of historical data in the second cache space to ensure that all historical data in the current device have been transferred. After the transfer of historical data is completed, the master-slave switching is performed to avoid data loss due to sudden changes in the communication link during the data transfer process, further improving the stability of the master-slave switching.

[0066] In order to trigger the data cache operation more accurately and intelligently, in one embodiment, Figure 4 As shown, the process of caching the target data of the second earphone into the first cache space includes:

[0067] Step 402: Generate a timer according to a preset data caching period.

[0068] In the embodiment, the data caching period is a preset operation processing time limit for storing target data into the first cache space. That is, during the data caching period, the operation of storing the target data into the first cache space will be continuously executed. The timer in the embodiment can be a general timing function implemented based on the clock source in the current device, or an advanced timing function implemented through an external clock source or directly from other timer waiting modes.

[0069] Exemplarily, before caching the target data content to be sent to the new main earphone in the embodiment, it is necessary to initialize or enable a built-in timer in the current device. At the same time, obtain the preset timing period, that is, the data caching period, to constrain and judge the processing time of the target data caching.

[0070] Step 404: If the timing of the timer is less than or equal to the data caching period, cache the target data through the first cache space.

[0071] Exemplarily, in the embodiment, by comparing the timing of the timer with the data caching period, it is possible to automatically detect whether the target data caching process is completed. Specifically, when the timing in the timer is less than or equal to the preset data caching period, it can be determined that the process of writing the target data into the cache space is still ongoing. Until the timing of the timer is equal to the preset data caching period, it is determined that the target data has been cached, and then the next step of judging the caching situation of the historical data can be carried out. In the embodiment, by setting the data caching period and the timer, the effect of automatically detecting the caching period of the target data can be achieved.

[0072] In one embodiment, when the timing set in the device has reached the preset data caching period, that is, after the timer times out, the method further includes the following specific steps: If the timing of the timer is greater than the data caching period, obtain the cache occupancy information of the historical data in the second cache space.

[0073] Specifically, in the embodiment, the purpose of setting the timer and the data caching period is to automatically trigger the detection of the cache cleaning situation of the historical data after caching the target data. It should be noted that in the embodiment, cache cleaning refers to transferring the historical data in the second cache space, for example, sending it to the intelligent device side for long-term storage.

[0074] Exemplarily, in an embodiment, the timing in the timer is obtained in real time, and it is determined whether the caching of the target data is completed according to a preset data caching period; alternatively, in the embodiment, the timer can be directly set to the data caching period, and then by directly determining whether the timer reaches this time or times out, the detection of the caching cleaning situation of the historical data is automatically triggered.

[0075] In order to ensure that the data of the current device can be reasonably stored before the master-slave switch is completed and avoid data loss, in one embodiment, in the method, the process of switching the second earphone to the master earphone according to the caching occupancy information of the historical data in the second cache space may include the following steps:

[0076] Step 1, sending the historical data in the second cache space to the mobile terminal.

[0077] Step 2, obtaining the caching occupancy information of the historical data in the second cache space according to the space capacity of the second cache space during the sending process.

[0078] Step 3, if it is determined according to the caching occupancy information that all the historical data in the second cache space has been sent to the mobile terminal, then switching the target device to the master earphone.

[0079] Among them, the caching occupancy information is used to characterize the transmission situation of the historical data in the second cache space. More specifically, the transmission situation referred to in the embodiment specifically refers to whether the data in the cache space has been completely transferred and the cache space has been emptied.

[0080] Exemplarily, take the master-slave switching process in the TWS earphones of a smart terminal as an example. The left earphone is the initial master earphone and needs to complete the master-slave switching before it completely powers off and disconnects, that is, switch the right earphone to the new master earphone. In the embodiment, the HCI layer in the Bluetooth low-level software stack is used as the cache space for the master earphone data of the left earphone. To avoid abnormal operations of the smart terminal caused by the loss of master earphone data during the master-slave switching process, in the embodiment, before the right earphone is switched to the new master earphone, the master earphone status data of the current device cached in the HCI layer needs to be sent to the local area of the smart terminal for storage. Therefore, before switching the master earphone in response to the master-slave switching instruction, in the embodiment, it will periodically query whether all the master earphone data cached in the HCI layer has been sent to the smart device for transfer storage. The HCI layer generates corresponding cache occupancy information according to the cache occupancy situation in its cache space and feeds it back to the left earphone. Further, after it is determined through the cache occupancy information of the HCI layer that all the master earphone data of the left earphone has been completely transferred and stored, based on the master-slave switching instruction to switch the right earphone to the master earphone, the right earphone is marked as the new master earphone, and the target data cached in the previous step is sent to the right earphone to realize data interaction between the right earphone and the smart terminal.

[0081] In one embodiment, the process of sending the target data in the first cache space to the master earphone according to the preset Bluetooth communication protocol in the method may include the following steps:

[0082] Step 1, construct multiple Bluetooth communication links.

[0083] Step 2, send the target data in the first cache space to the master earphone through the multiple Bluetooth communication links.

[0084] Exemplarily, since the Bluetooth communication protocols adopted between different devices may be different, and before the target device becomes the master earphone, it is the slave device of the current device and does not form a communication link with other devices. Therefore, in the embodiment, before sending the target data to the new master earphone, a communication link with the master earphone needs to be established first.

[0085] Further, since various Bluetooth communication protocols can be adopted in the embodiment, for example, the serial port protocol SPP and the general attribute protocol GATT, the smart terminal will establish multiple communication links with various different devices. Furthermore, the new master earphone needs to select a communication link according to the communication protocol supported by its device, and after determining the communication link that meets the device communication protocol, send the previously cached target data to the new master earphone through this communication link. In the embodiment, the communication links can be screened and matched to support communication methods of multiple Bluetooth communication protocols, and the usability is stronger.

[0086] In one embodiment, the process of sending the target data in the first buffer space to the main earphone through multiple Bluetooth communication links in the method may include the following steps:

[0087] Step 1: Obtain the communication control identifier carried in the target data. The communication control identifier is used to determine the target link corresponding to the target data.

[0088] Step 2: Filter out the target link from multiple Bluetooth communication links according to the communication control identifier.

[0089] Step 3: Send the target data in the first buffer space to the main earphone according to the mapping relationship between the communication control identifier and the data receiver, and the target link.

[0090] Among them, the communication control identifier is used to determine the communication link corresponding to the target data, and this communication link is one of the multiple optional communication links that the intelligent terminal can provide. The mapping relationship in the embodiment is used to describe the mapping relationship between a specific communication link and a device; the device that can satisfy the mapping relationship in the embodiment should be a device that supports the Bluetooth communication protocol corresponding to the communication link.

[0091] Exemplarily, the selected communication identifier in the embodiment is CID (channel id). CID is the link identifier of the L2CAP layer logical link of the Bluetooth communication link. According to the link identifier of the communication link carried in the target data and the mapping relationship between the link identifier stored in the intelligent device and other devices, the device corresponding to the target data, that is, the new main earphone after the master-slave switch, is determined. More specifically, in the embodiment, the main earphone specified for the transmission of the target data can be determined according to the CID parsed from the target data and the mapping relationship between the CID stored in the intelligent device and other main earphones. Through the link identifier of the L2CAP layer logical link, the embodiment can realize the correct distribution of the target data, which is beneficial to saving the number of data links between devices.

[0092] In one embodiment, the first buffer space can be implemented in the data format of a message buffer queue, that is, the process of constructing the first buffer space in the method and caching the target data through the first buffer space may include the following steps:

[0093] Step 1: Construct a message buffer queue.

[0094] Step 2: Cache the target data into the message buffer queue.

[0095] Among them, the message buffer queue, also known as the packet buffer queue, essentially belongs to a communication mechanism. The data transmitted based on this communication mechanism has a specific structure, rather than a simple byte stream. Specifically, this specific structure is a queue, where data enters the queue from the tail and is output from the head. The target data in the embodiment can refer to the data content sent from the smart terminal to the main earphone during the data interaction process.

[0096] Exemplarily, taking the scenario of master-slave switching of TWS earphones as an example, in order to maintain the integrity and coherence of the user operation experience, in the case where the left earphone is about to disconnect due to low battery, the embodiment still needs to continue to maintain the data transmission and interaction between the smart terminal and the TWS earphones. For the data packets or data content that the smart terminal needs to send to the main earphone, it is necessary to temporarily store the data in the form of a message buffer queue. Specifically, in the embodiment, the message buffer queue can be set in the application software (Application, App) layer of the smart terminal. According to the time sequence of the data packets generated by the smart terminal to maintain the corresponding operations or functions, the data packets are sent to the message buffer queue for storage; after the master-slave switching is completed, the data packets in the message buffer queue are sent to the new main earphone, that is, the right earphone in the embodiment, in a first-in-first-out manner.

[0097] More specifically, according to the appendix in the specification Figure 5 , combined with the scenario of master-slave switching of TWS earphones, the complete and detailed process description of the master-slave switching method provided by the technical solution of this application is as follows:

[0098] First, in the embodiment, there is a preset status monitoring program, which is used to monitor the working status of the TWS earphones. For example, when it is detected that the battery of the left earphone is low and it is about to disconnect from the mobile phone, a corresponding master-slave switching instruction needs to be triggered so that the right earphone can continue to maintain the usage status of the TWS earphones as the new main earphone.

[0099] Then, in order to maintain the integrity and coherence of the user operation experience, after the left earphone disconnects due to low battery, the embodiment needs to continue to maintain the data transmission and interaction between the mobile phone and the TWS earphones. For the data packets or data content that the mobile phone needs to send to the main earphone, it is necessary to temporarily store the data in the form of a cache space. In the embodiment, the cache space can be set in the application software (Application, App) layer of the mobile phone. According to the time sequence of the data packets generated by the mobile phone to maintain the corresponding operations or functions, the data packets are sent to the cache space for storage.

[0100] Secondly, in the embodiment, the historical data stored in the left earphone will be sent to the HCI layer in the Bluetooth low-level software stack. Through the interface defined by the HCI layer, data is transmitted with the mobile phone. After transmitting the stored main earphone data to the mobile phone, the master-slave switchover is performed.

[0101] Furthermore, in the embodiment, the HCI layer in the Bluetooth low-level software stack caches the historical data in the left earphone. Meanwhile, the HCI layer will send the historical data cached in the HCI layer to the mobile phone terminal for storage according to the communication interface determined by the TWS earphone and the mobile phone. After it is determined that the HCI layer has finished sending all the historical data it has cached, the master-slave switchover in the TWS earphone is formally performed.

[0102] Finally, in the embodiment, the serial port protocol SPP is used to implement the Bluetooth communication connection. Since SPP defines how to establish a virtual serial port communication between two BT devices; therefore, in the embodiment, the cached target data needs to be sent to the new master earphone through the virtual serial port.

[0103] It can be understood that in this embodiment scenario, after the left earphone resumes the connection with the mobile phone, the second master-slave switchover can be achieved through the same process as the above steps, and the process can be briefly described as follows:

[0104] Step 1, the current device receives the master-slave switchover instruction, enters the master-slave switchover preparation state, and simultaneously starts the master-slave switchover timer.

[0105] Step 2, within the time limit set by the master-slave switchover timer, in order to keep the data interaction process that was ongoing before the master-slave switchover stable, the SPP or GATT data packets generated by the intelligent terminal in response to the data interaction during the data interaction process are cached through the message cache queue.

[0106] Step 3, during the caching process of the SPP or GATT data packets, the current device that temporarily maintains the master earphone state will continue to perform the transfer and storage of the main earphone data. Specifically, the SPP data packets, GATT data packets, or other state machine data packets generated by the current device in the master earphone state and not yet completed in transmission are all transmitted to the HCI layer, and the HCI layer transmits the foregoing data packets to the intelligent terminal.

[0107] Step 4: When the master-slave switch timer completes a timing cycle, it will detect whether there are still unsent packets in the HCI layer. When it is detected that the HCI layer has completed the transmission of SPP packets, GATT packets, or other state machine packets, the master-slave switch process is executed, and the current device is switched to the slave headphone state or the master headphone state of the current device is removed, and according to the device in the slave headphone state specified in the master-slave switch instruction, it is switched to the master headphone state to become the new master headphone; and further, the SPP or GATT packets cached in the message cache queue in Step 2 are sent to the new master headphone. After the execution is completed, the preparation state of the master-slave switch set in Step 1 is cleared.

[0108] In summary, the problems existing in the master-slave switch of TWS during SPP or GATT data interaction in the traditional technical solution are mainly the loss of data or the invalidation of the application scenario caused by the failure of the master-slave switch. The method in this embodiment solves the above problems from two aspects. First, when triggering the master-slave switch, the APP layer caches the SPP or GATT packets, and when the master-slave switch is completed, the cached data is synchronized to the new master ear, and the new master ear uploads the SPP or GATT data. Second, when the master-slave switch occurs, the data in the HOST state machine is sent down to the HCI, and the master-slave switch is performed after the HCI finishes sending the data.

[0109] It should be understood that although the steps in the flowcharts involved in the above embodiments are shown in sequence according to the arrows, these steps do not necessarily have to be executed in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps has no strict order limit, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages. These steps or stages do not necessarily have to be executed at the same time, but can be executed at different times. The execution order of these steps or stages does not necessarily have to be sequential, but can be executed alternately or alternately with at least a part of other steps or steps or stages in other steps.

[0110] Based on the same inventive concept, the embodiment of the present application also provides a headphone device for implementing the master-slave switch method described above. The implementation solution for solving the problem provided by this device is similar to the implementation solution described in the above method. Therefore, the specific limitations in one or more headphone device embodiments provided below can refer to the limitations on the master-slave switch method in the above text, and will not be repeated here.

[0111] In one embodiment, as Figure 6As shown, a headphone device 600 is provided, including a first headphone and a second headphone, and further including: a first buffer processing module 601, a second buffer processing module 602, and a buffer data transmission module 603, where:

[0112] An instruction receiving module 601, configured to obtain a master-slave switching instruction, where the master-slave switching instruction is used to indicate performing a master-slave switch between the current device and a target device, and the target device is the slave headphone of the current device.

[0113] The first buffer processing module 601 is configured to obtain a master-slave switching instruction, cache target data of the second headphone into a first buffer space, where the master-slave switching instruction is used to indicate performing a master-slave switch between the first headphone and the second headphone, and the target data is data to be sent to the master headphone;

[0114] The second buffer processing module 602 is configured to cache historical data of the first headphone into a second buffer space, and switch the second headphone to be the master headphone according to the cache occupancy information of the historical data in the second buffer space;

[0115] The buffer data transmission module 603 is configured to send the target data in the first buffer space to the master headphone.

[0116] In one embodiment, the first buffer processing module 601 is further configured to generate a timer according to a preset data caching period; if the timing of the timer is less than or equal to the data caching period, cache the target data through the first buffer space.

[0117] In one embodiment, the first buffer processing module 601 is further configured to traverse the historical data cached in the second buffer space when the timing of the timer is greater than the data caching period, and generate cache occupancy information of the historical data.

[0118] In one embodiment, the second buffer processing module 602 is further configured to send the historical data in the second buffer space to a mobile terminal; obtain the cache occupancy information of the historical data in the second buffer space according to the space capacity of the second buffer space during the sending process; if it is determined according to the cache occupancy information that all the historical data in the second buffer space has been sent to the mobile terminal, switch the target device to be the master headphone.

[0119] In one embodiment, the buffer data transmission module 603 is further configured to construct a plurality of Bluetooth communication links; send the target data in the first buffer space to the master headphone through the plurality of Bluetooth communication links.

[0120] In one embodiment, the cache data transmission module 603 is further configured to obtain a communication control identifier carried in the target data, where the communication control identifier is used to determine a target link corresponding to the target data; filter out the target link from multiple Bluetooth communication links according to the communication control identifier; and send the target data in the first cache space to the main earphone according to the mapping relationship between the communication control identifier and the data receiver and the target link.

[0121] In one embodiment, the first cache space is a message cache queue; the first cache processing module 601 is further configured to construct the message cache queue; and cache the target data into the message cache queue.

[0122] Each module in the above earphone device can be implemented in whole or in part by software, hardware, and their combination. The above modules can be embedded in the processor of the earphone device in hardware form or independent of the processor, or stored in the memory of the earphone device in software form, so that the processor can call and execute the operations corresponding to the above modules.

[0123] In one embodiment, there is provided an earphone device, which can be a Bluetooth earphone, or a certain earphone device in a device cluster that is wirelessly connected and has a master-slave relationship. Its internal structure diagram can be as Figure 7 shown. The earphone device includes a processor, a memory, an input / output interface, and a communication interface. In some specific implementation scenarios, the input / output interface and the communication interface can be integrated into one interface. In this earphone device, the processor, the memory, and the input / output interface are connected through a system bus, and the communication interface and the input device are connected to the system bus through the input / output interface. Among them, the processor of the earphone device is used to provide necessary computing and control capabilities. The memory of the earphone device can include a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the earphone device is used to exchange information between the processor and external devices. The communication interface of the earphone device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through Bluetooth or other communication technologies that can form a master-slave relationship between devices. When the computer program is executed by the processor, it implements a master-slave switching method.

[0124] Those skilled in the art can understand that Figure 7 the structure shown in

[0125] In one embodiment, a headphone device is provided, including a memory and a processor. A computer program is stored in the memory. When the processor executes the computer program, the following steps are implemented:

[0126] Obtain a master-slave switching instruction, and cache the target data of the second headphone into the first cache space. The master-slave switching instruction is used to indicate master-slave switching between the first headphone and the second headphone, and the target data is the data to be sent to the master headphone;

[0127] Cache the historical data in the first headphone into the second cache space, and switch the second headphone to the master headphone according to the cache occupancy information of the historical data in the second cache space;

[0128] Send the target data in the first cache space to the master headphone.

[0129] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:

[0130] Obtain a master-slave switching instruction, and cache the target data of the second headphone into the first cache space. The master-slave switching instruction is used to indicate master-slave switching between the first headphone and the second headphone, and the target data is the data to be sent to the master headphone;

[0131] Cache the historical data in the first headphone into the second cache space, and switch the second headphone to the master headphone according to the cache occupancy information of the historical data in the second cache space;

[0132] Send the target data in the first cache space to the master headphone.

[0133] In one embodiment, a computer program product is provided, including a computer program. When the computer program is executed by a processor, the following steps are implemented:

[0134] Obtain a master-slave switching instruction, and cache the target data of the second headphone into the first cache space. The master-slave switching instruction is used to indicate master-slave switching between the first headphone and the second headphone, and the target data is the data to be sent to the master headphone;

[0135] Cache the historical data in the first headphone into the second cache space, and switch the second headphone to the master headphone according to the cache occupancy information of the historical data in the second cache space;

[0136] Send the target data in the first cache space to the master headphone.

[0137] Those of ordinary skill in the art can understand that all or part of the processes in the methods of the above embodiments can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above methods. Among them, any reference to a memory, database, or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memories. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc. The databases involved in the embodiments provided in the present application can include at least one of relational databases and non-relational databases. Non-relational databases can include distributed databases based on blockchain, etc., without limitation. The processors involved in the embodiments provided in the present application can be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, data processing logics based on quantum computing, etc., without limitation.

[0138] The technical features of the above embodiments can be combined arbitrarily. For the sake of brevity of description, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, it should be considered as the scope recorded in this specification.

[0139] The above embodiments only represent several implementation manners of the present application. The description is relatively specific and detailed, but it should not be construed as a limitation on the patent scope of the present application. It should be noted that for those of ordinary skill in the art, without departing from the concept of the present application, several modifications and improvements can still be made, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the appended claims.

Claims

1. A master-slave switching method, applied to a headphone device, the headphone device including a first headphone and a second headphone, characterized in that, the method includes: Obtaining a master-slave switching instruction, caching the target data of the second headphone in a first cache space, the master-slave switching instruction being used to indicate a master-slave switch between the first headphone and the second headphone, and the target data being data to be sent to the master headphone; Caching the historical data in the first headphone in a second cache space, and switching the second headphone to the master headphone according to the cache occupancy information of the historical data in the second cache space; Sending the target data in the first cache space to the master headphone.

2. The method according to claim 1, characterized in that, caching the target data of the second headphone in the first cache space includes: Generating a timer according to a preset data caching period; If the timing of the timer is less than or equal to the data caching period, caching the target data through the first cache space.

3. The method according to claim 2, characterized in that, the method further includes: If the timing of the timer is greater than the data caching period, obtaining the cache occupancy information of the historical data in the second cache space.

4. The method according to claim 1, characterized in that, switching the second headphone to the master headphone according to the cache occupancy information of the historical data in the second cache space includes: Sending the historical data in the second cache space to a mobile terminal; Obtaining the cache occupancy information of the historical data in the second cache space according to the space capacity of the second cache space during the sending process; If it is determined according to the cache occupancy information that all the historical data in the second cache space has been sent to the mobile terminal, switching the target device to the master headphone.

5. The method according to claim 1, characterized in that, sending the target data in the first cache space to the master headphone includes: Constructing a plurality of Bluetooth communication links; Sending the target data in the first cache space to the master headphone through the plurality of Bluetooth communication links.

6. The method according to claim 5, characterized in that, sending the target data in the first cache space to the master headphone through the plurality of Bluetooth communication links includes: Obtaining a communication control identifier carried in the target data, the communication control identifier being used to determine a target link corresponding to the target data; Filtering out a target link from the plurality of Bluetooth communication links according to the communication control identifier; Sending the target data in the first cache space to the master headphone according to the mapping relationship between the communication control identifier and the data recipient and the target link.

7. The method according to any one of claims 1 to 6, characterized in that, the first cache space is a message cache queue; caching the target data of the second headphone in the first cache space includes: Constructing a message cache queue; Caching the target data in the message cache queue.

8. A headphone device, including a first headphone and a second headphone, characterized in that, the headphone device further includes: The first cache processing module is used to obtain a master-slave switching instruction and cache the target data of the second earphone into the first cache space. The master-slave switching instruction is used to indicate the master-slave switching between the first earphone and the second earphone, and the target data is the data to be sent to the master earphone. The second cache processing module is used to cache the historical data of the first earphone into the second cache space and switch the second earphone to the master earphone according to the cache occupancy information of the historical data in the second cache space. The cache data transmission module is used to send the target data in the first cache space to the master earphone.

9. The earphone device according to claim 8, wherein, the first cache processing module is further used to generate a timer according to a preset data cache period; if the timing of the timer is less than or equal to the data cache period, the target data is cached through the first cache space.

10. The earphone device according to claim 9, wherein, the first cache processing module is further used to traverse the historical data cached in the second cache space to generate the cache occupancy information of the historical data when the timing of the timer is greater than the data cache period.

11. The earphone device according to claim 8, wherein, the second cache processing module is further used to send the historical data in the second cache space to the mobile terminal; obtain the cache occupancy information of the historical data in the second cache space according to the space capacity of the second cache space during the sending process; if it is determined according to the cache occupancy information that all the historical data in the second cache space has been sent to the mobile terminal, the target device is switched to the master earphone.

12. The earphone device according to claim 8, wherein, the cache data transmission module is further used to construct a plurality of Bluetooth communication links; and send the target data in the first cache space to the master earphone through the plurality of Bluetooth communication links.

13. The earphone device according to claim 12, wherein, the cache data transmission module is further used to obtain the communication control identifier carried in the target data, and the communication control identifier is used to determine the target link corresponding to the target data; screen the target link from the plurality of Bluetooth communication links according to the communication control identifier; and send the target data in the first cache space to the master earphone according to the mapping relationship between the communication control identifier and the data receiver and the target link.

14. The earphone device according to any one of claims 8-13, wherein, the first cache space is a message cache queue; the first cache processing module is further used to construct a message cache queue; and cache the target data into the message cache queue.