Usb port enumeration method, apparatus, device, medium, and program product

By optimizing the USB port enumeration logic and determining the completion of enumeration according to a fixed port enumeration order and preset conditions, the problem of misjudgment caused by the uncertainty of the USB device bus identifier is solved, and stable USB device management and resource optimization are achieved.

CN122152748APending Publication Date: 2026-06-05PATEO CONNECT (NANJING) CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
PATEO CONNECT (NANJING) CO LTD
Filing Date
2024-12-04
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

After the vehicle operating system wakes up from hibernation, the uncertainty of the bus identifier of the USB device leads to misjudgment by the upper-layer application and connection instability.

Method used

The USB port enumeration logic has been optimized to enumerate each USB port sequentially according to a fixed port enumeration order. The completion of enumeration is determined by monitoring changes in the number of USB devices and preset conditions, ensuring the consistency of bus identifiers.

Benefits of technology

It avoids misjudgments by upper-layer applications, improves response speed and real-time performance, can detect abnormal connections or port failures, and optimizes power usage and resource management.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122152748A_ABST
    Figure CN122152748A_ABST
Patent Text Reader

Abstract

The application provides a USB port enumeration method, device, equipment, medium and program product. The method comprises the following steps: in the case that the operating system of a vehicle is in a wake-up state, the following steps are sequentially performed on each USB port in n USB ports configured on the vehicle according to a preset port enumeration order, wherein each USB port is coupled with a USB device: turning on the i-th USB port, i is an integer greater than 0 and less than n; enumerating the USB devices coupled with the first i USB ports to determine the first quantity of the USB devices coupled with the first i USB ports, the order of the bus identification numbers of the USB devices coupled with the USB ports is positively correlated with the port enumeration order, and the bus identification number is used to identify the vehicle bus mounted by the USB device coupled with the USB port; in the case that the first quantity meets a preset condition, it is determined that the i-th USB port enumeration is completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to, but is not limited to, the field of computer technology, and in particular to a USB port enumeration method, apparatus, device, medium, and program product. Background Technology

[0002] In the Internet of Things (IoT) field, vehicles are typically equipped with multiple USB ports for coupling Universal Serial Bus (USB) devices. Each USB device corresponds to a bus identifier, allowing upper-layer applications (APPs) to distinguish between different USB devices using the bus identifier.

[0003] Typically, the vehicle's operating system re-enumerates the USB devices connected to each USB port each time it wakes up from sleep mode. However, this can lead to the same USB device having different bus identifiers in different sleep / wake cycles, which can cause problems for upper-layer applications. Summary of the Invention

[0004] One objective of this application is to provide a USB port enumeration method. By optimizing the USB port enumeration logic, each USB port is enumerated in a fixed enumeration order after each sleep / wake cycle of the vehicle's operating system. Only one USB port is enabled at a time, and the next USB port is enabled only after the enumeration of that USB port is complete. The method for determining the completion of enumeration is to enumerate the number of USB devices currently coupled to the vehicle. If this number meets a preset condition, it indicates that the enumeration of the enabled USB ports is complete. In this way, the bus identifier of the USB devices of the enumerated USB ports is fixed each time, thus avoiding misjudgments by the upper-layer application.

[0005] Another objective of this application is to provide a USB port enumeration method. When the difference between the number of USB devices coupled to the first i USB ports and the number of USB devices coupled to the first i-1 USB ports is greater than or equal to a preset threshold, the vehicle-mounted device can determine that the enumeration of the i-th USB port is complete. This method allows the vehicle-mounted device to monitor the connection status and the number of coupled USB devices for each USB port. When the number of newly added USB devices reaches the preset threshold, the vehicle-mounted device can respond immediately, thereby improving response speed and real-time performance. Moreover, by comparing the changes in the number of devices on different USB ports, abnormal connections or port failures can be detected more easily. Furthermore, the vehicle-mounted device can dynamically allocate and manage resources based on the number of USB devices coupled to each USB port. For example, if a USB port has a large number of coupled USB devices, the vehicle-mounted device can prioritize allocating more bandwidth or power resources to that USB port.

[0006] Another objective of this application is to provide a USB port enumeration method. The in-vehicle device can obtain the current state of the vehicle's operating system. When the current state is sleep mode, all USB ports are turned off to save power. When the current state transitions from sleep mode to wake-up mode, the number of USB ports coupled inside the vehicle is enumerated, and after enumeration, the first USB port is turned on for enumeration according to the port enumeration order. By monitoring the current state of the operating system, the in-vehicle device can intelligently manage USB ports to optimize power usage.

[0007] Another objective of this application is to provide a USB port enumeration method. When the number of USB devices coupled to the first i USB ports (e.g., a first number) does not meet a preset condition, the vehicle-mounted device repeatedly enumerates the USB devices coupled to the first i USB ports. If the number of times the first number fails to meet the preset condition reaches a preset number, it is determined that the USB device coupled to the i-th USB port is faulty. In this embodiment, when the number of USB devices enumerated for a particular USB port does not meet the preset condition, to rule out temporary faults, the enumeration is repeated. If the preset condition is still not met after multiple repeated enumerations, it is determined that the problem is caused by a USB device fault. By repeatedly enumerating, the scope of the problem can be gradually narrowed down, ultimately pointing to a possible hardware fault point. This helps ensure that the vehicle-mounted device can accurately and reliably identify and manage connected USB devices.

[0008] Another objective of this application is to provide a USB port enumeration device. By optimizing the USB port enumeration logic, each USB port is enumerated in a fixed port enumeration order after each sleep-wake cycle of the vehicle's operating system, resulting in a fixed bus identifier for each enumerated USB device. This can prevent misjudgments by the upper-layer APP.

[0009] Another objective of this application is to provide an in-vehicle device, including a memory and a processor. The memory stores a computer program that can run on the processor, and the processor executes the computer program to implement the steps in the above-described method. By optimizing the USB port enumeration logic, each USB port is enumerated in a fixed port enumeration order after each sleep-wake cycle of the vehicle's operating system, resulting in a fixed bus identifier for each enumerated USB device. This avoids misjudgments by the upper-layer APP.

[0010] Another objective of this application is to provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps in the above-described method. By optimizing the USB port enumeration logic, each USB port is enumerated in a fixed port enumeration order after each sleep-wake cycle of the vehicle's operating system, resulting in a fixed bus identifier for each enumerated USB device, thus preventing misjudgments by the upper-layer APP.

