CAN data processing method, device, equipment and medium
Patent Information
- Application Number
- CN202411984757.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-02-07
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Vehicle ECU systems are prone to packet loss when there are many data frames, resulting in the loss of important packets.
By obtaining messages in the vehicle CAN network, filtering messages based on preset sorting and segmentation, and putting filtered messages into the buffer. When the buffer is fully loaded, the CAN message reception interrupt is generated. All filtered messages are taken out from the buffer, stored in the receiving array, and match the messages in the receiving array according to the target ID and sent to the CAN controller.
It effectively avoids frame drop situations, ensures that important messages will not be ignored or discarded due to too many messages, thereby avoiding performance losses caused by vehicle loss due to critical messages.
Smart Images

Figure CN119402424A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of automobile communication technology, and in particular to a CAN data processing method, device, equipment and medium. Background Art
[0002] The CAN bus is widely used in automotive electronic systems. It mainly solves the problems of wiring complexity and weight increase caused by the increase in the number of electronic control units (ECUs) in the car. It realizes information sharing and communication between ECUs by building a local area network. When the local ECU wants to obtain information sent by other ECUs in the vehicle, it will face the effective reception and processing of CAN messages. Usually, the software will use polling and interrupt methods to achieve this.
[0003] However, the existing solution may cause frame loss of received messages during the actual vehicle testing phase. Analysis shows that the buffer of the CAN controller receiving structure is prone to full receiving buffer. If the receiver FIFO is full, all received messages will be discarded until the receiving buffer in the FIFO is available again, and new valid messages can be received. Although a data overload interrupt will be generated when the CAN controller FIFO is full, the hardware cannot automatically clear the fault bit through software release of the receiving buffer operation. At the same time, once an overload occurs, the CAN module must be initialized to restore the receiving buffer to be available again.
[0004] Therefore, the present invention proposes a CAN data processing method to solve the problem that when there are many data frames in the vehicle ECU system, message frame loss may easily occur, resulting in loss of important messages. Summary of the invention
[0005] In order to solve the problem that when there are many data frames in a vehicle ECU system, message frame loss may easily occur, resulting in loss of important messages, the present invention provides a CAN data processing method.
[0006] In a first aspect, the present invention provides a CAN data processing method, comprising: Get the message in the vehicle CAN network; Filtering the message based on preset sorting and segmentation; Put the filtered messages into the buffer; When the buffer is fully loaded, a CAN message reception interrupt is generated; Take all filtered messages out of the buffer and store them in the receiving array; Match the message ID corresponding to the message in the receiving array according to the target ID, wherein the message corresponding to the target ID is the message required by the CAN controller; Send the message in the receive array that matches the target ID to the CAN controller.
[0007] In some embodiments, the preset sorting and segmenting includes: Arrange the data segment where the message ID corresponding to the message required by the vehicle is located; Configure the filter ID and mask based on the data segment where the packet ID is located.
[0008] In some embodiments, the filter employs a mask bit pattern; The ID and mask setting methods of the standard frame and the extended frame of the filter are consistent.
[0009] In some embodiments, filtering the message includes: Extract the message ID from the bus message; Comparing the message ID with the content in an identifier acceptance register, wherein the identifier acceptance register is used to store a verification ID, and the verification ID is used to compare with the message ID; If the message ID matches the verification ID, the message corresponding to the message ID is allowed to be received.
[0010] In some embodiments, if the message ID does not match the verification ID, the message ID is compared with the content in an identifier mask register, wherein the identifier mask register is used to store the mask, and the mask is used to compare with the message ID; If the concerned bit in the mask matches the corresponding bit of the message ID, the message corresponding to the message ID will be received; If the concerned bit in the mask does not match the corresponding bit of the message ID, the message corresponding to the message ID will be filtered.
[0011] In some embodiments, taking out all filtered messages from the buffer and storing them in the receiving array includes: No more parsing and judgment of message data content; Traverse the messages in the buffer and take out all the messages and put them into the receiving array; If the buffer is empty, the buffer starts receiving messages again.
[0012] In some embodiments, if the message ID corresponding to the message in the received array does not match the target ID, the message corresponding to the unmatched message ID is discarded.
[0013] In a second aspect, the present invention provides a CAN data processing device, which includes the following modules: Acquisition module: used to obtain messages in the vehicle CAN network; Filtering module: used to filter the message based on preset sorting and segmentation, and put the filtered message into a buffer; Interrupt module: used to generate a CAN message reception interrupt when the buffer is full; take out all filtered messages from the buffer and store them in the receiving array; Matching module: used to match the message ID corresponding to the message in the receiving array according to the target ID, and send the message in the receiving array matching the target ID to the CAN controller, wherein the message corresponding to the target ID is the message required by the CAN controller.
[0014] In a third aspect, the present invention proposes an electronic device, characterized in that it includes a processor and a memory, wherein the memory stores a program that can be run on the processor, and when the program is executed by the processor, it implements the CAN data processing method described in the first aspect.
[0015] In a fourth aspect, the present invention proposes a storage medium, characterized in that a computer program is stored on the storage medium, and when the computer program is executed by at least one processor, the CAN data processing method as described in the first aspect is implemented.
[0016] In order to solve the problem that when there are many data frames in the vehicle ECU system, message frame loss may occur, resulting in loss of important messages, the present invention has the following advantages: The CAN data processing method of the present invention solves the problem that the CAN bus of existing vehicles is prone to message frame loss when receiving vehicle messages by reducing the number of network messages entering the receiving buffer and optimizing the received message processing method, thereby avoiding the loss of key message information and thus avoiding performance loss of the vehicle caused by the loss of key messages. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 A flow chart of a CAN data processing method is shown; Figure 2 The flowchart of CAN message reception interrupt is shown; Figure 3 A virtual module diagram of a CAN data processing device is shown. DETAILED DESCRIPTION
[0018] The present disclosure will now be discussed with reference to several exemplary embodiments. It should be understood that these embodiments are discussed only to enable those skilled in the art to better understand and thus implement the present disclosure, rather than implying any limitation on the scope of the present disclosure.
[0019] As used herein, the term "including" and its variants are to be interpreted as open-ended terms meaning "including but not limited to". The term "based on" is to be interpreted as "based at least in part on". The terms "one embodiment" and "an embodiment" are to be interpreted as "at least one embodiment". The term "another embodiment" is to be interpreted as "at least one other embodiment". The orientation or position relationship indicated by the terms "upper", "lower", "left", "right", "front", "back", "top", "bottom", "inner", "outer", "vertical", "horizontal", "lateral", "longitudinal" and the like is based on the orientation or position relationship shown in the accompanying drawings. These terms are mainly for better describing the present application and its embodiments, and are not used to limit the indicated devices, elements or components to have a specific orientation, or to be constructed and operated in a specific orientation. In addition, in addition to being used to indicate an orientation or position relationship, some of the above terms may also be used to indicate other meanings, such as the term "upper" may also be used to indicate a certain dependency or connection relationship in some cases. For those of ordinary skill in the art, the specific meanings of these terms in this application can be understood according to the specific circumstances. In addition, the terms "install", "set", "provided with", "connected" and "connected" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral structure; it can be a mechanical connection, or an electrical connection; it can be directly connected, or indirectly connected through an intermediate medium, or it can be an internal connection between two devices, elements or components. For those of ordinary skill in the art, the specific meanings of the above terms in this application can be understood according to the specific circumstances. In addition, the terms "first", "second", etc. are mainly used to distinguish different devices, elements or components (the specific types and structures may be the same or different), and are not used to indicate or imply the relative importance and quantity of the indicated devices, elements or components. Unless otherwise specified, "plurality" means two or more.
[0020] In a first aspect, this embodiment discloses a CAN data processing method, such as Figure 1 As shown, including: Get the message in the vehicle CAN network; Filtering the message based on preset sorting and segmentation; Put the filtered messages into the buffer; When the buffer is fully loaded, a CAN message reception interrupt is generated; Take all filtered messages out of the buffer and store them in the receiving array; Match the message ID corresponding to the message in the receiving array according to the target ID, wherein the message corresponding to the target ID is the message required by the CAN controller; Send the message in the receive array that matches the target ID to the CAN controller.
[0021] In this embodiment, a CAN data processing method is proposed. First, the sorting and segmentation rules are set in advance in the CAN network, the message IDs that the CAN controller needs to receive are sorted, filters are set, etc., the messages are sorted and segmented, and only the messages corresponding to the required message IDs are received. Secondly, the received messages are filtered using filters, and the filtered messages are placed in a buffer. Thirdly, when the number of messages is too large and the buffer is full, a CAN receive interrupt is generated, and the message is taken out of the buffer and stored in the receiving array. Finally, the message ID corresponding to the message in the receiving array is matched according to the target ID, and the corresponding message is sent to the CAN controller if the match is successful.
[0022] Specifically, the CAN data processing method of the present invention can effectively avoid frame loss. In addition, by filtering and matching the target ID, important messages will not be ignored or discarded due to too many messages, thereby causing vehicle abnormalities.
[0023] Specifically, the number of CAN network messages entering the buffer is reduced by presetting the sorting and segmentation rules on the one hand and filtering the messages through filters on the other hand. On this basis, a CAN message reception interrupt is added to avoid data overload.
[0024] In some embodiments, the preset sorting and segmenting includes: Arrange the data segment where the message ID corresponding to the message required by the vehicle is located; Configure the filter ID and mask based on the data segment where the packet ID is located.
[0025] In some embodiments, the filter employs a mask bit pattern; The ID and mask setting methods of the standard frame and the extended frame of the filter are consistent.
[0026] In this embodiment, sorting and segmentation are rules pre-set in the CAN network for preliminary message screening. The data segment where the message ID corresponding to the message required by the vehicle is located is sorted to filter out the data interval required or more important by the CAN controller. For example, if 0X18FF100-0X18FF2000 is used as the required data segment, all data segments in this interval will be received. Segmentation is coordinated with the ID and mask of the filter.
[0027] Specifically, the CAN controller filter uses a mask bit mode and can only be configured as a 32-bit or two 16-bit filters. The standard frame and extended frame ID and mask setting methods of the filter are the same. In the mask MASK, 1 means care and 0 means don't care. For example: ID = 0x5f, MASK = 0, since the MASK bit 0 means care, the filter will discard any message that does not match 0x5f.
[0028] Specifically, through the preset sorting, the more important parts of the message can be summarized and received in a targeted manner. By setting the filter ID and mask in the segment, the sorting results can be further implemented.
[0029] In some embodiments, filtering the message includes: Extract the message ID from the bus message; Comparing the message ID with the content in an identifier acceptance register, wherein the identifier acceptance register is used to store a verification ID, and the verification ID is used to compare with the message ID; If the message ID matches the verification ID, the message corresponding to the message ID is allowed to be received.
[0030] In some embodiments, if the message ID does not match the verification ID, the message ID is compared with the content in an identifier mask register, wherein the identifier mask register is used to store the mask, and the mask is used to compare with the message ID; If the concerned bit in the mask matches the corresponding bit of the message ID, the message corresponding to the message ID will be received; If the concerned bit in the mask does not match the corresponding bit of the message ID, the message corresponding to the message ID will be filtered.
[0031] In this embodiment, after the preset sorting and segmentation, filtering is performed again. When a message arrives on the bus, the CAN controller compares the identifier of the message with the content in the identifier acceptance register. If the ID of the message is the same as the ID in the identifier acceptance register, the message corresponding to the message ID is placed in the buffer. If the IDs are different, the message ID in the bus message is compared with the content in the identifier mask register. If the care bit of the ID in the identifier mask register is the same as the corresponding bit in the message ID in the bus message, the message corresponding to the message ID is placed in the buffer.
[0032] Specifically, if the verification ID is exactly the same as the message ID, the message corresponding to the message ID is received. If they are not consistent, the mask care bit is compared with the corresponding bit of the message ID. In the mask MASK, 1 means care, and 0 means don't care. For example: ID=0x5e, MASK=0, since MASK bit 0 means care, the filter will discard any message that does not match 0x5e; for example: ID=0x5f, MASK=0x01, since MASK bit 1 means don't care, the filter will ignore bit0, that is, 0x5f and 0x5e will be accepted; for example, ID=0x1802212f, MASK=0x00ff0000, the filter will ignore bit16~bit23 of the message ID in the same way.
[0033] Specifically, filtering can effectively reduce the number of messages entering the receiving buffer, so that the buffer is not so crowded, thereby preventing important messages from being dropped or even lost.
[0034] In some embodiments, taking out all filtered messages from the buffer and storing them in the receiving array includes: No more parsing and judgment of message data content; Traverse the messages in the buffer and take out all the messages and put them into the receiving array; If the buffer is empty, the buffer starts receiving messages again.
[0035] In some embodiments, if the message ID corresponding to the message in the received array does not match the target ID, the message corresponding to the unmatched message ID is discarded.
[0036] In this embodiment, after the buffer is fully loaded, all messages are taken out of the buffer and stored in the receiving array. Specifically, the process of CAN receiving interrupt is as follows: Figure 2 As shown, if a CAN message reception interrupt is generated, the message data content will no longer be parsed and judged. At the same time, each time the interrupt is entered, the entire buffer will be traversed, all the message data in the buffer will be taken out and stored in the receiving array.
[0037] Specifically, during the interruption process, if the message in the buffer is empty, the message reception will be restarted.
[0038] Specifically, the message stored in the array will be matched with the message ID corresponding to the message according to the target ID. If the match is successful, the corresponding message will be sent to the CAN controller. If the match fails, the corresponding message will be discarded.
[0039] Specifically, by processing the full load condition of the buffer, that is, taking out the message and storing it in the receiving array, and using the preset target ID to match the message in the receiving array, the loss of important messages and the message frame loss and message loss after the buffer is full are further avoided.
[0040] In a second aspect, the present invention provides a CAN data processing device, such as Figure 3 As shown, the device includes the following modules: Acquisition module: used to obtain messages in the vehicle CAN network; Filtering module: used to filter the message based on preset sorting and segmentation, and put the filtered message into a buffer; Interrupt module: used to generate a CAN message reception interrupt when the buffer is full; take out all filtered messages from the buffer and store them in the receiving array; Matching module: used to match the message ID corresponding to the message in the receiving array according to the target ID, and send the message in the receiving array matching the target ID to the CAN controller, wherein the message corresponding to the target ID is the message required by the CAN controller.
[0041] In a third aspect, the present invention proposes an electronic device, characterized in that it includes a processor and a memory, wherein the memory stores a program that can be run on the processor, and when the program is executed by the processor, it implements the CAN data processing method described in the first aspect.
[0042] In a fourth aspect, the present invention proposes a storage medium, characterized in that a computer program is stored on the storage medium, and when the computer program is executed by at least one processor, the CAN data processing method as described in the first aspect is implemented.
[0043] In summary, by reducing the number of network messages entering the receiving buffer and optimizing the received message processing method, the problem of message frame loss when the CAN bus of existing vehicles receives vehicle messages is solved, the loss of key message information is avoided, thereby avoiding the performance loss of the vehicle caused by the loss of key messages.
[0044] Those of ordinary skill in the art will appreciate that the modules and algorithm steps described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0045] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and equipment can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0046] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the modules is only a logical function division. There may be other division methods in actual implementation, such as multiple modules or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or modules, which can be electrical, mechanical or other forms.
[0047] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical modules, that is, they may be located in one place or distributed on multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the embodiments of the present invention.
[0048] In addition, each functional module in the embodiment of the present invention may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0049] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the energy-saving signal sending / receiving method of each embodiment of the present invention. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a magnetic disk, or an optical disk.
[0050] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the inventive concept. For example, the above features are replaced with (but not limited to) technical features with similar functions disclosed in the present application.
[0051] It should be understood that the size of the sequence number of each step in the content of the invention and the embodiments of the present invention does not absolutely mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention. For the purpose of example and description, the foregoing description of the implementation of the present disclosure has been given. The foregoing description is not exhaustive and is not intended to limit the present disclosure to the exact form disclosed. Various deformations and modifications may exist according to the above teachings, or various deformations and modifications may be obtained from the practice of the present disclosure. These embodiments are selected and described to illustrate the principles of the present disclosure and its practical application, so that those skilled in the art can use the present disclosure in various embodiments and various modifications suitable for the specific purpose conceived.
Claims
1. A CAN data processing method, characterized in that: include: Get the message in the vehicle CAN network; Filtering the message based on preset sorting and segmentation; Put the filtered messages into the buffer; When the buffer is fully loaded, a CAN message reception interrupt is generated; Take all filtered messages out of the buffer and store them in the receiving array; Match the message ID corresponding to the message in the receiving array according to the target ID, wherein the message corresponding to the target ID is the message required by the CAN controller; Send the message in the receive array that matches the target ID to the CAN controller.
2. A CAN data processing method as claimed in claim 1, characterized in that: The preset arrangement and segmentation include: Arrange the data segment where the message ID corresponding to the message required by the vehicle is located; Configure the filter ID and mask based on the data segment where the packet ID is located.
3. A CAN data processing method as claimed in claim 2, characterized in that: The filter uses a mask bit pattern; The ID and mask setting methods of the standard frame and the extended frame of the filter are consistent.
4. A CAN data processing method as claimed in claim 1, characterized in that: The filtering of the message includes: Extract the message ID from the bus message; Comparing the message ID with the content in an identifier acceptance register, wherein the identifier acceptance register is used to store a verification ID, and the verification ID is used to compare with the message ID; If the message ID matches the verification ID, the message corresponding to the message ID is allowed to be received.
5. A CAN data processing method as claimed in claim 4, characterized in that: If the message ID does not match the verification ID, comparing the message ID with the content in an identifier mask register, wherein the identifier mask register is used to store the mask, and the mask is used to compare with the message ID; If the concerned bit in the mask matches the corresponding bit of the message ID, the message corresponding to the message ID will be received; If the concerned bit in the mask does not match the corresponding bit of the message ID, the message corresponding to the message ID will be filtered.
6. A CAN data processing method as claimed in claim 1, characterized in that: The method of taking out all filtered messages from the buffer and storing them in the receiving array includes: No more parsing and judgment of message data content; Traverse the messages in the buffer and take out all the messages and put them into the receiving array; If the buffer is empty, the buffer starts receiving messages again.
7. A CAN data processing method as claimed in claim 1, characterized in that: If the message ID corresponding to the message in the received array does not match the target ID, the message corresponding to the unmatched message ID is discarded.
8. A CAN data processing device, characterized in that: The device comprises: Acquisition module: used to obtain messages in the vehicle CAN network; Filtering module: used to filter the message based on preset sorting and segmentation, and put the filtered message into a buffer; Interrupt module: used to generate a CAN message reception interrupt when the buffer is full; take out all filtered messages from the buffer and store them in the receiving array; Matching module: used to match the message ID corresponding to the message in the receiving array according to the target ID, and send the message in the receiving array matching the target ID to the CAN controller, wherein the message corresponding to the target ID is the message required by the CAN controller.
9. An electronic device, characterized in that: The method comprises a processor and a memory, wherein the memory stores a program that can be run on the processor, and when the program is executed by the processor, the CAN data processing method according to any one of claims 1 to 7 is implemented.
10. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by at least one processor, the CAN data processing method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Message processing method and device
CN110138797A
Vehicle communication monitoring method and device
CN112511396A
Timing system message data packet distribution method
CN115037798A
Message buffer full handling in a CAN device that employs reconfigurable message buffers
US6604156B1