A mailbox configuration method of CAN message and related device

By performing multiple grouping processes and load balancing calculations on CAN message groups, the problem of limited mailbox capacity in the CAN controller was solved, load-balanced mailbox configuration was achieved, and the real-time performance and reliability of the system were improved.

CN123145231APending Publication Date: 2026-11-20BEIJING JINGWEI HIRAIN TECH CO INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611568330.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-10
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In existing technologies, the mailbox capacity of CAN controllers is limited, making it impossible to allocate a separate mailbox for each CAN message, resulting in unbalanced load and affecting the real-time performance and reliability of the system.

Method used

By determining the number of mailboxes n in the current message group, the message group is grouped multiple times using different ID bit sets. The load balancing degree of each candidate grouping scheme is calculated, and the scheme with the highest load balancing degree is selected for allocation, thereby achieving load-balanced mailbox configuration.

Benefits of technology

It improved the utilization rate of mailbox resources, reduced message loss and transmission delay, and optimized the system's communication performance and resource utilization efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123145231A_ABST
    Figure CN123145231A_ABST
Patent Text Reader

Abstract

The application discloses a mailbox configuration method of CAN message and related devices, and relates to the field of automobile electronics. The application groups messages in a current message group by using different ID bit sets, obtains a plurality of candidate grouping schemes, each candidate grouping scheme includes n message subgroups, and each message subgroup is one-to-one corresponding to n mailboxes allocated to the current message group. Then, the application calculates characteristic values when messages in each message subgroup are allocated to the n mailboxes according to the grouping scheme, determines the load balancing degree corresponding to each candidate grouping scheme, selects the candidate grouping scheme corresponding to the highest load balancing degree as the final scheme, and realizes the task of uniformly dispersing CAN messages of the current message group to each mailbox. The application helps to solve the problems of message loss, transmission delay, mailbox overload or resource waste caused by improper mailbox configuration, and provides a basis for improving the real-time performance, reliability and other performances of CAN system communication.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of automotive electronics technology, and in particular to a method for configuring a mailbox for CAN messages and related devices. Background Technology

[0002] With the rapid development of automotive electronic systems, Controller Area Network (CAN) has gradually become the core network for real-time communication between various automotive Electronic Control Units (ECUs). However, in the current automotive electronic architecture, due to hardware resource constraints, the mailbox (MB) capacity of the CAN controller is usually limited, making it impossible to allocate a separate MB for each CAN message.

[0003] Therefore, in the face of the ever-increasing demand for CAN message communication, how to allocate mailbox resources for CAN messages in order to improve the real-time performance and reliability of the system's CAN communication has become a technical problem that urgently needs to be solved by those skilled in the art. Summary of the Invention

[0004] In view of the above problems, this application provides a method and related apparatus for configuring mailboxes for CAN messages, so as to realize the load-balanced mailbox configuration task and meet the real-time and reliability requirements of CAN message transmission.

[0005] The specific plan is as follows: The first aspect of this application provides a method for configuring a mailbox for CAN messages, including: Determine the number n mailboxes to be allocated to the current message group, where n is an integer greater than 1; the current message group includes multiple CAN messages, and the multiple CAN messages have the same CAN channel, communication direction and frame format but different identifier IDs; The current message group is processed multiple times to obtain k candidate grouping schemes. Each candidate grouping scheme includes n message subgroups, where k is a pre-set integer greater than 1. The set of ID bits used in each grouping process is determined according to a preset rule and is different for each subgroup. Based on at least the number of CAN messages carrying each target ID transmitted within a preset time period, the feature values ​​corresponding to the k candidate grouping schemes are calculated respectively; the target ID is the ID of the CAN message in the current message group, and the feature value is used to characterize the load balancing degree when the messages in the current message group are distributed to n mailboxes according to the corresponding candidate grouping scheme. Based on the calculation results, the candidate grouping scheme corresponding to the highest load balancing degree is determined as the final scheme, and the packets in the current packet group are distributed to n mailboxes according to the final scheme.

[0006] A second aspect of this application provides a CAN message mailbox configuration device, comprising: An initialization unit is used to determine the number of mailboxes n allocated to the current message group, where n is an integer greater than 1; the current message group includes multiple CAN messages, and the multiple CAN messages have the same CAN channel, communication direction and frame format but different identifier IDs; The grouping execution unit is used to perform multiple grouping processes on each message in the current message group to obtain k candidate grouping schemes; each candidate grouping scheme includes n message subgroups, where k is a pre-set integer greater than 1, and the set of ID bits used in each grouping process is determined according to a preset rule and is different for each one; The group evaluation unit is used to calculate the feature values ​​corresponding to the k candidate grouping schemes based on at least the number of CAN messages carrying each target ID transmitted within a preset time period; the target ID is the ID of the CAN message in the current message group; the feature value is used to characterize the load balancing degree when the messages in the current message group are distributed to n mailboxes according to the corresponding candidate grouping scheme; and, based on the calculation results, the candidate grouping scheme corresponding to the highest load balancing degree is determined as the final scheme. The grouping application unit is used to distribute the messages in the current message group to n mailboxes according to the final scheme.

[0007] A third aspect of this application provides a CAN message mailbox configuration device, comprising at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program to implement the mailbox configuration method for CAN messages described in the first aspect above.

