Communication method of vehicle-mounted software and vehicle-mounted unit and vehicle-mounted equipment
By integrating multiple types of messages into a message body and using multiple child threads to process tasks, the high concurrency problem of on-board software when receiving large amounts of data is solved, the fluency and responsiveness of the UI interface are achieved, and the on-board software is ensured. efficient communication.
Patent Information
- Application Number
- CN202410949218.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-15
- Publication Date
- 2024-11-12
AI Technical Summary
Car software faces high concurrency problems when receiving large amounts of data and information, resulting in UI interface lag or crash, insufficient performance, and inability to process messages in time.
The communication method between in-vehicle software and in-vehicle units is adopted, and the message queue is queued by integrating multiple types of message bodies, and multiple child threads are used for processing. The task results are refreshed through the main thread to ensure the responsiveness of the UI interface.
It realizes efficient and stable message processing, solves the problem of high concurrency of messages, ensures the fluency and responsiveness of the UI interface, and can handle a large number of messages in real time.
Smart Images

Figure CN118939449A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of vehicle-mounted technology, and in particular to a communication method between vehicle-mounted software and a vehicle-mounted unit and a vehicle-mounted device. Background Art
[0002] With the continuous development of Intelligent Transportation Systems (ITS), On Board Unit (OBU) is an indispensable part of ITS, responsible for communicating with Road Side Unit (RSU) and receiving road information data.
[0003] Through the communication between the OBU and the vehicle-mounted software in the vehicle equipment or mobile terminals (such as tablets and mobile phones) in the vehicle, the road information data can be displayed to the driver in real time using the Human-Machine Interface (HMI).
[0004] Due to the complexity of actual road conditions, a single OBU will send a large amount of data information at the same time, and the in-vehicle software faces the problem of high concurrency when receiving messages. The massive amount of data will seriously affect the performance of the vehicle equipment or the mobile terminal in the vehicle. The CPU's computing and data processing capabilities and the GPU's UI drawing capabilities in the vehicle equipment or the mobile terminal in the vehicle face huge challenges. General equipment configurations are difficult to meet the requirements, which directly leads to insufficient performance, untimely message processing, and stuck UI interfaces of the in-vehicle software, and even stuck and crashed in the vehicle software. Summary of the invention
[0005] The technical problem to be solved by the present invention is that, in view of at least one defect of the related technology mentioned in the above background technology: the vehicle-mounted software faces the problem of high concurrency in receiving messages, and the vehicle-mounted software fails to process messages in a timely manner, resulting in a freeze in its UI interface, and a communication method and a vehicle-mounted device are provided between the vehicle-mounted software and the vehicle-mounted unit.
[0006] The technical solution adopted by the present invention to solve the technical problem is: constructing a communication method between the vehicle-mounted software and the vehicle-mounted unit, which is applied to the vehicle-mounted software and includes the following steps:
[0007] Establishing a communication connection with the vehicle-mounted unit;
[0008] receiving a message body sent by the vehicle-mounted unit, wherein the message body has integrated multiple types of messages;
[0009] Enqueue the message body into a message queue;
[0010] Add the message queue to the task stack of the thread pool and start multiple child threads for processing;
[0011] The task results processed by multiple sub-threads are used to refresh the UI interface through the main thread.
[0012] Preferably, in the method for communicating between the vehicle-mounted software and the vehicle-mounted unit of the present invention, the communication connection with the vehicle-mounted unit includes:
[0013] Connecting to a wireless network emitted by the vehicle-mounted unit;
[0014] The onboard unit is connected according to the IP and port of the onboard unit.
[0015] Preferably, in the communication method between the vehicle-mounted software and the vehicle-mounted unit of the present invention, receiving the message body sent by the vehicle-mounted unit includes:
[0016] The message body sent by the vehicle-mounted unit is received at a preset frequency, where the preset frequency is the same as the frequency at which the vehicle-mounted unit sends the message body.
[0017] Preferably, in the communication method between the vehicle-mounted software and the vehicle-mounted unit of the present invention, the identifier of the message body is a preset identifier, and the message content of the message body includes a character string containing multiple types of messages, and the multiple types of messages include at least two of the vehicle message, other vehicle message, vulnerable traffic participant message, road sign message, traffic light message and warning message;
[0018] The communication method between the vehicle-mounted software and the vehicle-mounted unit also includes:
[0019] After determining that the identifier of the message body is the preset identifier, the message body is entered into a message queue for processing.
[0020] Preferably, in the method for communicating between the vehicle-mounted software and the vehicle-mounted unit of the present invention, the message body is enqueued into a message queue, and before that, the method further includes: creating the message queue.
[0021] Preferably, in the method for communicating between the vehicle-mounted software and the vehicle-mounted unit of the present invention, the message body is processed by entering a message queue, including:
[0022] The message body is parsed into an executable format and placed into the message queue.
[0023] Preferably, in the communication method between the vehicle-mounted software and the vehicle-mounted unit described in the present invention, the message queue is added to the task stack of the thread pool, and multiple sub-threads are started for processing, which also includes: creating the thread pool, and the thread pool includes multiple sub-threads.
[0024] Preferably, in the communication method between the vehicle-mounted software and the vehicle-mounted unit described in the present invention, the message queue is added to the task stack of the thread pool, and multiple sub-threads are started for processing, including:
[0025] Taking the message body from the message queue and encapsulating it into a task, wherein the task includes message parsing and processing logic;
[0026] The task is submitted to the task stack of the thread pool, and the tasks in the task stack are executed concurrently by multiple sub-threads.
[0027] Preferably, in the method for communicating between the vehicle-mounted software and the vehicle-mounted unit of the present invention, refreshing the UI interface through the main thread using the task results processed by the multiple sub-threads includes:
[0028] Create a Handler object;
[0029] The Handler object is used to send the task results processed by the multiple sub-threads to the main thread for execution, so as to refresh the UI interface.
[0030] The present invention also constructs a vehicle-mounted device, comprising:
[0031] one or more processors;
[0032] A storage device is used to store one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the communication method between the vehicle-mounted software and the vehicle-mounted unit described in any one of the above items.
[0033] By implementing the present invention, the following beneficial effects are achieved:
[0034] The present invention provides a set of efficient and stable communication solutions between vehicle-mounted software and vehicle-mounted units, which solves the problem of high message concurrency by integrating multiple types of messages into one message body. In addition, multiple sub-threads execute time-consuming tasks, and UI interface refresh is only executed in the main thread, so a large number of messages from the vehicle-mounted unit can be processed in real time and efficiently, and the entire processing process ensures the responsiveness of the UI interface, making the UI interface of the vehicle-mounted software smoother. BRIEF DESCRIPTION OF THE DRAWINGS
[0035] The present invention will be further described below with reference to the accompanying drawings and embodiments, in which:
[0036] Figure 1 The flow chart of the communication method between the vehicle-mounted software and the vehicle-mounted unit according to an embodiment of the present invention is shown as follows Figure 1 ;
[0037] Figure 2A flow chart showing step S10 in a method for communicating between vehicle-mounted software and a vehicle-mounted unit according to an embodiment of the present invention is shown;
[0038] Figure 3 The flow chart of the communication method between the vehicle-mounted software and the vehicle-mounted unit according to an embodiment of the present invention is shown as follows Figure 2 ;
[0039] Figure 4 A flow chart showing step S40 in a method for communicating between vehicle-mounted software and a vehicle-mounted unit according to an embodiment of the present invention is shown;
[0040] Figure 5 A flow chart showing step S50 in a method for communicating between vehicle-mounted software and a vehicle-mounted unit according to an embodiment of the present invention is shown;
[0041] Figure 6 A logical structure diagram of a vehicle-mounted device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0042] In order to have a clearer understanding of the technical features, purposes and effects of the present invention, specific embodiments of the present invention are now described in detail with reference to the accompanying drawings.
[0043] It should be noted that the flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor do they have to be executed in the order described. For example, some operations / steps can be decomposed, while some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0044] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0045] like Figure 1 As shown, an embodiment of the present invention discloses a method for communicating between vehicle-mounted software and a vehicle-mounted unit, which is applied to vehicle-mounted software on a vehicle-mounted device, for example, the vehicle-mounted device is a vehicle-mounted device or an in-vehicle mobile terminal (such as a tablet computer and a mobile phone). The communication method includes the following steps:
[0046] S10: Communicate and connect with the vehicle-mounted unit;
[0047] S20: receiving a message body sent by the vehicle-mounted unit, in which multiple types of messages have been integrated;
[0048] S30: put the message body into the message queue for processing;
[0049] S40: adding the message queue to the task stack of the thread pool, and starting multiple child threads for processing;
[0050] S50: Refreshing the UI interface through the main thread using the task results processed by the multiple sub-threads.
[0051] In some embodiments, Figure 2 As shown, step S10: communicating with the vehicle-mounted unit, including:
[0052] S101: Connect to the wireless network sent by the vehicle-mounted unit;
[0053] S102: Connect to the onboard unit according to the IP and port of the onboard unit.
[0054] Specifically, based on the TCP / IP protocol stack, the on-board software connects to the wireless network emitted by the on-board unit through WIFI, so that the on-board software and the on-board unit are in the same local area network, so that it can connect to the IP and port of the on-board unit, and then the on-board software sends a connection request to the on-board unit through InetSocketAddress according to the IP and port of the on-board unit. After the on-board unit agrees to the connection, the on-board unit sends the message body. Among them, there are two ways to obtain the IP and port of the on-board unit. One is to pre-define the IP and port of the on-board unit when developing the on-board software. The other is that the on-board unit informs the set IP and port, and the on-board software receives the IP and port of the on-board unit input manually.
[0055] In some embodiments, receiving a message body sent by the vehicle-mounted unit in step S20 includes:
[0056] Receive the message body sent by the vehicle-mounted unit at a preset frequency, and the preset frequency is the same as the frequency at which the vehicle-mounted unit sends the message body. For example, after the vehicle-mounted unit agrees to connect, the vehicle-mounted unit continuously sends the message body to the vehicle-mounted software at a frequency of 10HZ, and the vehicle-mounted software also reads the message body at a frequency of 10HZ, and processes and warns each time a message body is read. The vehicle-mounted software refreshes its UI interface every 100ms. The 10HZ and 100ms here are only examples and are not intended to limit this application.
[0057] In some embodiments, the identifier of the message body is a preset identifier (such as "OBU"), and the message content of the message body includes a string (such as a JSON string) containing multiple types of messages, and the multiple types of messages include at least two of the vehicle message, other vehicle message, vulnerable traffic participant message, road sign message, traffic light message and warning message, which are very important for the driver to make correct driving decisions, avoid potential dangers, and improve driving safety and efficiency. The "OBU" and JSON string here are only examples and are not intended to limit the present application.
[0058] Accordingly, the communication method further includes:
[0059] S22: After determining that the identifier of the message body is a preset identifier, executing step S30: enqueuing the message body into a message queue.
[0060] This embodiment integrates multiple types of messages into one message body regardless of how many connected vehicles and vulnerable traffic participants there are on the roadside. This solves the problem of reduced performance processing of vehicle equipment or mobile terminals in the vehicle and delays and freezes in the UI interface of the vehicle-mounted software when there are a large number of other connected vehicles, a large number of road signs and a large number of vulnerable traffic participants. It avoids the problem of high concurrency of messages occurring in the same millisecond and makes the UI interface of the vehicle-mounted software smoother.
[0061] The vehicle message includes at least one of coordinates, heading angle, speed and vehicle type. The vehicle message is used to display the vehicle on the map and display the moving status in real time.
[0062] The other vehicle message also includes at least one of the coordinates, heading angle, speed and vehicle type. The other vehicle message is used to display other connected vehicles on the map and show the movement status in real time.
[0063] The vulnerable traffic participant message includes the coordinates and direction of the vulnerable traffic participant. The vulnerable traffic participant message is used to display the vulnerable traffic participant (such as at least one of roadside pedestrians, bicycles and motorcycles) on the map and show the movement status in real time.
[0064] The road sign message is used to display road signs (such as at least one of a speed limit sign, a tunnel sign, a school sign, a sharp turn sign, an obstacle sign and a slippery road sign) on the map and provide prompts.
[0065] The traffic light message includes at least one of a traffic light countdown, traffic light information of the lane, and a recommended vehicle speed. The traffic light message is used to prompt the traffic light situation and is displayed on the map.
[0066] The warning messages include at least one of forward collision warning, left and right blind spot warning, overtaking warning, vehicle merging warning, speed limit warning, red light running warning, vehicle failure warning, rear emergency vehicle warning, rear special vehicle warning and left and right lane change warning. The warning messages are used to prompt warnings and are displayed on the map, so that drivers can better prevent accidents and have a better driving experience.
[0067] In some embodiments, Figure 3 As shown, step S30: the message body is queued for processing, which also includes:
[0068] S21: Create a message queue. For example, choose BlockingQueue (such as ArrayBlockingQueue, LinkedBlockingQueue) as the message queue. It is a thread-safe queue that supports blocking operations, which means that when the queue is empty, the thread that gets elements from the queue will wait (block) until an element is put into the queue; similarly, when the queue is full, the thread that adds elements to the queue will also wait until there is enough space in the queue.
[0069] In some embodiments, step S30: processing the message body into a message queue includes:
[0070] Parse the message body into its executable format and put it into the message queue.
[0071] In some embodiments, such as Figure 3 As shown, step S40: adding the message queue to the task stack of the thread pool, starting multiple child threads for processing, and before that also includes:
[0072] S31: Create a thread pool, which includes multiple child threads. For example, use ExecutorService (such as FixedThreadPool, CachedThreadPool or SingleThreadExecutor) to create a thread pool. The size of the thread pool is determined according to the application requirements and the performance of the device. After completing the task, the child thread will not be destroyed immediately, but will return to the thread pool to wait for the execution of a new task, which can reduce the overhead of thread creation and destruction. This embodiment creates a MainThreadExecutor thread pool, which is only an example and is not intended to limit this application.
[0073] In some embodiments, such as Figure 4 As shown, step S40: adding the message queue to the task stack of the thread pool, and starting multiple child threads for processing, including:
[0074] S401: Take the message body from the message queue and encapsulate it into a task (such as a Runnable or Callable task), which contains the message parsing and processing logic. Among them, Runnable and Callable are interfaces, which define a task to be executed by a thread, and can contain the code logic that needs to be parsed and processed. Encapsulation is for decoupling. After encapsulation, the message parsing and processing logic can be decoupled from the message acquisition and distribution logic. Secondly, the same message parsing and processing logic can be reused by multiple threads, which improves the reusability of the code. After encapsulation, it is more flexible and can dynamically add, modify or delete message parsing and processing logic according to actual needs;
[0075] S402: Submit the task to the task stack of the thread pool, and multiple child threads concurrently execute the tasks in the task stack, so as to avoid the main thread from executing time-consuming tasks (such as downloading maps and complex calculations, etc.), so as not to block the main thread and cause the UI interface to freeze. Optionally, the tasks in the task stack can be executed in sequence and / or priority.
[0076] In some embodiments, such as Figure 5 As shown, step S50: refreshing the UI interface through the main thread using the task results processed by the multiple sub-threads, including:
[0077] S501: Create a Handler object;
[0078] S502: Using the Handler object to send the task results processed by the multiple sub-threads to the main thread for execution, so as to refresh the UI interface. The use of the Handler object can ensure the security of UI interface update, and the UI interface refresh can only be updated on the main thread.
[0079] Specifically, a thread (main thread or child thread) can create many Handler objects. A thread (main thread or child thread) has only one Looper object and one MessageQueue message queue. Each Handler object needs to be bound to the Looper object. Multiple Handler objects can be bound to the same Looper object. Each Looper object corresponds to a MessageQueue message queue. The tasks or task results sent by the Handler object will be added to the MessageQueue message queue of the Looper object. The Looper object is responsible for creating a MessageQueue message queue, and then cyclically reads tasks or task results from it and calls back the corresponding processing function.
[0080] In some embodiments, the communication method further includes:
[0081] S60: While refreshing the UI interface, start an asynchronous thread to send a heartbeat message packet to the onboard unit to maintain a normal and stable connection with the onboard unit.
[0082] In some embodiments, the communication method further includes:
[0083] S61: When it is determined that the message body no longer needs to be received, for example, when the vehicle-mounted software exits, the connection with the vehicle-mounted unit is disconnected, and the thread pool is closed to release the resources occupied by it.
[0084] like Figure 6 As shown, one embodiment of the present invention discloses a vehicle-mounted device, including:
[0085] one or more processors;
[0086] A storage device is used to store one or more programs. When the one or more programs are executed by one or more processors, the one or more processors implement the communication method between the vehicle-mounted software and the vehicle-mounted unit as described in any of the above embodiments, which will not be repeated here.
[0087] By implementing the present invention, the following beneficial effects are achieved:
[0088] The present invention provides a set of efficient and stable communication solutions between vehicle-mounted software and vehicle-mounted units, which solves the problem of high message concurrency by integrating multiple types of messages into one message body. In addition, multiple sub-threads execute time-consuming tasks, and UI interface refresh is only executed in the main thread, so a large number of messages from the vehicle-mounted unit can be processed in real time and efficiently, and the entire processing process ensures the responsiveness of the UI interface, making the UI interface of the vehicle-mounted software smoother.
[0089] It can be understood that the above embodiments only express some implementation methods of the present invention, and the description thereof is relatively specific and detailed, but it cannot be understood as limiting the patent scope of the present invention. It should be pointed out that for ordinary technicians in this field, without departing from the concept of the present invention, the above embodiments or technical features can be freely combined, and several deformations and improvements can be made, which all belong to the protection scope of the present invention, that is, the embodiments described in "some embodiments" can be freely combined with any of the above and below embodiments; therefore, all equivalent changes and modifications made to the scope of the claims of the present invention should fall within the scope of the claims of the present invention.
Claims
1. A method for communicating between an on-board software and an on-board unit, applied to the on-board software, characterized in that: The following steps are involved: Establishing a communication connection with the vehicle-mounted unit; receiving a message body sent by the vehicle-mounted unit, wherein the message body has integrated multiple types of messages; Enqueue the message body into a message queue; Add the message queue to the task stack of the thread pool and start multiple child threads for processing; The task results processed by multiple sub-threads are used to refresh the UI interface through the main thread.
2. The method for communicating between vehicle-mounted software and a vehicle-mounted unit according to claim 1, characterized in that: Establishing a communication connection with the vehicle-mounted unit, comprising: Connecting to a wireless network emitted by the vehicle-mounted unit; The onboard unit is connected according to the IP and port of the onboard unit.
3. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: Receiving a message body sent by the vehicle-mounted unit, comprising: The message body sent by the vehicle-mounted unit is received at a preset frequency, where the preset frequency is the same as the frequency at which the vehicle-mounted unit sends the message body.
4. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: The identifier of the message body is a preset identifier, and the message content of the message body includes a character string containing multiple types of messages, and the multiple types of messages include at least two of the following: vehicle messages, other vehicle messages, vulnerable traffic participant messages, road sign messages, traffic light messages, and warning messages; The communication method between the vehicle-mounted software and the vehicle-mounted unit also includes: After determining that the identifier of the message body is the preset identifier, the message body is entered into a message queue for processing.
5. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: The message body is put into a message queue, and before that, the process also includes: creating the message queue.
6. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: The message body is put into a message queue for processing, including: The message body is parsed into an executable format and placed into the message queue.
7. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: The message queue is added to the task stack of the thread pool, and multiple sub-threads are started for processing, which also includes: creating the thread pool, which includes multiple sub-threads.
8. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: The message queue is added to the task stack of the thread pool, and multiple child threads are started for processing, including: Taking the message body from the message queue and encapsulating it into a task, wherein the task includes message parsing and processing logic; The task is submitted to the task stack of the thread pool, and the tasks in the task stack are executed concurrently by multiple sub-threads.
9. The method for communication between vehicle-mounted software and vehicle-mounted unit according to claim 1, characterized in that: The task results processed by multiple sub-threads are used to refresh the UI interface through the main thread, including: Create a Handler object; The Handler object is used to send the task results processed by the multiple sub-threads to the main thread for execution, so as to refresh the UI interface.
10. A vehicle-mounted device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to implement the communication method between the vehicle-mounted software and the vehicle-mounted unit as described in any one of claims 1 to 9.