[0011] Another objective of this application is to provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps in the above-described method. By optimizing the USB port enumeration logic, each USB port is enumerated in a fixed port enumeration order after each sleep-wake cycle of the vehicle's operating system, resulting in a fixed bus identifier for each enumerated USB device, thus preventing misjudgments by the upper-layer APP.

[0012] To achieve the above objectives, the technical solution of this application embodiment is implemented as follows:

[0013] In a first aspect, embodiments of this application provide a USB port enumeration method. When the vehicle's operating system is in a wake-up state, the following steps are performed sequentially on each of the n USB ports configured on the vehicle according to a preset port enumeration order, where n is the total number of USB ports configured on the vehicle and is a positive integer, and each USB port is coupled to a USB device: The i-th USB port is turned on, where i is an integer greater than 0 and less than n; the USB devices coupled to the first i USB ports of the vehicle are enumerated to determine a first number of USB devices coupled to the first i USB ports, wherein the USB devices coupled to the first i USB ports include at least the USB devices coupled to the i-th USB port, USB devices coupled inside the vehicle, and USB devices coupled to each of the first i-1 USB ports that have been turned on. The order of the bus identifiers of the USB devices coupled to the USB ports is positively correlated with the port enumeration order, and the bus identifiers are used to identify the vehicle bus to which the USB devices coupled to the USB ports are connected; if the first number satisfies a preset condition, the enumeration of the i-th USB port is determined to be complete.

[0014] Secondly, embodiments of this application provide a USB port enumeration device. The device includes: when the vehicle's operating system is in a wake-up state, performing the following steps sequentially on each of the n USB ports configured on the vehicle according to a preset port enumeration order, wherein n is the total number of USB ports configured on the vehicle, n is a positive integer, and each USB port is coupled to a USB device: a port opening module, used to open the i-th USB port, i is an integer greater than 0 and less than n; an enumeration module, used to enumerate the USB devices coupled to the first i USB ports of the vehicle to determine a first number of USB devices, wherein the USB devices coupled to the first i USB ports include at least the USB devices coupled to the i-th USB port, USB devices coupled inside the vehicle, and USB devices coupled to each of the first i-1 USB ports that have been opened, the order of the bus identification numbers of the USB devices coupled to the USB ports is positively correlated with the port enumeration order, and the bus identification number is used to identify the vehicle bus on which the USB devices coupled to the USB ports are connected; and a determination module, used to determine that the enumeration of the i-th USB port is completed when the first number is determined to meet a preset condition.

[0015] Thirdly, embodiments of this application provide an in-vehicle device, including a memory and a processor. The memory stores a computer program that can run on the processor, and the processor executes the program to implement the steps in the above-described method.

[0016] Fourthly, embodiments of this application provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps in the above-described method.

[0017] Fifthly, embodiments of this application provide a computer program product, including a computer program or instructions, which, when executed by a processor, implement the steps in the method described above.

[0018] It should be understood that the above general description and the following detailed description are merely exemplary and explanatory, and are not intended to limit the technical solutions of this application. Attached Figure Description

[0019] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with this application and, together with the specification, serve to explain the technical solutions of this application.

[0020] Figure 1 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment;

[0021] Figure 2 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment;

[0022] Figure 3 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment;

[0023] Figure 4 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment;

[0024] Figure 5 This is a schematic diagram of the composition structure of a USB port enumeration device provided in an embodiment of this application;

[0025] Figure 6 This is a schematic diagram of the hardware entity of an in-vehicle device provided in an embodiment of this application. Detailed Implementation

[0026] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application are further described in detail below with reference to the accompanying drawings and embodiments. The described embodiments should not be regarded as limitations on this application. All other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0027] In the following description, references to "some embodiments" refer to a subset of all possible embodiments. It is understood that "some embodiments" may be the same or different subsets of all possible embodiments and may be combined with each other without conflict. The terms "first / second / third" are used merely to distinguish similar objects and do not represent a specific ordering of objects. It is understood that "first / second / third" may be interchanged in a specific order or sequence where permitted, so that the embodiments of this application described herein can be implemented in an order other than that illustrated or described herein.

[0028] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. The terminology used herein is for descriptive purposes only and is not intended to limit the scope of this application.

[0029] USB port enumeration refers to the process by which in-vehicle devices identify and manage USB devices connected to the vehicle's USB ports. This process typically includes identifying the type, manufacturer, and serial number of the USB device, and allocating appropriate resources (such as memory, bus ID, and processor time) to it. During the vehicle's operating system's sleep and wake-up cycle, a specific behavior pattern exists: each time it wakes from sleep, the operating system automatically re-enumerates every USB device coupled through a USB port. This mechanism aims to ensure that the operating system can accurately identify and manage all newly connected or potentially changed USB external devices. However, whenever the operating system triggers the enumeration process, all USB ports are activated simultaneously, and then each begins its enumeration process independently. This enumeration process is based on a contention mechanism: the USB device coupled to the USB port that completes enumeration first is assigned a smaller bus ID.

[0030] Understandably, the bus identifier is a critical system resource used to uniquely identify each device coupled to a USB port within the system. However, due to the combined effects of operating system scheduling strategies, hardware performance differences, and other potential external factors (such as electromagnetic interference and power stability), the enumeration order of each USB port often differs each time the system wakes up from hibernation and re-enumerates. This uncertainty leads to a direct consequence: even for the same USB device, the bus identifier assigned during different hibernation-wake cycles may differ due to the different enumeration order of the connected USB ports, resulting in the device being treated as a different USB device at the system level. For upper-layer applications that rely on bus identifiers to identify and distinguish different USB devices and their functions, this randomness undoubtedly poses a challenge. It not only increases the development complexity of upper-layer applications, as developers need to write additional logic to handle this uncertainty, but it may also lead to a degraded user experience, such as device identification errors, unstable connections, or functional abnormalities.

[0031] Based on this, this application provides a USB port enumeration method. This method optimizes the USB port enumeration logic. After each sleep and wake-up of the vehicle's operating system, each USB port is enumerated in a fixed port enumeration order, resulting in a fixed bus identifier for each enumerated USB device. This can avoid misjudgment by the upper-layer APP.

[0032] Figure 1 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment. For example, this method can be executed by an in-vehicle device. Figure 1 As shown, the method includes steps S101 to S103.