[0008] A fourth aspect of this application provides a storage medium carrying one or more computer programs that, when executed by an electronic device, enable the electronic device to implement the mailbox configuration method for CAN messages described in the first aspect.

[0009] The fifth aspect of this application provides a computer program product including computer-readable instructions that, when executed on an electronic device, enable the electronic device to implement the mailbox configuration method for CAN messages described in the first aspect.

[0010] By employing the above technical solution, this application groups the messages in the current message group using different ID bit sets to obtain multiple candidate grouping schemes. Each candidate grouping scheme includes n message subgroups, and each message subgroup corresponds one-to-one with the n mailboxes allocated to the current message group. Then, the characteristic values ​​of allocating the messages in each message subgroup to the n mailboxes according to the grouping scheme are calculated to determine the load balancing degree corresponding to each candidate grouping scheme. The candidate grouping scheme with the highest load balancing degree is selected as the final scheme. This achieves the task of evenly distributing the CAN messages of the current message group to each mailbox, which helps to solve problems such as message loss, transmission delay, and mailbox resource waste caused by improper mailbox configuration, and improves the resource utilization and energy efficiency of the mailbox. Attached Figure Description

[0011] Various other advantages and benefits will become apparent to those skilled in the art upon reading the following detailed description of preferred embodiments. The accompanying drawings are for illustrative purposes only and are not intended to limit the scope of this application. Furthermore, the same reference numerals denote the same parts throughout the drawings. In the drawings: Figure 1 A schematic diagram of an implementation system architecture for the CAN message mailbox configuration method provided in the embodiments of this application; Figure 2 A flowchart illustrating a method for configuring a mailbox for a CAN message, as provided in an embodiment of this application; Figure 3 A schematic diagram of a CAN message mailbox configuration device provided in an embodiment of this application; Figure 4 This is a schematic diagram of the structure of a CAN message mailbox configuration device provided in an embodiment of this application. Detailed Implementation

[0012] The embodiments of this application are described below with reference to the accompanying drawings. The terminology used in the implementation section of this application is only for explaining specific embodiments and is not intended to limit the application. Those skilled in the art will recognize that, with technological advancements and the emergence of new scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.

[0013] The applicant discovered through research that the traditional solution uses a strategy similar to binary search to group CAN messages. Specifically, messages are grouped according to the different values ​​of the highest bit of the CAN message identifier (ID). If the existing number of groups does not meet the grouping requirements, the messages obtained from the previous grouping are grouped sequentially according to the different values ​​of the next ID bit, until the current number of message groups equals the pre-set number of mailboxes, thus completing the grouping. Based on this, each group of messages is matched with a mailbox to achieve mailbox allocation.

[0014] When using traditional solutions, CAN messages with similar ID values, i.e., CAN messages carrying IDs that start with the same high-order field (such as 0x18...), are more likely to be assigned to the same mailbox. This can lead to some mailboxes becoming overcrowded in scenarios where message IDs are concentrated, while others are underutilized. This can result in extremely unbalanced mailbox loads, significant waste of mailbox resources, system response delays, and even the loss of critical messages, affecting the real-time performance, determinism, and reliability of system communication.

[0015] To address the aforementioned issues, this application provides a method and related apparatus for configuring mailboxes for CAN messages, thereby achieving load-balanced message resource configuration tasks and optimizing the system's communication performance and resource utilization efficiency.

[0016] The mailbox configuration method for CAN messages provided in this application can be applied to, for example... Figure 1 The system architecture shown includes a terminal 100 and a server 200. The server 200 may include one or more servers (…). Figure 1 (This example uses a server as an illustration).

[0017] Either terminal 100 or server 200 can be used independently to execute the CAN message mailbox configuration method provided in this application embodiment. Alternatively, terminal 100 and server 200 can also be used collaboratively to execute the CAN message mailbox configuration method provided in this application embodiment. In this application embodiment, terminal 100 can be a computer, ECU (Electronic Control Unit), VCU (Vehicle Control Unit), MCU (Micro Controller Unit), HCU (Hybrid Control Unit), etc., and this application embodiment does not impose any limitations on this.

[0018] This application provides a method for configuring a mailbox for CAN messages. Taking the application of this method to a computer device as an example, the computer device can specifically be... Figure 1The system consists of terminal 100 or a combination of terminal 100 and server 200. (Refer to...) Figure 2 The CAN message mailbox configuration method provided in this embodiment specifically includes the following steps: Step S101: Determine the number n mailboxes to be allocated to the current message group.

[0019] It should be noted that the mailbox allocation information for each message group can be obtained in advance before allocating mailbox resources. Optionally, this process may include: The first step is to construct the message dataset.

[0020] Specifically, the entire vehicle's messages can be traversed to construct a message dataset, where different CAN messages can be represented by identifiers (IDs). Optionally, considering the potential differences in the mailbox (MB) configuration and processing logic corresponding to different CAN channels, when traversing the entire vehicle's messages, they can be grouped according to the CAN channel to which each message belongs, or tags can be configured to represent the CAN channel to which the message belongs. Furthermore, format and type validation can be performed on each message, and tags representing message type (standard frame / extended frame), message length (Data Length Code, DLC), or other key attributes such as signal / period can be configured to construct a structured global message dataset. For example, according to different formats and types, the entire vehicle's messages can be divided into five categories: transmit standard frames, receive standard frames, transmit extended frames, receive extended frames, and independent Network Management (NM) messages.

