CAN bus management method based on dynamic calibration mechanism
The CAN bus management method using a dynamic calibration mechanism solves the problem of significant software changes caused by controller message communication matrix updates, optimizes CAN data transmission and reduces coupling, and is applicable to various controllers.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-02
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, updating the controller message communication matrix requires significant changes to the underlying and application layer software, resulting in a large workload.
A CAN bus management method based on dynamic calibration mechanism is adopted. By establishing CAN ID mapping and data mapping, CAN data transmission between the underlying layer and the application layer is realized. The application layer defines the mapping relationship between CAN messages and CAN IDs and performs dynamic calibration. The underlying layer finds the location of CAN messages based on the CAN ID index.
It reduces the software development workload caused by changes in communication protocols, lowers the coupling between the underlying and application layers, optimizes the signal transmission process, and is suitable for various controllers.
Smart Images

Figure CN121770922A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of CAN communication technology, specifically to a CAN bus management method based on a dynamic calibration mechanism. Background Technology
[0002] Against the backdrop of the current explosive growth of new energy, there are numerous controllers and a surge in the number of custom messages. Especially in the new energy industry, the IDs and contents of a large number of messages are customized by the manufacturers, and the communication protocols are updated rapidly. Each update of the communication matrix causes changes to the application layer and the underlying code, resulting in significant changes to the underlying and application layer software, which presents a large workload problem. Summary of the Invention
[0003] The purpose of this invention is to provide a CAN bus management method based on a dynamic calibration mechanism, which solves the problem in the prior art where the update of the controller message communication matrix causes changes to the application layer and the underlying code, resulting in a large amount of software workload that requires significant modifications to the underlying and application layers.
[0004] The present invention solves the above problems through the following technical solution:
[0005] A CAN bus management method based on a dynamic calibration mechanism includes:
[0006] Establish a CAN ID mapping based on a dynamic calibration mechanism;
[0007] CAN data mapping is performed based on the CAN ID mapping to realize CAN data transmission between the underlying layer and the application layer.
[0008] Furthermore, the method for establishing CAN ID mapping based on a dynamic calibration mechanism is as follows:
[0009] Map the CAN ID to the storage slot;
[0010] The application layer defines the CAN messages that interact with the underlying layer, establishes the mapping relationship between CAN messages and CAN IDs, and performs dynamic calibration.
[0011] The underlying layer uses the CAN ID index to locate the CAN message position.
[0012] Furthermore, the application layer defines the CAN messages it interacts with the lower layer, establishes the mapping relationship between CAN messages and CAN IDs, and performs dynamic calibration as follows:
[0013] The application layer establishes an array of CAN message structures, which include specific data, CAN ID, period, priority, and online status.
[0014] The application layer defines and initializes the message attributes of the array;
[0015] The application layer dynamically calibrates interface variables, which are used to determine the position of the CAN message in the array and the message attributes.
[0016] Furthermore, the method for CAN data mapping based on the CAN ID mapping is as follows: the underlying layer receives CAN messages and writes the CAN messages into the corresponding array according to the mapping relationship between CAN messages and CAN IDs.
[0017] Furthermore, the underlying layer writes the CAN message into the corresponding array through the CAN message Handle number to achieve CAN data mapping.
[0018] Furthermore, the maximum length of the array is determined by the maximum number of messages that can be driven on the CAN bus.
[0019] Furthermore, the application layer initializes the data members of the CAN message.
[0020] Furthermore, the steps for mapping CAN IDs to storage slots are as follows: using any one of a lightweight hash function, binary search, or group search, map each CAN ID to a storage slot with the same number of CAN IDs.
[0021] Furthermore, the underlying method for locating the CAN message position based on the CAN ID index is as follows:
[0022] The underlying layer establishes transmit and receive array variables, and the underlying function interface implements data interaction with the application layer CAN message data interface.
[0023] A linear search with a time complexity of O(1) is performed for a single CAN message to match the corresponding CAN ID;
[0024] Implement a linear search with time complexity O(2) and space complexity O(1) on all CAN messages.
[0025] Furthermore, the O(1) linear lookup is implemented using a hash index table.
[0026] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0027] (1) This invention realizes the mapping of CAN bus data-lower layer data-application layer data. By calibrating the message ID and period, the dynamic calibration of the message is realized, thereby avoiding the need to make significant changes to the software of the lower layer and application layer, thus reducing the workload.
[0028] (2) When the communication protocol changes, the present invention only needs to mark the message ID and period at the application layer, without modifying the underlying layer, thus saving the workload of software development.
[0029] (3) The present invention solves the mapping process of CAN signal to the bottom layer and then to the application layer software, taking into account the complete transmission process of CAN signal, including the transmission at the bottom layer of software.
[0030] (4) This invention is applicable not only to VCU (vehicle controller) but also to any controller to realize the processing and transmission of CAN signals.
[0031] (5) The present invention can realize unified mapping of multi-channel CAN bus.
[0032] (6) The CAN communication protocol of the whole vehicle software of the present invention defines a fixed length of N bytes of message data for sending and receiving. The underlying function interface realizes the data interaction with the application layer, optimizes the transmission of specific signals of the historical application layer, and the signal parsing is handled by the application layer, avoiding repeated modification and communication between the application layer and the underlying layer, and reducing the coupling between the application layer and the underlying layer. Attached Figure Description
[0033] Figure 1 This is a flowchart of the present invention. Detailed Implementation
[0034] The present invention will be further described in detail below with reference to embodiments, but the implementation of the present invention is not limited thereto.
[0035] Technical terms:
[0036] Dynamic calibration refers to the process of adjusting, modifying, and optimizing the internal parameters of a system (usually a complex embedded system, such as an engine control unit or battery management system) in real time while it is running.
[0037] CAN bus: Controller Area Network, is a serial communication bus standard. It is specifically designed for reliable, real-time, distributed communication between microcontrollers and devices, or in harsh electrical environments where a master unit is not required.
[0038] Message: In the context of CAN bus (and other communication protocols), a message refers to a complete unit of information or data packet transmitted between nodes via the bus. It is the basic unit of communication.
[0039] o(1) / o(2): When describing algorithm complexity, o(1), o(n), o(logn), and o(nlogn) are commonly used to represent the time complexity of the corresponding algorithm, which are representations of the algorithm's time and space complexity. They are not only used to represent time complexity but also space complexity.
[0040] Example 1:
[0041] Combined with appendix Figure 1 As shown, a CAN bus management method based on a dynamic calibration mechanism includes:
[0042] 1. Establish CAN ID mapping based on a dynamic calibration mechanism;
[0043] 1.1 Establish a CAN ID mapping based on a dynamic calibration mechanism, specifically:
[0044] Map CAN IDs to storage slots; use any of the following methods: lightweight hash function, binary search, or group search to map CAN IDs to the same number of storage slots as the number of CAN IDs. For example, map 96 CAN IDs to 96 storage slots, where 96 is the maximum number of messages currently available.
[0045] 1.2 The application layer defines the CAN messages it interacts with the lower layer, establishes the mapping relationship between CAN messages and CAN IDs, and performs dynamic calibration; specifically:
[0046] The application layer establishes an array of CAN message structures, which include specific data, CAN ID, period, priority, and online status. The maximum length of the array is determined by the maximum number of messages that can be driven on the CAN bus.
[0047] The application layer defines and initializes the message attributes of the array; optionally, the application layer can also initialize the data members of the CAN message.
[0048] The application layer dynamically calibrates interface variables, which are used to determine the position of the CAN message in the array and the message attributes.
[0049] The following is an example of the code implementation for the dynamic calibration interface:
[0050] void Update_CAN_Mapping(uint8_t type, uint8_t index, CanMsg_TypeDefconfig) {
[0051] if(type == RX_MAPPING){
[0052] CANRXID[index] = config;
[0053] Setup_Filter(config.ID, index);
[0054] }else{
[0055] CANTXID[index] = config;
[0056] Setup_Mailbox(config.ID, index, TX_MODE);
[0057] }}
[0058] CAN communication is achieved through dynamic management and calibration at the application layer. The application layer determines the specific CAN messages needed, and can add or delete messages for interaction, as well as define message attributes. CAN messages contain period parameters. The application layer defines the message transmission period, and the underlying layer obtains the message attributes through a function interface. Then, the underlying CAN transmission mechanism's timer calculates and matches the transmission period (e.g., a periodic scheduling algorithm based on time remainder) to achieve message transmission at different periods.
[0059] 1.3 The underlying layer uses the CAN ID index for addressing to locate the CAN message position. Specifically:
[0060] The underlying layer establishes transmit and receive array variables, and the underlying function interface implements data interaction with the application layer CAN message data interface.
[0061] A linear search with a time complexity of O(1) is performed for a single CAN message to match the corresponding CAN ID;
[0062] Implement a linear search with time complexity O(2) and space complexity O(1) on all CAN messages.
[0063] Preferably, a hash index table is used to achieve a lookup time complexity of O(1). An example of the code implementation is as follows:
[0064] t_RxMsg_CANpack p_RxMsg_CANpack
[96] ;
[0065] t_TxMsg_CANpack p_TxMsg_CANpack
[96] ;
[0066] void App_RxMsg_IndexToAppLayer_CANpack_FUNC(PduIdType CanPduHandle,Can_IdType CanPduId)
[0067] {
[0068] UINT32 indexMsg;
[0069] UINT32 indexByte;
[0070] for (indexMsg = 0; indexMsg < 96; indexMsg++)
[0071] {
[0072] if (xxxxx[indexMsg].id == CanPduId)
[0073] {
[0074] for (indexByte = 0; indexByte < 8; indexByte++)
[0075] {
[0076] xxxxx[indexMsg].data[indexByte] = p_RxMsg_CANpack[CanPduHandle].InputMsg.DataFld[indexByte];
[0077] }
[0078] break;
[0079] }
[0080] }
[0081] return;
[0082] }
[0083] void App_TxMsg_IndexFromAppLayer_CANpack_FUNC(PduIdType CanPduHandle,Can_IdType CanPduId)
[0084] {
[0085] UINT32 indexMsg;
[0086] UINT32 indexByte;
[0087] for (indexMsg = 0; indexMsg < 96; indexMsg++)
[0088] {
[0089] if (xxxxx[indexMsg].id == CanPduId)
[0090] {
[0091] for (indexByte = 0; indexByte < 8; indexByte++)
[0092] {
[0093] p_TxMsg_CANpack[CanPduHandle].DataFld[indexByte] =xxxxx[indexMsg].data[indexByte];
[0094] }
[0095] break
[0096] }
[0097] }
[0098] return;
[0099] }
[0100] 2. Based on the CAN ID mapping, perform CAN data mapping to realize CAN data transmission between the underlying layer and the application layer.
[0101] The method for CAN data mapping based on the CAN ID mapping is as follows: the underlying layer receives CAN messages and writes the CAN messages into the corresponding array according to the mapping relationship between CAN messages and CAN IDs.
[0102] Furthermore, the underlying layer writes the CAN message into the corresponding array through the CAN message Handle number to achieve CAN data mapping.
[0103] The following is an example of code implementation:
[0104] void App_RxMsg_ToAppLayer_CANpack_FUNC(void)
[0105] {
[0106] UINT32 i;
[0107] App_RxMsg_IndexToAppLayer_CANpack_FUNC(CAN_HANDLE_RX_CAN_NAME,CAN_ID_TX_CAN_NAME);
[0108] return;
[0109] }
[0110] void App_TxMsg_FromAppLayer_CANpack_FUNC(void)
[0111] {
[0112] UINT32 i;
[0113] App_TxMsg_IndexFromAppLayer_CANpack_FUNC(CAN_HANDLE_TX_CAN_NAME,CAN_ID_TX_CAN_NAME);
[0114] return;
[0115] }
[0116] The underlying layer then packages all CAN signals and uses a variable to pass the data within each CAN signal to the application layer according to the byte order, thus achieving CAN data transmission between the underlying and application layers. A message exchange method that masks the bits of the CAN message signals is employed.
[0117] This invention encapsulates CAN data, ID, period, and other attributes into CAN message structures. Each CAN structure has a unique corresponding ID and related data and attributes. The application layer then initializes the vehicle's CAN messages into an independently modifiable CAN message array, ensuring each message is unique within the array. The underlying interface uses a linear search of the message array and matching the CAN ID to achieve message data interaction between the application layer and the underlying layer. Furthermore, the required message data is directly exchanged with the application layer via byte-level communication, shifting CAN message signal processing to the application layer. The underlying layer only manages message reception and transmission. With the vehicle communication network unchanged, the signal and vehicle control logic are entirely determined by the application layer, eliminating the underlying layer's involvement in software modifications. This significantly reduces software development workload and improves development efficiency. The reduced coupling between the underlying and application layers facilitates software maintenance.
[0118] This invention significantly reduces the workload of software development caused by communication protocol changes by enabling both CAN_ID and CAN_signal to be identifiable and by packaging CAN signals. It unifies the packaging of signals received at the lower level and extracts data from the corresponding position based directly on the CAN_ID, thus achieving a hardware abstraction layer and configuration separation architecture.
[0119] Although the present invention has been described herein with reference to illustrative embodiments, the above embodiments are merely preferred embodiments of the present invention, and the implementation of the present invention is not limited to the above embodiments. It should be understood that those skilled in the art can devise many other modifications and implementations, which will fall within the scope and spirit of the principles disclosed in this application.
Claims
1. A CAN bus management method based on a dynamic calibration mechanism, characterized in that, The application relates to a CAN ID mapping method based on a dynamic calibration mechanism. The application relates to a CAN data mapping method based on the CAN ID mapping. The CAN ID mapping method based on the dynamic calibration mechanism comprises the following steps:
2. The CAN bus management method based on dynamic calibration mechanism according to claim 1, characterized in that, mapping the CAN ID to a storage slot; defining CAN messages for interaction between the application layer and the bottom layer, establishing a mapping relationship between the CAN messages and the CAN ID, and performing dynamic calibration; the bottom layer indexes and addresses according to the CAN ID to find the CAN message position. The method for defining CAN messages for interaction between the application layer and the bottom layer, establishing a mapping relationship between the CAN messages and the CAN ID, and performing dynamic calibration comprises the following steps:
3. The CAN bus management method based on dynamic calibration mechanism according to claim 2, characterized in that, the application layer establishes an array of CAN message structures, the CAN message structure comprising specific data, a CAN ID, a period, a priority and an online state; the application layer defines and initializes message properties of the array; the application layer dynamically calibrates interface variables, and the interface variables are used to determine the position of the CAN message in the array and the message properties. The CAN data mapping method based on the CAN ID mapping comprises the following steps: the bottom layer receives the CAN message, and writes the CAN message into a corresponding array according to the mapping relationship between the CAN message and the CAN ID.
4. The CAN bus management method based on dynamic calibration mechanism according to claim 3, characterized in that, The bottom layer writes the CAN message into the corresponding array through a CAN message Handle number, and realizes CAN data mapping.
5. The CAN bus management method based on dynamic calibration mechanism according to claim 4, characterized in that, The maximum length of the array is determined by the maximum number of messages that can be driven on the CAN bus.
6. The CAN bus management method based on dynamic calibration mechanism according to claim 3, characterized in that, The application layer also initializes data members of the CAN message.
7. The CAN bus management method based on dynamic calibration mechanism according to claim 3, characterized in that, The step of mapping the CAN ID to the storage slot comprises the following steps: using any one of a lightweight hash function, a binary search method or a grouping search method to map the CAN ID to the same number of storage slots as the CAN ID.
8. The CAN bus management method based on dynamic calibration mechanism according to claim 2, characterized in that, The method for the bottom layer to index and address according to the CAN ID to find the CAN message position comprises the following steps:
9. The CAN bus management method based on dynamic calibration mechanism according to claim 2, characterized in that, the bottom layer establishes a receiving and transmitting array variable, and realizes data interaction of the application layer CAN message data interface through a bottom layer function interface; linear search with a time complexity of O(1) is completed for a single CAN message to match the corresponding CAN ID; linear search with a time complexity of O(2) and a space complexity of O(1) is realized on all CAN messages. The linear search with the time complexity of O(1) is realized through a hash index table.
10. The CAN bus management method based on dynamic scaling mechanism according to claim 9, characterized in that,