[0033] In step S101, when the vehicle's operating system is in a wake-up state, the i-th USB port is opened sequentially for each of the n USB ports configured on the vehicle according to a preset port enumeration order, where n is the total number of USB ports configured on the vehicle, n is a positive integer, each USB port is coupled to a USB device, and i is an integer greater than 0 and less than n.

[0034] In some embodiments, the vehicle's operating system, also known as the in-vehicle operating system, is the operating system installed and running on the vehicle's in-vehicle equipment. The in-vehicle operating system is system software that manages and controls in-vehicle hardware and software resources.

[0035] In some embodiments, the operating system of the vehicle device may be an Android system, a Linux system, a Windows system, an Apple system, a Harmony system, or other operating systems. This application embodiment does not limit this.

[0036] In some embodiments, the vehicle's operating system may include a shutdown state, a hibernation state, a wake-up state, and a running state. The shutdown state refers to the state where the vehicle's operating system is completely powered off; in this state, the operating system does not perform any tasks and does not consume power. The hibernation state is the state in which the vehicle's operating system can still respond to certain external or internal events while maintaining low power consumption. The wake-up state is the process by which the vehicle's operating system transitions from a hibernation or shutdown state to an active state; in the wake-up state, the operating system reloads necessary processes and services and prepares to perform various tasks. The running state is the state in which the vehicle's operating system is fully active and operational.

[0037] Typically, vehicles are equipped with multiple USB ports to meet the needs of different devices and functions. For example, USB ports can be located on the driver's side, passenger side, or instrument panel side, providing convenience for users in different positions. For example, the functions of a USB port can include data transfer, charging, and connecting other devices. Data Transfer: Some USB ports support data transfer, allowing users to read data from USB flash drives, such as music and videos, facilitating entertainment or navigation within the vehicle. Charging: USB ports all have charging capabilities, providing power to mobile devices such as smartphones and tablets. Connecting Other Devices: USB ports can connect to other electronic devices such as car vacuum cleaners, radar detectors, and dashcams, providing additional functionalities for the vehicle.

[0038] In some embodiments, each USB port is coupled to a USB device, meaning that an external USB device is plugged into each USB port. For example, in a vehicle equipped with three USB ports, USB-port0, USB-port1, and USB-port2, the USB device coupled to USB-port0 could be a USB flash drive for multimedia, the USB device coupled to USB-port1 could be a digital video recorder (DVR), and the USB device coupled to USB-port2 could be a telematics box (TBOX).

[0039] In some embodiments, the port enumeration order can be preset by the user in the vehicle device. For example, if the vehicle is equipped with USB-port0, USB-port1 and USB-port2, the port enumeration order can be USB-port0->USB-port1->USB-port2 or USB-port2->USB-port1->USB-port0. This application embodiment does not limit this.

[0040] Understandably, each time the operating system is woken up, it re-enumerates the USB devices coupled to each USB port. Therefore, in this embodiment, the in-vehicle device can obtain the state of the vehicle's operating system. When the operating system is found to be in a woken-up state, it can power on the first USB port according to a pre-set port enumeration order, and then perform the enumeration operation. After confirming that the first USB port enumeration is complete, it continues to power on the second USB port and so on, until all n USB ports are enumerated.

[0041] In step S102, the USB devices coupled to the first i USB ports of the vehicle are enumerated to determine a first number of USB devices coupled to the first i USB ports. The USB devices coupled to the first i USB ports include at least the USB device coupled to the i-th USB port, the USB devices coupled inside the vehicle, and the USB devices coupled to each of the first i-1 USB ports that are already open. The order of the bus identifiers of the USB devices coupled to the USB ports is positively correlated with the port enumeration order. The bus identifier is used to identify the vehicle bus to which the USB device coupled to the i-th USB port is connected.

[0042] Understandably, when an in-vehicle device starts enumerating USB devices after activating a USB port, it enumerates all USB devices coupled to all currently activated USB ports in the vehicle. Therefore, if the USB port is not the first USB port in the port enumeration order (i.e., when i is a value greater than 1 and less than n), the enumerated USB devices include the USB devices coupled to each of the first i-1 USB ports, as well as the USB devices coupled to the i-th USB port.

[0043] In some embodiments, the USB device currently coupled to the vehicle may also be a USB device coupled to the vehicle's internal network. A USB device coupled to the vehicle's internal network can be understood as a bus within the vehicle that can be used to connect devices such as USB flash drives. For example, the bus within the vehicle may include a Controller Area Network (CAN) bus, a Local Interconnect Network (LIN) bus, a Media Oriented Systems Transport (MOST) bus, and other buses.

[0044] Therefore, when i is a value greater than 1 and less than n, the USB devices enumerated by the in-vehicle device include the USB devices coupled to each of the first i-1 USB ports, the USB devices coupled to the ith USB port, and the USB devices coupled inside the vehicle. When i is 1, the USB devices enumerated by the in-vehicle device include the USB devices coupled to the first USB port and the USB devices coupled inside the vehicle.

[0045] Understandably, when an in-vehicle device enumerates USB devices, it assigns a bus identifier to each enumerated USB device. The earlier a USB device is enumerated, the smaller its corresponding bus identifier. Therefore, given a port enumeration order, the order of the bus identifiers of the USB devices coupled to a USB port is positively correlated with the port enumeration order. When a USB port is opened for enumeration according to a preset port enumeration order, the bus identifier of the USB device coupled to that USB port is greater than the bus identifier of the USB device coupled to the previous USB port. Therefore, in this embodiment, the bus identifiers of the USB devices enumerated according to the port enumeration order are fixed each time the operating system wakes up, thus preventing confusion for upper-layer applications.

[0046] In some embodiments, the in-vehicle device can initialize a counter and a data structure. The counter records the number of USB devices coupled to the first i-1 USB ports, including the USB device coupled to the i-th USB port, USB devices coupled within the vehicle, and USB devices coupled to each of the first i-1 USB ports that are currently active. The data structure stores detailed information about each USB port and its coupled USB devices, such as the bus identifier. For example, the data structure can be a list or a dictionary.

