A method, device, apparatus and medium for connecting an external Bluetooth device

CN122534693APending Publication Date: 2026-08-07TIANYI TELECOM TERMINALS
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
TIANYI TELECOM TERMINALS
Filing Date
2026-05-18
Publication Date
2026-08-07

AI Technical Summary

Benefits of technology

[0022]在本申请实施例中,通过扫描目标外接蓝牙设备的外轮廓的信息,进而确定该目标外接蓝牙设备的设备类型;随后向该目标外接蓝牙设备发送定向探测请求,并接收该目标外接蓝牙设备的响应信息;若该响应信息为满足要求的标准响应信息,则加载预设的该设备类型对应的连接指令;当该目标外接蓝牙设备被用户使用,即接收到该目标外接蓝牙设备的请求连接信号时,终端设备会采用目标信道将该连接指令发送给该目标外接蓝牙设备,从而实现了自动连接外接蓝牙设备的功能,避免了依赖人工操作才能实现终端设备和外接蓝牙设备的连接,提高了用户的无感体验。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122534693A_ABST
    Figure CN122534693A_ABST
Patent Text Reader

Abstract

The embodiment of the application discloses a kind of external bluetooth device connection method, device, equipment and medium, by scanning the information of the outer contour of target external bluetooth device, and then determine the device type of the target external bluetooth device;Subsequently, directional probe request is sent to the target external bluetooth device, and the response information of the target external bluetooth device is received;If the response information is the standard response information that meets the requirement, then load the connection instruction corresponding to the device type of the preset;When the target external bluetooth device is used by user, i.e. when receiving the request connection signal of the target external bluetooth device, terminal equipment will use target channel to send the connection instruction to the target external bluetooth device, so as to realize the function of automatically connecting external bluetooth device, avoid relying on manual operation to realize the connection of terminal equipment and external bluetooth device, improve the user's no-sense experience.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of wireless communication technology, and in particular to a method, apparatus, device and medium for connecting an external Bluetooth device. Background Technology

[0002] Bluetooth (BT) connectivity is an open, global standard for wireless data communication. Based on low-cost, short-range wireless connectivity, it establishes a unique wireless connection for communication between devices. After a successful connection is established between a terminal device and an external Bluetooth device, the external Bluetooth device can perform corresponding functions. The terminal device refers to the end-user device that directly faces the user and connects to a communication network or computer system, such as a mobile phone, personal computer, or tablet computer; its core function is to provide user interaction or data processing capabilities. An external Bluetooth device refers to a Bluetooth device used to extend the functionality of the terminal device, such as a printer, keyboard, or mouse; it is essentially an external auxiliary tool.

[0003] Currently, establishing a connection between a terminal device and an external Bluetooth device usually requires manual intervention from the user. For example, if there are multiple external Bluetooth devices near the terminal device that need to be connected, the terminal device will pop up multiple pairing requests. The user then has to manually click on the pairing request corresponding to the external Bluetooth device that needs to be connected before the connection between the terminal device and the external Bluetooth device can be established.

[0004] Therefore, existing technologies rely on manual operation to connect terminal devices and external Bluetooth devices, which cannot meet the core requirement of automatic connection. There is an urgent need for an automatic connection method for external Bluetooth devices. Summary of the Invention

[0005] This application provides a method, apparatus, device, and medium for connecting external Bluetooth devices, enabling automatic connection of external Bluetooth devices and improving the user's seamless experience.

[0006] In a first aspect, embodiments of this application provide a method for connecting an external Bluetooth device, the method comprising: The device type of the target external Bluetooth device is determined based on the information of the outer contour of the scanned target external Bluetooth device; Based on the straight-line distance between the target external Bluetooth device and the terminal device, determine the theoretical received signal strength indication value of the signal received from the target external Bluetooth device at the straight-line distance; Based on the received signal strength indication value contained in each received broadcast packet, determine the received signal strength indication value that deviates the least from the theoretical received signal strength indication value, and use the Bluetooth media access control address in the broadcast packet containing the received signal strength indication value as the Bluetooth media access control address corresponding to the target external Bluetooth device. Send a directional probe request to the Bluetooth Media Access Control address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, then load the connection instruction corresponding to the preset device type; If a connection request signal is received from the target external Bluetooth device, the connection command is sent to the target external Bluetooth device using the target channel.

[0007] In one possible implementation, the process of determining the target external Bluetooth device includes: Transmit a probe signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of sending and receiving each return signal; and determine the attitude angle of each external Bluetooth device. When the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

[0008] In one possible implementation, the method further includes: If the response information is non-standard, it is structured and segmented based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments. Each fragment is transformed into a corresponding vector using the bag-of-words model. For each type of fragment, the basic fragment with the highest similarity to the fragment is determined based on the similarity between the vector corresponding to the fragment of that type and the vector corresponding to the basic fragment of the same type in the preset protocol library. Based on the device type, and based on the relevant instruction fragments of each type of the device type stored in the preset protocol library, the initial necessary instruction fragments with corresponding weight values ​​greater than the preset third threshold are selected to obtain the initial necessary instruction fragment set. Based on the pre-saved list of necessary instruction fragments required to establish a connection with the device of the aforementioned device type, determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set; Based on the most similar basic fragment and the initial necessary instruction fragment, a connection instruction for connecting to the device type is generated according to a preset protocol logic order.

[0009] In one possible implementation, before generating connection instructions for connecting to the device type based on the most similar basic fragment and the initial necessary instruction fragment, according to a preset protocol logic order, the method further includes: Determine whether the types of fragments contained in the initial necessary instruction fragment set include all the instruction types required to establish a connection with a device of that device type; if so, generate connection instructions for connecting with the device of that device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, following a preset protocol logic order. If not, determine the missing type, and based on the missing type and the standard instruction fragments corresponding to each type that are pre-saved, determine the target standard instruction fragment corresponding to the missing type; add the target standard instruction fragment to the initial necessary instruction fragment set, and generate a connection instruction for connecting to the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, in a preset protocol logic order.

[0010] In one possible implementation, the process of determining the target channel includes: Based on the device type of the target external Bluetooth device and a preset device type and channel mapping table, determine the dedicated channel corresponding to the target external Bluetooth device; and determine whether the dedicated channel is occupied. If so, then determine the target channel with the highest signal-to-noise ratio and the least interference; Otherwise, the dedicated channel is determined to be the target channel.

[0011] In one possible implementation, after receiving the connection request signal from the target external Bluetooth device and before sending the connection command to the target external Bluetooth device using the target channel, the method further includes: Based on the device type of the target external Bluetooth device, obtain the instruction fragments and corresponding weight values ​​of the device type stored in the preset protocol library. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, then execute the subsequent operation of sending the connection command to the target external Bluetooth device using the target channel.

[0012] In one possible implementation, the method further includes: Based on the semantic boundaries of the Bluetooth protocol, the connection command is structurally segmented into multiple command fragments. For each command fragment, a target command fragment identical to the one in a preset protocol library is identified, and the old weight value of the target command fragment is determined. If the connection is successful, the updated weight corresponding to the target command fragment is determined to be an increase of a first preset value on the basis of the old weight value. If the connection fails, the updated weight corresponding to the target command fragment is determined to be a decrease of a second preset value on the basis of the old weight value, wherein both the first and second preset values ​​are positive numbers.

[0013] Secondly, embodiments of this application provide an apparatus for connecting an external Bluetooth device, the apparatus comprising: The determination module is used to determine the device type of the target external Bluetooth device based on the information of the outer contour of the scanned target external Bluetooth device; The processing module is configured to: determine the theoretical received signal strength indication (RSS) value of the target external Bluetooth device receiving the signal at the straight-line distance between the target external Bluetooth device and the terminal device; determine the RSS value with the smallest deviation from the theoretical RSS value based on the RSS value contained in each received broadcast packet; use the Bluetooth Media Access Control (MAC) address in the broadcast packet containing the RSS value as the Bluetooth MAC address corresponding to the target external Bluetooth device; send a directional probe request to the Bluetooth MAC address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, load a preset connection command corresponding to the device type; if a connection request signal is received from the target external Bluetooth device, send the connection command to the target external Bluetooth device using the target channel.

[0014] In one possible implementation, the processing module is specifically configured to transmit a detection signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of sending and receiving each return signal; and determine the attitude angle of each external Bluetooth device; when the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

[0015] In one possible implementation, the processing module is further configured to: if the response information is non-standard response information, structurally segment the response information based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments; convert each fragment into a corresponding vector using a bag-of-words model; for each type of fragment, determine the basic fragment with the highest similarity to the fragment based on the similarity between the vector corresponding to the fragment of that type and the vector corresponding to the basic fragment of the same type in a preset protocol library; according to the device type, filter the initial necessary instruction fragments with corresponding weight values ​​greater than a preset third threshold according to the relevant instruction fragments of each type of the device type stored in the preset protocol library to obtain an initial necessary instruction fragment set; determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set according to the instruction types of the necessary instruction fragments required to establish a connection with the device of the device type stored in a preset protocol library; and generate a connection instruction for connecting with the device of the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragments, following a preset protocol logic order.

[0016] In one possible implementation, the processing module is further configured to determine whether the types of fragments included in the initial necessary instruction fragment set contain all the instruction types required to establish a connection with a device of that device type; if yes, then based on the base fragment with the highest similarity and the initial necessary instruction fragment, a connection instruction for connecting with the device of that device type is generated according to a preset protocol logic order; if no, then a missing type is determined, and based on the missing type and the standard instruction fragments corresponding to each type that are pre-saved, a target standard instruction fragment corresponding to the missing type is determined; the target standard instruction fragment is added to the initial necessary instruction fragment set, and based on the base fragment with the highest similarity and the initial necessary instruction fragment, a connection instruction for connecting with the device of that device type is generated according to a preset protocol logic order.