[0021] The second step is to allocate mailbox resources for the whole vehicle message.

[0022] Due to the differences between different CAN channels, subsequent mailbox resource allocation operations can be performed sequentially for each CAN channel. First, the total number of available mailboxes for each communication channel is calculated. Based on this, since long messages (messages with a data length exceeding 8 bytes) cannot be written into ordinary mailboxes, the mailbox corresponding to a long message (which can be called a long mailbox) needs to be merged from multiple ordinary mailboxes. Therefore, when allocating mailbox resources for a message on a CAN channel, the existence of long messages can be checked first. If they exist, the longest data length is used to merge them into a long mailbox, which then carries the long message. Based on this, the mailbox resources corresponding to the current CAN channel are divided into two categories: long mailboxes and ordinary mailboxes. For each type of mailbox resource, since a single mailbox can only receive standard frames or extended frames, it is also necessary to group the vehicle's long messages / ordinary messages according to message type, transmission direction, etc. For example, according to the attribute tags configured in the first step, message IDs belonging to the same CAN channel but corresponding to different CAN message formats, types, etc., can be stored in different classification containers, and hardware mailbox resource allocation can be performed based on this. Optionally, to improve system availability, a basic resource unit can be reserved for each category of containers. Then, the remaining available resources are dynamically allocated based on the ratio of the number of packets corresponding to each category of containers to the total number of packets. This determines the resource allocation for each category of containers, such as the number of mailboxes. Specifically, if network management packets exist, individual network management packets can be identified and resources reserved to ensure reliable processing of these packets.

[0023] Through the mailbox resource allocation steps, the number of available mailboxes corresponding to each message group can be obtained. Each message group includes multiple CAN messages that have the same CAN channel, communication direction, and frame format but different IDs. The current message group is any one of the aforementioned message groups; that is, the current message group includes multiple CAN messages that have the same CAN channel, communication direction, and frame format but different identifier IDs. Through the first and second steps described above, the number of mailboxes allocated to the current message group can be obtained, also known as the mailbox MB allocation quota, denoted as n, where n is an integer greater than 1.

[0024] In addition, the current message group can be represented as a target ID set, which includes multiple target IDs, each of which corresponds one-to-one with each CAN message in the current message group.

[0025] Step S102: Perform multiple grouping processes on each message in the current message group to obtain k candidate grouping schemes.

[0026] Each candidate grouping scheme includes n message subgroups. In other words, for a candidate grouping scheme, the n message subgroups that make up the scheme correspond one-to-one with the n mailboxes assigned to the current message group.

[0027] The k is a pre-defined integer greater than 1. It should be noted that in this embodiment, by executing the grouping process multiple times, at least two grouping schemes that satisfy the grouping objective (that is, dividing the messages in the current message group into n groups) are obtained as candidate grouping schemes; that is, the number of times the grouping process is executed can be k or more.

[0028] In addition, before executing the grouping process, an ID list can be generated, which includes the message ID carried by each message in the current message group. To ensure reliability, the ID list can also be preprocessed, specifically including sorting and deduplication operations, to ensure the standardization and uniqueness of the data before executing the grouping process.

[0029] The set of ID bits used in each grouping process is determined according to preset rules and is different for each process. For a single grouping process, the set of ID bits used in this grouping process can consist of x ID bits. Each ID bit is determined by preset rules. x can be the minimum number of ID bits required for this grouping process to achieve its grouping goal, or it can be a fixed value determined according to preset rules that corresponds to the distribution of IDs in the list.

[0030] For example, the specific steps of a single grouping process can refer to the steps of a recursive grouping process based on bitmasks to utilize the bit-level characteristics of the CAN message ID to achieve the grouping task. Specifically, this may include: dynamically adjusting the value of the bitmask according to the frame type; performing an AND operation between the pre-configured bitmask and the message ID to filter out the ID bit values ​​that the group depends on; and further grouping according to the different ID bit values ​​until the target number of groups is reached. It should be noted that each ID bit in any set of ID bits used in this embodiment can be a consecutive ID bit in the message ID or a non-consecutive ID bit; in addition, the order of the ID bits in the set of ID bits (called the round-robin order), that is, the order in which each ID bit is used, can be from left to right, from right to left, or other preset orders, which are not limited in this embodiment.

[0031] Assuming the preset rule is to group packets according to a left-to-right round-robin order, based on the values ​​of a pre-specified ID bit and several ID bits to its right, and assuming the pre-specified ID is the highest bit of the packet ID, then a set of ID bits can be composed of the highest bit of the packet ID and several consecutive ID bits to its right. The corresponding grouping process (also known as a recursive grouping process) can specifically include: initializing the bitmask according to the frame type; for standard frames, setting the initial bitmask value to 0x400; for extended frames, setting the initial bitmask value to 0x10000000, to extract the highest bit ID value of the packet ID; traversing the ID list corresponding to the current packet group, performing bitwise operations on each packet ID using the bitmask, and grouping according to different ID bit values; if the current number of groups has not reached the preset target subgroup number n, then shifting the current bitmask bit by bit to the right to update the bitmask, and then performing a new round of grouping based on the updated bitmask. This process continues iterating until the current number of groups meets the grouping requirements.

