Communication method and device for server and client in ECU (Electronic Control Unit)
By combining SOME/IP protocol and shared memory in the ECU and using queue management to manage shared memory, the problem of low communication efficiency between server and client in the ECU is solved, and more efficient data transmission is achieved.
Patent Information
- Application Number
- CN202411917734.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-24
- Publication Date
- 2025-04-15
AI Technical Summary
The communication efficiency of server and client in the same ECU is not high. The existing technology mainly relies on SOME/IP protocol and local socket socket communication, resulting in interaction with the kernel and is low in efficiency.
By combining SOME/IP protocol and shared memory, using queues to manage shared memory, the server writes data to shared memory, and the client obtains data from shared memory based on the first address element to avoid interaction with the kernel.
It improves the efficiency of communication between server and client within the same ECU, and improves the data transmission efficiency of SOME/IP protocol in local communication.
Smart Images

Figure CN119835317A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of server-client communication applications of a single ECU, and in particular to a server-client communication method and device within an ECU. Background Art
[0002] The SOME / IP protocol is a mainstream vehicle application protocol used in service-oriented architecture (SOA) communications, which can achieve decoupling of application development. Currently, vehicle inter-system communication is mainly based on the TCP / UDP protocol, while communication within a system, i.e. local communication, is generally implemented using localsocket socket communication.
[0003] The inventors have found that the communication between the server and the client in an ECU electronic control system is generally carried out through a combination of the SOME / IP protocol and the localsocket socket; and the local communication based on the localsocket socket involves interaction with the kernel, so the efficiency of this type of local communication is average. Summary of the invention
[0004] In view of this, the purpose of the present invention is to provide a method and device for communication between a server and a client within an ECU, which is combined with the SOME / IP protocol and shared memory to alleviate the technical problem of low communication efficiency between the server and the client within the same ECU.
[0005] In a first aspect, an embodiment provides a method for communication between a server and a client in an ECU, including:
[0006] When the startup time comes, read the server configuration file and configure the queue and shared memory accordingly;
[0007] Write the first data corresponding to each event into the shared memory, and update the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory; wherein each event corresponds to a list in the queue, and each list includes a reference count element, a semaphore element and a data first address element;
[0008] According to the subscription request sent by each client, the target event is determined from each of the events, and the first address element and semaphore element corresponding to the target event are sent to each of the clients, so that each of the clients obtains the first data corresponding to the target event from the shared memory according to the first address element; wherein the client and the server are configured in the same ECU.
[0009] In an optional embodiment, the method further comprises:
[0010] When the second data is published for any event, the semaphore element in the list corresponding to the event is sent to at least one client subscribing to the event, so that at least one client searches for the corresponding first address element according to the received semaphore element and obtains the second data from the shared memory.
[0011] In an optional implementation, the step of reading the server configuration file and configuring the queue and the shared memory accordingly includes:
[0012] Initialize the shared memory;
[0013] Reading a server configuration file, obtaining the number of publishable events, a preset memory size, and a preset memory allocation method included in the server configuration file;
[0014] Applying for shared memory according to the preset memory size, and processing the shared memory based on the preset memory allocation method;
[0015] Set the number of lists in the queue according to the number of publishable events;
[0016] The shared memory processed according to the preset memory allocation method is initially configured for the data first address element in the list.
[0017] In an optional implementation, the preset memory allocation mode includes a large block allocation mode and a partner allocation mode.
[0018] In an optional implementation, the step of writing the first data published corresponding to each event into the shared memory, and updating the first address element in the list corresponding to each event in the queue according to the actual address of the first data published corresponding to each event in the shared memory, comprises:
[0019] If there are multiple events to be published at the same time, the first address element of each event to be published is updated in the order of obtaining unique write permissions, including:
[0020] Writing the first data published corresponding to the first event that currently obtains the only write permission into the shared memory according to the first address element;
[0021] When the first data corresponding to the first event has been completely written into the actual address in the shared memory, the first address element in the list corresponding to the second event that obtains the unique write permission is updated according to the actual address in the shared memory;
[0022] The second event is taken as a new first event, and the step of writing the first data corresponding to the first event that currently obtains the only write permission into the shared memory is returned to be executed according to the first address element, until each of the events to be published is traversed and terminated.
[0023] In an optional implementation, the step of writing the first data published corresponding to each event into the shared memory, and updating the first address element in the list corresponding to each event in the queue according to the actual address of the first data published corresponding to each event in the shared memory, comprises:
[0024] If there are multiple events to be published at the same time, the first data corresponding to each event to be published is written into the shared memory according to the first address element initially configured in the list corresponding to each event to be published;
[0025] Among them, the first address initially configured in each list corresponding to the event to be published is the first address in a preset number of continuous shared memory blocks; the shared memory blocks are evenly cut from the shared memory, and the size of each shared memory block matches the size of the first data.
[0026] In an optional implementation manner, the startup timing is divided by the trigger priority of the corresponding function type of the server;
[0027] When the trigger priority of the function type reaches a preset range, the startup timing includes power-on startup;
[0028] When the trigger priority of the function type does not reach a preset range, the start timing includes preset period start, preset condition trigger and preset control signal trigger.
[0029] In a second aspect, an embodiment provides a server-client communication device in an ECU, including:
[0030] The configuration module reads the server configuration file and configures the queue and shared memory accordingly when the startup time is reached;
[0031] An update module writes the first data corresponding to each event into the shared memory, and updates the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory; wherein each event corresponds to a list in the queue, and each list includes a reference count element, a semaphore element and a data first address element;
[0032] A communication module determines a target event from each of the events according to a subscription request sent by each client, and sends a first address element and a semaphore element corresponding to the target event to each of the clients, so that each of the clients obtains the first data published corresponding to the target event from the shared memory according to the first address element; wherein the client and the server are configured in the same ECU.
[0033] In a third aspect, an embodiment provides an electronic device, including a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, the steps of the method described in any of the aforementioned implementation methods are implemented.
[0034] In a fourth aspect, an embodiment provides a machine-readable storage medium, wherein the machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the steps of the method described in any one of the aforementioned implementations.
[0035] An embodiment of the present invention provides a method and device for communicating between a server and a client in an ECU. When the server is started, each list element in the queue is set based on a configuration file and a shared memory is applied for. The server writes the first data corresponding to each published event into the shared memory and updates the first address element in the list. When the client applies to subscribe to an event, the list information of the target event, such as the first address element, is sent to the client. The client can obtain the first data corresponding to the target event published by the server from the shared memory according to the first address element. The shared memory is used to replace the data communication between the server and the client implemented through the kernel (local socket) to improve efficiency.
[0036] Other features and advantages of the present disclosure will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present disclosure.
[0037] In order to make the above-mentioned objectives, features and advantages of the present disclosure more obvious and easy to understand, preferred embodiments are specifically cited below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0039] Figure 1A flow chart of a communication method between a server and a client in an ECU provided by an embodiment of the present invention;
[0040] Figure 2 A schematic diagram of a management queue and shared memory provided by an embodiment of the present invention;
[0041] Figure 3 A flow chart of another communication method between a server and a client in an ECU provided by an embodiment of the present invention;
[0042] Figure 4 A functional module diagram of a server-side and client-side communication device in an ECU provided by an embodiment of the present invention;
[0043] Figure 5 A schematic diagram of the hardware architecture of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0044] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0045] The inventors have found that the communication between the server and the client in the same ECU is generally based on a combination of socket communication based on some / IP and local socket; however, the local socket requires the server and the client to interact with the kernel data to achieve writing and reading, which leads to low communication efficiency between the server and the client in the same ECU.
[0046] Based on this, an embodiment of the present invention provides a method and device for communicating between a server and a client within an ECU, which manages shared memory in a queue manner. The server and the client in the same ECU do not need to interact with the kernel, so as to improve the efficiency of the SOME / IP protocol in the local communication process.
[0047] To facilitate understanding of this embodiment, a server-client communication method within an ECU disclosed in an embodiment of the present invention is first introduced in detail. The method is applied to the server in the ECU. It should be noted that each ECU includes at least one server and at least one client, the server publishes services, and the client subscribes to services.
[0048] Figure 1 A flow chart of a communication method between a server and a client in an ECU provided by an embodiment of the present invention.
[0049] like Figure 1 As shown, the method comprises the following steps:
[0050] Step S102, when the startup timing is reached, read the server configuration file and configure the queue and shared memory accordingly.
[0051] Among them, the startup timing of the server is divided by the trigger priority of the corresponding function type of the server; each server is used to publish the service of the corresponding function, and the startup timing of each server can be determined according to the trigger priority of the function service.
[0052] For example, when the trigger priority of the function type reaches a preset range, the start time includes power-on start; when the trigger priority of the function type does not reach the preset range, the start time includes preset period start, preset condition trigger and preset control signal trigger. The preset range can be understood as a higher / more critical priority.
[0053] For the server that publishes the engine status monitoring service, its trigger priority is relatively high and it starts when the power is turned on; for the entertainment system, its trigger priority is general and it can be triggered when the user sends a control signal, or it can be triggered at a scheduled time when the vehicle has traveled for more than a preset period, or it can be triggered when a preset condition is met, such as the vehicle has been slowing down for a preset time (traffic jam for a preset time).
[0054] It should be noted that the server configuration file is a file designed by the server and is used to configure queues and shared memory. Shared memory is an inter-process communication (IPC) mechanism that allows different processes to access the same memory area.
[0055] Step S104, writing the first data corresponding to each event into the shared memory, and updating the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory.
[0056] The event here can be understood as event types such as messages, notifications or services published by the server, and each event is published at least once. The first data can be understood as the first data published by the server under a certain event type.
[0057] It should be noted that for the same event type, if the specific notification content is different, it also belongs to different events; for example, event 1 of the server issuing a charging notification and event 2 of the server issuing a vehicle start notification are two different events.
[0058] Among them, each event corresponds to a list in the queue, and each list includes a reference count element, a semaphore element and a data first address element; it can be understood that the queue is a linear list, and each server can pre-build the queue.
[0059] Step S106, determine the target event from each event according to the subscription request sent by each client, and send the first address element and semaphore element corresponding to the target event to each client, so that each client obtains the first data corresponding to the target event from the shared memory according to the first address element.
[0060] The client and server are both configured in the same ECU.
[0061] When a client subscribes to a corresponding target event, the server first sends the specific list element corresponding to the target event to the client. After receiving the list element content, the client reads the first address element header content. At this time, the client can know where the first data of the target event is written to the shared memory, and then reads and copies the first data from the shared memory based on the address in the first address element header.
[0062] As an optional embodiment, if there are N clients subscribing to the first data of the target event, the number of clients that have read the first data can be counted in real time; if the current client is not the last client among the N clients subscribing to the first data of the target event to read the first data from the shared memory, the current client reads and copies the first data from the shared memory; if the current client is the last client among the N clients subscribing to the first data of the target event to read the first data from the shared memory, the current client reads and cuts the first data from the shared memory; thereby further saving the effective space of the shared memory.
[0063] In a preferred embodiment of actual application, when the server is started, each list element in the queue is set based on the configuration file and shared memory is applied for; the server writes the first data corresponding to each published event into the shared memory and updates the first address element in the list; when the client applies to subscribe to an event, the list information of the target event, such as the first address element, is sent to the client, and the client can obtain the first data corresponding to the target event published by the server from the shared memory according to the first address element; shared memory is used to replace the data communication between the server and the client implemented through the kernel to improve efficiency.
[0064] In some embodiments, the server may publish the second data again or multiple times for the same event. Based on the method provided in the embodiment of the present invention, the client subscribing to the second published data can obtain the second data more conveniently; specifically, the method includes:
[0065] Step 1.1), when the second data is published for any event, the semaphore element in the list corresponding to any event is sent to at least one client subscribed to any event, so that at least one client searches for the corresponding first address element according to the received semaphore element and obtains the second data from the shared memory.
[0066] It can be understood that one event corresponds to one list, and one event corresponds to one semaphore sem_t in one list; that is, event P corresponds to list 3, and the semaphore sem_t in list 3 is j; event Q corresponds to list 5, and the semaphore sem_t in list 5 is k.
[0067] It can be seen from the above-mentioned step embodiments that clients subscribing to the same event can or the element content in the list corresponding to the event; that is, if client 1 and client 2 both subscribe to event P, the server will send the semaphore j and the first address element in the subscription event P list to client 1 and client 2 respectively based on the subscription requests of client 1 and client 2 for event P.
[0068] When the event P on the server publishes the second data again and writes it into the shared memory, only by notifying the client 1 and the client 2 of the semaphore j, the client 1 and the client 2 can know the first address element header corresponding to the event P according to the semaphore j, and read the second data from the shared memory based on the first address element header.
[0069] It should be noted that each client may subscribe to events published by multiple servers at the same time, or multiple events published by the same server; through the list elements corresponding to each event sent by the server: semaphore sem_t and the first address element header, the client can know which server the data published corresponds to and which event it is published from, and from which first address element of the shared memory it is obtained.
[0070] In some embodiments, the step of reading the server configuration file and configuring the queue and shared memory accordingly in step S102 can be implemented by the following steps, including:
[0071] Step 2.1), initialize the shared memory.
[0072] Here, the shared memory that may have been previously allocated is restored to the initialized state.
[0073] Step 2.2), read the server configuration file, and obtain the number of publishable events, preset memory size, and preset memory allocation method included in the server configuration file.
[0074] Among them, the server configuration file includes the number of publishable events (Num), which is used to represent the maximum number of service events that the current server can publish, the preset memory size (memorySize), which is used to represent the size of the shared memory to be applied for, and the preset memory allocation method (type), which is used to represent the shared memory allocation method; and the preset memory allocation methods include Buddy allocation method and Chunk allocation method.
[0075] Buddy allocates a large block of shared memory and divides it according to the memory size required for each published subscription data. Chunk allocates a large block of shared memory according to the preset size ChunkSize, divides it into several small blocks, each of which is ChunkSize, and then allocates several blocks of memory to each list according to the size of the published data.
[0076] Step 2.3), apply for shared memory according to the preset memory size, and process the shared memory based on the preset memory allocation method.
[0077] According to the preset memory size in the server configuration file, apply for shared memory of the preset memory size memorySize; if the preset memory allocation type is Buddy, first apply for a large block of shared memory, and then cut this shared memory according to the memory size required for each published subscription data; if the preset memory allocation type is Chunk, then divide the shared memory of the preset memory size memorySize into several small blocks of ChunkSize.
[0078] Step 2.4), set the number of lists in the queue according to the number of events that can be published.
[0079] like Figure 2 As shown, each queue includes multiple lists, and the number of the lists is set according to the number of events that can be published; each list includes multiple elements, which may specifically include {{reference count RefCount}, {sem_t semaphore}, {first address header}...} and other information.
[0080] Step 2.5), according to the shared memory processed by the preset memory allocation method, the data first address element in the list is initially configured.
[0081] For the Buddy preset memory mode, the first address of the data in each list can be initially configured as the first address M of the shared memory; for the Chunk preset memory mode, A memory blocks can be pre-allocated for each list. If each memory block corresponds to B bytes in size, the address length corresponding to each list is AB bytes. In actual applications, the first address M in the first list is initially configured according to the first address of the shared memory in order, and then according to the address length AB of each list, it can be known that the first address of the second list is M+AB, and so on to know the initial configuration of the first address of each list.
[0082] On the basis of the above-mentioned embodiment, for the preset memory mode of processing the shared memory in the Buddy mode, after the first data of each event release is written into the shared memory, step S104 updates the first address element in the corresponding list according to the following method, specifically including:
[0083] Step 3.1), if there are multiple events to be published at the same time, the first address element of each event to be published is updated in the order of obtaining the unique write permission.
[0084] Here, in the case where there are multiple events to be published and written at the same time, only one event can be written to the list at the same time, that is, each event to be published needs to compete for the unique write permission; the event that successfully obtains the unique write permission is published, and the actual address of the event written to the shared memory is updated to replace the first address element in the list corresponding to the event, until there are no events to be published and written at the current moment.
[0085] Exemplarily, the step 3.1) may specifically include:
[0086] Step 3.1.1), write the first data published corresponding to the first event that currently obtains the only write permission into the shared memory according to the first address element.
[0087] Here, if the first event is the first one to be published, it may correspond to list 1 in the queue, and the first event may be written into the shared memory according to the initially set first address element.
[0088] If the first event is not the first one to be published, then according to the subsequent steps 3.1.2) to 3.1.3), the corresponding first address element is the actual address of the current first event written into the shared memory after being updated.
[0089] Step 3.1.2), when the first data corresponding to the first event has been completely written into the actual address in the shared memory, the first address element in the list corresponding to the second event that obtains the unique write permission is updated according to the actual address in the shared memory.
[0090] When the first data is completely written into the shared memory, the actual address at this time is used as the first address of the next write event, which can improve the utilization rate of the shared memory and ensure the available space size of the shared memory.
[0091] Step 3.1.3), take the second event as the new first event, and return to execute step 3.1.1), until all the events to be published at the current moment have been traversed and terminated.
[0092] According to the shared memory processed in the Buddy mode, when the first data of the event release is written, only a single data is written and the first address element is updated at the same time, which can ensure the reliability of each first data writing and the matching accuracy of each first data and its actual writing address.
[0093] In some embodiments, for the preset memory mode of processing the shared memory in a Chunk mode, after the first data published by each event is written into the shared memory, step S104 updates the first address element in the corresponding list according to the following method, specifically including:
[0094] Step 4.1), if there are multiple events to be published at the same time, then the first data corresponding to each event to be published is written into the shared memory according to the first address element initially configured in the list corresponding to each event to be published.
[0095] According to the above-mentioned embodiment, the first address initially configured in the list corresponding to each event to be published is the first address in a preset number of continuous shared memory blocks. For example, if the list includes A continuous shared memory blocks, the first address element initially configured in the list corresponding to each event to be published is the first address of the first shared memory block in the A shared memory blocks.
[0096] Here, the shared memory blocks may be evenly cut from the shared memory, and the size of each shared memory block matches the size of the first data.
[0097] In actual application scenarios, if the server needs to publish events of the real-time values of parameter X and parameter Y of the current vehicle, assuming that parameter X and parameter Y are both 2 bytes, the server can pre-process the shared memory in a Chunk manner so that each shared memory block is 2 bytes to match the value size of parameter X and parameter Y corresponding to the event release. At this time, the parameter data can be quickly written and read while saving shared memory space.
[0098] Figure 3 A flow chart of another method for communicating between a server and a client in an ECU provided by an embodiment of the present invention.
[0099] The client sends a subscription request to the server to register for read event 1;
[0100] Based on the subscription request, the server allocates a list 1 and returns the elements in list 1 of event 1;
[0101] The client retrieves data from the shared memory based on the first address header content in List 1;
[0102] If there is new data written on the server, a semaphore is sent to the client;
[0103] The client retrieves new data from the shared memory based on the first address header content in List 1.
[0104] The embodiment of the present invention combines SOME / IP with shared memory and uses a queue to manage the list corresponding to each event, so that the client can obtain subscription data from the corresponding address of the shared memory based on the elements in the list, thereby greatly improving the data transmission efficiency of the SOME / IP protocol in local communication and the communication efficiency of the entire vehicle.
[0105] In some embodiments, Figure 4 As shown, the embodiment of the present invention further provides a server-client communication device 200 in an ECU, comprising:
[0106] Configuration module 201, when the startup timing is reached, reads the server configuration file and configures the queue and shared memory accordingly;
[0107] The updating module 202 writes the first data corresponding to each event into the shared memory, and updates the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory; wherein each event corresponds to a list in the queue, and each list includes a reference count element, a semaphore element and a data first address element;
[0108] The communication module 203 determines the target event from each of the events according to the subscription request sent by each client, and sends the first address element and the semaphore element corresponding to the target event to each of the clients, so that each of the clients obtains the first data published corresponding to the target event from the shared memory according to the first address element; wherein the client and the server are configured in the same ECU.
[0109] In some embodiments, the device is also specifically used to: when the second data is re-published for any event, the semaphore element in the list corresponding to any event is sent to at least one client that subscribes to any event, so that at least one of the clients searches for the corresponding first address element according to the received semaphore element and obtains the second data from the shared memory.
[0110] Furthermore, the configuration module 201 is specifically used to initialize the shared memory; read the server configuration file to obtain the number of publishable events, the preset memory size and the preset memory allocation method included in the server configuration file; apply for shared memory according to the preset memory size, and process the shared memory based on the preset memory allocation method; set the number of lists in the queue according to the number of publishable events; and perform initial configuration on the data first address element in the list according to the shared memory processed by the preset memory allocation method.
[0111] In some embodiments, the preset memory allocation mode includes a large block allocation mode and a partner allocation mode.
[0112] In some embodiments, the update module 202 is further specifically configured to update the first address element of each event to be published in the order of obtaining the unique write permission if there are multiple events to be published at the same time;
[0113] In some embodiments, the update module 202 is further specifically used to write the first data published corresponding to the first event that currently obtains the unique write permission into the shared memory according to the first address element; when the first data published corresponding to the first event has been completely written to the actual address in the shared memory, update the first address element in the list corresponding to the next second event that obtains the unique write permission according to the actual address in the shared memory; take the second event as the new first event, and return to execute the step of writing the first data published corresponding to the first event that currently obtains the unique write permission into the shared memory according to the first address element, until each of the events to be published has been traversed.
[0114] In some embodiments, the update module 202 is also specifically used to, if there are multiple events to be published at the same time, write the first data corresponding to each event to be published into the shared memory based on the first address element initially configured in the list corresponding to each event to be published; wherein the first address initially configured in the list corresponding to each event to be published is the first address in a preset number of continuous shared memory blocks; the shared memory blocks are evenly cut from the shared memory, and the size of each shared memory block matches the size of the first data.
[0115] In some embodiments, the start timing is divided by the trigger priority of the corresponding function type of the server; when the trigger priority of the function type reaches a preset range, the start timing includes power-on start; when the trigger priority of the function type does not reach a preset range, the start timing includes preset period start, preset condition trigger and preset control signal trigger.
[0116] Figure 5 Schematic diagram of the hardware architecture of the electronic device 300 provided in an embodiment of the present invention. Figure 5 As shown, the electronic device 300 includes: a machine-readable storage medium 301 and a processor 302, and may also include a non-volatile storage medium 303, a communication interface 304 and a bus 305; wherein the machine-readable storage medium 301, the processor 302, the non-volatile storage medium 303 and the communication interface 304 complete mutual communication through the bus 305. The processor 302 can execute the server-client communication method in the ECU described in the above embodiment by reading and executing the machine-executable instructions for communication between the server and the client in the ECU in the machine-readable storage medium 301.
[0117] The machine-readable storage medium mentioned in this article can be any electronic, magnetic, optical or other physical storage device that can contain or store information, such as executable instructions, data, etc. For example, the machine-readable storage medium can be: RAM (Radom Access Memory), volatile memory, non-volatile memory, flash memory, storage drive (such as hard disk drive), any type of storage disk (such as CD, DVD, etc.), or similar storage medium, or a combination thereof.
[0118] The non-volatile medium may be a non-volatile memory, a flash memory, a storage drive (such as a hard drive), any type of storage disk (such as a CD, DVD, etc.), or a similar non-volatile storage medium, or a combination thereof.
[0119] It can be understood that the specific operation methods of each functional module in this embodiment can refer to the detailed description of the corresponding steps in the above method embodiment, and will not be repeated here.
[0120] The computer-readable storage medium provided in the embodiment of the present invention stores a computer program. When the computer program code is executed, the server-client communication method within the ECU described in any of the above embodiments can be implemented. The specific implementation can be found in the method embodiment, which will not be repeated here.
[0121] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0122] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0123] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.
[0124] Finally, it should be noted that the above-described embodiments are only specific implementation methods of the present invention, which are used to illustrate the technical solutions of the present invention rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the aforementioned embodiments, those of ordinary skill in the art should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the aforementioned embodiments within the technical scope disclosed by the present invention, or can easily conceive of changes, or make equivalent replacements for some of the technical features therein. Such modifications, changes or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the protection scope of the present invention.
Claims
1. A method for communication between a server and a client in an ECU, characterized in that: include: When the startup time comes, read the server configuration file and configure the queue and shared memory accordingly; Write the first data corresponding to each event into the shared memory, and update the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory; wherein each event corresponds to a list in the queue, and each list includes a reference count element, a semaphore element and a data first address element; According to the subscription request sent by each client, the target event is determined from each of the events, and the first address element and semaphore element corresponding to the target event are sent to each of the clients, so that each of the clients obtains the first data corresponding to the target event from the shared memory according to the first address element; wherein the client and the server are configured in the same ECU.
2. The method according to claim 1, characterized in that The method further comprises: When the second data is published for any event, the semaphore element in the list corresponding to the event is sent to at least one client subscribing to the event, so that at least one client searches for the corresponding first address element according to the received semaphore element and obtains the second data from the shared memory.
3. The method according to claim 1, characterized in that The steps to read the server configuration file and configure the queue and shared memory accordingly include: Initialize the shared memory; Reading a server configuration file, obtaining the number of publishable events, a preset memory size, and a preset memory allocation method included in the server configuration file; Applying for shared memory according to the preset memory size, and processing the shared memory based on the preset memory allocation method; Set the number of lists in the queue according to the number of publishable events; The shared memory processed according to the preset memory allocation method is initially configured for the data first address element in the list.
4. The method according to claim 3, characterized in that: The preset memory allocation mode includes a large block allocation mode and a partner allocation mode.
5. The method according to claim 4, characterized in that The step of writing the first data corresponding to each event into the shared memory, and updating the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory, comprises: If there are multiple events to be published at the same time, the first address element of each event to be published is updated in the order of obtaining unique write permissions, including: Writing the first data published corresponding to the first event that currently obtains the only write permission into the shared memory according to the first address element; When the first data corresponding to the first event has been completely written into the actual address in the shared memory, the first address element in the list corresponding to the second event that obtains the unique write permission is updated according to the actual address in the shared memory; The second event is taken as a new first event, and the step of writing the first data corresponding to the first event that currently obtains the only write permission into the shared memory is returned to be executed according to the first address element, until each of the events to be published is traversed and terminated.
6. The method according to claim 4, characterized in that The step of writing the first data corresponding to each event into the shared memory, and updating the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory, comprises: If there are multiple events to be published at the same time, the first data corresponding to each event to be published is written into the shared memory according to the first address element initially configured in the list corresponding to each event to be published; Among them, the first address initially configured in each list corresponding to the event to be published is the first address in a preset number of continuous shared memory blocks; the shared memory blocks are evenly cut from the shared memory, and the size of each shared memory block matches the size of the first data.
7. The method according to claim 1 or 3, characterized in that: The startup timing is divided by the trigger priority of the corresponding function type of the server; When the trigger priority of the function type reaches a preset range, the startup timing includes power-on startup; When the trigger priority of the function type does not reach a preset range, the start timing includes preset period start, preset condition trigger and preset control signal trigger.
8. A communication device between a server and a client in an ECU, characterized in that: include: The configuration module reads the server configuration file and configures the queue and shared memory accordingly when the startup time is reached; An update module writes the first data corresponding to each event into the shared memory, and updates the first address element in the list corresponding to each event in the queue according to the actual address of the first data corresponding to each event in the shared memory; wherein each event corresponds to a list in the queue, and each list includes a reference count element, a semaphore element and a data first address element; A communication module determines a target event from each of the events according to a subscription request sent by each client, and sends a first address element and a semaphore element corresponding to the target event to each of the clients, so that each of the clients obtains the first data published corresponding to the target event from the shared memory according to the first address element; wherein the client and the server are configured in the same ECU.
9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program that can be run on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.
10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the steps of the method described in any one of claims 1 to 7.