[0017] In one possible implementation, the processing module is specifically configured to determine the dedicated channel corresponding to the target external Bluetooth device based on the device type of the target external Bluetooth device and a preset device type and channel mapping table; and determine whether the dedicated channel is occupied; if so, determine the target channel with the highest signal-to-noise ratio and the least interference; otherwise, determine the dedicated channel as the target channel.

[0018] In one possible implementation, the processing module is further configured to obtain instruction fragments and corresponding weight values ​​of the device type stored in a preset protocol library according to the device type of the target external Bluetooth device. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, the subsequent operation of sending the connection instruction to the target external Bluetooth device using the target channel is executed.

[0019] In one possible implementation, the processing module is further configured to structurally segment the connection command based on the semantic boundaries of the Bluetooth protocol to obtain multiple command fragments; for each command fragment, to determine a target command fragment in a preset protocol library that is identical to the command fragment, and to determine the old weight value of the target command fragment; if the connection is successful, to determine that the updated weight corresponding to the target command fragment is an increase of a first preset value on the basis of the old weight value; if the connection fails, to determine that the updated weight corresponding to the target command fragment is a decrease of a second preset value on the basis of the old weight value, wherein both the first preset value and the second preset value are positive numbers.

[0020] Thirdly, embodiments of this application also provide an electronic device, the electronic device including a processor, the processor being configured to execute a computer program stored in a memory to implement the steps of any of the methods described above.

[0021] Fourthly, embodiments of this application also provide a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of any of the methods described above.

[0022] In this embodiment, the device type of the target external Bluetooth device is determined by scanning the outer contour information of the target external Bluetooth device. A directional probe request is then sent to the target external Bluetooth device, and a response is received from the target external Bluetooth device. If the response is a standard response that meets the requirements, a preset connection command corresponding to the device type is loaded. When the target external Bluetooth device is used by the user, i.e., when a connection request signal is received from the target external Bluetooth device, the terminal device sends the connection command to the target external Bluetooth device using the target channel. This achieves the function of automatically connecting to the external Bluetooth device, avoiding the need for manual operation to connect the terminal device and the external Bluetooth device, and improving the user's seamless experience. Attached Figure Description

[0023] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0024] Figure 1 This is a schematic diagram illustrating a method for connecting an external Bluetooth device according to an embodiment of this application. Figure 2A schematic diagram illustrating the process of processing non-standard response information and generating connection instructions, provided in an embodiment of this application; Figure 3 This application provides a detailed example diagram of channel allocation using an external Bluetooth device as a keyboard. Figure 4 This is a simplified example diagram illustrating channel allocation using an external Bluetooth device as a keyboard, as provided in this application. Figure 5 A simplified flowchart of a method for connecting an external Bluetooth device provided in this application; Figure 6 A simplified flowchart for constructing and optimizing a protocol library is provided for this application; Figure 7 A simplified flowchart for determining the connection command of an external Bluetooth device provided in this application; Figure 8 This application provides a schematic diagram of a device structure for connecting an external Bluetooth device. Figure 9 This is a schematic diagram of an electronic device structure provided in an embodiment of this application. Detailed Implementation

[0025] To make the objectives and implementation methods of this application clearer, the exemplary implementation methods of this application will be clearly and completely described below with reference to the accompanying drawings of the exemplary embodiments of this application. Obviously, the exemplary embodiments described are only some embodiments of this application, and not all embodiments.

[0026] It should be noted that the brief descriptions of terms in this application are only for the convenience of understanding the embodiments described below, and are not intended to limit the embodiments of this application. Unless otherwise stated, these terms should be understood in their ordinary and common meaning.

[0027] The terms "first," "second," "third," etc., used in the specification, claims, and accompanying drawings of this application are used to distinguish similar or related objects or entities, and do not necessarily imply a specific order or sequence, unless otherwise specified. It should be understood that such terms are interchangeable where appropriate.

[0028] The terms “comprising” and “having”, and any variations thereof, are intended to cover but not exclude inclusion, for example, a product or device that includes a range of components is not necessarily limited to all of the components that are clearly listed, but may include other components that are not clearly listed or that are inherent to such product or device.

[0029] The term "module" refers to any known or subsequently developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code that is capable of performing the functions associated with that element.

[0030] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features therein. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of this application.

[0031] For ease of explanation, the above description has been provided in conjunction with specific embodiments. However, the above exemplary discussion is not intended to be exhaustive or to limit the embodiments to the specific forms disclosed above. Various modifications and variations can be obtained based on the above teachings. The selection and description of the above embodiments are for the purpose of better explaining the principles and practical applications, thereby enabling those skilled in the art to better utilize the described embodiments and various different variations of embodiments suitable for specific use considerations.

[0032] Example 1: Figure 1 This application provides a schematic diagram of a method for connecting an external Bluetooth device, which includes the following steps: S101: Determine the device type of the target external Bluetooth device based on the information of the outer contour of the scanned target external Bluetooth device.

[0033] The external Bluetooth device connection method provided in this application embodiment is applied to a terminal device, which may be a smartphone, personal computer, tablet computer, computer, etc.

[0034] The target external Bluetooth device refers to the external Bluetooth device to be connected, which is a Bluetooth device used to extend the functionality of the terminal device, such as a printer, keyboard, mouse, etc. It is essentially an external auxiliary tool.

[0035] The information about the outer contour of the target external Bluetooth device refers to the geometric feature data corresponding to the outer contour of the target external Bluetooth device, such as the coordinates of each point, the shape of the target external Bluetooth device, or the size of the target external Bluetooth device. Device type refers to the device classification determined by the information about the outer contour of the external Bluetooth device.

[0036] In this application, the terminal device uses a scanning device in real time to scan the outer contour of a target external Bluetooth device in a preset direction, thereby acquiring information about the outer contour of the target external Bluetooth device. The preset direction can be a scan centered on the terminal device in all directions, or it can be a fixed preset direction. The scanning device can be an optical camera, laser scanning radar, or infrared sensor, etc., and can be integrated into the terminal device, such as a smartphone or computer, or it can communicate with the terminal device as a standalone device.

[0037] After obtaining the outline information of the target external Bluetooth device, the terminal device matches this outline information with the outline information corresponding to each type in a preset device type database to determine the device type of the target external Bluetooth device. This device type database stores information on the standard outlines of various external Bluetooth devices and their corresponding device types, such as printers and their corresponding standard outlines, scanners and their corresponding standard outlines, keyboards and their corresponding standard outlines, mice and their corresponding standard outlines, etc.

[0038] The matching process can be implemented using image recognition algorithms or machine learning models. For example, if the information of the outer contour consists of the coordinates of various points on the outer contour, then the length, width, and height values ​​of the target external Bluetooth device are determined based on the information of the target external Bluetooth device's outer contour. Based on these length, width, and height values ​​and the pre-stored standard outer contour information corresponding to each type of external Bluetooth device, the device type of the target external Bluetooth device is determined using an image recognition algorithm. The method of matching the device's outer contour information using image recognition algorithms or machine learning models to determine the device type is existing technology and will not be elaborated upon here.

[0039] If the pairing is successful, the device type of the target external Bluetooth device will be determined; if the pairing fails, the user will be prompted to manually select the device type or end the process.

[0040] S102: Based on the straight-line distance between the target external Bluetooth device and the terminal device, determine the theoretical received signal strength indication value of the target external Bluetooth device that receives the signal at the straight-line distance; based on the received signal strength indication value contained in each received broadcast packet, determine the received signal strength indication value with the smallest deviation from the theoretical received signal strength indication value, and use the Bluetooth Media Access Control (MAC) address in the broadcast packet containing the received signal strength indication value as the MAC address corresponding to the target external Bluetooth device.

[0041] The terminal device is pre-configured with an ultra-wideband (UWB) transmitter, which emits ultrasonic pulse signals in real time and receives return signals from the target external Bluetooth device. Then, based on the time it takes to send and receive the target's return signals, the straight-line distance between the terminal device and the target external Bluetooth device is determined. Based on the straight-line distance between the target external Bluetooth device and the terminal device, a Bluetooth signal propagation attenuation model is used to convert the straight-line distance between the target external Bluetooth device and the terminal device into a theoretical Received Signal Strength Indication (RSSI) value.

[0042] In addition, while determining the straight-line distance between the target external Bluetooth device and the terminal device, the terminal device activates the Bluetooth Low Energy (BLE) function to scan and capture broadcast packets from all surrounding external Bluetooth devices. The broadcast packets are used to extract the Bluetooth MAC address and RSSI value of each external Bluetooth device.

[0043] Based on the RSSI value contained in each received broadcast packet, the RSSI value with the smallest deviation from the theoretical RSSI value is determined. Specifically, for each received broadcast packet, the deviation between the RSSI value contained in the broadcast packet and the theoretical RSSI value is calculated, and the minimum deviation and the corresponding RSSI value are determined. The MAC address in the broadcast packet containing the RSSI value with the minimum deviation is then used as the MAC address of the target external Bluetooth device.

[0044] In one possible implementation, the broadcast packet also includes the device type. After determining the RSSI value with the smallest deviation from the theoretical RSSI value based on the RSSI values ​​contained in each received broadcast packet, if multiple identical RSSI values ​​with the smallest deviation exist simultaneously, the terminal device cannot accurately determine which is the true RSSI value with the smallest deviation. In this case, for each RSSI value with the smallest deviation, the device type carried in the broadcast packet containing the RSSI value with the device type determined in step 101 can be compared. If the comparison matches, the RSSI value with the smallest deviation is determined to be the final target RSSI value, and the subsequent step of using the MAC address in the broadcast packet containing the target RSSI value as the MAC address corresponding to the target external Bluetooth device is performed. If the comparison does not match, the RSSI value with the smallest deviation is determined to be not the final target RSSI value and is discarded.