[0047] After enabling the i-th USB port, the vehicle-mounted device can check if a USB device is coupled to the i-th USB port. If a USB device is coupled, a bus identifier is assigned to the USB device coupled to that port, and the USB device and its bus identifier are added to the data structure. A counter is incremented by 1. The bus identifier of the USB device coupled to the i-th USB port is greater than the bus identifier of the USB device coupled to the (i-1)-th USB port. For the first i-1 USB ports that are already enabled, if a USB device is coupled to each USB port, these USB devices should already be stored in the data structure. Therefore, the vehicle-mounted device can directly obtain the USB devices coupled to the first i-1 USB ports and their bus identifiers from the data structure, and determine the bus identifier of the USB device coupled to the (i-1)-th USB port as the bus identifier of the USB device coupled to the i-th USB port. In addition, the vehicle-mounted device can sum the number of USB devices coupled to the first i-1 USB ports recorded by the counter with the number of USB devices coupled to the currently determined i-th USB port to obtain the first number of USB devices coupled to the first i USB ports.

[0048] For example, if the counter records that the number of USB devices coupled to the first i-1 USB ports is 4, and the bus identifier of the USB device coupled to the (i-1)th USB port is Bus 004, then the bus identifier of the USB device coupled to the ith USB port is Bus 005. If the number of USB devices coupled to the ith USB port is determined to be 1, the vehicle-mounted device can determine that the first number of USB devices coupled to the first i USB ports = the number of USB devices coupled to the first i-1 USB ports + the number of USB devices coupled to the ith USB port = 4 + 1.

[0049] In step S103, if the first quantity meets the preset conditions, it is determined that the enumeration of the i-th USB port is complete.

[0050] Understandably, after the vehicle-mounted device obtains the first number after the i-th USB port is turned on, it determines whether the first number meets the preset conditions. If the first number meets the preset conditions, the vehicle-mounted device determines that the USB port enumeration is complete, and can increment the value of i by 1, and repeat the operation of steps S101 to S103 until the enumeration of n USB ports is completed.

[0051] In this embodiment, when the vehicle's operating system is in a woken-up state, the following steps are performed sequentially on each of the n USB ports configured on the vehicle according to a preset port enumeration order: the i-th USB port is turned on; the USB devices coupled to the first i USB ports are enumerated to determine a first number of USB devices coupled to the first i USB ports; if the first number meets a preset condition, the enumeration of the i-th USB port is considered complete. This application optimizes the USB port enumeration logic. After each sleep-wake cycle of the vehicle's operating system, each USB port is enumerated according to a fixed port enumeration order, with only one USB port turned on at a time. After the enumeration of that USB port is complete, the next USB port is turned on for enumeration. The method for determining whether enumeration is complete is to enumerate the number of USB devices currently coupled to the vehicle. If the number meets a preset condition, it indicates that the enumeration of the turned-on USB port is complete. In this way, the bus identifier of the USB devices of the sequentially enumerated USB ports is always fixed, thus avoiding misjudgment by the upper-layer application.

[0052] Figure 2 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment. Based on Figure 1 , Figure 1 The method may also include step S201, combining Figure 2 The steps shown are explained.

[0053] In step S201, if the difference between the first quantity and the second quantity is greater than or equal to a preset threshold, the first quantity is determined to meet the preset condition, and the second quantity is the number of USB devices coupled to the first i-1 USB ports.

[0054] Understandably, since the second quantity is the number of USB devices coupled to the first i-1 USB ports, the difference between the first quantity and the second quantity is calculated, which is the number of newly added USB devices. If the number of newly added USB devices is greater than or equal to a preset threshold, then the first quantity is determined to meet the preset condition. Based on this, the vehicle device can determine that the enumeration of the i-th USB port is complete.

[0055] Understandably, each USB port is coupled to a USB device. The vehicle-mounted device can preset a threshold, which is the maximum number of USB devices coupled to each USB port. When the vehicle-mounted device opens a USB port each time, it calculates the number of newly added USB devices. If the number of newly added USB devices is greater than or equal to the preset threshold, the vehicle-mounted device can determine that the enumeration of that USB port is complete.

[0056] For example, with a preset threshold of 2, after the vehicle-mounted device obtains that the number of USB devices coupled to the first i-1 USB ports (e.g., the second number) is 5, and determines that the enumeration of the (i-1)th USB port is complete, it opens the ith USB port for enumeration. If the enumerated number of USB devices coupled to the first i USB ports (e.g., the first number) is 7, the vehicle-mounted device can determine that the number of USB devices coupled to the first i USB ports and the number of USB devices coupled to the first i-1 USB ports are equal to the preset threshold, that is, it determines that the enumeration of the ith USB port is complete. Then, it can continue to open the (i+1)th USB port for enumeration.

[0057] In some embodiments, if a USB port does not increase the calculated first quantity compared to the second quantity after a USB device is connected, or if the difference between the calculated first quantity and the second quantity is much lower than a preset threshold, the vehicle device may consider that the USB port has a problem.

[0058] In some embodiments, the USB device coupled to the i-th USB port includes: an internal USB device virtualized by the i-th USB port and an external USB device coupled to the i-th USB port, with a preset threshold of 2.

[0059] Understandably, the virtual internal USB device associated with the i-th USB port is virtualized by the vehicle's operating system to achieve specific functions or testing purposes. This internal USB device is not directly physically connected to the USB port, but it is treated as a USB device coupled to that USB port at the system level. In some embodiments, the virtual internal USB device associated with the i-th USB port can be the i-th USB port itself; that is, the USB port itself is also a USB device. The external USB device coupled to the i-th USB port is the physical device actually plugged into the i-th port, such as a charging device, storage device, input device, etc. This external USB device communicates with the vehicle's USB port through a physical connection.

[0060] Understandably, if the USB devices coupled to the i-th USB port enumerated by the vehicle device include the i-th USB port itself and the external USB devices actually plugged into the i-th port, that is, if the number of newly added USB devices is determined to be 2, then the enumeration of the i-th USB port can be considered complete.

[0061] In some embodiments, the bus identifier of the internal USB device virtualized by the i-th USB port is the same as the bus identifier of the external USB device coupled to the i-th USB port.

[0062] In some embodiments, the bus identifier may include two parts: a bus number (Bus Identifier, Bus Id) and a device number (Device Identifier, Device Id). Therefore, the Bus Id of the internal USB device virtualized by the i-th USB port can be the same as the Bus Id of the external USB device coupled to the i-th USB port, while the Device Id of the internal USB device virtualized by the i-th USB port can be different from the Device Id of the external USB device coupled to the i-th USB port. This allows for the differentiation of different USB devices on the same bus. For example, the Bus Id of both the internal USB device virtualized by the i-th USB port and the external USB device coupled to the i-th USB port may be Bus 005, but the Device Id of the internal USB device virtualized by the i-th USB port may be Device 005, and the Device Id of the external USB device coupled to the i-th USB port may be Device 006.

