SoAd interface and POSIX socket interface adaptation method
By calling SoAd_IfTransmit and Socket_SoAdRxIndication functions in the adaptation layer, the adaptation between the SoAd interface and the POSIX socket interface is solved, and the difficulty of porting POSIX network applications on AUTOSAR CP is improved, and the porting efficiency and flexibility are improved.
Patent Information
- Application Number
- CN202411118398.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-11-15
AI Technical Summary
The SoAd interface of AUTOSAR CP cannot be directly connected to the POSIX socket interface, which makes it difficult to port POSIX network applications on AUTOSAR CP.
Send network data by calling the SoAd_IfTransmit function in the adapter layer, and calling the Socket_SoAdRxIndication function when receiving Ethernet data, store the data into the ring buffer, sending Event events to the POSIX socket program, making it call the recvmsg function based on the Event event, from The ring buffer reads data to realize the adaptation between the SoAd interface and the POSIX socket interface.
It improves the efficiency of porting network application systems with POSIX interface to AUTOSAR CP real-time system, reduces the amount of code modifications, and improves portability flexibility.
Smart Images

Figure CN118972398A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automotive electronics, and in particular to a method for adapting a SoAd interface to a POSIX socket interface. Background Art
[0002] Open software architecture for automotive electronic systems (AUTOSAR CP (Classic Platform)), service-oriented analysis and design SoAd module to achieve communication with TCP / IP protocol stack. The main purpose of the SoAd module is to create an interface between the AUTOSAR communication service module and the TCP / IP protocol stack. The main interfaces of SoAd are: SoAd_IfTransmit(Std_ReturnType,PduIdType,const PduInfoType*), PduR_SoAdTxConfirmation(PduIdType,Std_ReturnType), PduR_SoAdRxIndication(PduIdType,const PduInfoType*). SoAd relies on PDU (Protocol Data Unit) protocol data unit PduId to distinguish different communication channels. The main POSIX socket interfaces are: socket, bind, connect, accept, recv, recvmsg, send, sendmsg.
[0003] The POSIX socket interface relies on socket descriptors to distinguish different communication channels. Therefore, the SoAd interface of AUTOSAR CP and the socket interface of POSIX cannot be directly connected. A solution that can adapt the SoAd interface and the socket interface is needed to facilitate the porting of POSIX network applications on AUTOSAR CP.
[0004] The above contents are only used to assist in understanding the technical solution of the present invention and do not constitute an admission that the above contents are prior art. Summary of the invention
[0005] The main purpose of the present invention is to provide a method for adapting a SoAd interface to a POSIX socket interface, aiming to solve the technical problem of how to design a solution for adapting a SoAd interface to a POSIX socket interface, so as to facilitate the transplantation of POSIX network applications on AUTOSAR CP.
[0006] To achieve the above object, the present invention provides a method for adapting a SoAd interface to a POSIX socket interface, the method comprising:
[0007] When it is detected that the POSIX socket program sends network data, the SoAd_IfTransmit function is called in the adaptation layer based on the POSIX sendmsg function, and the network data is sent to the SoAd according to the SoAd_IfTransmit function;
[0008] When it is detected that the SoAd receives Ethernet data, the adaptation layer Socket_SoAdRxIndication function is called to store the Ethernet data in the ring buffer corresponding to the socket, and the Event event is sent to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, so that the POSIX socket program calls the resvmsg function based on the Event event to read the Ethernet data from the ring buffer.
[0009] Optionally, the step of calling the SoAd_IfTransmit function based on the POSIX sendmsg function comprises:
[0010] Obtain the socket descriptor corresponding to the socket creation function called by the POSIX socket program;
[0011] Convert the socket descriptor into a corresponding PduId according to the Socket-PduId hash table, and use the network data and the PduId as parameters;
[0012] The SoAd_IfTransmit function is called through the POSIX sendmsg function based on the parameters.
[0013] Optionally, after the step of converting the socket descriptor into a corresponding PduId according to the Socket-PduId hash table, the method further includes:
[0014] After the conversion is successful, call the SoAd function SoAd_SetRemoteAddr to set the remote address and port.
[0015] Optionally, the step of sending the network data to SoAd according to the SoAd_IfTransmit function comprises:
[0016] Determine the SoAd PduId channel corresponding to the SoAd_IfTransmit function;
[0017] The network data is sent to the SoAd based on the SoAd PduId channel.
[0018] Optionally, before the step of calling the adaptation layer Socket_SoAdRxIndication function to store the Ethernet data into a ring buffer corresponding to the socket, the step includes:
[0019] The adaptation layer Socket_SoAdRxIndication function is registered based on the SoAd_IfRxIndication function according to the reference of UpperModuleRef in the SoAd configuration.
[0020] Optionally, the step of calling the adaptation layer Socket_SoAdRxIndication function to store the Ethernet data into a ring buffer corresponding to the socket includes:
[0021] Call the adaptation layer Socket_SoAdRxIndication function and obtain the socket descriptor corresponding to SoAdPduId according to the PduId-socket hash table;
[0022] The ring buffer corresponding to the socket is determined according to the socket descriptor, and the Ethernet data is stored in the ring buffer corresponding to the socket.
[0023] Optionally, after the step of storing the Ethernet data in the ring buffer corresponding to the socket, the method further includes:
[0024] The remote IP address and port corresponding to the Ethernet data are recorded.
[0025] Optionally, after the step of sending the Event event to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, the method further includes:
[0026] The cond_wait condition variable in the socket packet receiving processing function is used to wait for the function to release the blocking state.
[0027] In addition, to achieve the above-mentioned purpose, the present invention also proposes a SoAd interface and POSIX socket interface adaptation device, the device comprising: a memory, a processor, and a SoAd interface and POSIX socket interface adaptation program stored in the memory and executable on the processor, the SoAd interface and POSIX socket interface adaptation program being configured to implement the steps of the SoAd interface and POSIX socket interface adaptation method as described above.
[0028] In addition, to achieve the above-mentioned purpose, the present invention also proposes a storage medium, on which a SoAd interface and POSIX socket interface adapter is stored. When the SoAd interface and POSIX socket interface adapter is executed by a processor, the steps of the SoAd interface and POSIX socket interface adaptation method described above are implemented.
[0029] When the present invention detects that the POSIX socket program sends network data, the SoAd_IfTransmit function is called based on the POSIX sendmsg function, and the network data is sent to SoAd according to the SoAd_IfTransmit function; when it is detected that SoAd receives Ethernet data, the adaptation layer Socket_SoAdRxIndication function is called to store the Ethernet data in the ring buffer corresponding to the socket, and the Event event is sent to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, so that the POSIX socket program calls the resvmsg function based on the Event event to read the Ethernet data from the ring buffer. Through the above adaptation scheme, the present invention improves the efficiency of transplanting the network application system of the POSIX interface to the AUTOSAR CP real-time system, reduces the amount of code modification, and improves the transplant flexibility of the network application system of the POSIX interface. BRIEF DESCRIPTION OF THE DRAWINGS
[0030] Figure 1 It is a structural diagram of a SoAd interface and a POSIX socket interface adapter device of a hardware operating environment involved in an embodiment of the present invention;
[0031] Figure 2 It is a flow chart of a first embodiment of a method for adapting a SoAd interface to a POSIX socket interface according to the present invention;
[0032] Figure 3This is a timing diagram of POSIXAUTOSAR-CP adaptation layer initialization according to the first embodiment of the method for adapting the SoAd interface to the POSIX socket interface of the present invention;
[0033] Figure 4 A structural diagram of the POSIX-AUTOSAR CP adaptation layer of the first embodiment of the method for adapting the SoAd interface to the POSIX socket interface of the present invention;
[0034] Figure 5 This is a timing diagram of data transmission and reception of the POSIXAUTOSAR-CP adaptation layer of the first embodiment of the SoAd interface and POSIX socket interface adaptation method of the present invention.
[0035] The realization of the purpose, functional features and advantages of the present invention will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0036] It should be understood that the specific embodiments described herein are only used to explain the present invention, and are not used to limit the present invention.
[0037] Reference Figure 1 , Figure 1 The present invention is a schematic diagram of the structure of the SoAd interface and POSIX socket interface adapter device of the hardware operating environment involved in the embodiment of the present invention.
[0038] like Figure 1 As shown, the SoAd interface and POSIX socket interface adapter device may include: a processor 1001, such as a central processing unit (CPU), a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 may include a display screen (Display), an input unit such as a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a wireless fidelity (Wireless-Fidelity, Wi-Fi) interface). The memory 1005 may be a high-speed random access memory (Random Access Memory, RAM), or a stable non-volatile memory (Non-Volatile Memory, NVM), such as a disk storage. The memory 1005 may also be a storage system independent of the aforementioned processor 1001.
[0039] Those skilled in the art will understand that Figure 1The structure shown in the figure does not constitute a limitation on the SoAd interface and POSIX socket interface adaptation device, and may include more or less components than those shown in the figure, or combine certain components, or arrange the components differently.
[0040] like Figure 1 As shown, the memory 1005 as a storage medium may include an operating system, a network communication module, a user interface module, and a SoAd interface and POSIX socket interface adapter.
[0041] exist Figure 1 In the SoAd interface and POSIX socket interface adaptation device shown, the network interface 1004 is mainly used for data communication with the network server; the user interface 1003 is mainly used for data interaction with the user; the processor 1001 and the memory 1005 in the SoAd interface and POSIX socket interface adaptation device of the present invention can be set in the SoAd interface and POSIX socket interface adaptation device, and the SoAd interface and POSIX socket interface adaptation device calls the SoAd interface and POSIX socket interface adaptation program stored in the memory 1005 through the processor 1001, and executes the SoAd interface and POSIX socket interface adaptation method provided by the embodiment of the present invention.
[0042] The embodiment of the present invention provides a method for adapting a SoAd interface to a POSIX socket interface, referring to Figure 2 , Figure 2 It is a flowchart of the first embodiment of the method for adapting the SoAd interface to the POSIX socket interface of the present invention.
[0043] In this embodiment, the method for adapting the SoAd interface to the POSIX socket interface includes the following steps:
[0044] Step S10: when it is detected that the POSIX socket program sends network data, the SoAd_IfTransmit function is called in the adaptation layer based on the POSIX sendmsg function, and the network data is sent to the SoAd according to the SoAd_IfTransmit function.
[0045] It is easy to understand that the execution subject of this embodiment can be an AUTOSAR-CP adaptation layer with functions such as data processing, network communication and program running, or other computer equipment with similar functions, etc., and this embodiment is not limited thereto.
[0046] In the specific implementation, refer to Figure 3 , Figure 3This is a POSIX AUTOSAR-CP adaptation layer initialization timing diagram of the first embodiment of the SoAd interface and POSIX socket interface adaptation method of the present invention. When the POSIX network application (i.e., the POSIX socket program) is initialized, the InitSocketAdaptor function is called, and then the InitSocketPduIdMapping function is called to initialize Hash Map1 (i.e., the Socket-PduId hash table) to configure the socket-PduId mapping relationship, and the InitPduIdSocketMapping function is called to initialize Hash Map2 (i.e., the PduId-socket hash table) to configure the PduId-socket mapping relationship.
[0047] The POSIX network application calls socket() to obtain the socket descriptor. The GetSocket function searches HashMap1, returns the corresponding socket value, and sets the isUsed flags of Hash Map1 and Hash Map2 to true.
[0048] In the real-time system of AUTOSAR CP in this embodiment, several SoAd channels are created and bound to corresponding local ports during initialization, and a bidirectional hash table is established: Hash Map 1 of SoAd PduId and socket descriptor is initialized, with socket descriptor as key and SoAd PduId as value; Hash Map 2 of SoAd PduId and socket descriptor is initialized, with SoAd PduId socket descriptor as key and socket as value. The number of SoAd communication channels to be configured is determined before operation, and these static communication channels are configured, and the corresponding Hash Map table status is unused.
[0049] It should be understood that the specific implementation is: Hash Map algorithm, using offset value combined with prime number modulus algorithm, the prime number selected must be greater than the number of sockets in the system, the implementation system has 20 sockets, and the selected prime number is 29. When the POSIX network application is initialized, it calls the InitSocketAdaptor function, and then calls the InitSocketPduIdMapping function to initialize Hash Map1 to configure the socket-PduId mapping relationship, and calls the InitPduIdSocketMapping function to initialize Hash Map2 to configure the PduId-socket mapping relationship.
[0050] Furthermore, the processing method of calling the SoAd_IfTransmit function in the adaptation layer based on the POSIX sendmsg function is to obtain the socket descriptor corresponding to the socket creation function called by the POSIX socket program; convert the socket descriptor into the corresponding PduId according to the Socket-PduId hash table, and after the conversion is successful, call the SoAd set remote address and port function SoAd_SetRemoteAddr, and use the network data and PduId as parameters; based on the parameters, call the SoAd_IfTransmit function in the adaptation layer through the POSIX sendmsg function.
[0051] It should also be noted that the adaptation layer calls the SoAd_IfTransmit function when implementing the sendmsg function. POSIX only calls the sendmsg interface function and does not specifically implement the sendmsg function.
[0052] When the socket closes the socket descriptor, SoAd does not directly release the channel, but sets the corresponding HashMap table status to unused. Therefore, it is necessary to determine the socket status. If it has been opened and used, the socket descriptor is converted into the PduId of SoAd through the hash table Hash Map1.
[0053] It should be understood that each socket has a corresponding receiving ring buffer, and the size of the receiving ring buffer of each socket is statically configured according to the flow of corresponding data actually received by the system.
[0054] Furthermore, the processing method of sending the network data to SoAd according to the SoAd_IfTransmit function is to determine the SoAd PduId channel corresponding to the SoAd_IfTransmit function; and send the network data to SoAd based on the SoAd PduId channel.
[0055] In the specific implementation, refer to Figure 4 , Figure 4 This is a structural diagram of the POSIX-AUTOSAR CP adaptation layer of the first embodiment of the method for adapting the SoAd interface to the POSIX socket interface of the present invention. Figure 4During runtime, the network application of the POSIX interface calls the socket creation function, obtains the corresponding socket descriptor according to the creation time sequence, and then obtains the corresponding SoAd PduId according to HashMap 1. The socket status is determined. If it has been opened and used, the socket descriptor is converted into the SoAd PduId through the hash table Hash Map1, otherwise an error is returned. After the SoAd PduId is successfully converted, the SoAd remote address and port setting function SoAd_SetRemoteAddr is called, and then SoAd_IfTransmit is called with PduId and the data payload to be sent as parameters to send the network data to the SoAd layer, and then the TCP / IP protocol stack is called through SoAd, and finally the network data is sent to the Ethernet interface.
[0056] It should also be noted that the reference Figure 5 , Figure 5 This is a timing diagram of data transmission and reception of the POSIX AUTOSAR-CP adaptation layer of the first embodiment of the SoAd interface and POSIX socket interface adaptation method of the present invention. When sending data, the POSIX socket program calls sendmsg, and after conversion by the POSIX AUTOSAR-CP adaptation layer, the SoAd_IfTransmit function is called.
[0057] Step S20: When it is detected that the SoAd receives Ethernet data, the adaptation layer Socket_SoAdRxIndication function is called to store the Ethernet data in the ring buffer corresponding to the socket, and the Event event is sent to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, so that the POSIX socket program calls the resvmsg function based on the Event event to read the Ethernet data from the ring buffer.
[0058] It should be noted that the adaptation layer Socket_SoAdRxIndication function processes the received data and stores the data in the ring buffer corresponding to the socket. The event notifies the POSIX socket program, which then calls the resvmsg function to read the data from the ring buffer.
[0059] Furthermore, when it is detected that the SoAd receives Ethernet data, the adaptation layer Socket_SoAdRxIndication function is registered based on the reference of UpperModuleRef in the SoAd configuration based on the SoAd_IfRxIndication function, the adaptation layer Socket_SoAdRxIndication function is called, and the socket descriptor corresponding to the SoAd PduId is obtained according to the PduId-socket hash table; the ring buffer corresponding to the socket is determined according to the socket descriptor, and the Ethernet data is stored in the ring buffer corresponding to the socket, and the remote IP address and port corresponding to the Ethernet data are recorded, and the Event event is sent to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, so that the POSIX socket program waits for the function to release the blocking state through the cond_wait condition variable in the socket packet receiving processing function, and calls the resvmsg function based on the Event event to read the Ethernet data from the ring buffer.
[0060] It should also be noted that Ethernet data is network data received from a network cable.
[0061] In this embodiment, reference Figure 4 and Figure 5 When receiving data, after receiving the network data, the SoAd module of AUTOSAR-CP calls the adaptation layer Socket_SoAdRxIndication function to store the data into the ring buffer corresponding to the socket. Socket_SoAdRxIndication sends the Event event to the POSIX socket program, and then calls the resvmsg function to read the data from the ring buffer.
[0062] In the specific implementation, in the SoAd_IfRxIndication function, a callback function Socket_SoAdRxIndication is registered according to the reference of UpperModuleRef in the SoAd configuration. After receiving the Ethernet data, SoAd calls Socket_SoAdRxIndication, searches the Socket-PduId hash table Hash Map2 to obtain the application layer socket descriptor corresponding to the SoAd PduId, and determines the status of the socket. If it has been opened and used, the received network data is copied into the ring buffer corresponding to the socket, and the remote IP address and port corresponding to the received data are recorded. Then the event SetEvent is sent to notify the network application of the POSIX interface, so that the cond_wait condition variable in the socket packet receiving processing function waits for the function to release the blocking state, and then the recvmsg function is called to read the received network data from the ring buffer corresponding to the socket.
[0063] In this embodiment, when it is detected that the POSIX socket program sends network data, the sendmsg function based on POSIX calls the SoAd_IfTransmit function in the adaptation layer, and sends the network data to SoAd according to the SoAd_IfTransmit function; when it is detected that SoAd receives Ethernet data, the adaptation layer Socket_SoAdRxIndication function is called to store the Ethernet data in the ring buffer corresponding to the socket, and the Event event is sent to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, so that the POSIX socket program calls the resvmsg function based on the Event event to read the Ethernet data from the ring buffer. For the real-time system of AUTOSAR CP, this embodiment adopts the adaptation layer solution of SoAd and socket interface, creates several SoAd channels and binds corresponding local ports during initialization, and initializes the HashMap of SoAd PduId and socket descriptor, which is a collection for storing Key-Value key-value pairs. Each key-value pair is also called Entry, Hash Map1 and Hash Map2, to implement static mapping of SoAd PduId and socket descriptor. Hash Map1 implements mapping from socket descriptor to SoAd PduId. Hash Map2 implements mapping from SoAd PduId to socket descriptor. At runtime, the network application of POSIX interface calls the socket creation function, obtains the corresponding socket descriptor according to the time sequence of creation, and then obtains the corresponding SoAd PduId according to HashMap1. The sendmsg function of POSIX directly calls SoAd_IfTransmit to use the interface to send data to the corresponding SoAd PduId channel. Register a callback function Socket_SoAdRxIndication to the SoAd receiving function. After receiving Ethernet data, SoAd calls Socket_SoAdRxIndication, searches for the socket descriptor according to SoAd PduId and the Hash Map2 of the socket descriptor, and stores the received network data in the receiving ring buffer corresponding to the socket descriptor. The POSIX interface network application can read the received network data from the ring buffer by calling the recvmsg function. This approach can improve the efficiency of porting the POSIX interface network application system to the AUTOSAR CP real-time system, reduce the amount of code modification, and improve the porting flexibility of the POSIX interface network application system.
[0064] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or system including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or system. In the absence of further restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or system including the element.
[0065] The serial numbers of the above embodiments of the present invention are only for description and do not represent the advantages or disadvantages of the embodiments.
[0066] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as a read-only memory / random access memory, a magnetic disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0067] The above are only preferred embodiments of the present invention, and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for adapting a SoAd interface to a POSIX socket interface, characterized in that: The method for adapting the SoAd interface to the POSIX socket interface comprises the following steps: When it is detected that the POSIX socket program sends network data, the SoAd_IfTransmit function is called in the adaptation layer based on the POSIX sendmsg function, and the network data is sent to the SoAd according to the SoAd_IfTransmit function; When it is detected that the SoAd receives Ethernet data, the adaptation layer Socket_SoAdRxIndication function is called to store the Ethernet data in the ring buffer corresponding to the socket, and the Event event is sent to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, so that the POSIX socket program calls the resvmsg function based on the Event event to read the Ethernet data from the ring buffer.
2. The method according to claim 1, characterized in that The step of calling the SoAd_IfTransmit function in the adaptation layer based on the POSIX sendmsg function includes: Obtain the socket descriptor corresponding to the socket creation function called by the POSIX socket program; Convert the socket descriptor into a corresponding PduId according to the Socket-PduId hash table, and use the network data and the PduId as parameters; Based on the parameters, the SoAd_IfTransmit function is called in the adaptation layer through the POSIX sendmsg function.
3. The method according to claim 2, characterized in that After the step of converting the socket descriptor into a corresponding PduId according to the Socket-PduId hash table, the method further includes: After the conversion is successful, call the SoAd function SoAd_SetRemoteAddr to set the remote address and port.
4. The method according to claim 3, characterized in that The step of sending the network data to SoAd according to the SoAd_IfTransmit function comprises: Determine the SoAd PduId channel corresponding to the SoAd_IfTransmit function; The network data is sent to the SoAd based on the SoAd PduId channel.
5. The method according to claim 1, characterized in that Before the step of calling the adaptation layer Socket_SoAdRxIndication function to store the Ethernet data into the ring buffer corresponding to the socket, the method includes: The adaptation layer Socket_SoAdRxIndication function is registered based on the SoAd_IfRxIndication function according to the reference of UpperModuleRef in the SoAd configuration.
6. The method according to claim 1, characterized in that The step of calling the adaptation layer Socket_SoAdRxIndication function to store the Ethernet data into the ring buffer corresponding to the socket comprises: Call the adaptation layer Socket_SoAdRxIndication function and obtain the socket descriptor corresponding to SoAdPduId according to the PduId-socket hash table; The ring buffer corresponding to the socket is determined according to the socket descriptor, and the Ethernet data is stored in the ring buffer corresponding to the socket.
7. The method according to claim 6, characterized in that After the step of storing the Ethernet data in the ring buffer corresponding to the socket, the method further includes: The remote IP address and port corresponding to the Ethernet data are recorded.
8. The method according to claim 7, characterized in that After the step of sending the Event event to the POSIX socket program through the adaptation layer Socket_SoAdRxIndication function, the method further includes: The cond_wait condition variable in the socket packet receiving processing function is used to wait for the function to release the blocking state.