[0045] S103: Send a directional probe request to the MAC address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, then load the connection instruction corresponding to the preset device type.

[0046] A Probe Request is a Bluetooth standard protocol-compliant request that is transmitted only on Bluetooth Broadcast Channels (BLE: CH37 / CH38 / CH39; Classic Bluetooth: CH32-CH39) and does not require prior data connection establishment. A Probe Response is the response returned by the target external Bluetooth device. A standard Probe Response is a response that meets preset qualification requirements.

[0047] Connection commands are configuration commands used to establish a connection between a terminal device and an external Bluetooth device.

[0048] After determining the MAC address of the target external Bluetooth device, the terminal device sends a targeted probe request to that MAC address. The header of this targeted probe request carries the MAC address of the target external Bluetooth device. Only the target external Bluetooth device will respond to this targeted probe request; other external Bluetooth devices will either discard the request or not respond, thus avoiding power waste and interference caused by over-broadcasting. In addition to the MAC address of the target external Bluetooth device, the targeted probe request also includes specific fields for verifying the identity and compatibility of the target external Bluetooth device. These specific fields can be [Opcode][Manufacturer ID][Device Type]. The opcode is a unique identifier for the instruction; for example, 0xA1 indicates a keyboard key press, and 0xC2 indicates mouse movement. The manufacturer ID is the manufacturer identifier of the external Bluetooth device; for example, 0xFFFF indicates a general instruction, and 0x05AC indicates Apple Inc. The device type is the device category of the external Bluetooth device; for example, XXX indicates a printer, YYY indicates a keyboard, etc.

[0049] After receiving a directional probe request, the target external Bluetooth device generates corresponding response information and returns it to the terminal device. This response information may include a device identifier, opcode, processing pointer, etc. The terminal device receives this response information and parses it.

[0050] The terminal device compares the received response information with preset standard response information. The standard response information is a predefined expected response information for each device type. For example, the predefined expected response information for a keyboard must include specific types of fields, such as [Operation Code], [Manufacturer ID], and [Device Type]. If the specific types of fields contained in the response information match the specific types of fields expected to be contained in the standard response information (e.g., the standard response information expects specific types of fields such as Operation Code, Identifier, Processing Pointer, and Device Type), and the response information also contains these specific types of fields, then the response information is determined to be a standard response information that meets the requirements. At this point, the terminal device loads the preset connection command corresponding to that device type from the storage unit. This connection command establishes a Bluetooth connection between the terminal device and the target external Bluetooth device, and includes configuration parameters and authentication data for establishing the Bluetooth connection. The storage unit can be local storage or a cloud database.

[0051] To ensure a smooth connection with an external Bluetooth device, in one possible implementation, if no response is received from the target external Bluetooth device within a preset timeout period, steps 101 and 102 can be re-executed for verification and re-attempted pairing. If the number of failed pairing attempts exceeds a preset number, the user is prompted to manually select the connection command corresponding to the target external Bluetooth device, ensuring the robustness of the solution.

[0052] S104: If a connection request signal is received from the target external Bluetooth device, the connection instruction is sent to the target external Bluetooth device using the target channel.

[0053] The target channel refers to the specific communication path corresponding to the device type of the external Bluetooth device.

[0054] A connection request signal is triggered when the event detector of a target external Bluetooth device detects that the value of its corresponding sensor has reached a certain threshold. This indicates that the user is using the target external Bluetooth device and a Bluetooth connection with the terminal device needs to be established. Therefore, the target external Bluetooth device directly sends a connection request signal to the terminal device. The event detector is a sensor used to detect signals from sensors such as capacitive sensors / gyroscopes. Table 1 shows the sensor type, trigger threshold, and response action of the event detectors for different device types.

[0055]

[0056] Table 1

[0057] As shown in Table 1 above, if the device type is a keyboard, when the keyboard's capacitance sensor detects a capacitance value greater than 200fF, the keyboard activates channel CH36 and sends a connection request signal to the terminal device at a frequency of 2402MHz. If the device type is a mouse, when the mouse's gyroscope angular velocity is greater than 0.5rad / s, the mouse is assigned channel CH38 and sends a connection request signal to the terminal device at a frequency of 2426MHz with 100Hz polling enabled. If the device type is a printer, when the printer's photoelectric paper tray sensor detects a light intensity change greater than 50lux, the printer activates channel CH40 after a 50ms delay and sends a connection request signal to the terminal device at a frequency of 2480MHz.

[0058] Once the terminal device receives a connection request signal from the target external Bluetooth device, it sends the loaded connection command to the target external Bluetooth device via the target channel. The target channel is a pre-determined communication path based on the device type; for example, a specific keyboard channel corresponding to a keyboard device.

[0059] After sending the connection command, the terminal device establishes a stable connection with the target external Bluetooth device to complete subsequent data exchange or control operations.

[0060] It should be noted that, to further improve the user's seamless experience, this application, when connecting an external Bluetooth device, detects the use of the target external Bluetooth device through its event detector. For example, when the value of the corresponding sensor reaches the corresponding trigger threshold, the target external Bluetooth device directly sends a connection request signal to the terminal device. That is, the external Bluetooth device actively initiates the Bluetooth connection through a hardware interrupt rather than the terminal device polling the external Bluetooth device. Its advantages are as follows: Traditional terminal devices poll external Bluetooth devices by checking for button presses, movement, etc., every X milliseconds. The response latency for connection discovery events fluctuates randomly between 0 and X milliseconds.

[0061] The external Bluetooth device in this application initiates the connection proactively via a hardware interrupt: when the external Bluetooth device makes a button press or movement, it directly "interrupts" the terminal device, and the terminal device responds to the connection event immediately within 5 microseconds. This extremely low latency improves the user's seamless experience. Furthermore, if the terminal device does not respond to the connection event immediately within 5 microseconds, it can also record the connection event in its internal error log and trigger a sensor self-test process, without disturbing the user.

[0062] In this embodiment, the device type of the target external Bluetooth device is determined by scanning the outer contour information of the target external Bluetooth device. A directional probe request is then sent to the target external Bluetooth device, and a response is received from the target external Bluetooth device. If the response is a standard response that meets the requirements, a preset connection command corresponding to the device type is loaded. When the target external Bluetooth device is used by the user, i.e., when a connection request signal is received from the target external Bluetooth device, the terminal device sends the connection command to the target external Bluetooth device using the target channel. This achieves the function of automatically connecting to the external Bluetooth device, avoiding the need for manual operation to connect the terminal device and the external Bluetooth device, and improving the user's seamless experience.

[0063] Example 2: To ensure the accuracy of external Bluetooth device connections, this application also provides a detailed description of how to determine the target external Bluetooth device. The process for determining the target external Bluetooth device includes: Transmit a probe signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of receiving each return signal; and determine the attitude angle of each external Bluetooth device. When the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

[0064] A UWB transmitter is used to transmit a detection signal in real time and receive a return signal from each external Bluetooth device. The detection signal can be an ultrasonic pulse signal. Then, the straight-line distance between the terminal device and each external Bluetooth device is determined based on the time of sending and receiving each return signal.

[0065] In one possible implementation, to ensure the accuracy of the calculation, multiple UWB transmitters are pre-set. For each external Bluetooth device, the terminal device can use a triangulation algorithm to calculate the device space coordinates of the external Bluetooth device relative to the terminal device, based on the pre-calibrated three-dimensional coordinates of each UWB transmitter in the terminal device's coordinate system and the straight-line distance between each UWB transmitter and the external Bluetooth device. Based on these device space coordinates, the coordinates corresponding to the geometric center point of the external Bluetooth device are determined. Then, using the coordinates of the geometric center point and the coordinates of the terminal device's preset geometric center point, the straight-line distance between the terminal device and the external Bluetooth device is calculated using the point-to-point distance calculation formula. The use of a triangulation algorithm to calculate multiple straight-line distances and determine the device space coordinates of the external Bluetooth device relative to the terminal device is existing technology and will not be elaborated further here.

[0066] The terminal device uses a scanning device, such as a 905nm VCSEL laser with a scanning frequency of 10Hz, to scan the outer contour of each external Bluetooth device, acquiring information about the outer contour of each device, i.e., the initial outer contour information, such as the coordinates of each point in the initial outer contour. Optionally, the straight-line distance measured by the UWB transmitter and the initial outer contour information are converted to the same coordinate system, and a 1m×1m×0.5m cubic grid is established with the terminal device as the center. Subsequently, for each external Bluetooth device, a quaternion rotation matrix is ​​used to correct the initial outer contour information of the device, obtaining standardized outer contour information, such as the coordinates of each point in the standardized outer contour. A feature point correspondence is established between the standardized outer contour information and the initial outer contour information using a feature matching algorithm. Based on the feature point correspondence, a singular value decomposition algorithm is used to calculate the relative rigid body transformation matrix between the standardized outer contour information and the initial outer contour information. The rotation component is extracted from the relative rigid body transformation matrix and converted into Euler angles. The obtained Euler angles are output as attitude angles to determine the attitude angles of each external Bluetooth device. The methods used, such as correcting the initial outer contour information of the external Bluetooth device using a quaternion rotation matrix, calculating the relative rigid body transformation matrix between the standardized outer contour information and the initial outer contour information using a singular value decomposition algorithm, extracting rotational components from the relative rigid body transformation matrix, and converting them into Euler angles, are existing technologies and will not be elaborated here.

