CAN message filtering item configuration method, system, device and medium

By using a clustering algorithm based on Hamming distance and redundancy elimination technology, the problem of low efficiency in merging CAN message filtering items was solved, achieving fast and efficient filtering item merging, and improving the filtering efficiency and hardware resource utilization of the CAN system.

CN121664580APending Publication Date: 2026-03-13SUZHOU SUIFEI TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-29
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

In existing technologies, the efficiency of CAN message filtering item merging is low, and the utilization of hardware resources is insufficient, resulting in a significant increase in processor time consumption.

Method used

A Hamming distance-based clustering algorithm is used to group filter items, and redundant items are detected and deleted within each group. The number of filter items is reduced to the number of available entries in the hardware filter through an iterative merging process, and the hardware filter is dynamically updated in conjunction with software filtering.

Benefits of technology

It significantly reduces the computational load of pairwise comparisons of filter items, removes unnecessary filter items, reduces processor time usage, and improves the overall filtering efficiency and flexibility of the CAN system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121664580A_ABST
    Figure CN121664580A_ABST
Patent Text Reader

Abstract

The invention provides a CAN message filtering item configuration method, system and device and a medium, and relates to the field of CAN buses, and the method comprises the steps: defining filtering items of a CAN message, and obtaining an initial filtering item set; clustering the filtering items into a plurality of groups based on Hamming distance by adopting a clustering algorithm, and detecting and deleting redundant filtering items in each group; calculating the grade after the filtering items in each group are combined pairwise, and constructing a candidate combination pair priority queue according to the grade; selecting a candidate pair with the highest level from the priority queue to perform filtering item combination, generating a new filtering item, and updating a filtering item set and a grouping structure; and configuring the updated filtering item set to a hardware filter, and applying the initial filtering item set to software filtering. According to the invention, the problems of low filtering item merging efficiency and insufficient hardware resource utilization rate in the prior art are solved, the filtering item merging operation with high speed, high efficiency and clear structure is realized, and the overall filtering efficiency and flexibility of the CAN system are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of CAN bus technology, specifically to a CAN message filtering configuration method, system, device, and medium based on Hamming distance grouping and redundancy elimination. Background Technology

[0002] In CAN bus-based communication systems, a large number of filtering rules are often needed to filter unnecessary CAN messages. However, the number of hardware filters is limited, and the application layer often needs to process CAN ID sets far exceeding the number of hardware filters. When the number of user-defined filter items exceeds the hardware's capacity, software filtering of CAN messages must be performed. When there are many filter items, it significantly consumes processor time, necessitating the merging of these filter items to meet hardware load limits and reduce processor time consumption. To address this, this paper proposes a filter item merging method based on Hamming distance for fast clustering and intra-group redundancy elimination, achieving a fast, efficient, and structurally clear filter item merging operation. Summary of the Invention

[0003] In view of this, embodiments of this application provide a CAN message filtering item configuration method, system, device and medium based on Hamming distance grouping and redundancy elimination, aiming to solve the problems of low filtering item merging efficiency and insufficient hardware resource utilization in the prior art, so as to achieve fast, efficient and structurally clear filtering item merging operation and improve the overall filtering efficiency and flexibility of the CAN system.

[0004] This application provides the following technical solution: a CAN message filtering item configuration method based on Hamming distance grouping and redundancy elimination, including: Define the filtering items for the CAN message and obtain an initial set of filtering items; wherein each filtering item includes a mask M and a reference ID value R for matching the CAN frame identifier, and define the level r of each filtering item based on the mask M; If the number of filter items in the initial filter item set exceeds the number of available entries in the hardware filter, an iterative merging process is performed until the number of filter items does not exceed the number of available entries in the hardware filter. The iterative merging process includes: using a clustering algorithm to cluster the filter items into several groups based on Hamming distance, and detecting and deleting redundant filter items within each group. Calculate the ranking of each pair of filter items within each group after merging, and construct a priority queue of candidate merge pairs based on the ranking; select the candidate pair with the highest ranking from the priority queue to perform filter item merging operation, generate new filter items, and update the filter item set and grouping structure; The updated set of filter items is configured into the hardware filter, and the initial set of filter items is used for software filtering; wherein, during system operation, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of the software filter.