[0063] In some embodiments, when the i-th USB port is enabled, the USB devices coupled to the i-th USB port may include, in addition to the i-th USB port itself and the external USB devices actually plugged into the i-th port, other bus devices (also referred to as USB devices) connected to the i-th USB port. In this case, the number of USB devices coupled to the enumerated first i USB ports and the number of USB devices coupled to the first i-1 USB ports is greater than a preset threshold of 2.

[0064] In some embodiments, when the USB device coupled to the i-th USB port includes other bus devices external to the i-th USB port, the bus identifier value assigned to the bus device by the vehicle device is different from the bus identifier values ​​of the i-th USB port itself and the external USB device actually plugged into the i-th port, in order to facilitate differentiation. Further, the Bus Id of the bus device can be set to be different from the Bus Id of the i-th USB port itself and the external USB device actually plugged into the i-th port. For example, if the Bus Id of the i-th USB port itself and the external USB device actually plugged into the i-th port is Bus 005, the Bus Id of the bus device external to the i-th USB port can be Bus 006.

[0065] In this embodiment, the vehicle-mounted device can determine that the enumeration of the i-th USB port is complete when the difference between the number of USB devices coupled to the first i USB ports and the number of USB devices coupled to the first i-1 USB ports is greater than or equal to a preset threshold. This method allows the vehicle-mounted device to monitor the connection status and the number of coupled USB devices for each USB port. When the number of newly added USB devices reaches the preset threshold, the vehicle-mounted device can respond immediately, thereby improving response speed and real-time performance. Moreover, by comparing the changes in the number of devices on different USB ports, abnormal connections or port failures can be detected more easily. In addition, the vehicle-mounted device can dynamically allocate and manage resources based on the number of USB devices coupled to each USB port. For example, if a USB port has a large number of coupled USB devices, the vehicle-mounted device can prioritize allocating more bandwidth or power resources to that USB port.

[0066] Figure 3 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment. Based on Figure 1 , Figure 1 The method may also include steps S301 to S304, which will be discussed below. Figure 3 The steps shown are explained.

[0067] In step S301, the status of the vehicle's operating system is obtained.

[0068] Understandably, in-vehicle equipment can first obtain the current state of the operating system, and then perform different operations based on the different states of the operating system.

[0069] In some embodiments, the in-vehicle device can view the current state of the operating system through the vehicle's own system. For example, the current state of the operating system can be obtained through the instrument panel or the central control display. For instance, some vehicles may display status information such as "system hibernation," "system wake-up," or "system running" on the instrument panel.

[0070] In some embodiments, the on-board device can query the current status of the operating system using vehicle diagnostic tools. For example, the current status of the operating system can be obtained through an On-Board Diagnostics (OBD) system or specialized diagnostic software. For instance, most vehicles are equipped with an OBD system, which can monitor the vehicle's operating status in real time and store fault information. By connecting an OBD diagnostic tool (such as a diagnostic tool or scanner), fault codes, system status information, etc., can be read to understand the vehicle's operating system's sleep, wake-up, or running status.

[0071] In some embodiments, the operating system may include a power attribute for the USB port, "sys.pateo.usbpower", which indicates the current state of the operating system. If the USB port's power state is declared as "sys.pateo.usbpower = 0", it indicates that the vehicle's operating system is in a hibernation state. If the USB port's power state is declared as "sys.pateo.usbpower = 1", it indicates that the vehicle's operating system is in a wake-up state. The in-vehicle device can determine the current state of the operating system by obtaining this attribute.

[0072] In step S302, when the state is in hibernation mode, n USB ports are turned off.

[0073] Understandably, each time a vehicle's operating system wakes up from sleep mode, it re-enumerates each USB device connected via a USB port. Therefore, if the onboard device detects that the operating system is currently in sleep mode, the enumeration operation will not be triggered, and the onboard device can then disable all USB ports in the vehicle. Disabling USB ports saves power and prevents unnecessary device communication or data exchange during sleep mode.

[0074] In step S303, when the state changes from sleep state to wake state, the USB devices coupled inside the vehicle are enumerated to obtain a third number of USB devices.

[0075] Understandably, once the in-vehicle device obtains that the operating system is currently awake, it can begin the enumeration operation. As mentioned earlier, there are also some bus devices inside the vehicle. Therefore, in this embodiment of the application, before opening the USB port, the in-vehicle device can first enumerate the USB devices coupled inside the vehicle to obtain the number of USB devices coupled inside the vehicle.

[0076] In some embodiments, the in-vehicle device enumerates the USB devices coupled to the vehicle interior and assigns a bus identifier to each enumerated USB device coupled to the vehicle interior.

[0077] In some embodiments, the USB devices coupled inside the vehicle are multiple USB devices, the multiple USB devices have the same bus identifier number, and the bus identifier number is less than the bus identifier number of the USB device coupled to the first USB port.

[0078] Understandably, the earlier a USB device is enumerated, the smaller its bus ID will be. Therefore, the bus ID of the enumerated USB devices coupled within the vehicle is smaller than the bus ID of the USB device coupled to the first USB port. For example, the Bus ID of the enumerated USB devices coupled within the vehicle is Bus 001, and the Bus ID of the USB device coupled to the first USB port is Bus 002.

[0079] In some embodiments, when there are multiple USB devices coupled inside the vehicle, each USB device coupled inside the vehicle has the same Bus ID but a different Device ID, which can distinguish different devices under the same bus. For example, if there are three USB devices coupled inside the vehicle, the Bus ID of these three USB devices can all be Bus 001, but the Device IDs are different. For example, the Device IDs of the three USB devices can be Device 001, Device 002, and Device 003, respectively.

[0080] In step S304, after the enumeration of USB devices coupled inside the vehicle is completed, the first USB port is opened according to the port enumeration order.

[0081] In some embodiments, after enumerating all USB devices coupled to the vehicle interior and their quantities, the in-vehicle device can start enumerating the first USB port according to a preset port enumeration order. In this case, the in-vehicle device determines that the first USB port enumeration is complete by comparing the difference between the number of USB devices currently coupled to the vehicle and the previously calculated number of USB devices coupled to the vehicle interior (such as a third number) with a preset threshold.

