CAN message merging uniformity optimization method and system

By sorting the results of the previous round of mergers during the CAN message merging process, priority is given to the group containing many elements, the problem of uneven packets in the prior art is solved, and communication efficiency and MCU processing speed of messages are improved.

CN120223648APending Publication Date: 2025-06-27BEIJING JINGWEI HIRAIN TECH CO INC
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510238792.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-28
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

The existing CAN message merging method causes uneven packets of packets, resulting in too many packets merged in a mailbox, affecting communication efficiency and MCU processing speed.

Method used

Before each merge, the results of the previous round of merges are sorted according to the number of elements in the group, and groups containing many elements are preferred, so as to avoid the problem that the smaller the packet ID, the sparse the merger, and the larger the packet ID, the more concentrated the merger.

Benefits of technology

It improves the uniformity of packets, avoids the problem of excessive number of packets merged in a mailbox, which is conducive to improving communication efficiency and thus improving the MCU's processing speed of packets.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120223648A_ABST
    Figure CN120223648A_ABST
Patent Text Reader

Abstract

The invention discloses a CAN message merging uniformity optimization method and system, and relates to the technical field of automotive electronics, and the method comprises the steps: storing message information to a first array and a second array; calculating the number of mailboxes allocated to the messages in the first array and the second array; sequentially carrying out AND on each message ID and the mask in the current array, and splitting the current array into two groups according to an AND result; subtracting 1 from the mailbox number of the message corresponding to the current array; judging whether the mailbox number of the message corresponding to the current array is 0 or not, and if not, shifting the mask value rightwards by one bit to serve as a new mask; and sequentially carrying out AND on each message ID in the operation array and the new mask, splitting the operation array into two groups according to the AND result, and subtracting 1 from the mailbox number of the message corresponding to the current array. According to the method, the group containing multiple elements is preferentially processed during each time of merging, so that the problems that the smaller the message ID is, the sparser the merging is, the larger the message ID is, and the more concentrated the merging is are avoided, and the uniformity of message grouping is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of automotive electronics technology, and more particularly, to a method and system for optimizing the uniformity of CAN message merging. Background Art

[0002] Since the number of mailboxes in the CAN (Controller Area Network) module of an automotive MCU (Microcontroller Unit) is often less than the number of messages to be received, if message merging is not performed, the MCU will not be able to fully receive all CAN communication messages. Therefore, multiple messages must be merged so that multiple message data can be received by one mailbox.

[0003] Existing CAN message merging methods generally read and parse the.dbc document to the corresponding message IDs. First, all messages are sorted according to the ID size, and then the ID is ANDed with a mask whose initial value is 0x10000000. Grouping is performed according to whether the result is 1 or 0. Then, the mask is shifted 1 bit to the right, and all IDs are ANDed with the mask again, and grouping is performed according to the result. The above operation is repeated, and the mask is shifted to the right and ANDed with all IDs in turn until the number of groups is equal to the number of mailboxes, and all message merging is completed.

[0004] In the existing message merging method, the message IDs are first arranged in ascending order. When grouping, messages with smaller ID values are preferentially grouped. Therefore, messages with smaller IDs have a greater probability of occupying a mailbox alone, that is, the first allocated mailbox has sparser merged messages, and the later allocated mailbox has more merged messages. When the number of groups is equal to the number of mailboxes, all the remaining messages will be merged into the last mailbox. Therefore, the higher the ID value, the greater the probability that multiple messages will be merged together. This operation will result in uneven message grouping, with too many messages merged into one mailbox, which will affect the message reception efficiency during communication and reduce the processing speed of the MCU for messages. Summary of the Invention

[0005] The present invention provides a method and system for optimizing the uniformity of CAN message merging to overcome at least one technical problem existing in the prior art.

[0006] On the one hand, an embodiment of the present invention provides a method for optimizing the uniformity of CAN message merging, including:

[0007] Extracting message information from the DBC file, where the message information at least includes message IDs;

[0008] Splitting the message information into two groups and storing them in a first array and a second array respectively;

[0009] Calculate the number of mailboxes assigned to the messages in the first array and the number of mailboxes assigned to the messages in the second array;

[0010] Sort the message information in the first array and the second array in ascending order according to the message ID;

[0011] Select the first array as the current array;

[0012] Set the mask value to 0x10000000;

[0013] Successively AND each message ID in the current array with the mask, and split the current array into two groups according to the AND result to obtain two first-level arrays, and use the first-level arrays as alternative arrays;

[0014] Decrease the number of mailboxes corresponding to the messages in the current array by 1;