[0032] Optionally, after obtaining a candidate grouping scheme, the message IDs corresponding to each message subgroup can be stored in different vectors to provide a structured data foundation for subsequent processing.

[0033] Step S103: Calculate the feature values ​​corresponding to the k candidate grouping schemes based on at least the number of CAN messages carrying each target ID transmitted within a preset time period.

[0034] Wherein, the target ID is the ID of the CAN message in the current message group. The feature value is used to characterize the load balancing degree when the messages in the current message group are distributed to n mailboxes according to the corresponding candidate grouping scheme. The mailbox load can be represented by the number of messages to be carried within a certain period, and the feature values ​​for different grouping schemes applied to the n mailboxes in the current message group can be calculated accordingly.

[0035] Step S104: Based on the calculation results, the candidate grouping scheme corresponding to the highest load balancing degree is determined as the final scheme.

[0036] The highest load balancing degree indicates that the grouping of the corresponding candidate grouping scheme is the most uniform. When the corresponding scheme is applied, the possibility of the system experiencing packet congestion, individual mailbox overload or low utilization is low, and the system communication performance is good.

[0037] It should be noted that in practical applications, an iterative optimization method can be adopted to obtain a candidate grouping scheme and calculate a feature value, without having to perform the feature value calculation step after obtaining k candidate grouping schemes.

[0038] Step S105: Distribute the messages in the current message group to n mailboxes according to the final scheme.

[0039] By employing the above scheme, this embodiment groups the messages in the current message group using different ID bit sets to obtain multiple candidate grouping schemes. Each candidate grouping scheme includes n message subgroups, and each message subgroup corresponds one-to-one with the n mailboxes allocated to the current message group. The characteristic values ​​of allocating the messages in each message subgroup to the n mailboxes according to the grouping scheme are calculated to determine the load balancing degree corresponding to each candidate grouping scheme. The candidate grouping scheme with the highest load balancing degree is selected as the final scheme. This achieves the task of evenly distributing the CAN messages of the current message group to each mailbox, helping to solve problems such as message loss, transmission delay, and mailbox resource waste caused by improper mailbox configuration, and improving mailbox resource utilization and energy efficiency. Based on this embodiment, the message allocation optimization task of a multi-channel CAN communication system with limited mailbox resources can be realized, providing a foundation for improving the real-time performance and reliability of system communication.

[0040] In one possible implementation, the set of ID bits used when executing any packetization process may include several consecutive ID bits that match the frame type of the packets in the current packet group, i.e., several consecutive ID bits in the standard frame packet ID, or several consecutive ID bits in the extended frame packet ID.

[0041] Since the frame type of the messages in the current message group is fixed, i.e., the number of bits in the message ID is fixed, the message ID described below refers to the message ID that matches the frame type of the messages in the current message group. Furthermore, since this scheme extracts the value of a specific ID bit based on a bitmask, the ID bits in the set of ID bits used—that is, the ID bits used in any grouping procedure—are called filter bits. Further, the ID bit used in the first execution of the grouping procedure is called the start filter bit.

[0042] Based on the above, the set of ID bits used when executing any grouping process may include: a pre-set starting filter bit to be used in this grouping, and x-1 consecutive ID bits located to the left or right of the starting filter bit of this group in the concatenated ID.

[0043] Where x represents the minimum number of ID bits required to divide the packets in the current packet group into n subgroups when performing a bitmask-based recursive grouping operation according to the starting filter bit and a preset round-robin order. It should be noted that, due to reasons such as packet IDs often being left blank in practical applications, after sorting the ID list corresponding to the current packet group in ascending order, there are usually cases where adjacent packet IDs are not consecutive. Therefore, when performing a bitmask-based recursive grouping process on multiple ID lists with the same total number of IDs but different ID values, the recursion depth at which the grouping target is reached and the grouping process stops is usually inconsistent. That is to say, the total number of ID bits used in a given grouping process needs to be determined based on the actual situation. If the ID list corresponding to the current packet group satisfies the condition that adjacent packet ID values ​​are consecutive after ascending order, then... Where ceiling() represents the floor function; in other cases, the minimum value of x is 1. .

[0044] In one or more embodiments provided in this application, when the value of k is the ID length carried by the CAN message in the current message group, each starting filter bit used in each grouping process corresponds one-to-one with each ID bit.

[0045] Assuming the ID length carried in the CAN message is L bits, i.e., k=L, then each initial filter bit corresponds one-to-one with the L ID bits. Based on the above, the execution process of any grouping procedure can include: Perform multiple rounds of grouping operations on the messages in the current message group until the total number of current message subgroups equals n, and determine the current message grouping result as the candidate grouping scheme corresponding to this grouping.

[0046] Each round of grouping operations may include the following steps: Step S201: Determine the ID filter bit for this round.

[0047] In a single packet processing flow, the ID filter bit in the first round is the starting filter bit for this packet. The ID filter bits in subsequent rounds are determined by taking the next ID filter bit from the concatenated IDs, following the rounding order. For example, using a standard frame packet ID (11 bits), assuming the starting filter bit is the 11th bit and the rounding order is from left to right, the set of ID bits used in this packet processing flow can be represented as the 11th bit, the 1st bit, the 2nd bit, ..., for a total of x bits.