[0005] According to one embodiment of this application, filtering items are clustered into several groups based on Hamming distance, including: Set a distance threshold D, and initially treat each filter item as an independent set; Calculate the Hamming distance between all filter item pairs. If the Hamming distance is less than the distance threshold D, merge the corresponding independent sets to obtain several groups. The Hamming distance is calculated as follows: For two filter terms A(M) A ,R A ) and B(M B ,R B The Hamming distance is: ; In this context, bitcount(·) counts the number of bits that are 1, ⊕ represents the bitwise XOR operation, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

[0006] According to one embodiment of this application, the detection method for the redundant filter item is as follows: For two filter terms A(M) A ,R A ) and B(M B ,R B If the following conditions are met, then A is considered to contain B: ,and ; If A contains B, then delete filter item B; In this context, bitcount(·) counts the number of bits that are 1, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

[0007] According to one embodiment of this application, the filter item merging operation is used to merge two filter items A(M) A ,R A ) and B(M B ,R B ) are merged into a new filter item X(M) X , R X ),in: M X = ; R X = M X ; Where ⊕ represents the bitwise XOR operation, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

[0008] According to one embodiment of this application, the level r of the filter item is the number of bits that are 1 in the filter item mask M, r = bitcount(M); the level of the new filter item after merging is bitcount(M). X ).

[0009] According to one embodiment of this application, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of software filtering, including: During system operation, the number of times each filter item in the statistical software is hit is counted; Filters that hit more than a set threshold are dynamically added to the reserved entries of the hardware filter.

[0010] According to one embodiment of this application, the dynamic update further includes: Record the CAN frames filtered by the software and the number of times each CAN frame appears; Add CAN frame identifiers that appear more than the threshold number of times to the reserved entries of the hardware filter.

[0011] This application also provides a CAN message filtering item configuration system for implementing the above method, including: The filter item management module is used to define filter items for CAN messages and obtain an initial set of filter items; wherein each filter item includes a mask M and a reference ID value R for matching CAN frame identifiers, and the level r of each filter item is defined based on the mask M. The clustering and redundancy elimination module is used to perform an iterative merging process when the number of filter items in the initial filter item set exceeds the number of available entries in the hardware filter, until the number of filter items does not exceed the number of available entries in the hardware filter; the iterative merging process includes: using a clustering algorithm to cluster the filter items into several groups based on Hamming distance, and detecting and deleting redundant filter items in each group; The merge processing module is used to calculate the ranking of each filter item in each group after merging, and to build a priority queue of candidate merge pairs based on the ranking. The hardware configuration and dynamic adaptation module is used to configure the updated set of filter items to the hardware filter and use the initial set of filter items for software filtering; wherein, during system operation, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of the software filter.

[0012] This application also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the above-described CAN message filtering configuration method.

[0013] This application also provides a computer-readable storage medium storing a computer program that performs the above-described CAN message filtering configuration method.

[0014] Compared with the prior art, the beneficial effects that can be achieved by the above-mentioned at least one technical solution adopted in the embodiments of this specification include at least the following: by grouping the Hamming distances of the filter items, the embodiments of this invention can significantly reduce the computational amount of pairwise comparisons of filter items; by detecting redundant filter items within the group, unnecessary filter items can be deleted; and finally, the most relevant merging pairs are performed within the group, thereby effectively reducing the number of filter items, ensuring that the number of filter items meets the hardware load limit, reducing the processor's time occupation, and improving the overall filtering efficiency and flexibility of the CAN system. Attached Figure Description

[0015] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0016] Figure 1 This is a schematic flowchart of the CAN message filtering item configuration method based on Hamming distance grouping and redundancy elimination according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the CAN message filtering item configuration system structure according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of the computer device of the present invention. Detailed Implementation

[0017] The embodiments of this application will now be described in detail with reference to the accompanying drawings.

[0018] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. This application can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, in the absence of conflict, the following embodiments and features in the embodiments can be combined with each other. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0019] like Figure 1 As shown, this embodiment of the invention provides a CAN message filtering item configuration method based on Hamming distance grouping and redundancy elimination, including: S101. Define the filtering items for the CAN message and obtain an initial set of filtering items; wherein each filtering item includes a mask M and a reference ID value R for matching the CAN frame identifier, and define the level r of each filtering item based on the mask M; S102. If the number of filter items in the initial filter item set exceeds the number of available entries in the hardware filter, then an iterative merging process is executed until the number of filter items does not exceed the number of available entries in the hardware filter; the iterative merging process includes: using a clustering algorithm to cluster the filter items into several groups based on Hamming distance, and detecting and deleting redundant filter items in each group; S103. Calculate the level of each pair of filter items in each group after merging, and construct a priority queue of candidate merging pairs according to the level; select the candidate pair with the highest level from the priority queue to perform filter item merging operation, generate new filter items and update the filter item set and grouping structure; S104. Configure the updated set of filter items to the hardware filter, and use the initial set of filter items for software filtering; wherein, during system operation, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of the software filter.