[0082] In this embodiment, the in-vehicle device can obtain the current state of the vehicle's operating system. When the current state is in sleep mode, all USB ports are turned off to save power. When the current state changes from sleep mode to wake-up mode, the number of USB ports coupled inside the vehicle is enumerated, and after the enumeration is completed, the first USB port is turned on for enumeration according to the port enumeration order. By monitoring the current state of the operating system, the in-vehicle device can intelligently manage USB ports to optimize power consumption.

[0083] Figure 4 This is an optional flowchart illustrating the USB port enumeration method provided in this application embodiment. Based on Figure 2 , Figure 2 The method may further include steps S401 to S402, combining Figure 4 The steps shown are explained.

[0084] In step S401, if it is determined that the first quantity does not meet the preset condition, the USB devices coupled to the first i USB ports of the vehicle are repeatedly enumerated.

[0085] In some embodiments, if the number of USB devices coupled to the first i USB ports (such as a first number) does not meet a preset condition, that is, the difference between the number of USB devices coupled to the first i USB ports and the number of USB devices coupled to the first i-1 USB ports is less than a preset threshold, the vehicle device can initialize the i-th port and re-enumerate the USB devices coupled to the first i USB ports.

[0086] It is understandable that when a USB port is opened for the initial enumeration, temporary faults such as the USB device failing to respond correctly or the USB device connection being unstable may cause the number of USB devices enumerated initially to not meet the preset conditions. Therefore, the vehicle equipment can close and reopen the USB port to re-enumerate in order to eliminate these temporary faults.

[0087] In step S402, if the number of times the first quantity does not meet the preset condition reaches a preset number, it is determined that the USB device coupled to the i-th USB port has failed.

[0088] Understandably, if the number of USB devices coupled to the i-th USB port obtained in the initial enumeration does not meet the preset condition, and this failure occurs a preset number of times, the vehicle-mounted device can determine that the USB device connected to the i-th USB port is faulty. At this time, the vehicle-mounted device can prompt the user that the USB device is faulty and needs to be repaired or replaced.

[0089] In some embodiments, the in-vehicle device can set a preset number of times. If the number of times the first quantity fails to meet the preset condition reaches the preset number, the USB device coupled to the i-th USB port is considered to be faulty. Based on this, when the in-vehicle device first determines that the first quantity fails to meet the preset condition, it can set a counter to record the number of times the preset condition is not met; at this time, the counter value is 1. Then, the in-vehicle device can turn the i-th USB device off and on again to re-enumerate the first quantity and calculate whether the first quantity meets the preset condition. If the first quantity meets the preset condition at this time, the in-vehicle device can determine that the enumeration of the i-th USB port is complete. If the first quantity still does not meet the condition at this time, the counter value is incremented by 1, and the enumeration is repeated until the number of times the first quantity fails to meet the preset condition reaches the preset number, at which point the in-vehicle device determines that the USB device connected to the i-th USB port has failed.

[0090] In one example, when the vehicle transitions from sleep to wake-up mode, the enumeration result of all USB ports before they are enabled is: Bus 001Device 001:ID 1d6b:0002, where Bus 001 is the bus number, Device 001 is the device number, 1d6b is the manufacturer identifier, and 0002 is the product identifier. With USB port 0 being the first USB port in the port enumeration order, the enumeration result after USB port 0 is enabled is: Bus 003Device 001:ID 1d6b:0003, Bus 002Device 002:ID 24a9:205a, Bus 001Device 001:ID 1d6b:0002, Bus 002Device 001:ID 1d6b:0002. Based on the above enumeration results, it can be seen that before USB port 0 is enabled, the number of enumerated USB devices (1d6b:0002) coupled to the vehicle interior is 1, and the bus number of this USB device is Bus 001. After USB port 0 is enabled, the bus number of the USB device (1d6b:0002) coupled to the vehicle interior remains Bus 001. After USB port 0 is enabled, three new USB devices are added, and the bus numbers of these three new USB devices are all greater than the bus numbers of the USB devices coupled to the vehicle interior. Among the new USB devices, USB device (1d6b:0002) is USB port 0 itself, USB device (24a9:205a) is an external USB device plugged into USB port 0, and USB device (1d6b:0003) may be another device connected to USB port 0.

[0091] In this embodiment, if the number of USB devices coupled to the first i USB ports (the first number) does not meet a preset condition, the vehicle-mounted device repeatedly enumerates the USB devices coupled to the first i USB ports. If the number of times the first number fails to meet the preset condition reaches a preset number, it is determined that the USB device coupled to the i-th USB port is faulty. In this embodiment, when the number of USB devices enumerated for a particular USB port does not meet the preset condition, to rule out temporary faults, the enumeration is repeated. If the preset condition is still not met after multiple repeated enumerations, it is determined that the problem is caused by a USB device fault. By repeatedly enumerating, the scope of the problem can be gradually narrowed down, eventually pointing to a possible hardware fault point. This helps to ensure that the vehicle-mounted device can accurately and reliably identify and manage connected USB devices.

[0092] Based on the foregoing embodiments, this application provides a USB port enumeration device. The modules and units included in the device can be implemented by a processor in a computer device; of course, they can also be implemented by specific logic circuits. In the implementation process, the processor can be a central processing unit (CPU), a microprocessor unit (MPU), a digital signal processor (DSP), or a field programmable gate array (FPGA), etc.

[0093] Reference Figure 5 , Figure 5 This is a schematic diagram of the composition structure of a USB port enumeration device provided in an embodiment of this application. The USB port enumeration device 500 includes: a port opening module 501, an enumeration module 502, and a determination module 503. When the vehicle's operating system is in a wake-up state, the following steps are performed sequentially on each of the n USB ports configured on the vehicle according to a preset port enumeration order, where n is the total number of USB ports configured on the vehicle and is a positive integer. Each USB port is coupled to a USB device: the port opening module 501 is used to open the i-th USB port, where i is an integer greater than 0 and less than n; the enumeration module 502 is used to enumerate... The first number of USB devices is determined by identifying the USB devices coupled to the first i USB ports of the vehicle. The first number of USB devices coupled to the first i USB ports includes at least the USB device coupled to the i-th USB port, the USB devices coupled inside the vehicle, and the USB devices coupled to each of the first i-1 USB ports that are already enabled. The order of the bus identifiers of the USB devices coupled to the USB ports is positively correlated with the port enumeration order. The bus identifier is used to identify the vehicle bus to which the USB device coupled to the USB port is connected. The determining module 503 is used to determine that the enumeration of the i-th USB port is complete when the first number satisfies a preset condition.