[0015] Judge whether the number of mailboxes corresponding to the messages in the current array is 0. If it is 0, judge whether the current array is the second array. If it is the second array, it means that the grouping of both groups of messages is completed, and output the grouped message arrays as an excel table file; if it is not the second array, select the second array as the current array and return to the step of setting the mask value to 0x10000000; if it is not 0, shift the mask value one bit to the right to obtain a new mask;

[0016] Select the one with the largest number of message IDs included from the alternative arrays as the operation array;

[0017] Successively AND each message ID in the operation array with the new mask, and split the operation array into two groups according to the AND result to obtain two secondary arrays, and decrease the number of mailboxes corresponding to the messages in the current array by 1;

[0018] Judge whether all the arrays in the alternative arrays have been operated. If not, select the one with the largest number of message IDs included from the remaining arrays as the operation array and return to the step of successively AND each message ID in the operation array with the new mask; if so, use all the secondary arrays as the alternative arrays and return to the step of judging whether the number of mailboxes corresponding to the messages in the current array is 0;

[0019] Optionally, the message information further includes the message transfer direction;

[0020] Split the message information into two groups, specifically:

[0021] Split the message information into sent messages and received messages according to the message transfer direction;

[0022] Save the sent messages to the first array as the sent message array; save the received messages to the second array as the received message array.

[0023] Optionally, calculate the number of mailboxes assigned to the messages in the first array and the number of mailboxes assigned to the messages in the second array, specifically as follows:

[0024] Obtain the total number of mailboxes BoxNum, the total number of messages SumMessageNum, and the number of received messages RxMessageNum;

[0025] According to the total number of mailboxes BoxNum, the total number of messages SumMessageNum, and the number of received messages RxMessageNum, calculate that the number of mailboxes for received messages is RxNum = BoxNum * RxMessageNum / SumMessageNum;

[0026] According to the total number of mailboxes BoxNum and the number of mailboxes for received messages RxNum, calculate that the number of mailboxes for sent messages is TxNum = BoxNum – RxNum.

[0027] Optionally, split the current array into two groups according to the AND result, specifically as follows:

[0028] Judge whether the result of AND operation between the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if it is not 0, store the message information corresponding to the current message ID in another new array.

[0029] Optionally, split the operation array into two groups according to the AND result, specifically as follows:

[0030] Judge whether the result of AND operation between the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if it is not 0, store the message information corresponding to the current message ID in another new array.

[0031] On the other hand, the present invention also provides a CAN message merging uniformity optimization system, including:

[0032] An extraction module, configured to extract message information from a DBC file, where the message information at least includes a message ID and a message transfer direction;

[0033] A storage module, configured to split the message information into two groups and store them in a first array and a second array respectively;

[0034] A calculation module, configured to calculate the number of mailboxes assigned to the messages in the first array and the number of mailboxes assigned to the messages in the second array;

[0035] A sorting module, configured to sort the message information in the first array and the second array in ascending order according to the message ID;

[0036] The first selection module is used to select the first array as the current array;

[0037] The setting module is used to set the mask value to 0x10000000;

[0038] The first splitting module is used to successively AND each message ID in the current array with the mask, split the current array into two groups according to the AND result to obtain two first-level arrays, and use the first-level arrays as alternative arrays;

[0039] The decrement module is used to decrement the number of mailboxes corresponding to the messages in the current array by 1;

[0040] The first judgment module is used to judge whether the number of mailboxes corresponding to the messages in the current array is 0. If it is 0, judge whether the current array is the second array. If it is the second array, it means that the grouping of both groups of messages is completed, and the received message array and the sent message array obtained by grouping are output as an excel table file; if it is not the second array, select the second array as the current array and return to the step of setting the mask value to 0x10000000; if it is not 0, shift the mask value one bit to the right as the new mask;

[0041] The second selection module is used to select the one with the largest number of message IDs included from the alternative arrays as the operation array;

[0042] The second splitting module is used to successively AND each message ID in the operation array with the new mask, split the operation array into two groups according to the AND result to obtain two secondary arrays, and decrement the number of mailboxes corresponding to the messages in the current array by 1;

[0043] The second judgment module is used to judge whether all the arrays in the alternative arrays have been operated. If not, select the one with the largest number of message IDs included from the remaining arrays as the operation array and return to the step of successively ANDing each message ID in the operation array with the new mask; if so, use all the secondary arrays as alternative arrays and return to the step of judging whether the number of mailboxes corresponding to the messages in the current array is 0.

[0044] Optionally, the message information further includes the message transfer direction;

[0045] The saving module is specifically used for:

[0046] Split the message information into sent messages and received messages according to the message transfer direction;

[0047] Save the sent messages to the first array as the sent message array; save the received messages to the second array as the received message array.