[0020] In some embodiments of the present invention, the filter items are clustered into several groups based on Hamming distance, including: Set a distance threshold D, and initially treat each filter item as an independent set; Calculate the Hamming distance between all filter item pairs. If the Hamming distance is less than the distance threshold D, merge the corresponding independent sets to obtain several groups. The Hamming distance is calculated as follows: For two filter terms A(M) A ,RA ) and B(M B ,R B The Hamming distance is: ; In this context, bitcount(·) counts the number of bits that are 1, ⊕ represents the bitwise XOR operation, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

[0021] In some embodiments of the present invention, the detection method for the redundant filter item is as follows: For two filter terms A(M) A ,R A ) and B(M B ,R B If the following conditions are met, then A is considered to contain B: ,and ; If A contains B, then delete filter item B; In this context, bitcount(·) counts the number of bits that are 1, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

[0022] In some embodiments of the present invention, the filter item merging operation is used to merge two filter items A(M) A ,R A ) and B(M B ,R B ) are merged into a new filter item X(M) X , R X ),in: M X = ; R X = M X ; Where ⊕ represents the bitwise XOR operation, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

[0023] In some embodiments of the present invention, the level r of the filter item is the number of bits that are 1 in the filter item mask M, r = bitcount(M); the level of the new filter item after merging is bitcount(M). X ).

[0024] In some embodiments of the present invention, the dynamic updating of the reserved entries of the hardware filter based on the hit statistics of software filtering includes: during system operation, counting the number of hits of each filter item in the software filter; and dynamically adding filter items whose hit count exceeds a set threshold to the reserved entries of the hardware filter.

[0025] In some embodiments of the present invention, the dynamic update further includes: recording the CAN frames filtered by the software and the number of times the CAN frames occur; adding the identifiers of CAN frames whose occurrence count exceeds a threshold to the reserved entries of the hardware filter.

[0026] In specific implementation, the CAN message filtering item configuration method of the present invention is implemented as follows: 1. Define a filter term, which includes a mask M and a reference ID value R. For a CAN frame to be received, if its CAN ID value X satisfies... If the filter is hit, the frame can be received. 2. Given two filter terms A(MA,RA) and B(MB,RB), perform the following operations on them: a) Perform an XOR operation on the values ​​of RA and RB to obtain the conflicting bit C between A and B; b) Invert the value of C from step a, and keep the bits where A and B are both 1; c) Perform a logical AND operation on the M values ​​of A and B, and retain the bits where A and B are both 1; d) Perform a logical AND operation on the results of steps b and c to form a masked superset m of filter terms A and B. M ; e) Perform a logical AND operation on the results of steps A and d to form a merged ID set m of A and B. R ; 3. The filter item merging operation is defined as follows: Mask merging of A and B:

[0027] Merging the IDs of A and B:

[0028] In this context, & represents the bitwise AND operation, ⊕ represents the bitwise XOR operation, and ~ represents the bitwise NOT operation.