[0048] The bitmask corresponding to the ID filter bit in this round is a binary number that satisfies the following characteristics: it is 1 only at the ID filter bit in this round, 0 at other ID bits, and has a length of L bits. Subsequent bitmasks can be obtained by right-shifting the bitmask of this round bit by bit.

[0049] Step S202: Determine a combination from the pending message groups in this round as the processing target.

[0050] In this embodiment, the message group to be processed in the first round is the current message group, and the message groups to be processed in the subsequent rounds are the message subgroups after the previous round of grouping. It should be noted that in a round of grouping operation, the processing object determined each time can be the combination with the most messages among the message combinations that have not been further grouped in this round, or it can be the combination with the smallest or largest corresponding ID value, or it can be a combination with other characteristics. This embodiment does not limit the specific method of determining the processing object.

[0051] Step S203: According to the different values ​​of the ID filter bit in the current round of the CAN message ID, the CAN messages in the processing object are divided into two groups to obtain two message subgroups.

[0052] In specific cases, in practical applications, there may be situations where the ID filter bit of the CAN message ID in the current round is all 1 or all 0. In this case, the current total number of message subgroups is not updated, and the current processing object is directly removed from the pending message group in this round. In addition, there may be combinations in the pending message group in this round that contain only one CAN message and cannot be further grouped. In this case, when determining the processing object, the aforementioned combination can be excluded, or no special processing can be performed. After determining that the aforementioned combination is the processing object, the step of removing the current processing object from the pending message group in this round can be directly executed.

[0053] Step S204: If the total number of message subgroups in the current round is less than n, remove the processing object from the message groups to be processed in this round, and return to the step of determining a combination from the message groups to be processed in this round as the processing object, until the message groups to be processed in this round are empty, and then execute the next round of grouping operation.

[0054] Based on the above content, this embodiment starts from each ID bit of the message ID, executes a bitmask-based recursive grouping process in a left-to-right polling order, until n message subgroups are obtained and the grouping target is reached. This embodiment fully considers the feature that CAN message ID naming in practical applications often follows certain rules, and performs recursive division starting from each bit of the ID in turn, recursively splitting the message set into two subsets according to whether the value of each ID bit is 0 or 1, which provides a variety of feasible allocation schemes for achieving the purpose of evenly distributing the messages of the current message group across different mailboxes. The above scheme solves the problems of insufficient recursion depth, failure to cover all bits of the message ID, and difficulty in achieving globally optimal allocation when grouping is performed only starting from the first bit of the message ID. The grouping process used in this embodiment efficiently processes CAN message IDs and performs load balance degree optimization accordingly, so as to realize the task of evenly distributing CAN messages.

[0055] The specific implementation scheme of the load balance degree evaluation step is exemplarily described below.

[0056] In one or more embodiments provided in this application, the process of determining the number of CAN messages carrying each target ID transmitted within the preset time period may include the following steps: Step S301: In the case that the current message group includes event messages, the number of each type of event message transmitted within the preset time period is determined as 1.

[0057] Step S302: In the case that the current message group includes first periodic messages, the number of each type of first periodic message transmitted within the preset time period is determined as 1.

[0058] Wherein, the first periodic message is a periodic message satisfying t≥T, t is the cycle duration of the periodic message, and T is the duration of the preset time period.

[0059] Step S303: In the case that the current message group includes second periodic messages, the number of each type of second periodic message transmitted within the preset time period is determined as T / t.

[0060] Wherein, the second periodic message is a periodic message satisfying t<T. In another possible implementation, ceiling(T / t) may also be used to replace the aforementioned T / t, that is, the number of each type of second periodic message transmitted within the preset time period is determined as ceiling(T / t). It should be noted that each of the aforementioned event / first periodic / second periodic messages refers to event / first periodic / second periodic messages with different corresponding message ID values.

[0061] For example, the preset time period may be 1 second (s), that is, 1000 milliseconds (ms).

[0062] Based on the above, the calculation process for the feature value corresponding to any candidate grouping scheme can include: Step S401: Calculate the sum of the number of CAN messages carrying each target ID transmitted within the preset time period, and use it as the total load value.

[0063] Step S402: Calculate the average load value allocated to each mailbox of the current message group based on the total load value.

[0064] The average load value can be expressed as: MsgSum represents the total payload value, and MBSum represents the number of mailboxes allocated to the current message group, i.e., n mentioned above.

[0065] Step S403: After pairing the n message subgroups in the current grouping scheme with the n mailboxes allocated to the current message group one by one, calculate the number of CAN messages for each mailbox within the preset time period, and use it as the load value allocated to each mailbox in the current message group.

[0066] Step S404: Calculate the variance based on the load value of each mailbox assigned to the current message group and the average load value to obtain the characteristic value corresponding to the current grouping scheme.