[0048] Optionally, the calculation module is specifically used for:

[0049] Obtain the total number of mailboxes BoxNum, the total number of messages SumMessageNum, and the number of received messages RxMessageNum;

[0050] Based on the total number of mailboxes BoxNum, the total number of messages SumMessageNum, and the number of received messages RxMessageNum, calculate that the number of mailboxes for received messages is RxNum = BoxNum * RxMessageNum / SumMessageNum;

[0051] Based on the total number of mailboxes BoxNum and the number of mailboxes for received messages RxNum, calculate that the number of mailboxes for sent messages is TxNum = BoxNum – RxNum.

[0052] Optionally, the first splitting module is specifically configured to:

[0053] Determine whether the result of the bitwise AND operation between the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if it is not 0, store the message information corresponding to the current message ID in another new array.

[0054] Optionally, the second splitting module is specifically configured to:

[0055] Determine whether the result of the bitwise AND operation between the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if it is not 0, store the message information corresponding to the current message ID in another new array.

[0056] The innovation points of the embodiments of the present invention include:

[0057] In this embodiment, before each merge, the results of the previous merge are sorted according to the number of elements in the group, and the group with more elements is processed first, so as to avoid the problem that the smaller the message ID, the sparser the merge, and the larger the message ID, the more concentrated the merge, improve the uniformity of message grouping, avoid the problem that the number of messages merged into one mailbox is too large, which is beneficial to improving communication efficiency, and further improve the processing speed of the MCU for messages, which is one of the innovation points of the embodiments of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0059] Figure 1A flowchart of the CAN message merging uniformity optimization method provided by an embodiment of the present invention;

[0060] Figure 2 A schematic structural diagram of the CAN message merging uniformity optimization system provided by an embodiment of the present invention. Specific embodiments

[0061] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0062] It should be noted that the terms "include" and "have" and any variations thereof in the embodiments of the present invention and the accompanying drawings are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products, or devices.

[0063] The embodiments of the present invention disclose a CAN message merging uniformity optimization method and system. The following will be described in detail respectively.

[0064] Figure 1 A flowchart of the CAN message merging uniformity optimization method provided by an embodiment of the present invention, please refer to Figure 1 , the CAN message merging uniformity optimization method provided by the embodiments of the present invention includes:

[0065] Step 1: Extract the message information in the DBC file, and the message information includes at least the message ID;

[0066] Step 2: Split the message information into two groups and save them to the first array and the second array respectively;

[0067] Step 3: Calculate the number of mailboxes allocated to the messages in the first array and the number of mailboxes allocated to the messages in the second array;

[0068] Step 4: Sort the message information in the first array and the second array in ascending order according to the message ID;

[0069] Step 5: Select the first array as the current array;

[0070] Step 6: Set the mask value to 0x10000000;

[0071] Step 7: AND each message ID in the current array with the mask in turn, split the current array into two groups according to the AND result to obtain two first-level arrays, and use the first-level arrays as alternative arrays;

[0072] Step 8: Decrease the number of mailboxes corresponding to the messages in the current array by 1;

[0073] Step 9: Determine whether the number of mailboxes corresponding to the messages in the current array is 0. If it is 0, determine whether the current array is the second array. If it is the second array, it means that the grouping of both groups of messages is completed, and output the grouped message arrays as an excel spreadsheet file; if it is not the second array, select the second array as the current array and return to the step of setting the mask value to 0x10000000; if it is not 0, shift the mask value one bit to the right to be the new mask;

[0074] Step 10: Select the one with the largest number of message IDs included from the alternative arrays as the operation array;

[0075] Step 11: AND each message ID in the operation array with the new mask in turn, split the operation array into two groups according to the AND result to obtain two secondary arrays, and decrease the number of mailboxes corresponding to the messages in the current array by 1;

[0076] Step 12: Determine whether all arrays in the alternative arrays have been operated. If not, select the one with the largest number of message IDs included from the remaining arrays as the operation array and return to the step of ANDing each message ID in the operation array with the new mask in turn; if so, use all the secondary arrays as the alternative arrays and return to the step of determining whether the number of mailboxes corresponding to the messages in the current array is 0.

[0077] Specifically, please refer to Figure 1 , in the CAN message merging uniformity optimization method provided by the embodiment of the present invention, in step 1, the message information in the DBC file is extracted by reading line by line. Usually, the DBC file contains all message information, such as message signals, message names, message IDs, message transfer directions, etc.

[0078] After extracting the message information, in step 2, the message information is saved in two groups to the first array and the second array. In this embodiment, the message information is grouped according to the message transfer direction. For example, all the transmitted messages are divided into one group, and all the received messages are divided into one group. The transmitted messages are saved to the first array as the transmitted message array; the received messages are saved to the second array as the received message array.