[0067] When the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold, and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device. The first and second thresholds can be preset by the user according to actual conditions.

[0068] In one possible implementation, for each external Bluetooth device, the standardized outer contour information, the straight-line distance between the terminal device and the external Bluetooth device, and the attitude angle are input to a preset Kalman filter, which outputs the precise device space coordinates of the external Bluetooth device. The preset Kalman filter is an integrated filter pre-configured by maintenance personnel according to specific input and output requirements. It is used to determine the precise device space coordinates of the external Bluetooth device based on the standardized outer contour information, the straight-line distance between the terminal device and the external Bluetooth device, and the attitude angle. Based on the precise device space coordinates of the external Bluetooth device, the precise straight-line distance between the external Bluetooth device and the terminal device is determined. When the precise straight-line distance between the external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is identified as the target external Bluetooth device.

[0069] In one possible implementation, to ensure the accuracy of the identified target external Bluetooth device, this application can also pre-establish a standard outer contour range database. Specifically, for each type of external Bluetooth device, a three-dimensional model library is constructed by scanning samples of different models and angles multiple times. For example, N different keyboard models are collected, and point cloud data of them are scanned in various states, including flat, tilted at 5 degrees relative to the horizontal plane, and tilted at 10 degrees relative to the horizontal plane. Based on all the point cloud data, a spatial range that can encompass the vast majority of data points is fitted using a three-dimensional convex hull or Gaussian mixture model. This range is the "standard outer contour range of the keyboard."

[0070] In practical applications, the standard outer contour range of each device type is pre-saved in a fixed coordinate system. For each external Bluetooth device, the terminal device first determines the standard outer contour range of that device type in the fixed coordinate system based on its device type. Then, it maps the coordinates of the precise contour of the external Bluetooth device to the fixed coordinate system. Based on the coordinates of the precise contour, the terminal device rotates and translates the coordinates of the precise contour using a point cloud registration algorithm. For each point of the rotated and translated precise contour, the corresponding coordinate is searched within the standard outer contour range of that device type in the fixed coordinate system. The nearest point is found, and the distance between that point and the nearest point is calculated. When the sum of the distances between all points and their corresponding nearest points is minimized, the coordinates of the precise outline of the external Bluetooth device are aligned with the coordinates of the standard outer outline of the device type in a fixed coordinate system. In the aligned fixed coordinate system, the points falling within the range of the standard outer outline are calculated to obtain the point cloud matching degree. It is then determined whether the point cloud matching degree is greater than a preset fifth threshold. If the point cloud matching degree is greater than the preset fifth threshold, and the precise straight-line distance between the external Bluetooth device and the terminal device is less than a preset first threshold, and the attitude angle is less than a preset second threshold, then the external Bluetooth device is determined to be the target external Bluetooth device.

[0071] For example, if an external Bluetooth device simultaneously meets the following conditions: the straight-line distance measured by UWB is less than 0.1m, the point cloud matching degree is greater than 90%, and the attitude angle is less than 5°, then the external Bluetooth device is determined to be the target external Bluetooth device.

[0072] In this embodiment, a detection signal is transmitted and a return signal is received from each external Bluetooth device. Then, based on the time of receiving each return signal, the straight-line distance between the terminal device and each external Bluetooth device is determined; and the attitude angle of each external Bluetooth device is determined. Only when the straight-line distance and attitude angle simultaneously meet the preset thresholds is the external Bluetooth device determined to be the target external Bluetooth device, thereby ensuring the accuracy of the connection to the target external Bluetooth device.

[0073] Example 3: To ensure the successful connection of external Bluetooth devices, when the terminal device receives a non-standard response, this application intelligently analyzes and adaptively generates a valid connection command. Figure 2 A schematic diagram illustrating the process of processing non-standard response information and generating connection instructions, provided in this application embodiment, includes the following steps: S201: If the response information is non-standard response information, the response information is structurally segmented based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments; each fragment is converted into a corresponding vector through the bag-of-words model.

[0074] Non-standard response information refers to device response data that does not conform to the preset standard format.

[0075] When the response information is determined to be non-standard, the terminal device first structurally segments the response information based on the semantic boundaries of the Bluetooth protocol, obtaining different types of fragments. Each fragment contains one or more consecutive bytes, representing specific data of different types in the response information. Then, using the bag-of-words model, each fragment is transformed into a corresponding vector. The bag-of-words model treats each fragment as a text unit, generating feature vectors based on the features of the byte sequence. This vectorization process ensures that semantically similar instructions are close in distance within the vector space.

[0076] In one possible implementation, if the response information is structurally segmented based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments, in order to ensure the integrity of the generated instructions, the terminal device can also determine the fragment type corresponding to the different types of fragments obtained based on the fragment types in the pre-saved response information corresponding to the device type; and determine whether the fragment types corresponding to the different types of fragments obtained contain the fragment types in the response information corresponding to the device type; if not, determine the missing fragment type in the response information, and automatically complete the fragment of the missing fragment type based on the missing fragment type and the default fields of each fragment type in the response information corresponding to the device type in the preset protocol library, and execute the subsequent step of converting each fragment into a corresponding vector; if yes, directly execute the step of converting each fragment into a corresponding vector.

[0077] S202: For each type of fragment, based on the similarity between the vector corresponding to that type of fragment and the vector corresponding to the basic fragment of the same type in the preset protocol library, determine the basic fragment with the highest similarity to that fragment.

[0078] Cosine similarity algorithm evaluates the similarity between two vectors by measuring the cosine of the angle between them. Basic fragments refer to the standard instruction components stored in the protocol library.

[0079] For each type of fragment, a cosine similarity algorithm is used to calculate the similarity between the vector corresponding to that type of fragment and the vector corresponding to the same type of basic fragment in a preset protocol library. The basic fragment with the highest similarity to this fragment is then determined as the matching result, i.e., the basic fragment with the highest similarity to this fragment is identified. The basic fragment with the highest similarity is the standard command fragment most similar to the current fragment in the protocol library. For example, fields such as vendor ID and device model included in the response information are used to identify external Bluetooth devices. Here, "vendor ID" and "device model" are types; "specific data corresponding to vendor ID" and "specific data corresponding to device model" are fields. In this application, the command fragment is essentially a field.

[0080] S203: Based on the device type, and according to the relevant instruction fragments of each type of the device type stored in the preset protocol library, filter out the initial necessary instruction fragments whose corresponding weight values ​​are greater than the preset third threshold to obtain the initial necessary instruction fragment set.

[0081] The preset protocol library stores relevant instruction fragments for each type of device, along with the weight value for each fragment. The terminal device, based on the device type determined in step 101, queries the preset protocol library for the relevant instruction fragments for that device type. These relevant instruction fragments are components of the connection instructions required for establishing a connection with an external Bluetooth device.

[0082] Among the relevant instruction fragments corresponding to each device type, initial necessary instruction fragments with weight values ​​greater than a preset third threshold are selected to obtain the initial necessary instruction fragment set. This weight value reflects the importance of each relevant instruction fragment in historical connections; that is, the weight value of the relevant instruction fragment is a dynamically updated value based on historical connection success rate statistics. The third threshold is set according to the actual application scenario; for example, the weight value corresponding to the relevant instruction fragment is ≥0.7. The selected initial necessary instruction fragments are key instruction components necessary for establishing a stable connection. For example, the initial necessary instruction fragment set includes device type identifier fragments corresponding to the device type identifier, connection request frame header fragments corresponding to the connection request frame header, and checksum field fragments related to checksum fields, etc.

[0083] S204: Based on the pre-saved instruction types of the necessary instruction fragments required to establish a connection with the device of the aforementioned device type, determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set.

[0084] The terminal device pre-stores a list of connection fragments corresponding to each device type. Each connection fragment list records the instruction types of the necessary instruction fragments required for establishing a connection for that device type. For example, if the device type is a keyboard, the necessary instruction fragments for establishing a connection for the keyboard device include instruction type 1, instruction type 2, and instruction type 3; if the device type is a mouse, the necessary instruction fragments for establishing a connection for the mouse device include instruction type a, instruction type b, and instruction type c.

[0085] Based on the pre-saved list of necessary instruction fragments required to establish a connection with a device of that type, i.e., the list of connection fragments corresponding to that device type, the initial instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set selected in step 203 are determined, thereby obtaining the initial instruction fragments required to establish a connection.

[0086] S205: Based on the most similar basic fragment and the initial necessary instruction fragment, generate a connection instruction for connecting to the device type according to a preset protocol logic order.

[0087] Based on the basic fragment with the highest similarity determined in step 202 and the initial necessary instruction fragment determined in step 204, connection instructions for connecting to the device of this device type are generated according to the preset protocol logic order. The protocol logic order is pre-stored in the protocol library, which specifies the arrangement order and execution timing of fragments of each type in the device connection instructions of different device types.

[0088] In this application, the connection command is a connection request frame conforming to the Bluetooth protocol specification, i.e., a connection command that generates a connection to a device of the specified device type. This connection command is composed of the most similar basic fragment and the selected initial necessary command fragments, combined according to a preset protocol logic order. The most similar basic fragment is obtained by segmenting the response information of the target external Bluetooth device into different types of fragments. Each fragment is then compared with the basic fragments of the same type in a preset protocol library for similarity calculation, and then filtered. For example, fields such as manufacturer ID and device model contained in the response information are used. The most similar basic fragment corresponding to each type of fragment in the protocol library is matched to achieve the identification of the external Bluetooth device. The selected initial necessary command fragments can be necessary command fragments corresponding to the Bluetooth connection request frame header, necessary command fragments corresponding to connection parameter configuration (such as connection interval, timeout, channel mapping, etc.), and necessary command fragments corresponding to verification, etc., forming the basic framework for ensuring connection compliance.