[0067] For example, assuming the preset time period is 1 second, and the period duration of the second cycle message is expressed in milliseconds, MsgSum can be expressed as MsgSum = number of event messages + number of first cycle messages + 1000 / t 2_1 +...+1000 / t 2_m , where t 2_i Let i = 1, ..., m represent the period duration of the i-th type of second-cycle message. It should be noted that the aforementioned messages refer to each event / first-cycle / second-cycle message in the current message group. The actual load carried by the j-th mailbox (j = 1, ..., n) allocated to the current message group can be represented as X. j It can be represented as: X j =Number of event messages in the message subgroup corresponding to the j-th mailbox + Number of first-cycle messages in the message subgroup corresponding to the j-th mailbox + 1000 / t 2_j1 +...+1000 / t 2_jm , where t 2_ji Let i = 1, ..., m represent the period duration of the i-th type of second-period message in the message subgroup corresponding to the j-th mailbox. Based on this, the characteristic value, i.e., the variance, corresponding to the current grouping scheme can be expressed as Var .

[0068] Based on the above, this application calculates the actual number of messages carried by each mailbox for each allocation scheme as the mailbox load value, and calculates the variance between these load values ​​and the average load. The smaller the variance, the more uniform the load distribution among the mailboxes, and the better the overall load balance of the system. Based on this, the candidate grouping scheme with the smallest variance can be selected as the optimal grouping scheme, thereby achieving efficient utilization of hardware resources and reasonable scheduling of communication load, providing a foundation for ensuring the reliable operation of the CAN network under high load conditions.

[0069] Optionally, when evaluating load balancing, in addition to the total number of packets, other factors such as packet priority and mailbox access efficiency can also be considered.

[0070] In one or more embodiments provided in this application, calculating the feature values ​​corresponding to the k candidate grouping schemes based at least on the number of CAN messages carrying each target ID transmitted within a preset time period may include: Based on the priority of the CAN message carrying each target ID and the number of CAN messages carrying each target ID transmitted within a preset time period, the feature values ​​corresponding to the k candidate grouping schemes are calculated respectively.

[0071] Based on the above scheme, higher priority weights can be configured for higher priority messages to improve the load balancing characteristic value of the mailbox carrying high priority messages (hereinafter referred to as high priority mailbox), providing a basis for the final scheme of high priority mailbox carrying fewer messages, thereby improving the transmission reliability of critical messages.

[0072] In one or more embodiments provided in this application, allocating packets in the current packet group to n mailboxes according to the final scheme may include: A mapping table is generated based on the final scheme, and each CAN message in the current message group is stored in the corresponding mailbox according to the mapping table.

[0073] Specifically, a mapping table and a mailbox MB index can be initialized first. For each MB in the final scheme, all message IDs corresponding to the current MB are stored in the mapping table as keys and the current index as values, and this process is repeated until a complete mapping table is obtained. Optionally, the generated mapping table can be stored in member variables for mapping establishment.

[0074] This embodiment constructs a mapping table from message IDs to MB storage locations based on the final scheme. This mapping table enables rapid lookup, allowing message IDs to be quickly mapped to their corresponding MB locations during runtime, thus providing a foundation for improving system efficiency. Furthermore, by constructing a mapping table for each CAN channel, it provides a basis for efficient data access and management, helping to improve the system's real-time performance and stability in complex communication scenarios.

[0075] It should be noted that after generating the mapping table, the mapping relationship between the message ID and the MB position can be adjusted in real time during actual use to dynamically respond to changes in communication load, further optimize MB usage efficiency, meet MB configuration requirements under different communication loads, and thus improve the system's adaptability.

[0076] The following describes the CAN message mailbox configuration device provided in the embodiments of this application. The CAN message mailbox configuration device described below and the CAN message mailbox configuration method described above can be referred to in correspondence.

[0077] Figure 3 This is a schematic diagram of the structure of a CAN message mailbox configuration device disclosed in an embodiment of this application. Figure 3 As shown, the device may include: Initialization unit 11 is used to determine the number n mailboxes allocated to the current message group, where n is an integer greater than 1; the current message group includes multiple CAN messages, and the multiple CAN messages have the same CAN channel, communication direction and frame format but different identifier IDs; The grouping execution unit 12 is used to perform multiple grouping processes on each message in the current message group to obtain k candidate grouping schemes; each candidate grouping scheme includes n message subgroups, where k is a pre-set integer greater than 1, and the set of ID bits used in each grouping process is determined according to a preset rule and is different for each one; The group evaluation unit 13 is used to calculate the feature values ​​corresponding to the k candidate grouping schemes based on at least the number of CAN messages carrying each target ID transmitted within a preset time period; the target ID is the ID of the CAN message in the current message group, and the feature value is used to characterize the load balancing degree when the messages in the current message group are distributed to n mailboxes according to the corresponding candidate grouping scheme; and, based on the calculation results, the candidate grouping scheme corresponding to the highest load balancing degree is determined as the final scheme; The group application unit 14 is used to distribute the messages in the current message group to n mailboxes according to the final scheme.

[0078] In one or more embodiments provided in this application, the set of ID bits used when executing any packet processing includes: a pre-set start filter bit to be used in this packet, and x-1 consecutive ID bits located to the left or right of the start filter bit of this packet in the concatenated ID; wherein, x is the minimum number of ID bits required to divide the packets in the current packet group into n subgroups when performing recursive packet processing based on bitmasks according to the start filter bit of this packet and a preset round-robin order.

[0079] In one or more embodiments provided in this application, when the value of k is the ID length carried by the CAN message in the current message group, each starting filter bit used in each grouping process corresponds one-to-one with each ID bit.