[0079] After grouping is completed, in step 3, according to the grouping result, calculate the number of mailboxes that can be allocated to the transmitted message and the received message. Assume that the maximum number of mailboxes that the MCU itself can provide, that is, the total number of mailboxes is BoxNum, the total number of messages is SumMessageNum, and the number of received messages is RxMessageNum. Then, according to the total number of mailboxes BoxNum, the total number of messages SumMessageNum, and the number of received messages RxMessageNum, the number of mailboxes for received messages can be calculated as RxNum = BoxNum * RxMessageNum / SumMessageNum. Then, according to the total number of mailboxes BoxNum and the number of mailboxes for received messages RxNum, the number of mailboxes for transmitted messages can be calculated as TxNum = BoxNum – RxNum.

[0080] In step 4, sort the message information in the first array and the second array respectively. In the present invention, sort the message information in ascending order of the message ID.

[0081] After sorting is completed, merge the messages in the first array and the second array respectively. In the present invention, first merge the messages in the first array. Therefore, select the first array as the current array through step 5.

[0082] In the present invention, messages are merged by performing a bitwise AND operation between the message ID and the mask. Therefore, set the mask through step 6 and assign an initial value of 0x10000000 to the mask. After setting the mask, in step 7, according to the sorting of each message ID in the current array, perform a bitwise AND operation between each message ID in the current array and the mask in sequence, and split the current array into two groups according to the AND result to obtain two first-level arrays.

[0083] When grouping the message information in the current array, group according to whether the result of the bitwise AND operation between the message ID and the mask is 0 or 1. For example, if the result of the bitwise AND operation between the message ID and the mask is 0, store the message information corresponding to the message ID in a new array. Conversely, if the result of the bitwise AND operation between the message ID and the mask is not 0, store the message information corresponding to the message ID in another new array.

[0084] When all the messages in the current array have been grouped, it means that the merge judgment for this bit is completed. At this time, the two newly created new arrays are two first-level arrays. Use the first-level arrays as alternative arrays to facilitate further message merging for the messages in the two first-level arrays obtained by merging at this level to adapt to the number of message mailboxes allocated to the current array.

[0085] The number of mailboxes for receiving messages is the maximum number of groups into which the received messages can be merged, and the number of mailboxes for sending messages is the maximum number of groups into which the sent messages can be merged. Since the current array is divided into two first-level arrays, when the number of arrays increases by one, the corresponding number of groupable quantities decreases by one. Therefore, in step 8, the number of mailboxes corresponding to the messages in the current array is decreased by 1. For example, if the current array is the first array, that is, the sending message array, then at this time, the number of mailboxes for sending messages, TxNum, is decreased by 1.

[0086] When the number of mailboxes is decreased to 0, it means that the merging of the messages in the current array is completed. Therefore, after the number of mailboxes is decreased by 1, it is necessary to determine in step 9 whether the number of mailboxes corresponding to the messages in the current array is 0, so as to determine whether the message merging is completed.

[0087] For example, when the number of mailboxes corresponding to the messages in the current array is not 0, it indicates that the obtained alternative array can be further merged. When merging the alternative array, the mask value needs to be shifted one bit to the right to serve as a new mask to achieve the merging of the next bit.

[0088] When merging the messages in the alternative array, all alternative arrays need to be processed on the new mask bit. To improve the uniformity of message grouping, in step 10 of the present invention, according to the number of elements in the array, the alternative array obtained from the previous round of merging is sorted, and the one with the largest number of message IDs included in the alternative array is selected as the operating array, and the array with more elements is preferentially processed, so as to avoid the problem that the smaller the message ID, the sparser the merging, and the larger the message ID, the more concentrated the merging.

[0089] After obtaining the operating array, in step 11, according to the sorting of each message ID in the operating array, each message ID in the operating array is successively ANDed with the new mask, and the operating array is split into two groups according to the ANDing result to obtain two secondary arrays.

[0090] When grouping the message information in the operating array, grouping is performed according to whether the result of ANDing the message ID with the mask is 0 or 1. For example, if the result of ANDing the message ID with the mask is 0, the message information corresponding to the message ID is stored in a new array. Conversely, if the result of ANDing the message ID with the mask is not 0, the message information corresponding to the message ID is stored in another new array.

[0091] When all the messages in the operating array are grouped, it means that the merging judgment of the currently selected alternative array is completed, and the two newly obtained arrays are the two secondary arrays. At this time, the number of arrays increases by one, and the corresponding number of groupable quantities decreases by one. Therefore, the number of mailboxes corresponding to the messages in the current array is decreased by 1 again.