[0089] When generating a connection command, the two types of fragments mentioned above are first aligned. Then, based on the device type command template corresponding to the device type pre-stored in the protocol library, all fragments are arranged into a complete frame structure according to a preset protocol logic order, generating a connection command for connecting to a device of that device type, such as "frame header → vendor ID → device type identifier → connection parameters → checksum". This command is then sent to the target external Bluetooth device through the target channel to complete the connection establishment.

[0090] In one possible implementation, when generating a connection command for connecting to a device of this device type, the byte length, data format, and execution sequence of each fragment in the connection command are set according to a pre-saved Bluetooth protocol specification. Furthermore, the generated connection command can be verified for protocol compliance to confirm that the frame structure, field order, and parameter range all conform to the Bluetooth protocol standard.

[0091] In this embodiment, a smart vector matching and weighted filtering mechanism is used to effectively process non-standard response information and adaptively generate usable connection commands, which greatly improves the compatibility and success rate of connecting external Bluetooth devices.

[0092] Example 4: In this application, the weight values ​​of relevant instruction fragments are dynamically updated based on historical connection success rate statistics. Initial necessary instruction fragments, such as device type identifiers, connection request frame headers, and verification fields, have extremely high success rates in historical connections, therefore their weight values ​​are naturally higher than the preset third threshold and can be stably retained. However, to avoid incomplete connection instruction generation, this application also verifies the initial necessary instruction fragment set before generating connection instructions for this device type. The specific process is as follows: Determine whether the types of fragments contained in the initial necessary instruction fragment set include all the instruction types required to establish a connection with a device of that device type; if so, generate connection instructions for connecting with the device of that device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, following a preset protocol logic order. If not, determine the missing type, and based on the missing type and the standard instruction fragments corresponding to each type that are pre-saved, determine the target standard instruction fragment corresponding to the missing type; add the target standard instruction fragment to the initial necessary instruction fragment set, and generate a connection instruction for connecting to the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, in a preset protocol logic order.

[0093] After step 204, in order to ensure the integrity of the generated connection instructions, the terminal device determines whether the types of fragments contained in the initial necessary instruction fragment set include all the instruction types required to establish a connection with a device of that device type. That is, it checks whether the filtered initial necessary instruction fragment set covers all the necessary instruction fragments of that device type that must exist for each instruction type.

[0094] If it contains all the instruction types required to establish a connection with a device of that device type, then the connection instruction for connecting with the device of that device type is generated directly according to the basic fragment with the highest similarity and the initial necessary instruction fragment, in accordance with the preset protocol logic order, i.e., step 205 in the above embodiment 3, which will not be repeated here.

[0095] If the required instruction types for establishing a connection with a device of that type are not included, the missing type of the required instruction fragment in the initial required instruction fragment set is determined, and the target standard instruction fragment corresponding to the missing type is determined according to the missing type and the standard instruction fragments corresponding to each type that are saved in advance; the target standard instruction fragment is added to the initial required instruction fragment set, and the step of generating connection instructions in step 205 is executed.

[0096] In this embodiment, by determining whether the types of fragments contained in the initial necessary instruction fragment set include the various instruction types required to establish a connection with a device of that device type, and automatically filling in the missing types, the subsequent generated connection instructions can be used to achieve a normal Bluetooth connection with the target external Bluetooth device.

[0097] Example 5: To ensure seamless connection of external Bluetooth devices and improve the user experience, this application performs a target channel determination process after device type identification and before sending the connection command. The core of this process is to intelligently select the optimal communication channel based on the device type, ensuring reliable transmission of the connection command. The target channel determination process includes: Based on the device type of the target external Bluetooth device and a preset device type and channel mapping table, determine the dedicated channel corresponding to the target external Bluetooth device; and determine whether the dedicated channel is occupied. If so, then the channel with the highest signal-to-noise ratio and the least interference is determined as the target channel; Otherwise, the dedicated channel is determined to be the target channel.

[0098] The target channel refers to the communication channel that is ultimately selected for sending connection commands.

[0099] A dedicated channel refers to a preferred channel preset for a device type by querying the "Device Type and Channel Mapping Table". "Occupied" means the dedicated channel is currently unavailable. Signal-to-noise ratio (SNR) and interference are two core quantitative indicators for evaluating channel quality and selecting backup target channels.

[0100] After determining the device type of the target external Bluetooth device, the terminal device accesses a device type and channel mapping table in local storage or a cloud database. This mapping table predefines the association between different device types and their corresponding dedicated channels. For example, the mapping table can specify that the device type "mouse" is mapped to dedicated channel "CH36"; the device type "printer" is mapped to dedicated channel "CH149", and so on.

[0101] The terminal device determines the current status of the designated dedicated channel through a channel sensing mechanism. Optionally, if it is a wireless channel, this can be determined by detecting the Received Signal Strength Indication (RSSI) or Energy Detection (ED) of the channel. If the RSSI value remains higher than a preset threshold, the dedicated channel is determined to be occupied. If it is a wired channel, such as a specific USB data cable pair, the occupancy status can be determined by detecting the voltage level or data collision on the line. There are no limitations on this.

[0102] If not, meaning the determination result indicates that the dedicated channel is idle, the terminal device directly identifies that dedicated channel as the target channel. This path prioritizes the optimal matching of device type and channel, following the preset communication plan.

[0103] If so, meaning the determination result indicates that the dedicated channel is occupied by other communication links, the terminal device initiates the backup channel selection process. Specifically, the terminal device performs a panoramic scan of all available channels to obtain the real-time status parameters of each channel. Then, it calculates the signal-to-noise ratio (SNR) and interference level of each available channel, and selects the channel with the highest SNR and the lowest interference level as the target channel. The interference level can be quantified and calculated by comprehensively considering the number of non-target signals on the channel, the bit error rate (BER), or the packet collision rate; there are no restrictions on this.

[0104] Figure 3 The following is a detailed example diagram illustrating channel allocation using an external Bluetooth device as a keyboard, as provided in this application. Figure 3As shown, when the event detector of the external Bluetooth device detects that the capacitance value of the keyboard is greater than 200fF, it sends a connection request signal to the connection controller of the terminal device. At this time, the connection controller determines that the dedicated channel corresponding to the device type of the external Bluetooth device is channel CH36 with a frequency of 2402MHz, based on the device type of the external Bluetooth device and the preset device type and channel mapping table. Then, it requests channel CH36 with a frequency of 2402MHz from the radio frequency management module of the terminal device. If channel CH36 is available, the allocation is considered successful, and the radio frequency management module returns a "channel allocation successful" response to the connection controller. The connection controller then sends the identifier corresponding to channel CH36 to the protocol engine module. This is used to subsequently determine the target channel based on the identifier corresponding to channel CH36 and send the connection command. If channel CH36 is occupied, the channel is determined to be occupied, and the RF management module returns a "channel occupied, target channel recommended" response to the connection controller. The connection controller sends a request for spectrum scanning to the interference analyzer, which performs a panoramic scan of all available channels to obtain the real-time status parameters of each channel. The interference analyzer determines the recommended channel CH44 and its corresponding identifier. The frequency of the recommended channel CH44 may be 2422MHz. The dynamically modified carrier frequency and the identifier corresponding to the recommended channel CH44 are sent to the protocol engine module to complete the channel allocation.

[0105] Figure 4 The following is a simplified example diagram illustrating channel allocation using an external Bluetooth device as a keyboard, as provided in this application. Figure 4 As shown, when the capacitance value of the keyboard is greater than 200fF, i.e., when the capacitor is triggered, the terminal device determines whether channel CH36 is available. If it is, the channel allocation is successful; otherwise, the interference analyzer scans the spectrum of each channel to determine the recommended channel, the corresponding identifier, and modify the carrier frequency.

[0106] Optionally, to improve the user's seamless experience, the terminal device can also pre-set the first time threshold required for the channel allocation process to 20 milliseconds. Subsequently, based on the first time after the connection controller sends a channel allocation command to the radio frequency management module, and the first time the connection controller receives the corresponding "channel allocation successful" or "channel occupied, target channel recommended" response from the radio frequency management module, it determines whether the first time is less than the first time threshold. If not, the connection event is recorded in the internal error log and fed back to the maintenance personnel at fixed time intervals so that the maintenance personnel can optimize the channel allocation process. This constrains the maximum time from when the connection controller sends a channel allocation command to the radio frequency management module to when it receives the corresponding response, ensuring the smooth connection of external Bluetooth devices and avoiding timeouts. Furthermore, the required second time threshold for the interference analyzer to scan the spectrum of each channel can be preset to 100 milliseconds. This means that a full-band channel interference assessment can be completed every 100 milliseconds, refreshing the list of available channels. Subsequently, based on the second time of the interference analyzer scanning the spectrum of each channel and the preset second time threshold, it is determined whether the second time is less than the second time threshold. If not, the connection event is recorded in the internal error log and fed back to the operation and maintenance personnel at fixed time intervals so that the operation and maintenance personnel can optimize the interference analyzer. At the same time, it can also be set to directly use the valid results cached from the previous scan to provide recommendations, ensuring that the process of determining the recommended channel does not get stuck. This supports the ability to quickly switch target channels and maintain a stable connection in a strong interference environment.