[0094] In some embodiments, the determining module 503 is further configured to: determine that the first quantity satisfies a preset condition when the difference between the first quantity and the second quantity is greater than or equal to a preset threshold, wherein the second quantity is the number of USB devices coupled to the first i-1 USB ports.

[0095] In some embodiments, the USB device coupled to the i-th USB port includes: an internal USB device virtualized by the i-th USB port and an external USB device coupled to the i-th USB port, with a preset threshold of 2.

[0096] In some embodiments, the apparatus further includes a module for performing the following operations: obtaining the state of the vehicle's operating system; closing n USB ports when the state is in a hibernation state; enumerating the USB devices coupled to the vehicle interior to obtain a third number of USB devices when the state changes from hibernation to wake-up; and after the enumeration of the USB devices coupled to the vehicle interior is completed, opening the first USB port in the order of port enumeration.

[0097] In some embodiments, the USB devices coupled inside the vehicle are multiple USB devices, the multiple USB devices have the same bus identifier number, and the bus identifier number is less than the bus identifier number of the USB device coupled to the first USB port.

[0098] In some embodiments, the determining module 503 is further configured to: repeatedly enumerate the USB devices coupled to the first i USB ports of the vehicle when the first quantity does not meet the preset condition; and determine that the USB device coupled to the i-th USB port has failed when the number of times the first quantity does not meet the preset condition reaches a preset number.

[0099] The descriptions of the apparatus embodiments above are similar to those of the method embodiments above, and have similar beneficial effects. In some embodiments, the functions or modules included in the apparatus provided in this application can be used to perform the methods described in the method embodiments above. For technical details not disclosed in the apparatus embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0100] It should be noted that, in the embodiments of this application, if the above-mentioned USB port enumeration method is implemented as a software functional module and sold or used as an independent product, it can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the embodiments of this application, or the part that contributes to the related technology, can be embodied in the form of a software product. This software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, mobile hard drives, read-only memory (ROM), magnetic disks, or optical disks. Thus, the embodiments of this application are not limited to any specific hardware, software, or firmware, or any combination of hardware, software, and firmware.

[0101] This application provides an in-vehicle device, including a memory and a processor. The memory stores a computer program that can run on the processor, and the processor executes the program to implement the steps in the above-described method.

[0102] This application provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps in the above-described method. The computer-readable storage medium can be transient or non-transient.

[0103] This application provides a computer program including computer-readable code, wherein when the computer-readable code is executed in a computer device, a processor in the computer device performs steps for implementing the method described above.

[0104] This application provides a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program. When the computer program is read and executed by a computer, it implements the steps in the above-described method. This computer program product can be implemented specifically through hardware, software, or a combination thereof. In some embodiments, the computer program product is specifically embodied as a computer storage medium; in other embodiments, the computer program product is specifically embodied as a software product, such as a software development kit (SDK), etc.

[0105] It should be noted that the descriptions of the various embodiments above tend to emphasize the differences between them, while their similarities or commonalities can be referenced interchangeably. The descriptions of the vehicle-mounted device, storage medium, computer program, and computer program product embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the vehicle-mounted device, storage medium, computer program, and computer program product embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0106] Figure 6 This is a schematic diagram of the hardware entity of an in-vehicle device provided in an embodiment of this application, such as... Figure 6 As shown, the vehicle-mounted device 600 may include: a memory 610, at least one processor 620, an external device interface 630, and a user interface 640. The various components in the vehicle-mounted device 600 are coupled together via a bus system. It is understood that the bus system is used to enable communication and connection between these components.

[0107] The processor 620 can be an integrated circuit chip with signal processing capabilities, such as a general-purpose processor, DSP, or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor can be a microprocessor or any conventional processor.

[0108] External device interface 630 includes input / output subsystem 631, wherein input / output subsystem 631 includes touch screen controller 6311 and multiple USB ports. Figure 6 The example uses three USB ports, USB-PORT0, USB-PORT1, and USB-PORT2.

[0109] User interface 640 includes multiple input / output devices that enable the presentation of media content. Figure 6 The following describes the device as an example: a touchscreen 641, a multimedia USB flash drive 642, a DVR USB flash drive 643, and a TBOX 644. Specifically, the touchscreen controller 6311 corresponds to the touchscreen 641; the external USB device coupled to USB-PORT0 6312 is the multimedia USB flash drive 642; the external USB device coupled to USB-PORT1 6313 is the DVR USB flash drive 643; and the external USB device coupled to USB-PORT2 6314 is the TBOX 644.

[0110] The memory 610 may be removable, non-removable, or a combination thereof. Exemplary hardware devices include solid-state storage, hard disk drives, optical disk drives, etc. The memory 610 may optionally include one or more storage devices physically located away from the processor 620.

[0111] The memory 610 may include volatile memory or non-volatile memory, or both. The non-volatile memory may be ROM, and the volatile memory may be random access memory (RAM). The memory 610 described in this application embodiment is intended to include any suitable type of memory.

[0112] In some embodiments, memory 610 is capable of storing data to support various operations, examples of which include programs, modules, and data structures or subsets or supersets thereof, as illustrated below.

[0113] Operating system 611 includes system programs for handling various basic system services and performing hardware-related tasks, such as a framework layer, core library layer, and driver layer, for implementing various basic business functions and handling hardware-based tasks; network communication module 612 for reaching other computing devices via one or more (wired or wireless) network interfaces, exemplary network interfaces including Bluetooth, WiFi, and USB; presentation module 613 for enabling the presentation of information via one or more output devices (e.g., display screen, speaker, etc.) associated with the user interface; and input processing module 614 for detecting and translating one or more user inputs or interactions from one or more input devices.

[0114] In some embodiments, the apparatus provided in this application can be implemented in software. Figure 6 A USB port enumeration device 500 stored in memory 610 is shown. The USB port enumeration device 500 can be software in the form of programs and plug-ins.

[0115] In other embodiments, the apparatus provided in this application can be implemented in hardware. For example, the apparatus provided in this application can be a processor in the form of a hardware decoding processor, programmed to execute the USB port enumeration method provided in this application. For instance, the processor in the form of a hardware decoding processor can employ one or more application-specific integrated circuits (ASICs), DSPs, programmable logic devices (PLDs), complex programmable logic devices (CPLDs), FPGAs, or other electronic components.