[0092] After each alternative array is processed, it is necessary to determine whether there are still unprocessed alternative arrays. The present invention determines whether all alternative arrays have been operated through step 12. When there are unprocessed alternative arrays, one of the unprocessed alternative arrays that contains the largest number of message IDs is selected as the operating array. After selecting the new operating array, return to step 11 and repeat the above steps to complete the message merging of the current operating array.

[0093] When there are no unprocessed alternative arrays, it indicates that all the alternative arrays obtained from the previous round of merging have been processed. At this time, all the secondary arrays obtained from this round of merging are used as alternative arrays, and then return to step 9 to determine whether the number of mailboxes corresponding to the messages in the current array is 0, so as to determine whether the message merging in the current array is completed.

[0094] If the number of mailboxes corresponding to the messages in the current array is 0, it means that the message merging in the current array is completed. At this time, it is necessary to determine whether the message merging of the first array and the second array is completed. Since the present invention processes the first array first, if the current array is the second array, it means that the message merging of the first array and the second array is completed. Therefore, here, by determining whether the current array is the second array, it is determined whether the message merging of the first array and the second array is completed.

[0095] If the current array is the second array, it means that the message merging of both groups is completed, and the merged message array is output as an excel spreadsheet file. On the contrary, if the current array is not the second array, it means that the message merging of the first array is completed, but the message merging of the second array is not completed. At this time, the second array is selected as the current array, and then return to step 6, set the mask value to 0x10000000, and repeat the above steps to complete the message merging of the second array.

[0096] The CAN message merging uniformity optimization method provided by the present invention sorts the results of the previous round of merging according to the number of elements in the group before each merging, and preferentially processes the group with more elements, so as to avoid the problem that the smaller the message ID, the sparser the merging, and the larger the message ID, the more concentrated the merging, improve the uniformity of message grouping, avoid the problem that the number of messages merged into one mailbox is too large, which is beneficial to improving the communication efficiency, and further improve the processing speed of the MCU for messages.

[0097] Based on the same inventive concept, the present invention also provides a CAN message merging uniformity optimization system Figure 2 For a structural schematic diagram of the CAN message merging uniformity optimization system provided by an embodiment of the present invention, please refer to Figure 2 The CAN message merging uniformity optimization system 100 provided by the present invention includes:

[0098] An extraction module for extracting message information from a DBC file, where the message information includes at least a message ID and a message transfer direction;

[0099] A saving module for splitting the message information into two groups and saving them to a first array and a second array respectively;

[0100] A calculation module for calculating the number of mailboxes allocated to the messages in the first array and the number of mailboxes of the messages in the second array;

[0101] A sorting module for sorting the message information in the first array and the second array in ascending order according to the message ID;

[0102] A first selection module for selecting the first array as the current array;

[0103] A setting module for setting the mask value to 0x10000000;

[0104] A first splitting module for successively ANDing each message ID in the current array with the mask, splitting the current array into two groups according to the AND result to obtain two first-level arrays, and using the first-level arrays as alternative arrays;

[0105] A decrement module for decrementing the number of mailboxes corresponding to the messages in the current array by 1;

[0106] A first judgment module for judging whether the number of mailboxes corresponding to the messages in the current array is 0. If it is 0, judge whether the current array is the second array. If it is the second array, it means that the grouping of both groups of messages is completed, and the received message array and the sent message array obtained by grouping are output as an excel table file; if it is not the second array, select the second array as the current array and return to the step of setting the mask value to 0x10000000; if it is not 0, shift the mask value one bit to the right as the new mask;

[0107] A second selection module for selecting the one with the largest number of message IDs included from the alternative arrays as the operation array;

[0108] A second splitting module for successively ANDing each message ID in the operation array with the new mask, splitting the operation array into two groups according to the AND result to obtain two secondary arrays, and decrementing the number of mailboxes corresponding to the messages in the current array by 1;

[0109] A second judgment module for judging whether all arrays in the alternative arrays have been operated. If not, select the one with the largest number of message IDs included from the remaining arrays as the operation array and return to the step of successively ANDing each message ID in the operation array with the new mask; if so, use all the secondary arrays as the alternative arrays and return to the step of judging whether the number of mailboxes corresponding to the messages in the current array is 0.

[0110] Specifically, please refer to Figure 2 For the CAN message merging uniformity optimization system 100 provided by the embodiment of the present invention, the extraction module extracts the message information in the DBC file by reading line by line. Usually, the DBC file contains all message information, such as message signals, message names, message IDs, message transfer directions, etc.