[0107] In this embodiment, the dedicated channel corresponding to the target external Bluetooth device is determined based on the device type of the target external Bluetooth device and a preset device type-channel mapping table. It is then determined whether the dedicated channel is occupied. If so, the target channel with the highest signal-to-noise ratio and the least interference is selected; otherwise, the dedicated channel is selected as the target channel. This process selects the optimal communication channel, ensuring reliable transmission of connection commands and improving the user's seamless experience. Furthermore, the dynamic channel selection mechanism effectively avoids channel conflicts and interference while ensuring the priority of communication for different types of devices, thus enhancing the system's connection robustness in complex electromagnetic environments.

[0108] Example 6: To ensure the connection of external Bluetooth devices, this application verifies the weight of command fragments after receiving a connection request signal but before sending the connection command. The core of this approach is to ensure the integrity and reliability of the connection command through a weight evaluation mechanism. The specific steps are as follows: Based on the device type of the target external Bluetooth device, obtain the instruction fragments and corresponding weight values ​​of the device type stored in the preset protocol library. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, then execute the subsequent operation of sending the connection command to the target external Bluetooth device using the target channel.

[0109] Instruction fragments refer to the fragments obtained after breaking down a complete connection instruction. Each fragment undertakes a specific communication function and is stored in a pre-defined protocol library. The protocol library is a database that stores "instruction fragments" and "weight values" for various devices.

[0110] After determining the device type of the target external Bluetooth device, the terminal device accesses a preset protocol library to retrieve all instruction fragments and their corresponding weight values ​​for that device type. This preset protocol library is stored in the terminal device's non-volatile memory, indexed by device type, and contains the complete instruction sets required by various types of devices.

[0111] The terminal device's protocol engine module calculates the sum of the weight values ​​of all instruction fragments corresponding to the device type and compares this sum with a set condition. This set condition can be that the sum of the weight values ​​is greater than a preset total value. If the calculated sum of weight values ​​meets the set condition, the protocol engine module confirms that the connection command is complete and usable, allowing subsequent operations to be performed, i.e., sending the connection command to the target external Bluetooth device using the target channel. If the sum of weight values ​​does not meet the set condition, the current connection process is terminated, and an error report is generated, prompting the user to check the completeness of the protocol library or the accuracy of the device type matching.

[0112] In one possible implementation, to ensure the accuracy of external Bluetooth device connections, the terminal device can also verify the command fragments based on the average weight of each command fragment from historical connections corresponding to each device type and a preset threshold. The calculation process is as follows: The weight values ​​corresponding to each command fragment from all historical connections under that device type are read from the protocol library; an accumulation calculation is performed to obtain the sum of the weight values ​​of all command fragments corresponding to that device type; and based on the number of all protocol fragments in the protocol library and the sum of these weight values, the average weight of each command fragment from historical connections corresponding to that device type is calculated. The average weight... If the average weight is greater than the preset threshold, the subsequent operation of sending the connection command to the target external Bluetooth device via the target channel will be executed; otherwise, the current connection process will be terminated, and an error report will be generated, prompting the user to check the integrity of the protocol library or the accuracy of the device type matching.

[0113] In this embodiment, by introducing a weighted verification mechanism, the integrity and reliability of the connection instructions are ensured, effectively avoiding connection failures.

[0114] Example 7: After each connection is completed, the terminal device updates the dynamic weights of the instruction fragments used in the connection command. The core of this update lies in dynamically adjusting the weight values ​​of instruction fragments in the protocol library based on the connection result, thereby optimizing the reliability of subsequent connection commands. Specifically: Based on the semantic boundaries of the Bluetooth protocol, the connection command is structurally segmented into multiple command fragments. For each command fragment, a target command fragment identical to the one in a preset protocol library is identified, and the old weight value of the target command fragment is determined. If the connection is successful, the updated weight corresponding to the target command fragment is determined to be an increase of a first preset value on the basis of the old weight value. If the connection fails, the updated weight corresponding to the target command fragment is determined to be a decrease of a second preset value on the basis of the old weight value, wherein both the first and second preset values ​​are positive numbers.

[0115] Command fragments refer to the fragments obtained after decomposing the semantic boundaries of the Bluetooth protocol to form a complete connection command. Target command fragments refer to the stored entries in the protocol library that are identical to the current command fragment. Old weight values ​​refer to the historical weight values ​​of the target command fragment before the update.

[0116] Each instruction fragment has its own weight value. After each connection attempt, regardless of success or failure, the weight value of the instruction fragment used is dynamically updated based on the result. Specifically: Based on the semantic boundaries of the Bluetooth protocol, the terminal device structurally segments the connection command to be sent into multiple command fragments. Each command fragment contains one or more bytes, representing a logical segment of the connection command. For each segmented command fragment, the terminal device accesses a preset protocol library to search for a target command fragment with identical content. This protocol library stores command fragment sets for various device types, and each command fragment is associated with a historical weight value, i.e., an old weight value. If a matching target command fragment is found, its current old weight value is read; otherwise, the command fragment is added as a new entry to the protocol library and an initial weight value is assigned.

[0117] Based on the result of this connection attempt, the terminal device updates the weight value of each instruction fragment. Specifically, if the connection is successful, for each instruction fragment, the updated weight corresponding to the target instruction fragment is determined to be the old weight value plus a first preset value. The first setting value is a positive number. For example, if the first setting value is 0.1, then... If the connection fails, the updated weight corresponding to the target instruction fragment is determined to be the old weight value minus a second preset value. In other words, The second setting value is a positive number. For example, if the second setting value is 0.15, then... .

[0118] In one possible implementation, to avoid drastic fluctuations in weight values ​​due to a single abnormal result, the terminal device can pre-set corresponding proportional weights for the old weight value and the set value. Subsequently, when determining the updated weight corresponding to the target instruction fragment, the proportional weights corresponding to the old weight value and the set value are introduced. For example, if the first set value is 0.1 when the connection is successful, the preset proportional weight corresponding to the old weight value is 0.8, and the preset proportional weight corresponding to the set value is 0.2, then... When the connection failed, the second setting value was set to 0.15. The preset old weight value corresponded to a proportional weight of 0.8, and the preset setting value corresponded to a proportional weight of 0.2. This design allows recent connection results to have a greater impact on weight values, while retaining some historical state to prevent weight values ​​from fluctuating drastically due to a single abnormal result; it also allows for faster elimination of invalid or harmful instruction fragments.

[0119] After the update, the weight value of the corresponding target instruction fragment in the protocol library is set to the calculated updated weight value. Optionally, the terminal device can also limit the weight value of each instruction fragment to the range of [0.1, 1.0] to prevent the weight value from reaching zero due to consecutive failures or growing indefinitely. It should be noted that those skilled in the art can adjust the first set value, the second set value, and the old weight value and the set value to set corresponding proportional weights according to specific application scenarios, and this application does not limit this.

[0120] In this embodiment, through a dynamic weight update mechanism, the weight values ​​of instruction fragments in the protocol library can adaptively reflect their contribution to successful connection. Instruction fragments with higher weight values ​​will be preferentially used or retained in subsequent connections, while instruction fragments with lower weight values ​​may be eliminated or modified, thereby optimizing the composition of connection instructions and improving the reliability of connection instructions.

[0121] Example 8: Figure 5 A simplified flowchart of an external Bluetooth device connection method provided in this application is shown below. Figure 5As shown, it includes a multimodal perception layer for determining spatial coordinates and the outline of the external Bluetooth device, which is the specific content described in Embodiment 2 above, and will not be repeated here; a protocol reconfiguration engine for customizing connection instructions, which is the specific content described in Embodiments 3 and 4 above, and will not be repeated here; a security authentication module for verifying the historical connection success rate of instruction fragments corresponding to this type of device, which is the specific content described in Embodiment 6 above, and will not be repeated here; an event detector and a connection controller for allocating target channels, which is the specific content described in Embodiment 5 above, and will not be repeated here; and a device communication interface for sending connection instructions.

[0122] Figure 6 A simplified flowchart for building and optimizing a protocol library is provided in this application. The process includes the following steps: S601: Collects standard connection commands from various types of external Bluetooth devices, extracts command fragments, and assigns them initial weight values.

[0123] S602: Establish a mapping relationship between device types and instruction fragments to ensure that each device type has a corresponding complete instruction set.

[0124] S603: Periodically adjust weight values ​​based on newly generated connection commands and user feedback, and optimize the weight values ​​of command fragments.

[0125] S604: Update the bag-of-words model and vector database to ensure good recognition capabilities for newly emerging non-standard response information.

[0126] S601-S604 are the specific processes described in Embodiment 7 above, and will not be repeated here.

[0127] Figure 7 A simplified flowchart for determining the connection command of an external Bluetooth device provided in this application is shown below. Figure 7 As shown, the system receives response information from the target external Bluetooth device; it determines whether the response information meets the requirements of a standard response; if so, it loads the preset connection command corresponding to the device type; otherwise, it performs instruction fragment genetic optimization to generate a connection command for the device type. The specific processes described in Embodiments 1, 3, and 4 above will not be repeated here.

[0128] Example 9: Based on the same concept, embodiments of this application provide a device for connecting external Bluetooth devices. Figure 8 Please refer to the schematic diagram of a device structure for connecting an external Bluetooth device provided in this application embodiment. Figure 8 The device includes: The determining module 801 is used to determine the device type of the target external Bluetooth device based on the information of the outer contour of the scanned target external Bluetooth device; The processing module 802 is configured to: determine the theoretical received signal strength indication value of the target external Bluetooth device signal received at the straight-line distance between the target external Bluetooth device and the terminal device; determine the received signal strength indication value with the smallest deviation from the theoretical received signal strength indication value based on the received signal strength indication value contained in each received broadcast packet; use the Bluetooth Media Access Control (MAC) address in the broadcast packet containing the received signal strength indication value as the Bluetooth MAC address corresponding to the target external Bluetooth device; send a directional probe request to the Bluetooth MAC address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, load a preset connection command corresponding to the device type; if a connection request signal is received from the target external Bluetooth device, send the connection command to the target external Bluetooth device using the target channel.