[0029] 4. Define the level r of the filter item, where r is the sum of the bits in the filter item mask parameter M: bitcount(M); 5. Define the number of configurable entries allowed for the hardware receive filter (N) H ), which is the total number of configurable entries for the hardware filter (N) A Subtract the number of retained entries (N) R Hardware filtering retains entries (N) R This is used for dynamic filtering and adjustment, such as low-frequency messages like diagnostic messages for temporary nodes; 6. Based on all messages that need filtering in the application scenario, each node constructs a filter item based on CAN ID for each message, forming the initial filter configuration set P. I ; 7. If the number of entries in the filter configuration set P (N) P (More than N) H Then perform the following operations until N. P Less than or equal to N H : a) Cluster the configuration items into several groups using a clustering algorithm (based on Hanming distance); the steps are as follows: a.1) For two filter terms A(M) A ,R A ) and B(M B ,R B ), and its clustering algorithm is defined as That is, the Hanming distance is the number of bits that differ in effective bits; a.2) Initially, each configuration item is a separate set; a.3) Compare each configuration item pairwise; if the Hanming distance is less than the threshold D, then merge the sets. a.4) This ultimately results in several groups based on Hamming distance; b) For two filter items A(M) A ,R A ) and B(M B ,R B ),if: ,and A is said to contain B; c) Remove redundant configuration items within each group, i.e., compare them pairwise; if A contains B, then delete B. d) Construct a priority queue P Q Store candidate configuration pairs. The steps are as follows: d.1) Calculate the rank r of each group after the merging operation. d.2) Following the rule that the higher the level r, the earlier the candidate configuration item is placed in P. Q ; e) From queue P Q Select the first pair of configuration items, A and B; f) Remove configuration items A and B from the filter configuration set P; g) Add a new configuration item X to the filter configuration set P. The mask of X is the combined mask of configuration items A and B, and the ID is the combined ID of configuration items A and B; that is... , ; h) Place X into the corresponding group, calculate candidate pairs with other configuration items within this group, and place them into P. Q ; i) Repeat step a until N P Less than or equal to N H; 8. The final filter configuration set P F Configure it in the hardware filter; 9. Set the initial filter configuration set P I Apply it to software filtering; 10. Temporary filter entries can be added / deleted from the hardware-reserved entries via command issuance; 11. Perform software filtering on the CAN frames that have undergone hardware filtering, and count the number of hits for each filter item; 12. Periodically determine the hit count and add the filter entry with the highest hit count to the hardware filter retention list; 13. Record the CAN frames filtered by the software and their counts; 14. Periodically check the number of occurrences and add CAN frame IDs that exceed the threshold to the hardware filter retention entries.

[0030] This invention proposes a method for generating a "near-optimal configuration" that can be dynamically adjusted. By iteratively merging multiple filter configuration items and introducing an "ID grouping" mechanism to avoid full merging, the method preserves the initial configuration filter conditions as much as possible, generating a configuration set that does not exceed the number of available hardware filters. During operation, filter configurations can be dynamically added / deleted based on the number of times the filters are matched, thus fully utilizing the hardware filtering function of the CAN controller to reduce software resource consumption.

[0031] like Figure 2 As shown, this application also provides a CAN message filtering item configuration system 200 for implementing the above method, including: The filter item management module 201 is used to define filter items for CAN messages and obtain an initial filter item set; wherein each filter item includes a mask M and a reference ID value R for matching CAN frame identifiers, and the level r of each filter item is defined based on the mask M. The clustering and redundancy elimination module 202 is used to perform an iterative merging process when the number of filter items in the initial filter item set exceeds the number of available entries in the hardware filter, until the number of filter items does not exceed the number of available entries in the hardware filter; the iterative merging process includes: using a clustering algorithm to cluster the filter items into several groups based on Hamming distance, and detecting and deleting redundant filter items in each group. The merging processing module 203 is used to calculate the level of each pair of filter items in each group after merging, and to construct a priority queue of candidate merging pairs based on the level. The hardware configuration and dynamic adaptation module 204 is used to configure the updated set of filter items to the hardware filter and use the initial set of filter items for software filtering; wherein, during system operation, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of the software filter.

[0032] In one embodiment, a computer device is provided, such as Figure 3 As shown, it includes a memory 301, a processor 302, and a computer program stored in the memory 301 and executable on the processor 302. When the processor 302 executes the computer program, it implements the above-mentioned CAN message filtering item configuration method.

[0033] Specifically, the computer device can be a computer terminal, a server, or a similar computing device.

[0034] In this embodiment, a computer-readable storage medium is provided, which stores a computer program that performs the above-described CAN message filtering configuration method.

[0035] Specifically, computer-readable storage media, including both permanent and non-permanent, removable and non-removable media, can store information using any method or technology. Information can be computer-readable instructions, data structures, program modules, or other data. Examples of computer-readable storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable storage media does not include transient media, such as modulated data signals and carrier waves.

[0036] Obviously, those skilled in the art should understand that the modules or steps of the above-described embodiments of the present invention can be implemented using general-purpose computing devices. They can be centralized on a single computing device or distributed across a network of multiple computing devices. Optionally, they can be implemented using computer-executable program code, thereby storing them in a storage device for execution by a computing device. In some cases, the steps shown or described can be performed in a different order than those presented here, or they can be fabricated as separate integrated circuit modules, or multiple modules or steps can be fabricated as a single integrated circuit module. Thus, the embodiments of the present invention are not limited to any particular hardware and software combination.