[0111] After extracting the message information, the storage module stores the message information in two groups into the first array and the second array. In this embodiment, the message information is grouped according to the message transfer direction. For example, all transmitted messages are grouped into one group, and all received messages are grouped into one group. By storing the transmitted messages into the first array as the transmitted message array; and storing the received messages into the second array as the received message array.

[0112] After grouping, the calculation module calculates the number of mailboxes that can be allocated to the transmitted messages and the received messages according to the grouping results. Assume that the maximum number of mailboxes that the MCU itself can provide, that is, the total number of mailboxes is BoxNum, the total number of messages is SumMessageNum, and the number of received messages is RxMessageNum. Then, according to the total number of mailboxes BoxNum, the total number of messages SumMessageNum, and the number of received messages RxMessageNum, the number of mailboxes for received messages can be calculated as RxNum = BoxNum * RxMessageNum / SumMessageNum. Then, according to the total number of mailboxes BoxNum and the number of mailboxes for received messages RxNum, the number of mailboxes for transmitted messages can be calculated as TxNum = BoxNum - RxNum.

[0113] The sorting module sorts the message information in the first array and the second array respectively. In the present invention, the message information is sorted in ascending order of the message ID.

[0114] After sorting, the messages in the first array and the second array are merged respectively. In the present invention, the messages in the first array are merged first. Therefore, the first selection module selects the first array as the current array.

[0115] In the present invention, the messages are merged by performing a bitwise AND operation between the message ID and the mask. Therefore, the mask is set by the setting module and given an initial value of 0x10000000. After setting the mask, the first splitting module sequentially performs a bitwise AND operation between each message ID in the current array and the mask according to the sorting of the message IDs in the current array, and splits the current array into two groups according to the AND result, obtaining two first-level arrays.

[0116] When grouping the message information in the current array, group it according to whether the result of the bitwise AND operation between the message ID and the mask is 0 or 1. For example, if the result of the bitwise AND operation between the message ID and the mask is 0, store the message information corresponding to the message ID in a new array. Conversely, if the result of the bitwise AND operation between the message ID and the mask is not 0, store the message information corresponding to the message ID in another new array.

[0117] When all the messages in the current array have been grouped, it means that the merging judgment for this bit is completed. At this time, the two newly created arrays are two first-level arrays. Use the first-level arrays as candidate arrays to facilitate further message merging for the messages in the two first-level arrays obtained by merging at this level, so as to adapt to the number of message mailboxes allocated to the current array.

[0118] The number of mailboxes for receiving messages is the maximum number of groups that the received messages can be merged into, and the number of mailboxes for sending messages is the maximum number of groups that the sent messages can be merged into. Since the current array is divided into two first-level arrays, when the number of arrays increases by one, the corresponding number of groupable quantities decreases by one. Therefore, the decrement module subtracts 1 from the number of mailboxes for the messages corresponding to the current array. For example, if the current array is the first array, that is, the sending message array, then at this time, subtract 1 from the number of mailboxes for sending messages, TxNum.

[0119] When the number of mailboxes is reduced to 0, it means that the message merging for the current array is completed. Therefore, after subtracting 1 from the number of mailboxes, it is necessary to use the first judgment module to determine whether the number of mailboxes for the messages corresponding to the current array is 0, so as to determine whether the message merging is completed.

[0120] For example, when the number of mailboxes for the messages corresponding to the current array is not 0, it indicates that the obtained candidate arrays can be further merged. When merging the candidate arrays, it is necessary to shift the mask value one bit to the right as the new mask to achieve the merging of the next bit.

[0121] When merging the messages in the candidate arrays, it is necessary to process all candidate arrays on the new mask bit. To improve the uniformity of message grouping, the second selection module sorts the candidate arrays obtained from the previous round of merging according to the number of elements in the array, and selects the one with the largest number of message IDs included in the candidate arrays as the operating array, and gives priority to processing the array with more elements, so as to avoid the problem that the smaller the message ID, the sparser the merging, and the larger the message ID, the more concentrated the merging.

[0122] After obtaining the operating array, the second splitting module sequentially performs a bitwise AND operation between each message ID in the operating array and the new mask according to the sorting of each message ID in the operating array, and splits the operating array into two groups according to the AND result to obtain two secondary arrays.

[0123] When grouping the message information in the operation array, it is grouped according to whether the result of the AND operation between the message ID and the mask is 0 or 1. For example, if the result of the AND operation between the message ID and the mask is 0, the message information corresponding to the message ID is stored in a new array. Conversely, if the result of the AND operation between the message ID and the mask is not 0, the message information corresponding to the message ID is stored in another new array.