[0080] In one or more embodiments provided in this application, the process of the grouping execution unit 12 executing any grouping process may include: Perform multiple rounds of grouping operations on the messages in the current message group until the total number of current message subgroups is equal to n, and determine the current message grouping result as the candidate grouping scheme corresponding to this grouping; Each round of grouping operations includes: Determine the ID filter bit for this round. The ID filter bit for the first round is the starting filter bit for this grouping. The ID filter bits for the remaining rounds are determined by taking the next ID filter bit from the previous round from the IDs after concatenating the first and last IDs, according to the rounding order. A group is selected from the pending message groups in this round as the processing object; wherein, the pending message group in the first round is the current message group, and the pending message groups in the remaining rounds are the message subgroups after the previous round of grouping. Based on the different values ​​of the ID filter bit in the current round of the CAN message ID, the CAN messages in the processing object are divided into two groups, resulting in two message subgroups. If the total number of message subgroups is less than n, remove the processing object from the message groups to be processed in this round, and return to the step of determining a combination from the message groups to be processed in this round as the processing object, until the message groups to be processed in this round are empty, and then execute the next round of grouping operation.

[0081] In one or more embodiments provided in this application, the process by which the group evaluation unit 13 determines the number of CAN messages carrying each target ID transmitted within the preset time period may include: If the current message group contains event messages, the number of each type of event message transmitted within the preset time period is determined to be 1; In the case that the current message group includes a first-cycle message, the number of each type of first-cycle message transmitted within the preset time period is determined to be 1; the first-cycle message is a periodic message satisfying t≥T, where t is the cycle duration of the periodic message, and T is the duration of the preset time period; In the case that the current message group includes a second-cycle message, the number of each type of second-cycle message transmitted within the preset time period is determined to be T / t, where the second-cycle message is a periodic message satisfying t<T.

[0082] In one or more embodiments provided in the present application, the process of calculating, by the grouping evaluation unit 13, the feature value corresponding to any candidate grouping scheme may include: Calculating the sum of the number of CAN messages carrying each target ID transmitted within the preset time period as a total load value; Calculating the average load value of each mailbox allocated to the current message group according to the total load value; After one-to-one pairing the n message subgroups in the current grouping scheme with the n mailboxes allocated to the current message group, respectively calculating the number of CAN messages in each mailbox within the preset time period, as the respective load value of each mailbox allocated to the current message group; Calculating a variance according to the respective load value of each mailbox allocated to the current message group and the average load value, to obtain the feature value corresponding to the current grouping scheme.

[0083] In one or more embodiments provided in the present application, the process of calculating, by the grouping evaluation unit 13, the feature values corresponding to the k candidate grouping schemes at least based on the number of CAN messages carrying each target ID transmitted within the preset time period may include: Respectively calculating the feature values corresponding to the k candidate grouping schemes based on the priority of the CAN message carrying each target ID and the number of CAN messages carrying each target ID transmitted within the preset time period.

[0084] In one or more embodiments provided in the present application, the process of allocating, by the grouping application unit 14, the messages in the current message group to n mailboxes according to the final scheme may include: Generating a mapping table according to the final scheme, so as to store each CAN message in the current message group into the corresponding mailbox according to the mapping table.

[0085] Each unit in the mailbox configuration apparatus for CAN messages may be implemented entirely or partially by software, hardware, or a combination thereof. Each of the above units may be embedded in or independent of the processor in the computer device in the form of hardware, or may be stored in the memory in the computer device in the form of software, so that the processor invokes and executes the operations corresponding to each of the above units.

[0086] The CAN message mailbox configuration device provided in this application embodiment can be applied to CAN message mailbox configuration devices, such as terminals with data processing capabilities: mobile phones, computers, ECUs (Electronic Control Units), VCUs (Vehicle Control Units), MCUs (Micro Controller Units), HCUs (Hybrid Control Units), etc. Optionally, Figure 4 The diagram shows the hardware structure of the CAN message mailbox configuration device. (Refer to...) Figure 4 The hardware structure of the CAN message mailbox configuration device may include: at least one processor 1, at least one communication interface 2, at least one memory 3, and at least one communication bus 4; In this embodiment of the application, the number of processor 1, communication interface 2, memory 3, and communication bus 4 is at least one, and processor 1, communication interface 2, and memory 3 communicate with each other through communication bus 4; Processor 1 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement embodiments of the present invention. Memory 3 may include high-speed RAM, and may also include non-volatile memory, such as at least one disk storage device; The memory stores computer programs, and the processor executes the computer programs to enable the CAN message mailbox configuration device to implement any of the above-described CAN message mailbox configuration methods.

[0087] This application also provides a storage medium that carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any of the CAN message mailbox configuration methods provided in this application.

[0088] This application also provides a computer program product, including computer-readable instructions, which, when executed on an electronic device, enable the electronic device to implement any of the CAN message mailbox configuration methods provided in this application.

[0089] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.

[0090] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The various embodiments can be combined as needed, and the same or similar parts can be referred to each other.