[0037] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A CAN message filtering item configuration method based on Hamming distance grouping and redundancy elimination, characterized in that, include: Define the filtering items for the CAN message and obtain an initial set of filtering items; wherein each filtering item includes a mask M and a reference ID value R for matching the CAN frame identifier, and define the level r of each filtering item based on the mask M; If the number of filter items in the initial filter item set exceeds the number of available entries in the hardware filter, an iterative merging process is performed until the number of filter items does not exceed the number of available entries in the hardware filter. The iterative merging process includes: using a clustering algorithm to cluster the filter items into several groups based on Hamming distance, and detecting and deleting redundant filter items within each group. Calculate the ranking of each pair of filter items within each group after merging, and construct a priority queue of candidate merge pairs based on the ranking; select the candidate pair with the highest ranking from the priority queue to perform filter item merging operation, generate new filter items, and update the filter item set and grouping structure; The updated set of filter items is configured into the hardware filter, and the initial set of filter items is used for software filtering; wherein, during system operation, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of the software filter.

2. The CAN message filtering item configuration method according to claim 1, characterized in that, The filter terms are clustered into several groups based on Hamming distance, including: Set a distance threshold D, and initially treat each filter item as an independent set; Calculate the Hamming distance between all filter item pairs. If the Hamming distance is less than the distance threshold D, merge the corresponding independent sets to obtain several groups. The Hamming distance is calculated as follows: For two filter terms A(M) A ,R A ) and B(M B ,R B The Hamming distance is: ; In this context, bitcount(·) counts the number of bits that are 1, ⊕ represents the bitwise XOR operation, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

3. The CAN message filtering item configuration method according to claim 1, characterized in that, The detection method for the redundant filter items is as follows: For two filter terms A(M) A ,R A ) and B(M B ,R B If the following conditions are met, then A is considered to contain B: ,and ; If A contains B, then delete filter item B; In this context, bitcount(·) counts the number of bits that are 1, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

4. The CAN message filtering configuration method according to claim 1, characterized in that, The filter item merging operation is used to combine two filter items A(M) A ,R A ) and B(M B ,R B ) are merged into a new filter item X(M) X , R X ),in: M X = ; R X = M X ; Where ⊕ represents the bitwise XOR operation, & represents the bitwise AND operation, and ~ represents the bitwise NOT operation.

5. The CAN message filtering item configuration method according to claim 4, characterized in that, The level r of the filter item is the number of bits that are 1 in the filter item mask M, r = bitcount(M); the level of the new filter item after merging is bitcount(M). X ).

6. The CAN message filtering item configuration method according to claim 1, characterized in that, The hit statistics based on software filtering dynamically update the reserved entries of the hardware filter, including: During system operation, the number of times each filter item in the statistical software is hit is counted; Filters that hit more than a set threshold are dynamically added to the reserved entries of the hardware filter.

7. The CAN message filtering item configuration method according to claim 6, characterized in that, The dynamic update also includes: Record the CAN frames filtered by the software and the number of times each CAN frame appears; Add CAN frame identifiers that appear more than the threshold number of times to the reserved entries of the hardware filter.

8. A CAN message filtering configuration system for implementing the method according to any one of claims 1-7, characterized in that, include: The filter item management module is used to define filter items for CAN messages and obtain an initial set of filter items; wherein each filter item includes a mask M and a reference ID value R for matching CAN frame identifiers, and the level r of each filter item is defined based on the mask M. The clustering and redundancy elimination module is used to perform an iterative merging process when the number of filter items in the initial filter item set exceeds the number of available entries in the hardware filter, until the number of filter items does not exceed the number of available entries in the hardware filter; the iterative merging process includes: using a clustering algorithm to cluster the filter items into several groups based on Hamming distance, and detecting and deleting redundant filter items in each group; The merge processing module is used to calculate the ranking of each filter item in each group after merging, and to build a priority queue of candidate merge pairs based on the ranking. The hardware configuration and dynamic adaptation module is used to configure the updated set of filter items to the hardware filter and use the initial set of filter items for software filtering; wherein, during system operation, the reserved entries of the hardware filter are dynamically updated based on the hit statistics of the software filter.

9. A computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the CAN message filtering item configuration method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that performs the CAN message filtering item configuration method according to any one of claims 1 to 7.