[0124] When all the messages in the operation array are grouped, it means that the merging judgment of the selected alternative array is completed. At this time, two new arrays are newly obtained, which are two secondary arrays. At this time, the number of arrays increases by one, and the corresponding number of groupable quantities decreases by one. Therefore, the number of mailboxes corresponding to the messages in the current array is decreased by 1 again.

[0125] After each alternative array is processed, it is necessary to determine whether there are still unprocessed alternative arrays. The present invention determines whether all alternative arrays have been operated through the second judgment module. When there are unprocessed alternative arrays, select the one with the largest number of message IDs included from all unprocessed alternative arrays as the operation array. After selecting the new operation array, return and perform the AND operation between each message ID in the operation array and the new mask in sequence, and repeat the above steps to complete the message merging of the current operation array.

[0126] When there are no unprocessed alternative arrays, it indicates that all the alternative arrays obtained from the previous round of merging have been processed. At this time, all the secondary arrays obtained from this round of merging are used as alternative arrays, and then return to determine whether the number of mailboxes corresponding to the messages in the current array is 0, so as to determine whether the message merging in the current array is completed.

[0127] If the number of mailboxes corresponding to the messages in the current array is 0, it means that the message merging in the current array is completed. At this time, it is necessary to determine whether the message merging of the first array and the second array is completed. Since the present invention processes the first array first, if the current array is the second array, it means that the message merging of the first array and the second array is completed. Therefore, here, it is determined whether the current array is the second array to determine whether the message merging of the first array and the second array is completed.

[0128] If the current array is the second array, it means that the message merging of both groups is completed, and the merged message array is output as an excel table file. Conversely, if the current array is not the second array, it means that the message merging of the first array is completed, but the message merging of the second array is not completed. At this time, select the second array as the current array, and then return to set the mask value to 0x10000000 and repeat the above steps to complete the message merging of the second array.

[0129] The CAN message merging uniformity optimization system provided by the present invention sorts the results of the previous round of merging according to the number of elements in each group before each merging, and preferentially processes the groups with more elements, so as to avoid the problem that the smaller the message ID, the sparser the merging, and the larger the message ID, the more concentrated the merging, improve the uniformity of message grouping, avoid the problem that the number of messages merged into one mailbox is too large, which is beneficial to improving the communication efficiency, and further improve the processing speed of the MCU for messages.

[0130] Those of ordinary skill in the art can understand that the drawings are only schematic diagrams of an embodiment, and the modules or processes in the drawings are not necessarily essential for implementing the present invention.

[0131] Those of ordinary skill in the art can understand that the modules in the device in the embodiment can be distributed in the device of the embodiment according to the description of the embodiment, or can be correspondingly changed and located in one or more devices different from the present embodiment. The modules in the above embodiments can be combined into one module, or further split into multiple sub-modules.

[0132] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims

1. A method for optimizing CAN message merging uniformity, characterized in that: include: Extracting message information from the DBC file, wherein the message information at least includes a message ID; Splitting the message information into two groups, and saving them into a first array and a second array respectively; Calculate the number of mailboxes allocated to the messages in the first array and the number of mailboxes allocated to the messages in the second array; Sort the message information in the first array and the second array in ascending order according to the message ID; Select the first array as the current array; Set the mask value to 0x10000000; Sequentially AND each message ID and mask in the current array, split the current array into two groups according to the AND result, obtain two first-level arrays, and use the first-level arrays as candidate arrays; Subtract 1 from the number of mailboxes corresponding to the message in the current array; Determine whether the number of mailboxes corresponding to the message in the current array is 0. If it is 0, determine whether the current array is the second array. If it is the second array, it means that both groups of messages have been grouped, and the message array obtained by grouping is output as an Excel spreadsheet file; if it is not the second array, select the second array as the current array, and return to the step of setting the mask value to 0x10000000; if it is not 0, shift the mask value right by one bit as the new mask; Selecting the one containing the largest number of message IDs from the candidate arrays as the operation array; Sequentially AND each message ID in the operation array with the new mask, split the operation array into two groups according to the AND result, obtain two secondary arrays, and reduce the number of mailboxes corresponding to the message in the current array by 1; Determine whether all arrays in the candidate array have been operated. If not, select the one with the largest number of message IDs from the remaining arrays as the operation array, and return to the step of ANDing each message ID in the operation array with the new mask in turn; if so, use all secondary arrays as candidate arrays, and return to the step of determining whether the number of mailboxes corresponding to the message in the current array is 0.

2. The CAN message merging uniformity optimization method according to claim 1, characterized in that: The message information also includes a message transmission direction; The message information is divided into two groups, specifically: According to the message transmission direction, the message information is split into a sending message and a receiving message; The sent message is saved in the first array as a sent message array; and the received message is saved in the second array as a received message array.