[0129] In one possible implementation, the processing module 802 is specifically configured to transmit a detection signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of sending and receiving each return signal; and determine the attitude angle of each external Bluetooth device; when the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

[0130] In one possible implementation, the processing module 802 is further configured to: if the response information is non-standard response information, structurally segment the response information based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments; convert each fragment into a corresponding vector using a bag-of-words model; for each type of fragment, determine the basic fragment with the highest similarity to the fragment based on the similarity between the vector corresponding to the fragment of that type and the vector corresponding to the basic fragment of the same type in a preset protocol library; according to the device type, filter the initial necessary instruction fragments with corresponding weight values ​​greater than a preset third threshold according to the relevant instruction fragments of each type of the device type stored in the preset protocol library to obtain an initial necessary instruction fragment set; determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set according to the instruction types of the necessary instruction fragments required to establish a connection with the device of the device type stored in a preset protocol library; and generate a connection instruction for connecting with the device of the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragments, in a preset protocol logical order.

[0131] In one possible implementation, the processing module 802 is further configured to determine whether the types of fragments included in the initial necessary instruction fragment set contain all the instruction types required to establish a connection with a device of that device type; if yes, then according to the base fragment with the highest similarity and the initial necessary instruction fragment, a connection instruction for connecting with the device of that device type is generated in a preset protocol logic order; if no, then a missing type is determined, and according to the missing type and the standard instruction fragments corresponding to each type that are pre-saved, a target standard instruction fragment corresponding to the missing type is determined; the target standard instruction fragment is added to the initial necessary instruction fragment set, and according to the base fragment with the highest similarity and the initial necessary instruction fragment, a connection instruction for connecting with the device of that device type is generated in a preset protocol logic order.

[0132] In one possible implementation, the processing module 802 is specifically configured to determine the dedicated channel corresponding to the target external Bluetooth device based on the device type of the target external Bluetooth device and a preset device type and channel mapping table; and determine whether the dedicated channel is occupied; if so, determine the target channel with the highest signal-to-noise ratio and the least interference; otherwise, determine the dedicated channel as the target channel.

[0133] In one possible implementation, the processing module 802 is further configured to obtain instruction fragments and corresponding weight values ​​of the device type stored in a preset protocol library according to the device type of the target external Bluetooth device. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, the subsequent operation of sending the connection instruction to the target external Bluetooth device using the target channel is executed.

[0134] In one possible implementation, the processing module 802 is further configured to structurally segment the connection command based on the semantic boundaries of the Bluetooth protocol to obtain multiple command fragments; for each command fragment, to determine a target command fragment in a preset protocol library that is identical to the command fragment, and to determine the old weight value of the target command fragment; if the connection is successful, to determine that the updated weight corresponding to the target command fragment is an increase of a first preset value on the basis of the old weight value; if the connection fails, to determine that the updated weight corresponding to the target command fragment is a decrease of a second preset value on the basis of the old weight value, wherein both the first preset value and the second preset value are positive numbers.

[0135] Example 10: Based on the same concept, embodiments of this application provide an electronic device that can implement the steps of the external Bluetooth device connection method described above. Figure 9 This application provides a schematic diagram of an electronic device structure, such as... Figure 9As shown, it includes: processor 901, communication interface 902, memory 903 and communication bus 904, wherein processor 901, communication interface 902 and memory 903 communicate with each other through communication bus 904. The memory 903 stores a computer program. When the program is executed by the processor 901, the processor 901 performs the following steps: The device type of the target external Bluetooth device is determined based on the information of the outer contour of the scanned target external Bluetooth device; Based on the straight-line distance between the target external Bluetooth device and the terminal device, determine the theoretical received signal strength indication value of the signal received from the target external Bluetooth device at the straight-line distance; Based on the received signal strength indication value contained in each received broadcast packet, determine the received signal strength indication value that deviates the least from the theoretical received signal strength indication value, and use the Bluetooth media access control address in the broadcast packet containing the received signal strength indication value as the Bluetooth media access control address corresponding to the target external Bluetooth device. Send a directional probe request to the Bluetooth Media Access Control address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, then load the connection instruction corresponding to the preset device type; If a connection request signal is received from the target external Bluetooth device, the connection command is sent to the target external Bluetooth device using the target channel.

[0136] In one possible implementation, the processor 901 is specifically configured to transmit a detection signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of sending and receiving each return signal; and determine the attitude angle of each external Bluetooth device; when the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

[0137] In one possible implementation, the processor 901 is further configured to: structurally segment the response information based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments; convert each fragment into a corresponding vector using a bag-of-words model; for each type of fragment, determine the basic fragment with the highest similarity to the fragment based on the similarity between the vector corresponding to the fragment of that type and the vector corresponding to the basic fragment of the same type in a preset protocol library; according to the device type, filter the initial necessary instruction fragments with corresponding weight values ​​greater than a preset third threshold according to the relevant instruction fragments of each type of the device type stored in the preset protocol library to obtain an initial necessary instruction fragment set; determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set according to the instruction types of the necessary instruction fragments required to establish a connection with the device of the device type stored in a preset protocol library; and generate a connection instruction for connecting with the device of the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragments, following a preset protocol logic order.

[0138] In one possible implementation, the processor 901 is further configured to determine whether the types of fragments included in the initial necessary instruction fragment set contain all the instruction types required to establish a connection with a device of that device type; if yes, then based on the base fragment with the highest similarity and the initial necessary instruction fragment, a connection instruction for connecting with the device of that device type is generated according to a preset protocol logic order; if no, then a missing type is determined, and based on the missing type and the standard instruction fragments corresponding to each type that are pre-saved, a target standard instruction fragment corresponding to the missing type is determined; the target standard instruction fragment is added to the initial necessary instruction fragment set, and based on the base fragment with the highest similarity and the initial necessary instruction fragment, a connection instruction for connecting with the device of that device type is generated according to a preset protocol logic order.

[0139] In one possible implementation, the processor 901 is specifically configured to determine the dedicated channel corresponding to the target external Bluetooth device based on the device type of the target external Bluetooth device and a preset device type and channel mapping table; and determine whether the dedicated channel is occupied; if so, determine the target channel with the highest signal-to-noise ratio and the least interference; otherwise, determine the dedicated channel as the target channel.

[0140] In one possible implementation, the processor 901 is further configured to obtain instruction fragments and corresponding weight values ​​of the device type stored in a preset protocol library according to the device type of the target external Bluetooth device. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, the processor 901 is configured to perform the subsequent operation of sending the connection instruction to the target external Bluetooth device using the target channel.

[0141] In one possible implementation, the processor 901 is further configured to structurally segment the connection command based on the semantic boundaries of the Bluetooth protocol to obtain multiple command fragments; for each command fragment, to determine a target command fragment in a preset protocol library that is identical to the command fragment, and to determine the old weight value of the target command fragment; if the connection is successful, to determine that the updated weight corresponding to the target command fragment is an increase of a first preset value on the basis of the old weight value; if the connection fails, to determine that the updated weight corresponding to the target command fragment is a decrease of a second preset value on the basis of the old weight value, wherein both the first preset value and the second preset value are positive numbers.

[0142] The communication bus mentioned in the aforementioned electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. This communication bus can be divided into address bus, data bus, control bus, etc. For ease of illustration, only one thick line is used in the figure, but this does not indicate that there is only one bus or one type of bus. The communication interface 902 is used for communication between the aforementioned electronic device and other devices. The memory can include random access memory (RAM) or non-volatile memory (NVM), such as at least one disk storage device. Optionally, the memory can also be at least one storage device located remotely from the aforementioned processor.

[0143] The processors mentioned above can be general-purpose processors, including central processing units, network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits, field-programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0144] Example 11: Based on the same technical concept, embodiments of this application provide a computer-readable storage medium storing a computer program executable by an electronic device. When the program is run on the electronic device, the electronic device performs the following steps: The device type of the target external Bluetooth device is determined based on the information of the outer contour of the scanned target external Bluetooth device; Based on the straight-line distance between the target external Bluetooth device and the terminal device, determine the theoretical received signal strength indication value of the signal received from the target external Bluetooth device at the straight-line distance; Based on the received signal strength indication value contained in each received broadcast packet, determine the received signal strength indication value that deviates the least from the theoretical received signal strength indication value, and use the Bluetooth media access control address in the broadcast packet containing the received signal strength indication value as the Bluetooth media access control address corresponding to the target external Bluetooth device. Send a directional probe request to the Bluetooth Media Access Control address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, then load the connection instruction corresponding to the preset device type; If a connection request signal is received from the target external Bluetooth device, the connection command is sent to the target external Bluetooth device using the target channel.

[0145] In one possible implementation, the process of determining the target external Bluetooth device includes: Transmit a probe signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of sending and receiving each return signal; and determine the attitude angle of each external Bluetooth device. When the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

