Data transmission method and device, vehicle and storage medium
By adding an intermediate software layer between the application layer and the driving layer in the vehicle, and using the notification interface to detect the status of the second terminal, the portability and compatibility problems of data transmission logic in the prior art are solved, and efficient and accurate data transmission is achieved.
Patent Information
- Application Number
- CN202411655465.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-04-08
AI Technical Summary
In the prior art, the data transmission method of the Linux operating system in the vehicle and other terminals is not conducive to the portability and compatibility of the data transmission logic.
By adding an intermediate software layer between the application layer and the driving layer of the first terminal in the vehicle, and performing data transmission logic with the second terminal by the middleware layer, the notification interface detects the status of the second terminal to determine whether data transmission is performed.
It improves the efficiency and accuracy of data transmission, enhances the portability and compatibility of data transmission logic, and reduces the complexity of development and maintenance.
Smart Images

Figure CN119781824A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of vehicle technology, and in particular to a data transmission method, device, vehicle and storage medium. Background Art
[0002] The Linux operating system is widely used in various environments such as embedded devices and automotive data acquisition due to its stability and high performance. In the process of data acquisition, data transmission between the Linux operating system and other terminals (such as other MCU (Microcontroller Unit) terminals in the vehicle) is crucial.
[0003] At present, for data transmission between the Linux operating system and other terminals, the relevant transmission logic is generally executed through the driver layer of the Linux operating system. However, this method is a challenge to the portability of the driver. When the relevant transmission logic is executed through the driver layer of other environments, the application layer cannot interact normally with the driver layer. This requires the relevant transmission logic of the driver layer to be adapted to the application layer accordingly, which is not conducive to the portability and compatibility of the data transmission logic. Summary of the invention
[0004] The present application provides a data transmission method, device, vehicle and storage medium to solve the technical problem that the data transmission method between the Linux operating system in the vehicle and other terminals in the prior art is not conducive to the portability and compatibility of the data transmission logic.
[0005] In a first aspect, the present application provides a data transmission method, which is applied to a middleware layer of a first terminal in a vehicle, wherein the first terminal includes an application layer, a middleware layer, and a driver layer, and the method includes:
[0006] When it is determined that the application layer is performing data transmission with the second terminal, updating the first notification interface in the driver layer to a preset state;
[0007] detecting a current state of a second notification interface in the second terminal, the second notification interface being connected to the first notification interface;
[0008] When it is detected that the current state of the second notification interface is the preset state, data is transmitted with the second terminal through the transmission interface of the driving layer.
[0009] As a possible implementation manner, the determining that the application layer performs data transmission with the second terminal includes:
[0010] In a case where the data to be transmitted sent by the application layer is received through the preset interface, determining that the application layer performs data transmission with the second terminal;
[0011] or,
[0012] In case of receiving a transmission signal sent by the second terminal, it is determined that the application layer performs data transmission with the second terminal, wherein the transmission signal is used to indicate that the second terminal performs data transmission with the first terminal.
[0013] As a possible implementation manner, the detecting a current state of the second notification interface in the second terminal includes:
[0014] Obtaining a file path of a target file corresponding to the second notification interface in the second terminal, where the target file is used to record a current state of the second notification interface;
[0015] According to the file path, the current state of the second notification interface of the target file record is obtained.
[0016] As a possible implementation manner, acquiring the current state of the second notification interface recorded in the target file according to the file path includes:
[0017] Writing the file path into a preset file monitoring tool, so that the file monitoring tool monitors the target file corresponding to the file path, and triggers a preset event when the target file is changed;
[0018] Obtaining a file descriptor corresponding to the file monitoring tool, and writing the file descriptor into a preset monitoring function, so that the monitoring function monitors whether the file monitoring tool triggers a preset event;
[0019] In the case where the file monitoring tool triggers a preset event through the monitoring function, the preset reading function is used to block and wait for the preset event, and the current value of the target file record is read;
[0020] According to the current value, a current state of the second notification interface of the target file record is determined.
[0021] As a possible implementation, the second notification interface is a general purpose input / output port GPIO interface, the preset state is a rising edge state of the GPIO interface, and the determining, according to the current value, the current state of the second notification interface recorded in the target file includes:
[0022] When the current value is the first value, determining that the current state of the second notification interface of the target file record is a rising edge state;
[0023] When the current value is the second value, it is determined that the current state of the second notification interface of the target file record is a falling edge state.
[0024] As a possible implementation method, it also includes:
[0025] Upon receiving the data to be transmitted sent by the application layer, and in the case that the file monitoring tool does not trigger a preset event through the monitoring function within a preset time period, the data to be transmitted is stored in a preset timeout queue;
[0026] Re-execute the following steps at least once: after updating the first notification interface in the driver layer to a non-preset state, update the first notification interface to the preset state again; determine whether the file monitoring tool triggers a preset event by monitoring the monitoring function within a preset time period;
[0027] When the file monitoring tool triggers a preset event through the monitoring function within a preset time period and it is determined that the second notification interface is in a preset state, the data to be transmitted in the timeout queue is sent to the second terminal.
[0028] As a possible implementation method, it also includes:
[0029] In the case that the preset event triggered by the file monitoring tool is not monitored by the monitoring function every time after the preset time period, determining an abnormal stage in which an abnormality occurs in the process of detecting the current state of the second notification interface;
[0030] Determining a target error identifier corresponding to the abnormal stage from a pre-stored correspondence between abnormal stages and error identifiers;
[0031] The target error identifier is sent to the application layer, so that the application layer corrects the abnormal phase based on the target error identifier.
[0032] As a possible implementation manner, the second notification interface corresponds to an interruption configuration file, the interruption configuration file is used to record a preset state of the second notification interface, and the preset state is used to represent a state of data transmission with the first terminal;
[0033] The step of, when detecting that the current state of the second notification interface is the preset state, transmitting data with the second terminal through the transmission interface of the driving layer includes:
[0034] Acquire a preset state corresponding to the second notification interface from the interruption configuration file;
[0035] When the current state is the preset state recorded in the interrupt configuration file, triggering a preset interrupt signal;
[0036] When the interrupt signal is detected, data is transmitted to the second terminal through the transmission interface of the driving layer.
[0037] In a second aspect, the present application provides a data transmission device, which is applied to a middleware layer of a first terminal in a vehicle, wherein the first terminal includes an application layer, a middleware layer, and a driver layer, and the device includes:
[0038] An updating module, configured to update the first notification interface in the driver layer to a preset state when it is determined that the application layer is performing data transmission with the second terminal;
[0039] a detection module, configured to detect a current state of a second notification interface in the second terminal, the second notification interface being connected to the first notification interface;
[0040] A transmission module is used to transmit data with the second terminal through the transmission interface of the driving layer when it is detected that the current state of the second notification interface is the preset state.
[0041] In a third aspect, the present application provides a vehicle, comprising a processor and a memory, wherein the processor is used to execute a data transmission program stored in the memory to implement the data transmission method described in any one of the first aspects.
[0042] In a fourth aspect, the present application provides a storage medium storing one or more programs, wherein the one or more programs can be executed by one or more processors to implement the data transmission method described in any one of the first aspects.
[0043] The technical solution provided by the embodiment of the present application updates the first notification interface in the driver layer to a preset state when it is determined that the application layer is transmitting data with the second terminal, detects the current state of the second notification interface in the second terminal, and the second notification interface is connected to the first notification interface. When it is detected that the current state of the second notification interface is the preset state, data is transmitted with the second terminal through the transmission interface of the driver layer. This technical solution, by adding a middleware layer between the application layer and the driver layer of the first terminal in the vehicle, and the middleware layer executes the data transmission logic with the second terminal, there is no need to change the driver, avoiding new problems and bugs that may be introduced during the driver migration process, reducing the complexity of development and maintenance, and the application layer does not need to pay attention to the specific implementation of the underlying layer. By calling the interface provided by the middleware, a series of transitions from the application layer to the underlying layer can be achieved, thereby improving the flexibility and efficiency of the system. Furthermore, by adding a notification interface between the first terminal and the second terminal, before data transmission, the middleware is used to detect whether the notification interface of the second terminal is in a preset state where data transmission can be performed, and data transmission is performed when it is determined that the notification interface of the second terminal is in the preset state, thereby improving the efficiency and accuracy of data transmission, achieving improved data transmission efficiency and accuracy while increasing the portability and compatibility of data transmission logic. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0045] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the prior art texts are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0046] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.
[0047] Figure 1 A schematic diagram of the structure of a first terminal provided in an embodiment of the present application;
[0048] Figure 2 A flowchart of an embodiment of a data transmission method provided in an embodiment of the present application;
[0049] Figure 3A flowchart of another data transmission method provided in an embodiment of the present application;
[0050] Figure 4 A schematic diagram of data transmission between a first terminal and a second terminal provided in an embodiment of the present application;
[0051] Figure 5 A flowchart of another data transmission method provided in an embodiment of the present application;
[0052] Figure 6 A flowchart of another data transmission method provided in the present application;
[0053] Figure 7 A block diagram of an embodiment of a data transmission device provided in an embodiment of the present application;
[0054] Figure 8 A schematic diagram of the structure of a vehicle provided in an embodiment of the present application. DETAILED DESCRIPTION
[0055] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described in conjunction with the drawings in the embodiments of the present application. Obviously, the embodiments described in the text are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.
[0056] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0057] In order to solve the technical problem that the data transmission method between the Linux operating system in the vehicle and other terminals in the prior art is not conducive to the portability and compatibility of the data transmission logic, the present application provides a data transmission method, device, vehicle and storage medium, which can add a middleware layer between the application layer and the driver layer of the first terminal in the vehicle, and the middleware layer executes the data transmission logic with the second terminal. It does not need to modify the driver, avoids new problems and bugs that may be introduced during the driver transplantation process, and reduces the complexity of development and maintenance. The application layer does not need to pay attention to the specific implementation of the underlying layer. By calling the interface given by the middleware, a series of transitions from the application layer to the underlying layer can be achieved, thereby improving the flexibility and efficiency of the system. Furthermore, by adding a notification interface between the first terminal and the second terminal, before data transmission, the middleware is used to detect whether the notification interface of the second terminal is in a preset state where data transmission can be performed, and data transmission is performed when it is determined that the notification interface of the second terminal is in the preset state, thereby improving the efficiency and accuracy of data transmission, and achieving the improvement of the efficiency and accuracy of data transmission while increasing the portability and compatibility of data transmission logic.
[0058] To facilitate understanding of the data transmission method provided by the present application, the structure of the first terminal in the vehicle is first illustrated below.
[0059] See also Figure 1 , is a schematic diagram of the structure of a first terminal provided in an embodiment of the present application. Figure 1 As shown, the first terminal 10 may include an application layer 11 , a middleware layer 12 , and a driver layer 13 .
[0060] The first terminal 10 may be a terminal using a Linux operating system, such as a SOC (System on Chip) terminal in a vehicle.
[0061] The application layer 11 may include various application programs installed in the first terminal, which may be used to process data and send the data to be transmitted to the middleware layer so that the middleware layer transmits the data to be transmitted.
[0062] The middleware layer 12 is used to implement the data transmission method provided by the present application to perform data transmission with other terminals.
[0063] The driver layer 13 includes providing an operation interface of external devices for upper-layer programs and implementing a driver program of the device. The driver program can serve as a bridge between hardware and software.
[0064] In addition, the first terminal 10 may further include a hardware layer 14, and the hardware layer 14 may include hardware inside the first terminal.
[0065] In an embodiment of the present application, when the application layer 11 transmits data with other terminals in the vehicle (such as MCU (Microcontroller Unit)), it can directly call the interface of the above-mentioned middleware layer 12. The middleware layer 12 can complete the data transmission between the application layer 11 and other terminals by calling the interface in the driver layer 13 and using the data transmission method provided by the present application.
[0066] The data transmission method provided by the present application is further explained below with reference to specific embodiments in conjunction with the accompanying drawings. The embodiments do not constitute a limitation on the embodiments of the present invention.
[0067] See also Figure 2 , is a flow chart of an embodiment of a data transmission method provided in an embodiment of the present application. As an embodiment, Figure 2 The process shown may be applied to the middleware layer of a first terminal in a vehicle, wherein the first terminal may include an application layer, a middleware layer, and a driver layer, for example Figure 1 The first terminal 10 shown may include an application layer 11, a middleware layer 12, and a driver layer 13. Figure 2 As shown, the process may include the following steps:
[0068] Step 201: When it is determined that the application layer is performing data transmission with the second terminal, the first notification interface in the driver layer is updated to a preset state.
[0069] The above-mentioned application layer refers to a structure for data transmission in the first terminal, which may include multiple applications installed in the first terminal, and data processing is performed through the applications. Further, the above-mentioned application layer may also include a communication interface, which is used for data transmission inside the first terminal. The above-mentioned communication interface may be a four-wire SPI (Serial Peripheral Interface) communication interface, and the above-mentioned four-wire SPI communication interface may include: SCLK (Serial Clock), which is generated by the master device and used to synchronize the data transmission rate; MOSI (Master Out Slave In), a data line output by the master device and input by the slave device; MISO (Master In Slave Out), a data line input by the master device and output by the slave device; SS / CS (Slave Select / Chip Select), a chip select line, which is controlled by the master device and is used to select the slave device to communicate.
[0070] The above-mentioned first notification interface refers to an interface selected in the driver layer for notification, that is, when the first terminal and the second terminal are transmitting data, it is used to notify the second terminal whether it is currently in a data transmission state. Optionally, when the first notification interface is in a preset state, the first terminal can currently transmit data. Furthermore, the above-mentioned preset state can be a preset value for the value of the first notification interface, such as a GPIO (General-purpose input / output) interface. The GPIO interface can have two value changes 1 and 0. When the value of the GPIO interface is 1, it can indicate that the first notification interface is in a preset state.
[0071] The above-mentioned second terminal refers to another terminal that performs data transmission with the first terminal, and it may be another control terminal in the vehicle, such as the vehicle MCU.
[0072] In the embodiment of the present application, one or more interfaces (such as GPIO interface) in the driver layer may be selected as the first notification interface when performing data transmission with the second terminal.
[0073] Furthermore, the number of the first notification interfaces may be two, one of which is used to notify the transmission of data to the second terminal, and the other is used to notify the preparation for receiving the data transmitted by the second terminal.
[0074] In one embodiment, when the middleware layer determines that the application layer is performing data transmission with the second terminal, the middleware layer may update the first notification interface in the driver layer to a preset state to notify the second terminal that data transmission is currently possible.
[0075] As an optional implementation manner, when the middleware layer receives the data to be transmitted sent by the application layer through a preset interface, the middleware layer may determine that the application layer performs data transmission with the second terminal.
[0076] Furthermore, when the middleware layer receives the above-mentioned data to be transmitted, it indicates that the above-mentioned data to be transmitted needs to be transmitted to the second terminal at this time. Therefore, the first notification interface used to notify the transmission of data to the second terminal can be updated to a preset state, and the preset state indicates that the current middleware layer is in a data transmission state.
[0077] As another optional implementation method, when the middleware layer receives a transmission signal sent by the second terminal, it can determine that the application layer is performing data transmission with the second terminal at this time, wherein the above-mentioned transmission signal can be used to indicate that the second terminal is performing data transmission with the first terminal, that is, indicating that the second terminal is ready to transmit data to the first terminal, and the above-mentioned transmission signal can be used to indicate that the notification interface in the second terminal for notifying external data transmission has been modified to a preset state, for example, the value of the notification interface is a preset value (for example, 1).
[0078] Furthermore, when the middleware layer receives a transmission signal sent by the second terminal, it indicates that the second terminal is ready to transmit data to the first terminal. Therefore, the first notification interface used to notify the preparation for receiving data can be updated to a preset state, and the preset state indicates that the current middleware layer is in a data transmission state.
[0079] In addition, after the middleware layer updates the first notification interface to the preset state, it can send a notification signal indicating that the state of the first notification interface is the preset state to the second terminal, so that the second device updates its own second notification interface to the preset state according to the received notification signal.
[0080] In one embodiment, when the middleware layer updates the first notification interface to the preset state, the first notification interface may be placed in the preset state by pulling up or pulling down the first notification interface.
[0081] As an optional implementation, when the first notification interface is in a non-preset state, it can be in a low level state. When the first notification interface is updated to a preset state, the first notification interface can be pulled high, that is, a rising edge is triggered.
[0082] Step 202: Detect the current state of the second notification interface in the second terminal, where the second notification interface is connected to the first notification interface.
[0083] Step 203: When it is detected that the current state of the second notification interface is a preset state, data is transmitted with the second terminal through the transmission interface of the driving layer.
[0084] The following is a unified description of step 202 and step 203:
[0085] The above-mentioned second notification interface refers to the interface in the second terminal connected to the first notification interface, which can be a GPIO interface. Its notification function is relative to that of the first notification interface. That is, if the function of the first notification interface is to notify the second terminal to send data to be sent, then the function of the second notification interface is to notify the first terminal to prepare to receive the data to be sent.
[0086] Therefore, after updating its own first notification interface to a preset state, the middleware layer can detect the current state of the second notification interface in the second terminal in real time or periodically.
[0087] Afterwards, when it is detected that the current state of the second notification interface is the preset state, data is transmitted with the second terminal through the transmission interface of the driving layer. The transmission interface may be a four-wire SPI interface, which may be used to transmit data.
[0088] As for how to detect the current state of the second notification interface in the second terminal, it can be described below. Figure 3 The process shown is explained and will not be described in detail here.
[0089] For example, see Figure 4 , is a schematic diagram of data transmission between a first terminal and a second terminal provided in an embodiment of the present application. Figure 4 The process shown is described by taking the first terminal as the host, the second terminal as the slave, and the first notification interface and the second notification interface as GPIO interfaces. Figure 4 As shown, the host may include a first notification interface GPIO1, and the slave may include a second notification interface GPIO2, and the interaction process between the two is as follows:
[0090] First, the default host GPIO1 idle state (that is, non-preset state) is a low level, and the slave GPIO2 idle state is also a low level. Based on this, when the host is ready to send data, the GPIO1 interface can be pulled high, that is, a rising edge is triggered.
[0091] Afterwards, the host may send a pull-up signal to the slave to notify the slave to pull GPIO2 high, or the slave may actively detect whether the GPIO1 interface in the host is pulled high.
[0092] Afterwards, when the slave determines that the host's GPIO1 is currently at a high level, it can trigger a rising edge on the GPIO2 interface. The host then detects in real time whether GPIO2 has a rising edge trigger.
[0093] Finally, when the host determines that GPIO2 in the slave is in a high level state, it can start sending and receiving data, and after the sending and receiving is completed, the GPIO1 interface is pulled low, while the GPIO2 interface is pulled low by the slave after sending and receiving data.
[0094] In addition, in one embodiment, the second notification interface may correspond to an interruption configuration file, which is used to record a preset state of the second notification interface, that is, when the current state of the second notification interface is the preset state recorded in the interruption configuration file, an interruption signal may be triggered.
[0095] Based on this, after detecting the current state of the second notification interface, the preset state corresponding to the second notification interface can be obtained from the above interruption configuration file, and when the current state is the preset state recorded in the above interruption configuration file, the preset interruption signal is triggered.
[0096] Afterwards, when the middleware layer detects the interrupt signal, the data can be transmitted to the second terminal through the transmission interface of the driver layer. The data transmission is determined by the interrupt triggering method, so that the data to be transmitted in the application layer can be transmitted timely and accurately.
[0097] The technical solution provided by the embodiment of the present application updates the first notification interface in the driver layer to a preset state when it is determined that the application layer is transmitting data with the second terminal, detects the current state of the second notification interface in the second terminal, and the second notification interface is connected to the first notification interface. When it is detected that the current state of the second notification interface is the preset state, data is transmitted with the second terminal through the transmission interface of the driver layer. This technical solution, by adding a middleware layer between the application layer and the driver layer of the first terminal in the vehicle, and the middleware layer executes the data transmission logic with the second terminal, there is no need to change the driver, avoiding new problems and bugs that may be introduced during the driver migration process, reducing the complexity of development and maintenance, and the application layer does not need to pay attention to the specific implementation of the underlying layer. By calling the interface provided by the middleware, a series of transitions from the application layer to the underlying layer can be achieved, thereby improving the flexibility and efficiency of the system. Furthermore, by adding a notification interface between the first terminal and the second terminal, before data transmission, the middleware is used to detect whether the notification interface of the second terminal is in a preset state where data transmission can be performed, and data transmission is performed when it is determined that the notification interface of the second terminal is in the preset state, thereby improving the efficiency and accuracy of data transmission, achieving improved data transmission efficiency and accuracy while increasing the portability and compatibility of data transmission logic.
[0098] See also Figure 3 , which is a flow chart of an embodiment of another data transmission method provided in an embodiment of the present application. Figure 3 The process shown in Figure 2 Based on the process shown in FIG. 1 , a specific method for detecting the current state of the second notification interface in the second terminal is described. Figure 3 As shown, the process may include the following steps:
[0099] Step 301: Obtain a file path of a target file corresponding to a second notification interface in a second terminal.
[0100] Step 302: According to the above file path, obtain the current state of the second notification interface of the target file record.
[0101] The following is a unified description of step 301 and step 302:
[0102] The above-mentioned target file is used to record the current state of the second notification interface. For example, in the Linux system, the Value file of the GPIO interface is used to record the current state of the GPIO interface. It records the current state of the GPIO interface by recording the current value of the GPIO interface.
[0103] In the embodiment of the present application, the second notification interface in the second terminal may correspond to a target file that records the state of the second notification interface, and the middleware layer of the first terminal may directly read the file path of the target file.
[0104] Based on this, the middleware layer can obtain the current state of the second notification interface of the target file record according to the above file path.
[0105] As an optional implementation manner, the current state of the second notification interface recorded in the target file may be directly read through a preset reading function.
[0106] As another optional implementation method, since data transmission is performed only when the second notification interface is in a preset state, and under normal circumstances, the state of the second notification interface is a non-preset state, in order to save system resources, the middleware layer can use a monitoring and listening mechanism to obtain the current state of the second notification interface when the state of the second notification interface is updated, that is, when the target file is modified.
[0107] As an exemplary embodiment, the middleware layer can be Figure 5 The process shown is implemented to obtain the current state of the second notification interface of the target file record according to the above file path.
[0108] See also Figure 5 , which is a flow chart of another embodiment of a data transmission method provided in an embodiment of the present application. Figure 5 The process shown describes how to obtain the current status of the second notification interface of the target file record according to the file path. Figure 5 As shown, the process may include the following steps:
[0109] Step 501: Write the file path into a preset file monitoring tool so that the file monitoring tool monitors the target file corresponding to the file path and triggers a preset event when the target file is changed.
[0110] Step 502: Obtain a file descriptor corresponding to the file monitoring tool, and write the file descriptor into a preset monitoring function, so that the monitoring function monitors whether the file monitoring tool triggers a preset event.
[0111] Step 503: When the file monitoring tool triggers a preset event through the above-mentioned monitoring function, the preset reading function is blocked to wait for the above-mentioned preset event, and the current value of the target file record is read.
[0112] The following is a unified description of steps 501 to 503:
[0113] The above-mentioned file monitoring tool refers to a command line tool used to monitor operations in the file system, which may include but is not limited to monitoring read, write, and create operations in the file system. The above-mentioned file monitoring tool may be inotify (command line tool) in the Linux system.
[0114] In an embodiment of the present application, in order to timely obtain the current status of the second notification interface in the second terminal, and the current status of the second notification interface can be recorded by the target file corresponding to the second notification interface, the middleware layer can write the above file path into a preset file monitoring tool after obtaining the file path of the target file corresponding to the second notification interface, so that the file monitoring tool can monitor in real time whether the target file corresponding to the file path is changed, and trigger a preset event after detecting that the target file is changed.
[0115] Based on this, in order to obtain the current status of the second notification interface more timely, the middleware layer can obtain the file descriptor corresponding to the file monitoring tool, and write the above file descriptor into the preset listening function, so that the listening function can monitor in real time whether the file monitoring tool triggers the preset event.
[0116] As an optional implementation method, the above-mentioned monitoring function may be a select function.
[0117] Furthermore, in order to monitor the file monitoring tool more efficiently and quickly, the above-mentioned monitoring function can also be a poll function or an epoll function, and the above-mentioned functions are all functions involved in the IO multiplexing mechanism.
[0118] Optionally, when the file monitoring tool triggers a preset event through the above-mentioned monitoring function, it indicates that the target file has changed at this time, and the preset reading function can be blocked to wait for the above-mentioned preset event, and the current value of the target file record can be read, wherein the current value of the target file record can be detected in time by blocking and waiting for the above-mentioned preset event. The above-mentioned reading function can be a read function, and the above-mentioned current value can be 0 or 1, or other values, which is not limited in the embodiment of the present application.
[0119] Step 504: Determine the current state of the second notification interface of the target file record according to the current value.
[0120] From the above description, it can be seen that the current value of the target file record is the value of the second notification interface. Therefore, after obtaining the current value of the target file record, the current state of the second notification interface of the target file record can be determined according to the above current value.
[0121] In one embodiment, the above-mentioned second notification interface may be a GPIO interface, and the preset state of the second notification interface may be the rising edge state of the GPIO interface. Based on this, when the above-mentioned current value is the first value, it can be determined that the current state of the second notification interface recorded in the target file is a rising edge state; when the above-mentioned current value is the second value, it can be determined that the current state of the second notification interface recorded in the target file is a falling edge state.
[0122] Furthermore, in one embodiment, the second notification interface may correspond to an interruption configuration file, which is used to record a preset state of the second notification interface, that is, when the current state of the second notification interface is the preset state recorded in the interruption configuration file, an interruption signal may be triggered.
[0123] Based on this, after detecting the current state of the second notification interface, the preset state corresponding to the second notification interface can be obtained from the above interruption configuration file, and when the current state is the preset state recorded in the above interruption configuration file, the preset interruption signal is triggered.
[0124] Afterwards, when the middleware layer detects the interrupt signal, the data can be transmitted to the second terminal through the transmission interface of the driver layer. The data transmission is determined by the interrupt triggering method, so that the data to be transmitted in the application layer can be transmitted timely and accurately.
[0125] In addition, since the middleware layer may have a delayed response when detecting the current status of the second notification interface, in an embodiment of the present application, a timeout and retransmission mechanism can be set for obtaining the current status of the second notification interface, thereby achieving error handling while ensuring the integrity of data transmission.
[0126] As an optional implementation method, when the middleware layer receives the data to be transmitted sent by the application layer and fails to detect the file monitoring tool triggering a preset event through the above-mentioned listening function within a preset time period, the above-mentioned data to be transmitted can be stored in a preset timeout queue first.
[0127] Afterwards, the following steps can be re-executed at least once: after updating the first notification interface in the driver layer to a non-preset state, updating the first notification interface to a preset state again, and then re-determining whether the file monitoring tool triggers a preset event through the listening function within the preset time.
[0128] Optionally, when the file monitoring tool triggers a preset event through the monitoring function within a preset time period and the second notification interface is determined to be in a preset state, the data to be transmitted in the above timeout queue can be sent to the second terminal.
[0129] Optionally, when no preset event is detected by the file monitoring tool through the monitoring function every time after a preset time period has passed, an abnormal stage in which an abnormality occurs during the process of detecting the current state of the second notification interface is determined.
[0130] Afterwards, the error identification corresponding to each abnormal extreme can be pre-stored, such as the file monitoring tool monitoring stage, the monitoring function monitoring stage, the preset event triggering stage, and the interrupt signal triggering stage. Furthermore, the file monitoring tool monitoring stage can correspond to error identification 1, the monitoring function monitoring stage can correspond to error identification 2, the preset event triggering stage can correspond to error identification 3, the interrupt signal triggering stage can correspond to error identification 4, and so on.
[0131] Based on this, the target error identifier corresponding to the abnormal stage can be determined from the pre-stored correspondence between the abnormal stage and the error identifier, and the target error identifier can be sent to the application layer so that the application layer can correct the abnormal stage based on the target error identifier.
[0132] The technical solution provided by the embodiment of the present application is to obtain the file path of the target file corresponding to the second notification interface in the second terminal, obtain the current state of the second notification interface recorded by the target file according to the above file path, further, write the file path into the preset file monitoring tool, so that the file monitoring tool monitors the target file corresponding to the file path, and triggers the preset event after the target file is changed, obtain the file descriptor corresponding to the file monitoring tool, and write the above file descriptor into the preset listening function, so that the listening function listens to whether the above file monitoring tool triggers the preset event, and in the case of listening to the file monitoring tool triggering the preset event through the above listening function, block and wait for the above preset event through the preset reading function, and read the current value of the target file record, and determine the current state of the second notification interface recorded by the target file according to the above current value. This technical solution, through the combination of the listening function, the file monitoring tool, the reading function, and the interrupt detection, can not only quickly and accurately respond to the jump of the second notification interface, and immediately perform data processing, but also optimize the error handling, so as to solve the problem of slow delayed response and the problem of high CPU occupancy, and add the interrupt trigger, and also ensure the accuracy of the data, so as to realize fast and accurate data transmission.
[0133] See also Figure 6 , which is a flow chart of an embodiment of another data transmission method provided in an embodiment of the present application. Figure 6The process shown in Figure 4 Based on the process shown, the data transmission method provided in the embodiment of the present application is illustrated by way of example. Figure 6 As shown, the process may include the following:
[0134] First, when there is no data to be sent between the host (first terminal) and the slave (second terminal), GPIO1 in the host remains at a low level; when the host has data to send, the host pulls up GPIO2 (ie triggers a rising edge).
[0135] Based on this, the middleware layer can create a thread to detect the transition of the slave GPIO2 (taking the rising edge as an example). Specifically, the detection of the GPIO2 transition can be achieved through the following steps:
[0136] Step 1: Initialize inotify_init(), and then use inotify_add_watch() to add the path of the target file of the GPIO value to be detected to inotify (file monitoring tool).
[0137] Step 2: Set the select (listening function) listening step, configure the timeout, and then add the initialized inotify device file descriptor to the select listening. The above-mentioned listening function can be determined according to the system, and it can also be poll or epoll instead of select.
[0138] Step 3: Use inotify+read to detect file attribute changes. In Linux, by using the inotify mechanism, you can monitor the attribute changes of specified files or directories in real time. When the file attributes are changed, inotify will trigger a preset event. At this time, you can block and wait for the event through the read function to detect the file attribute changes.
[0139] Step 4: Configure the pin to trigger an interrupt on a rising edge or falling edge by writing to the / sys / class / gpio / gpio2 / edge file. When the state of the GPIO pin changes, an interrupt signal will be triggered, thereby achieving a quick response to the change in the state of the GPIO pin. Specifically, you can use the following command to configure the GPIO pin: ``$echo1> / sys / class / gpio / gpioN / direction$echo1> / sys / class / gpio / gpioN / edge``, where gpioN represents the specified GPIO pin number, the direction parameter indicates setting it to input or output, and the edge parameter indicates setting it to trigger an interrupt on a rising edge or falling edge; you can also write a string to the file through the write function.
[0140] Step 5: Accurately detect the timing of GPIO pin status changes, and then immediately process related business logic (triggered events such as sending and receiving data, opening the tailgate, turning on the lights, etc.).
[0141] Then, after setting the detection steps of the second notification interface determined above, you can enter the main while loop, set the timeout time to 30ms in select(), and then start select monitoring. Among them, the 30ms timeout mechanism is based on the premise that the SPI rate reaches 8M, and it takes about 9ms to transmit 8K data plus business logic. Therefore, the timeout time can be greater than the above 9ms or other values.
[0142] After that, you can combine the inotify mechanism to select and monitor whether the status of the character device file has changed. Optionally, if the file status has changed, after the value of / sys / clas / gpio / gpioxx / value read by read() is changed, determine whether the file is read successfully. If the file is read successfully, parse the event to determine whether the event is a file modification event, that is, whether IN_MODIFY is true. Further, if it is true, it indicates that the value of GPIO has been written from 0 to 1, indicating that the slave has triggered a rising edge interrupt. At this time, SPI data can be sent and the underlying ioctl() interface can be called to send the data to be transmitted to the slave. Among them, if it is determined that the value of GPIO has not been written from 0 to 1, you can continue to return to the step of executing select monitoring.
[0143] On the contrary, if no file status change is detected after 30ms, it means that the slave did not receive a high-level response from the host or handled it abnormally. The host immediately triggers the timeout mechanism, that is, it pulls GPIO1 down or up (that is, gives another rising edge), and adds the failed data to the timeout queue for retransmission.
[0144] Among them, the above steps may include the / sys / clas / gpio / gpioxx / value file and the / sys / clas / gpio / gpioxx / edge file. In the Linux system file, the value in the value file is used to indicate the current level of the GPIO pin, 0 indicates a low level, and 1 indicates a high level; and the content in the edge file defaults to none, that is, no interrupt trigger mode is set, which can be set to rising, failing, and both, respectively indicating rising edge triggered interrupt, falling edge triggered interrupt, and edge triggered interrupt (that is, either rising edge or falling edge can be triggered). The corresponding string can be written to the file, that is, the preset state of the second notification interface generating an interrupt signal is set.
[0145] Furthermore, the function interfaces required for inotify_init(), inotify_add_watch(), select(), read(), struct inotify_event_*event, detecting whether it is a file change event and judging whether the flag event->mask&IN_MODIFY is true are all provided by Linux, without the need for a third-party library, so porting is relatively convenient.
[0146] The technical solution provided by the embodiment of the present application has the following beneficial effects:
[0147] 1. High precision and high real-time performance: Due to the use of the interrupt method, the present application can notify the application program through a hardware interrupt when the state of the second notification interface pin of the second terminal changes, thereby achieving efficient event response. Compared with the existing polling method, the present application can reduce the consumption of system resources and improve the real-time performance of the system.
[0148] 2. Reduce complexity: Since this application is implemented in the Linux middleware layer, there is no need to modify the driver, avoiding new problems and bugs that may be introduced during the driver migration process, and reducing the complexity of development and maintenance. The application layer does not need to pay attention to the specific implementation of the underlying layer. By calling the interface provided by the middleware, a series of leaps from the application layer to the underlying layer can be achieved, which improves the flexibility and efficiency of the system.
[0149] 3. Wide application scenarios: Due to the superior performance and stability of this application, it can be widely used in various occasions that require high-precision, high-real-time data transmission and control systems, etc., which require timely response to GPIO.
[0150] 4. Easy to integrate: Since this application is based on the Linux operating system, it can be easily integrated with other Linux applications and system services to achieve more flexible and powerful functions.
[0151] See also Figure 7 , is a block diagram of an embodiment of a data transmission device provided in an embodiment of the present application. As an embodiment, the device can be applied to the middleware layer of a first terminal in a vehicle, and the first terminal may include an application layer, a middleware layer, and a driver layer. Figure 7 As shown, the device may include:
[0152] An updating module 71, configured to update the first notification interface in the driver layer to a preset state when it is determined that the application layer is performing data transmission with the second terminal;
[0153] A detection module 72, configured to detect a current state of a second notification interface in the second terminal, the second notification interface being connected to the first notification interface;
[0154] The transmission module 73 is configured to transmit data to the second terminal via the transmission interface of the driving layer when it is detected that the current state of the second notification interface is the preset state.
[0155] like Figure 8 As shown, it is a schematic diagram of the structure of a vehicle provided in an embodiment of the present application, including a processor 81, a communication interface 82, a memory 83 and a communication bus 84, wherein the processor 81, the communication interface 82, and the memory 83 communicate with each other through the communication bus 84.
[0156] A memory 83, for storing computer programs;
[0157] In one embodiment of the present application, the processor 81 is used to execute the program stored in the memory 83 to implement the data transmission method provided by any of the above method embodiments, including:
[0158] When it is determined that the application layer is performing data transmission with the second terminal, updating the first notification interface in the driver layer to a preset state;
[0159] detecting a current state of a second notification interface in the second terminal, the second notification interface being connected to the first notification interface;
[0160] When it is detected that the current state of the second notification interface is the preset state, data is transmitted with the second terminal through the transmission interface of the driving layer.
[0161] An embodiment of the present application further provides a storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the steps of the data transmission method provided in any of the aforementioned method embodiments are implemented.
[0162] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment.
[0163] Through the text of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0164] It should be understood that the terms used in the text are only for the purpose of the specific example implementation of the text, and are not intended to be limited. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used in the text can also be represented to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of the stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or their combinations. The method steps, processes, and operations of the text in the text are not interpreted as necessarily requiring them to be performed in the specific order of the text or description, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps can be used.
[0165] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be 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 present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.
Claims
1. A data transmission method, characterized in that: A middleware layer applied to a first terminal in a vehicle, wherein the first terminal includes an application layer, a middleware layer, and a driver layer, and the method includes: When it is determined that the application layer is performing data transmission with the second terminal, updating the first notification interface in the driver layer to a preset state; detecting a current state of a second notification interface in the second terminal, the second notification interface being connected to the first notification interface; When it is detected that the current state of the second notification interface is the preset state, data is transmitted with the second terminal through the transmission interface of the driving layer.
2. The method according to claim 1, characterized in that The determining that the application layer performs data transmission with the second terminal includes: In a case where the data to be transmitted sent by the application layer is received through the preset interface, determining that the application layer performs data transmission with the second terminal; or, In case of receiving a transmission signal sent by the second terminal, it is determined that the application layer performs data transmission with the second terminal, wherein the transmission signal is used to indicate that the second terminal performs data transmission with the first terminal.
3. The method according to claim 1, characterized in that The detecting a current state of the second notification interface in the second terminal includes: Obtaining a file path of a target file corresponding to the second notification interface in the second terminal, where the target file is used to record a current state of the second notification interface; According to the file path, the current state of the second notification interface of the target file record is obtained.
4. The method according to claim 3, characterized in that The acquiring, according to the file path, a current state of the second notification interface of the target file record includes: Writing the file path into a preset file monitoring tool, so that the file monitoring tool monitors the target file corresponding to the file path, and triggers a preset event when the target file is changed; Obtaining a file descriptor corresponding to the file monitoring tool, and writing the file descriptor into a preset monitoring function, so that the monitoring function monitors whether the file monitoring tool triggers a preset event; In the case where the file monitoring tool triggers a preset event through the monitoring function, the preset reading function is used to block and wait for the preset event, and the current value of the target file record is read; According to the current value, a current state of the second notification interface of the target file record is determined.
5. The method according to claim 4, characterized in that The second notification interface is a general purpose input / output port GPIO interface, the preset state is a rising edge state of the GPIO interface, and the current state of the second notification interface recorded in the target file is determined according to the current value, including: When the current value is the first value, determining that the current state of the second notification interface of the target file record is a rising edge state; When the current value is the second value, it is determined that the current state of the second notification interface of the target file record is a falling edge state.
6. The method according to claim 4, characterized in that Also includes: Upon receiving the data to be transmitted sent by the application layer, and in the case that the file monitoring tool does not trigger a preset event through the monitoring function within a preset time period, the data to be transmitted is stored in a preset timeout queue; Re-performing the following steps at least once: after updating the first notification interface in the driver layer to a non-preset state, updating the first notification interface to the preset state again; Determine whether the file monitoring tool triggers a preset event by monitoring the monitoring function within a preset time period; When the file monitoring tool triggers a preset event through the monitoring function within a preset time period and it is determined that the second notification interface is in a preset state, the data to be transmitted in the timeout queue is sent to the second terminal.
7. The method according to claim 6, characterized in that Also includes: In the case that the preset event triggered by the file monitoring tool is not monitored by the monitoring function every time after the preset time period, determining an abnormal stage in which an abnormality occurs in the process of detecting the current state of the second notification interface; Determining a target error identifier corresponding to the abnormal stage from a pre-stored correspondence between abnormal stages and error identifiers; The target error identifier is sent to the application layer, so that the application layer corrects the abnormal phase based on the target error identifier.
8. The method according to claim 1, characterized in that The second notification interface corresponds to an interruption configuration file, the interruption configuration file is used to record a preset state of the second notification interface, and the preset state is used to represent a state of data transmission with the first terminal; The step of, when detecting that the current state of the second notification interface is the preset state, transmitting data with the second terminal through the transmission interface of the driving layer includes: Acquire a preset state corresponding to the second notification interface from the interruption configuration file; When the current state is the preset state recorded in the interrupt configuration file, triggering a preset interrupt signal; When the interrupt signal is detected, data is transmitted to the second terminal through the transmission interface of the driving layer.
9. A data transmission device, characterized in that: A middleware layer applied to a first terminal in a vehicle, wherein the first terminal includes an application layer, a middleware layer, and a driver layer, and the device includes: An updating module, configured to update the first notification interface in the driver layer to a preset state when it is determined that the application layer is performing data transmission with the second terminal; a detection module, configured to detect a current state of a second notification interface in the second terminal, the second notification interface being connected to the first notification interface; A transmission module is used to transmit data with the second terminal through the transmission interface of the driving layer when it is detected that the current state of the second notification interface is the preset state.
10. A vehicle, characterized in that: The vehicle comprises a processor and a memory, wherein the processor is used to execute a data transmission program stored in the memory to implement the data transmission method according to any one of claims 1 to 8.
11. A storage medium, characterized in that: The storage medium stores one or more programs, and the one or more programs can be executed by one or more processors to implement the data transmission method according to any one of claims 1 to 8.
Citation Information
Patent Citations
Cross-platform automatic test method and device and in-vehicle equipment
CN115470148A
Sensor data acquisition method and device, equipment, storage medium and program product
CN116089111A
Data transmission method and device, vehicle-mounted terminal and storage medium
CN118535510A
Data interaction method and device, electronic equipment and storage medium
CN118760645A
Data transmission method, terminal and server
WO2016000138A1