3. The CAN message merging uniformity optimization method according to claim 2 is characterized in that: Calculate the number of mailboxes assigned to the messages in the first array and the number of mailboxes assigned to the messages in the second array, specifically: Get the total number of mailboxes BoxNum, the total number of messages SumMessageNum and the number of received messages RxMessageNum; According to the total number of mailboxes BoxNum, the total number of messages SumMessageNum and the number of received messages RxMessageNum, the number of mailboxes receiving messages is calculated as RxNum = BoxNum*RxMessageNum / SumMessageNum; According to the total number of mailboxes BoxNum and the number of mailboxes for receiving messages RxNum, the number of mailboxes for sending messages is calculated as TxNum = BoxNum – RxNum.

4. The CAN message merging uniformity optimization method according to claim 1, characterized in that: The current array is split into two groups according to the AND result, specifically: Determine whether the result of the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if not 0, store the message information corresponding to the current message ID in another new array.

5. The CAN message merging uniformity optimization method according to claim 1, characterized in that: The operation array is split into two groups according to the AND result, specifically: Determine whether the result of the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if not 0, store the message information corresponding to the current message ID in another new array.

6. A CAN message merging uniformity optimization system, characterized in that: include: An extraction module, used to extract message information from the DBC file, wherein the message information at least includes a message ID and a message transmission direction; A storage module, used for splitting the message information into two groups, and storing them in a first array and a second array respectively; A calculation module, used to calculate the number of mailboxes allocated to the messages in the first array and the number of mailboxes allocated to the messages in the second array; A sorting module, used to sort the message information in the first array and the second array in ascending order according to the message ID; A first selection module, used for selecting a first array as a current array; Setting module, used to set the mask value to 0x10000000; A first splitting module is used to perform AND operations on each message ID and mask in the current array in turn, split the current array into two groups according to the AND operation results, obtain two first-level arrays, and use the first-level arrays as candidate arrays; The decrement module is used to reduce the number of mailboxes corresponding to the message in the current array by 1; The first judgment module is used to judge whether the number of mailboxes corresponding to the message of the current array is 0. If it is 0, it is judged whether the current array is the second array. If it is the second array, it means that both groups of messages have been grouped, and the received message array and the sent message array obtained by grouping are output as an Excel spreadsheet file; if it is not the second array, the second array is selected as the current array, and the step of setting the mask value to 0x10000000 is returned; if it is not 0, the mask value is shifted right by one bit as a new mask; A second selection module is used to select one containing the largest number of message IDs from the candidate array as an operation array; The second splitting module is used to perform AND operations on each message ID in the operation array and the new mask in turn, split the operation array into two groups according to the AND operation results, obtain two secondary arrays, and reduce the number of mailboxes corresponding to the message in the current array by 1; The second judgment module is used to judge whether all arrays in the candidate array have been operated. If not, the one containing the largest number of message IDs is selected from the remaining arrays as the operation array, and the step of ANDing each message ID in the operation array with the new mask is returned in turn; if so, all secondary arrays are used as candidate arrays, and the step of judging whether the number of mailboxes corresponding to the message in the current array is 0 is returned.

7. The CAN message merging uniformity optimization system according to claim 6, characterized in that: The message information also includes a message transmission direction; The storage module is specifically used for: According to the message transmission direction, the message information is split into a sending message and a receiving message; The sent message is saved in the first array as a sent message array; and the received message is saved in the second array as a received message array.

8. The CAN message merging uniformity optimization system according to claim 7, characterized in that: The computing module is specifically used for: Get the total number of mailboxes BoxNum, the total number of messages SumMessageNum and the number of received messages RxMessageNum; According to the total number of mailboxes BoxNum, the total number of messages SumMessageNum and the number of received messages RxMessageNum, the number of mailboxes receiving messages is calculated as RxNum = BoxNum*RxMessageNum / SumMessageNum; According to the total number of mailboxes BoxNum and the number of mailboxes for receiving messages RxNum, the number of mailboxes for sending messages is calculated as TxNum = BoxNum – RxNum.

9. The method for optimizing CAN message merging uniformity according to claim 6, characterized in that: The first splitting module is specifically used for: Determine whether the result of the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if not 0, store the message information corresponding to the current message ID in another new array.

10. The method for optimizing CAN message merging uniformity according to claim 6, characterized in that: The second splitting module is specifically used for: Determine whether the result of the message ID and the mask is 0. If it is 0, store the message information corresponding to the current message ID in a new array; if not 0, store the message information corresponding to the current message ID in another new array.