[0116] This application provides a computer storage medium storing one or more programs that can be executed by one or more processors to implement the steps of the USB port enumeration method as described in any of the above embodiments.

[0117] It should be noted that the descriptions of the storage medium and device embodiments above are similar to the descriptions of the method embodiments above, and have similar beneficial effects. For technical details not disclosed in the storage medium and device embodiments of this application, please refer to the descriptions of the method embodiments of this application for understanding.

[0118] The aforementioned computer storage media / memory can be ROM, Programmable Read-Only Memory (PROM), Erasable Programmable Read-Only Memory (EPROM), Electrically Erasable Programmable Read-Only Memory (EEPROM), Ferromagnetic Random Access Memory (FRAM), Flash Memory, Magnetic Surface Memory, Optical Disc, or Compact Disc Read-Only Memory (CD-ROM), etc.; or it can be various terminals that include one or any combination of the above-mentioned memories, such as mobile phones, computers, tablet devices, personal digital assistants, etc.

[0119] It should be understood that the phrase "one embodiment" or "an embodiment" throughout the specification means that a specific feature, structure, or characteristic related to the embodiment is included in at least one embodiment of this application. Therefore, "in one embodiment" or "in an embodiment" appearing throughout the specification does not necessarily refer to the same embodiment. Furthermore, these specific features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. It should be understood that in the various embodiments of this application, the sequence numbers of the above steps / processes do not imply a sequential order of execution; the execution order of each step / process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application. The sequence numbers of the above embodiments of this application are merely descriptive and do not represent the superiority or inferiority of the embodiments.

[0120] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0121] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods, such as: multiple units or components can be combined, or integrated into another system, or some features can be ignored or not executed. In addition, the coupling, direct coupling, or communication connection between the various components shown or discussed can be through some interfaces, and the indirect coupling or communication connection between devices or units can be electrical, mechanical, or other forms.

[0122] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units. They may be located in one place or distributed across multiple network units. Some or all of the units may be selected based on actual needs to achieve the purpose of this embodiment.

[0123] In addition, each functional unit in the various embodiments of this application can be integrated into one processing unit, or each unit can be a separate unit, or two or more units can be integrated into one unit; the integrated unit can be implemented in hardware or in the form of hardware plus software functional units.

[0124] Those skilled in the art will understand that all or part of the steps of the above method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, it performs the steps of the above method embodiments. The aforementioned storage medium includes various media that can store program code, such as mobile storage devices, ROMs, magnetic disks, or optical disks.

[0125] Alternatively, if the integrated units described above are implemented as software functional modules and sold or used as independent products, they can also be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence or the part that contributes to related technologies, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as mobile storage devices, ROM, magnetic disks, or optical disks.

[0126] The above description is merely an embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A method for enumerating USB ports on a universal serial bus, characterized in that, The method includes: With the vehicle's operating system awake, the following steps are executed sequentially on each of the n USB ports configured on the vehicle, according to a preset port enumeration order, where n is the total number of USB ports configured on the vehicle, n is a positive integer, and each USB port is coupled to a USB device: Open the i-th USB port, where i is an integer greater than 0 and less than n; The USB devices coupled to the first i USB ports of the vehicle are enumerated to determine a first number of USB devices coupled to the first i USB ports. The USB devices coupled to the first i USB ports include at least the USB devices coupled to the i-th USB port, the USB devices coupled inside the vehicle, and the USB devices coupled to each of the first i-1 USB ports that are already enabled. The order of the bus identifiers of the USB devices coupled to the USB ports is positively correlated with the port enumeration order. The bus identifiers are used to identify the vehicle bus to which the USB devices coupled to the USB ports are connected. If the first quantity meets the preset conditions, the enumeration of the i-th USB port is determined to be complete.

2. The method according to claim 1, characterized in that, The method further includes: If the difference between the first quantity and the second quantity is greater than or equal to a preset threshold, the first quantity is determined to satisfy the preset condition, and the second quantity is the number of USB devices coupled to the first i-1 USB ports.

3. The method according to claim 2, characterized in that, The USB devices coupled to the i-th USB port include: an internal USB device virtualized by the i-th USB port and an external USB device coupled to the i-th USB port, and the preset threshold is 2.

4. The method according to claim 1, characterized in that, The method further includes: Obtain the status of the vehicle's operating system; When the state is in sleep mode, the n USB ports are turned off; When the state changes from the sleep state to the wake state, the USB devices coupled inside the vehicle are enumerated to obtain a third number of the USB devices; After the enumeration of USB devices coupled inside the vehicle is completed, the first USB port is opened according to the port enumeration order.

5. The method according to claim 4, characterized in that, The USB devices coupled inside the vehicle are multiple USB devices, and the multiple USB devices have the same bus identifier number, which is less than the bus identifier number of the USB device coupled to the first USB port.

6. The method according to claim 1, characterized in that, The method further includes: If it is determined that the first quantity does not meet the preset condition, the USB devices coupled to the first i USB ports of the vehicle are repeatedly enumerated. If the number of times the first quantity fails to meet the preset condition reaches a preset number, it is determined that the USB device coupled to the i-th USB port has malfunctioned.

7. A Universal Serial Bus (USB) port enumeration device, characterized in that, The device includes: With the vehicle's operating system awake, the following steps are executed sequentially on each of the n USB ports configured on the vehicle, according to a preset port enumeration order, where n is the total number of USB ports configured on the vehicle, n is a positive integer, and each USB port is coupled to a USB device: The port opening module is used to open the i-th USB port, where i is an integer greater than 0 and less than n; An enumeration module is used to enumerate the USB devices coupled to the first i USB ports of the vehicle to determine a first number of USB devices coupled to the first i USB ports. The USB devices coupled to the first i USB ports include at least the USB devices coupled to the i-th USB port, the USB devices coupled inside the vehicle, and the USB devices coupled to each of the first i-1 USB ports that are already open. The order of the bus identifiers of the USB devices coupled to the USB ports is positively correlated with the port enumeration order. The bus identifier is used to identify the vehicle bus to which the USB devices coupled to the USB ports are connected. The determining module is used to determine that the enumeration of the i-th USB port is complete when the first quantity meets the preset conditions.

8. An in-vehicle device, comprising a memory and a processor, wherein the memory stores a computer program executable on the processor, characterized in that, When the processor executes the program, it implements the steps of the method according to any one of claims 1 to 6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the method according to any one of claims 1 to 6.

10. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 6.