[0091] The above description of the disclosed embodiments enables those skilled in the art to make or use this application. Various modifications to these embodiments will be readily 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 this application. Therefore, this application is not to be limited to the embodiments shown herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A method for configuring a mailbox for CAN messages, characterized in that, include: Determine the number n mailboxes to be allocated to the current message group, where n is an integer greater than 1; the current message group includes multiple CAN messages, and the multiple CAN messages have the same CAN channel, communication direction and frame format but different identifier IDs; The current message group is processed multiple times to obtain k candidate grouping schemes. Each candidate grouping scheme includes n message subgroups, where k is a pre-set integer greater than 1. The set of ID bits used in each grouping process is determined according to a preset rule and is different for each subgroup. Based at least on the number of CAN messages carrying each target ID transmitted within a preset time period, the feature values ​​corresponding to the k candidate grouping schemes are calculated respectively. The target ID is the ID of the CAN message in the current message group, and the feature value is used to characterize the load balancing degree when the messages in the current message group are distributed to n mailboxes according to the corresponding candidate grouping scheme. Based on the calculation results, the candidate grouping scheme corresponding to the highest load balancing degree is determined as the final scheme, and the packets in the current packet group are distributed to n mailboxes according to the final scheme.

2. The mailbox configuration method for CAN messages according to claim 1, characterized in that, The set of ID bits used when executing any packet processing includes: a pre-defined start filter bit to be used in this packet, and x-1 consecutive ID bits located to the left or right of the start filter bit of this packet in the concatenated ID; wherein, x is the minimum number of ID bits required to divide the packets in the current packet into n subgroups when performing recursive packet processing based on bitmasks according to the start filter bit of this packet and a preset round-robin order.

3. The mailbox configuration method for CAN messages according to claim 2, characterized in that, When the value of k is the ID length carried by the CAN message in the current message group, each starting filter bit used in each grouping process corresponds one-to-one with each ID bit.

4. The mailbox configuration method for CAN messages according to claim 3, characterized in that, The execution process of any grouping procedure includes: Perform multiple rounds of grouping operations on the messages in the current message group until the total number of current message subgroups is equal to n, and determine the current message grouping result as the candidate grouping scheme corresponding to this grouping; Each round of grouping operations includes: Determine the ID filter bit for this round. The ID filter bit for the first round is the starting filter bit for this grouping. The ID filter bits for the remaining rounds are determined by taking the next ID filter bit from the previous round from the IDs after concatenating the first and last IDs, according to the rounding order. A group is selected from the pending message groups in this round as the processing object; wherein, the pending message group in the first round is the current message group, and the pending message groups in the remaining rounds are the message subgroups after the previous round of grouping. Based on the different values ​​of the ID filter bit in the current round of the CAN message ID, the CAN messages in the processing object are divided into two groups, resulting in two message subgroups. If the total number of message subgroups is less than n, remove the processing object from the message groups to be processed in this round, and return to the step of determining a combination from the message groups to be processed in this round as the processing object, until the message groups to be processed in this round are empty, and then execute the next round of grouping operation.

5. The method for configuring a mailbox for a CAN message according to any one of claims 1-4, characterized in that, The process of determining the number of CAN messages carrying each target ID transmitted within the preset time period includes: In the case that the current message group includes event messages, the number of each type of event message transmitted within the preset time period is determined to be 1; In the case that the current message group includes first periodic messages, the number of each type of first periodic message transmitted within the preset time period is determined to be 1; the first periodic messages are periodic messages satisfying t≥T, where t is the period duration of the periodic message, and T is the duration of the preset time period; In the case that the current message group includes second periodic messages, the number of each type of second periodic message transmitted within the preset time period is determined to be T / t, and the second periodic messages are periodic messages satisfying t<T.

6. The mailbox configuration method for CAN messages according to claim 5, characterized in that, The calculation process of the feature value corresponding to any candidate grouping scheme includes: Calculating the sum of the number of CAN messages carrying each target ID transmitted within the preset time period as the total load value; Calculating the average load value of each mailbox allocated to the current message group according to the total load value; After one-to-one pairing of the n message subgroups in the current grouping scheme with the n mailboxes allocated to the current message group, calculating the number of CAN messages of each mailbox within the preset time period respectively as the respective load value of each mailbox allocated to the current message group; Calculating the variance according to the respective load value of each mailbox allocated to the current message group and the average load value, to obtain the feature value corresponding to the current grouping scheme.

7. The method for configuring a mailbox for a CAN message according to any one of claims 1-4, characterized in that, Allocating the messages in the current message group to n mailboxes according to the final scheme includes: Generating a mapping table according to the final scheme, so as to store each CAN message in the current message group into the corresponding mailbox according to the mapping table.

8. The method for configuring a mailbox for a CAN message according to any one of claims 1-4, characterized in that, Calculating the feature values corresponding to the k candidate grouping schemes respectively at least based on the number of CAN messages carrying each target ID transmitted within the preset time period includes: Calculating the feature values corresponding to the k candidate grouping schemes respectively based on the priority of the CAN messages carrying each target ID and the number of CAN messages carrying each target ID transmitted within the preset time period.

9. A CAN message mailbox configuration device, characterized in that, Comprising at least one processor and a memory connected to the processor, wherein: The memory is configured to store a computer program; The processor is configured to execute the computer program, so that the mailbox configuration apparatus for CAN messages can implement the mailbox configuration method for CAN messages according to any one of claims 1 to 8.

10. A computer program product, characterized in that, Comprising computer-readable instructions, which when run on an electronic device, enable the electronic device to implement the mailbox configuration method for CAN messages according to any one of claims 1 to 8.