[0146] In one possible implementation, the method further includes: If the response information is non-standard, it is structured and segmented based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments. Each fragment is transformed into a corresponding vector using the bag-of-words model. For each type of fragment, the basic fragment with the highest similarity to the fragment is determined based on the similarity between the vector corresponding to the fragment of that type and the vector corresponding to the basic fragment of the same type in the preset protocol library. Based on the device type, and based on the relevant instruction fragments of each type of the device type stored in the preset protocol library, the initial necessary instruction fragments with corresponding weight values ​​greater than the preset third threshold are selected to obtain the initial necessary instruction fragment set. Based on the pre-saved list of necessary instruction fragments required to establish a connection with the device of the aforementioned device type, determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set; Based on the most similar basic fragment and the initial necessary instruction fragment, a connection instruction for connecting to the device type is generated according to a preset protocol logic order.

[0147] In one possible implementation, before generating connection instructions for connecting to the device type based on the most similar basic fragment and the initial necessary instruction fragment, according to a preset protocol logic order, the method further includes: Determine whether the types of fragments contained in the initial necessary instruction fragment set include all the instruction types required to establish a connection with a device of that device type; if so, generate connection instructions for connecting with the device of that device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, following a preset protocol logic order. If not, determine the missing type, and based on the missing type and the standard instruction fragments corresponding to each type that are pre-saved, determine the target standard instruction fragment corresponding to the missing type; add the target standard instruction fragment to the initial necessary instruction fragment set, and generate a connection instruction for connecting to the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, in a preset protocol logic order.

[0148] In one possible implementation, the process of determining the target channel includes: Based on the device type of the target external Bluetooth device and a preset device type and channel mapping table, determine the dedicated channel corresponding to the target external Bluetooth device; and determine whether the dedicated channel is occupied. If so, then determine the target channel with the highest signal-to-noise ratio and the least interference; Otherwise, the dedicated channel is determined to be the target channel.

[0149] In one possible implementation, after receiving the connection request signal from the target external Bluetooth device and before sending the connection command to the target external Bluetooth device using the target channel, the method further includes: Based on the device type of the target external Bluetooth device, obtain the instruction fragments and corresponding weight values ​​of the device type stored in the preset protocol library. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, then execute the subsequent operation of sending the connection command to the target external Bluetooth device using the target channel.

[0150] In one possible implementation, the method further includes: Based on the semantic boundaries of the Bluetooth protocol, the connection command is structurally segmented into multiple command fragments. For each command fragment, a target command fragment identical to the one in a preset protocol library is identified, and the old weight value of the target command fragment is determined. If the connection is successful, the updated weight corresponding to the target command fragment is determined to be an increase of a first preset value on the basis of the old weight value. If the connection fails, the updated weight corresponding to the target command fragment is determined to be a decrease of a second preset value on the basis of the old weight value, wherein both the first and second preset values ​​are positive numbers.

[0151] The aforementioned computer-readable storage medium can be any available medium or data storage device that can be accessed by the processor in an electronic device, including but not limited to magnetic storage such as floppy disks, hard disks, magnetic tapes, magneto-optical disks (MO), optical storage such as CDs, DVDs, BDs, HVDs, etc., and semiconductor storage such as ROMs, EPROMs, EEPROMs, non-volatile memory (NAND flash), solid-state drives (SSDs), etc.

[0152] Based on the same concept, this application also provides a computer program product, which includes computer program code. When the computer program code is run on a computer, it causes the computer to execute any of the external Bluetooth device connection methods described above. Since the principle by which the above computer program product solves the problem is similar to that of an external Bluetooth device connection method, the implementation of the above computer program product can be referred to the implementation of the method, and repeated details will not be described again.

[0153] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0154] Computer programs used to perform the operations of this disclosure may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, status setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The computer-readable program instructions may execute entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing status information from the computer-readable program instructions to implement various aspects of this disclosure.

[0155] The computer program product described herein can be implemented specifically through hardware, software, or a combination thereof. In one alternative embodiment, the computer program product is specifically embodied in a computer storage medium; in another alternative embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.

[0156] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0157] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0158] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0159] Although preferred embodiments of this application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of this application.

[0160] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if such modifications and variations fall within the scope of the claims of this application and their equivalents, this application also intends to include such modifications and variations.

Claims

1. A method for connecting an external Bluetooth device, characterized in that, The method includes: The device type of the target external Bluetooth device is determined based on the information of the outer contour of the scanned target external Bluetooth device; Based on the straight-line distance between the target external Bluetooth device and the terminal device, determine the theoretical received signal strength indication value of the signal received from the target external Bluetooth device at the straight-line distance; Based on the received signal strength indication value contained in each received broadcast packet, determine the received signal strength indication value that deviates the least from the theoretical received signal strength indication value, and use the Bluetooth media access control address in the broadcast packet containing the received signal strength indication value as the Bluetooth media access control address corresponding to the target external Bluetooth device. Send a directional probe request to the Bluetooth Media Access Control address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, then load the connection instruction corresponding to the preset device type; If a connection request signal is received from the target external Bluetooth device, the connection command is sent to the target external Bluetooth device using the target channel.

2. The method according to claim 1, characterized in that, The process of identifying the target external Bluetooth device includes: Transmit a probe signal and receive a return signal from each external Bluetooth device; determine the straight-line distance between the terminal device and each external Bluetooth device based on the time of sending and receiving each return signal; and determine the attitude angle of each external Bluetooth device. When the straight-line distance between any external Bluetooth device and the terminal device is less than a preset first threshold and the attitude angle is less than a preset second threshold, the external Bluetooth device is determined to be the target external Bluetooth device.

3. The method according to claim 1, characterized in that, The method further includes: If the response information is non-standard, it is structured and segmented based on the semantic boundaries of the Bluetooth protocol to obtain different types of fragments. Each fragment is transformed into a corresponding vector using the bag-of-words model. For each type of fragment, the basic fragment with the highest similarity to the fragment is determined based on the similarity between the vector corresponding to the fragment of that type and the vector corresponding to the basic fragment of the same type in the preset protocol library. Based on the device type, and based on the relevant instruction fragments of each type of the device type stored in the preset protocol library, the initial necessary instruction fragments with corresponding weight values ​​greater than the preset third threshold are selected to obtain the initial necessary instruction fragment set. Based on the pre-saved list of necessary instruction fragments required to establish a connection with the device of the aforementioned device type, determine the initial necessary instruction fragments corresponding to each instruction type in the initial necessary instruction fragment set; Based on the most similar basic fragment and the initial necessary instruction fragment, a connection instruction for connecting to the device type is generated according to a preset protocol logic order.

4. The method according to claim 3, characterized in that, Before generating connection instructions for connecting to the device type based on the most similar basic fragment and the initial necessary instruction fragment, according to a preset protocol logic order, the method further includes: Determine whether the types of fragments contained in the initial necessary instruction fragment set include all the instruction types required to establish a connection with a device of that device type; if so, generate connection instructions for connecting with the device of that device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, following a preset protocol logic order. If not, determine the missing type, and based on the missing type and the standard instruction fragments corresponding to each type that are pre-saved, determine the target standard instruction fragment corresponding to the missing type; add the target standard instruction fragment to the initial necessary instruction fragment set, and generate a connection instruction for connecting to the device type according to the basic fragment with the highest similarity and the initial necessary instruction fragment, in a preset protocol logic order.

5. The method according to claim 1, characterized in that, The process of determining the target channel includes: Based on the device type of the target external Bluetooth device and a preset device type and channel mapping table, determine the dedicated channel corresponding to the target external Bluetooth device; and determine whether the dedicated channel is occupied. If so, then determine the target channel with the highest signal-to-noise ratio and the least interference; Otherwise, the dedicated channel is determined to be the target channel.

6. The method according to claim 1, characterized in that, After receiving the connection request signal from the target external Bluetooth device, and before sending the connection command to the target external Bluetooth device using the target channel, the method further includes: Based on the device type of the target external Bluetooth device, obtain the instruction fragments and corresponding weight values ​​of the device type stored in the preset protocol library. If the sum of the weight values ​​corresponding to the instruction fragments of the device type meets the set conditions, then execute the subsequent operation of sending the connection command to the target external Bluetooth device using the target channel.

7. The method according to claim 1, characterized in that, The method further includes: Based on the semantic boundaries of the Bluetooth protocol, the connection command is structurally segmented into multiple command fragments. For each command fragment, a target command fragment identical to the one in a preset protocol library is identified, and the old weight value of the target command fragment is determined. If the connection is successful, the updated weight corresponding to the target command fragment is determined to be an increase of a first preset value on the basis of the old weight value. If the connection fails, the updated weight corresponding to the target command fragment is determined to be a decrease of a second preset value on the basis of the old weight value, wherein both the first and second preset values ​​are positive numbers.

8. A device for connecting to an external Bluetooth device, characterized in that, The device includes: The determination module is used to determine the device type of the target external Bluetooth device based on the information of the outer contour of the scanned target external Bluetooth device; The processing module is configured to: determine the theoretical received signal strength indication (RSS) value of the target external Bluetooth device receiving the signal at the straight-line distance between the target external Bluetooth device and the terminal device; determine the RSS value with the smallest deviation from the theoretical RSS value based on the RSS value contained in each received broadcast packet; use the Bluetooth Media Access Control (MAC) address in the broadcast packet containing the RSS value as the Bluetooth MAC address corresponding to the target external Bluetooth device; send a directional probe request to the Bluetooth MAC address corresponding to the target external Bluetooth device and receive the response information from the target external Bluetooth device; if the response information is a standard response information that meets the requirements, load a preset connection command corresponding to the device type; if a connection request signal is received from the target external Bluetooth device, send the connection command to the target external Bluetooth device using the target channel.

9. An electronic device, characterized in that, The electronic device includes a processor for implementing the method as described in any one of claims 1-7 when executing a computer program stored in a memory.

10. A computer-readable storage medium, characterized in that, It stores a computer program that, when executed by a processor, implements the method as described in any one of claims 1-7.