Adaptive communication method and device based on shared memory, storage medium and electronic device
Patent Information
- Application Number
- CN202610948152.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-29
- Publication Date
- 2026-09-22
AI Technical Summary
[0003]针对相关技术中存在的上述问题,暂未发现高效且准确的解决方案
1、解决通信中间件在域内通信数据量多时频繁IPC通知导致系统CPU资源消耗高,或者部分业务数据量少,空转轮询查询数据导致资源消耗的问题,提高资源利用率;
Smart Images

Figure CN122802581A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of vehicle technology, and more specifically, to an adaptive communication method and apparatus, storage medium, and electronic device based on shared memory. Background Technology
[0002] In related technologies, DDS (Data Distribution Service) communication middleware is currently widely used in vehicle communication middleware. To improve communication efficiency and throughput for large data transfers, communication within the controller domain generally uses shared memory communication methods. However, different applications within the controller have different communication scenarios and requirements, with varying communication data volumes and latency requirements.
[0003] No efficient and accurate solution has yet been found to address the aforementioned issues in the relevant technologies. Summary of the Invention
[0004] This invention provides an adaptive communication method and apparatus, storage medium, and electronic device based on shared memory to solve technical problems in related technologies.
[0005] According to an embodiment of the present invention, an adaptive communication method based on shared memory is provided, comprising: determining first data to be sent by a first process of a target vehicle through a Data Distribution Service (DDS) communication middleware, and determining a second process to receive the first data; writing the first data into a first shared memory block of the first process, and recording the first memory write position of the first data in the first shared memory block; reading a first remote read entity proxy reader of the first process from the second process, wherein the first proxy reader is virtually connected to a write entity writer of the first process, the first proxy reader is used to record a second shared memory message queue and a second communication mode of the second process, the communication mode being used to characterize the communication latency requirements of the corresponding process; and transmitting the first data to the second process according to the second shared memory message queue and the second communication mode.
[0006] Optionally, transmitting the first data to the second process according to the second shared memory message queue and the second communication mode includes: filling the first memory write location into the second shared memory message queue; determining whether the second communication mode is a notification mode, wherein the second communication mode includes a notification mode or a polling mode; if the second communication mode is a notification mode, controlling the first process to send a first inter-process communication (IPC) notification to the second process, so that the second process transmits the first data from the second shared memory message queue to the second process, wherein the first IPC notification is used to notify the second process that there is new data to receive.
[0007] Optionally, after determining whether the second communication mode is a notification mode, the method further includes: if the second communication mode is a polling mode, waiting for the second process to send a polling message according to a preset period, so that the second process can transfer the first data from the second shared memory message queue to the second process, wherein the polling message is used to periodically detect whether there is new data to be received in the second shared memory message queue.
[0008] Optionally, determining the second process to receive the first data includes: creating a shared memory block for the first process according to user configuration when the first process initializes the DDS protocol stack; receiving an announcement message sent by the second process, wherein the announcement message carries the following information of the second process: second shared memory block information, IPC channel information, and communication mode; and establishing a communication link between the first process and the second process using the announcement message.
[0009] Optionally, establishing a communication link between the first process and the second process using the notification message includes: controlling the first process to parse the following information of the second process carried in the notification message: second shared memory block information, IPC channel information, and communication mode; after the first process creates a local proxy participant (Proxyparticipant), opening and mapping the second shared memory block using the second shared memory block information, and saving the second shared memory block information, the IPC channel information, and the communication mode to the proxyparticipant information of the first process; when the first process receives a read flag data(r) sent by the second process, controlling the writer of the first process at its local end and the first proxy reader at the second process's end to establish a virtual connection, and inheriting the proxy participant information to the first proxy reader.
[0010] Optionally, the method further includes: determining the second data to be received by the first process from the third process; receiving the data sent by the third process and writing it to the tag data(w); controlling the reader on the local end of the first process to establish a virtual connection with the proxy writer of the first process on the remote end of the third process; saving the shared memory information of the proxy writer to the global linked list of the first process; and using the global linked list to transmit the second data to the first process.
[0011] Optionally, transmitting the second data to the first process using the global linked list includes: receiving a second IPC notification sent by the third process, or detecting that the first process polls the message queue of the third process and there is new data to be received, wherein the second IPC notification is used to notify the first process that there is new data to be received; controlling the first process to retrieve the second data from the global linked list at the third memory write location of the third process; controlling the first process to obtain protocol stack data from the third memory write location and decoding the protocol stack data into the content of the second data.
[0012] According to another embodiment of the present invention, an adaptive communication device based on shared memory is provided, comprising: a first determining module, configured to determine first data to be sent by a first process of a target vehicle through a Data Distribution Service (DDS) communication middleware, and to determine a second process to receive the first data; a recording module, configured to write the first data into a first shared memory block of the first process, and record the first memory write position of the first data in the first shared memory block; a reading module, configured to read a first remote reading entity proxyreader of the first process from the second process, wherein the first proxyreader is virtually connected to a local writing entity writer of the first process, and the first proxyreader is configured to record a second shared memory message queue and a second communication mode of the second process, the communication mode being used to characterize the communication latency requirements of the corresponding process; and a first transmitting module, configured to transmit the first data to the second process according to the second shared memory message queue and the second communication mode.
[0013] Optionally, the first transmission module includes: a filling unit, configured to fill the first memory write location into the second shared memory message queue; a judging unit, configured to judge whether the second communication mode is a notification mode, wherein the second communication mode includes a notification mode or a polling mode; and a first transmission unit, configured to, if the second communication mode is a notification mode, control the first process to send a first inter-process communication (IPC) notification to the second process, so that the second process transmits the first data from the second shared memory message queue to the second process, wherein the first IPC notification is used to notify the second process that there is new data to receive.
[0014] Optionally, the first transmission module further includes: a second transmission unit, configured to, after the judgment unit determines whether the second communication mode is a notification mode, wait for a polling message sent by the second process according to a preset period if the second communication mode is a polling mode, so that the second process transmits the first data from the second shared memory message queue to the second process, wherein the polling message is used to periodically detect whether there is new data to be received in the second shared memory message queue.
[0015] Optionally, the first determining module includes: a configuration unit, configured to create a shared memory block for the first process according to user configuration when the first process initializes the DDS protocol stack; a receiving unit, configured to receive a notification message sent by the second process, wherein the notification message carries the following information of the second process: second shared memory block information, IPC channel information, and communication mode; and a creation unit, configured to establish a communication link between the first process and the second process using the notification message.
[0016] Optionally, the creation unit includes: a parsing subunit, configured to control the first process to parse the following information of the second process carried in the notification message: second shared memory block information, IPC channel information, and communication mode; a saving subunit, configured to, after the first process creates a local proxy participant, open and map the second shared memory block using the second shared memory block information, and save the second shared memory block information, the IPC channel information, and the communication mode to the proxy participant information of the first process; and a control subunit, configured to, when the first process receives the read flag data(r) sent by the second process, control the writer of the first process at its local end to establish a virtual connection with the first proxy reader at the second process's end, and inherit the proxy participant information to the first proxy reader.
[0017] Optionally, the apparatus further includes: a second determining module, configured to determine second data to be received by the first process from the third process; a receiving module, configured to receive the data write flag data(w) sent by the third process; a control module, configured to control the reader at the local end of the first process to establish a virtual connection with the proxywriter at the remote end of the third process; a saving module, configured to save the shared memory information of the proxy writer to the global linked list of the first process; and a second transmission module, configured to use the global linked list to transmit the second data to the first process.
[0018] Optionally, the second transmission module includes: a processing unit, configured to receive a second IPC notification sent by the third process, or to detect that the first process polls the message queue of the third process and there is new data to be received, wherein the second IPC notification is used to notify the first process that there is new data to be received; a reading unit, configured to control the first process to retrieve the second data from the global linked list at the third memory write location of the third process; and a parsing unit, configured to control the first process to obtain protocol stack data from the third memory write location and decode the protocol stack data into the content of the second data.
[0019] According to another aspect of the embodiments of this application, a storage medium is also provided, the storage medium including a stored program that executes the above steps when the program is run.
[0020] According to another aspect of the embodiments of this application, an electronic device is also provided, including a processor, a communication interface, a memory, and a communication bus, wherein the processor, the communication interface, and the memory communicate with each other through the communication bus; wherein: the memory is used to store computer programs; and the processor is used to execute the steps in the above method by running the programs stored in the memory.
[0021] This application also provides a computer program product containing instructions that, when run on a computer, cause the computer to perform the steps in the above-described method.
[0022] The beneficial effects of this invention are: 1. Solve the problem of high CPU resource consumption caused by frequent IPC notifications when the communication middleware has a large amount of communication data in the domain, or the problem of resource consumption caused by idle polling query when the amount of some business data is small, thereby improving resource utilization; 2. Furthermore, the sending end adapts to different latency requirements of the business. For scenarios with high latency requirements, it is configured as an IPC notification, and the sending end will promptly send a notification to the remote end to read the data, thereby improving the flexibility of inter-process communication. Attached Figure Description
[0023] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings: Figure 1 This is a hardware structure block diagram of a vehicle according to an embodiment of the present invention; Figure 2 This is a flowchart of an adaptive communication method based on shared memory according to an embodiment of the present invention; Figure 3 This is a flowchart illustrating the process of sending shared memory data in an embodiment of the present invention; Figure 4 This is a flowchart of the data IPC notification processing in an embodiment of the present invention; Figure 5 This is a flowchart of the data polling process in an embodiment of the present invention; Figure 6 This is an interaction diagram of the sending end and the receiving end in an embodiment of the present invention; Figure 7 This is a structural block diagram of an adaptive communication device based on shared memory according to an embodiment of the present invention. Detailed Implementation
[0024] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present application, and not all of them. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present application. It should be noted that, unless otherwise specified, the embodiments and features in the embodiments of the present application can be combined with each other.
[0025] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0026] Example 1 The method embodiment provided in Embodiment 1 of this application can be executed in a vehicle, vehicle controller, processor, computer, or similar processing device. Taking its operation in a vehicle as an example, Figure 1 This is a hardware structure block diagram of a vehicle according to an embodiment of the present invention. For example... Figure 1 As shown, a vehicle may include one or more ( Figure 1 Only one is shown in the diagram. A processor 102 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and a memory 104 for storing data are also shown. Optionally, the vehicle may further include a transmission device 106 for communication functions and an input / output device 108. Those skilled in the art will understand that... Figure 1 The structure shown is for illustrative purposes only and does not limit the structure of the vehicle described above. For example, the vehicle may also include components that are larger than... Figure 1 The more or fewer components shown, or having the same Figure 1 The different configurations shown.
[0027] The memory 104 can be used to store vehicle programs, such as application software programs and modules, like the vehicle program corresponding to a shared memory-based adaptive communication method for a vehicle in this embodiment of the invention. The processor 102 executes various functional applications and data processing by running the vehicle program stored in the memory 104, thereby implementing the aforementioned method. The memory 104 may include high-speed random access memory and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some instances, the memory 104 may further include memory remotely located relative to the processor 102, and these remote memories can be connected to the vehicle via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.
[0028] The transmission device 106 is used to receive or send data via a network. Specific examples of the network described above may include a wireless network provided by the vehicle's communication provider. In one example, the transmission device 106 includes a Network Interface Controller (NIC), which can connect to other network devices via a base station to communicate with the Internet. In another example, the transmission device 106 may be a Radio Frequency (RF) module used for wireless communication with the Internet.
[0029] This embodiment provides an adaptive communication method based on shared memory. Figure 2 This is a flowchart of an adaptive communication method based on shared memory according to an embodiment of the present invention, such as... Figure 2As shown, the process includes the following steps: Step S201: Determine the first data to be sent by the first process of the target vehicle through the Data Distribution Service (DDS) communication middleware, and determine the second process to receive the first data. The vehicle communication middleware in this embodiment includes a first process, a second process, etc., and each process is a communication node.
[0030] Step S202: Write the first data into the first shared memory block of the first process, and record the first memory write position of the first data in the first shared memory block; When initializing the DDS protocol stack, each process creates shared memory based on the user's configuration information and configures a block of memory at the end of that shared memory as a shared memory message queue for receiving messages for that node.
[0031] Step S203: Read the first remote reading entity proxyreader of the first process from the second process, wherein the first proxy reader is virtually connected to the write entity writer of the first process, and the first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process, wherein the communication mode is used to characterize the communication latency requirements of the corresponding process. The first proxy reader resides on the second process. Optionally, the communication modes include a notification mode with relatively high communication latency requirements and a polling mode with relatively low communication latency requirements.
[0032] Step S204: The first data is transmitted to the second process according to the second shared memory message queue and the second communication mode.
[0033] Through the above steps, the first process of the target vehicle is determined to send first data through the Data Distribution Service (DDS) communication middleware, and the second process to receive the first data is determined; the first data is written into the first shared memory block of the first process, and the first memory write position of the first data in the first shared memory block is recorded; the first remote read entity proxy reader of the first process is read from the second process, wherein the first proxy reader is virtually connected to the write entity writer of the first process, and the first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process, wherein the communication mode is used to characterize the communication latency requirements of the corresponding process; the first data is transmitted to the second process according to the second shared memory message queue and the second communication mode, thereby avoiding the problem of high system CPU resource consumption caused by frequent IPC notifications when the communication middleware has a large amount of communication data in the domain, or the problem of resource consumption caused by idle polling queries when the amount of some business data is small. This solves the technical problem of low resource utilization caused by the use of fixed communication modes between processes in DDS communication in the prior art. The sending end can flexibly select the communication mode according to different latency requirements of the business, thereby improving the flexibility of inter-process communication.
[0034] In one example of this embodiment, determining the second process to receive the first data includes: creating a shared memory block for the first process according to user configuration when the first process initializes the DDS protocol stack; receiving an announcement message sent by the second process, wherein the announcement message carries the following information of the second process: second shared memory block information, IPC channel information, and communication mode; and establishing a communication link between the first process and the second process using the announcement message.
[0035] Shared memory information and IPC channel information are added to the DDS announcement content. That is, the DDS data(p) announcement information includes shared memory information, IPC channel information and shared memory communication mode. The DDS discovery protocol is implemented through UDP (User Datagram Protocol) multicast.
[0036] Optionally, establishing a communication link between the first process and the second process using the notification message includes: controlling the first process to parse the following information of the second process carried in the notification message: second shared memory block information, IPC channel information, and communication mode; after the first process creates a local proxy participant (Proxyparticipant), opening and mapping the second shared memory block using the second shared memory block information, and saving the second shared memory block information, the IPC channel information, and the communication mode to the proxyparticipant information of the first process; when the first process receives a read flag data(r) sent by the second process, controlling the writer of the first process at its local end and the first proxy reader at the second process's end to establish a virtual connection, and inheriting the proxy participant information to the first proxy reader.
[0037] A communication system based on the DDS protocol stack includes multiple processes (such as Process 1, Process 2, etc.). Each process, upon initializing the DDS protocol stack, creates shared memory based on user configuration information and configures a portion of the shared memory at the end of that block as a shared memory message queue for receiving messages. Shared memory information (the location of the shared memory block) and IPC channel information are added to the DDS SPDP announcement content. That is, the DDS data(p) announcement information includes shared memory information, IPC channel information, and the shared memory communication mode. The DDS discovery protocol is implemented via UDP multicast. Upon receiving a data(p) from another process (Data(p) is a special message from the DDS protocol stack that sends local protocol information via multicast for participant discovery), any process parses the shared memory information, remote IPC communication information, and remote communication mode announced by the remote process. After successfully creating the proxy participant, the shared memory segment is opened and mapped according to the shared memory information announced by the remote end. At the same time, the remote shared memory information, remote IPC communication information, and remote message queue address information are saved to the remote proxy participant information.
[0038] When any process acting as the sender receives information from the remote receiver via data(r), it establishes a correspondence with the remote reader. When the local writer and the remote proxy reader establish a connection, the local writer inherits the shared memory information, IPC channel information, and communication mode information from the proxy participant, and records the results under that proxy reader. Data(r) and data(w) are DDS protocol stack messages used to establish a connection between the writer and the reader.
[0039] When any process acting as the receiving end receives information from the remote sender via data(w), it establishes a correspondence with the remote proxywriter. When the local reader and the remote proxywriter establish a connection, the shared memory information of the remote proxywriter channel is stored in a global linked list. This allows the receiving end to find the corresponding shared memory and read its contents from the global linked list after receiving notification from the sender via the IPC channel or polling to find shared memory information in the message queue.
[0040] In this embodiment, the reader (reading entity) and writer (writing entity) are the local reader and writer, while the proxywriter and proxy reader represent the remote reader and writer of the process. The local writer and the remote proxy reader of the same process will establish a connection, and the local reader and the remote proxy writer will establish a connection. The connection is a virtual connection, which is a correspondence between data sending and receiving.
[0041] In one implementation scenario of this embodiment, transmitting the first data to the second process according to the second shared memory message queue and the second communication mode includes: filling the first memory write location into the second shared memory message queue; determining whether the second communication mode is a notification mode, wherein the second communication mode includes a notification mode or a polling mode; if the second communication mode is a notification mode, controlling the first process to send a first inter-process communication (IPC) notification to the second process, so that the second process transmits the first data from the second shared memory message queue to the second process, wherein the first IPC notification is used to notify the second process that there is new data to receive.
[0042] In this implementation scenario, the first process acts as the sender. Its local writer iterates through all remote readers that have established connections with it. Based on the communication mode stored during connection establishment and the shared memory message queue corresponding to the remote reader's process, it fills the shared memory block information where the recorded data is stored into each remote reader's shared memory message queue. Then, based on the communication mode announced by the remote reader, it selects whether to send an IPC notification to the corresponding recv receiving thread. Figure 3This is a flowchart of the shared memory data transmission process in an embodiment of the present invention. In the normal data transmission process of the DDS protocol stack, the writer of the sending end requests a shared memory block initialized by the process itself, records the information of the shared memory block, copies the serialized data into the shared memory of the sending end, generates the information corresponding to the shared memory, writes the shared memory information corresponding to the data into the peer's message queue, and determines the message queue communication mode announced by the peer. Scenario 1: IPC announces that there is information written to the peer's message queue; Scenario 2: No operation is performed, and the peer actively polls its own message queue periodically to see if there is information written.
[0043] Figure 4 This is a flowchart of the data IPC notification processing in an embodiment of the present invention. If the second process is configured in IPC notification mode, the recv receiving thread (such as the second process) is blocked and waiting for IPC notification. If an IPC notification sent from the remote end is received, each message in the shared memory message queue of this process is retrieved one by one. According to the shared memory information indicated by the message, the data is retrieved from the corresponding shared memory address and placed into the normal data processing flow of the DDS protocol stack.
[0044] In another implementation scenario of this embodiment, after determining whether the second communication mode is a notification mode, the method further includes: if the second communication mode is a polling mode, waiting for the second process to send a polling message according to a preset period, so that the second process can transfer the first data from the second shared memory message queue to the second process, wherein the polling message is used to periodically detect whether there is new data to be received in the second shared memory message queue.
[0045] If the remote notification is in polling mode, no action is taken, and the second process is allowed to poll the message queue itself.
[0046] Figure 5 This is a flowchart of the data polling process in this embodiment of the invention. If the second process is configured to polling reception mode, the recv receiving thread periodically queries the shared memory message queue of its own process to see if any information has been written, according to the user-configured polling period, such as 10ms. If data is detected in the message queue, each piece of shared memory information is retrieved one by one. Based on the shared memory information indicated by the message, the data is retrieved from the corresponding shared memory address and placed into the normal data processing flow of the DDS protocol stack.
[0047] In one embodiment of this example, the first process is a process for receiving data, and the third process is a process for sending data. The method further includes: determining second data to be received by the first process from the third process; receiving data sent by the third process and writing it to a marker data(w); controlling the reader on the local end of the first process to establish a virtual connection with the proxy writer on the remote end of the third process; saving the shared memory information of the proxy writer to a global linked list of the first process; and using the global linked list to transmit the second data to the first process.
[0048] In this implementation, the first process is the receiving end, and the third process is the sending end.
[0049] Optionally, transmitting the second data to the first process using the global linked list includes: receiving a second IPC notification sent by the third process, or detecting that the first process polls the message queue of the third process and there is new data to be received, wherein the second IPC notification is used to notify the first process that there is new data to be received; controlling the first process to retrieve the second data from the global linked list at the third memory write location of the third process; controlling the first process to obtain protocol stack data from the third memory write location and decoding the protocol stack data into the content of the second data.
[0050] This embodiment uses the DDS discovery protocol to announce the shared memory communication information and communication mode of each DDS communication node. The remote end selects the communication mode announced by the remote end in the DDS protocol stack through the announcement information and sends data. The sending end automatically adapts to the communication mode announced by the receiving end and chooses to notify the remote end to read the shared memory through IPC, or simply write the data to the shared memory and wait for the remote end to poll and read it.
[0051] Figure 6This is an interaction diagram of the sending end and receiving end in an embodiment of the present invention, including: the sending end initializes shared memory and IPC channel information; the receiving end initializes shared memory and uses the tail as a message queue; the receiving end sends Data(p) to the sending end; the sending end parses the shared memory information, IPC information, and communication mode announced by the remote end through Data(p), and records them under the proxyparticipant structure; the sending end sends Data(p) to the receiving end; the receiving end parses the shared memory information, IPC information, and communication mode announced by the remote end, and records them under the proxy participant structure; the receiving end sends Data(r) to the sending end; the writer of the sending end and the remote proxy reader (located at the receiving end) establish a connection, and record the shared memory information in the proxy participant into the proxy reader; the sending end sends Data(w) to the receiving end; the reader of the receiving end and the remote proxy writer establish a connection, and store the shared memory information of the sending end proxy writer channel in a global linked list; the sending end writes data into the sending end shared memory, and writes the shared memory information into the receiving end proxy. The reader corresponds to a shared memory queue, and based on the communication mode announced by the remote reader, it chooses whether to send an IPC notification to the corresponding recv receiving thread (i.e., the receiving end). The receiving end queries the shared memory message queue periodically according to its own data receiving mode. If a notification is detected, it blocks and waits for the sending end to write the IPC notification. If a message is detected in the message queue, it retrieves each message one by one, retrieves the data from the corresponding shared memory address according to the shared memory information indicated by the message, and puts it into the normal data processing flow of the DDS protocol stack.
[0052] The solution adopted in this embodiment solves the problems of high system CPU consumption (frequent IPC notifications) when the communication middleware has a large amount of communication data within the domain, or the problem of idle polling for data querying when some business data is small. Furthermore, the sending end adaptively adapts to different latency requirements of the business. For scenarios with high latency requirements, it is configured to use IPC notifications, and the sending end will promptly send notifications to the remote end to read data.
[0053] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods according to the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of the present invention.
[0054] Example 2 This embodiment also provides a shared memory-based adaptive communication device for implementing the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that implements a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0055] Figure 7 This is a structural block diagram of an adaptive communication device based on shared memory according to an embodiment of the present invention, such as... Figure 7 As shown, the device includes: The first determining module 71 is used to determine the first data to be sent by the first process of the target vehicle through the Data Distribution Service (DDS) communication middleware, and to determine the second process to receive the first data. The recording module 72 is used to write the first data into the first shared memory block of the first process and record the first memory write position of the first data in the first shared memory block. The reading module 73 is used to read the first remote reading entity proxyreader of the first process from the second process, wherein the first proxy reader is virtually connected to the write entity writer of the first process, and the first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process, wherein the communication mode is used to characterize the communication latency requirements of the corresponding process. The first transmission module 74 is used to transmit the first data to the second process according to the second shared memory message queue and the second communication mode.
[0056] Optionally, the first transmission module includes: a filling unit, configured to fill the first memory write location into the second shared memory message queue; a judging unit, configured to judge whether the second communication mode is a notification mode, wherein the second communication mode includes a notification mode or a polling mode; and a first transmission unit, configured to, if the second communication mode is a notification mode, control the first process to send a first inter-process communication (IPC) notification to the second process, so that the second process transmits the first data from the second shared memory message queue to the second process, wherein the first IPC notification is used to notify the second process that there is new data to receive.
[0057] Optionally, the first transmission module further includes: a second transmission unit, configured to, after the judgment unit determines whether the second communication mode is a notification mode, wait for a polling message sent by the second process according to a preset period if the second communication mode is a polling mode, so that the second process transmits the first data from the second shared memory message queue to the second process, wherein the polling message is used to periodically detect whether there is new data to be received in the second shared memory message queue.
[0058] Optionally, the first determining module includes: a configuration unit, configured to create a shared memory block for the first process according to user configuration when the first process initializes the DDS protocol stack; a receiving unit, configured to receive a notification message sent by the second process, wherein the notification message carries the following information of the second process: second shared memory block information, IPC channel information, and communication mode; and a creation unit, configured to establish a communication link between the first process and the second process using the notification message.
[0059] Optionally, the creation unit includes: a parsing subunit, configured to control the first process to parse the following information of the second process carried in the notification message: second shared memory block information, IPC channel information, and communication mode; a saving subunit, configured to, after the first process creates a local proxy participant, open and map the second shared memory block using the second shared memory block information, and save the second shared memory block information, the IPC channel information, and the communication mode to the proxy participant information of the first process; and a control subunit, configured to, when the first process receives the read flag data(r) sent by the second process, control the writer of the first process at its local end to establish a virtual connection with the first proxy reader at the second process's end, and inherit the proxy participant information to the first proxy reader.
[0060] Optionally, the apparatus further includes: a second determining module, configured to determine second data to be received by the first process from the third process; a receiving module, configured to receive the data write flag data(w) sent by the third process; a control module, configured to control the reader at the local end of the first process to establish a virtual connection with the proxywriter at the remote end of the third process; a saving module, configured to save the shared memory information of the proxy writer to the global linked list of the first process; and a second transmission module, configured to use the global linked list to transmit the second data to the first process.
[0061] Optionally, the second transmission module includes: a processing unit, configured to receive a second IPC notification sent by the third process, or to detect that the first process polls the message queue of the third process and there is new data to be received, wherein the second IPC notification is used to notify the first process that there is new data to be received; a reading unit, configured to control the first process to retrieve the second data from the global linked list at the third memory write location of the third process; and a parsing unit, configured to control the first process to obtain protocol stack data from the third memory write location and decode the protocol stack data into the content of the second data.
[0062] It should be noted that the above modules can be implemented by software or hardware. For the latter, they can be implemented in the following ways, but are not limited to: all the above modules are located in the same processor; or, the above modules are located in different processors in any combination.
[0063] Example 3 Embodiments of the present invention also provide a storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above method embodiments when running.
[0064] Optionally, in this embodiment, the storage medium may be configured to store a computer program for performing the following steps: S1, determine the first data to be sent by the first process of the target vehicle through the Data Distribution Service (DDS) communication middleware, and determine the second process to receive the first data; S2, write the first data into the first shared memory block of the first process, and record the first memory write position of the first data in the first shared memory block; S3, read the first remote read entity proxy reader of the first process from the second process, wherein the first proxy reader is virtually connected to the write entity writer of the first process, and the first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process, wherein the communication mode is used to characterize the communication latency requirements of the corresponding process; S4, the first data is transmitted to the second process according to the second shared memory message queue and the second communication mode.
[0065] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media capable of storing computer programs, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0066] Embodiments of the present invention also provide an electronic device including a memory and a processor, the memory storing a computer program and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.
[0067] Optionally, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor and the input / output device is connected to the processor.
[0068] Optionally, in this embodiment, the processor can be configured to perform the following steps via a computer program: S1, determine the first data to be sent by the first process of the target vehicle through the Data Distribution Service (DDS) communication middleware, and determine the second process to receive the first data; S2, write the first data into the first shared memory block of the first process, and record the first memory write position of the first data in the first shared memory block; S3, read the first remote read entity proxy reader of the first process from the second process, wherein the first proxy reader is virtually connected to the write entity writer of the first process, and the first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process, wherein the communication mode is used to characterize the communication latency requirements of the corresponding process; S4, the first data is transmitted to the second process according to the second shared memory message queue and the second communication mode.
[0069] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments and optional implementations, and will not be repeated here.
[0070] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0071] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented using software plus a general-purpose hardware platform, or of course, using hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0072] It should be understood that the terminology used herein is for the purpose of describing particular exemplary embodiments only and is not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms “a,” “an,” and “described” as used herein may also include the plural forms. The terms “comprising,” “including,” “containing,” and “having” are inclusive and therefore indicate the presence of the stated features, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, elements, components, and / or combinations thereof. The method steps, processes, and operations described herein are not construed as requiring them to be performed in a particular order described or illustrated unless the order of performance is explicitly indicated. It should also be understood that additional or alternative steps may be used.
[0073] The above description is merely a specific embodiment of the present invention, enabling those skilled in the art to understand or implement the invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the invention. Therefore, the present invention is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features claimed herein.
Claims
1. An adaptive communication method based on shared memory, characterized in that, include: The first process that determines the target vehicle sends the first data to be sent through the Data Distribution Service (DDS) communication middleware, and the second process that determines the first data to be received. Write the first data into the first shared memory block of the first process, and record the first memory write position of the first data in the first shared memory block; The first remote read entity proxy reader of the first process is read from the second process, wherein the first proxy reader is virtually connected to the write entity writer of the first process. The first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process. The communication mode is used to characterize the communication latency requirements of the corresponding process. The first data is transmitted to the second process according to the second shared memory message queue and the second communication mode.
2. The method according to claim 1, characterized in that, Transmitting the first data to the second process according to the second shared memory message queue and the second communication mode includes: Fill the first memory write location into the second shared memory message queue; Determine whether the second communication mode is a notification mode, wherein the second communication mode includes a notification mode or a polling mode; If the second communication mode is a notification mode, the first process is controlled to send a first inter-process communication (IPC) notification to the second process, so that the second process transmits the first data from the second shared memory message queue to the second process. The first IPC notification is used to notify the second process that there is new data to receive.
3. The method according to claim 2, characterized in that, After determining whether the second communication mode is a notification mode, the method further includes: If the second communication mode is polling mode, wait for the polling message sent by the second process according to a preset period, so that the second process can transfer the first data from the second shared memory message queue to the second process. The polling message is used to periodically detect whether there is new data to be received in the second shared memory message queue.
4. The method according to claim 1, characterized in that, The second process for determining the recipient of the first data includes: When the first process initializes the DDS protocol stack, a shared memory block is created for the first process according to the user configuration. Receive a notification message sent by the second process, wherein the notification message carries the following information about the second process: second shared memory block information, IPC channel information, and communication mode; A communication link is established between the first process and the second process using the notification message.
5. The method according to claim 4, characterized in that, Establishing a communication link between the first process and the second process using the notification message includes: The first process is controlled to parse the following information about the second process carried in the notification message: second shared memory block information, IPC channel information, and communication mode; After the first process creates the local proxy participant, it uses the second shared memory block information to open and map the second shared memory block, and saves the second shared memory block information, the IPC channel information, and the communication mode into the proxy participant information of the first process. When the first process receives the read flag data(r) sent by the second process, it controls the writer on the local end of the first process to establish a virtual connection with the first proxy reader on the second process end, and inherits the proxyparticipant information to the first proxy reader.
6. The method according to claim 1, characterized in that, The method further includes: Determine the second data that the first process needs to receive from the third process; The data sent by the third process is written to the marker data(w); The reader on the local end of the first process is controlled to establish a virtual connection with the proxywriter of the first process on the remote end of the third process. Save the shared memory information of the proxy writer to the global linked list of the first process; The second data is transmitted to the first process using the global linked list.
7. The method according to claim 6, characterized in that, Using the global linked list to transmit the second data to the first process includes: The process receives a second IPC notification sent by the third process, or detects that the first process has polled the message queue of the third process and there is new data that needs to be received. The second IPC notification is used to notify the first process that there is new data that needs to be received. Control the first process to retrieve the second data from the global linked list at the third memory write location of the third process; The first process is controlled to obtain protocol stack data from the third memory write location and decode the protocol stack data into the content of the second data.
8. An adaptive communication device based on shared memory, characterized in that, include: The first determining module is used to determine the first data to be sent by the first process of the target vehicle through the Data Distribution Service (DDS) communication middleware, and to determine the second process to receive the first data. The recording module is used to write the first data into the first shared memory block of the first process and record the first memory write position of the first data in the first shared memory block; The reading module is used to read the first remote reading entity proxyreader of the first process from the second process. The first proxy reader is virtually connected to the write entity writer of the first process. The first proxy reader is used to record the second shared memory message queue and the second communication mode of the second process. The communication mode is used to characterize the communication latency requirements of the corresponding process. The first transmission module is configured to transmit the first data to the second process according to the second shared memory message queue and the second communication mode.
9. A storage medium, characterized in that, The storage medium stores a computer program, wherein the computer program is configured to execute the method described in any one of claims 1 to 7 when it is run.
10. An electronic device comprising a memory and a processor, characterized in that, The memory stores a computer program, and the processor is configured to run the computer program to perform the method as described in any one of claims 1 to 7.