WO2022237493A1 - 一种无线连接的方法以及电子设备 - Google Patents

一种无线连接的方法以及电子设备 Download PDF

Info

Publication number
WO2022237493A1
WO2022237493A1 PCT/CN2022/088244 CN2022088244W WO2022237493A1 WO 2022237493 A1 WO2022237493 A1 WO 2022237493A1 CN 2022088244 W CN2022088244 W CN 2022088244W WO 2022237493 A1 WO2022237493 A1 WO 2022237493A1
Authority
WO
WIPO (PCT)
Prior art keywords
electronic device
broadcast message
broadcast
information
service
Prior art date
Application number
PCT/CN2022/088244
Other languages
English (en)
French (fr)
Inventor
周蓉
李奕成
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Priority claimed from CN202110827479.6A external-priority patent/CN115348568A/zh
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2022237493A1 publication Critical patent/WO2022237493A1/zh

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W28/00Network traffic management; Network resource management
    • H04W28/02Traffic management, e.g. flow control or congestion control
    • H04W28/10Flow control between communication endpoints
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W4/00Services specially adapted for wireless communication networks; Facilities therefor
    • H04W4/80Services using short range communication, e.g. near-field communication [NFC], radio-frequency identification [RFID] or low energy communication
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04WWIRELESS COMMUNICATION NETWORKS
    • H04W8/00Network data management
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Definitions

  • the present application relates to the technical field of wireless communication, and in particular to a wireless connection method and electronic equipment.
  • Bluetooth low energy Bluetooth low energy
  • BLE Bluetooth low energy
  • BLE Bluetooth low energy
  • BLE Bluetooth low energy
  • BLE Bluetooth low energy
  • how to further optimize the BLE connection technology is still a hot research topic among manufacturers.
  • the wireless connection method and the electronic device provided by the present application can accelerate the discovery and connection process of the electronic device.
  • a wireless discovery communication system including a first electronic device and a second electronic device, the first electronic device is used to send a first broadcast message, and the first broadcast message is used to discover the first electronic device Surrounding electronic devices; the second electronic device is configured to send a second broadcast message in response to receiving the first broadcast message, and the second broadcast message includes first information of the second electronic device, wherein the first information includes the device One or more of identification, device name, login account, device type and business identification; the first electronic device is used to store the first information of the second electronic device; the second electronic device is also used to store the first information of the second electronic device The device sends a third broadcast message after the first period of time after sending the second broadcast message, and the third broadcast message includes second information of the second electronic device, where the second information includes device identification, login account, device type, One or more of the equipment capability and business identification, and the second information is different from the first information in at least part of the content; the first electronic device is also used to determine the discovery based on the first information and the second
  • the second electronic device When the second electronic device replies the device information (including the first information and the second information) of the second electronic device to the first electronic device, it often needs to send two or two broadcast messages.
  • the second electronic device after the second electronic device sends a broadcast message (that is, the second broadcast message, that is, the broadcast message B hereinafter), it will wait for the first electronic device to receive the second broadcast message. After receiving the message, return the confirmation message to the second electronic device.
  • the second electronic device proceeds to the next broadcast message (that is, the third broadcast message, ie, the broadcast message C hereinafter) after receiving the confirmation message returned by the first electronic device.
  • T2 is usually 300ms.
  • the second electronic device directly sends the third broadcast message after a time period T1 (that is, the first time period) after sending the second broadcast message.
  • T1 is smaller than T2.
  • T1 may be set as a fixed duration (for example, 60ms) plus a random duration (for example, a random duration within 40ms).
  • T1 can be set to not more than 100ms.
  • the second electronic device after the second electronic device receives the first broadcast message sent by the first electronic device (that is, the discovery broadcast message, that is, the broadcast message A below), the second electronic device The electronic device needs to send more than two (for example, N1, N1 is greater than 2) broadcast messages to reply the information of the second electronic device.
  • N1, N1 is greater than 2 broadcast messages
  • the second electronic device sends each broadcast message after the first broadcast message (for example, the second broadcast message, that is, broadcast message B)
  • the broadcast message is sent directly after the time period T1 after sending the last broadcast message.
  • the second electronic device when the second electronic device sends each broadcast message after the first broadcast message (that is, the broadcast message B), it needs to wait for the first electronic device to send This broadcast message is sent after the ACK message of the previous broadcast message.
  • the next broadcast message is automatically sent after a time period T1 after sending a broadcast message.
  • the first electronic device is also used to store the second information of the second electronic device; the first electronic device is also used to send a fourth broadcast message, and the fourth broadcast message is used to discover Electronic devices around the first electronic device; the second electronic device is further configured to send a fifth broadcast message in response to receiving the fourth broadcast message, where the fifth broadcast message includes the first information of the second electronic device; the second electronic device The second electronic device is further configured to determine to find the second electronic device according to the first information of the second electronic device in the fifth broadcast message and the stored second information of the second electronic device.
  • the first electronic device needs to discover the second electronic device again within a relatively short period of time (for example, within the buffering duration of the buffered broadcast message C). For example, the first electronic device triggers the forwarding/sharing function of pictures/files/videos again within the short period of time, or the first electronic device refreshes the discovered electronic devices periodically (the period is shorter than the duration T1).
  • the process of the first electronic device discovering the second electronic device again is the same as the process of discovering the second electronic device for the first time, that is, the second electronic device needs to send two broadcast messages to respond to the first electronic device
  • the broadcast message sent for discovery and after the second electronic device receives the ACK message sent by the first electronic device for the first broadcast message, the second electronic device sends the second broadcast message arts.
  • the first electronic device can perform content splicing according to the broadcast message and another previously cached broadcast message, and determine that the first electronic device finds 2. Electronic equipment.
  • the second electronic device after the second electronic device receives the broadcast message A sent by the first electronic device, the second electronic device needs to send more than two (for example, N1, N1 is greater than 2)
  • the broadcast message is used to reply the information of the second electronic device.
  • the first electronic device after the first electronic device receives the first broadcast message sent by the second electronic device, it can determine in advance to discover the second electronic device according to other broadcast messages (one or more broadcast messages) cached by itself, and accelerate A discovery process for the second electronic device.
  • the first electronic device is further configured to send a sixth broadcast message
  • the sixth broadcast message is used to prompt the second electronic device to alternately send the first broadcast message of the second electronic device. information and the second information of the second electronic device.
  • the first electronic device is further configured to receive the first information of the second electronic device and not receive or store the second information of the second electronic device, or, when receiving the second When the second information of the electronic device is received and the first information of the second electronic device is not received or stored, the third broadcast message is sent.
  • the first electronic device when it has not received all the information of the first electronic device, it can send a third broadcast message, namely the following broadcast message F, to request the second electronic device to quickly and alternately send messages for Responding to all the messages in the discovery broadcast message (that is, the first broadcast message, that is, the broadcast message A) helps the first electronic device to quickly obtain all the information of the second electronic device, and accelerates the discovery process.
  • a third broadcast message namely the following broadcast message F
  • a wireless discovery method is provided, which is applied to a second electronic device, and the method includes: receiving a first broadcast message sent by the first electronic device, and the first broadcast message is used to discover the surroundings of the first electronic device Electronic device; sending a second broadcast message, the second broadcast message includes the first information of the second electronic device, wherein the first information includes one or more of the device identifier, device name, login account, device type and service identifier item; after the first duration after the second electronic device sends the second broadcast message, send the third broadcast message, the third broadcast message includes the second information of the second electronic device, wherein the second information includes the device identification, One or more of the login account, device type, device capability and service identification, and the second information and the first information are at least partially different in content; wherein, the first information and the second information of the second electronic device are used for the first An electronic device determines to discover the second electronic device.
  • the second electronic device When the second electronic device replies the device information (including the first information and the second information) of the second electronic device to the first electronic device, it often needs to send two or two broadcast messages.
  • the second electronic device after the second electronic device sends a broadcast message (that is, the second broadcast message, that is, the broadcast message B hereinafter), it will wait for the first electronic device to receive the second broadcast message. After receiving the message, return the confirmation message to the second electronic device.
  • the second electronic device proceeds to the next broadcast message (that is, the third broadcast message, ie, the broadcast message C hereinafter) after receiving the confirmation message returned by the first electronic device.
  • T2 is usually 300ms.
  • the second electronic device directly sends the third broadcast message after a time period T1 after sending the second broadcast message.
  • T1 is smaller than T2.
  • the broadcast type of the first electronic device is set to unconnectable.
  • the broadcast type of the first electronic device is unconnectable, when the application layer of the first electronic device sends broadcast message A (i.e. the first broadcast message) to the bottom layer, the bottom layer does not need to wait for other electronic devices (such as the second electronic device ) connected broadcast message, but directly sends broadcast message A.
  • the broadcast type of the first electronic device is connectable.
  • the bottom layer (for example, specifically L2CAP) needs to wait for a connection interval (connection interval) for waiting to receive broadcast messages connected by other electronic devices.
  • the connection interval is a time interval for interaction between two electronic devices, which is generally 20 ms. It can be seen that when the first electronic device sets the broadcast type to unconnectable before sending the broadcast message A, it is beneficial for the discovery process to speed up the duration of a connection interval, for example, 20ms.
  • the broadcast type of the first electronic device is set to connectable.
  • the broadcast type of the first electronic device is set to be scannable.
  • the broadcast type of the first electronic device is set to unscannable.
  • the bluetooth chip of the electronic device does not support the paging scan capability, it does not have the ability to splice response packets, then set the attribute value of the broadcast parameter scannable of the electronic device to false. Then, when the bottom layer of the electronic device receives multiple response packets for the discovery request (such as broadcast message B and broadcast message C below), it does not splice the multiple response packets, and directly reports the multiple response packets to the Upper application. If the scannable attribute value of the electronic device is still true at this time, the electronic device will still wait for the package processing time (for example, 20ms), and then report multiple response packets to the upper-layer application. Therefore, when the bluetooth chip of the electronic device does not support the paging scanning capability, setting the scannable attribute value to false is beneficial to save the time of the grouping process and speed up the discovery process and the connection process.
  • the device identifier of the second electronic device is a hash value of the first identifier of the second electronic device; the first identifier of the second electronic device is the serial number SN of the second electronic device , International Mobile Equipment Identity (IMEI), and Media Access Control (MAC) address.
  • IMEI International Mobile Equipment Identity
  • MAC Media Access Control
  • the use of the hash value as the unique identifier of the electronic device improves the security issues in the discovery process of the electronic device and the connection process.
  • a wireless discovery method which is applied to a first electronic device, and the method includes: sending a first broadcast message, and the first broadcast message is used to discover electronic devices around the first electronic device; receiving a second The second broadcast message sent by the electronic device, the second broadcast message includes the first information of the second electronic device, wherein the first information includes one or more of the device identifier, device name, login account, device type and service identifier item; search for the second information of the second electronic device according to the first information of the second electronic device; wherein the second information includes one or more of device identification, login account, device type, device capability and service identification, and the second The second information is different from the first information at least in part; and it is determined that the second electronic device is found according to the first information of the second electronic device and the found second information.
  • the process of the first electronic device discovering the second electronic device again is the same as the process of discovering the second electronic device for the first time, that is, the second electronic device needs to send two broadcast messages to respond to the first electronic device
  • the broadcast message sent for discovery and after the second electronic device receives the ACK message sent by the first electronic device for the first broadcast message, the second electronic device sends the second broadcast message arts.
  • the first electronic device can perform content splicing according to the broadcast message and another previously cached broadcast message, and determine that the first electronic device finds 2. Electronic equipment.
  • the method further includes: the first electronic device sends a third broadcast message, and the third broadcast message is used to prompt the second electronic device to alternately send the first information of the second electronic device and the second The second information of the electronic device.
  • the first electronic device when the first information of the second electronic device is received, and the second information of the second electronic device is not received or stored, or, when the second information of the second electronic device is received, And when the first information of the second electronic device is not received or stored, the first electronic device sends the third broadcast message.
  • the first electronic device when it has not received all the information of the first electronic device, it can send a third broadcast message, namely the following broadcast message F, to request the second electronic device to quickly and alternately send messages for Responding to all the messages in the discovery broadcast message (that is, the first broadcast message, that is, the broadcast message A) helps the first electronic device to quickly obtain all the information of the second electronic device, and accelerates the discovery process.
  • a third broadcast message namely the following broadcast message F
  • a method for wireless discovery and connection includes: the first electronic device obtains the information of the first electronic device, and the information of the first electronic device includes the business scene of the first electronic device and the state of the first electronic device , and one or more of the capabilities of the wireless communication chip configured by the first electronic device; the first electronic device adjusts the broadcast parameters of the first electronic device according to the information of the first electronic device; wherein the broadcast parameters include broadcast type, scanning duty cycle , broadcast duty cycle, broadcast channel number or one or more items.
  • the first electronic device dynamically adjusts the broadcast parameters during the discovery process and the connection process according to the information of the first electronic device, so as to send the discovery process, improve the discovery success rate, speed up the connection process, and save the cost of the first electronic device. power consumption.
  • the first electronic device adjusts the broadcast parameters of the first electronic device according to the business scenario of the first electronic device, including: before the first electronic device sends a discovery broadcast message, setting the first electronic device's The broadcast type is set to be unconnectable; after the first electronic device receives any message in response to the discovery broadcast message from any electronic device, the broadcast type of the first electronic device is set to be connectable.
  • the broadcast type of the first electronic device is unconnectable, when the application layer of the first electronic device sends a discovery broadcast message (i.e. broadcast message A below) to the bottom layer, the bottom layer does not need to wait for other electronic devices (such as the second electronic device) Device) connection broadcast message, but directly send broadcast message A.
  • the broadcast type of the first electronic device is connectable.
  • the bottom layer (for example, specifically L2CAP) needs to wait for a connection interval (connection interval) for waiting to receive broadcast messages connected by other electronic devices.
  • the connection interval is a time interval for interaction between two electronic devices, which is generally 20 ms. It can be seen that when the first electronic device sets the broadcast type to unconnectable before sending the broadcast message A, it is beneficial for the discovery process to speed up the duration of a connection interval, for example, 20ms.
  • the first electronic device adjusts the broadcast parameters of the first electronic device according to the state of the first electronic device, and further includes: when the state of the first electronic device satisfies a preset condition, the first electronic device adds Large scanning duty cycle and/or broadcast duty cycle: wherein, the preset condition is any one or more of the following conditions: the first electron enters the first preset time period from the screen-off state to the screen-on state; Within the second preset time period when the first electronic device enters the unlocked state from the locked screen state; within the third preset time period after the first electronic device starts the first application; the first electronic device switches the second application from running in the background to the foreground During the fourth preset duration of running; the first electronic device runs a preset application.
  • the preset condition is any one or more of the following conditions: the first electron enters the first preset time period from the screen-off state to the screen-on state; Within the second preset time period when the first electronic device enters the unlocked state from the locked screen state; within the third preset
  • the first electronic device has a higher probability of discovering other electronic devices in these scenarios, so increasing the broadcast duty cycle and/or scanning duty cycle of the first electronic device is conducive to the first electronic device quickly Broadcast or scan to speed up the discovery process with other electronic devices.
  • the first electronic device adjusts the broadcast parameters of the first electronic device according to the state of the first electronic device, and further includes: after the first electronic device is powered on or powered on or starts the wireless communication function, and after Before it is detected that the first electronic device activates the preset service, the broadcasting process or the scanning process of the first electronic device is in an inactive state.
  • the probability that the first electronic device finds other electronic devices is small, or even zero, so the broadcast duty cycle and/or scanning duty cycle are reduced, and even the broadcast duty cycle and/or Or the scanning duty cycle is adjusted to zero, which is beneficial to reduce the power consumption of the first electronic device.
  • the duty cycle (including scanning duty cycle, broadcast duty cycle, etc.) is dynamically adjusted according to the state of the first electronic device.
  • the first electronic device detects that the user chooses to connect to a certain electronic device for a duration T3
  • the first electronic device can increase the broadcast duty cycle/scanning duty cycle, which is beneficial for the first electronic device to quickly broadcast or scan, and speed up the communication with the electronic device.
  • the connection process of the second electronic device After the connection between the first electronic device and the second electronic device is established, the first electronic device may reduce the broadcast duty cycle and/or the scan duty cycle to reduce the power consumption of the electronic device.
  • the first electronic device dynamically adjusts the broadcast parameters of the first electronic device according to the capability of the wireless communication chip configured on the first electronic device, including: according to whether the wireless communication chip configured on the first electronic device supports paging
  • the scanning capability is used to set whether the broadcast type of the first electronic device is scannable.
  • the bluetooth chip of the first electronic device supports page scan (page scan) capability, then possesses the ability of splicing the response packet, then the attribute value of the broadcast parameter scannable of the first electronic device is set to true.
  • the bottom layer of the first electronic device receives multiple response packets for the discovery request (such as the following broadcast message B and broadcast message C), it can splice the multiple response packets, and then splice the spliced
  • the data packet is reported to the upper layer application.
  • the bluetooth chip of the first electronic device does not support paging scan capability, then it does not have the capability of splicing response packets, then set the attribute value of the broadcast parameter scannable of the first electronic device to false. Then, when the bottom layer of the first electronic device receives multiple response packets for the discovery request (such as the following broadcast message B and broadcast message C), it does not splice the multiple response packets, and directly combines the multiple response packets Report to the application of the upper layer. If the scannable attribute value of the first electronic device is still true at this time, the electronic device will still wait for the package processing time (for example, 20ms) at this time, and then report multiple response packets to the upper-layer application. Therefore, when the bluetooth chip of the first electronic device does not support the paging scanning capability, setting the attribute value of scannable to false is beneficial to save the time of the grouping process and speed up the discovery process and the connection process.
  • the first electronic device dynamically adjusts the broadcast parameters of the first electronic device according to the capability of the wireless communication chip configured by the first electronic device, including: the first electronic device configures the wireless communication chip according to the first electronic device Ability to adjust the number of scanners of the first electronic device, where each scanner corresponds to a scanning duty cycle.
  • the Bluetooth chip configured on the electronic device (such as the first electronic device or the second electronic device) supports a unicast channel, then, when multiple services of the electronic device are concurrent, at the same time the electronic device Only the broadcast message of one service can be sent, and the broadcast message of other services is delayed, or the broadcast message of other services is directly discarded, thus affecting the discovery and connection of these services. If the Bluetooth chip configured on the electronic device supports multiple broadcast channels, when the number of broadcast messages triggered on the electronic device is greater than the number of currently available broadcast channels at the same time, the above-mentioned conflicts also exist, affecting the discovery and connection of some services .
  • the electronic device may combine broadcast packets and reverse broadcast packets of different tasks of the same service. For example, if the user triggers a picture/file/video sharing function on the first electronic device, then the first electronic device sends a broadcast message (such as broadcast message A) for discovering surrounding electronic devices. When the first electronic device receives the first response packet (eg broadcast message B) returned by the second electronic device, the first electronic device sends a reverse broadcast message (eg broadcast message F). If the user triggers another picture/file/video sharing function on the first electronic device before the first electronic device sends the reverse broadcast message, then the first electronic device responds to the user's trigger operation and again A broadcast message (for example, broadcast message A) for discovering surrounding electronic devices is sent.
  • a broadcast message such as broadcast message A
  • the first electronic device sends a reverse broadcast message (for example, a broadcast message F) and a broadcast message (for example, a broadcast message A) for discovering surrounding electronic devices is found for the second time to send a conflict.
  • a reverse broadcast message for example, a broadcast message F
  • a broadcast message for example, a broadcast message A
  • the two broadcast messages may be combined, and then the combined broadcast message may be sent.
  • the second electronic device parses to obtain the contents of the two broadcast messages (that is, the broadcast message F and the broadcast message A). It can be seen that, compared with the prior art, the electronic device combines and sends two broadcast messages, which ensures the concurrency of two tasks of the same service and accelerates the discovery and connection process of different tasks of the service.
  • a preset number N3 of broadcast channels may be set for transmitting broadcast messages, so as to save chip resources.
  • the N3 broadcast channels may correspond to the N3 service types.
  • the service selects a broadcast channel corresponding to its own service type for sending the broadcast message. If multiple services of the same service type need to send broadcast packets at this time, the broadcast packets corresponding to the service types may be multiplexed.
  • the application layer of the electronic device combines the broadcast messages of these multiple services, and then sends the combined broadcast message through the broadcast channel corresponding to the service type, so as to ensure that the broadcast messages of each service are sent in time, reducing the The waiting time is shortened, and the discovery process and connection process of multiple services are accelerated.
  • services of different service types select and multiplex broadcast channels corresponding to the service types.
  • the Bluetooth chip configured in the electronic device supports a unicast broadcast channel, or, although the Bluetooth chip configured in the electronic device supports a multicast channel, the chip capability is not enough to provide a preset number N3 broadcast channels Channels are used to transmit broadcast messages.
  • some of these business types can be combined.
  • multiple service types multiplex one broadcast channel, so two or more service types can be indicated in the Sender Btype (or Receiver Btype).
  • services of two or more service types can also be combined in one broadcast message.
  • the first electronic device dynamically adjusts the broadcast parameters of the first electronic device according to the capability of the wireless communication chip configured on the first electronic device, including: if the capability of the wireless communication chip configured on the first electronic device supports multiple broadcast channel, the first electronic device sets a preset number of N3 broadcast channels, where each broadcast channel corresponds to a service type, and where each service type corresponds to multiple services.
  • the electronic device may combine broadcast packets and reverse broadcast packets of different tasks of the same service. For example, if the user triggers a picture/file/video sharing function on the first electronic device, then the first electronic device sends a broadcast message (such as broadcast message A) for discovering surrounding electronic devices. When the first electronic device receives the first response packet (eg broadcast message B) returned by the second electronic device, the first electronic device sends a reverse broadcast message (eg broadcast message F). If the user triggers another picture/file/video sharing function on the first electronic device before the first electronic device sends the reverse broadcast message, then the first electronic device responds to the user's trigger operation and again A broadcast message (for example, broadcast message A) for discovering surrounding electronic devices is sent.
  • a broadcast message such as broadcast message A
  • the first electronic device sends a reverse broadcast message (for example, a broadcast message F) and a broadcast message (for example, a broadcast message A) for discovering surrounding electronic devices is found for the second time to send a conflict.
  • a reverse broadcast message for example, a broadcast message F
  • a broadcast message for example, a broadcast message A
  • the two broadcast messages may be combined, and then the combined broadcast message may be sent.
  • the second electronic device parses to obtain the contents of the two broadcast messages (that is, the broadcast message F and the broadcast message A). It can be seen that, compared with the prior art, the electronic device combines and sends two broadcast messages, which ensures the concurrency of two tasks of the same service and accelerates the discovery and connection process of different tasks of the service.
  • a preset number N3 of broadcast channels may be set for transmitting broadcast messages, so as to save chip resources.
  • the N3 broadcast channels may correspond to the N3 service types.
  • the service selects a broadcast channel corresponding to its own service type for sending the broadcast message. If multiple services of the same service type need to send broadcast packets at this time, the broadcast packets corresponding to the service types may be multiplexed.
  • the application layer of the electronic device combines the broadcast messages of these multiple services, and then sends the combined broadcast message through the broadcast channel corresponding to the service type, so as to ensure that the broadcast messages of each service are sent in time, reducing the The waiting time is shortened, and the discovery process and connection process of multiple services are accelerated.
  • services of different service types select and multiplex broadcast channels corresponding to the service types.
  • the first electronic device dynamically adjusts the broadcast parameters of the first electronic device according to the wireless communication chip capability configured on the first electronic device, and further includes: if the wireless communication chip capability configured on the first electronic device does not support multiple broadcast channels, multiple service types of the first electronic device multiplex one broadcast channel.
  • the electronic device may combine broadcast packets and reverse broadcast packets of different tasks of the same service. For example, if the user triggers a picture/file/video sharing function on the first electronic device, then the first electronic device sends a broadcast message (such as broadcast message A) for discovering surrounding electronic devices. When the first electronic device receives the first response packet (eg broadcast message B) returned by the second electronic device, the first electronic device sends a reverse broadcast message (eg broadcast message F). If the user triggers another picture/file/video sharing function on the first electronic device before the first electronic device sends the reverse broadcast message, then the first electronic device responds to the user's trigger operation and again A broadcast message (for example, broadcast message A) for discovering surrounding electronic devices is sent.
  • a broadcast message such as broadcast message A
  • the first electronic device sends a reverse broadcast message (for example, a broadcast message F) and a broadcast message (for example, a broadcast message A) for discovering surrounding electronic devices is found for the second time to send a conflict.
  • a reverse broadcast message for example, a broadcast message F
  • a broadcast message for example, a broadcast message A
  • the two broadcast messages may be combined, and then the combined broadcast message may be sent.
  • the second electronic device parses to obtain the contents of the two broadcast messages (that is, the broadcast message F and the broadcast message A). It can be seen that, compared with the prior art, the electronic device combines and sends two broadcast messages, which ensures the concurrency of two tasks of the same service and accelerates the discovery and connection process of different tasks of the service.
  • the method further includes: the first electronic device determines a display order of the discovered electronic devices according to a service scenario of the first electronic device and/or chip capabilities configured by the first electronic device.
  • the first electronic device determines the display order of the discovered electronic devices according to the business scenario of the first electronic device, including: if any one of the gallery application, file manager, and video player is detected
  • the first electronic device preferentially displays rich devices among the discovered electronic devices.
  • the first electronic device determines the display order of the discovered electronic devices according to the business scenario of the first electronic device, and further includes: if it is detected that the discovery function is triggered in the smart home application, the first electronic device Electronic devices registered in the smart home app are displayed preferentially.
  • the first electronic device determines the display order of the discovered electronic devices according to the chip capability configured by the first electronic device, and further includes: if the first electronic device is configured with an ultra-wideband UWB chip, then the first electronic device An electronic device preferentially displays the electronic device pointed to by the first electronic device.
  • the first electronic device if the first electronic device is configured with a Bluetooth chip or a Wi-Fi chip or a neighbor-aware network NAN, the first electronic device preferentially displays electronic devices that are closest to the first electronic device, or , the first electronic device preferentially displays electronic devices with strong wireless signals.
  • the first electronic device may also combine the above several display strategies.
  • the above display strategies can be combined according to the following priorities: (1) The electronic devices discovered within 1s are sorted according to the following priorities: firstly display the discovered electronic devices that the first electronic device is currently pointing at; An electronic device located within a certain distance range; then sorted according to the display strategy of the user's trigger to discover the function of the surrounding electronic device; and then sorted according to the value of the RSSI. (2) The electronic devices found after 1s are sorted according to the time order of discovery, and arranged after the electronic devices found within 1s.
  • the method further includes: the first electronic device dynamically adjusts the connection parameters of the first electronic device according to the business scenario of the first electronic device and/or the capability of the wireless communication chip configured by the first electronic device, and the connection Parameters include connection interval and/or number of connection channels.
  • the first electronic device dynamically adjusts the connection parameters of the first electronic device according to the business scenario of the first electronic device, including: the first electronic device adjusts the connection parameters of the first electronic device according to the size of the cached discovery packet.
  • a connection interval where discovery packets are used to discover surrounding electronic devices.
  • the duty cycle (including scanning duty cycle, broadcast duty cycle, etc.) is dynamically adjusted according to the state of the first electronic device.
  • the first electronic device detects that the user chooses to connect to a certain electronic device for a preset duration T3
  • the first electronic device can increase the broadcast duty cycle/scanning duty cycle, which is beneficial for the first electronic device to quickly broadcast or scan, and speed up the communication with the electronic device.
  • the connection process of other electronic devices After the first electronic device establishes a connection with other electronic devices, the electronic device can reduce the broadcast duty cycle and/or the scanning duty cycle to reduce power consumption of the electronic device.
  • the first electronic device dynamically adjusts the connection parameters of the first electronic device according to the capability of the wireless communication chip configured by the first electronic device, including: the first electronic device configures the wireless communication chip according to the first electronic device The number of connection channels is established on each wireless communication chip; at least two services of the first electronic device multiplex at least one connection channel.
  • a data packet transmitted by one connection channel includes a service identifier and a serial number.
  • a data packet transmitted by a connection channel further includes a packet header mark and/or a priority mark.
  • the electronic device since multiple services reuse the same socket, after the electronic device receives the data packet, it can return the data packet to the corresponding service according to the service identifier therein. It can be seen that the embodiment of the present application ensures that when multiple services multiplex the connection channel, there will be no service disorder.
  • sequence number (seq) is used to determine the timing of each data packet.
  • each service corresponds to a queue, and in each queue, the sequence numbers of the data packets sent by the sending end increase in odd numbers, and the sequence numbers of the data packets sent by the receiving end increase in even numbers.
  • the packet header mark is used to mark whether the data packet is a packet header. If it is a packet header, the packet header flag is set to a first value, for example, 1, and if it is not a packet header, the packet header flag is set to a second value, such as 0.
  • the electronic device at the receiving end can splice multiple data packets according to the packet header mark.
  • the priority marking is used to mark data packets of different importance in the same service, for example, data packets of control signaling have the highest priority, high priority service packets, low priority service packets and so on.
  • data packets of control signaling have the highest priority, high priority service packets, low priority service packets and so on.
  • data packets with high priority can be sent preferentially according to the priority mark, so as to ensure efficient data transmission.
  • the discovery request broadcast by the first electronic device carries the service identifier.
  • multiple services triggered by different electronic devices can also multiplex the same connection channel.
  • the first electronic device determines to initiate service 1 (that is, step S1401 in FIG. 14 )
  • the first electronic device establishes a connection channel (such as executing step S1405 in FIG.
  • the second electronic device sends a broadcast message to inform the second electronic device that the first electronic device has initiated a connection request. Then, the second electronic device does not initiate a connection request within the preset time period T5.
  • the second electronic device does not respond to the connection request, or delays in responding to the connection request.
  • the second electronic device may also prompt the user that other electronic devices are connecting to the second electronic device.
  • the first electronic device after the first electronic device establishes the connection channel (such as executing step S1405 in FIG. 14 ), the first electronic device communicates to the The second electronic device sends a message to inform the second electronic device that the first electronic device has initiated a connection request.
  • the embodiment of the present application does not limit the manner and timing for the first electronic device to notify the second electronic device.
  • the device identifier of the second electronic device is the hash value of the first identifier of the second electronic device; the first identifier of the second electronic device is the serial number SN of the first electronic device, the international mobile device Any one of the identification code IMEI and the media access control address MAC address. Since the hash value is not easy to identify and is not easy to be de-analyzed, using the hash value as the unique identifier of the electronic device improves the security issues in the discovery process and the connection process.
  • the user can recalculate the unique identifier of the second electronic device by, for example, restarting the second electronic device, that is, reusing the public key to identify the electronic device (such as SN, IMEI, MAC address, etc.) to calculate the hash value, and use some bytes in the hash value as the unique identifier of the new second electronic device. It can be seen that the user can control to regenerate the unique identifier of the second electronic device. In other words, the unique identifier of the second electronic device can be changed, which further increases the difficulty of being attacked and further improves the security issues in the discovery process and connection process of the second electronic device.
  • the identification of the discovered second electronic device can also be verified, and it is ensured that the connected electronic device is the same as the discovered electronic device
  • the device identification of the first electronic device may also be similarly encrypted.
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase that is, phase 1
  • the connection phase 1 between the GATT client of the first electronic device and the GATT server of the second electronic device fails
  • the first The electronic device and the second electronic device retry automatically, and the number of retries does not exceed the preset number of times 1 (for example, 3 times)
  • the total duration of the first electronic device in phase 1 is controlled within the preset duration (for example, 4s).
  • the first electronic device and the second electronic device automatically retries, and the number of retries does not exceed the preset number of times 2 (for example, 1 time), and the total duration of the first electronic device in phase 2 is controlled within the preset duration (for example, 4s).
  • the technical solution provided by the embodiment of the present application improves the success rate of this connection by retrying recoverable exceptions in phase 1 and phase 2. Moreover, by controlling the total duration of the first electronic device in phase 1 and phase 2, the retry method saves connection time compared with the method of re-triggering the connection by the user, so as to speed up the connection process.
  • the first electronic device before or after the first electronic device determines to establish a connection channel with the second electronic device, the first electronic device sends a first message to the second electronic device, and the first message is used to notify the second electronic device No connection request is sent to the first electronic device.
  • the service identifier carried in the discovery request message may be included.
  • the MTU phase is directly set (ie, executing phase 3).
  • the first electronic device After the first electronic device discovers the second electronic device, if it does not receive the broadcast message sent by the second electronic device within a preset time period T7 (for example, 4s) after discovery, it will determine The second electronic device goes offline, that is, the identifier of the second electronic device is no longer displayed in the list of discovered electronic devices.
  • T7 for example, 4s
  • the first electronic device may also set different preset durations T7 for electronic devices of different device types. For example, when the discovered electronic device is a PC, the preset duration T7 is set to 6s; when the discovered electronic device is a mobile phone, the preset duration T7 is set to 4s. This is because electronic devices of different device types have different broadcast duty ratios, which is beneficial to improve the accuracy of offline.
  • an electronic device including: a processor, a memory, and a wireless communication module, the memory and the wireless communication module are coupled to the processor, the memory is used to store computer program codes, and the computer
  • the program code includes computer instructions, and when the processor reads the computer instructions from the memory, the electronic device executes any of the second aspect, the third aspect, the fourth aspect, and any of the above-mentioned aspects. method in one possible implementation.
  • a computer-readable storage medium which includes computer instructions, and when the computer instructions are run on the electronic device, the electronic device executes the above-mentioned second aspect, the third aspect, the fourth aspect and any one of them.
  • a computer program product is provided, and when the computer program product is run on a computer, the computer is made to execute any possible implementation of the second aspect, the third aspect, the fourth aspect and any one of them method in .
  • a chip system including a processor, and when the processor executes instructions, the processor executes any possible implementation of the second aspect, the third aspect, the fourth aspect, and any one of them method in .
  • FIG. 1 is a schematic structural diagram of a wireless communication system provided by an embodiment of the present application.
  • FIG. 2 is a schematic structural diagram of an electronic device provided in an embodiment of the present application.
  • FIG. 3 is a schematic structural diagram of a BLE protocol stack provided by an embodiment of the present application.
  • FIG. 4 is a schematic flowchart of a method for a first electronic device to discover a second electronic device according to an embodiment of the present application
  • FIG. 5 is a schematic diagram of the format of a broadcast message provided by the embodiment of the present application.
  • FIG. 6 is a schematic diagram of a user interface of some first electronic devices provided in an embodiment of the present application.
  • FIG. 7 is a schematic flowchart of a method for discovering a second electronic device by some first electronic devices according to an embodiment of the present application
  • FIG. 8 is a schematic diagram of the contents of some HCI data packets provided by the embodiment of the present application.
  • FIG. 9 is an example diagram of a solution to the overlapping of the discovery window and the connection window provided by the embodiment of the present application.
  • FIG. 10 is a schematic diagram of the contents of some other HCI data packets provided by the embodiment of the present application.
  • FIG. 11 is a schematic diagram of the format of a data field in a broadcast message provided by an embodiment of the present application.
  • FIG. 12 is a schematic flowchart of a method for multiplexing broadcast channels provided in an embodiment of the present application.
  • FIG. 13 is a schematic diagram of a connection process when multiple services are triggered on the first electronic device in the prior art
  • FIG. 14 is a schematic flowchart of a method for multiplexing a connection channel provided in an embodiment of the present application.
  • FIG. 15 is a schematic flowchart of another wireless connection method provided by the embodiment of the present application.
  • FIG. 16 is a schematic structural diagram of a chip system provided by an embodiment of the present application.
  • a relationship means that there may be three kinds of relationships, for example, A and/or B means: A exists alone, A and B exist simultaneously, and B exists alone.
  • first and second are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance or implicitly specifying the quantity of indicated technical features. Thus, a feature defined as “first” and “second” may explicitly or implicitly include one or more of these features.
  • plural means two or more.
  • exemplary or “for example” are used to mean an example, illustration, or illustration. Any embodiment or design scheme described as “exemplary” or “for example” in the embodiments of the present application shall not be interpreted as being more preferred or more advantageous than other embodiments or design schemes. Rather, the use of words such as “exemplary” or “such as” is intended to present related concepts in a concrete manner.
  • FIG. 1 it is a schematic structural diagram of a communication system provided by an embodiment of the present application, and the communication system includes at least a first electronic device 100 and a second electronic device 200 .
  • the first electronic device 100 and the second electronic device 200 both have a wireless connection function.
  • the wireless connections include, for example, BLE connections, classic Bluetooth (BR) connections, point-to-point (point to point, P2P) connections, neighbor awareness network (neighbor awareness network, NAN) connections, Constrained Application Protocol (Constrained Application Protocol, CoAP) connections, etc.
  • BR classic Bluetooth
  • P2P point-to-point
  • NAN neighbor awareness network
  • Constrained Application Protocol Constrained Application Protocol
  • CoAP Constrained Application Protocol
  • the first electronic device 100/second electronic device 200 can be, for example, a mobile phone, a tablet computer, a personal computer (personal computer, PC), a personal digital assistant (personal digital assistant, PDA), a netbook, a wearable electronic device (such as smart watches), augmented reality (augmented reality, AR) equipment, virtual reality (virtual reality, VR) equipment, vehicle equipment, smart screen, smart audio, smart home appliances, etc.
  • the specific form of the second electronic device 200 is not particularly limited.
  • the specific form of the first electronic device 100 may be the same as or different from the specific form of the second electronic device 200 .
  • FIG. 2 is a schematic structural diagram of a first electronic device 100 provided in an embodiment of the present application.
  • the second electronic device 200 may also refer to the structural description of the first electronic device 100 .
  • the structure of the second electronic device 200 may be the same as or different from that of the first electronic device 100 .
  • the second electronic device 200 may include more or fewer components than the first electronic device 100, or combine certain components, or separate certain components, or have different component arrangements.
  • the first electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (universal serial bus, USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, Antenna 2, mobile communication module 150, wireless communication module 160, audio module 170, speaker 170A, receiver 170B, microphone 170C, earphone jack 170D, sensor module 180, button 190, motor 191, indicator 192, camera 193, display screen 194 , and a subscriber identification module (subscriber identification module, SIM) card interface 195, etc.
  • SIM subscriber identification module
  • the structure illustrated in the embodiment of the present invention does not constitute a specific limitation on the first electronic device 100 .
  • the first electronic device 100 may include more or fewer components than shown in the illustration, or combine some components, or separate some components, or arrange different components.
  • the illustrated components can be realized in hardware, software or a combination of software and hardware.
  • the interface connection relationship between the modules shown in the embodiment of the present invention is only a schematic illustration, and does not constitute a structural limitation of the first electronic device 100 .
  • the first electronic device 100 may also adopt different interface connection methods in the above embodiments, or a combination of multiple interface connection methods.
  • the processor 110 may include one or more processing units, for example: the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processing unit (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), controller, video codec, digital signal processor (digital signal processor, DSP), baseband processor, and/or neural network processor (neural-network processing unit, NPU), etc. Wherein, different processing units may be independent devices, or may be integrated in one or more processors.
  • application processor application processor, AP
  • modem processor graphics processing unit
  • GPU graphics processing unit
  • image signal processor image signal processor
  • ISP image signal processor
  • controller video codec
  • digital signal processor digital signal processor
  • baseband processor baseband processor
  • neural network processor neural-network processing unit
  • a memory may also be provided in the processor 110 for storing instructions and data.
  • the memory in processor 110 is a cache memory.
  • the memory may hold instructions or data that the processor 110 has just used or recycled. If the processor 110 needs to use the instruction or data again, it can be called directly from the memory. Repeated access is avoided, and the waiting time of the processor 110 is reduced, thus improving the efficiency of the system.
  • the charging management module 140 is configured to receive a charging input from a charger.
  • the power management module 141 is used for connecting the battery 142 , the charging management module 140 and the processor 110 .
  • the power management module 141 receives the input from the battery 142 and/or the charging management module 140 to provide power for the processor 110 , the internal memory 121 , the display screen 194 , the camera 193 , and the wireless communication module 160 .
  • the wireless communication function of the first electronic device 100 can be realized by the antenna 1, the antenna 2, the mobile communication module 150, the wireless communication module 160, the modem processor and the baseband processor.
  • Antenna 1 and Antenna 2 are used to transmit and receive electromagnetic wave signals.
  • Each antenna in the first electronic device 100 may be used to cover single or multiple communication frequency bands. Different antennas can also be multiplexed to improve the utilization of the antennas.
  • Antenna 1 can be multiplexed as a diversity antenna of a wireless local area network.
  • the antenna may be used in conjunction with a tuning switch.
  • the mobile communication module 150 can provide wireless communication solutions including 2G/3G/4G/5G applied on the first electronic device 100 .
  • the wireless communication module 160 can provide applications on the first electronic device 100 including wireless local area networks (wireless local area networks, WLAN) (such as wireless fidelity (wireless fidelity, Wi-Fi) network), bluetooth (bluetooth, BT), global Wireless communication solutions such as global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR).
  • the wireless communication module 160 may be one or more devices integrating at least one communication processing module.
  • the wireless communication module 160 receives electromagnetic waves via the antenna 2 , frequency-modulates and filters the electromagnetic wave signals, and sends the processed signals to the processor 110 .
  • the wireless communication module 160 can also receive the signal to be sent from the processor 110 , frequency-modulate it, amplify it, and convert it into electromagnetic waves through the antenna 2 for radiation.
  • the first electronic device 100 implements a display function through a GPU, a display screen 194 , and an application processor.
  • the external memory interface 120 can be used to connect an external memory card, such as a Micro SD card, so as to expand the storage capacity of the first electronic device 100.
  • the external memory card communicates with the processor 110 through the external memory interface 120 to implement a data storage function. Such as saving music, video and other files in the external memory card.
  • the internal memory 121 may be used to store computer-executable program codes including instructions.
  • the internal memory 121 may include an area for storing programs and an area for storing data.
  • the stored program area can store an operating system, at least one application program required by a function (such as a sound playing function, an image playing function, etc.) and the like.
  • the storage data area can store data created during the use of the first electronic device 100 (such as audio data, phonebook, etc.) and the like.
  • the internal memory 121 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one magnetic disk storage device, flash memory device, universal flash storage (universal flash storage, UFS) and the like.
  • the processor 110 executes various functional applications and data processing of the first electronic device 100 by executing instructions stored in the internal memory 121 and/or instructions stored in a memory provided in the processor.
  • the first electronic device 100 can implement audio functions through the audio module 170 , the speaker 170A, the receiver 170B, the microphone 170C, the earphone interface 170D, and the application processor. Such as music playback, recording, etc.
  • FIG. 3 it is a schematic structural diagram of a Bluetooth low energy protocol stack.
  • the above-mentioned first electronic device 100/second electronic device 200 shown in FIG. 1 can adopt the Bluetooth low energy protocol shown in FIG. 3 to realize the BLE application on the first electronic device 100/second electronic device 200.
  • the BLE protocol stack is used to package the BLE application data layer by layer to generate an air data packet that meets the BLE protocol. That is to say, the BLE application data is wrapped in a series of frame headers and frame tails.
  • the BLE protocol stack includes: a BLE application (application) layer, a BLE host (host) layer, and a BLE control (control) layer.
  • the BLE application layer includes an application program and a profile (profile)/service (service) based on a generic attribute profile (generic attribute profile, GATT).
  • the application program is a specific BLE application, such as a music application, a picture application, a voice application, a video application, and the like.
  • the BLE host layer includes generic access profile (generic access profile, GAP), GATT, attribute protocol (attribute protocol, ATT), security management (secure manager, SM) and logical link control and adaptation protocol (logic link control and adaptation) protocol, L2CAP).
  • GAP generic access profile
  • GATT attribute protocol
  • ATT attribute protocol
  • security management secure manager
  • SM secure manager
  • L2CAP logical link control and adaptation protocol
  • GAP is used to control the connection and broadcasting of electronic devices.
  • GAP defines four roles: broadcaster, observer, peripheral, and central.
  • the broadcaster refers to an electronic device that is sending an advertising event.
  • Observer refers to an electronic device that is receiving broadcast events.
  • a peripheral device refers to an electronic device that receives a link layer (link layer, LL) connection (corresponding to the slave role of the LL layer).
  • the central device refers to the electronic device initiating the LL connection (corresponding to the master device (master) role of the LL layer).
  • GAP defines the operation modes and processes for realizing various communications, including realizing one-way connectionless communication, realizing the discovery operation of electronic devices, realizing the connection operation of electronic devices, and realizing the pairing operation of Bluetooth devices, etc.
  • GAP defines Bluetooth parameters related to user interface, including Bluetooth address, Bluetooth name, Bluetooth type, and the like.
  • GATT built on the basis of ATT, establishes some common operations and frameworks for ATT to transmit and store data.
  • GATT defines two roles from the perspective of data provision and use: GATT server (server) and GATT client (client).
  • the GATT server maintains an ATT lookup table and definitions of services and characteristics.
  • a GATT client sends a request to a GATT server and receives a response from the GATT server.
  • ATT is the basis of GATT and GAP, which defines the data structure and organization of the upper layer of the BLE protocol stack.
  • the concept of attribute is the core of the ATT layer.
  • the ATT layer defines the content of the attribute and specifies the method and authority to access the attribute.
  • Attributes can be understood as a data structure, which includes data types and data values.
  • the top level is the configuration file (profile), which governs multiple services (services), services governs multiple characteristics (characteristics), and features governs multiple descriptors (descriptors).
  • ATT defines the way of communication between client and server, including: request, response, command, indication, confirmation and notification .
  • SM is responsible for the security-related content in BLE communication, including pairing, authentication and encryption.
  • L2CAP The functions provided by L2CAP include: protocol/channel multiplexing; segmentation (and reassembly) of upper-layer application data, and generation of protocol data units (packet data unit, PDU) to meet user data transmission delay requirements and facilitate follow-up Realization of retransmission, flow control and other mechanisms; PDU fragmentation (and reassembly) to generate data slices that meet LL transmission requirements; support streaming transmission (such as audio, video, etc., no retransmission or only limited retransmission is required )Wait.
  • protocol/channel multiplexing segmentation (and reassembly) of upper-layer application data, and generation of protocol data units (packet data unit, PDU) to meet user data transmission delay requirements and facilitate follow-up Realization of retransmission, flow control and other mechanisms
  • PDU fragmentation (and reassembly) to generate data slices that meet LL transmission requirements
  • support streaming transmission such as audio, video, etc., no retransmission or only limited retransmission
  • the BLE control layer includes LL and physical layer (physical layer, PL).
  • the functions implemented by LL include: which radio frequency channel is selected for communication, how to identify air data packets, at what point in time to send data packets, how to ensure data integrity, how to retransmit, and how to link management and control etc.
  • PL is used to specify the wireless frequency band used by BLE, the mode and method of modulation and demodulation, etc.
  • a host controller interface (host controller interface, HCI) is also included between the BLE host and the BLE controller.
  • HCI can be used in the occasion where two Bluetooth chips implement the BLE protocol stack, and is used to standardize the communication protocol and communication commands between the two.
  • FIG. 4 it is a schematic flowchart of a method for a first electronic device to discover a second electronic device provided in the embodiment of the present application, and the process includes:
  • the first electronic device displays a first interface.
  • the first electronic device In response to receiving a user's trigger operation on the first interface, the first electronic device sends a broadcast message A, where the broadcast message A is used to discover surrounding electronic devices.
  • the second electronic device receives the broadcast message A.
  • the user triggers the BLE function of the first electronic device on the first interface displayed by the first electronic device to discover other electronic devices.
  • the user's trigger operation is, for example, the user triggers functions such as sharing/forwarding in the interface of the gallery application (ie, the first interface), or the user triggers functions such as screen projection in the video playback interface (ie, the first interface),
  • the user enables the Bluetooth function in the setting application interface (ie, the first interface) of the first electronic device, or, the user inputs a voice command to trigger sharing/forwarding/casting/enabling the Bluetooth function, etc.
  • the first electronic device In response to receiving a user's trigger operation on the first interface, the first electronic device sends a broadcast message A (also referred to as a discovery request message) for discovering surrounding electronic devices.
  • the broadcast packet A may carry device information of the first electronic device (eg, manufacturer information of the first electronic device, name of the first electronic device, etc.).
  • the broadcast message A may also carry the service identifier of the first electronic device (for example, image sharing service, screen projection service, and discovery service).
  • the second electronic device sends the broadcast message B.
  • the broadcast message B is received by the first electronic device.
  • the second electronic device After receiving the broadcast message A, the second electronic device parses the broadcast message A. If it is confirmed according to the analysis result of the broadcast message A that the second electronic device is a candidate electronic device scanned by the first electronic device, a broadcast message B is sent in response to the received broadcast message A. If it is determined according to the analysis result of the broadcast message A that the second electronic device is not a candidate electronic device scanned by the first electronic device, the broadcast message A is ignored. For example: according to the manufacturer information of the first electronic device in the broadcast message A, the second electronic device determines that the second electronic device is the same manufacturer as the first electronic device, or is a cooperative manufacturer of the first electronic device, and confirms that the second electronic device A device is a candidate electronic device for scanning by the first electronic device. Then, the second electronic device sends a broadcast message B, wherein the broadcast message B carries information such as the device identifier of the second electronic device, the account number logged in, the device type, and the service identifier registered by the second electronic device.
  • the BLE broadcast message includes a 1-byte preamble, a 4-byte access address, a 1-byte header, a 1-byte length, 0 to 37 bytes of data, and a 3-byte checksum.
  • the header includes 4-bit broadcast message type, 2-bit reserved bit, 1-bit sending address type and 1-bit receiving address type.
  • the data includes a 6-byte broadcast device address and a 31-byte payload
  • the content that the electronic device (such as the second electronic device) needs to broadcast includes, for example: device name (usually 22 bytes), account name, device type, registration service, capability and other information, and these contents are usually larger than 31 characters. section, and the payload included in a broadcast message is at most 31 bytes. Therefore, the discovered electronic device generally needs to send multiple broadcast messages for responding to the broadcast message A sent by the first electronic device. It should be noted that the process shown in Figure 4 is based on the fact that the discovered electronic device needs to broadcast two broadcast messages (respectively the broadcast message B in this step and the broadcast message C in step S404) as an example Illustrated.
  • the broadcast message B carries, for example, the device identifier of the second electronic device (such as a media access control address (media access control address, MAC address), device name (such as SoundX), login account (such as 123@huawei.com), One or more of registered business identifiers and device types (such as smart speakers).
  • the device identifier of the second electronic device such as a media access control address (media access control address, MAC address), device name (such as SoundX), login account (such as 123@huawei.com), One or more of registered business identifiers and device types (such as smart speakers).
  • the first electronic device buffers the broadcast packet B.
  • the caching mechanism of the first electronic device may be, for example, an LruCache mechanism, which caches the recently received N4 (for example, 20) broadcast messages B (the N4 broadcast messages B may be any sent by one or more electronic devices). That is to say, when the 21st broadcast message B is received, if the 21st broadcast message B is the same as any of the first 20 broadcast message B, update the timestamp of the same broadcast message B . If the 21st broadcast message B is different from the first 20 broadcast messages B (for example, the identification and account number of the electronic device are different), replace the earliest received broadcast message B with the broadcast message B received this time.
  • N4 for example, 20
  • the second electronic device sends the broadcast message C after a time period T1.
  • the broadcast message C is received by the first electronic device.
  • the broadcast message C carries, for example, a device identifier (such as a MAC address) of the second electronic device.
  • the broadcast message C may also carry one or more items of the second electronic device's login account, registered service identifier, and device capability.
  • the broadcast packet C may carry the information of the second electronic device that is not carried in the broadcast packet B. That is, at least part of the contents of the broadcast message C and the broadcast message B are different.
  • the first electronic device parses the broadcast message B, and then sends an acknowledgment (acknowledge, ACK) message for the broadcast message B.
  • the second electronic device parses the ACK message, and then sends the broadcast message C.
  • T2 is usually 300ms.
  • the second electronic device directly sends the broadcast message C after the time period T1 after sending the broadcast message B, that is, the second electronic device does not need to wait to receive the broadcast message B sent by the first electronic device.
  • ACK packets are smaller than T2 (for example, 300ms).
  • T1 may be set as a fixed duration (for example, 60ms) plus a random duration (for example, a random duration within 40ms).
  • T2 is usually 300ms.
  • the first electronic device caches the broadcast message C.
  • the first electronic device After receiving the broadcast message C sent by the second electronic device, the first electronic device caches the content of the broadcast message C. It should be noted that here, the first electronic device caches the content of the broadcast message C of the second electronic device, so that when the first electronic device discovers surrounding electronic devices again later, it can quickly discover the second electronic device. Of course, this step is optional.
  • the first electronic device displays a second interface according to the broadcast message B and the broadcast message C, where the second interface includes information about the second electronic device.
  • the first electronic device After the first electronic device receives the broadcast message C, it finds the broadcast message B according to the MAC address of the broadcast message C, wherein the found MAC address of the broadcast message B is the same as the MAC address of the broadcast message C, That is, the broadcast message B and the broadcast message C are sent by the same electronic device (ie, the second electronic device). Then, the first electronic device splices the content of the broadcast message B and the broadcast message C to determine whether to display the information of the second electronic device in the discovery list (ie, the second interface) displayed by the first electronic device.
  • an interface 601 that is, a first interface of a setting application displayed by a first electronic device (such as a mobile phone).
  • a first electronic device such as a mobile phone.
  • the mobile phone detects that the user operates the switch control 602 of the Bluetooth function in the interface 601, the mobile phone sends a broadcast message A to discover surrounding electronic devices.
  • the second electronic device (such as a smart speaker) sends the broadcast message B after receiving the broadcast message A, and sends the broadcast message C after sending the broadcast message B for a duration T1.
  • the first electronic device determines to find the second electronic device according to the received broadcast message B and broadcast message C, and then displays an interface 603 as shown in (2) in FIG. 6 .
  • the interface 603 includes a list of surrounding devices discovered by the mobile phone, for example, includes a second electronic device identifier 604 (for example, a smart speaker, the device name is SoundX). It can be seen that, because the second electronic device sends the broadcast message C in advance, the process of the first electronic device discovering the second electronic device is accelerated.
  • a second electronic device identifier 604 for example, a smart speaker, the device name is SoundX.
  • the second electronic device after the second electronic device receives the broadcast message A sent by the first electronic device, the second electronic device needs to send more than two (for example, N1, N1 is greater than 2)
  • the broadcast message is used to reply the information of the second electronic device.
  • the second electronic device sends each broadcast message after the first broadcast message (that is, broadcast message B)
  • the broadcast message is sent directly after the time length T1 after sending the last broadcast message.
  • the second electronic device when the second electronic device sends each broadcast message after the first broadcast message (that is, the broadcast message B), it needs to wait for the first electronic device to send This broadcast message is sent after the ACK message of the previous broadcast message.
  • the next broadcast message is automatically sent after a time period T1 after sending a broadcast message.
  • the first electronic device needs to discover the second electronic device again within a relatively short period of time (for example, within the buffering period of buffering the broadcast message C). For example, the first electronic device triggers the forwarding/sharing function of pictures/files/videos again within the short period of time, or the first electronic device refreshes the discovered electronic devices periodically (the period is shorter than the duration T1). Then, after performing step S406, the first electronic device further performs step S407-step S409.
  • the first electronic device sends the broadcast message A.
  • the second electronic device receives the broadcast message A.
  • the broadcast message A is used to discover electronic devices around the first electronic device.
  • the broadcast packet A may carry device information of the first electronic device (eg, manufacturer information of the first electronic device, name of the first electronic device, etc.).
  • the broadcast message A may also carry the service identifier of the first electronic device (for example, image sharing service, screen projection service, and discovery service).
  • the first electronic device After the user triggers a picture sharing function on the first electronic device, the first electronic device discovers the second electronic device after performing the above steps S401-S406, and the first electronic device can establish a connection with the second electronic device and transmit The picture shared this time. In a short period of time, when the user triggers another picture sharing function on the first electronic device again, the first electronic device sends a broadcast message A to discover surrounding electronic devices again.
  • the second electronic device sends the broadcast message B.
  • the broadcast message B is received by the first electronic device.
  • the broadcast message B here is the same as the broadcast message B sent by the second electronic device in step S402, wherein the broadcast message B carries information such as the device identification (such as MAC address), login account, and device type of the second electronic device.
  • the broadcast message B carries information such as the device identification (such as MAC address), login account, and device type of the second electronic device.
  • the first electronic device searches for broadcast message C according to broadcast message B, and then displays a third interface according to broadcast message B and broadcast message C, where the third interface includes information about the second electronic device.
  • the first electronic device after the first electronic device receives the broadcast message B, it can find the previously cached broadcast message C according to the MAC address of the broadcast message B, and store the contents of the broadcast message B and the broadcast message C Splicing is performed to determine whether to display the information of the second electronic device in the list of discovered devices refreshed by the first electronic device (that is, the third interface), such as displaying the icon and name of the second electronic device.
  • the process of the first electronic device discovering the second electronic device again is the same as the process of discovering the second electronic device for the first time, that is, the second electronic device needs to send two broadcast messages to respond to the first electronic device
  • the broadcast message sent for discovery and after the second electronic device receives the ACK message sent by the first electronic device for the first broadcast message, the second electronic device sends the second broadcast message arts.
  • the first electronic device can perform content splicing according to the broadcast message and another previously cached broadcast message, and determine that the first electronic device finds 2. Electronic equipment.
  • the second electronic device after the second electronic device receives the broadcast message A sent by the first electronic device, the second electronic device needs to send more than two (for example, N1, N1 is greater than 2)
  • the broadcast message is used to reply the information of the second electronic device.
  • the first electronic device after the first electronic device receives the first broadcast message sent by the second electronic device, it can determine in advance to discover the second electronic device according to other broadcast messages (one or more broadcast messages) cached by itself, and accelerate A discovery process for the second electronic device.
  • a reverse broadcast packet may be sent.
  • the reverse broadcast message is used to request the second electronic device to alternately send all the broadcast messages used to respond to the broadcast message A.
  • step S402 after step S402 is executed, the first electronic device receives the broadcast message B, but at this time there is still a lack of other broadcast messages for responding to the broadcast message A, such as broadcast message C. Then, the first electronic device executes step S501, that is, sends a broadcast message F, and the broadcast message F is used to request the second electronic device to alternately send all broadcast messages for responding to the broadcast message A. Then, there are two situations.
  • the second electronic device receives the broadcast message F before the time period T1 after sending the broadcast message B, then the second electronic device alternately sends a message to respond to the broadcast message A All the packets (that is, the time interval for the second electronic device to send each broadcast packet is relatively short, less than the duration T1).
  • the second electronic device receives the broadcast message F after the time T1 after sending the broadcast message B, then the second electronic device still sends the broadcast message C after the time T1 after sending the broadcast message B (i.e. execute step S404). Then, after the broadcast message F is received, all the messages used to respond to the broadcast message A are sent alternately.
  • the broadcast message F sent by the first electronic device can be used to trigger the second electronic device to quickly and alternately send all the broadcast messages used to respond to the broadcast message A, which is beneficial for the first electronic device to quickly collect the response broadcast message All broadcast messages of A to quickly discover the second electronic device.
  • step S402 when step S402 is executed, if the broadcast message B is lost, the first electronic device does not receive the broadcast message B.
  • the second electronic device continues to send the broadcast message C after a time period T1 after sending the broadcast message B, that is, executes step S404.
  • the first electronic device receives the broadcast message C, it determines that there is still no other broadcast message corresponding to the broadcast message A, such as the broadcast message B, and then sends a reverse broadcast message (that is, executes step S502).
  • the second electronic device receives the broadcast message F, it alternately sends all the messages used to respond to the broadcast message A. After the second electronic device sends the missing broadcast message (for example, broadcast message B) (i.e.
  • step S503 after the first electronic device receives the missing broadcast message (for example, broadcast message B), and then according to the previous For the buffered broadcast message (for example, broadcast message C), go to step S406.
  • the first electronic device buffers the received broadcast packet B (that is, executes step S504).
  • the first electronic device needs to resend the broadcast message A
  • the second electronic device also needs to resend all the broadcast messages used to respond to the broadcast message A (that is, broadcast message B and broadcast message C), and the interval between broadcast messages sent by the second electronic device is T1.
  • the first electronic device sends a reverse broadcast message, that is, the broadcast message F, which is beneficial to trigger the second electronic device to quickly and alternately send Responding to all the broadcast messages of the broadcast message A (that is, the time interval for the second electronic device to send each broadcast message is relatively short, less than the duration T1), it is beneficial for the first electronic device to quickly collect all the broadcast messages responding to the broadcast message A. text, quickly discover the second electronic device.
  • the broadcast message F that is, the time interval for the second electronic device to send each broadcast message is relatively short, less than the duration T1
  • the second electronic device may not broadcast its own information (that is, send the broadcast message B and Broadcast the packet C), so as to be discovered by other electronic devices (such as the first electronic device).
  • the second electronic device does not need to broadcast the information of the second electronic device, that is, the second electronic device does not need to send broadcast messages frequently, which is beneficial to save power consumption of the second electronic device.
  • the above-mentioned description takes the discovery process of the first electronic device and the second electronic device as an example, and this embodiment of the present application can also be applied to other scenarios (such as networking scenarios, scenarios of sending heartbeat messages) .
  • the sender's electronic device does not need to wait for the receiver's electronic device to reply with an ACK message. After T1, subsequent data packets are automatically sent, etc.
  • the broadcast parameters of the electronic device can also be adjusted according to the business scenario (such as the business stage, the size of the cached business data), the state of the electronic device, the capability of the Bluetooth chip, etc. (such as broadcast type, scan duty cycle, broadcast duty cycle, number of broadcast channels, etc.), connection parameters (such as connection interval, number of connection channels, etc.), to speed up the discovery process, improve the discovery success rate, and speed up the connection process.
  • the business scenario such as the business stage, the size of the cached business data
  • the state of the electronic device such as broadcast type, scan duty cycle, broadcast duty cycle, number of broadcast channels, etc.
  • connection parameters such as connection interval, number of connection channels, etc.
  • the electronic device sets different broadcast parameters (such as broadcast types) in different business stages.
  • the first electronic device sends an advertisement message A for discovering surrounding electronic devices (that is, executes step S401 in FIG. non-connectable). Since the broadcast type of the first electronic device is unconnectable, when the application layer of the first electronic device sends the broadcast message A to the bottom layer, the bottom layer does not need to wait for the broadcast message connected by other electronic devices (such as the second electronic device), and It is to send broadcast message A directly. In the prior art, the broadcast type of the first electronic device is connectable. When the application layer of the first electronic device sends the broadcast message A to the bottom layer, the bottom layer (for example, specifically L2CAP) needs to wait for a connection interval (connection interval) for waiting to receive broadcast messages connected by other electronic devices.
  • a connection interval connection interval
  • connection interval is a time interval for interaction between two electronic devices, which is generally 20 ms. It can be seen that when the first electronic device sets the broadcast type to unconnectable before sending the broadcast message A, it is beneficial for the discovery process to speed up the duration of a connection interval, for example, 20ms.
  • the broadcast type of the first electronic device is set as connectable (connectable). That is to say, when the first electronic device subsequently sends a reverse broadcast (such as step S501 in (1) in FIG. 7, step S502 in (2) in FIG. In step S407), the broadcast type of the first electronic device is connectable. This is because, when the first electronic device receives any broadcast message from the second electronic device, when the bottom layer of the first electronic device sends the broadcast message of the application layer, it can wait for a connection interval for receiving Whether other electronic devices (such as the second electronic device) have a connection broadcast message, so as to improve the success rate of connecting other electronic devices.
  • the second electronic device After the second electronic device receives any broadcast message sent by the first electronic device, for example, the second electronic device receives the broadcast message A of the first electronic device (that is, as shown in FIG. 4 After step S401), the broadcast type of the second electronic device can be set as connectable. Then, when the bottom layer of the second electronic device sends the broadcast message of the application layer, it may wait for a connection interval to receive connection requests from other electronic devices (such as the first electronic device).
  • the application layer of the first electronic device or the second electronic device can call the application programming interface (application programming interface, API) setting of AdvertiseSettings.Builder setConnectable (boolean connectable) Whether the broadcast type is connectable or not connectable.
  • the application programming interface application programming interface, API
  • AdvertiseSettings.Builder setConnectable boolean connectable
  • FIG. 8 (1) in FIG. 8 is the content of an HCI layer data packet captured by the Bluetooth packet capture tool. Wherein, mark 801 shows that the broadcast type of the electronic device is set as connectable. (2) in Figure 8 is the content of another HCI layer data packet captured by the Bluetooth packet capture tool. Wherein, mark 802 shows that the broadcast type of the electronic device is set as unconnectable.
  • the electronic device dynamically adjusts the connection interval according to the amount of cached service data.
  • two or more tasks when there are two or more tasks (which may be different tasks of the same business or tasks of different businesses) between the first electronic device and the second electronic device, two or more There may be conflicts between tasks.
  • one of the tasks needs to send a data packet of the discovery process (abbreviated as a discovery packet, such as broadcast message A and broadcast message F sent by the first electronic device in Figure 4, and broadcast message B and broadcast message sent by the second electronic device.
  • Broadcast message C another task needs to send a data packet (referred to as a connection packet for short) after the connection is established. If the electronic device needs to send the discovery packet and the connection packet at the same time, a conflict occurs.
  • the first electronic device For example, if the user triggers a picture/file/video sharing function (referred to as a sharing task) on the first electronic device, then the first electronic device establishes a BLE connection with the second electronic device and transmits the shared picture/file/video. Packet of video etc. If in the process of transmitting the connection packet, other tasks (such as networking tasks) of the first electronic device also require the first electronic device and the second electronic device to interact with the discovery packet, then the discovery of the interaction between the first electronic device and the second electronic device The packet may collide with a connection packet being transmitted by the first electronic device and the second electronic device.
  • a sharing task a picture/file/video sharing function
  • the time window for the first electronic device and the second electronic device to send the discovery packet in the networking task (abbreviated as the discovery window) is different from the time window for sending the connection packet in the sharing task.
  • the time window (referred to as the connection window for short) coincides.
  • the hardware layer also called the chip layer
  • the hardware layer will The priority of the connection packet is considered to be higher than that of the discovery packet, and the connection packet is sent first, and the discovery packet is discarded.
  • the prior art prolongs the discovery process of two electronic devices in the networking task, which may even cause the two electronic devices to fail to discover each other, that is, the success rate of discovery is reduced.
  • the L2CAP layer of the electronic device (such as the first electronic device/second electronic device) receives the discovery packet and the connection packet sent by the application layer
  • the L2CAP layer of the electronic device caches the discovery packet to be sent. package, send a connection package.
  • the connection interval refers to a time interval between interactions between the first electronic device and the second electronic device after the first electronic device establishes a connection with the second electronic device.
  • the embodiment of the present application caches the discovery packet in the networking task, and sends the discovery packet in the networking task when the connection interval in the sharing task is detected, Therefore, the function of aligning the discovery window of the sharing task with the connection interval of the networking task is achieved, thereby shortening the discovery process of two electronic devices in the networking task compared with the prior art.
  • the L2CAP layer of the electronic device when multiple discovery packets conflict with connection packets, when the L2CAP layer of the electronic device (first electronic device/second electronic device) is caching the discovery packets of multiple services, it may follow a certain priority
  • the cache queue is established according to the level (for example, according to the importance of the business, or the importance of the discovery packet, etc.).
  • the L2CAP layer of the electronic device When the connection interval is detected, the L2CAP layer of the electronic device will send the discovery packets with high priority according to the order of priority, so as to ensure the discovery speed and success rate of services with high priority.
  • the connection interval between the first electronic device and the second electronic device may also be dynamically adjusted according to the data amount of the cached discovery packet.
  • a maximum threshold may be set for the data volume of the cached discovery packet
  • a minimum threshold may be set for the cached data volume of the discovery packet.
  • connection interval between the first electronic device and the second electronic device increases, it means that the first electronic device and the second electronic device are used to send discovery packets of other services
  • the discovery window is also increased, which is beneficial to quickly sending more discovery packets between the first electronic device and the second electronic device, shortening the discovery process of other services and improving the success rate of discovery.
  • connection interval between the first electronic device and the second electronic device decreases, it is equivalent to the increase of the connection window between the first electronic device and the second electronic device.
  • the discovery window used by the first electronic device and the second electronic device for sending discovery packets of other services is also reduced.
  • Chip resources are allocated appropriately.
  • connection parameters between the first electronic device and the second electronic device can also be restored to the value before adjustment or restored Default etc.
  • L2CAP connection parameter ie, connection interval
  • the electronic device dynamically adjusts the duty cycle (including scanning duty cycle, broadcast duty cycle, etc.) according to the state of the electronic device.
  • the duty cycle refers to the processing time of the electronic device divided by the idle interval time.
  • the broadcast duty cycle refers to the broadcast duration of the electronic device divided by the idle interval duration. Understandably, the larger the broadcast duty cycle, the more frequently the electronic device broadcasts, and the faster the electronic device is discovered and connected.
  • the scanning duty cycle refers to the scanning duration of the electronic device divided by the idle interval duration, wherein scanning refers to listening to broadcasts. It can be understood that the greater the scanning duty cycle, the more frequently the electronic device scans, the faster it finds other electronic devices, and the faster the connection.
  • the duty cycle (including scanning duty cycle, broadcast duty cycle, etc.) is dynamically adjusted according to the state of the electronic device.
  • an electronic device such as the first electronic device/second electronic device
  • enters the preset time period T3 for example, 1 minute
  • enters the preset time period T3 from the locked screen state to the unlocked state or within the preset duration T3 of opening a new application, or within the preset duration T3 of switching an application from the background to the foreground, or when the electronic device is running a specific application
  • the electronic device can increase the broadcast duty ratio/scan duty cycle.
  • the electronic device has a higher probability of finding other electronic devices, so increasing the broadcast duty cycle and/or scanning duty cycle of the electronic device is conducive to the rapid broadcast or scan of the electronic device, and speeds up communication with other electronic devices.
  • Other electronic device discovery process is considering that in these scenarios, the electronic device has a higher probability of finding other electronic devices, so increasing the broadcast duty cycle and/or scanning duty cycle of the electronic device is conducive to the rapid broadcast or scan of the electronic device, and speeds up communication with other electronic devices.
  • Other electronic device discovery process is considering that in these scenarios, the electronic device has a higher probability of finding other electronic devices, so increasing the broadcast duty cycle and/or scanning duty cycle of the electronic device is conducive to the rapid broadcast or scan of the electronic device, and speeds up communication with other electronic devices.
  • Other electronic device discovery process is considering that in these scenarios, the electronic device has a higher probability of finding other electronic devices, so increasing the broadcast duty cycle and/or scanning duty cycle of the electronic device is conducive to the rapid broadcast or scan of the electronic device, and speeds up communication with other electronic devices.
  • the electronic device may reduce the broadcast duty cycle and/or the scan duty cycle. This is because, in this scenario, the probability that the electronic device finds other electronic devices is small, or even zero, so reduce the broadcast duty cycle and/or scan duty cycle, or even reduce the broadcast duty cycle and/or scan duty cycle.
  • the duty cycle is adjusted to zero, which is beneficial to reduce the power consumption of electronic equipment.
  • the broadcast duty cycle/scanning duty cycle of the electronic device can be set to other values, such as default values.
  • the application layer of the electronic device when the application layer of the electronic device detects that the electronic device enters the bright screen state from the off-screen state, or enters the unlocked state from the locked screen state, or starts a new application (application, APP), or when an application is switched from the background to the foreground, or when the electronic device runs a specific application, the application layer of the electronic device can call the setScanWindowMillis(int scanWindowMillis) API to set a larger scan window (relatively Compared with the default scan window, or the middle value of the scan window); call the setScanIntervalMillis(int scanIntervalMillis) API to set a smaller scan interval (compared to the default scan interval, or the middle value of the scan interval), thereby increasing Scan duty cycle.
  • the API of setScanWindowMillis(int scanWindowMillis) can be called to set a smaller scan window; the API of setScanIntervalMillis(int scanIntervalMillis) can be called to set a larger scan interval, thereby reducing the Scan duty cycle.
  • the duty cycle (including scanning duty cycle, broadcast duty cycle, etc.) is dynamically adjusted according to the state of the electronic device.
  • the electronic device detects that the user chooses to connect to a certain electronic device for a preset duration T3
  • the electronic device can increase the broadcast duty cycle/scanning duty cycle, which is conducive to the rapid broadcast or scan of the electronic device, and accelerates the communication with other electronic devices.
  • connection process After the electronic device establishes a connection with other electronic devices, the electronic device can reduce the broadcast duty cycle and/or the scanning duty cycle, thereby reducing the power consumption of the electronic device.
  • the electronic device can increase the broadcast duty cycle by reducing the paging interval (page interval) and increasing the paging window (page windows). Conversely, turn down the broadcast duty cycle. Increase the scan duty cycle by reducing the page scan interval and increasing the page scan windows. Conversely, turn down the scan duty cycle.
  • the value of the preset duration T3 in different states of the electronic device may be the same or different, which is not limited in this embodiment of the present application.
  • the electronic devices When the electronic devices (such as the first electronic device or the second electronic device) have different Bluetooth chip capabilities, different broadcast parameters are set. For example, if the bluetooth chip of the electronic device supports page scan (page scan) capability, then has the ability of splicing the response packet, then set the attribute value of the broadcast parameter scannable of the electronic device to true. In other words, when the bottom layer of the electronic device receives multiple response packets for the discovery request (such as the broadcast message B and broadcast message C in Figure 4 above), it can splice the multiple response packets, and then splicing them together The data packets are reported to the upper layer application.
  • page scan page scan
  • the Bluetooth chip of the electronic device does not support the paging scan capability, it does not have the ability to splice response packets, so set the attribute value of the broadcast parameter scannable of the electronic device to false. Then, when the bottom layer of the electronic device receives multiple response packets for the discovery request (such as the broadcast message B and broadcast message C in the above-mentioned Figure 4), it does not splice the multiple response packets, and directly combines the multiple response packets The packet is reported to the upper layer application. If the scannable attribute value of the electronic device is still true at this time, the electronic device will still wait for the package processing time (for example, 20ms), and then report multiple response packets to the upper-layer application. Therefore, when the bluetooth chip of the electronic device does not support the paging scanning capability, setting the scannable attribute value to false is beneficial to save the time of the grouping process and speed up the discovery process and the connection process.
  • the application layer of the electronic device can call the API of AdvertisingSettingsParameters.Builder setScannable(boolean scannable) to set the attribute value of scannable.
  • the API of AdvertisingSettingsParameters.Builder setScannable (boolean scannable) to set the attribute value of scannable.
  • FIG. 10 is the content of an HCI layer data packet captured by the Bluetooth packet capture tool. Wherein, mark 1001 shows that the broadcast type of the electronic device is set to be scannable.
  • mark 1002 shows that the broadcast type of the electronic device is set as unscannable.
  • the electronic device sets the scanning duty cycle according to the capability of the Bluetooth chip.
  • each service will register a scanner at the L2CAP layer at the application layer of the electronic device (such as the first electronic device or the second electronic device) when using Bluetooth.
  • one service corresponds to one scanner.
  • a certain number for example, 32
  • new services will no longer be able to register the scanners, so the Bluetooth function of the electronic device cannot be used.
  • the electronic device provides a preset number N2 of scanners, wherein each scanner corresponds to a scanning duty cycle of a gear.
  • each business selects one of the scanners for registration according to its own business type, business characteristics, business needs and other factors.
  • the scanning duty cycle of the scanner selected by each service can meet the scanning requirements of the service.
  • multiple services can be registered on one scanner.
  • the embodiment of the present application solves the problem that the electronic device can only register a limited number (for example, 32) of scanners by multiplexing the scanners.
  • the electronic device may also dynamically adjust the scanners of each gear provided by the electronic device according to the capabilities of the Bluetooth chip.
  • the electronic device is equipped with dual bluetooth chips, they are bluetooth chip A and bluetooth chip B respectively. Moreover, the electronic device is equipped with a scanner with 4 gears. The order of the duty cycles of the four gears from low to high is: gear 1 ⁇ gear 2 ⁇ gear 3 ⁇ gear 4.
  • the scanners of gear 1 and gear 2 can be configured on Bluetooth chip A, and the scanners of gear 3 and gear 4 can be configured on Bluetooth chip B.
  • the Bluetooth chip A of the electronic device continues to work, and the Bluetooth chip B stops working.
  • the scanning duty cycle on the Bluetooth chip A is relatively low, which is beneficial to reduce the overall power consumption of the electronic device.
  • the scanners of gears 1 and 4 on Bluetooth chip A, and configure the scanners of gears 2 and 3 on Bluetooth chip B. Then, one of the scanners is selected for registration based on factors such as the business type, business characteristics, and business requirements of the running business itself. Due to the reasonable allocation of high and low gear scanners on a Bluetooth chip, it is beneficial for electronic devices to quickly find the opposite electronic device, speeding up the discovery process and connection process.
  • the Bluetooth chip A and the Bluetooth chip B can also be equipped with scanners with 4 gears, that is, gears 1 to 4, respectively.
  • gears 1 to 4 gears 1 to 4, respectively.
  • an application that can call this bluetooth chip for example, bluetooth chip A
  • bluetooth chip B can switch to calling another bluetooth chip (for example, bluetooth chip B). Since the gears of the barcode scanners on the two Bluetooth chips are the same, the user has no perception when the application switches the Bluetooth chip.
  • the preset rule can Identify scanners with specific settings.
  • the electronic device is originally configured with 4-gear scanners, and the order of duty cycles of the 4-gear scanners from low to high is: gear 1 ⁇ gear 2 ⁇ gear 3 ⁇ gear 4.
  • gear 1 ⁇ gear 2 ⁇ gear 3 ⁇ gear 4 At this time, when the electronic device can only support one or two scanners, one or two scanners can be configured according to preset rules. Businesses are then registered on the one or two stall scanners.
  • the preset rule is: (1) The electronic device selects a scanner with a higher configuration level (for example, a level 4 is selected, or a level 4 and a level 3 are selected). In this way, when the running business is registered on a scanner with a higher gear, the electronic device can meet the scanning needs of all businesses.
  • the electronic device selects a scanner configured with more gears corresponding to services. For example, there are 6 services running on an electronic device, of which 1 service corresponds to gear 1, 2 services correspond to gear 2, 3 services correspond to gear 3, and 1 service corresponds to gear 4. Then, when the chip capability of the electronic device is not enough, you can choose configuration level 3 or select a scanner with configuration level 3 and level 2. In this way, electronic equipment can keep most businesses unaffected.
  • the electronic device selects and configures a scanner corresponding to a service with a higher priority. In this way, the electronic device can ensure that services with high priority will not be affected.
  • the electronic device selects and configures a scanner corresponding to the gear of the service running in the foreground. In this way, the electronic device can ensure that the services running in the foreground will not be affected.
  • the preset rule may also be other rules, and the content of the preset rule is not limited in this embodiment of the present application.
  • the electronic device can be configured with different scanning duty cycles according to the available number of Bluetooth chips and the load of the Bluetooth chips, so as to meet the scanning requirements of various services in various scenarios.
  • the electronic device is configured with a single Bluetooth chip, multiple different scanning duty cycles can be configured for the single Bluetooth chip, so that each service can choose a reasonable scanning duty cycle.
  • the Bluetooth chip configured on the electronic device (such as the first electronic device or the second electronic device) supports a unicast channel, then, when multiple services of the electronic device are concurrent, at the same time the electronic device Only the broadcast message of one service can be sent, and the broadcast message of other services is delayed, or the broadcast message of other services is directly discarded, thus affecting the discovery and connection of these services. If the Bluetooth chip configured on the electronic device supports multiple broadcast channels, when the number of broadcast messages triggered on the electronic device is greater than the number of currently available broadcast channels at the same time, the above-mentioned conflicts also exist, affecting the discovery and connection of some services .
  • the electronic device may combine broadcast packets and reverse broadcast packets of different tasks of the same service. For example, if the user triggers a picture/file/video sharing function on the first electronic device, then the first electronic device sends a broadcast message (such as broadcast message A) for discovering surrounding electronic devices. When the first electronic device receives the first response packet (eg broadcast message B) returned by the second electronic device, the first electronic device sends a reverse broadcast message (eg broadcast message F). If the user triggers another picture/file/video sharing function on the first electronic device before the first electronic device sends the reverse broadcast message, then the first electronic device responds to the user's trigger operation and again A broadcast message (for example, broadcast message A) for discovering surrounding electronic devices is sent.
  • a broadcast message such as broadcast message A
  • the first electronic device sends a reverse broadcast message (for example, a broadcast message F) and a broadcast message (for example, a broadcast message A) for discovering surrounding electronic devices is found for the second time to send a conflict.
  • a reverse broadcast message for example, a broadcast message F
  • a broadcast message for example, a broadcast message A
  • the two broadcast messages may be combined, and then the combined broadcast message may be sent.
  • the second electronic device parses to obtain the contents of the two broadcast messages (that is, the broadcast message F and the broadcast message A). It can be seen that, compared with the prior art, the electronic device combines and sends two broadcast messages, which ensures the concurrency of two tasks of the same service and accelerates the discovery and connection process of different tasks of the service.
  • FIG. 11 it is the format of the effective payload (31 bytes) part in the data field in the broadcast message. Since there are only four fields in the broadcast message used for discovery (for example, broadcast message A) and the reverse broadcast message (for example, broadcast message F), the content of the four fields is different, which are the sender Btype (Sender Btype), sender BID (Sender BID), Receiver Btype (Receiver Btype) and Receiver BID (Receiver BID).
  • the broadcast message used for discovery for example, broadcast message A
  • the sender Btype (Sender Btype) and the sender BID (Sender BID) while the receiver Btype (Receiver Btype) and the receiver BID ( Receiver BID) is empty.
  • the content in the sender Btype (Sender Btype) and sender BID (Sender BID) in the reverse broadcast message (such as broadcast message F) is empty, while the receiver Btype (Receiver Btype) and receiver BID (Receiver BID) has content.
  • a preset number N3 of broadcast channels may be set for transmitting broadcast messages, so as to save chip resources.
  • the N3 broadcast channels may correspond to the N3 service types.
  • the service selects a broadcast channel corresponding to its own service type for sending the broadcast message. If multiple services of the same service type need to send broadcast packets at this time, the broadcast packets corresponding to the service types may be multiplexed.
  • the application layer of the electronic device combines the broadcast messages of these multiple services, and then sends the combined broadcast message through the broadcast channel corresponding to the service type, so as to ensure that the broadcast messages of each service are sent in time, reducing the The waiting time is shortened, and the discovery process and connection process of multiple services are accelerated.
  • services of different service types select and multiplex broadcast channels corresponding to the service types.
  • the electronic device sets four broadcast channels for transmitting broadcast packets, where the four broadcast channels respectively correspond to service types of signaling type, text type, file type, and video type. It can be understood that the service characteristics of these four service types are different, and there are great differences in rate, stability, and duration. Therefore, a corresponding broadcast channel is matched for this service type. For example, the broadcast channel with the best communication quality is preferentially provided to the broadcast message of the signaling type. As shown in Table 1, it is a description of broadcast channels of four service types.
  • the electronic device may indicate the service type of the broadcast message in the Sender Btype (or Receiver Btype).
  • Sender Btype (or Receiver Btype) is 1 byte, including 8 bits. Each bit corresponds to a service type, and the Sender Btype (or Receiver Btype) can indicate 8 service types in total.
  • the electronic device is set with four service types, which are signaling type, text type, file type, and video type. Then, the 4 bits starting from the lowest bit in the Sender Btype (or Receiver Btype) are used to indicate the signaling type, text type, file type and video type in turn.
  • the electronic device can also indicate the service identifier of the broadcast message on the Sender BID (or Receiver BID).
  • Sender BID (or Receiver BID) is 2 bytes, including 16 bits. Each bit corresponds to a service identifier, and the Sender BID (or Receiver BID) can indicate 16 different service identifiers in total. In other words, the embodiment of the present application can combine the broadcast messages of up to 16 services into one broadcast message. After the above-mentioned Sender Btype, Sender BID, Receiver Btype and Receiver BID indicate the service type and the service identification of multiple services, the application layer of the electronic device merges the contents of the optional TLV (Optional TLV) field of multiple services.
  • TLV Optional TLV
  • the Bluetooth chip configured in the electronic device supports a unicast broadcast channel, or, although the Bluetooth chip configured in the electronic device supports a multicast channel, the chip capability is not enough to provide a preset number N3 broadcast channels Channels are used to transmit broadcast messages.
  • some of these business types can be combined.
  • multiple service types multiplex one broadcast channel, so two or more service types can be indicated in the Sender Btype (or Receiver Btype).
  • services of two or more service types can also be combined in one broadcast message.
  • merging processes refer to the description of related content above, and will not repeat them here.
  • FIG. 12 it is a flow chart of a method for multiplexing a broadcast channel provided in the embodiment of the present application, and the process includes:
  • a service application generates a broadcast message to be sent.
  • step S1202. Determine whether the service application specifies the service type of the broadcast message. If the service application specifies the service type of the broadcast packet, step S1203 is executed. If the service application does not specify the service type of the broadcast message, step S1210 is performed.
  • step S1203. Determine whether the broadcast channel corresponding to the specified service type has been used. If it has been used, go to step S1204. If not used, execute step S1205.
  • the broadcast message requested to be sent by the current service application is combined with the broadcast message to be sent by the broadcast channel. For example, add the service identifier indicating the corresponding service application in the Sender BID (or Receiver BID), and add the corresponding content in the broadcast message requested by the service application in the Optional TLV.
  • step S1205. Determine whether there is a broadcast channel to be allocated. If yes, execute step S1206. If not, go to step S1207.
  • the Bluetooth chip configured in the electronic device determines whether the number of broadcast channels supported by the Bluetooth chip configured in the electronic device is fully occupied. If all are occupied, there are no broadcast channels to be allocated; if not all are occupied, there are still broadcast channels to be allocated.
  • the broadcast channel is subsequently used to transmit the service type specified by this service application.
  • the broadcast channel corresponding to other service types is multiplexed to send the broadcast message requested by the current service application. That is, the broadcast message requested to be sent by the current service application is combined with the broadcast message to be sent by a broadcast channel corresponding to a certain other service type. For example, add to Sender Btype (or Receiver Btype) to indicate the business type specified by this business application, add to Sender BID (or Receiver BID) to indicate the business identifier corresponding to this business application, and add this business to Optional TLV The corresponding content in the broadcast message requested by the application.
  • Sender Btype or Receiver Btype
  • Sender BID or Receiver BID
  • step S1210 Determine whether there is a used broadcast channel. If yes, execute step S1211. If not, go to step S1212.
  • FIG. 12 is only an example of a method flow provided by the embodiment of the present application, and in some other embodiments, some steps may be omitted, or some steps may be combined, or the order of some steps may be exchanged.
  • many electronic devices start the scanning/broadcasting process after being powered on or turned on.
  • some thin devices such as air conditioners, smart lights, smart watches, earphones, etc.
  • broadcast themselves device information so that other electronic devices can discover and connect to themselves.
  • some electronic devices start the scanning/broadcasting process after turning on the Bluetooth function, for example, after turning on the Bluetooth function, the mobile phone starts scanning so as to discover other electronic devices and connect to other electronic devices. It can be seen that the scanning/broadcasting process starts after the electronic device is powered on or turned on or after the Bluetooth function is turned on, which consumes a lot of electricity.
  • the electronic device may be configured to trigger a scanning/broadcasting process by a service. That is to say, the electronic device does not broadcast/scan after the Bluetooth function is turned on or after it is powered on or turned on. Broadcasting/scanning is only performed when the electronic device detects and starts the corresponding service function. For example, mobile phones/tablets/smart TVs do not scan after the Bluetooth function is turned on. When the operation of the user triggering the sharing function of pictures/files/videos is detected, or the operation of the user triggering the screen projection function is detected, or the operation of the user triggering the discovery function is detected, the mobile phone/tablet/smart TV starts scanning .
  • air conditioners, smart lights, smart watches, earphones, etc. do not broadcast after they are powered on or turned on.
  • the air conditioner, smart lamp, smart watch, earphone, etc. detect that the user performs a specific operation (such as clicking a specific control, pressing a specific button, inputting a specific voice, etc.), the air conditioner, smart lamp, smart watch, earphone, etc. start broadcasting.
  • the electronic device when the electronic device is in an off-screen state, the electronic device does not scan.
  • the scanning duty cycle of the electronic device is reduced.
  • the preset application such as a smart home application, etc.
  • other applications such as a gallery application, etc.
  • preset services such as preset serviceData or UUID or other fields carried in the broadcast message
  • other services such as preset serviceData or UUID or other fields carried in the broadcast message
  • the electronic device when the electronic device is in the off-screen state, scanning is performed after receiving a broadcast message of a preset broadcast type (for example, a broadcast message whose broadcast type is connectable). Scanning will not be performed when receiving broadcast packets of other broadcast types.
  • the electronic device when the electronic device is in the off-screen state, the electronic device only receives the broadcast message sent to itself, and analyzes the broadcast message.
  • the electronic device when the electronic device is in a screen-off state, the electronic device scans only when it receives a broadcast message with a specified vendor ID. In this way, it can avoid the situation of receiving other surrounding broadcast messages from being frequently woken up, so as to achieve the effect of saving power consumption.
  • the electronic device when the electronic device is in the off-screen state, when the electronic device replies, it replies with a one-way broadcast message (that is, the broadcast message contains the address of the destination electronic device), so as to avoid other unwanted Relevant electronic devices are woken up to save power consumption.
  • a one-way broadcast message that is, the broadcast message contains the address of the destination electronic device
  • electronic devices regularly update discovered electronic devices, they also use multicast to send messages to reduce other unrelated electronic devices from being woken up.
  • the electronic device may also notify other electronic devices in a multicast manner. Then, other electronic devices may set the electronic device as an inactive state in the group broadcast list.
  • an electronic device in an inactive state may reply m broadcast messages after receiving n broadcast messages, where m and n are positive integers, and m ⁇ n. Electronic devices that are inactive reduce transmissions.
  • the electronic device when the electronic device starts the discovery function, the electronic device displays a list of scanned electronic devices around, but the user has not selected the electronic device or operated the connection within the preset time period T4. Control, the electronic device terminates the discovery task this time, and conducts a power consumption analysis. For example, the user clicks on the sharing function of pictures/files/videos etc. on the first electronic device, and the first electronic device executes a discovery process (for example, the process in FIG. 4 ). After the first electronic device displays the scanned electronic devices (for example, including the second electronic device), the user has not selected the electronic device to be connected.
  • a discovery process for example, the process in FIG. 4
  • the first electronic device within the preset time period T4 (for example, 10 minutes) after the user clicks the sharing function of pictures/files/videos on the first electronic device, after the first electronic device does not receive the electronic device selected by the user to connect, the first electronic device The electronic device terminates the current connection task.
  • T4 for example, 10 minutes
  • the display sequence of the discovered electronic devices may be determined according to the service scenarios of the electronic devices. This is because the electronic device can determine the user's intention according to the business scenario of the electronic device, determine the user's target electronic device, and then preferentially display the identification of the target electronic device in the list of discovered electronic devices, so that the user can quickly select the target electronic device. This speeds up the connection process and improves user experience.
  • the trigger to discover the function entry of the surrounding electronic devices is a gallery application/file manager/video player, etc.
  • the target electronic devices are usually rich devices, such as PCs, mobile phones, TVs, tablets, etc.
  • the user triggers the function of sharing pictures in the gallery application of the electronic device when the electronic device displays the discovered electronic devices, it will give priority to displaying the identification of the electronic device that supports the P2P transmission protocol, such as the identification of PC, mobile phone, TV, tablet, etc.
  • the user triggers the screen projection function in the video player of the electronic device when the electronic device displays the found electronic devices, it will preferentially display the identifications of electronic devices with large screens, such as PCs and TVs.
  • the trigger when the trigger discovers that the function entry of the surrounding electronic devices is a smart life application, etc., the user's intention is usually to send commands to control one or several electronic devices, and the electronic device displays the found electronic device , the devices that have been registered in the smart life application are displayed first, such as air conditioners, smart lights, TVs, etc.
  • the electronic device may also use its other capabilities to determine the user's intention. For example, when an electronic device is equipped with an Ultra Wide Band (UWB) chip, the electronic device can measure the current orientation of the electronic device and the distance between itself and the discovered electronic device. Then, when the electronic device displays the discovered electronic device, it may preferentially display the discovered electronic device to which the electronic device is currently pointing. Alternatively, the discovered electronic equipment that is closer to the electronic equipment is preferentially displayed.
  • UWB Ultra Wide Band
  • the electronic device when an electronic device is equipped with a NAN chip, a Bluetooth chip, or a Wi-Fi chip, the electronic device can measure the distance to the discovered electronic device, then, when the electronic device displays the discovered electronic device, it will give priority to displaying the distance between the electronic device and the electronic device. More recently discovered electronic devices.
  • the electronic device points to a certain discovered electronic device, which refers to aligning a specific coordinate axis in the carrier coordinate system of the electronic device with the certain electronic device.
  • the electronic device Take the electronic device as a mobile phone as an example.
  • the mobile phone orientation (or mobile phone pointing) can be defined as: parallel to the long side of the mobile phone and pointing to the top along the tail of the mobile phone. Therefore, the orientation of the mobile phone can be referred to as the top orientation of the mobile phone.
  • the top of a mobile phone is a body part where hardware such as a front-facing camera, an infrared emitter, an earpiece, a light sensor, or a distance sensor are installed.
  • the tail of the phone is the body part where the microphone and speaker are installed.
  • the electronic device can find the surrounding electronic devices within 1 second, so the electronic devices found within 1 second can be sorted according to the received signal strength indication (Received Signal Strength Indication, RSSI) .
  • RSSI Receiveived Signal Strength Indication
  • the electronic device may also combine the above several display strategies.
  • the above display strategies can be combined according to the following priorities: (1) The electronic devices discovered within 1s are sorted according to the following priorities: firstly display the discovered electronic devices that the electronic devices are currently pointing at; The discovered electronic devices within a certain distance; then sort according to the display strategy of the user's trigger to discover the function of the surrounding electronic devices; and then sort according to the value of RSSI. (2) The electronic devices found after 1s are sorted according to the time order of discovery, and arranged after the electronic devices found within 1s.
  • FIG. 13 it is a flow chart of a method for multiplexing connection channels for multiple services in the prior art, and the process includes:
  • the first electronic device initiates service 1.
  • the application program of the BLE application layer of the first electronic device receives the user's operation of triggering service 1 (for example, file sharing), and the application program initiates a request for service 1 to the bottom layer, and sends the request to the bottom layer through the bottom layer.
  • triggering service 1 for example, file sharing
  • the second electronic device initiates a request for service 1,
  • the GATT client 1 (referred to as client 1 for short) of the first electronic device is successfully connected with the GATT server (referred to as server for short) of the second electronic device.
  • the BLE host layer receives the request of the service 1 initiated by the application program, creates a GATT client 1, and successfully connects with the GATT server (referred to as the server) created by the second electronic device.
  • step S1302a and step S1302b are shown.
  • the client 1 may provide multiple services, and the first electronic device searches for a service corresponding to the service 1 from the services provided by the client 1 .
  • the first electronic device and the second electronic device perform a discovery process, and the specific discovery process may refer to the process shown in FIG. 4 , which will not be repeated here.
  • Figure 13 simplifies this discovery process.
  • the first electronic device displays the discovered electronic devices (including the second electronic device). The user chooses to connect to the second electronic device on the first electronic device, and the first electronic device establishes a connection with the second electronic device.
  • the first electronic device sets a maximum transmission unit (maximum transmission unit, MTU) to 32 bytes.
  • MTU maximum transmission unit
  • the data packet of service 1 (also referred to as a shared data packet) has a maximum size of 32 bytes.
  • the first electronic device establishes a socket (socket).
  • the first electronic device automatically generates a serial number, and sends a sharing data packet to the second electronic device.
  • the second electronic device automatically generates a sequence packet, and replies a corresponding sharing data packet to the first electronic device.
  • the first electronic device initiates service 2.
  • the user also triggers service 2 on the first electronic device.
  • service 2 For other content, refer to related content in step S1301.
  • the GATT client 2 (referred to as client 2 for short) of the first electronic device is successfully connected with the GATT server (referred to as server for short) of the second electronic device.
  • the BLE host layer receives the request of the service 2 initiated by the application, creates a GATT client 2, and successfully connects with the GATT server (referred to as the server) created by the second electronic device.
  • the GATT server referred to as the server
  • the client 2 may provide multiple services, and the first electronic device searches for a service corresponding to the service 2 from the services provided by the client 2 .
  • the first electronic device sets a maximum transmission unit (maximum transmission unit, MTU) to 512 bytes.
  • MTU maximum transmission unit
  • the data packet of service 2 (also referred to as the screen projection data packet) has a maximum size of 512 bytes.
  • the first electronic device establishes a second socket.
  • the data packets of service 1 and service 2 have different sizes, that is, the MTU is different, and an additional socket needs to be established to transmit the data packets of service 2.
  • the first electronic device sends a sharing data packet (32 bytes) to the second electronic device.
  • the second electronic device sends a screen projection data packet (512 bytes) to the first electronic device.
  • the second electronic device uses the latest set MTU (512 bytes) to reply the sharing data packet to the client 1 of the first electronic device.
  • the second electronic device Since the second electronic device can only distinguish the sender of the data packet through the MAC address of the first electronic device, it cannot distinguish which client the data packet comes from from the first electronic device.
  • the identifier of the client of the first electronic device is the MAC address of the first electronic device. Since client 1 and client 2 of the first electronic device correspond to the same MAC address of the first electronic device, the server of the second electronic device cannot distinguish client 1 and client 2 of the first electronic device. Therefore, when the second electronic device replies a data packet to the first electronic device, there may be a problem of sending a wrong client. For example, reply the data packet of service 2 to client 1, and reply the data packet of service 1 to client 2.
  • the server end of the second electronic device there is only one MTU at the server end of the second electronic device.
  • the newly negotiated MTU between the second electronic device and the first electronic device will overwrite the previously negotiated MTU.
  • the 512 bytes negotiated by the service 2 process will cover the 32 bytes negotiated by the service 1 process.
  • the subsequent data packet returned by the second electronic device to the first electronic device is not larger than 512 bytes, so the server of the second electronic device often makes an error when replying the data packet to the client 1 of the first electronic device.
  • the client 1 of the first electronic device receives the sharing data packet (512 bytes) replied by the second electronic device, and the data reception is abnormal.
  • the client 1 of the first electronic device can only receive data packets not smaller than 32 bytes, when receiving the 512-byte shared data packet replied by the server of the second electronic device, the received data is abnormal.
  • the embodiment of the present application provides a method for multiplexing a connection channel by multiple services.
  • the electronic device sets a general MTU, that is, an MTU that can be used by multiple services, and a socket can be set for the general MTU.
  • a general MTU that is, an MTU that can be used by multiple services
  • a socket can be set for the general MTU.
  • the sent data packets carry service identifiers and serial numbers.
  • the data packet may also carry a packet header mark, a priority mark, and the like.
  • the application layer of the electronic device when it sends the data packet downward, it may carry a service identifier, a sequence number, a packet header mark, and a priority mark, etc. in the packet header of the data packet.
  • the electronic device can return the data packet to the corresponding service according to the service identifier therein. It can be seen that the embodiment of the present application ensures that when multiple services multiplex the connection channel, there will be no service disorder.
  • sequence number (seq) is used to determine the timing of each data packet.
  • each service corresponds to a queue, and in each queue, the sequence numbers of the data packets sent by the sending end increase in odd numbers, and the sequence numbers of the data packets sent by the receiving end increase in even numbers.
  • the packet header mark is used to mark whether the data packet is a packet header. If it is a packet header, the packet header flag is set to a first value, for example, 1, and if it is not a packet header, the packet header flag is set to a second value, such as 0.
  • the electronic device at the receiving end can splice multiple data packets according to the packet header mark.
  • the priority marking is used to mark data packets of different importance in the same service, for example, data packets of control signaling have the highest priority, high priority service packets, low priority service packets and so on.
  • data packets of control signaling have the highest priority, high priority service packets, low priority service packets and so on.
  • data packets with high priority can be sent preferentially according to the priority mark, so as to ensure efficient data transmission.
  • FIG 14 it is a flow chart of a method for multiplexing connection channels for multiple services provided by the embodiment of the present application.
  • the process includes:
  • the application program of the BLE application layer of the first electronic device receives the user's operation of triggering service 1 (for example, file sharing), and the application program initiates a request for service 1 to the bottom layer, and sends the request to the bottom layer through the bottom layer.
  • triggering service 1 for example, file sharing
  • the second electronic device sends a request for service 1,
  • the GATT client (referred to as the client for short) of the first electronic device connects successfully to the GATT server (referred to as the server for short) created by the second electronic device.
  • the BLE host layer receives the service 1 request initiated by the application, creates a GATT client, and successfully connects with the GATT server (referred to as the server) created by the second electronic device.
  • the GATT server referred to as the server
  • step S1402a and step S1402b are shown.
  • the client may provide multiple services, and the first electronic device searches for a service corresponding to service 1 from the services provided by the client.
  • the first electronic device and the second electronic device perform a discovery process, and the specific discovery process may refer to the process shown in FIG. 4 , which will not be repeated here.
  • Figure 14 simplifies this discovery process.
  • the first electronic device displays the discovered electronic devices (including the second electronic device). The user chooses to connect to the second electronic device on the first electronic device, and the first electronic device establishes a connection with the second electronic device.
  • the first electronic device sets the MTU, for example, to 512 bytes.
  • the maximum data packet of service 1 is 512 bytes. It should be noted that, since multiple services in this embodiment of the present application all use a common MTU, an appropriate MTU value is set in consideration of multiple services.
  • the first electronic device establishes a socket.
  • the first electronic device sends the data packet.
  • the data packet carries a sequence number, a service identifier, a packet header mark and a priority mark.
  • the sequence number is 1, the service identifier is 1 (corresponding to the identifier of service 1), the header mark is 1 (indicating that the data packet is a header data packet), and the priority mark is 1.
  • the second electronic device receives the data packet sent by the first electronic device, and synchronously records the serial number and the service identifier.
  • the second electronic device detects in real time whether packet loss occurs in the data packets of the service according to the service identifier and the serial number. If it is found that packet loss occurs, it can request the corresponding service identification and serial number data packets from the opposite end. It can be seen that the method provided by the embodiment of the present application also solves the problem of packet loss and ensures correct transmission of service data packets.
  • the second electronic device replies with a data packet to the first electronic device.
  • the data packet carries a sequence number and a service identifier.
  • the serial number is 2, and the service ID is 1 (corresponding to the ID of service 1).
  • the first electronic device receives the data packet sent by the second electronic device, and synchronously records the serial number and the service identifier.
  • the first electronic device detects in real time whether packet loss occurs in the data packets of the service according to the service identifier and the serial number. If it is found that packet loss occurs, it can request the corresponding service identification and serial number data packets from the opposite end. It can be seen that the method provided by the embodiment of the present application also solves the problem of packet loss and ensures correct transmission of service data packets.
  • the first electronic device sends the data packet.
  • the data packet carries a sequence number, a service identifier, a packet header mark and a priority mark.
  • the sequence number is 3, the service ID is 1 (corresponding to the ID of service 1), the header mark is 0 (indicating that the data packet is a data packet other than the header), and the priority mark is 1.
  • the second electronic device receives the data packet sent by the first electronic device, and synchronously records the serial number and the service identifier.
  • the second electronic device replies with a data packet to the first electronic device.
  • the data packet carries a sequence number and a service identifier.
  • the serial number is 4, and the service ID is 1 (corresponding to the ID of service 1).
  • the first electronic device receives the data packet sent by the second electronic device, and synchronously records the serial number and the service identifier.
  • the first electronic device initiates service 2.
  • the user also triggers service 2 on the first electronic device.
  • service 2 For other content, refer to related content in step S1401.
  • the first electronic device determines that there is an existing connection, and directly reuses the existing socket.
  • the first electronic device does not need to set the MTU again, nor does it need to create a new socket, which speeds up the connection process of the service 2.
  • the first electronic device sends the data packet.
  • the data packet carries a sequence number, a service identifier, a packet header mark and a priority mark.
  • the sequence number is 1, the service identifier is 2 (corresponding to the identifier of service 2), the header mark is 1 (indicating that the data packet is a packet header), and the priority mark is 1.
  • the second electronic device receives the data packet sent by the first electronic device, and synchronously records the serial number and the service identifier.
  • the second electronic device returns the data packet to the first electronic device.
  • the data packet carries a sequence number and a service identifier.
  • the serial number is 2, and the service ID is 2 (corresponding to the ID of service 1).
  • the first electronic device receives the data packet sent by the second electronic device, and synchronously records the serial number and the service identifier.
  • the second electronic device or the first electronic device can distinguish which service the data packet belongs to according to the service identifier carried in the data packet, and can also determine the timing of the data packets in each service according to the sequence number. This ensures that no errors will occur when multiple services reuse the same connection channel.
  • the above process uses the same electronic device to initiate multiple services as an example to illustrate the process of multiplexing connection channels.
  • multiple services triggered by different electronic devices may also multiplex the same connection channel.
  • the first electronic device determines to initiate service 1 (that is, step S1401 in FIG. 14 )
  • the first electronic device establishes a connection channel (such as executing step S1405 in FIG.
  • the second electronic device sends a broadcast message to inform the second electronic device that the first electronic device has initiated a connection request.
  • the second electronic device does not initiate a connection request within the preset time period T5. If the user initiates a connection request through the second electronic device within the preset time period T5, the second electronic device does not respond to the connection request, or delays in responding to the connection request.
  • the second electronic device may also prompt the user that other electronic devices are connecting to the second electronic device.
  • the first electronic device after the first electronic device establishes the connection channel (such as executing step S1405 in FIG. 14 ), the first electronic device communicates to the The second electronic device sends a message to inform the second electronic device that the first electronic device has initiated a connection request.
  • the embodiment of the present application does not limit the manner and timing for the first electronic device to notify the second electronic device.
  • the single Bluetooth chip can establish a connection channel, and multiple services can realize multiplexing the connection channel on the connection channel.
  • the electronic device is equipped with multiple Bluetooth chips (for example, two Bluetooth chips), then a connection channel can be established on each Bluetooth chip, and the above method can also be used in this connection channel to realize multi-service multiplexing.
  • Connection channel Taking an electronic device configured with two Bluetooth chips as an example, the electronic device can establish a connection channel on each Bluetooth chip, that is, establish two connection channels in total. Then, when the electronic device triggers a high-priority service, it can select a connection channel with good communication quality.
  • a connection channel with poor communication quality may be selected.
  • one of the connection channels is selected for odd-numbered requests, and another connection channel is selected for even-numbered requests.
  • it can be divided according to the types of services, the request of control signaling type selects one of the connection channels with good communication quality, and the request of transmitting time-consuming service packets selects another connection channel of which the communication quality is poor.
  • one of the connection channels is selected for the service request initiated by the local end, and another connection channel is selected for the service request initiated by the opposite end.
  • connection channels respectively established on the two Bluetooth chips, and the corresponding connection channels are subsequently selected according to the MTU of the service. In this way, when a single Bluetooth chip needs to switch the MTU, it is necessary to disconnect the connection channel and re-establish the connection channel, resulting in time-consuming connection problems.
  • FIG. 14 is only an example of a method flow provided by the embodiment of the present application. In some other embodiments, some steps may be omitted, or some steps may be combined, or the order of some steps may be exchanged.
  • the above-mentioned embodiment is described by taking BLE connection as an example, and the technical solution provided by the embodiment of the present application can also be used in other wireless connection methods (such as Wi-Fi).
  • Wi-Fi wireless connection methods
  • the same type of protocol can multiplex the same socket, and the data packets of multiple services multiplexing the same socket can adopt the data packet format provided by the above embodiment. That is, the data packet carries a service identifier and a serial number.
  • the data packet may also carry a packet header mark, a priority mark, and the like.
  • protocols adopted by Wi-Fi such as transmission control protocol (transmission control protocol, TCP), user datagram protocol (user datagram protocol, UDP), video datagram protocol (video datagram protocol, VDP), etc.
  • TCP transmission control protocol
  • UDP user datagram protocol
  • VDP video datagram protocol
  • Multiple services using TCP multiplex a socket that is, multiplex a connection.
  • Multiple services using UDP multiplex a socket that is, multiplex a connection.
  • Multiple services using VDP multiplex a socket that is, multiplex a connection.
  • steps S1402 (including S1402a, S1402b) to S1404 in FIG. 14 may be omitted.
  • connection channel can also be established on a single Wi-Fi chip, and multiple services using the same protocol can multiplex a connection channel.
  • Bluetooth chip please refer to the description of the Bluetooth chip, and will not repeat it here.
  • BR MAC address, BLE MAC address or unique device identifier are used as the identification of electronic devices. Because the format and content of BR MAC address, BLE MAC address or UDID are relatively fixed, they are easy to be attacked and counterfeited by fake base stations, so there are security problems.
  • the public key of the preset encryption algorithm can be used to identify the electronic device (such as the serial number (serial number, SN) of the electronic device, the international mobile equipment identity (international mobile equipment identity, IMEI), MAC address, etc.) to get the hash value, and use some bytes in the hash value as the unique identification of the electronic device.
  • the identification of the electronic device carried is part of the bytes in the hash value.
  • the preset encryption algorithm may be, for example, encryption algorithms such as RSA3072 and HmacSHA256.
  • the public key and the first 16 bytes of the public key can be used as parameters to calculate the hash value (hash code) for the SN of the electronic device, and the first 20 bytes of the calculated hash value can be used as the unique identifier of the electronic device . Since the hash value is not easy to be identified and reversed, the use of the hash value as the unique identifier of the electronic device improves the security issues in the discovery process of the electronic device and the connection process.
  • the user can recalculate the unique identifier of the electronic device by, for example, restarting the electronic device, that is, recalculate the identifier (such as SN, IMEI, MAC address, etc.) of the electronic device using the public key Hash value, using some bytes in the hash value as the unique identifier of the new electronic device.
  • the user can control the regeneration of the unique identifier of the electronic device, in other words, the unique identifier of the electronic device can be changed, which further increases the difficulty of being attacked and further improves the security issues in the discovery process of the electronic device and the connection process.
  • the identification of the discovered electronic device can also be verified, and it is ensured that the connected electronic device is the same electronic device as the electronic device at the time of discovery, ensuring that the electronic device The connection of the device is secure.
  • FIG. 15 it is a flow chart of a method for verifying the identification of an electronic device in the discovery process provided by the embodiment of the present application, and the process includes:
  • the first electronic device sends a broadcast message A to discover surrounding electronic devices.
  • the second electronic device After receiving the broadcast message A, the second electronic device sends the broadcast message B.
  • the broadcast message B carries information such as the name of the electronic device, account name, and device type.
  • the first electronic device caches the broadcast message B.
  • the second electronic device sends the broadcast message C after sending the broadcast message B for a duration T1.
  • the broadcast message C carries the identifier of the electronic device generated by the method provided in this embodiment.
  • the identification of the electronic device such as SN, IMEI, MAC address, etc.
  • the identification of the electronic device is hashed, and some bytes in the hash value are used as the unique identification of the electronic device.
  • the first electronic device determines to discover the second electronic device according to the broadcast message B and the broadcast message C.
  • step S1501-step S1505 is a process of discovering the first electronic device and the second electronic device.
  • step S1501-step S1505 is a process of discovering the first electronic device and the second electronic device.
  • the first electronic device establishes a BLE connection with the second electronic device.
  • the first electronic device initiates a counter mode with cipher-block chaining message authentication code protocol (CCMP) connection request to the second electronic device through the established BLE connection.
  • CCMP cipher-block chaining message authentication code protocol
  • the first electronic device requests the information of the second electronic device, such as the version number of CCMP supported by the second electronic device, the digest, and whether encryption verification is supported.
  • the second electronic device returns a response to the first electronic device.
  • the response carries the CCMP version number supported by the second electronic device, the digest, whether encryption verification is supported, and the like.
  • the first electronic device sends the CCMP version number of the first electronic device to the second electronic device.
  • step S1509 If the version number supported by the second electronic device is greater than or equal to CCMP 4.0, perform step S1509. If the version number supported by the second electronic device is equal to CCMP 4.0, a CCMP connection is established according to the corresponding logic.
  • the second electronic device negotiates a common CCMP version number.
  • the second electronic device negotiates the CCMP version number used by the two electronic devices.
  • the second electronic device returns the supported CCMP version number to the first electronic device, that is, the public CCMP version number negotiated by the second electronic device.
  • the first electronic device negotiates a public CCMP version number.
  • the first electronic device sends the public key A of the first electronic device to the second electronic device.
  • the second electronic device replies with the public key B of the second electronic device to the first electronic device.
  • the first electronic device verifies the identification of the electronic device received in the discovery process according to the public key B, and has determined whether the second electronic device connected at this time is the same electronic device as the electronic device found in the discovery process.
  • the first electronic device After the verification is passed, the first electronic device generates a random number, and encrypts the random number with the public key B, that is, generates an AES Key, and sends the AES Key to the second electronic device.
  • the second electronic device receives the AES Key sent by the first electronic device, and decrypts it to obtain a random number. Then, encrypt the random number with the public key A, that is, generate the AES Key that is replied to the first electronic device.
  • the second electronic device sends an AES Key to the first electronic device.
  • the first electronic device decrypts the AES Key to obtain a random number. Then, the first electronic device determines whether the random number obtained by decryption is the same as the random number sent by itself.
  • the verification is passed, the first electronic device and the second electronic device establish a CCMP connection, and then can communicate.
  • FIG. 15 is only an example of a method flow provided by the embodiment of the present application. In some other embodiments, for example, when different protocols are used, some steps in the above flow can be omitted, or some steps can be combined, or The order of some steps can be swapped.
  • the process of establishing a connection between the first electronic device and the second electronic device includes three stages: stage 1, the connection stage between the GATT client of the first electronic device and the GATT server of the second electronic device.
  • Phase 2 service discovery phase.
  • Phase 3 Set the MTU phase.
  • the first electronic device will confirm that the connection fails. If it is desired to connect again, the user needs to re-trigger the connection operation on the first electronic device, and then the first electronic device and the second electronic device perform a connection establishment process (including 3 stages) again. Among them, it generally takes 10s to perform the connection establishment process again.
  • the first electronic device and the second electronic device automatically retry, and the number of retries is The preset number of times does not exceed 1 (for example, 3 times), and the total duration of the first electronic device in stage 1 is controlled within the preset duration (for example, 4s).
  • the first electronic device and the second electronic device automatically retry, and the number of retries does not exceed the preset number of times 2 (for example, 1 time), and the total duration of the first electronic device in phase 2 is controlled within Within a preset time period (for example, 4s).
  • phase 1 the connection between the GATT client of the first electronic device and the GATT server of the second electronic device times out, and the abnormality found in phase 2 may be recovered by retrying, but the phase 3 cannot be recovered.
  • the technical solution provided by the embodiment of the present application increases the success rate of this connection by retrying recoverable exceptions in phase 1 and phase 2.
  • the retry method saves connection time and speeds up the connection process.
  • the service identifier carried in the discovery request message may be included.
  • the first electronic device may add the service identifier in the request message through the API of addServiceUuid(ParcelUuid serviceUuid) of AdvertiseData.Builder.
  • the second electronic device can parse out the service identifier from the broadcast discovery request message through the getServiceUuid() API. In other words, during the discovery process, the first electronic device can request the service corresponding to the service identifier from the second electronic device.
  • the MTU phase is directly set (ie, executing phase 3).
  • the first electronic device and the second electronic device have successfully discovered the service, that is, there is no need to execute stage 2 during this connection process, thereby speeding up the connection process.
  • the first electronic device after the first electronic device discovers the second electronic device, if it does not receive the broadcast message sent by the second electronic device within the preset time period T7 (for example, 4s) after discovery, it will It is determined that the second electronic device is offline, that is, the identifier of the second electronic device is no longer displayed in the list of discovered electronic devices. For example, during the discovery process, the first electronic device records the identifier of the sender and the time stamp of the received broadcast message. The timestamp is the difference between the current time and the receiving time.
  • T7 for example, 4s
  • the first electronic device determines that the second electronic device is offline, that is, it is no longer displayed in the list of discovered electronic devices An identification of the second electronic device. For another example, after receiving the broadcast message sent by the second electronic device, the first electronic device starts a timer with a preset duration T7. If the broadcast message sent by the second electronic device is received again before the timer reaches the preset duration T7, the timer is reset to zero and starts counting again.
  • the preset duration T7 for example, 4s
  • the timer When the timer reaches the preset duration T7, it is considered that the first electronic device has not received the broadcast message of the second electronic device during the preset duration T7, and it is determined that the second electronic device is offline, that is, it is not in the list of discovered electronic devices The identification of the second electronic device is displayed again.
  • the first electronic device may also determine the discovered electronic device according to the identifier and service identifier of the sender of the received broadcast message. Whether the device is offline. For example, if the user triggers the function of sharing pictures in the gallery application of the first electronic device, the first electronic device records the identifier of the sender, the service identifier (such as the identifier of the image sharing service) and the time stamp of the received broadcast message. The timestamp is the difference between the current time and the receiving time.
  • the time stamp of the broadcast packet sent by the second electronic device and the service identifier is the identifier of the image sharing service is greater than the preset time length T7 (for example, 4s)
  • T7 the preset time length
  • the second electronic device is offline, that is, the electronic device that is found
  • the identifier of the second electronic device is no longer displayed in the device list.
  • the first electronic device starts a timer with a preset duration T7. Before the timer reaches the preset duration T7, if the broadcast message sent by the second electronic device and carrying the logo of the picture sharing service is received again, the timer is reset to zero, and timing is restarted.
  • the timer When the timer reaches the preset duration T7, it is considered that the first electronic device has not received the broadcast message sent by the second electronic device during the preset duration T7 and carries the logo of the picture sharing service, and the second electronic device is determined to be offline , that is, the identifier of the second electronic device is no longer displayed in the list of discovered electronic devices.
  • the first electronic device may also set different preset durations T7 for electronic devices of different device types. For example, when the discovered electronic device is a PC, the preset duration T7 is set to 6s; when the discovered electronic device is a mobile phone, the preset duration T7 is set to 4s. This is in consideration of the different broadcast duty ratios of electronic devices of different device types, which is beneficial to improve the accuracy of offline.
  • the first electronic device may also set a different preset time length T7 for whether the first electronic device is discovered for the first time.
  • the preset duration T7 corresponding to an electronic device discovered for the first time is 18s
  • the preset duration T7 corresponding to an electronic device not discovered for the first time is set to 6s or 4s.
  • An embodiment of the present application further provides a chip system, as shown in FIG. 16 , the chip system includes at least one processor 1601 and at least one interface circuit 1602 .
  • the processor 1601 and the interface circuit 1602 may be interconnected through wires.
  • interface circuit 1602 may be used to receive signals from other devices such as memory.
  • the interface circuit 1602 may be used to send signals to other devices (eg, a processor).
  • the interface circuit 1602 can read instructions stored in the memory, and send the instructions to the processor 1601 .
  • the electronic device may be made to perform various steps performed by the first electronic device or the second electronic device in the foregoing embodiments.
  • the chip system may also include other discrete devices, which is not specifically limited in this embodiment of the present application.
  • the embodiment of the present application also provides a device, the device is included in the electronic device (the first electronic device or the second electronic device), and the device has the electronic device (the first electronic device or the second electronic device) for implementing any method in the above embodiments 2.
  • the function of the behavior of electronic devices may be implemented by hardware, or may be implemented by executing corresponding software on the hardware.
  • Hardware or software includes at least one module or unit corresponding to the above functions. For example, a sending module or unit, a receiving module or unit, a processing module or unit, and a storage module or unit.
  • the embodiment of the present application also provides a computer storage medium, including computer instructions.
  • the computer instructions When the computer instructions are run on the electronic device (the first electronic device or the second electronic device), the electronic device (the first electronic device or the second electronic device) ) to perform any method as in the above-mentioned embodiments.
  • An embodiment of the present application further provides a computer program product, which, when the computer program product is run on a computer, causes the computer to execute any method in the foregoing embodiments.
  • the above-mentioned first electronic device or the second electronic device includes corresponding hardware structures and/or software modules for performing various functions.
  • the embodiments of the present application can be implemented in the form of hardware or a combination of hardware and computer software in combination with the example units and algorithm steps described in the embodiments disclosed herein. Whether a certain function is executed by hardware or computer software drives hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be regarded as exceeding the scope of the embodiments of the present invention.
  • the embodiment of the present application can divide the functional modules of the above-mentioned first electronic device or the second electronic device according to the above-mentioned method example, for example, each functional module can be divided corresponding to each function, or two or more functions can be integrated in a processing module.
  • the above-mentioned integrated modules can be implemented in the form of hardware or in the form of software function modules. It should be noted that the division of modules in the embodiment of the present invention is schematic, and is only a logical function division, and there may be another division manner in actual implementation.
  • Each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may physically exist separately, or two or more units may be integrated into one unit.
  • the above-mentioned integrated units can be implemented in the form of hardware or in the form of software functional units.
  • the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.
  • the technical solution of the embodiment of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage
  • the medium includes several instructions to enable a computer device (which may be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of the methods described in the various embodiments of the present application.
  • the aforementioned storage medium includes: flash memory, mobile hard disk, read-only memory, random access memory, magnetic disk or optical disk, and other various media capable of storing program codes.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Databases & Information Systems (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

一种无线连接的方法以及电子设备,涉及无线通信技术领域,可以加速发现连接过程,降低电子设备的功耗,该方法包括:第一电子设备获取第一电子设备的信息,第一电子设备的信息包括第一电子设备的业务场景、第一电子设备的状态、以及第一电子设备配置的无线通信芯片能力中一项或多项;第一电子设备根据第一电子设备的信息调整第一电子设备的广播参数;其中所述广播参数包括广播类型、扫描占空比、广播占空比、广播通道数中一项或多项。

Description

一种无线连接的方法以及电子设备
本申请要求于2021年5月14日提交国家知识产权局、申请号为202110528395.2、申请名称为“一种连接提速方法及装置”的中国专利,以及于2021年7月21日提交国家知识产权局、申请号为202110827479.6、申请名称为“一种无线连接的方法以及电子设备”的中国专利申请的优先权,这两件专利的全部内容通过引用结合在本申请中。
技术领域
本申请涉及无线通信技术领域,尤其涉及一种无线连接的方法以及电子设备。
背景技术
随着物联网在智能家居、电子产品、智能工业等领域的全面发展,近距离通信的无线连接技术越来越多地应用在物联网新兴产品中,为设备提供稳定和低功耗的数据传输服务。其中,蓝牙低能耗(bluetooth low energy,BLE),也称低功耗蓝牙,因其高可靠性、低成本、低功耗、快速连接等优势成为物联网市场的宠儿,被广泛应用到医疗领域、定位应用、数据传输等近距离通信场景中。并且,如何进一步优化BLE的连接技术仍然是当前厂商们研究的一个热点。
发明内容
本申请提供的一种无线连接的方法以及电子设备,可以加速电子设备的发现和连接过程。
为了实现上述目的,本申请实施例提供了以下技术方案:
第一方面、提供一种无线发现的通信系统,包括第一电子设备和第二电子设备,第一电子设备,用于发送第一广播报文,第一广播报文用于发现第一电子设备周围的电子设备;第二电子设备,用于响应于接收到第一广播报文,发送第二广播报文,第二广播报文包括第二电子设备的第一信息,其中第一信息包括设备标识、设备名称、登录账号、设备类型和业务标识中的一项或多项;第一电子设备,用于存储第二电子设备的第一信息;第二电子设备,还用于在第二电子设备发送第二广播报文后的第一时长后,发送第三广播报文,第三广播报文包括第二电子设备的第二信息,其中第二信息包括设备标识、登录账号、设备类型、设备能力和业务标识中的一项或多项,且第二信息和第一信息至少部分内容不同;第一电子设备,还用于根据第二电子设备的第一信息和第二信息,确定发现第二电子设备。
由于第二电子设备向第一电子设备回复第二电子设备的设备信息(包括第一信息和第二信息)时,常需要发送两个或两个广播报文。然而,在现有技术中,第二电子设备在发送一个广播报文(即第二广播报文,也即下文中的广播报文B)后,会等待第一电子设备在接收到第二广播报文后,向第二电子设备返回确认报文后。第二电子设备在接收到第一电子设备返回的确认报文后,才继续下一个广播报文(即第三广播报文,也即下文中的广播报文C)。其中,从第二电子设备发送第二广播报文之后到第二电子设备发送第三广播报文之前的整个过程耗时为时长T2,例如T2通常为300ms。
然而,在本申请实施例中第二电子设备在发送第二广播报文后的时长T1(即第一时长)后直接发送第三广播报文。其中,T1小于T2。在一个示例中,T1可以设置为一个固定的时长(例如60ms)加上一个随机时长(例如40ms之内的随机时长)。T1可设置为不大于100ms。那么,本申请实施例提供的技术方案相较于现有技术的技术方案节省了T0=T2-T1,T0大于200ms。即,本申请实施例提供的技术方案加速了电子设备的发现过程,从而也加速了电子设备的连接过程。
可以理解的是,在其他一些实施例中,第二电子设备在接收到第一电子设备发送的第一广播报文(即发现广播报文,也即下文的广播报文A)后,第二电子设备需要发送大于两条(例如N1条,N1大于2)的广播报文用于回复第二电子设备的信息。在该实施例中,第二电子设备在发送第一条广播报文(例如,第二广播报文,也即广播报文B)后的每一条广播报文时,均无需等待第一电子设备针对上一条广播报文的ACK报文,便直接在发送完上一条广播报文后的时长T1后,发送本条广播报文。相较于现有技术,现有技术中第二电子设备在发送第一条广播报文(即广播报文B)后的每一条广播报文时,均需等待接收到第一电子设备发送针对上一条广播报文的ACK报文后才发送本条广播报文。而本申请提供的实施例则在发送一条广播报文后的时长T1后自动发送下一条广播报文。那么,本申请实施例提供的技术方案中,第一电子设备发现第二电子设备的过程可节省的时长T0’=(N1-1)*(T2-T1)。由此可见,当第二电子设备需要回复的广播报文数量N1越大时,本申请实施例提供的技术方案提升发现速率的效果越显著。
在一种可能的实现方式中,第一电子设备,还用于存储第二电子设备的第二信息;第一电子设备,还用于发送第四广播报文,第四广播报文用于发现第一电子设备周围的电子设备;第二电子设备,还用于响应于接收到第四广播报文,发送第五广播报文,第五广播报文包括第二电子设备的第一信息;第二电子设备,还用于根据第五广播报文中的第二电子设备的第一信息和存储的第二电子设备的第二信息,确定发现第二电子设备。
第一电子设备在较短的时间内(例如在缓存广播报文C的缓存时长之内)需再次发现第二电子设备。例如,第一电子设备在该较短时间内再次触发图片/文件/视频等的转发/分享功能,或者第一电子设备周期性(周期小于时长T1)刷新发现的电子设备。
在现有技术中,第一电子设备再次发现第二电子设备的流程与第一次发现第二电子设备的流程相同,即第二电子设备需发送两条广播报文用于响应第一电子设备发送的用于发现的广播报文,并且,在第二电子设备在接收到第一电子设备发送的针对第一条广播报文的ACK报文后,第二电子设备才发送第二条广播报文。然而,在本申请实施例中,第二电子设备仅发送了一条广播报文时,第一电子设备便可以根据该广播报文和之前缓存的另一条的广播报文进行内容拼接,确定发现第二电子设备。现有技术中,从第一电子设备接收到第二电子设备发送的第一条广播报文后,到向第二电子设备发送针对第一条广播报文的ACK报文后,再到接收到第二电子设备发送的第二条广播报文的过程耗时大于T2,本申请实施例中节省了该过程。也就是说,第一电子设备再次发现第二电子设备的整个过程节省了至少T2的时长,例如节省了至少300ms。
可以理解的是,在其他一些实施例中,第二电子设备在接收到第一电子设备发送的广播报文A后,第二电子设备需要发送大于两条(例如N1条,N1大于2)的广播报文用于回复第二电子设备的信息。类似的,第一电子设备接收到第二电子设备发送的第一条广播报文后,可以根据自身缓存的其他广播报文(一条或多条广播报文)提前确定发现第二电子设备,加速第二电子设备的发现过程。
在一种可能的实现方式中,第一电子设备,还用于发送第六广播报文,第六广播报文用于提示所述第二电子设备交替发送所述第二电子设备的所述第一信息和所述第二电子设备的所述第二信息。
示例性的,第一电子设备,还用于当接收到第二电子设备的第一信息时,且未接收到或未存储有第二电子设备的第二信息时,或者,当接收到第二电子设备的第二信息时,且未接收到或未存储有第二电子设备的第一信息时,发送第三广播报文。
也就是说,当第一电子设备未接收到第一电子设备的全部信息时,可以向发送第三广播报文,即下文的广播报文F,用于请求第二电子设备快速交替发送用于响应发现广播报文(即第一广播报文,也即广播报文A)的全部报文,有利于第一电子设备快速获取到第二电子设备的全部信息,加速发现过程。
第二方面、提供一种无线发现的方法,应用于第二电子设备,该方法包括:接收第一电子设备发送的第一广播报文,第一广播报文用于发现第一电子设备周围的电子设备;发送第二广播报文,第二广播报文包括第二电子设备的第一信息,其中第一信息包括设备标识、设备名称、登录账号、设备类型和业务标识中的一项或多项;在第二电子设备发送第二广播报文后的第一时长后,发送第三广播报文,第三广播报文包括第二电子设备的第二信息,其中第二信息包括设备标识、登录账号、设备类型、设备能力和业务标识中的一项或多项,且第二信息和第一信息至少部分内容不同;其中,第二电子设备的第一信息和第二信息,用于第一电子设备确定发现第二电子设备。
由于第二电子设备向第一电子设备回复第二电子设备的设备信息(包括第一信息和第二信息)时,常需要发送两个或两个广播报文。然而,在现有技术中,第二电子设备在发送一个广播报文(即第二广播报文,也即下文中的广播报文B)后,会等待第一电子设备在接收到第二广播报文后,向第二电子设备返回确认报文后。第二电子设备在接收到第一电子设备返回的确认报文后,才继续下一个广播报文(即第三广播报文,也即下文中的广播报文C)。其中,从第二电子设备发送第二广播报文之后到第二电子设备发送第三广播报文之前的整个过程耗时为时长T2,例如T2通常为300ms。然而,在本申请实施例中第二电子设备在发送第二广播报文后的时长T1后直接发送第三广播报文。其中,T1小于T2。本申请实施例提供的技术方案加速了电子设备的发现过程,从而也加速了电子设备的连接过程。
一种可能的实现方式中,在第一电子设备发送所述第一广播报文之前,设置第一电子设备的广播类型设置为不可连接。
由于第一电子设备的广播类型为不可连接时,第一电子设备的应用层在向底层送广播报文A(即第一广播报文)时,底层无需等待其他电子设备(如第二电子设备)连接的广播报文,而是直接发送广播报文A。在现有技术中,第一电子设备的广播类型为可连接(connectable)。第一电子设备的应用层在向底层发送广播报文A时,底 层(例如具体是L2CAP)需等待一个连接间隔(connection interval),用于等待接收其他电子设备连接的广播报文。其中,连接间隔是两个电子设备间交互的时间间隔,一般为20ms。可见,当第一电子设备在发送广播报文A之前,将广播类型设置为不可连接,有利于发现过程加速一个连接间隔的时长,例如20ms。
一种可能的实现方式中,在第一电子设备接收到第二电子设备发送的第二广播报文之后,设置第一电子设备的广播类型设置为可连接。
一种可能的实现方式中,如果第一电子设备配置的无线通信芯片支持寻呼扫描能力,设置第一电子设备的广播类型为可扫描。
一种可能的实现方式中,如果第一电子设备配置的无线通信芯片不支持寻呼扫描能力,设置第一电子设备的广播类型为不可扫描。
如果电子设备的蓝牙芯片不支持寻呼扫描能力,则不具备拼接响应包的能力,那么设置电子设备的广播参数scannable的属性值为false。那么,电子设备的底层在接收到多个针对发现请求的响应包(例如下文的广播报文B和广播报文C)时,则不对多个响应包进行拼接,直接将多个响应包上报给上层的应用。如果此时电子设备的scannable的属性值仍然为true,那么此时电子设备仍然会等待拼包处理的时长(例如为20ms),再将多个响应包上报给上层的应用。因此,电子设备的蓝牙芯片不支持寻呼扫描能力时,设置scannable的属性值为false,有利于节省该拼包处理的时长,加速发现过程和连接过程。
一种可能的实现方式中,第二电子设备的设备标识为第二电子设备的第一标识的哈希值;第二电子设备的所述第一标识为所述第二电子设备的序列号SN、国际移动设备识别码IMEI、媒体存取控制地址MAC地址中的任一项。
由于哈希值不易识别以及不易被反解析,因此使用哈希值作为电子设备的唯一标识,提升了电子设备发现过程以及连接过程中的安全问题。
第三方面、提供一种无线发现的方法,应用于第一电子设备,该方法包括:发送第一广播报文,第一广播报文用于发现第一电子设备周围的电子设备;接收第二电子设备发送的第二广播报文,第二广播报文包括第二电子设备的第一信息,其中第一信息包括设备标识、设备名称、登录账号、设备类型和业务标识中的一项或多项;根据第二电子设备的第一信息查找第二电子设备的第二信息;其中第二信息包括设备标识、登录账号、设备类型、设备能力和业务标识中的一项或多项,且第二信息和第一信息至少部分内容不同;根据第二电子设备的第一信息,以及查找到的第二信息,确定发现第二电子设备。
在现有技术中,第一电子设备再次发现第二电子设备的流程与第一次发现第二电子设备的流程相同,即第二电子设备需发送两条广播报文用于响应第一电子设备发送的用于发现的广播报文,并且,在第二电子设备在接收到第一电子设备发送的针对第一条广播报文的ACK报文后,第二电子设备才发送第二条广播报文。然而,在本申请实施例中,第二电子设备仅发送了一条广播报文时,第一电子设备便可以根据该广播报文和之前缓存的另一条的广播报文进行内容拼接,确定发现第二电子设备。现有技术中,从第一电子设备接收到第二电子设备发送的第一条广播报文后,到向第二电子设备发送针对第一条广播报文的ACK报文后,再到接收到第二电子设备发送的第二条 广播报文的过程耗时大于T2,本申请实施例中节省了该过程。也就是说,第一电子设备再次发现第二电子设备的整个过程节省了至少T2的时长,例如节省了至少300ms。
在一种可能的实现方式中,该方法还包括:第一电子设备发送第三广播报文,第三广播报文用于提示第二电子设备交替发送第二电子设备的第一信息和第二电子设备的第二信息。
示例性的,当接收到第二电子设备的第一信息时,且未接收到或未存储有第二电子设备的第二信息时,或者,当接收到第二电子设备的第二信息时,且未接收到或未存储有第二电子设备的第一信息时,第一电子设备发送第三广播报文。
也就是说,当第一电子设备未接收到第一电子设备的全部信息时,可以向发送第三广播报文,即下文的广播报文F,用于请求第二电子设备快速交替发送用于响应发现广播报文(即第一广播报文,也即广播报文A)的全部报文,有利于第一电子设备快速获取到第二电子设备的全部信息,加速发现过程。
第四方面、提供一种无线发现及连接方法,该方法包括:第一电子设备获取第一电子设备的信息,第一电子设备的信息包括第一电子设备的业务场景、第一电子设备的状态、以及第一电子设备配置的无线通信芯片能力中一项或多项;第一电子设备根据第一电子设备的信息调整第一电子设备的广播参数;其中广播参数包括广播类型、扫描占空比、广播占空比、广播通道数中一项或多项。
换言之,第一电子设备根据第一电子设备的信息动态调整发现过程中、连接过程中设置是连接后的广播参数,以发送发现过程,提升发现成功率,加速连接过程,节省第一电子设备的功耗。
在一种可能的实现方式中,第一电子设备根据第一电子设备的业务场景调整第一电子设备的广播参数,包括:在第一电子设备发送发现广播报文之前,设置第一电子设备的广播类型设置为不可连接;在第一电子设备在接收到任一电子设备针对发现广播报文回复的任一报文之后,设置第一电子设备的广播类型设置为可连接。
由于第一电子设备的广播类型为不可连接时,第一电子设备的应用层在向底层送发现广播报文(即下文的广播报文A)时,底层无需等待其他电子设备(如第二电子设备)连接的广播报文,而是直接发送广播报文A。在现有技术中,第一电子设备的广播类型为可连接(connectable)。第一电子设备的应用层在向底层发送广播报文A时,底层(例如具体是L2CAP)需等待一个连接间隔(connection interval),用于等待接收其他电子设备连接的广播报文。其中,连接间隔是两个电子设备间交互的时间间隔,一般为20ms。可见,当第一电子设备在发送广播报文A之前,将广播类型设置为不可连接,有利于发现过程加速一个连接间隔的时长,例如20ms。
在一种可能的实现方式中,第一电子设备根据第一电子设备的状态调整第一电子设备的广播参数,还包括:当第一电子设备的状态满足预设条件时,第一电子设备增大扫描占空比和/或广播占空比:其中,预设条件为以下条件中的任一项或任几项:第一电子从灭屏状态进入亮屏状态的第一预设时长内;第一电子设备从锁屏状态进入解锁状态的第二预设时长内;第一电子设备启动第一应用后的第三预设时长内;第一电子设备将第二应用从后台运行切换至前台运行的第四预设时长内;第一电子设备运行预设应用。
这是考虑到,在这些场景中第一电子设备发现其他电子设备的概率较大,因此增大第一电子设备的广播占空比和/或扫描占空比,有利于第一电子设备快速地广播或扫描,加速与其他电子设备发现过程。
在一种可能的实现方式中,第一电子设备根据第一电子设备的状态调整第一电子设备的广播参数,还包括:在第一电子设备上电或开机或启动无线通信功能之后,且在检测到第一电子设备启动预设业务之前,第一电子设备的广播过程或扫描过程处于未启动状态。
这是因为,在该场景中,第一电子设备发现其他电子设备的概率较小,甚至概率为零,因此减小广播占空比和/或扫描占空比,甚至将广播占空比和/或扫描占空比调至零,有利于降低第一电子设备的功耗。
在一种可能的实现方式中,在第一电子设备和第二电子设备的连接过程中,根据第一电子设备的状态动态调整占空比(包括扫描占空比、广播占空比等)。当第一电子设备检测到用户选择连接某个电子设备的时长T3时,第一电子设备可以增大广播占空比/扫描占空比,有利于第一电子设备快速地广播或扫描,加速与第二电子设备的连接过程。当第一电子设备与第二电子设备建立连接后,第一电子设备可以减小广播占空比和/或扫描占空比,降低电子设备的功耗。
在一种可能的实现方式中,第一电子设备根据第一电子设备配置的无线通信芯片能力动态调整第一电子设备的广播参数,包括:根据第一电子设备配置的无线通信芯片是否支持寻呼扫描能力,设置第一电子设备的广播类型是否为可扫描。
例如,如果第一电子设备的蓝牙芯片支持寻呼扫描(page scan)能力,则具备拼接响应包的能力,那么设置第一电子设备的广播参数scannable的属性值为true。换言之,第一电子设备的底层在接收到多个针对发现请求的响应包(例如下文的广播报文B和广播报文C)时,可以进行对多个响应包进行拼接,再将拼接好的数据包上报给上层的应用。
如果第一电子设备的蓝牙芯片不支持寻呼扫描能力,则不具备拼接响应包的能力,那么设置第一电子设备的广播参数scannable的属性值为false。那么,第一电子设备的底层在接收到多个针对发现请求的响应包(例如下文的广播报文B和广播报文C)时,则不对多个响应包进行拼接,直接将多个响应包上报给上层的应用。如果此时第一电子设备的scannable的属性值仍然为true,那么此时电子设备仍然会等待拼包处理的时长(例如为20ms),再将多个响应包上报给上层的应用。因此,第一电子设备的蓝牙芯片不支持寻呼扫描能力时,设置scannable的属性值为false,有利于节省该拼包处理的时长,加速发现过程和连接过程。
在一种可能的实现方式中,第一电子设备根据第一电子设备配置的无线通信芯片能力动态调整第一电子设备的广播参数,包括:第一电子设备根据第一电子设备配置的无线通信芯片能力,调整第一电子设备的扫描器的数量,其中每个扫描器对应一个扫描占空比。
在现有技术中,如果电子设备(例如第一电子设备或第二电子设备)配置的蓝牙芯片支持单路广播通道,那么,当该电子设备的多个业务并发时,在同一个时刻电子设备只能发送一个业务的广播报文,而延迟发送其他业务的广播报文,或者直接丢弃 其他业务的广播报文,从而影响了这些业务的发现和连接。如果电子设备配置的蓝牙芯片支持多路广播通道时,那么在同一时刻电子设备上触发广播报文的数量大于当前可用的广播通道的数量时,也存在上述冲突,影响其中部分业务的发现和连接。
在本申请的一些实施例中,电子设备可以合并同一业务的不同任务的广播报文和反向广播报文。例如,用户在第一电子设备上触发了一次图片/文件/视频等的分享功能,那么第一电子设备发送用于发现周围电子设备的广播报文(例如广播报文A)。当第一电子设备接收到第二电子设备返回的第一个响应包(例如广播报文B)时,第一电子设备发送反向广播报文(例如广播报文F)。如果用户在第一电子设备发送反向广播报文之前,又在第一电子设备上触发了另一次的图片/文件/视频等的分享功能,那么第一电子设备响应于用户的触发操作,再次发送用于发现周围电子设备的广播报文(例如广播报文A)。并且,第一电子设备发送反向广播报文(例如广播报文F)和第二次发现用于发现周围电子设备的广播报文(例如广播报文A)发送冲突。那么,在本申请实施例中,可以将两个广播报文进行合并,然后发送合并后的广播报文。第二电子设备在接收到该合并后的广播报文后,解析可获得两个广播报文的内容(即广播报文F和广播报文A)。由此可见,相较于现有技术,电子设备将两个广播报文进行合并发送,保证了同业务的两个任务的并发,加速了该业务不同任务的发现与连接过程。
在本申请的另一些实施例中,如果电子设备配置的蓝牙芯片支持多路广播通道,可以设置预设数量N3个广播通道用于传输广播报文,以节省芯片资源。其中,N3个广播通道可以对应N3个业务类型。后续,当电子设备有业务有待发送的广播报文时,该业务选择自身的业务类型对应广播通道,用于发送广播报文。如果此时有业务类型相同的多个业务需要发送广播报文,则可以复用该业务类型对应的广播报文。即,电子设备的应用层将这多个业务的广播报文进行合并,然后通过该业务类型对应的广播通道发送合并后的广播报文,从而保证及时发送各个业务的广播报文,减少各个业务的等待时间,加速多个业务的发现过程和连接过程。换言之,不同业务类型的业务选择复用业务类型对应的广播通道。
在本申请的又一些实施例中,如果电子设备配置的蓝牙芯片支持单路广播通道,或者,虽然电子设备配置的蓝牙芯片支持多路广播通道,但芯片能力不足以提供预设数量N3个广播通道用于传输广播报文。那么,可以合并其中部分的业务类型。换言之,多个业务类型复用一个广播通道,那么在Sender Btype(或Receiver Btype)中可以指示两个或两个以上的业务类型。换言之,两个或两个以上的业务类型的业务也可以合并在一条广播报文中。
在一种可能的实现方式中,第一电子设备根据第一电子设备配置的无线通信芯片能力动态调整第一电子设备的广播参数,包括:如果第一电子设备配置的无线通信芯片能力支持多路广播通道,则第一电子设备设置预设数量N3个广播通道,其中每个广播通道对应一个业务类型,其中每个业务类型对应多个业务。
在本申请的一些实施例中,电子设备可以合并同一业务的不同任务的广播报文和反向广播报文。例如,用户在第一电子设备上触发了一次图片/文件/视频等的分享功能,那么第一电子设备发送用于发现周围电子设备的广播报文(例如广播报文A)。 当第一电子设备接收到第二电子设备返回的第一个响应包(例如广播报文B)时,第一电子设备发送反向广播报文(例如广播报文F)。如果用户在第一电子设备发送反向广播报文之前,又在第一电子设备上触发了另一次的图片/文件/视频等的分享功能,那么第一电子设备响应于用户的触发操作,再次发送用于发现周围电子设备的广播报文(例如广播报文A)。并且,第一电子设备发送反向广播报文(例如广播报文F)和第二次发现用于发现周围电子设备的广播报文(例如广播报文A)发送冲突。那么,在本申请实施例中,可以将两个广播报文进行合并,然后发送合并后的广播报文。第二电子设备在接收到该合并后的广播报文后,解析可获得两个广播报文的内容(即广播报文F和广播报文A)。由此可见,相较于现有技术,电子设备将两个广播报文进行合并发送,保证了同业务的两个任务的并发,加速了该业务不同任务的发现与连接过程。
在本申请的另一些实施例中,如果电子设备配置的蓝牙芯片支持多路广播通道,可以设置预设数量N3个广播通道用于传输广播报文,以节省芯片资源。其中,N3个广播通道可以对应N3个业务类型。后续,当电子设备有业务有待发送的广播报文时,该业务选择自身的业务类型对应广播通道,用于发送广播报文。如果此时有业务类型相同的多个业务需要发送广播报文,则可以复用该业务类型对应的广播报文。即,电子设备的应用层将这多个业务的广播报文进行合并,然后通过该业务类型对应的广播通道发送合并后的广播报文,从而保证及时发送各个业务的广播报文,减少各个业务的等待时间,加速多个业务的发现过程和连接过程。换言之,不同业务类型的业务选择复用业务类型对应的广播通道。
在一种可能的实现方式中,第一电子设备根据第一电子设备配置的无线通信芯片能力动态调整第一电子设备的广播参数,还包括:如果第一电子设备配置的无线通信芯片能力不支持多路广播通道,则第一电子设备的多个业务类型复用一个广播通道。
在本申请的一些实施例中,电子设备可以合并同一业务的不同任务的广播报文和反向广播报文。例如,用户在第一电子设备上触发了一次图片/文件/视频等的分享功能,那么第一电子设备发送用于发现周围电子设备的广播报文(例如广播报文A)。当第一电子设备接收到第二电子设备返回的第一个响应包(例如广播报文B)时,第一电子设备发送反向广播报文(例如广播报文F)。如果用户在第一电子设备发送反向广播报文之前,又在第一电子设备上触发了另一次的图片/文件/视频等的分享功能,那么第一电子设备响应于用户的触发操作,再次发送用于发现周围电子设备的广播报文(例如广播报文A)。并且,第一电子设备发送反向广播报文(例如广播报文F)和第二次发现用于发现周围电子设备的广播报文(例如广播报文A)发送冲突。那么,在本申请实施例中,可以将两个广播报文进行合并,然后发送合并后的广播报文。第二电子设备在接收到该合并后的广播报文后,解析可获得两个广播报文的内容(即广播报文F和广播报文A)。由此可见,相较于现有技术,电子设备将两个广播报文进行合并发送,保证了同业务的两个任务的并发,加速了该业务不同任务的发现与连接过程。
在一种可能的实现方式中,该方法还包括:第一电子设备根据第一电子设备的业务场景和/或第一电子设备配置的芯片能力确定发现的电子设备的显示顺序。
一种可能的实现方式中,第一电子设备根据所述第一电子设备的业务场景确定发现的电子设备的显示顺序,包括:如果检测到在图库应用、文件管理器、视频播放器中任一个应用中触发发现功能,则第一电子设备优先显示被发现的电子设备中的富设备。
一种可能的实现方式中,第一电子设备根据所述第一电子设备的业务场景确定发现的电子设备的显示顺序,还包括:如果检测到智能家居应用中触发发现功能,则第一电子设备优先显示智能家居应用中注册的电子设备。
一种可能的实现方式中,第一电子设备根据所述第一电子设备配置的芯片能力确定发现的电子设备的显示顺序,还包括:如果第一电子设备配置超宽带UWB芯片,则所述第一电子设备优先显示所述第一电子设备指向的电子设备。
一种可能的实现方式中,如果第一电子设备配置蓝牙芯片或无线保真Wi-Fi芯片或邻居感知网络NAN,则第一电子设备优先显示距离所述第一电子设备近的电子设备,或者,第一电子设备优先显示无线信号强的电子设备。
当然,第一电子设备还可以将上述几种显示策略进行组合。例如,可以按照下述的优先级组合上述显示策略:(1)1s内发现的电子设备按照如下的优先级进行排序:优先显示第一电子设备当前指向的被发现的电子设备;然后显示距离第一电子设备位于一定距离范围内的发现的电子设备;再按照用户触发发现周围电子设备功能的入口的显示策略进行排序;再按照RSSI的数值大小进行排序。(2)1s后发现电子设备按照发现的时间顺序进行排序,且排列在1s内发现的电子设备之后。
在一种可能的实现方式中,该方法还包括:第一电子设备根据第一电子设备的业务场景和/或第一电子设备配置的无线通信芯片能力动态调整第一电子设备的连接参数,连接参数包括连接间隔和/或连接通道数。
在一种可能的实现方式中,第一电子设备根据第一电子设备的业务场景动态调整第一电子设备的连接参数,包括:第一电子设备根据缓存的发现包的大小调整第一电子设备的连接间隔,其中,发现包用于发现周围的电子设备。
另一些实施例中,在连接过程中,根据第一电子设备的状态动态调整占空比(包括扫描占空比、广播占空比等)。当电子设备检测到用户选择连接某个电子设备的预设时长T3时,第一电子设备可以增大广播占空比/扫描占空比,有利于第一电子设备快速地广播或扫描,加速与其他电子设备的连接过程。当第一电子设备与其他电子设备建立连接后,电子设备可以减小广播占空比和/或扫描占空比,降低电子设备的功耗。
在一种可能的实现方式中,第一电子设备根据第一电子设备配置的无线通信芯片能力动态调整第一电子设备的连接参数,包括:第一电子设备根据第一电子设备配置的无线通信芯片的数量,在每个无线通信芯片上分别建立一个连接通道;第一电子设备的至少两个业务复用至少一个连接通道。
在一种可能的实现方式中,在第一电子设备的至少两个业务复用一个连接通道的过程中,一个连接通道传输的数据包包括业务标识和序列号。
在一种可能的实现方式中,一个连接通道传输的数据包还包括包头标记和/或优先级标记。
其中,由于多个业务复用同一个套接字,因此电子设备接收到数据包后,可以根 据其中的业务标识向相应的业务返回数据包。可见,本申请实施例保证了多个业务复用连接通道时也不会出现业务错乱的情况。
其中,序列号(seq),用于确定各个数据包的时序。例如,各个业务对应一个队列,每个队列中,发送端发送的数据包的序列号奇数递增,接收端发送的数据包的序列号偶数递增。
其中,包头标记,用于标记该数据包是否为包头。如果为包头,该包头标记置第一值,例如置1,如果为非包头,该包头标记置第二值,例如置0。接收端电子设备可以根据包头标记对多个数据包进行拼接。
其中,优先级标记,用于标记同一业务中不同重要程度的数据包,例如,控制信令类的数据包的优先级最高,高优先级的业务包,低优先级的业务包等。换言之,当连接通道的负荷较重时,可以根据优先级标记优先发送优先级高的数据包,保证高效地数据传输。
在一种可能的实现方式中,在第一电子设备建立连接通道之前,第一电子设备广播的发现请求中携带服务标识。
例如,不同电子设备触发的多个业务也可以复用同一个连接通道。在一些实施例中,为避免对端的两个电子设备同时发起连接,造成连接冲突进而连接失败的情况发生。在第一电子设备确定发起业务1(即在图14中步骤S1401)之前或之后,或者,在第一电子设备建立连接通道(如执行图14中步骤S1405)之前或之后,第一电子设备向第二电子设备发送广播报文,用于告知第二电子设备,第一电子设备已发起连接请求。那么,第二电子设备在预设时长T5内不再发起连接请求。如果用户在该预设时长T5内通过第二电子设备发起连接请求,则第二电子设备不响应该连接请求,或者延迟响应该连接请求。可选的,第二电子设备也可以提示用户,其他电子设备正在连接第二电子设备。可选的,在其他一些实施例中,在第一电子设备建立连接通道(如执行图14中步骤S1405)之后,第一电子设备通过已建立的套接字(即已建立的连接通道)向第二电子设备发送报文,用于告知第二电子设备,第一电子设备已发起连接请求。总之,本申请实施例不限定第一电子设备告知第二电子设备的方式和时机。
一种可能的实现方式中,第二电子设备的设备标识为第二电子设备的第一标识的哈希值;第二电子设备的第一标识为第一电子设备的序列号SN、国际移动设备识别码IMEI、媒体存取控制地址MAC地址中的任一项。由于哈希值不易识别以及不易被反解析,因此使用哈希值作为电子设备的唯一标识,提升了发现过程以及连接过程中的安全问题。
在本申请的另一些实施例中,用户可以通过例如重启第二电子设备的方式,重新计算得到第二电子设备的唯一标识,即重新使用公钥对电子设备的标识(例如SN、IMEI、MAC地址等)计算哈希值,使用哈希值中的部分字节作为新的第二电子设备的唯一标识。可见,用户可以控制重新生成第二电子设备的唯一标识,换言之第二电子设备的唯一标识可以变化,进一步加大被攻击的难度,进一步提升第二电子设备发现过程以及连接过程中的安全问题。
在本申请的又一些实施例中,在与第二电子设备连接过程中,还可以对发现的第二电子设备的标识进行校验,而且保证连接的电子设备与发现时的电子设备是同一个 电子设备,保证连接第二电子设备的连接安全。第一电子设备的设备标识也可以做类似的加密处理。
一种可能的实现方式中,在第一电子设备与第二电子设备的连接过程中,第一电子设备GATT客户端与第二电子设备GATT服务端的连接阶段(即阶段1)失败时,第一电子设备和第二电子设备自动重试,重试次数不超过预设次数1(例如3次),并且,第一电子设备处于阶段1的总时长控制在预设时长(例如4s)内。
一种可能的实现方式中,在第一电子设备与第二电子设备的连接过程中,第一电子设备和第二电子设备的服务发现阶段(即阶段2)失败时,第一电子设备和第二电子设备自动重试,重试次数不超过预设次数2(例如1次),并且,第一电子设备处于阶段2的总时长控制在预设时长(例如4s)内。
本申请实施例提供的技术方案通过对阶段1和阶段2的可恢复的异常进行重试,提升在本次连接的成功率。并且,通过控制第一电子设备处于阶段1和阶段2的总时长,从而使得重试的方法相较于用户重新触发连接的方法,节省连接时间,以加速连接过程。
一种可能的实现方式中,在第一电子设备确定与第二电子设备建立连接通道之前或之后,第一电子设备向第二电子设备发送第一消息,第一消息用于通知第二电子设备不向第一电子设备发送连接请求。
在第一电子设备向第二电子设备发送发现请求报文(例如广播报文A)时,可以在发现请求报文中携带的服务标识。那么,在连接过程中,在第一电子设备GATT客户端与第二电子设备GATT服务端的建立连接后(即执行阶段1后),直接设置MTU阶段(即执行阶段3)。换言之,在阶段1时第一电子设备和第二电子设备已实现服务发现成功,即本次连接过程中无需执行阶段2,由此加速了连接过程。
一种可能的实现方式中,第一电子设备在发现第二电子设备后,如果在发现后的预设时长T7(例如4s)内未接收到第二电子设备发送的广播报文时,将确定第二电子设备下线,即在发现的电子设备的列表中不再显示第二电子设备的标识。
如此,避免当第二电子设备不满足连接条件时,仍然出现在发现列表中,误导用户选择连接的电子设备。
在本申请的又一些实施例中,第一电子设备还可以为不同设备类型的电子设备设置不同的预设时长T7。例如,被发现的电子设备是PC时,预设时长T7设置为6s;被发现的电子设备是手机时,预设时长T7设置为4s。这是考虑到不同设备类型的电子设备的广播占空比不同,有利于提高下线的准确性。
第五方面、提供一种电子设备,包括:处理器、存储器和无线通信模块,所述存储器、所述无线通信模块与所述处理器耦合,所述存储器用于存储计算机程序代码,所述计算机程序代码包括计算机指令,当所述处理器从所述存储器中读取所述计算机指令,以使得所述电子设备执行上述第二方面、第三方面、第四方面以及其中任一方面的任一种可能的实现方式中的方法。
第六方面、提供一种计算机可读存储介质,包括计算机指令,当计算机指令在电子设备上运行时,使得电子设备执行如上述第二方面、第三方面、第四方面以及其中任一方面的任一种可能的实现方式中的方法。
第七方面、提供一种计算机程序产品,当计算机程序产品在计算机上运行时,使得计算机执行如上述第二方面、第三方面、第四方面以及其中任一方面的任一种可能的实现方式中的方法。
第八方面、提供一种芯片系统,包括处理器,当处理器执行指令时,处理器执行如上述第二方面、第三方面、第四方面以及其中任一方面的任一种可能的实现方式中的方法。
第五方面至第八方面提供的电子设备、计算机可读存储介质、计算机程序产品以及芯片系统所能达到的技术效果可参考第二方面、第三方面、第四方面以及其中任一方面的任一种可能的实现方式中有关技术效果的描述。
附图说明
图1为本申请实施例提供的一种无线通信系统的结构示意图;
图2为本申请实施例提供的一种电子设备的结构示意图;
图3为本申请实施例提供的一种BLE协议栈的结构示意图;
图4为本申请实施例提供的一种第一电子设备发现第二电子设备的方法流程示意图;
图5为本申请实施例提供的一种广播报文的格式示意图;
图6为本申请实施例提供的一些第一电子设备的用户界面示意图;
图7为本申请实施例提供的一些第一电子设备发现第二电子设备的方法流程示意图;
图8为本申请实施例提供的一些HCI数据包的内容示意图;
图9为本申请实施例提供的一种发现窗口与连接窗口重合的解决方法的示例图;
图10为本申请实施例提供的又一些HCI数据包的内容示意图;
图11为本申请实施例提供的一种广播报文中数据域的格式示意图;
图12为本申请实施例提供的一种复用广播通道的方法流程示意图;
图13为现有技术中第一电子设备上触发多个业务时连接过程的示意图;
图14为本申请实施例提供的一种复用连接通道的方法流程示意图;
图15为本申请实施例提供的又一种无线连接方法的流程示意图;
图16为本申请实施例提供的一种芯片系统的结构示意图。
具体实施方式
在本申请实施例的描述中,除非另有说明,“/”表示或的意思,例如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,例如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。以下,术语“第一”、“第二”仅用于描述目的,而不能理解为指示或暗示相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括一个或者更多个该特征。在本申请实施例的描述中,除非另有说明,“多个”的含义是两个或两个以上。另外,“示例性的”或者“例如”等词用于表示作例子、例证或说明。本申请实施例中被描述为“示例性的”或者“例如”的任何实施例或设计方案不应被解释为比其它实施例或设计方案更优选或更具优势。确切而言,使用“示例性的”或者“例如”等词旨在以具体方式呈现相关概 念。
如图1所示,为本申请实施例提供的一种通信系统的结构示意图,该通信系统包括至少第一电子设备100以及第二电子设备200。其中,其中第一电子设备100和第二电子设备200均具备无线连接功能。其中无线连接例如为BLE连接、经典蓝牙(BR)连接、点对点(point to point,P2P)连接,邻居感知网络(neighbor awareness network,NAN)连接,约束应用协议(Constrained Application Protocol,CoAP)连接等。本申请实施例提供的技术方案可应用于第一电子设备100和第二电子设备200之间建立无线通信连接的场景。
示例性的,该第一电子设备100/第二电子设备200例如可以为手机、平板电脑、个人计算机(personal computer,PC)、个人数字助理(personal digital assistant,PDA)、上网本、可穿戴电子设备(例如智能手表)、增强现实技术(augmented reality,AR)设备、虚拟现实(virtual reality,VR)设备、车载设备、智慧屏、智能音响、智能家电等,本申请对第一电子设备100/第二电子设备200的具体形式不做特殊限制。并且,第一电子设备100的具体形式与第二电子设备200的具体形式可以相同,也可以不同。
请参见图2,为本申请实施例提供的第一电子设备100的结构示意图。需要说明的是,第二电子设备200也可以参考第一电子设备100的结构描述。并且,第二电子设备200的结构可以与第一电子设备100相同,也可以不同。换言之,第二电子设备200可以包括比第一电子设备100具有更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。
第一电子设备100可以包括处理器110,外部存储器接口120,内部存储器121,通用串行总线(universal serial bus,USB)接口130,充电管理模块140,电源管理模块141,电池142,天线1,天线2,移动通信模块150,无线通信模块160,音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,传感器模块180,按键190,马达191,指示器192,摄像头193,显示屏194,以及用户标识模块(subscriber identification module,SIM)卡接口195等。
可以理解的是,本发明实施例示意的结构并不构成对第一电子设备100的具体限定。在本申请另一些实施例中,第一电子设备100可以包括比图示更多或更少的部件,或者组合某些部件,或者拆分某些部件,或者不同的部件布置。图示的部件可以以硬件,软件或软件和硬件的组合实现。另外,本发明实施例示意的各模块间的接口连接关系,只是示意性说明,并不构成对第一电子设备100的结构限定。在本申请另一些实施例中,第一电子设备100也可以采用上述实施例中不同的接口连接方式,或多种接口连接方式的组合。
处理器110可以包括一个或多个处理单元,例如:处理器110可以包括应用处理器(application processor,AP),调制解调处理器,图形处理器(graphics processing unit,GPU),图像信号处理器(image signal processor,ISP),控制器,视频编解码器,数字信号处理器(digital signal processor,DSP),基带处理器,和/或神经网络处理器(neural-network processing unit,NPU)等。其中,不同的处理单元可以是独立的器件,也可以集成在一个或多个处理器中。
处理器110中还可以设置存储器,用于存储指令和数据。在一些实施例中,处理 器110中的存储器为高速缓冲存储器。该存储器可以保存处理器110刚用过或循环使用的指令或数据。如果处理器110需要再次使用该指令或数据,可从所述存储器中直接调用。避免了重复存取,减少了处理器110的等待时间,因而提高了系统的效率。
充电管理模块140用于从充电器接收充电输入。电源管理模块141用于连接电池142,充电管理模块140与处理器110。电源管理模块141接收电池142和/或充电管理模块140的输入,为处理器110,内部存储器121,显示屏194,摄像头193,和无线通信模块160等供电。
第一电子设备100的无线通信功能可以通过天线1,天线2,移动通信模块150,无线通信模块160,调制解调处理器以及基带处理器等实现。
天线1和天线2用于发射和接收电磁波信号。第一电子设备100中的每个天线可用于覆盖单个或多个通信频带。不同的天线还可以复用,以提高天线的利用率。例如:可以将天线1复用为无线局域网的分集天线。在另外一些实施例中,天线可以和调谐开关结合使用。
移动通信模块150可以提供应用在第一电子设备100上的包括2G/3G/4G/5G等无线通信的解决方案。
无线通信模块160可以提供应用在第一电子设备100上的包括无线局域网(wireless local area networks,WLAN)(如无线保真(wireless fidelity,Wi-Fi)网络),蓝牙(bluetooth,BT),全球导航卫星系统(global navigation satellite system,GNSS),调频(frequency modulation,FM),近距离无线通信技术(near field communication,NFC),红外技术(infrared,IR)等无线通信的解决方案。无线通信模块160可以是集成至少一个通信处理模块的一个或多个器件。无线通信模块160经由天线2接收电磁波,将电磁波信号调频以及滤波处理,将处理后的信号发送到处理器110。无线通信模块160还可以从处理器110接收待发送的信号,对其进行调频,放大,经天线2转为电磁波辐射出去。
第一电子设备100通过GPU,显示屏194,以及应用处理器等实现显示功能。
外部存储器接口120可以用于连接外部存储卡,例如Micro SD卡,实现扩展第一电子设备100的存储能力。外部存储卡通过外部存储器接口120与处理器110通信,实现数据存储功能。例如将音乐,视频等文件保存在外部存储卡中。
内部存储器121可以用于存储计算机可执行程序代码,所述可执行程序代码包括指令。内部存储器121可以包括存储程序区和存储数据区。其中,存储程序区可存储操作系统,至少一个功能所需的应用程序(比如声音播放功能,图像播放功能等)等。存储数据区可存储第一电子设备100使用过程中所创建的数据(比如音频数据,电话本等)等。此外,内部存储器121可以包括高速随机存取存储器,还可以包括非易失性存储器,例如至少一个磁盘存储器件,闪存器件,通用闪存存储器(universal flash storage,UFS)等。处理器110通过运行存储在内部存储器121的指令,和/或存储在设置于处理器中的存储器的指令,执行第一电子设备100的各种功能应用以及数据处理。
第一电子设备100可以通过音频模块170,扬声器170A,受话器170B,麦克风170C,耳机接口170D,以及应用处理器等实现音频功能。例如音乐播放,录音等。
本申请中以第一电子设备100与第二电子设备200建立BLE的无线连接为例,对 本申请实施例提供的无线连接方法进行详细说明。
如图3所示,为一种低功耗蓝牙协议栈的结构示意图。上述图1所示的第一电子设备100/第二电子设备200均可采用图3所示的低功耗蓝牙协议,以实现第一电子设备100/第二电子设备200上的BLE应用。简单来说,BLE协议栈用于对BLE应用数据进行层层封包,以生成一个满足BLE协议的空中数据包。也就是说,把BLE应用数据包裹在一系列的帧头(header)和帧尾(tail)中。具体来说,BLE协议栈包括:BLE应用(application)层、BLE主机(host)层以及BLE控制(control)层。
其中,BLE应用层包括应用程序和基于通用属性配置文件(generic attribute profile,GATT)的配置文件(profile)/服务(service)。其中,应用程序为具体的BLE应用,例如音乐应用、图片应用、语音应用、视频应用等。
BLE主机层包括通用访问配置文件(generic access profile,GAP)、GATT、属性协议(attribute protocol,ATT)、安全管理(secure manager,SM)以及逻辑链路控制和适配协议(logic link control and adaptation protocol,L2CAP)。
其中,GAP,用来控制电子设备连接和广播。例如,从数据的发起和接收角度,GAP定义了四个角色:广播者(broadcaster)、观察者(observer)、外围设备(peripheral)和中央设备(central)。其中,广播者,指电子设备正在发送广播事件(advertising event)。观察者,指电子设备正在接收广播事件。外围设备,指电子设备接收链路层(link layer,LL)连接(对应于LL层的从设备(slave)角色)。中心设备,指电子设备发起LL连接(对应于LL层的主设备(master)角色)。又例如,GAP定义了实现各种通信的操作模式和过程,包括实现单向的无连接的通信方式、实现电子设备的发现操作、实现电子设备的连接操作、实现蓝牙设备的配对操作等。又例如,GAP定义了用户接口(user interface)有关的蓝牙参数,包括蓝牙地址、蓝牙名称、蓝牙类型等。
GATT,是在ATT的基础上进行构建的,为ATT传输和存储数据建立了一些通用操作和框架。其中GATT从数据的提供和使用的角度定义了两个角色:GATT服务器(server)和GATT客户端(client)。其中,GATT服务器,维护了ATT的查找表以及service和特性(characteristic)的定义等。GATT客户端向GATT服务器发送请求,并接收GATT服务器的响应。
ATT,是GATT和GAP的基础,它定义了BLE协议栈上层的数据结构和组织方式。属性(attribute)概念是ATT层的核心,ATT层定义了属性的内容,规定了访问属性的方法和权限。属性可以理解为一个数据结构,它包括了数据类型和数据值。属性有多级,顶级为配置文件(profile),下辖多个服务(service),服务下辖多个特征(characteristic),特征下辖多个描述符(descriptor)。ATT定义了客户端(client)和服务器(server)之间通信的方式,包括:请求(request)、响应(response)、命令(command)、指示(indication)、确认(confirmation)和通知(notification)。
SM,负责BLE通信中有关安全的内容,包括配对(pairing,)、认证(authentication)和加密(encryption)等过程。
L2CAP提供的功能包括:协议/信道多路复用;上层应用数据的分割(和重组),生成协议数据单元(packet data unit,PDU),以满足用户数据传输对延时的要求,并便于后续的重传、流控等机制的实现;PDU的分片(和重组),生成符合LL传输要 求的数据片;支持流式传输(如音频、视频等,不需要重传或者只需要有限重传)等。
BLE控制层包括LL和物理层(physical layer,PL)。
其中,LL实现的功能包括:具体选择哪个射频通道进行通信,怎么识别空中数据包,具体在哪个时间点把数据包发送出去,怎么保证数据的完整性,如何进行重传,以及如何对链路进行管理和控制等。PL用于指定BLE所用的无线频段,调制解调方式和方法等。
可选的,在BLE主机和BLE控制器之间还包括主机控制器接口(host controller interface,HCI)。HCI可以用于2颗蓝牙芯片实现BLE协议栈的场合,用来规范两者之间的通信协议和通信命令等。
(一)发现流程
如图4所示,为本申请实施例提供的一种第一电子设备发现第二电子设备的方法流程示意图,该流程包括:
S400、第一电子设备显示第一界面。
S401、响应于接收到用户在第一界面上的触发操作,第一电子设备发送广播报文A,其中广播报文A用于发现周围的电子设备。
相应的,第二电子设备接收到广播报文A。
在步骤S400和步骤S401中,用户在第一电子设备显示的第一界面上触发第一电子设备的BLE功能,用于发现其他电子设备。示例性的,用户的触发操作例如为用户在图库应用的界面(即第一界面)中触发分享/转发等功能,或者,用户在视频播放界面(即第一界面)中触发投屏等功能,又或者,用户在第一电子设备的设置应用的界面(即第一界面)中开启蓝牙功能,又或者,用户输入语音命令触发分享/转发/投屏/开启蓝牙功能等。响应于接收到用户在第一界面上的触发操作,第一电子设备发送广播报文A(也称为发现请求报文),用于发现周围的电子设备。一些示例中,广播报文A中可以携带第一电子设备的设备信息(例如第一电子设备厂商信息、第一电子设备的名称等)。可选的,广播报文A中还可以携带第一电子设备的业务标识(例如图像分享业务、投屏业务、发现业务)。
S402、第二电子设备发送广播报文B。
相应的,第一电子设备接收到广播报文B。
第二电子设备接收广播报文A后,对广播报文A进行解析。若根据广播报文A的解析结果确认第二电子设备是第一电子设备扫描的备选电子设备,发送广播报文B,用于响应接收到的广播报文A。若根据广播报文A的解析结果确认第二电子设备不是第一电子设备扫描的备选电子设备,则忽略该广播报文A。例如:第二电子设备根据广播报文A中第一电子设备的厂商信息,确定第二电子设备与第一电子设备为同一个厂商,或者是第一电子设备的合作厂商时,确认第二电子设备是第一电子设备扫描的备选电子设备。那么,第二电子设备发送广播报文B,其中广播报文B中携带第二电子设备的设备标识、登录的账号、设备类型、第二电子设备注册的业务标识等信息。
如图5所示,为一种BLE广播报文的格式。BLE广播报文包括1字节的前导、4字节的接入地址、1字节的报头、1字节的长度、0~37字节的数据以及3字节的校验。其中,报头中包括4比特的广播报文类型、2比特的保留位、1比特的发送地址类型以 及1比特的接收地址类型。数据包括6字节的广播设备地址以及31字节的净荷
(payload)。需要注意的是,电子设备(例如第二电子设备)需要广播的内容例如包括:设备名(通常为22字节)、账号名、设备类型、注册业务、能力等信息,这些内容通常大于31字节,而一条广播报文中包括的净荷最多为31字节。因此,被发现的电子设备一般需要发送多条广播报文,用于响应第一电子设备发送的广播报文A。需要说明的是,图4中所示的流程是以被发现的电子设备需广播两条广播报文(分别为本步骤中的广播报文B以及步骤S404中的广播报文C)为例进行说明的。其中,广播报文B例如携带第二电子设备的设备标识(例如媒体存取控制地址(media access control address,MAC地址)、设备名称(例如SoundX)、登录账号(例如123@huawei.com)、注册的业务标识和设备类型(例如智能音箱)等中的一项或多项。
S403、第一电子设备缓存广播报文B。
当第一电子设备接收到第二电子设备发送的广播报文B后,缓存广播报文B的内容,缓存时长例如可以8秒。可选的,第一电子设备的缓存机制例如可以是LruCache机制,缓存最近接收到的N4(例如为20)个广播报文B(该N4个广播报文B可以是第一电子设备周围的任意一个或多个的电子设备发送的)。也就是说,当接收到第21个广播报文B时,如果第21个广播报文B与前20个广播报文B中任一个相同时,则更新该相同的广播报文B的时间戳。如果第21个广播报文B与前20个广播报文B不同(例如电子设备的标识、账号等不同)时,用本次接收的广播报文B替换最早接收的广播报文B。
S404、第二电子设备在时长T1后发送广播报文C。
相应的,第一电子设备接收到广播报文C。
其中,广播报文C例如携带第二电子设备的设备标识(例如MAC地址)。可选的,广播报文C还可以携带第二电子设备的登录账号、注册的业务标识和设备能力等中的一项或多项。换言之,广播报文C可以携带广播报文B中未携带的第二电子设备的信息。即,广播报文C和广播报文B中至少部分内容不同。
在现有技术中,当第一电子设备接收到广播报文B后,对广播报文B进行解析,然后发送针对广播报文B的确认(acknowledge,ACK)报文。第二电子设备在接收到第一电子设备发送的ACK报文后,对ACK报文进行解析,再发送广播报文C。其中,从第二电子设备发送广播报文B之后到第二电子设备发送广播报文C之前的整个过程耗时为时长T2,例如T2通常为300ms。
然而,在本申请实施例中第二电子设备在发送广播报文B后的时长T1后直接发送广播报文C,即第二电子设备无需等待接收到第一电子设备发送的针对广播报文B的ACK报文。其中,T1小于T2(例如300ms)。在一个示例中,T1可以设置为一个固定的时长(例如60ms)加上一个随机时长(例如40ms之内的随机时长)。对比现有技术,现有技术中从第二电子设备发送广播报文B后,到第二电子设备发送广播报文C整个过程耗时为时长T2,T2通常为300ms,然而本申请实施例中这个过程耗时为T1,T1可设置为不大于100ms。可见,本申请实施例提供的技术方案相较于现有技术的技术方案节省了T0=T2-T1,T0大于200ms。
S405、第一电子设备缓存广播报文C。
第一电子设备在接收到第二电子设备发送的广播报文C后,缓存广播报文C的内容。需要说明的是,这里第一电子设备缓存第二电子设备的广播报文C的内容,便于后续第一电子设备再次发现周围电子设备时,能快速发现第二电子设备。当然本步骤是可选的。
S406、第一电子设备根据广播报文B和广播报文C显示第二界面,第二界面中包括第二电子设备的信息。
在第一电子设备接收到广播报文C后,根据广播报文C的MAC地址查找到广播报文B,其中,查找到的广播报文B的MAC地址与广播报文C的MAC地址相同,即广播报文B和广播报文C为同一个电子设备(即第二电子设备)发送的。而后,第一电子设备将广播报文B和广播报文C的内容进行拼接,用于确定是否在第一电子设备显示的发现列表(即第二界面)中显示第二电子设备的信息。
示例性的,如图6中(1)所示,为第一电子设备(例如手机)显示的设置应用的界面601(即第一界面)的示例。当手机检测到用户在界面601中操作蓝牙功能的开关控件602,手机发送广播报文A,用于发现周围的电子设备。其中,第二电子设备(例如智能音箱)在接收到广播报文A后发送广播报文B,并在发送广播报文B的时长T1后发送广播报文C。第一电子设备根据接收到的广播报文B和广播报文C,确定发现第二电子设备,则显示如图6中(2)所示的界面603。界面603中包括手机发现的周围的设备的列表,例如包括第二电子设备标识604(例如智能音箱,设备名为SoundX)。由此可见,由于第二电子设备提前发送了广播报文C,加快了第一电子设备发现第二电子设备的过程。
可以理解的是,在其他一些实施例中,第二电子设备在接收到第一电子设备发送的广播报文A后,第二电子设备需要发送大于两条(例如N1条,N1大于2)的广播报文用于回复第二电子设备的信息。在该实施例中,第二电子设备在发送第一条广播报文(即广播报文B)后的每一条广播报文时,均无需等待第一电子设备针对上一条广播报文的ACK报文,便直接在发送完上一条广播报文后的时长T1后,发送本条广播报文。相较于现有技术,现有技术中第二电子设备在发送第一条广播报文(即广播报文B)后的每一条广播报文时,均需等待接收到第一电子设备发送针对上一条广播报文的ACK报文后才发送本条广播报文。而本申请提供的实施例则在发送一条广播报文后的时长T1后自动发送下一条广播报文。那么,本申请实施例提供的技术方案中,第一电子设备发现第二电子设备的过程可节省的时长T0’=(N1-1)*(T2-T1)。由此可见,当第二电子设备需要回复的广播报文数量N1越大时,本申请实施例提供的技术方案提升发现速率的效果越显著。
在本申请的又一些实施例中,第一电子设备在较短的时间内(例如在缓存广播报文C的缓存时长之内)需再次发现第二电子设备。例如,第一电子设备在该较短时间内再次触发图片/文件/视频等的转发/分享功能,或者第一电子设备周期性(周期小于时长T1)刷新发现的电子设备。那么,第一电子设备在执行步骤S406之后,还执行步骤S407-步骤S409。
S407、第一电子设备发送广播报文A。
相应的,第二电子设备接收到广播报文A。
其中,广播报文A用于发现第一电子设备周围的电子设备。一些示例中,广播报文A中可以携带第一电子设备的设备信息(例如第一电子设备厂商信息、第一电子设备的名称等)。可选的,广播报文A中还可以携带第一电子设备的业务标识(例如图像分享业务、投屏业务、发现业务)。
例如,用户在第一电子设备上触发了一次图片分享功能后,第一电子设备通过执行上述步骤S401-步骤S406后发现第二电子设备,第一电子设备可以与第二电子设备建立连接并传输本次分享的图片。在较短时间内,用户再次在第一电子设备上触发另一次图片分享功能时,第一电子设备发送广播报文A,用于再次发现周围的电子设备。
S408、第二电子设备发送广播报文B。
相应的,第一电子设备接收到广播报文B。
这里广播报文B与步骤S402中第二电子设备发送的广播报文B相同,其中广播报文B中携带第二电子设备的设备标识(例如MAC地址)、登录的账号、设备类型等信息。
S409、第一电子设备根据广播报文B查找广播报文C,然后根据广播报文B和广播报文C显示第三界面,其中第三界面中包括第二电子设备的信息。
需要注意的是,这里第一电子设备在接收到广播报文B后,可以根据广播报文B的MAC地址查找到之前缓存的广播报文C,将广播报文B和广播报文C的内容进行拼接,用于确定是否在第一电子设备刷新的发现设备的列表(即第三界面)中显示第二电子设备的信息,例如显示第二电子设备的图标、名称等。
在现有技术中,第一电子设备再次发现第二电子设备的流程与第一次发现第二电子设备的流程相同,即第二电子设备需发送两条广播报文用于响应第一电子设备发送的用于发现的广播报文,并且,在第二电子设备在接收到第一电子设备发送的针对第一条广播报文的ACK报文后,第二电子设备才发送第二条广播报文。然而,在本申请实施例中,第二电子设备仅发送了一条广播报文时,第一电子设备便可以根据该广播报文和之前缓存的另一条的广播报文进行内容拼接,确定发现第二电子设备。现有技术中,从第一电子设备接收到第二电子设备发送的第一条广播报文后,到向第二电子设备发送针对第一条广播报文的ACK报文后,再到接收到第二电子设备发送的第二条广播报文的过程耗时大于T2,本申请实施例中节省了该过程。也就是说,第一电子设备再次发现第二电子设备的整个过程节省了至少T2的时长,例如节省了至少300ms。
可以理解的是,在其他一些实施例中,第二电子设备在接收到第一电子设备发送的广播报文A后,第二电子设备需要发送大于两条(例如N1条,N1大于2)的广播报文用于回复第二电子设备的信息。类似的,第一电子设备接收到第二电子设备发送的第一条广播报文后,可以根据自身缓存的其他广播报文(一条或多条广播报文)提前确定发现第二电子设备,加速第二电子设备的发现过程。
在本申请的又一些实施例中,第一电子设备在接收到第二电子设备发送的用于响应广播报文A的任一广播报文,但未接收到第二电子设备发送的用于响应广播报文A的全部广播报文时,可以发送反向广播报文。该反向广播报文用于请求第二电子设备交替发送用于响应广播报文A的全部广播报文。
例如,请参见图7中(1)所示流程:在执行步骤S402之后,第一电子设备接收 到广播报文B,但此时仍缺少用于响应广播报文A的其他广播报文,例如广播报文C。那么,第一电子设备执行步骤S501,即发送广播报文F,广播报文F用于请求第二电子设备交替发送用于响应广播报文A的全部广播报文。那么,存在两种情况,一种情况是:第二电子设备在发送广播报文B后时长T1之前,接收到广播报文F,那么第二电子设备交替性发送用于响应广播报文A的全部报文(即第二电子设备发送各个广播报文的时间间隔较短,小于时长T1)。另一种情况是:第二电子设备在发送广播报文B后时长T1之后,接收到广播报文F,那么,第二电子设备仍然在发送广播报文B后时长T1之后发送广播报文C(即执行步骤S404)。而后,在接收到广播报文F之后,交替性发送用于响应广播报文A的全部报文。可以注意到,第一电子设备发送广播报文F,可用于触发第二电子设备快速交替发送用于响应广播报文A的全部广播报文,有利于第一电子设备快速收集到响应广播报文A的全部广播报文,快速发现第二电子设备。
本流程中其他步骤的描述可参考图4中相应内容的描述,这里不再赘述。
又例如,请参见图7中(2)所示流程:在执行步骤S402时,若广播报文B发生丢包时,第一电子设备未接收到广播报文B。第二电子设备继续在发送广播报文B后的时长T1后发送广播报文C,即执行步骤S404。在第一电子设备接收广播报文C时,确定此时仍然缺少响应广播报文A的其他广播报文,例如广播报文B,则发送反向广播报文(即执行步骤S502)。当第二电子设备接收到广播报文F,则交替性发送用于响应广播报文A的全部报文。当第二电子设备发送了缺少的广播报文(例如广播报文B)(即执行步骤S503)后,第一电子设备接收到缺少的广播报文(例如广播报文B)后,再根据之前缓存的广播报文(例如广播报文C),执行步骤S406。可选的,第一电子设备缓存接收到的广播报文B(即执行步骤S504)。
在现有技术中,如果发生丢包,则第一电子设备需要在重新发送广播报文A,并且,第二电子设备也需要重新发送用于响应广播报文A的全部广播报文(即广播报文B和广播报文C),并且第二电子设备发的广播报文之间间隔时长T1。然而,在申请实施例中提供的技术方案中,在发生丢包的情况下,第一电子设备发送反向广播报文,即广播报文F,有利于触发第二电子设备快速交替发送用于响应广播报文A的全部广播报文(即第二电子设备发送各个广播报文的时间间隔较短,小于时长T1),有利于第一电子设备快速收集到响应广播报文A的全部广播报文,快速发现第二电子设备。
在本申请的又一些实施例中,第二电子设备可以在接收到广播报文A或者反向广播报文(即广播报文F)后,才广播自身的信息(即发送广播报文B和广播报文C),以便被其他电子设备(例如第一电子设备)发现。在其他情况下,第二电子设备可以不用广播第二电子设备的信息,即第二电子设备无需频繁发送广播报文,有利于节省第二电子设备的功耗。
还需要说明的是,上述以第一电子设备和第二电子设备的发现过程为例进行说明的,本申请实施例也可以适用于其他场景(例如组网场景、发送心跳报文的场景)中。例如,在其他需要在一段时间内固定发送两个或两个以上数据包的场景中,发送方的电子设备可以不用等待接收方的电子设备回复ACK报文,在发送上一个数据包后的时长T1后,自动发送后续的数据包等。
在本申请的又一些实施例,在电子设备的发现过程中,还可以根据业务场景(例如业务阶段、缓存的业务数据量大小)、电子设备的状态、蓝牙芯片能力等调整电子设备的广播参数(如广播类型、扫描占空比、广播占空比、广播通道数等)、连接参数(如连接间隔、连接通道数等)等,以加速发现过程,提升发现成功率,加速连接过程等。
(二)电子设备在不同的业务阶段下设置不同的广播参数(例如广播类型)。
示例性的,在第一电子设备第一次发送广播报文A用于发现周围电子设备(即执行图4中步骤S401)之前,设置第一电子设备的广播类型(advertisement type)设置不可连接(non-connectable)。由于第一电子设备的广播类型为不可连接时,第一电子设备的应用层在向底层送广播报文A时,底层无需等待其他电子设备(如第二电子设备)连接的广播报文,而是直接发送广播报文A。在现有技术中,第一电子设备的广播类型为可连接(connectable)。第一电子设备的应用层在向底层发送广播报文A时,底层(例如具体是L2CAP)需等待一个连接间隔(connection interval),用于等待接收其他电子设备连接的广播报文。其中,连接间隔是两个电子设备间交互的时间间隔,一般为20ms。可见,当第一电子设备在发送广播报文A之前,将广播类型设置为不可连接,有利于发现过程加速一个连接间隔的时长,例如20ms。
后续,在第一电子设备接收到第二电子设备的任一广播报文后,将第一电子设备的广播类型设置为可连接(connectable)。也就是说,当第一电子设备后续发送反向广播(例如图7中(1)中的步骤S501、图7中(2)中的步骤S502)或者再次发送广播报文A(例如图4中步骤S407)时,第一电子设备的广播类型为可连接。这是因为,当第一电子设备接收到第二电子设备的任一广播报文后,第一电子设备的底层在发送应用层的广播报文时,可以等待一个连接间隔的时长,用于接收其他电子设备(如第二电子设备)是否有连接的广播报文,提升连接其他电子设备的成功率。
对于第二电子设备,在第二电子设备接收到第一电子设备发送的任一广播报文后,例如,第二电子设备接受到第一电子设备的广播报文A(即如图4中的步骤S401)后,第二电子设备的广播类型可设置为可连接。那么,第二电子设备的底层在发送应用层的广播报文时,可以等待一个连接间隔的时长,用于接收其他电子设备(如第一电子设备)连接请求。
在一个具体实现方式中,以安卓(Android)系统为例,第一电子设备或第二电子设备的应用层可以调用AdvertiseSettings.Builder setConnectable(boolean connectable)的应用程序接口(application programming interface,API)设置广播类型是否为可连接或者不可连接。例如,如图8中(1)为利用蓝牙抓包工具抓取的一个HCI层的数据包的内容。其中,标记801示出了该电子设备的广播类型被设置为可连接。如图8中(2)为利用蓝牙抓包工具抓取的另一个HCI层的数据包的内容。其中,标记802示出了该电子设备的广播类型被设置为不可连接。
(三)电子设备根据缓存的业务数据量动态调整连接间隔。
在一些场景中,第一电子设备和第二电子设备之间存在两个或两个以上的任务(可以是同一业务的不同任务,也可以是不同业务的任务)时,两个或两个以上的任务之间可能存在冲突的情况。例如,其中一个任务需发送发现过程的数据包(简称为发现 包,例如图4中的第一电子设备发送的广播报文A和广播报文F,第二电子设备发送的广播报文B和广播报文C),另一个任务需发送建立连接后的数据包(简称为连接包)。如果电子设备同时需要发送发现包和连接包时,发生冲突。
比如,用户在第一电子设备上触发了图片/文件/视频等的分享功能(简称分享任务),那么第一电子设备与第二电子设备建立BLE连接,并传输本次分享的图片/文件/视频等的数据包。如果在传输连接包的过程中,第一电子设备的其他任务(例如组网任务)也需要第一电子设备和第二电子设备交互发现包,那么第一电子设备与第二电子设备交互的发现包,可能与第一电子设备和第二电子设备正在传输的连接包发生冲突。也就是说,如图9中(1)所示,第一电子设备和第二电子设备在组网任务中发送发现包的时间窗口(简称为发现窗口),与分享任务中用于发送连接包的时间窗口(简称为连接窗口)出现重合。在现有技术中,由于在同一时刻蓝牙芯片的硬件层(也称为芯片层)仅能发送一个数据包,因此当接收到来自蓝牙芯片的软件层的发现包与连接包时,硬件层会认为连接包优先级高于发现包,优先发送连接包,丢弃发现包。可见,现有技术中延长了组网任务中两个电子设备的发现过程,甚至可能造成两个电子设备未成功发现对方,即降低了发现的成功率。然而,在本申请实施例中,当电子设备(例如第一电子设备/第二电子设备)的L2CAP层接收到应用层发送的发现包和连接包时,电子设备的L2CAP层缓存待发送的发现包,发送连接包。当检测到连接间隔时,电子设备的L2CAP层再发送缓存的发现包。其中,连接间隔是指第一电子设备向第二电子设备建立连接后,第一电子设备和第二电子设备交互间的时间间隔。也就是说,如图9中(2)所示,本申请实施例通过缓存组网任务中的发现包,并在检测到分享任务中的连接间隔时,再发送组网任务中的发现包,从而达到将分享任务的发现窗口与组网任务的连接间隔对齐的作用,从而相对现有技术缩短了组网任务中两个电子设备的发现过程。
需要说明的是,当存在多个发现包与连接包冲突的情况下,电子设备(第一电子设备/第二电子设备)的L2CAP层在缓存多个业务的发现包时,可以按照一定的优先级(例如根据业务的重要性、或者发现包的重要性等)建立缓存队列。当检测到连接间隔时,电子设备的L2CAP层按照优先级的顺序优先发送优先级高的发现包,从而优先保证优先级高的业务的发现速度和发现成功率。
可选的,在其他一些示例中,还可以根据缓存的发现包的数据量动态地调整第一电子设备和第二电子设备之间的连接间隔。在具体实现时,可以为缓存的发现包的数据量设置一个最大阈值,和/或,为缓存的发现包的数据量设置一个最小阈值。当电子设备(例如第一电子设备/第二电子设备)的L2CAP层的缓存的发现包的数据量大于或等于最大阈值时,增大第一电子设备和第二电子设备之间的连接间隔。当电子设备的L2CAP层的缓存的发现包的数据量小于或等于最小阈值时,减小第一电子设备和第二电子设备之间的连接间隔。例如,如图9中(3)所示,当第一电子设备和第二电子设备之间的连接间隔增大后,相当于第一电子设备和第二电子设备用于发送其他业务的发现包的发现窗口也增大了,有利于快速发送第一电子设备和第二电子设备之间较多的发现包,缩短其他业务的发现过程以及提高发现成功率。又例如,如图9中(4)所示,当第一电子设备和第二电子设备之间的连接间隔减小后,相当于第一电子设备 和第二电子设备的连接窗口增多了,第一电子设备和第二电子设备用于发送其他业务的发现包的发现窗口也减小了。那么,既加快了第一电子设备和第二电子设备之间已建立连接的业务的连接包的传输速率,又能满足发送第一电子设备和第二电子设备之间较少的发现包,合理地分配了芯片资源。
当缓存的发现数据包的数据量恢复到一定范围内(大于最小阈值,且小于最大阈值)时,第一电子设备和第二电子设备之间的连接参数也可以恢复到调整之前的数值或者恢复默认值等。
在一个具体实现中,当第一电子设备或第二电子设备的L2CAP层在检测到缓存的发现包的数据量大于或等于最大阈值时,可以调用gap_conn_params.min_conn_interval=MIN_CONN_INTERVAL的方式增大连接间隔的最小值,以及调用gap_conn_params.max_conn_interval=MAX_CONN_INTERVAL的方式增大连接间隔的最大值。换言之,将连接间隔的范围整体增大。或者,当第一电子设备或第二电子设备的L2CAP层在检测到缓存的发现包的数据量小于或等于最小阈值时,可以调用gap_conn_params.min_conn_interval=MIN_CONN_INTERVAL的方式减小连接间隔的最小值,以及调用gap_conn_params.max_conn_interval=MAX_CONN_INTERVAL的方式减小连接间隔的最大值。换言之,将连接间隔的范围整体减小。
在某个电子设备(例如第一电子设备/第二电子设备)增大/减小连接间隔后,需向对端的电子设备(例如第二电子设备/第一电子设备)发送L2CAP连接参数(即连接间隔)更新请求,以告知对端的电子设备已更新L2CAP连接参数。
需要说明的是,上述实施例是以BLE为例进行说明的,其他的无线连接方式(例如Wi-Fi)也可以采用上述实施例提供的方案动态调整连接间隔,不再一一赘述。
(四)电子设备根据电子设备的状态动态调整占空比(包括扫描占空比、广播占空比等)。
其中,占空比是指电子设备处理时长除以空闲的间隔时长。广播占空比,是指电子设备广播的时长除以空闲的间隔时长。可以理解的,广播占空比越大,电子设备广播得越频繁,那么电子设备被发现得越快,连接越快。扫描占空比,是指电子设备扫描的时长除以空闲的间隔时长,其中,扫描是指监听广播。可以理解的,扫描占空比越大,电子设备扫描得越频繁,发现其他电子设备越快,连接越快。
在本申请的一些实施例中,在电子设备的发现过程中,根据电子设备的状态动态调整占空比(包括扫描占空比、广播占空比等)。当电子设备(例如第一电子设备/第二电子设备)从灭屏状态进入亮屏状态的预设时长T3(例如1分钟)内时,或者从锁屏状态进入解锁状态的预设时长T3内时,或者开启新的应用的预设时长T3内,或者将某个应用从后台切换至前台运行的预设时长T3内,又或者电子设备运行特定的应用时,电子设备可以增大广播占空比/扫描占空比。这是考虑到,在这些场景中电子设备发现其他电子设备的概率较大,因此增大电子设备的广播占空比和/或扫描占空比,有利于电子设备快速地广播或扫描,加速与其他电子设备发现过程。
当电子设备(例如第一电子设备/第二电子设备)灭屏时,或者某个应用切换后台运行时,电子设备可以减小广播占空比和/或扫描占空比。这是因为,在该场景中,电子设备发现其他电子设备的概率较小,甚至概率为零,因此减小广播占空比和/或扫描 占空比,甚至将广播占空比和/或扫描占空比调至零,有利于降低电子设备的功耗。
在其他场景中,电子设备的广播占空比/扫描占空比可以设置为其他值,例如默认值。
在一个具体实现中,以安卓系统为例,当电子设备的应用层检测到电子设备从灭屏状态进入亮屏状态时,或者从锁屏状态进入解锁状态时,或者开启新的应用(application,APP)时,或者将某个应用从后台切换至前台运行时,又或者电子设备运行特定的应用时,电子设备的应用层可以调用setScanWindowMillis(int scanWindowMillis)的API,设置较大的扫描窗口(相较于默认的扫描窗口,或者扫描窗口的中间值);调用setScanIntervalMillis(int scanIntervalMillis)的API,设置较小的扫描间隔(相较于默认的扫描间隔,或者扫描间隔的中间值),从而增大扫描占空比。还可以调用AdvertisingSetParameters.Builder setInterval(int interval)的API设置较小的广播间隔(相较于默认的广播间隔,或者广播间隔的中间值),相对应的广播窗口较大,从而增大广播占空比。当电子设备的应用层检测到电子设备灭屏时,可以调用setScanWindowMillis(int scanWindowMillis)的API,设置较小的扫描窗口;调用setScanIntervalMillis(int scanIntervalMillis)的API,设置较大的扫描间隔,从而减小扫描占空比。还可以调用AdvertisingSetParameters.Builder setInterval(int interval)的API设置较大的广播间隔,相对应的广播窗口较小,从而减小广播占空比。
在本申请的另一些实施例中,在连接过程中,根据电子设备的状态动态调整占空比(包括扫描占空比、广播占空比等)。当电子设备检测到用户选择连接某个电子设备的预设时长T3时,电子设备可以增大广播占空比/扫描占空比,有利于电子设备快速地广播或扫描,加速与其他电子设备的连接过程。当电子设备与其他电子设备建立连接后,电子设备可以减小广播占空比和/或扫描占空比,降低电子设备的功耗。在一个具体实现中,电子设备可以通过减小寻呼间隔(page interval),增大寻呼窗口(page windows)的方式增大广播占空比。反之,调小广播占空比。通过减小寻呼扫描间隔(page scan interval),增大寻呼扫描窗口(page scan windows)的方式增大扫描占空比。反之,调小扫描占空比。
需要说明的是,上述预设时长T3在不同的电子设备状态时的取值可以相同,也可以不同,本申请实施例对此不做限定。
还需要说明的是,上述实施例是以BLE为例进行说明的,其他的无线连接方式(例如Wi-Fi)也可以采用上述实施例提供的方案动态调整连接间隔的方式调整广播/扫描占空比,不再一一赘述。
(五)电子设备根据芯片能力设置广播参数。
电子设备(如第一电子设备或第二电子设备)具备的蓝牙芯片能力不同时,设置不同的广播参数。例如,如果电子设备的蓝牙芯片支持寻呼扫描(page scan)能力,则具备拼接响应包的能力,那么设置电子设备的广播参数scannable的属性值为true。换言之,电子设备的底层在接收到多个针对发现请求的响应包(例如上述图4中的广播报文B和广播报文C)时,可以进行对多个响应包进行拼接,再将拼接好的数据包上报给上层的应用。
如果电子设备的蓝牙芯片不支持寻呼扫描能力,则不具备拼接响应包的能力,那 么设置电子设备的广播参数scannable的属性值为false。那么,电子设备的底层在接收到多个针对发现请求的响应包(例如上述图4中的广播报文B和广播报文C)时,则不对多个响应包进行拼接,直接将多个响应包上报给上层的应用。如果此时电子设备的scannable的属性值仍然为true,那么此时电子设备仍然会等待拼包处理的时长(例如为20ms),再将多个响应包上报给上层的应用。因此,电子设备的蓝牙芯片不支持寻呼扫描能力时,设置scannable的属性值为false,有利于节省该拼包处理的时长,加速发现过程和连接过程。
在一个具体实现方式中,以安卓系统为例,电子设备(例如第一电子设备或第二电子设备)的应用层可以调用AdvertisingSettingsParameters.Builder setScannable(boolean scannable)的API设置scannable的属性值。例如,如图10中(1)为利用蓝牙抓包工具抓取的一个HCI层的数据包的内容。其中,标记1001示出了该电子设备的广播类型被设置为可扫描。如图10中(2)为利用蓝牙抓包工具抓取的另一个HCI层的数据包的内容。其中,标记1002示出了该电子设备的广播类型被设置为不可扫描。
(六)电子设备根据蓝牙芯片能力设置扫描占空比。
现有技术中,每个业务在使用蓝牙时都会在电子设备的(如第一电子设备或第二电子设备)应用层注册一个L2CAP层的扫描器。换言之,一个业务对应一个扫描器。当L2CAP层注册的扫描器达到一定数量(例如32个)后,新的业务将不能再注册扫描器,那么无法使用该电子设备的蓝牙功能。
在本申请的一些实施例中,电子设备提供预设数量N2个的扫描器,其中每个扫描器对应一个档位的扫描占空比。例如,电子设备提供4个扫描器(即N2=4),分别对应4个档位的扫描占空比,分别为5%、10%、50%以及100%。后续,每个业务根据自身的业务类型、业务特征、业务需求等因素选择其中一个扫描器进行注册。换言之,每个业务选择的扫描器的扫描占空比能够满足该业务的扫描需求。可以注意到,在本申请实施例中,一个扫描器上可以注册多个业务。换言之,本申请实施例通过复用扫描器的方式解决了电子设备仅能注册有限个(例如32个)扫描器的问题。
在本申请的另一些实施例中,电子设备还可以根据蓝牙芯片能力动态调整电子设备提供的各个档位的扫描器。
示例性的,若电子设备配置的双蓝牙芯片,分别为蓝牙芯片A和蓝牙芯片B。并且,电子设备配置了4个档位的扫描器。其中4个档位的扫描器的占空比从低到高的顺序为:档位1<档位2<档位3<档位4。
如果用户偏好是省电模式,则可以在蓝牙芯片A上配置档位1和档位2的扫描器,在蓝牙芯片B上配置档位3和档位4的扫描器。这样,当电子设备处于省电模式下或者电子设备处于灭屏状态时,电子设备的蓝牙芯片A继续工作,蓝牙芯片B则停止工作。此时运行的业务则选择注册档位1或档位2的扫描器。可见,蓝牙芯片A上的扫描占空比均比较低,有利于降低电子设备的整体功耗。
如果用户偏好是高性能模式,则可以在蓝牙芯片A上配置档位1和档位4的扫描器,在蓝牙芯片B上配置档位2和档位3的扫描器。那么,运行的业务自身的业务类型、业务特征、业务需求等因素选择其中一个扫描器进行注册。由于在一个蓝牙芯片上合理配置了高低档位的扫描器,有利于电子设备快速找到对端电子设备,提速发现 过程以及连接过程。
在其他一些实施例中,还可以在蓝牙芯片A和蓝牙芯片B分别配置4个档位的扫描器,即档位1至档位4。这样,当其中一个蓝牙芯片(例如蓝牙芯片A)的能力不足时,可以调用该蓝牙芯片(例如蓝牙芯片A)的应用可以切换到调用另一个蓝牙芯片(例如蓝牙芯片B)。由于两个蓝牙芯片上的扫码器的档位相同,应用切换蓝牙芯片时用户无感知。
再示例性的,若电子设备配置的单个蓝牙芯片,或者,电子设备虽然配置了双蓝牙芯片,但例如负荷较重造成芯片能力不足以提供预设数量N2的扫描器时,可以根据预设规则确定设置特定几个档位的扫描器。例如,电子设备原本配置了4个档位的扫描器,4个档位的扫描器的占空比从低到高的顺序为:档位1<档位2<档位3<档位4。此时,电子设备仅能支持一个或两个扫描器时,可以按照预设规则选择配置一个或两个档位的扫描器。而后,业务则在这一个或两个档位的扫描器上进行注册。
其中,预设规则为:(1)电子设备选择配置档位较高(如选择档位4,或者选择档位4和档位3)的扫描器。这样,当运行的业务注册在档位较高的扫描器上时,电子设备可以满足所有业务的扫描需求。
(2)电子设备选择配置较多业务对应档位的扫描器。例如,电子设备运行的业务有6个业务,其中有1个业务对应档位1,2个业务对应档位2,3个业务对应档位3,1个业务对应档位4。那么,当电子设备的芯片能力不足时,可以选择配置档位3或者选择配置档位3和档位2的扫描器。这样,电子设备能够保证大多数业务不受影响。
(3)电子设备选择配置优先级较高的业务对应档位的扫描器。这样,电子设备能够保证优先级高的业务不受影响。
(4)电子设备选择配置前台运行的业务对应档位的扫描器。这样,电子设备能够保证前台运行的业务不受影响。
(5)如果电子设备配置为省电模式,则选择配置较低档位的扫描器,以保证电子设备的整体功耗较低。
当然,预设规则还可以是其他的规则,本申请实施例对预设规则的内容不做限定。
综上可见,在本申请实施例中,电子设备可以根据蓝牙芯片的可用数量,以及蓝牙芯片的负荷配置不同的扫描占空比,以满足各个场景下各个业务的扫描需求。另外,即使电子设备配置了单个蓝牙芯片,也可以为单个蓝牙芯片配置多个不同扫描占空比,以便各个业务选择合理的扫描占空比。
(七)复用广播通道。
在现有技术中,如果电子设备(例如第一电子设备或第二电子设备)配置的蓝牙芯片支持单路广播通道,那么,当该电子设备的多个业务并发时,在同一个时刻电子设备只能发送一个业务的广播报文,而延迟发送其他业务的广播报文,或者直接丢弃其他业务的广播报文,从而影响了这些业务的发现和连接。如果电子设备配置的蓝牙芯片支持多路广播通道时,那么在同一时刻电子设备上触发广播报文的数量大于当前可用的广播通道的数量时,也存在上述冲突,影响其中部分业务的发现和连接。
在本申请的一些实施例中,电子设备可以合并同一业务的不同任务的广播报文和反向广播报文。例如,用户在第一电子设备上触发了一次图片/文件/视频等的分享功能, 那么第一电子设备发送用于发现周围电子设备的广播报文(例如广播报文A)。当第一电子设备接收到第二电子设备返回的第一个响应包(例如广播报文B)时,第一电子设备发送反向广播报文(例如广播报文F)。如果用户在第一电子设备发送反向广播报文之前,又在第一电子设备上触发了另一次的图片/文件/视频等的分享功能,那么第一电子设备响应于用户的触发操作,再次发送用于发现周围电子设备的广播报文(例如广播报文A)。并且,第一电子设备发送反向广播报文(例如广播报文F)和第二次发现用于发现周围电子设备的广播报文(例如广播报文A)发送冲突。那么,在本申请实施例中,可以将两个广播报文进行合并,然后发送合并后的广播报文。第二电子设备在接收到该合并后的广播报文后,解析可获得两个广播报文的内容(即广播报文F和广播报文A)。由此可见,相较于现有技术,电子设备将两个广播报文进行合并发送,保证了同业务的两个任务的并发,加速了该业务不同任务的发现与连接过程。
在一个具体的实现方式中,如图11所示,为广播报文中数据域中有效净荷(31字节)部分的格式。由于用于发现的广播报文(例如广播报文A)以及反向广播报文(例如广播报文F)中只有四个字段的内容不同,分别为发送端Btype(Sender Btype)、发送端BID(Sender BID)、接收端Btype(Receiver Btype)和接收端BID(Receiver BID)。具体的,用于发现的广播报文(例如广播报文A)中发送端Btype(Sender Btype)和发送端BID(Sender BID)中有内容,而接收端Btype(Receiver Btype)和接收端BID(Receiver BID)的内容为空。反向广播报文(例如广播报文F)中发送端Btype(Sender Btype)和发送端BID(Sender BID)中的内容为空,而接收端Btype(Receiver Btype)和接收端BID(Receiver BID)中有内容。那么,合并这两个广播报文时,可以合并发送端Btype(Sender Btype)、发送端BID(Sender BID)、接收端Btype(Receiver Btype)和接收端BID(Receiver BID)中的内容,即四个字段中都包含有内容。
在本申请的另一些实施例中,如果电子设备配置的蓝牙芯片支持多路广播通道,可以设置预设数量N3个广播通道用于传输广播报文,以节省芯片资源。其中,N3个广播通道可以对应N3个业务类型。后续,当电子设备有业务有待发送的广播报文时,该业务选择自身的业务类型对应广播通道,用于发送广播报文。如果此时有业务类型相同的多个业务需要发送广播报文,则可以复用该业务类型对应的广播报文。即,电子设备的应用层将这多个业务的广播报文进行合并,然后通过该业务类型对应的广播通道发送合并后的广播报文,从而保证及时发送各个业务的广播报文,减少各个业务的等待时间,加速多个业务的发现过程和连接过程。换言之,不同业务类型的业务选择复用业务类型对应的广播通道。
例如,电子设备设置4个广播通道用于传输广播报文,其中这4个广播通道分别对应信令类型、文本类型、文件类型以及视频类型的业务类型。可以理解,这4个业务类型的业务特性不同,在速率、稳定性、持续时间上都有很大的差异,因此为这个业务类型匹配相对应的广播通道。例如,优先提供通信质量最好的广播通道给信令类型的广播报文。如表一所示,为4个业务类型的广播通道的说明。
表一
Figure PCTCN2022088244-appb-000001
Figure PCTCN2022088244-appb-000002
在一个具体的实现方式中,如图11所示,电子设备可以在Sender Btype(或Receiver Btype)中指示广播报文的业务类型。Sender Btype(或Receiver Btype)为1个字节,包含8比特。其中每一比特对应一个业务类型,Sender Btype(或Receiver Btype)一共可以指示8个业务类型。例如,电子设备设置了4个业务类型,分别为信令类型、文本类型、文件类型以及视频类型。那么,Sender Btype(或Receiver Btype)中从最低位开始的4比特依次用于指示信令类型、文本类型、文件类型和视频类型。电子设备还可以在Sender BID(或Receiver BID)指示广播报文的业务标识。Sender BID(或Receiver BID)为2个字节,包含16比特。其中每一比特对应一个业务标识,Sender BID(或Receiver BID)一共可以指示16个不同的业务标识。换言之,本申请实施例可以实现最多16个业务的广播报文合并成一个广播报文。电子设备的应用层在上述Sender Btype、Sender BID、Receiver Btype和Receiver BID指示业务类型以及多个业务的业务标识后,再合并多个业务的可选的TLV(Optional TLV)字段的内容。
在本申请的又一些实施例中,如果电子设备配置的蓝牙芯片支持单路广播通道,或者,虽然电子设备配置的蓝牙芯片支持多路广播通道,但芯片能力不足以提供预设数量N3个广播通道用于传输广播报文。那么,可以合并其中部分的业务类型。换言之,多个业务类型复用一个广播通道,那么在Sender Btype(或Receiver Btype)中可以指示两个或两个以上的业务类型。换言之,两个或两个以上的业务类型的业务也可以合并在一条广播报文中。其他合并的过程参考上文相关内容的描述,这里不再赘述。
如图12所示,为本申请实施例提供的一种复用广播通道的方法流程图,该流程包括:
S1201、业务应用生成待发送的广播报文。
S1202、确定业务应用是否指定该广播报文的业务类型。如果业务应用指定该广播报文的业务类型,则执行步骤S1203。如果业务应用未指定该广播报文的业务类型,则执行步骤S1210。
S1203、确定该指定的业务类型对应的广播通道是否已使用。如果已使用,则执行步骤S1204。如果未使用,则执行步骤S1205。
S1204、更新该业务类型对应的广播通道待发送的广播报文,通过该广播通道发送更新后的广播报文。
也就是说,将当前业务应用请求发送的广播报文,和该广播通道待发送的广播报文进行合并。例如,在Sender BID(或Receiver BID)中增加指示本次业务应用对应的业务标识,在Optional TLV中增加本次业务应用请求的广播报文中相应的内容。
本流程结束。
S1205、确定是否有待分配的广播通道。如有,执行步骤S1206。如没有,执行步骤S1207。
即,确定该电子设备配置的蓝牙芯片支持的广播通道数量是否全部占用。如果全部占用,则没有待分配的广播通道,如果未全部占用,则还有待分配的广播通道。
S1206、开启有新的广播通道,用于发送该业务应用请求发送的广播报文。
并且,该广播通道后续用于传输本次业务应用指定的业务类型。
本流程结束。
S1207、确定是否有其他业务对应的广播通道正在使用。若有,则执行步骤S1208。若没有,则执行步骤S1209。
S1208、更新某个其他业务类型对应的广播通道的待发送广播报文。
也就是说,复用其他业务类型对应的广播通道发送当前业务应用请求发送的广播报文。即,将当前业务应用请求发送的广播报文和某个其他业务类型对应的广播通道待发送的广播报文进行合并。例如,在Sender Btype(或Receiver Btype)中增加指示本次业务应用指定的业务类型,在Sender BID(或Receiver BID)中增加指示本次业务应用对应的业务标识,在Optional TLV中增加本次业务应用请求的广播报文中相应的内容。
本流程结束。
S1209、确定没有可用的广播通道。
也就是说,延迟发送当前业务应用请求发送的广播报文,或者不发送当前业务应用请求发送的广播报文。
本流程结束。
S1210、确定是否有已使用的广播通道。如有,执行步骤S1211。如没有,执行步骤S1212。
S1211、从已使用的广播通道中选择一路复用。即,更新该选择的广播通道的待发送广播报文,并发送更新后的广播报文。
本流程结束。
S1212、开启一路新的广播通道,用于传输当前业务应用请求发送的广播报文。
本流程结束。
需要说明的是,图12仅为本申请实施例提供的一种方法流程的示例,在其他一些实施例中部分步骤可以省略,或者部分步骤可以合并,或者部分步骤的顺序可以交换。
(八)根据电子设备的状态触发电子设备的扫描/广播过程。
在现有技术中,很多电子设备是在上电或开机后就启动扫描/广播过程,例如,一些瘦设备(例如空调、智能灯、智能手表、耳机等)在上电或开机后就广播自身的设备信息,以便其他电子设备能够发现自己并连接自己。或者,有些电子设备在开启蓝牙功能后就启动扫描/广播过程,例如,手机在开启蓝牙功能后,就开始扫描,以便发现其他电子设备,连接到其他电子设备。由此可见,电子设备在上电后或开机后或开启蓝牙功能后就开始扫描/广播过程,耗电极大。
在本申请的一些实施例中,可以设置电子设备由业务触发扫描/广播过程。也就是说,电子设备在开启蓝牙功能或上电后或开机后,不进行广播/扫描。当电子设备检测启动相应的业务功能时,才进行广播/扫描。例如,手机/平板/智能电视等在开启蓝牙功能后,不进行扫描。当检测到用户触发图片/文件/视频等的分享功能的操作,或者,检测到用户触发投屏功能的操作,或者,检测到用户触发发现功能的操作时,手机/平板/智能电视等开始扫描。又例如,空调、智能灯、智能手表、耳机等在上电或开机后,不进行广播。当空调、智能灯、智能手表、耳机等检测到用户执行特定操作(如点击特定控件、按压特定按键、输入特定语音等)后,空调、智能灯、智能手表、耳机等开始广播。
在本申请的另一些实施例中,当电子设备处于灭屏状态时,电子设备不进行扫描。或者,当电子设备处于灭屏状态时,降低电子设备的扫描占空比。又或者,在电子设备处于灭屏状态时,允许预设应用(例如智能家居应用等)进行扫描,非预设应用的其他应用(例如图库应用等)不允许进行扫描。又或者,在电子设备处于灭屏状态时,允许预设业务(例如广播报文中携带预设的serviceData或UUID或其他字段)进行扫描,非预设业务的其他业务不允许进行扫描。又或者,在电子设备处于灭屏状态时,在接收到预设广播类型的广播报文(例如广播类型为connectable的广播报文)后,才进行扫描。接收到其他广播类型的广播报文时,不进行扫描。又或者,在电子设备处于灭屏状态时,电子设备仅接收发送给自己的广播报文,并对该广播报文进行解析。又或者,在电子设备处于灭屏状态时,电子设备仅接收指定厂商ID的广播报文时,才进行扫描。如此,可避免接收周围其他的广播报文被频繁唤醒的情况,达到节省功耗的作用。
在本申请的又一些实施例中,当电子设备处于灭屏状态时,电子设备在回复时,回复单向的广播报文(即广播报文中包含目的电子设备的地址),以避免其他不相关的电子设备被唤醒,达到节省功耗的作用。类似的,在组网场景中,电子设备之间定时更新发现的电子设备时,也采用多播的方式发送报文,减少其他不相关的电子设备被唤醒。可选的,如果电子设备不想被唤醒,也可以采用多播的方式告知其他电子设备。那么,其他电子设备可以在群组广播列表中将给该电子设备设置为不活跃状态。后续其他电子设备再发送多播报文时,不再向该不活跃状态的电子设备发送报文。总而言之,电子设备尽量缩小接收到报文的电子设备的范围,尽量避免其他不相关的电子设备因接收到广播报文被频繁唤醒,节省功耗。又或者,处于不活跃状态的电子设 备可以在接收到n个广播报文后,回复m个广播报文,其中,m、n为正整数,且m<n。处于不活跃状态的电子设备减少发送。
在本申请的又一些实施例中,当电子设备启动了发现功能,电子设备显示了扫描到的周围的电子设备的列表,但用户在预设时长T4内一直未选择的电子设备或者未操作连接控件,电子设备终止本次的发现任务,进行功耗兜底。例如,用户在第一电子设备上点击图片/文件/视频等的分享功能,第一电子设备执行发现流程(例如,如图4中的流程)。在第一电子设备显示扫描到的电子设备(例如包括第二电子设备)后,用户一直未选择待连接的电子设备。换言之,从用户在第一电子设备上点击图片/文件/视频等的分享功能后的预设时长T4(例如10分钟)内,第一电子设备未接收到用户选择连接的电子设备后,第一电子设备终止本次的连接任务。
(九)根据电子设备的业务场景、电子设备的芯片能力确定发现的电子设备的显示顺序。
当发现的电子设备较多时,可以根据电子设备的业务场景确定发现的电子设备的显示顺序。这是因为,电子设备可以根据电子设备的业务场景确定用户意图,确定出用户的目标电子设备,然后在发现的电子设备列表中优先显示目标电子设备的标识,便于用户能够快速选择目标电子设备,从而加速连接过程,提升用户体验。
在本申请的一些实施例中,触发发现周围电子设备功能入口是图库应用/文件管理器/视频播放器等,目标电子设备通常富设备,例如,PC、手机、电视、平板等。例如,用户在电子设备的图库应用中触发分享图片的功能,则电子设备在显示发现的电子设备时,优先显示支持P2P传输协议的电子设备的标识,例如PC、手机、电视、平板等的标识。又例如,用户在电子设备的视频播放器中触发投屏功能,则电子设备在显示发现的电子设备时,优先显示具有大屏的电子设备,例如PC、电视等的标识。
在本申请的另一些实施例中,触发发现周围电子设备功能入口是智慧生活应用等时,用户意图通常是对某个或某几个电子设备发送命令控制,则电子设备在显示发现的电子设备时,优先显示已在智慧生活应用中注册的设备,例如空调、智能灯、电视等。
在本申请的又一些实施例中,电子设备还可以借助自身其他的能力,确定用户的意图。例如,电子设备配置有超宽带(Ultra Wide Band,UWB)芯片时,电子设备可以测到电子设备当前的指向,以及自身与被发现的电子设备的距离等。那么,电子设备在显示发现的电子设备时,可以优先显示电子设备当前指向的被发现的电子设备。或者,优先显示距离电子设备较近的被发现的电子设备。又例如,电子设备配置有NAN芯片或蓝牙芯片或Wi-Fi芯片时,电子设备可以测到与被发现的电子设备的距离,那么,电子设备在显示发现的电子设备时,优先显示距离电子设备较近的被发现的电子设备。
其中,电子设备指向某个被发现的电子设备,是指将该电子设备的载体坐标系中特定的坐标轴对准某个电子设备。以电子设备是手机为例。基于大部分用户使用手机的习惯,可定义手机朝向(或者手机指向)为:平行于手机的长边,且沿手机的尾部指向顶部的方向。因此,可以将手机的朝向称为手机的顶部朝向。通常情况下,手机的顶部为安装有前置摄像头、红外发射器、听筒、光传感器、或者距离传感器等硬件 的机身部分。手机的尾部为安装有麦克风和扬声器的机身部分。
在本申请的又一些实施例中,一般在电子设备能在1秒内发现周围的电子设备,故在1s内发现的电子设备可以按照接收的信号强度指示(Received Signal Strength Indication,RSSI)进行排序。RSSI越大,表示信号越强,越有利于加快传输速率。
当然,电子设备还可以将上述几种显示策略进行组合。例如,可以按照下述的优先级组合上述显示策略:(1)1s内发现的电子设备按照如下的优先级进行排序:优先显示电子设备当前指向的被发现的电子设备;然后显示距离电子设备位于一定距离范围内的发现的电子设备;再按照用户触发发现周围电子设备功能的入口的显示策略进行排序;再按照RSSI的数值大小进行排序。(2)1s后发现电子设备按照发现的时间顺序进行排序,且排列在1s内发现的电子设备之后。
(十)复用连接通道。
如图13所示,为现有技术中多个业务复用连接通道的方法流程图,该流程包括:
S1301、第一电子设备发起业务1。
结合图3所示的蓝牙协议栈,第一电子设备的BLE应用层的应用程序接收到用户触发业务1(例如为文件分享)的操作,应用程序向底层发起业务1的请求,并通过底层向第二电子设备发起业务1的请求,
S1302、第一电子设备的GATT客户端1(简称为客户端1)与第二电子设备的GATT服务端(简称为服务端)连接成功。
BLE主机层接收到应用程序发起的业务1的请求,创建GATT客户端1,并与第二电子设备创建的GATT服务端(简称为服务端)连接成功。图中以步骤S1302a和步骤S1302b示出。
S1303、服务发现成功。
客户端1可能给提供多个服务,第一电子设备从客户端1提供的服务中查找业务1对应的服务。
需要说明的是,第一电子设备和第二电子设备执行发现过程,具体的发现流程可参考图4所示流程,这里不再赘述。图13简化了该发现过程。当服务发现成功后,第一电子设备显示发现的电子设备(包括第二电子设备)。用户在第一电子设备上选择连接第二电子设备,第一电子设备和第二电子设备建立连接。
S1304、第一电子设备设置最大传输单元(maximum transmission unit,MTU)为32字节。
也就是说,业务1的数据包(也称为分享数据包)最大为32字节。
S1305、第一电子设备建立一个套接字(socket)。
S1306a第一电子设备自动生成序列号,向第二电子设备发送分享数据包。
S1306b、第二电子设备自动生成序列包,向第一电子设备回复相应的分享数据包。
S1307、第一电子设备发起业务2。
在第一电子设备和第二电子设备传输业务1的数据包的过程中,用户在第一电子设备上还触发了业务2。其他内容参见步骤S1301中相关内容。
S1308、第一电子设备的GATT客户端2(简称为客户端2)与第二电子设备的GATT服务端(简称为服务端)连接成功。
BLE主机层接收到应用程序发起的业务2的请求,创建GATT客户端2,并与第二电子设备创建的GATT服务端(简称为服务端)连接成功。图中以步骤S1308a和步骤S1308b示出。
S1309、服务发现成功。
客户端2可能给提供多个服务,第一电子设备从客户端2提供的服务中查找业务2对应的服务。
S1310、第一电子设备设置最大传输单元(maximum transmission unit,MTU)为512字节。
也就是说,业务2的数据包(也称为为投屏数据包)最大为512字节。
S1311、第一电子设备建立第二个套接字。
业务1和业务2的数据包大小不同,即MTU不同,需另外建立一个套接字,用于传输业务2的数据包。
S1312、第一电子设备向第二电子设备发送分享数据包(32字节)。
S1313、第二电子设备向第一电子设备发送投屏数据包(512字节)。
S1314、第二电子设备使用最新设置的MTU(512字节)向第一电子设备的客户端1回复了分享数据包。
由于第二电子设备仅能通过第一电子设备的MAC地址来区分数据包的发送方,无法区分数据包是来自第一电子设备的哪个客户端。换言之,对于第二电子设备的服务端来说,第一电子设备的客户端的标识为第一电子设备的MAC地址。由于第一电子设备的客户端1和客户端2对应的是相同的第一电子设备的MAC地址,故第二电子设备的服务端无法区分第一电子设备的客户端1和客户端2。因此,第二电子设备向第一电子设备回复数据包时,会存在发错客户端的问题。例如,将业务2的数据包回复给客户端1,将业务1的数据包回复给客户端2。
另外,第二电子设备服务端的MTU仅有一个。换言之,第二电子设备与第一电子设备新协商好的MTU会覆盖之前协商好的MTU。这里,业务2过程协商的512字节将覆盖业务1过程协商的32字节。换言之,后续第二电子设备向第一电子设备回复的数据包为不大于512字节,因此第二电子设备服务端向第一电子设备客户端1回复数据包时常常出错。
S1315、第一电子设备的客户端1接收第二电子设备回复的分享数据包(512字节),数据接收异常。
由于第一电子设备的客户端1只能接收不小大于32字节的数据包,那么当接收到第二电子设备服务端回复的512字节的分享数据包,接收数据出现异常。
综上可见,现有技术中多业务复用连接通道的过程中常出现错误,复用成功率不高。
为此,本申请实施例提供一种多业务复用连接通道的方法,电子设备设置一个通用的MTU,即多个业务都可使用的MTU,并针对该通用的MTU可设置一个套接字。这样,当触发多个业务时,直接复用该通用的MTU,以及相应的套接字即可。这样,既有利于避免服务端发错客户端的问题,还可以节省多次设置MTU,以及创建多个套接字的时间,有利于加速连接过程。
另外,在一个连接通道上发送多个业务的数据包时,发送的数据包携带业务标识、序列号。可选的,数据包还可以携带包头标记、优先级标记等。在一个示例中,电子设备的应用层在向下发送数据包时,可以在数据包的包头中携带业务标识、序列号、包头标记、以及优先级标记等。
其中,由于多个业务复用同一个套接字,因此电子设备接收到数据包后,可以根据其中的业务标识向相应的业务返回数据包。可见,本申请实施例保证了多个业务复用连接通道时也不会出现业务错乱的情况。
其中,序列号(seq),用于确定各个数据包的时序。例如,各个业务对应一个队列,每个队列中,发送端发送的数据包的序列号奇数递增,接收端发送的数据包的序列号偶数递增。
其中,包头标记,用于标记该数据包是否为包头。如果为包头,该包头标记置第一值,例如置1,如果为非包头,该包头标记置第二值,例如置0。接收端电子设备可以根据包头标记对多个数据包进行拼接。
其中,优先级标记,用于标记同一业务中不同重要程度的数据包,例如,控制信令类的数据包的优先级最高,高优先级的业务包,低优先级的业务包等。换言之,当连接通道的负荷较重时,可以根据优先级标记优先发送优先级高的数据包,保证高效地数据传输。
如图14所示,为本申请实施例提供的一种多个业务复用连接通道的方法流程图,该流程包括:
S1401、第一电子设备发起业务1。
结合图3所示的蓝牙协议栈,第一电子设备的BLE应用层的应用程序接收到用户触发业务1(例如为文件分享)的操作,应用程序向底层发起业务1的请求,并通过底层向第二电子设备发送业务1的请求,
S1402a、第一电子设备的GATT客户端(简称为客户端)第二电子设备创建的GATT服务端(简称为服务端)连接成功。
BLE主机层接收到应用程序发起的业务1的请求,创建GATT客户端,并与第二电子设备创建的GATT服务端(简称为服务端)连接成功。图中以步骤S1402a和步骤S1402b示出。
S1403、服务发现成功。
客户端可能给提供多个服务,第一电子设备从客户端提供的服务中查找业务1对应的服务。
需要说明的是,第一电子设备和第二电子设备执行发现过程,具体的发现流程可参考图4所示流程,这里不再赘述。图14简化了该发现过程。当服务发现成功后,第一电子设备显示发现的电子设备(包括第二电子设备)。用户在第一电子设备上选择连接第二电子设备,第一电子设备和第二电子设备建立连接。
S1404、第一电子设备设置MTU,例如设置为512字节。
也就是说,业务1的数据包最大为512字节。需要说明的是,由于本申请实施例的多个业务均使用一个通用的MTU,故考虑多个业务设置合适的MTU数值。
S1405、第一电子设备建立一个套接字。
S1406、第一电子设备发送数据包。
其中,该数据包中携带序列号、业务标识、包头标记以及优先级标记。例如,序列号为1、业务标识为1(对应业务1的标识)、包头标记为1(表示该数据包为包头的数据包)、优先级标记为1。
S1407、第二电子设备接收到第一电子设备发送的数据包,并同步记录序列号和业务标识。
也就是说,第二电子设备根据业务标识和序列号,实时检测该业务的数据包是否发生丢包。如果发现出现丢包,可以向对端请求相应的业务标识和序列号的数据包。可见,本申请实施例提供的方法还解决了丢包的问题,保证业务的数据包的正确传输。
S1408、第二电子设备向第一电子设备回复数据包。
其中,该数据包中携带序列号和业务标识。例如,序列号为2、业务标识为1(对应业务1的标识)。
S1409、第一电子设备接收到第二电子设备发送的数据包,并同步记录序列号和业务标识。
也就是说,第一电子设备根据业务标识和序列号,实时检测该业务的数据包是否发生丢包。如果发现出现丢包,可以向对端请求相应的业务标识和序列号的数据包。可见,本申请实施例提供的方法还解决了丢包的问题,保证业务的数据包的正确传输。
S1410、第一电子设备发送数据包。
其中,该数据包中携带序列号、业务标识、包头标记以及优先级标记。例如,序列号为3、业务标识为1(对应业务1的标识)、包头标记为0(表示该数据包为非包头的数据包)、优先级标记为1。
S1411、第二电子设备接收到第一电子设备发送的数据包,并同步记录序列号和业务标识。
S1412、第二电子设备向第一电子设备回复数据包。
其中,该数据包中携带序列号和业务标识。例如,序列号为4、业务标识为1(对应业务1的标识)。
S1413、第一电子设备接收到第二电子设备发送的数据包,并同步记录序列号和业务标识。
S1414、第一电子设备发起业务2。
在第一电子设备和第二电子设备传输业务1的数据包的过程中,用户在第一电子设备上还触发了业务2。其他内容参见步骤S1401中相关内容。
S1415、第一电子设备确定已有连接,则直接复用已有的套接字。
可见,此时第一电子设备无需再次设置MTU,也无需创建新的套接字,加速了业务2的连接过程。
S1416、第一电子设备发送数据包。
其中,该数据包中携带序列号、业务标识、包头标记以及优先级标记。例如,序列号为1、业务标识为2(对应业务2的标识)、包头标记为1(表示该数据包为包头的数据包)、优先级标记为1。
S1417、第二电子设备接收到第一电子设备发送的数据包,并同步记录序列号和业 务标识。
S1418、第二电子设备向第一电子设备回复数据包。
其中,该数据包中携带序列号和业务标识。例如,序列号为2、业务标识为2(对应业务1的标识)。
S1419、第一电子设备接收到第二电子设备发送的数据包,并同步记录序列号和业务标识。
由此可见,第二电子设备或第一电子设备可以根据数据包携带的业务标识区分该数据包为哪个业务的数据包,另外可以根据序列号确定各个业务中数据包的时序。从而保证多个业务复用同一连接通道时也不会出现错误。
需要说明的是,上述流程是以同一电子设备发起多个业务为例说明复用连接通道的过程的。在其他一些示例中,不同电子设备触发的多个业务也可以复用同一个连接通道。在一些实施例中,为避免对端的两个电子设备同时发起连接,造成连接冲突进而连接失败的情况发生。在第一电子设备确定发起业务1(即在图14中步骤S1401)之前或之后,或者,在第一电子设备建立连接通道(如执行图14中步骤S1405)之前或之后,第一电子设备向第二电子设备发送广播报文,用于告知第二电子设备,第一电子设备已发起连接请求。那么,第二电子设备在预设时长T5内不再发起连接请求。如果用户在该预设时长T5内通过第二电子设备发起连接请求,则第二电子设备不响应该连接请求,或者延迟响应该连接请求。可选的,第二电子设备也可以提示用户,其他电子设备正在连接第二电子设备。可选的,在其他一些实施例中,在第一电子设备建立连接通道(如执行图14中步骤S1405)之后,第一电子设备通过已建立的套接字(即已建立的连接通道)向第二电子设备发送报文,用于告知第二电子设备,第一电子设备已发起连接请求。总之,本申请实施例不限定第一电子设备告知第二电子设备的方式和时机。
还需要说明的是,如果电子设备配置单个蓝牙芯片,则该单个蓝牙芯片可以建立一个连接通道,在该连接通道上可以实现多业务复用该连接通道。在其他一些示例中,电子设备配置有多个蓝牙芯片(例如两个蓝牙芯片),则在每个蓝牙芯片上可以建立一个连接通道,在该连接通道也可以采用上述方法实现多业务复用一个连接通道。以电子设备配置两个蓝牙芯片为例,电子设备可以在每个蓝牙芯片上建立一个连接通道,即共建立两个连接通道。那么当电子设备触发高优先级的业务时,可以选择其中通信质量好的连接通道。当电子设备触发低优先级的业务时,可以选择其中通信质量较差的连接通道。或者,根据电子设备上触发业务请求的时间顺序,奇数请求选择其中一个连接通道,偶数请求选择另一个连接通道。又或者,根据业务的类型进行划分,控制信令类的请求选择其中通信质量好的连接通道,传输耗时的业务包的请求选择其中通信质量较差的另一个连接通道。又或者,根据发起方进行划分,本端发起的业务请求,选择其中一个连接通道,对端发起的业务请求选择另一个连接通道。这样,可以避免在同一个蓝牙芯片上两侧的电子设备同时发起建立连接通道的请求,造成连接失败的问题。又或者,为两个蓝牙芯片上分别建立的连接通道设置不同的MTU,后续根据业务的MTU选择相应的连接通道。这样,能够解决单个蓝牙芯片需要切换MTU时,需要断开连接通道并重新建立连接通道造成连接耗时的问题。
另外,图14仅为本申请实施例提供的一种方法流程的示例,在其他一些实施例中部分步骤可以省略,或者部分步骤可以合并,或者部分步骤的顺序可以交换。
还需要说明的是,上述实施例是以BLE连接为例进行说明的,在其他的无线连接方式(例Wi-Fi)也使用本申请实施例提供的技术方案。例如,在Wi-Fi连接中,同类型的协议可以复用同一个套接字,并且复用同一套接字的多个业务的数据包可以采用上述实施例提供的数据包格式。即,数据包携带业务标识、序列号。可选的,数据包还可以携带包头标记、优先级标记等。例如,Wi-Fi采用的协议例如传输控制协议(transmission control protocol,TCP)、用户数据报协议(user datagram protocol、UDP)、视频数据报协议(video datagram protocol、VDP)等。采用TCP的多个业务复用一个套接字,即复用一个连接。采用UDP的多个业务复用一个套接字,即复用一个连接。采用VDP的多个业务复用一个套接字,即复用一个连接。在Wi-Fi场景中,图14中的步骤S1402(包括S1402a、S1402b)至S1404可以省略。
另外,针对电子设备配置有多个Wi-Fi芯片,也可以在单个Wi-Fi芯片建立一个连接通道,使用同一协议的多个业务可以复用一个连接通道。其他内容请参见关于蓝牙芯片的描述,不再重复赘述。
(十一)电子设备的标识的加密处理
目前使用BR MAC地址、BLE MAC地址或唯一设备识别符(unique device identifier,UDID)等作为电子设备的标识。由于BR MAC地址、BLE MAC地址或UDID的格式和内容较为固定,容易被攻击,易被伪基站仿冒,存在安全性问题。在本申请实施例中,可以采用预设加密算法的公钥对电子设备的标识(例如电子设备的序列号(serial number,SN)、国际移动设备识别码(international mobile equipment identity,IMEI)、MAC地址等)进行取哈希值,以哈希值中的部分字节作为电子设备的唯一标识。即,在发现和连接等过程中,携带的电子设备的标识为哈希值中的部分字节。其中,预设加密算法例如可以是RSA3072、HmacSHA256等加密算法。例如,可以取公钥和公钥的前16字节作为参数,对电子设备的SN计算哈希值(hash code),取计算得到的哈希值的前20字节作为该电子设备的唯一标识。由于哈希值不易识别以及不易被反解析,因此使用哈希值作为电子设备的唯一标识,提升了电子设备发现过程以及连接过程中的安全问题。
在本申请的另一些实施例中,用户可以通过例如重启电子设备的方式,重新计算得到电子设备的唯一标识,即重新使用公钥对电子设备的标识(例如SN、IMEI、MAC地址等)计算哈希值,使用哈希值中的部分字节作为新的电子设备的唯一标识。可见,用户可以控制重新生成电子设备的唯一标识,换言之电子设备的唯一标识可以变化,进一步加大被攻击的难度,进一步提升电子设备发现过程以及连接过程中的安全问题。
在本申请的又一些实施例中,在电子设备连接过程中,还可以对发现的电子设备的标识进行校验,而且保证连接的电子设备与发现时的电子设备是同一个电子设备,保证电子设备的连接安全。
如图15所示,为本申请实施例提供的一种对发现过程中的电子设备的标识进行验证的方法流程图,该流程包括:
S1501、第一电子设备发送广播报文A,用于发现周围的电子设备。
S1502、第二电子设备接收到广播报文A后,发送广播报文B。
其中,广播报文B中携带电子设备的名称、账号名、设备类型等信息。
S1503、第一电子设备缓存广播报文B。
S1504、第二电子设备在发送广播报文B的时长T1后,发送广播报文C。
其中,广播报文C中携带采用本实施例提供的方法生成的电子设备的标识。例如,根据预设加密算法的公钥对电子设备的标识(例如SN、IMEI、MAC地址等)进行取哈希值,以哈希值中的部分字节作为电子设备的唯一标识。
S1505、第一电子设备根据广播报文B和广播报文C确定发现第二电子设备。
其中,步骤S1501-步骤S1505为第一电子设备与第二电子设备发现流程,具体内容可参考图4中的相关内容的描述,这里不再赘述。
S1506、第一电子设备与第二电子设备建立BLE连接。
S1507、第一电子设备通过建立的BLE连接向第二电子设备发起计数器模式密码块链信息认证码协议(counter mode with cipher-block chaining message authentication code protocol,CCMP)连接请求。
示例性的,第一电子设备请求第二电子设备的信息,例如第二电子设备支持的CCMP版本号、摘要、是否支持加密校验等。
S1508、第二电子设备向第一电子设备回复响应。
示例性的,响应中携带第二电子设备支持的CCMP版本号、摘要、是否支持加密校验等。
S1509、第一电子设备向第二电子设备发送第一电子设备的CCMP版本号。
如果第二电子设备支持的版本号大于或等于CCMP 4.0,则执行步骤S1509。第二电子设备支持的版本号等于CCMP 4.0,则按照相应的逻辑建立CCMP连接。
S1510、第二电子设备协商公共的CCMP版本号。
第二电子设备根据接收到的第一电子设备支持的CCMP版本号,以及自身支持的CCMP版本号,协商两个电子设备共同使用的CCMP版本号。
S1511、第二电子设备向第一电子设备回复支持的CCMP版本号,即第二电子设备协商的公共的CCMP版本号。
S1512、第一电子设备协商公共的CCMP版本号。
S1513、第一电子设备向第二电子设备发送第一电子设备的公钥A。
S1514、第二电子设备向第一电子设备回复第二电子设备的公钥B。
S1515、第一电子设备根据公钥B校验发现流程中接收到的电子设备的标识,已确定此时连接的第二电子设备是否和发现流程中发现的电子设备是同一个电子设备。
S1516、当校验通过后,第一电子设备生成随机数,并用公钥B加密随机数,即生成AES Key,并向第二电子设备发送该AES Key。
S1517、第二电子设备接收到第一电子设备发送的AES Key,进行解密得到随机数。然后,用公钥A加密随机数,即生成回复给第一电子设备的AES Key。
S1518、第二电子设备向第一电子设备AES Key。
S1519、第一电子设备解密AES Key得到随机数。然后,第一电子设备确定解密得到的随机数是否与自己发送的随机数相同。
如果相同,则验证通过,第一电子设备和第二电子设备建立CCMP连接,而后可以进行通信。
需要说明的是,图15仅为本申请实施例提供的一种方法流程的示例,在其他一些实施例,例如采用不同的协议时,上述流程中部分步骤可以省略,或者部分步骤可以合并,或者部分步骤的顺序可以交换。
(十二)连接重试
请参考图14,第一电子设备和第二电子设备建立连接的过程包括3个阶段:阶段1、第一电子设备GATT客户端与第二电子设备GATT服务端的连接阶段。阶段2、服务发现阶段。阶段3、设置MTU阶段。在现有技术中,阶段1至阶段3任一个阶段出现异常时,第一电子设备都将确认连接失败。如果希望再次进行连接,则用户需要重新在第一电子设备触发连接操作,那么第一电子设备和第二电子设备再次执行一遍建立连接过程(包括3个阶段)。其中,再次执行一遍建立连接过程一般耗时10s。
在本申请的一些实施例中,在第一电子设备和第二电子设备建立连接的过程中,针对阶段1的连接异常的情况,第一电子设备和第二电子设备自动重试,重试次数不超过预设次数1(例如3次),并且,第一电子设备处于阶段1的总时长控制在预设时长(例如4s)内。针对阶段2出现异常的情况,第一电子设备和第二电子设备自动重试,重试次数不超过预设次数2(例如1次),并且,第一电子设备处于阶段2的总时长控制在预设时长(例如4s)内。这是因为:阶段1中第一电子设备GATT客户端与第二电子设备GATT服务端的连接超时,以及阶段2发现异常是可能通过重试进行恢复的,而阶段3是不可以恢复的。换言之,本申请实施例提供的技术方案通过对阶段1和阶段2的可恢复的异常进行重试,提升在本次连接的成功率。并且,通过控制第一电子设备处于阶段1和阶段2的总时长,从而使得重试的方法相较于用户重新触发连接的方法,节省连接时间,以加速连接过程。
在本申请的另一些实施例中,在第一电子设备向第二电子设备发送发现请求报文(例如图4中的广播报文A)时,可以在发现请求报文中携带的服务标识。例如,第一电子设备可以通过AdvertiseData.Builder的addServiceUuid(ParcelUuid serviceUuid)的API在请求报文中添加服务标识。相应的,第二电子设备可以通过getServiceUuid()的API从广播的发现请求报文中解析出业务标识。换言之,在发现过程中第一电子设备就可以向第二电子设备请求该服务标识对应的服务。那么,在连接过程中,在第一电子设备GATT客户端与第二电子设备GATT服务端的建立连接后(即执行阶段1后),直接设置MTU阶段(即执行阶段3)。换言之,在阶段1时第一电子设备和第二电子设备已实现服务发现成功,即本次连接过程中无需执行阶段2,由此加速了连接过程。
(十三)发现过程中确定下线的电子设备。
在本申请的一些实施例中,第一电子设备在发现第二电子设备后,如果在发现后的预设时长T7(例如4s)内未接收到第二电子设备发送的广播报文时,将确定第二电子设备下线,即在发现的电子设备的列表中不再显示第二电子设备的标识。例如,第一电子设备在发现过程中,记录接收到的广播报文的发送方的标识,以及时间戳。其中时间戳为当前时间与接收时间的差值。如果检测到第二电子设备发送的广播报文的 时间戳大于预设时长T7(例如4s),则第一电子设备确定第二电子设备下线,即在发现的电子设备的列表中不再显示第二电子设备的标识。又例如,第一电子设备在接收到第二电子设备发送的广播报文后,启动预设时长T7的定时器。在定时器未达到预设时长T7内,再次接收到第二电子设备发送的广播报文,则定时器清零,重新开始计时。在定时器达到预设时长T7,则认为第一电子设备在预设时长T7一直未接收到第二电子设备广播报文,确定第二电子设备下线,即在发现的电子设备的列表中不再显示第二电子设备的标识。
如此,避免当第二电子设备不满足连接条件时,仍然出现在发现列表中,误导用户选择连接的电子设备。
可选的,如果用户在第一电子设备上具体的业务上触发发现周围电子设备的,则第一电子设备还可以根据接收到的广播报文的发送方的标识以及业务标识确定被发现的电子设备是否下线。例如,用户在第一电子设备的图库应用中触发分享图片的功能,则第一电子设备记录接收到的广播报文的发送方的标识,业务标识(例如分享图片业务的标识)以及时间戳。其中时间戳为当前时间与接收时间的差值。如果检测到第二电子设备发送的,且业务标识为分享图片业务的标识的广播报文的时间戳大于预设时长T7(例如4s),则确定第二电子设备下线,即在发现的电子设备的列表中不再显示第二电子设备的标识。又例如,第一电子设备在接收到第二电子设备发送的,且携带分享图片业务的标识的广播报文后,启动预设时长T7的定时器。在定时器未达到预设时长T7内,再次接收到第二电子设备发送的,且携带分享图片业务的标识的广播报文,则定时器清零,重新开始计时。在定时器达到预设时长T7,则认为第一电子设备在预设时长T7一直未接收到第二电子设备发送的,且携带分享图片业务的标识的广播报文,确定第二电子设备下线,即在发现的电子设备的列表中不再显示第二电子设备的标识。
如此,避免当第二电子设备不满足连接条件时,仍然出现在发现列表中,误导用户选择连接的电子设备。
在本申请的又一些实施例中,第一电子设备还可以为不同设备类型的电子设备设置不同的预设时长T7。例如,被发现的电子设备是PC时,预设时长T7设置为6s;被发现的电子设备是手机时,预设时长T7设置为4s。这是考虑到不同设备类型的电子设备的广播占空比不同,有利于提高下线的准确性。
在本申请的又一些实施例中,第一电子设备还可以为是否为首次发现的电子设备设置不同的预设时长T7。例如,首次被发现的电子设备对应的预设时长T7为18s,非首次发现的电子设备对应的预设时长T7设置为6s或4s。
还需要说明的是,上述各个实施例提供的技术方案可以独立使用,也可以在方案不矛盾的前提下进行任意的组合。
本申请实施例还提供一种芯片系统,如图16所示,该芯片系统包括至少一个处理器1601和至少一个接口电路1602。处理器1601和接口电路1602可通过线路互联。例如,接口电路1602可用于从其它装置(例如存储器)接收信号。又例如,接口电路1602可用于向其它装置(例如处理器)发送信号。示例性的,接口电路1602可读取存储器中存储的指令,并将该指令发送给处理器1601。当所述指令被处理器1601执行时,可使得电子设备执行上述实施例中的第一电子设备或第二电子设备执行的各个 步骤。当然,该芯片系统还可以包含其他分立器件,本申请实施例对此不作具体限定。
本申请实施例还提供一种装置,该装置包含在电子设备(第一电子设备或第二电子设备)中,该装置具有实现上述实施例中任一方法中电子设备(第一电子设备或第二电子设备)行为的功能。该功能可以通过硬件实现,也可以通过硬件执行相应的软件实现。硬件或软件包括至少一个与上述功能相对应的模块或单元。例如,发送模块或单元、接收模块或单元、处理模块或单元、以及存储模块或单元等。
本申请实施例还提供一种计算机存储介质,包括计算机指令,当计算机指令在电子设备(第一电子设备或第二电子设备)上运行时,使得电子设备(第一电子设备或第二电子设备)执行如上述实施例中任一方法。
本申请实施例还提供一种计算机程序产品,当计算机程序产品在计算机上运行时,使得计算机执行如上述实施例中任一方法。
可以理解的是,上述第一电子设备或第二电子设备等为了实现上述功能,其包含了执行各个功能相应的硬件结构和/或软件模块。本领域技术人员应该很容易意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,本申请实施例能够以硬件或硬件和计算机软件的结合形式来实现。某个功能究竟以硬件还是计算机软件驱动硬件的方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本发明实施例的范围。
本申请实施例可以根据上述方法示例对上述第一电子设备或第二电子设备等进行功能模块的划分,例如,可以对应各个功能划分各个功能模块,也可以将两个或两个以上的功能集成在一个处理模块中。上述集成的模块既可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。需要说明的是,本发明实施例中对模块的划分是示意性的,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式。
通过以上的实施方式的描述,所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。上述描述的系统,装置和单元的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。
在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
所述集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实施例的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可以是个人计算机,服务器,或者网络设备等)或处理器执行本申请各个实施例所述方法的全部或部分步骤。而前述的存储介质包括:快闪存储器、移动硬盘、只读存储器、随机存取存储器、磁碟或者光盘等各种可以存储程序代码的介质。
以上所述,仅为本申请的具体实施方式,但本申请的保护范围并不局限于此,任何在本申请揭露的技术范围内的变化或替换,都应涵盖在本申请的保护范围之内。因此,本申请的保护范围应以所述权利要求的保护范围为准。

Claims (23)

  1. 一种无线发现的通信系统,其特征在于,包括第一电子设备和第二电子设备,
    所述第一电子设备,用于发送第一广播报文,所述第一广播报文用于发现所述第一电子设备周围的电子设备;
    所述第二电子设备,用于响应于接收到所述第一广播报文,发送第二广播报文,所述第二广播报文包括所述第二电子设备的第一信息,其中所述第一信息包括设备标识、设备名称、登录账号、设备类型和业务标识中的一项或多项;
    所述第一电子设备,用于存储所述第二电子设备的所述第一信息;
    所述第二电子设备,还用于在所述第二电子设备发送所述第二广播报文后的第一时长后,发送第三广播报文,所述第三广播报文包括所述第二电子设备的第二信息,其中所述第二信息包括所述设备标识、所述登录账号、所述设备类型、设备能力和所述业务标识中的一项或多项,且所述第二信息和所述第一信息至少部分内容不同;
    所述第一电子设备,还用于根据所述第二电子设备的所述第一信息和所述第二信息,确定发现所述第二电子设备。
  2. 根据权利要求1所述的通信系统,其特征在于,
    所述第一电子设备,还用于存储所述第二电子设备的所述第二信息;
    所述第一电子设备,还用于发送第四广播报文,所述第四广播报文用于发现所述第一电子设备周围的电子设备;
    所述第二电子设备,还用于响应于接收到所述第四广播报文,发送第五广播报文,所述第五广播报文包括所述第二电子设备的所述第一信息;
    所述第二电子设备,还用于根据所述第五广播报文中的所述第二电子设备的所述第一信息和存储的所述第二电子设备的所述第二信息,确定发现所述第二电子设备。
  3. 根据权利要求1或2所述的通信系统,其特征在于,
    所述第一电子设备,还用于发送第六广播报文,所述第六广播报文用于提示所述第二电子设备交替发送所述第二电子设备的所述第一信息和所述第二电子设备的所述第二信息。
  4. 一种无线发现的方法,其特征在于,应用于第二电子设备,所述方法包括:
    接收第一电子设备发送的第一广播报文,所述第一广播报文用于发现所述第一电子设备周围的电子设备;
    发送第二广播报文,所述第二广播报文包括所述第二电子设备的第一信息,其中所述第一信息包括设备标识、设备名称、登录账号、设备类型和业务标识中的一项或多项;
    在所述第二电子设备发送所述第二广播报文后的第一时长后,发送第三广播报文,所述第三广播报文包括所述第二电子设备的第二信息,其中所述第二信息包括所述设备标识、所述登录账号、所述设备类型、设备能力和所述业务标识中的一项或多项,且所述第二信息和所述第一信息至少部分内容不同;其中,所述第二电子设备的所述第一信息和所述第二信息,用于所述第一电子设备确定发现所述第二电子设备。
  5. 一种无线发现的方法,其特征在于,应用于第一电子设备,所述方法包括:
    发送第一广播报文,所述第一广播报文用于发现所述第一电子设备周围的电子设 备;
    接收第二电子设备发送的第二广播报文,所述第二广播报文包括所述第二电子设备的第一信息,其中所述第一信息包括设备标识、设备名称、登录账号、设备类型和业务标识中的一项或多项;
    根据所述第二电子设备的所述第一信息查找所述第二电子设备的第二信息;其中所述第二信息包括所述设备标识、所述登录账号、所述设备类型、设备能力和所述业务标识中的一项或多项,且所述第二信息和所述第一信息至少部分内容不同;
    根据所述第二电子设备的所述第一信息,以及查找到的所述第二信息,确定发现所述第二电子设备。
  6. 根据权利要求5所述的方法,其特征在于,所述方法还包括:
    所述第一电子设备发送第三广播报文,所述第三广播报文用于提示所述第二电子设备交替发送所述第二电子设备的所述第一信息和所述第二电子设备的所述第二信息。
  7. 一种无线发现及连接方法,其特征在于,所述方法包括:
    第一电子设备获取所述第一电子设备的信息,所述第一电子设备的信息包括所述第一电子设备的业务场景、所述第一电子设备的状态、以及所述第一电子设备配置的无线通信芯片能力中一项或多项;
    所述第一电子设备根据所述第一电子设备的信息调整所述第一电子设备的广播参数;其中所述广播参数包括广播类型、扫描占空比、广播占空比、广播通道数中一项或多项;
    所述第一电子设备根据所述第一电子设备的信息调整所述第一电子设备的连接参数,所述连接参数包括连接间隔和/或连接通道数。
  8. 根据权利要求7所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备的业务场景调整所述第一电子设备的广播参数,包括:
    在所述第一电子设备发送发现广播报文之前,设置所述第一电子设备的广播类型设置为不可连接;
    在所述第一电子设备在接收到任一电子设备针对发现广播报文回复的任一报文之后,设置所述第一电子设备的广播类型设置为可连接。
  9. 根据权利要求7或8所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备的状态调整所述第一电子设备的广播参数,还包括:
    当所述第一电子设备的状态满足预设条件时,所述第一电子设备增大扫描占空比和/或广播占空比:
    其中,所述预设条件为以下条件中的任一项或任几项:所述第一电子从灭屏状态进入亮屏状态的第一预设时长内;所述第一电子设备从锁屏状态进入解锁状态的第二预设时长内;所述第一电子设备启动第一应用后的第三预设时长内;所述第一电子设备将第二应用从后台运行切换至前台运行的第四预设时长内;所述第一电子设备运行预设应用。
  10. 根据权利要求7-9任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备的状态调整所述第一电子设备的广播参数,还包括:
    在所述第一电子设备上电或开机或启动无线通信功能之后,且在检测到所述第一 电子设备启动预设业务之前,所述第一电子设备的广播过程或扫描过程处于未启动状态。
  11. 根据权利要求7-10任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备配置的无线通信芯片能力调整所述第一电子设备的广播参数,包括:
    根据所述第一电子设备配置的无线通信芯片是否支持寻呼扫描能力,设置所述第一电子设备的广播类型是否为可扫描。
  12. 根据权利要求7-11任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备配置的无线通信芯片能力调整所述第一电子设备的广播参数,包括:
    所述第一电子设备根据所述第一电子设备配置的无线通信芯片能力,调整所述第一电子设备的扫描器的数量,其中每个扫描器对应一个扫描占空比。
  13. 根据权利要求7-12任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备配置的无线通信芯片能力调整所述第一电子设备的广播参数,包括:
    如果所述第一电子设备配置的无线通信芯片能力支持多路广播通道,则所述第一电子设备设置预设数量N3个广播通道,其中每个广播通道对应一个业务类型,其中每个业务类型对应多个业务。
  14. 根据权利要求7-13任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备配置的无线通信芯片能力调整所述第一电子设备的广播参数,还包括:
    如果所述第一电子设备配置的无线通信芯片能力不支持多路广播通道,则所述第一电子设备的多个业务类型复用一个广播通道。
  15. 根据权利要求7-14任一项所述的方法,其特征在于,所述方法还包括:
    所述第一电子设备根据所述第一电子设备的业务场景和/或所述第一电子设备配置的芯片能力确定发现的电子设备的显示顺序。
  16. 根据权利要求7-15任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备的业务场景调整所述第一电子设备的连接参数,包括:
    所述第一电子设备根据缓存的发现包的大小调整所述第一电子设备的连接间隔,其中,所述发现包用于发现周围的电子设备。
  17. 根据权利要求7-16任一项所述的方法,其特征在于,所述第一电子设备根据所述第一电子设备配置的无线通信芯片能力调整所述第一电子设备的连接参数,包括:
    所述第一电子设备根据所述第一电子设备配置的无线通信芯片的数量,在每个无线通信芯片上分别建立一个连接通道;所述第一电子设备的至少两个业务复用至少一个连接通道。
  18. 根据权利要求17所述的方法,其特征在于,在所述第一电子设备的至少两个业务复用一个连接通道的过程中,所述一个连接通道传输的数据包包括业务标识和序列号。
  19. 根据权利要求18所述的方法,其特征在于,所述一个连接通道传输的数据包还包括包头标记和/或优先级标记。
  20. 根据权利要求16-19任一项所述的方法,其特征在于,在所述第一电子设备建立连接通道之前,所述第一电子设备广播的发现请求中携带服务标识。
  21. 根据权利要求16-20任一项所述的方法,其特征在于,在所述第一电子设备确定与第二电子设备建立连接通道之前或之后,所述第一电子设备向所述第二电子设备发送第一消息,所述第一消息用于通知所述第二电子设备不向所述第一电子设备发送连接请求。
  22. 一种电子设备,其特征在于,包括:处理器、存储器和无线通信模块,所述存储器、所述无线通信模块与所述处理器耦合,所述存储器用于存储计算机程序代码,所述计算机程序代码包括计算机指令,当所述处理器从所述存储器中读取所述计算机指令,以使得所述电子设备执行如权利要求4-21任一项所述的方法。
  23. 一种计算机可读存储介质,其特征在于,包括计算机指令,当所述计算机指令在电子设备上运行时,使得所述电子设备执行如权利要求4-21任一项所述的方法。
PCT/CN2022/088244 2021-05-14 2022-04-21 一种无线连接的方法以及电子设备 WO2022237493A1 (zh)

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN202110528395.2 2021-05-14
CN202110528395 2021-05-14
CN202110827479.6 2021-07-21
CN202110827479.6A CN115348568A (zh) 2021-05-14 2021-07-21 一种无线连接的方法以及电子设备

Publications (1)

Publication Number Publication Date
WO2022237493A1 true WO2022237493A1 (zh) 2022-11-17

Family

ID=81125430

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/088244 WO2022237493A1 (zh) 2021-05-14 2022-04-21 一种无线连接的方法以及电子设备

Country Status (2)

Country Link
CN (1) CN114363871B (zh)
WO (1) WO2022237493A1 (zh)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107615713A (zh) * 2015-09-16 2018-01-19 广东欧珀移动通信有限公司 调整通信参数的方法和设备
CN110891298A (zh) * 2019-12-18 2020-03-17 惠州拓邦电气技术有限公司 一种蓝牙连接方法、装置、蓝牙设备及系统
CN111246550A (zh) * 2020-01-07 2020-06-05 维沃移动通信有限公司 电子设备状态调整方法以及电子设备
CN111436038A (zh) * 2019-10-23 2020-07-21 珠海市杰理科技股份有限公司 蓝牙连接方法及系统、蓝牙主、从设备连接方法及蓝牙主、从设备
CN111436039A (zh) * 2019-10-23 2020-07-21 珠海市杰理科技股份有限公司 蓝牙回连方法及系统、蓝牙主、从设备回连方法及蓝牙主、从设备
JP2020145756A (ja) * 2020-06-04 2020-09-10 オッポ広東移動通信有限公司Guangdong Oppo Mobile Telecommunications Corp., Ltd. 通信パラメータ調整方法及び装置
CN109618393B (zh) * 2019-02-01 2021-03-02 Oppo广东移动通信有限公司 通信控制方法、装置、移动终端及存储介质

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112449328B (zh) * 2019-08-30 2023-08-22 华为技术有限公司 一种蓝牙搜索方法、系统及相关装置

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN107615713A (zh) * 2015-09-16 2018-01-19 广东欧珀移动通信有限公司 调整通信参数的方法和设备
CN109618393B (zh) * 2019-02-01 2021-03-02 Oppo广东移动通信有限公司 通信控制方法、装置、移动终端及存储介质
CN111436038A (zh) * 2019-10-23 2020-07-21 珠海市杰理科技股份有限公司 蓝牙连接方法及系统、蓝牙主、从设备连接方法及蓝牙主、从设备
CN111436039A (zh) * 2019-10-23 2020-07-21 珠海市杰理科技股份有限公司 蓝牙回连方法及系统、蓝牙主、从设备回连方法及蓝牙主、从设备
CN110891298A (zh) * 2019-12-18 2020-03-17 惠州拓邦电气技术有限公司 一种蓝牙连接方法、装置、蓝牙设备及系统
CN111246550A (zh) * 2020-01-07 2020-06-05 维沃移动通信有限公司 电子设备状态调整方法以及电子设备
JP2020145756A (ja) * 2020-06-04 2020-09-10 オッポ広東移動通信有限公司Guangdong Oppo Mobile Telecommunications Corp., Ltd. 通信パラメータ調整方法及び装置

Also Published As

Publication number Publication date
CN114363871A (zh) 2022-04-15
CN114363871B (zh) 2023-03-03

Similar Documents

Publication Publication Date Title
US10917920B2 (en) Method and apparatus for connecting alternative communication means using bluetooth low energy (LE)
US10693969B2 (en) Electronic device using logical channels for communication
US10827334B2 (en) Method and apparatus for connecting devices using Bluetooth LE technology
US10034160B2 (en) Method and apparatus for transmitting or receiving data using bluetooth in wireless communication system
US10349253B2 (en) Method for transmitting and receiving data, and device therefor
JP6374526B2 (ja) 無線通信システムにおけるデータ送信率調節方法及び装置
US9544718B2 (en) Method and apparatus for transmitting and receiving audio stream in wireless communication system
US9930240B2 (en) Method and apparatus for controlling a camera by using Bluetooth communication in a wireless communication system
US10932313B2 (en) Wireless connection switching method and terminal
US10142767B2 (en) Method and apparatus for transmitting data using Bluetooth low energy in wireless communication system
US20170054787A1 (en) Method and apparatus for performing object transfer service using bluetooth low energy in wireless communication system
US20230345221A1 (en) Method for transmitting data in near field, device, and system
US10194477B2 (en) Method and apparatus for controlling a device using bluetooth technology
US20240049116A1 (en) Method for transmitting and receiving data and device for same in short-range wireless communication system
US10299104B2 (en) Method for performing discovery in wireless communication system and device therefor
KR102398992B1 (ko) 통신 장치, 통신 방법, 및 기억 매체에 저장된 프로그램
WO2022237493A1 (zh) 一种无线连接的方法以及电子设备
US11882533B2 (en) Method for transmitting audio data using short-range wireless communication in wireless communication system, and apparatus therefor
US20230103916A1 (en) Audio data reception method using short-range wireless communication in wireless communication system, and apparatus therefor
CN115348568A (zh) 一种无线连接的方法以及电子设备
WO2024088173A1 (zh) 组播通信方法及相关装置
WO2023284862A1 (zh) 一种无线信道资源的管理方法、设备以及系统
JP2009253621A (ja) 無線通信端末およびデバイス起動方法
KR20170056807A (ko) 무선 통신 시스템에서 데이터를 송수신하기 위한 방법 및 장치

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22806463

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 22806463

Country of ref document: EP

Kind code of ref document: A1