A CAN decoding code generation method and decoding method based on encoding detection and protocol metadata, and a computing device.

By constructing a standardized message model and static bit mapping, the byte order consistency problem in DBC file parsing is solved, ensuring accurate differentiation and security of CAN messages, and making it suitable for CAN decoding in the field of intelligent driving technology.

CN123123466APending Publication Date: 2026-11-17BEIJING YUNCHI FUTURE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611356404.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-03
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

Existing tools are prone to inconsistencies between logical and physical bits when parsing DBC files, especially when processing across Intel/Motorola byte order. Classic CAN and CAN FD messages may be incorrectly merged, and generators changing the descriptor order may disrupt consumers' reliance on the common enumeration order and indexes, leading to compatibility and security issues.

Method used

By using a method based on code probing and protocol metadata, a standardized message model is constructed, a static bit mapping is established from the logical bits of the signal to the physical payload bits, a complete frame identity is constructed using the channel, CAN identifier, and extended frame flag, an appropriate code generation contract is selected, C code is generated, and strict verification is performed at runtime to ensure the accuracy and compatibility of signal extraction.

Benefits of technology

It reduces source code bit order errors generated when parsing DBC files, improves the accuracy and security of protocol differentiation, reduces the risk of version evolution, and is suitable for resource-constrained embedded operating environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123123466A_ABST
    Figure CN123123466A_ABST
Patent Text Reader

Abstract

This invention provides a CAN decoding code generation method, decoding method, and computing device based on encoding probing and protocol metadata. The method includes: receiving a DBC database file and project configuration; constructing a standardized message model based on the DBC database file; for the signal of a selected message, establishing a static bit mapping from the logical bits of the signal to the physical payload bits through encoding probing based on the protocol facts corresponding to the selected message in the standardized message model; constructing a complete frame identity for the selected message based on the protocol facts in the standardized message model, and mapping the actual payload length of the message to the original data length code; selecting a corresponding code generation contract according to the protocol type of the selected message, and generating C code based on the code generation contract. According to the technical solution of this invention, it is possible to reduce bit order errors in the source code generated when parsing DBC files, improve the accuracy of protocol differentiation, enhance the security of protocol runtime, improve compatibility, and reduce version evolution risks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent driving technology, specifically to a CAN decoding code generation method and decoding method and computing device based on encoding detection and protocol metadata. Background Technology

[0002] DBC files typically describe messages, signals, signal lengths, byte order, scaling factors, offsets, frame identifiers, and message lengths in a CAN network. Existing tools can parse DBCs and generate source code, but when processing across Intel / Motorola byte orders, relying on manually written bit order formulas can easily lead to inconsistencies between logical and physical bits in cross-byte signals.

[0003] Classic CAN and CAN FD cannot be distinguished solely by payload length. CAN FD messages can have 8-byte payloads, and there is a non-linear mapping between the Raw Data Length Code (DLC) 9 to 15 and the actual payload length. If only the channel, CAN identifier, and extended frame flag are used for identification during runtime, classic CAN and CAN FD messages may be incorrectly merged.

[0004] Furthermore, when the generator changes the order of common descriptors to improve descriptor query efficiency, it may break existing consumers' dependencies on the common enumeration order and indexes. Changes in the signal definition of the same frame identity in the definition metadata record (manifest) of historical messages may also cause incompatibility with silent structures.

[0005] Therefore, a technical solution is needed that can reduce the bit order errors in the source code generated when parsing DBC files, improve the accuracy of protocol differentiation, enhance the security of protocol runtime, improve compatibility, and reduce the risk of version evolution. Summary of the Invention

[0006] This invention aims to provide a CAN decoding code generation method, decoding method, and computing device based on encoding detection and protocol metadata. It can reduce the bit order errors in the source code generated when parsing DBC files, improve the accuracy of protocol differentiation, enhance the security of protocol runtime, improve compatibility, and reduce the risk of version evolution.

[0007] According to one aspect of the present invention, a method for generating CAN decoding codes based on encoding detection and protocol metadata is provided, the method comprising:

[0008] Receive DBC database file and project configuration, and construct a standardized message model based on the DBC database file, wherein the DBC database file defines messages, signals, signal length, byte order, scaling factor, offset and frame identifier in the CAN network;

[0009] For the selected message signal, based on the protocol facts corresponding to the selected message in the normalized message model, a static bit mapping from the logical bits of the signal to the physical payload bits is established through encoding detection;

[0010] Based on the protocol facts in the normalized message model, the complete frame identity of the selected message is constructed, and the actual payload length of the selected message is mapped to the original data length code.

[0011] Select the corresponding code generation contract based on the protocol type of the selected message, and generate C code based on the selected code generation contract.

[0012] According to some embodiments, the normalized message model includes signal mapping, signal type, scaling parameters, DBC payload length, raw data length code, CAN identifier, extended frame flag, and FD flag fields.

[0013] According to some embodiments, establishing a static bit mapping from the logic bits of the signal to the physical payload bits through encoding detection includes:

[0014] For a signal with N logic bits, set other signals in the same message to their original zero values;

[0015] For each logical bit index i, the unsigned signal uses a left shift of i bits to construct the probe value, while the signed signal uses a negative binary two's complement boundary to construct the probe value when i is the highest sign bit.

[0016] With physical quantity scaling disabled, the DBC message encoder is invoked to encode the probed value;

[0017] The encoded probe value is scanned byte by byte and bit by bit, and exactly one physical bit is required to be set, thereby establishing a mapping from the logical bit to the physical payload bit.

[0018] According to some embodiments, based on the protocol facts in the normalized message model, a complete frame identity for the selected message is constructed, and the actual payload length of the selected message is mapped to the original data length code, including:

[0019] The complete frame identity of the selected message is constituted using the channel, CAN identifier, extended frame flag, and FD flag, and messages with duplicate complete frame identities are rejected.

[0020] The actual payload length is mapped to the original data length code according to the classic CAN and CAN FD protocol rules.

[0021] According to some embodiments, the actual payload length is mapped to the original data length code according to the classic CAN and CAN FD protocol rules, including:

[0022] For classic CAN, the actual payload length of 0 to 8 bytes is directly mapped to the raw data length code of 0 to 8 bytes;

[0023] For CAN FD, the actual payload lengths of 12 bytes, 16 bytes, 20 bytes, 24 bytes, 32 bytes, 48 ​​bytes, and 64 bytes are mapped to raw data length codes of 9 to 15 bytes, respectively.

[0024] If the actual payload length cannot be represented by the original data length code mapping rules of classic CAN or CAN FD, then the code for the corresponding message will be rejected and will not be rounded to the adjacent length.

[0025] According to some embodiments, a corresponding code generation contract is selected based on the protocol type of the selected message, and C code is generated based on the selected code generation contract, including:

[0026] When all selected messages are classic CAN, select the first compatible contract;

[0027] When the set of selected messages contains any CAN FD, select the second capability contract;

[0028] Specifically, when running the second capability contract, precise verification is performed: empty records and CAN records with out-of-bounds lengths are rejected in sequence; the channel is compared with the CAN identifier, the extended frame flag is compared with the FD flag, and the original data length code is compared with the actual payload length; after all verifications pass, signal extraction according to the static bit mapping is allowed.

[0029] According to some embodiments, the method further includes:

[0030] Maintain the model order in the common descriptor array;

[0031] Generate a common index sorted lexicographically by channel, CAN identifier, extended frame flag, and FD flag, with the original common index serving as the deterministic arbitration node;

[0032] The common index arrangement is stored as a read-only static array, and an iterative half-open interval binary search without dynamic allocation is performed on the common index arrangement to locate the descriptor.

[0033] According to some embodiments, the method further includes:

[0034] Calculate the definition hash of the selected message based on the selected message;

[0035] The defined hash is compared with the defined hash of the same complete frame identity in the defined metadata record of the message to prevent silent reuse of incompatible signal structures under the same complete frame identity.

[0036] According to another aspect of the present invention, a CAN decoding method based on encoding detection and protocol metadata is provided, the decoding method comprising:

[0037] Retrieve CAN records containing channel information, CAN identifier, flag bits, raw data length code, actual payload length, and payload data;

[0038] Based on the complete frame identity of each message in the normalized message model, locate the message descriptor corresponding to the current CAN record on the common descriptor array;

[0039] After locating the corresponding message descriptor, the current CAN record is verified. Once the verification is successful, the signal extraction path is entered.

[0040] The load data is subjected to bit-by-bit and / or byte-by-byte shifting and masking operations according to the physical payload bit order to extract the original integer value of each signal;

[0041] Perform sign extension on the original integer value, and apply a scaling factor and offset to perform physical quantity conversion on the original integer value to obtain the signal physical value;

[0042] The physical value of the signal is encapsulated into message data encoded as IPC and transmitted by an external communication module.

[0043] According to another aspect of the present invention, a computing device is provided, comprising:

[0044] Processor; and

[0045] A memory that stores a computer program, which, when executed by the processor, implements the method as described in any of the preceding methods.

[0046] According to an embodiment of the present invention, a normalized message model is constructed based on a DBC database file. For the signal of a selected message, a static bit mapping from the logical bits of the signal to the physical payload bits is established through encoding probing based on the protocol facts corresponding to the selected message in the normalized message model. Then, based on the protocol facts in the normalized message model, the complete frame identity of the message is constructed, and the actual payload length of the message is mapped to the original data length code. The bit mapping in this scheme comes from the actual semantics of the DBC encoder, which can reduce the risk of errors in handwritten formulas for cross-byte signals and reduce bit order errors in the source code generated when parsing DBC files. A corresponding code generation contract is selected according to the protocol type of the message, and C code is generated based on the selected code generation contract. This invention can improve the accuracy of protocol differentiation, enhance the security of protocol runtime, improve compatibility, and reduce the risk of version evolution.

[0047] According to the embodiments, the use of a common descriptor array and binary search to replace the traditional linear traversal matching can significantly reduce the frame matching time in high message throughput scenarios, making it suitable for embedded operation scenarios.

[0048] According to the embodiment, the mapping relationship is determined at compile time / initialization. At runtime, the shift / masking is performed directly according to the pre-calculated positions. Compared with dynamically parsing signal bits based on DBC files or manually hard-coded bit operations, this method explicitly operates according to bit order (rather than simply by byte), making the processing path for cross-byte signals clear. On the one hand, there is zero parsing overhead at runtime; on the other hand, for cross-byte signals, bit-by-bit operations on the physical payload bit order ensure the correctness of the bit order. Therefore, efficient signal extraction can be achieved on resource-constrained MCUs.

[0049] According to an embodiment, the physical value of the signal is encapsulated as message data encoded as IPC and transmitted by an external communication module. The IPC data format includes a known flag mask, and any unknown flags exceeding the known flag mask are rejected before the payload data is published. This prevents maliciously crafted CAN frames from entering the application layer, enables automotive network security at the decoding layer, and prevents anomalous data from contaminating the IPC channel, thereby protecting all subscribers.

[0050] It should be understood that the above general description and the following detailed description are merely exemplary and do not limit the invention. Attached Figure Description

[0051] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below.

[0052] Figure 1 A schematic diagram of the overall architecture for generation and operation according to an example embodiment is shown.

[0053] Figure 2 A flowchart illustrating a method for code generation based on encoding detection and protocol metadata according to an example embodiment is shown.

[0054] Figure 3 A schematic diagram of the coded probe signal bit mapping according to an example embodiment is shown.

[0055] Figure 4 This diagram illustrates protocol-aware contract routing according to an example embodiment.

[0056] Figure 5 A schematic diagram illustrating runtime verification and extraction of the second capability protocol according to an example embodiment is shown.

[0057] Figure 6 This diagram illustrates a descriptor lookup that maintains a common order according to an example embodiment.

[0058] Figure 7 A block diagram of a computing device according to an exemplary embodiment is shown. Detailed Implementation

[0059] Exemplary embodiments will now be described more fully with reference to the accompanying drawings. However, these exemplary embodiments can be implemented in many forms and should not be construed as limited to the embodiments set forth herein; rather, they are provided so that the invention will be thorough and complete, and the concept of the exemplary embodiments will be fully conveyed to those skilled in the art. The same reference numerals in the drawings denote the same or similar parts, and therefore repeated descriptions of them will be omitted.

[0060] Furthermore, the described features, structures, or characteristics can be combined in any suitable manner in one or more embodiments. Numerous specific details are provided in the following description to give a full understanding of embodiments of the invention. However, those skilled in the art will recognize that the technical solutions of the invention can be practiced without one or more of the specific details, or other methods, components, apparatuses, steps, etc., can be employed. In other instances, well-known methods, apparatuses, implementations, or operations are not shown or described in detail to avoid obscuring various aspects of the invention.

[0061] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.

[0062] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily have to be performed in the described order. For example, some operations / steps can be broken down, while others can be combined or partially combined; therefore, the actual execution order may change depending on the specific circumstances.

[0063] It should be understood that although the terms first, second, third, etc., may be used herein to describe various components, these components should not be limited by these terms. These terms are used to distinguish one component from another. Therefore, the first component discussed below may be referred to as the second component without departing from the teachings of the present invention. As used herein, the term "and / or" includes all combinations of any one and more of the associated listed items.

[0064] Those skilled in the art will understand that the accompanying drawings are merely schematic diagrams of exemplary embodiments, and the modules or processes in the drawings are not necessarily essential for implementing the present invention, and therefore cannot be used to limit the scope of protection of the present invention.

[0065] DBC files are typically used to describe information such as messages, signals, signal length, byte order, scaling factor, offset, frame identifier, and message length in a CAN network. Existing tools can parse DBC files and generate corresponding source code, but when dealing with cross-Intel and Motorola byte orders, relying on manually written bit order formulas can easily lead to inconsistencies between logical and physical bits in cross-byte signals, resulting in signal parsing errors.

[0066] Classic CAN and CAN FD cannot be distinguished solely by payload length. CAN FD messages can also have 8-byte payloads, and there is a non-linear mapping between the original data length code 9 to 15 and the actual payload length. If only the channel, CAN identifier, and extended frame flag are used as message identifiers during runtime, classic CAN and CAN FD messages may be incorrectly merged and processed.

[0067] In addition, when the generator changes the order of common descriptors to improve descriptor query efficiency, it may break the existing consumer's dependence on the common enumeration order and index; if the signal definition of the same frame identity in the historical manifest changes, it may also cause silent structural incompatibility.

[0068] To address this, the present invention proposes a CAN decoding code generation and decoding method based on encoding detection and protocol metadata. This method can reduce bit order errors in the source code generated when parsing DBC files, improve the accuracy of protocol differentiation, enhance the security of protocol runtime, improve compatibility, and reduce the risk of version evolution.

[0069] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention.

[0070] Figure 1 A schematic diagram of the overall architecture for generation and operation according to an example embodiment is shown.

[0071] See Figure 1 , Figure 1 This illustrates the relationship between DBC input, project selection, host-side model building, code detection, contract routing, C code generation, and target-side runtime verification. The entire architecture is divided into three core phases from top to bottom: protocol input and project selection, host-side model building and code generation, and target-side runtime decoding and output.

[0072] In some implementations, protocol input and project selection serve as the starting point of the entire process, responsible for collecting all necessary configuration and definition information. The inputs to protocol input and project selection include: a DBC database, providing basic definitions of messages, signals, byte order, scaling factors, etc., in the CAN network; project configuration, defining which channels, messages, and signals the current project needs to process; a protocol catalog, containing metadata for CAN / CAN FD, used to differentiate protocol types later; and channel / message / signal selection, which is the specific filtering logic that determines the scope of entities ultimately participating in code generation. The output of protocol input and project selection is filtered and integrated configuration data, directly driving the next stage of model building.

[0073] The host-side model building and code generation are the core processing stages, responsible for transforming static configuration into executable C code. It standardizes the message model, converting DBC and project configuration into a unified internal model to resolve format differences between data sources. Reverse shifting and DBC encoding probing are performed to analyze the signal bit layout and establish a mapping relationship between logical signals and physical bits, preparing for static bit mapping. Based on the message protocol type (classic CAN or CAN FD), the corresponding code generation contract is selected to ensure that the generated code can correctly handle the Raw Data Length Code (DLC) rules and payload lengths of different protocols. Based on the above model and contract, the final C code, including static bit mapping, typed decoding functions, descriptors, and a manifest, is generated. Hash definitions and compatibility definition metadata records (manifests) are defined for compatibility comparisons during the generation stage, ensuring that the data received by the target side completely matches the code generated by the host side.

[0074] The target-side decoding and output stage is the final execution phase, responsible for real-time processing of CAN data on the embedded controller. During runtime, the process of sequentially checking identity, format, DLC, length, and boundaries before signal extraction is recorded. Utilizing the complete frame identity comprised of "channel + frame identifier (CAN ID) + extended frame flag + FD flag," the system quickly locates and verifies the validity of the current frame, rejecting duplicate or undefined messages, completing a four-element identity binary search. Strict checks are performed on DLC, length, and boundaries to prevent out-of-bounds access or data errors. Based on the static bit mapping generated on the host side, signal values ​​are directly extracted from the original payload, and converted into physical quantities using scaling factors and offsets, ultimately outputting to the upper-layer application.

[0075] This invention uses the DBC authoritative encoder as the source of bit layout facts, and generates a mapping from logical bits to physical payload bits by probing each logical bit individually, avoiding the need to manually write byte order formulas. It uses the channel, CAN identifier, extended frame flag, and FD flag together as the complete frame identity, preventing classic CAN and CAN FD messages from being merged due to identical three-field identities.

[0076] Figure 2 A flowchart illustrating a method for code generation based on encoding detection and protocol metadata according to an example embodiment is shown.

[0077] See Figure 2 In S201, the DBC database file and project configuration are received, and a standardized message model is constructed based on the DBC database file, wherein the DBC database file defines the message, signal, signal length, byte order, scaling factor, offset and frame identifier in the CAN network.

[0078] According to some embodiments, the normalized message model includes signal mapping, signal type, scaling parameters, DBC payload length, raw data length code, CAN identifier, extended frame flag, and FD flag fields.

[0079] According to some embodiments, one or more DBC data files are received, which define the basic metadata of the CAN network. A JSON project configuration is also received, which defines the list of logical channels to be processed in the current project, the message whitelist, and the specific signal selection strategy.

[0080] Specifically, the system reads a standard DBC database file and extracts the defined CAN network metadata, including message name, CAN ID, signal name, signal start bit in the message, signal length (bit width), byte order (Intel / Motorola), physical value scaling factor, and offset. Simultaneously, it receives the project configuration file, which defines the list of logical channels to be processed in the current project, the message whitelist, and the specific signal selection strategy. The original definitions in the DBC are then merged with the project configuration, filtering out unselected messages and signals and retaining only valid data.

[0081] According to some implementations, data from different sources is uniformly transformed into an internally standardized "normalized message model". During this process, the protocol attributes of each selected message (whether it's classic CAN or CAN FD) are defined, and a standardized data structure is prepared for subsequent steps, ensuring that subsequent processing does not depend on specific DBC tool formats.

[0082] In S203, for the signal of the selected message, based on the protocol facts corresponding to the selected message in the normalized message model, a static bit mapping from the logical bits of the signal to the physical payload bits is established by encoding detection.

[0083] According to some embodiments, for a signal with N logical bits, other signals in the same message are set to their original zero values. For each logical bit index i, an unsigned signal is constructed by left-shifting i bits to obtain a probe value, while a signed signal is constructed using a negative two's complement boundary when i is the highest sign bit. With physical scaling disabled, the DBC message encoder is invoked to encode the probe value, scanning the encoded probe value byte by byte and bit by bit, ensuring that exactly one physical bit is set, thereby establishing a mapping from the logical bits to the physical payload bits.

[0084] According to some implementations, for a signal with N logical bits, other signals in the same message are first set to their original zero values. For logical bit index i, an unsigned signal is left-shifted by i bits; if the signal is signed and i is the highest sign bit, a negative two's complement boundary is used. Subsequently, with physical scaling disabled and the current strict semantics preserved, the DBC message encode function is called. The generator scans the resulting payload byte by byte and bit by bit, requiring exactly one bit to be set.

[0085] Specifically, based on the standardized model generated by S201, protocol fact analysis is performed on each selected message to confirm its frame type (standard frame / extended frame), protocol type (classic CAN / CAN FD), and specific DLC (Data Length Code) definition. Encoding probing is performed on each signal within the message, calculating its specific bit position in the 8-byte (classic CAN) or 64-byte (CAN FD) physical payload array based on the signal's start bit, length, and byte order. Finally, a static mapping is generated based on the above analysis results; this is a compile-time determined lookup table that describes how to accurately extract the original values ​​of each logical signal from the raw physical payload byte stream through bit shifting and masking operations, thereby avoiding runtime dynamic parsing and improving decoding efficiency.

[0086] Figure 3 A schematic diagram of the coded probe signal bit mapping according to an example embodiment is shown.

[0087] See Figure 3 , Figure 3 The detailed logic for the physical location of the reverse probe signal is shown, which resolves the issue of potential inconsistencies between the DBC definition and the actual binary layout.

[0088] According to some implementations, a target signal is first selected from the message, and processing begins according to its logical bit index. A specific raw probe value is constructed, physical scaling is disabled (i.e., the raw integer value is used directly), and a standard DBC encoder is invoked to encode it. After encoding, the generated payload is scanned to find which physical bit the probe value appears on. If the probe value appears exactly once in the payload, the location is successful, and the "logical bit → physical bit" correspondence is recorded. If it appears multiple times or cannot be found, it indicates ambiguity or error, code generation is rejected, and a DBC semantic error is reported. The above process is repeated for all logical bits in the message, and finally, all verified mapping relationships are solidified into a static C mapping array for direct lookup at runtime.

[0089] In S205, based on the protocol facts in the normalized message model, the complete frame identity of the selected message is constructed, and the actual payload length of the selected message is mapped to the original data length code.

[0090] According to some embodiments, the complete frame identity of the selected message is constituted using the channel, CAN identifier, extended frame flag, and FD flag, and messages with duplicate complete frame identities are rejected. The actual payload length is mapped to the original data length code according to the classic CAN and CAN FD protocol rules.

[0091] According to some embodiments, for classic CAN, the actual payload length of 0 to 8 bytes is directly mapped to the original data length code of 0 to 8 bytes. For CAN FD, 9 to 15 bytes of the original data length code are mapped to actual payload lengths of 12, 16, 20, 24, 32, 48, and 64 bytes, respectively. If the actual payload length cannot be represented by the data length code mapping rules of classic CAN or CAN FD, the code for the corresponding message is rejected, and the length is not rounded to the nearest integer. Contract routing is driven by DBC protocol facts and model capabilities, not by project name, payload length, or runtime observations.

[0092] Specifically, in multi-channel, hybrid protocol networks, to uniquely identify a message frame, the system constructs a "complete frame identity" using information from the normalized model. This identity is a quadruple consisting of the logical channel number, CAN identifier (CAN ID), extended frame flag (0 or 1), and FD flag (0 or 1), serving as the unique index key for the message at runtime. Based on this, the message length information is further processed. Addressing the non-linear relationship between the DLC value and the actual payload length in the CAN FD protocol (e.g., DLC=9 corresponds to 12 bytes), the actual physical payload length of the message (e.g., 12, 16, 20…64 bytes) is mapped back to the standard Raw Data Length Code (DLC) to ensure correct configuration of the receive buffer and verification logic during the code generation phase.

[0093] In S207, a corresponding code generation contract is selected according to the protocol type of the selected message, and C code is generated based on the selected code generation contract.

[0094] According to some embodiments, when all the selected messages are classic CAN, the first compatible contract (V1 contract) is selected, and when the selected messages are CAN FD, the second capability contract (V2 contract) is selected.

[0095] Specifically, the process begins with contract routing. Based on the message protocol type, the corresponding code generation contract is automatically selected. For classic CAN, a contract template adapting to 8-byte payloads and standard DLC rules is chosen; for CAN FD, a contract template adapting to 64-byte payloads and non-linear DLC mapping is selected. Next, the C code generation stage begins. Based on the selected contract template, static bit mapping, complete frame identity, and signal scaling parameters (factor / offset) are filled into the code template. The final output is a C language code file containing a descriptor, a manifest defining metadata record, decoding functions, and an IPC interface. The descriptor contains a structure containing the complete frame identity and DLC information; the manifest is used for compatibility comparison during the generation stage, rejecting the release of the generated product if inconsistencies are found; the decoding functions perform static bit extraction and physical value conversion; and the IPC interface defines the interface structure for how the decoded data is passed to the application layer.

[0096] Figure 4 This diagram illustrates protocol-aware contract routing according to an example embodiment.

[0097] See Figure 4 , Figure 4 A code generation contract routing mechanism based on protocol type is shown to ensure that the generated C code can correctly handle different versions of the CAN protocol.

[0098] Extract message attributes from the normalized model, particularly the `message.is_fd` flag and the complete identity tuple including channel, ID, and extended frame flags. Check if the current generation unit (i.e., the set of messages being processed) contains CAN FD messages. If so, route to the right branch and select the V2 CAN FD capability contract. The V2 contract supports large payloads of up to 64 bytes and integrates the mapping logic from the original DLC to the actual length, as well as a complete identity and boundary verification mechanism. If only classic CAN messages are contained, route to the left branch and select the V1 classic CAN contract. The V1 contract is strictly limited to 8-byte payloads, has an entry compatibility layer, and explicitly rejects any frames with the FD flag to ensure compatibility with traditional protocols. Finally, depending on the selected contract version, the generator will use different memory layouts, verification logic, and decoding strategies to generate the final C code.

[0099] According to some embodiments, precise verification is performed when running the second capability contract: empty records and CAN records of out-of-bounds length are rejected sequentially; the channel is compared with the CAN identifier; the extended frame flag is compared with the FD flag; and the original DLC is compared with the actual payload length. After all verifications pass, signal extraction according to the static bit mapping is permitted.

[0100] The V2 contract (FD capability contract) uses a vendor-free `can_record_t`, which includes the channel, CAN ID, flags, original DLC, actual payload length, and payload. For each message, a verification adapter with fixed expected parameters is generated. It sequentially rejects empty records and out-of-bounds lengths, compares the channel with the CAN ID, compares the Extended Frame Flags (EXT) with the FD flags, and precisely compares the original DLC with the actual payload length. Only after all comparisons pass is extraction by mapping allowed.

[0101] Figure 5 A schematic diagram illustrating runtime verification and extraction of the second capability protocol according to an example embodiment is shown.

[0102] See Figure 5The process begins with receiving `can_record_t` data and performs four layers of rigorous checks sequentially. First, basic field checks are performed, checking the channel, CAN ID, Extended Frame (EXT), and FD flag. Next, DLC mapping checks are performed to verify that the original DLC matches the expected protocol. Then, a length check is performed to confirm the actual payload length is valid. Finally, pointer safety checks are performed to check the payload pointer and its access boundaries to prevent out-of-bounds errors. If any of these checks fails, the process immediately jumps to a typed failure state, explicitly preventing entry into the signal extraction path and ensuring the safety of subsequent processing. Only after all checks pass will the original signal value be extracted according to the static bit mapping, and then sign extension and scaling conversion will be performed sequentially, ultimately encoding and outputting decoded IPC data.

[0103] According to some embodiments, the model order of the common descriptor array is maintained, and a common index arrangement is generated, sorted lexicographically by channel, CAN identifier, extended frame flag, and FD flag. The original common index serves as a deterministic arbitration node. The common index arrangement is saved as a read-only static array, and an iterative half-open interval binary search without dynamic allocation is performed on the common index arrangement to locate the descriptor.

[0104] The common descriptor array maintains the original order of the model. The generator generates a separate permutation containing the index of each common descriptor, sorted lexicographically by the channel, CAN ID, EXT, and FD fields. The original common indexes are only used as deterministic arbitrator nodes (tie-breakers). The permutation is saved as a read-only static array. A private comparator compares the four fields sequentially, and an iterative half-open interval binary search locates the descriptor on the permutation.

[0105] Figure 6 This diagram illustrates a descriptor lookup that maintains a common order according to an example embodiment.

[0106] See Figure 6 , Figure 6 This demonstrates a lookup optimization mechanism that separates data from the index, used to solve the problem of efficiently locating message descriptors at runtime.

[0107] According to some implementations, a common descriptor array is maintained, which strictly adheres to the original order in the normalized model, for example, 0, 1, 2…N-1. This order is typically stable and represents the defined order of messages in the project configuration or DBC file. Based on this, an auxiliary index arrangement is generated during compilation or initialization. This arrangement is not the original order but rather the result of sorting according to the runtime lookup key values ​​(i.e., the complete frame identity composed of channel, CAN ID, EXT, FD), i.e., 2, 0, N-1, 1. When a complete frame identity is received at runtime, the original common array is not traversed; instead, a binary search without dynamic allocation is performed on the auxiliary index arrangement, leveraging its ordered nature for rapid location. Once a match is found, the value stored at that position (i.e., the index of the original common array) is retrieved and returned as the common descriptor index. Through this mechanism, regardless of how the auxiliary index is rearranged to optimize search speed, the final returned index always points to the correct position in the common array, thus ensuring the consistency between the common enumeration order and the index semantics.

[0108] According to some embodiments, the definition hash of the selected message is calculated based on the selected message, and the definition hash is compared with the definition hash of the same complete frame identity in the definition metadata record of the message to prevent silent multiplexing of incompatible signal structures under the same complete frame identity.

[0109] The input for defining the hash consists of two parts: message-level fields and signal-level fields. Message-level fields include message name, channel, bus, CAN ID, extended frame flag, topic, and DBC payload length. Signal-level fields include selected signal name, C field name, C type, bit width, sign, scaling factor, offset, and physical bit mapping. For protocol differentiation, FD messages additionally include the FD facts in addition to the above fields, while classic CAN messages maintain historical hash compatibility and do not introduce additional fields. At the output, the decoded IPC data maintains the CAN protocol version 2 and uses a fixed 40-byte header. Unknown flags are rejected before the payload is published to ensure backward compatibility.

[0110] This invention also provides a CAN decoding method based on code probing and protocol metadata, used for decoding CAN messages during C code execution. The decoding method includes: acquiring a CAN record containing the channel, CAN identifier, flag bits, original data length code, actual payload length, and payload data. Based on the complete frame identity of each message in the normalized message model, locating the message descriptor corresponding to the current CAN record in the common descriptor array. After locating the corresponding message descriptor, performing verification on the current CAN record; if the verification passes, proceeding to the signal extraction path. Performing bit-by-bit and / or byte-by-byte shifting and masking operations on the payload data according to the physical payload bit order to extract the original integer value of each signal. Performing sign extension on the original integer value, and applying a scaling factor and offset to perform physical quantity conversion on the original integer value to obtain the signal physical value. Encapsulating the signal physical value into message data encoded as IPC, which is then transmitted by an external communication module.

[0111] According to some embodiments, based on the complete frame identity of each message in the normalized message model, a binary search is performed on the common index arrangement to locate the corresponding message descriptor in the common descriptor array. After locating the corresponding message descriptor, identity verification, format verification, DLC verification, length verification, and boundary verification are performed sequentially. After all verifications pass, the signal extraction path is entered.

[0112] According to some embodiments, the payload data is shifted and masked bit-by-bit or byte-by-byte according to the physical payload bit order, based on a static bit mapping, to extract the original integer value of each signal. A sign extension is performed on the extracted original integer values, wherein, for signed signals, the value of the highest sign bit is extended and filled into the high bits of the signal width. A scaling factor and offset are applied to the original integer values ​​for physical quantity conversion to obtain the physical value of the signal.

[0113] According to some embodiments, physical values ​​are encapsulated in a predefined IPC data format, wherein the IPC data format uses a fixed-length header and includes a known flag bit mask, and any unknown flag bits exceeding the known flag bit mask are rejected before the payload data is published.

[0114] This invention uses the DBC authoritative encoder as the source of fact for bit layout, generating a mapping from logical bits to physical payload bits through bit-by-bit probing, thus avoiding the need to manually write Intel / Motorola byte order formulas. Simultaneously, the channel, CAN identifier, extended frame flag, and FD flag together constitute a complete frame identity, preventing classic CAN and CAN FD messages from being merged due to identical three-field identities.

[0115] In the generation stage, the present invention strictly implements the mapping rules from DLC to payload length of classic CAN / CAN FD, directly rejects the generation of unrepresentable lengths, and performs contract routing based on model capabilities. It is fully compatible with classic CAN output V1, outputs FD capability V2 when CAN FD is included, and performs precise verification during V2 runtime.

[0116] This invention maintains the order of the public descriptor array while generating a private sorted index and performing a binary search without dynamic allocation, balancing compatibility and query performance. During runtime, before extracting the signal, the identity, format, original DLC, actual payload length, and boundaries are compared; if this fails, a distinguishable state is returned. A deterministic hash is calculated for the publicly defined message and compared with historical manifests to prevent the reuse of incompatible signal structures by the same complete frame identity. The decoded IPC uses a fixed 40-byte V2 header and a known flag mask; the FD capability contract only sets the FD flag for FD messages and rejects unknown flags.

[0117] This invention directly derives the actual semantics of the DBC encoder through bit mapping, uniformly covering the byte order (Intel and Motorola) signal layout, effectively reducing the risk of errors in handwritten formulas for cross-byte signals. Simultaneously, the FD status originates from DBC protocol metadata and runtime explicit flags, avoiding misinterpretation of 8-byte CAN FD messages as classic CAN, thereby improving the accuracy of protocol differentiation.

[0118] Regarding runtime security, the second capability contract (V2 contract) of this invention accurately compares the original DLC with the actual length before signal extraction, and can reject truncated, excessively long, or inconsistently formatted records. In terms of performance and compatibility, the public descriptor order remains stable, query paths are searched through read-only index arrangement, and hot paths do not require dynamic allocation, runtime sorting, or string formatting.

[0119] Furthermore, comparing the defined hash with the historical manifest can detect incompatible structural changes under the same complete frame identity during the generation phase, reducing the risk of version evolution and avoiding silent releases. Finally, the generated C code uses static tables and bounded access methods at runtime, making it suitable for deployment in resource-constrained embedded target environments.

[0120] Figure 7 A block diagram of a computing device according to an exemplary embodiment is shown.

[0121] like Figure 7As shown, the computing device 30 includes a processor 12 and a memory 14. The computing device 30 may also include a bus 22, a network interface card 16, and an I / O interface 18. The processor 12, memory 14, network interface card 16, and I / O interface 18 can communicate with each other via the bus 22.

[0122] Processor 12 may include one or more general-purpose CPUs (Central Processing Units), microprocessors, or application-specific integrated circuits, for executing relevant program instructions. According to some embodiments, computing device 30 may also include a high-performance display adapter (GPU) 20 for accelerating processor 12.

[0123] Memory 14 may include a machine system readable medium in the form of volatile memory, such as random access memory (RAM), read-only memory (ROM), and / or cache memory. Memory 14 is used to store one or more programs containing instructions, as well as data. Processor 12 may read the instructions stored in memory 14 to perform the methods described above according to embodiments of the present invention.

[0124] The computing device 30 can also communicate with one or more networks via a network interface card 16. The network interface card is used for data processing or external communication, and the central processing unit is used for processing data scheduled by the network interface card. The network interface card includes a root system-on-a-chip (SoC) and multiple interfaces, through which the SoC performs data communication. The SoC includes a processor and a memory, on which a computer program is stored. When the processor runs the computer program stored in the memory, it implements the method according to an embodiment of the present invention.

[0125] Bus 22 can include address bus, data bus, control bus, etc. Bus 22 provides a path for exchanging information between components.

[0126] It should be noted that, in specific implementations, the computing device 30 may also include other components necessary for normal operation. Furthermore, those skilled in the art will understand that the device described above may only include the components necessary for implementing the embodiments of this specification, and not necessarily all the components shown in the figures.

[0127] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the above-described method. The computer-readable storage medium may include, but is not limited to, any type of disk, including floppy disks, optical disks, DVDs, CD-ROMs, microdrives, as well as magneto-optical disks, ROMs, RAMs, EPROMs, EEPROMs, DRAMs, VRAMs, flash memory devices, magnetic cards or optical cards, nanosystems (including molecular memory ICs), network storage devices, cloud storage devices, or any type of medium or device suitable for storing instructions and / or data.

[0128] This invention also provides a computer program product comprising a computer program operable to cause a computer to perform some or all of the steps of any of the methods described in the above method embodiments.

[0129] Those skilled in the art will clearly understand that the technical solutions of the present invention can be implemented by means of software and / or hardware. In this specification, "unit" and "module" refer to software and / or hardware capable of independently performing or cooperating with other components to perform a specific function, wherein the hardware may be, for example, a field-programmable gate array (FPGA), an integrated circuit, etc.

[0130] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the present invention is not limited to the described order of actions, because according to the present invention, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to the present invention.

[0131] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0132] In the several embodiments provided by this invention, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between devices or units may be electrical or other forms.

[0133] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0134] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0135] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of the present invention.

[0136] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0137] Exemplary embodiments of the present invention have been specifically shown and described above. It should be understood that the present invention is not limited to the detailed structures, arrangements, or implementations described herein; rather, the present invention is intended to cover various modifications and equivalent arrangements contained within the spirit and scope of the appended provisions.

Claims

1. A CAN decoding code generation method based on encoding probes and protocol metadata, characterized by, The method includes: Receive DBC database file and project configuration, and construct a standardized message model based on the DBC database file, wherein the DBC database file defines messages, signals, signal length, byte order, scaling factor, offset and frame identifier in the CAN network; For the selected message signal, based on the protocol facts corresponding to the selected message in the normalized message model, a static bit mapping from the logical bits of the signal to the physical payload bits is established through encoding detection; Based on the protocol facts in the normalized message model, the complete frame identity of the selected message is constructed, and the actual payload length of the selected message is mapped to the original data length code. Select the corresponding code generation contract based on the protocol type of the selected message, and generate C code based on the selected code generation contract.

2. The method of claim 1, wherein, The standardized message model includes signal mapping, signal type, scaling parameters, DBC payload length, raw data length code, CAN identifier, extended frame flag, and FD flag fields.

3. The method of claim 1, wherein, Establishing a static bit mapping from the logic bits of the signal to the physical payload bits through encoding detection includes: For a signal with N logic bits, set other signals in the same message to their original zero values; For each logical bit index i, the unsigned signal uses a left shift of i bits to construct the probe value, while the signed signal uses a negative binary two's complement boundary to construct the probe value when i is the highest sign bit. With physical quantity scaling disabled, the DBC message encoder is invoked to encode the probed value; The encoded probe value is scanned byte by byte and bit by bit, and exactly one physical bit is required to be set, thereby establishing a mapping from the logical bit to the physical payload bit.

4. The method of claim 1, wherein, Based on the protocol facts in the normalized message model, the complete frame identity of the selected message is constructed, and the actual payload length of the selected message is mapped to the original data length code, including: The complete frame identity of the selected message is constituted using the channel, CAN identifier, extended frame flag, and FD flag, and messages with duplicate complete frame identities are rejected. The actual payload length is mapped to the original data length code according to the classic CAN and CAN FD protocol rules.

5. The method of claim 4, wherein, The actual payload length is mapped to the original data length code according to the classic CAN and CAN FD protocol rules, including: For classic CAN, the actual payload length of 0 to 8 bytes is directly mapped to the raw data length code of 0 to 8 bytes; For CAN FD, the actual payload lengths of 12 bytes, 16 bytes, 20 bytes, 24 bytes, 32 bytes, 48 ​​bytes, and 64 bytes are mapped to raw data length codes of 9 to 15 bytes, respectively. If the actual payload length cannot be represented by the original data length code mapping rules of classic CAN or CAN FD, then the code for the corresponding message will be rejected and will not be rounded to the adjacent length.

6. The method of claim 1, wherein, Based on the protocol type of the selected message, a corresponding code generation contract is selected, and C code is generated based on the selected code generation contract, including: When all selected messages are classic CAN, select the first compatible contract; When the set of selected messages contains any CAN FD, select the second capability contract; Specifically, when running the second capability contract, precise verification is performed: empty records and CAN records with out-of-bounds lengths are rejected in sequence; the channel is compared with the CAN identifier, the extended frame flag is compared with the FD flag, and the original data length code is compared with the actual payload length; after all verifications pass, signal extraction according to the static bit mapping is allowed.

7. The method of claim 1, wherein, The method further includes: Maintain the model order in the common descriptor array; Generate a common index sorted lexicographically by channel, CAN identifier, extended frame flag, and FD flag, with the original common index serving as the deterministic arbitration node; The common index arrangement is stored as a read-only static array, and an iterative half-open interval binary search without dynamic allocation is performed on the common index arrangement to locate the descriptor.

8. The method of claim 1, wherein, The method further includes: Calculate the definition hash of the selected message based on the selected message; The defined hash is compared with the defined hash of the same complete frame identity in the defined metadata record of the message to prevent silent reuse of incompatible signal structures under the same complete frame identity.

9. A CAN decoding method based on encoding probes and protocol metadata, characterized in that, The decoding method includes: Retrieve CAN records containing channel information, CAN identifier, flag bits, raw data length code, actual payload length, and payload data; Based on the complete frame identity of each message in the normalized message model, locate the message descriptor corresponding to the current CAN record on the common descriptor array; After locating the corresponding message descriptor, the current CAN record is verified. Once the verification is successful, the signal extraction path is entered. The load data is subjected to bit-by-bit and / or byte-by-byte shifting and masking operations according to the physical payload bit order to extract the original integer value of each signal; Perform sign extension on the original integer value, and apply a scaling factor and offset to perform physical quantity conversion on the original integer value to obtain the signal physical value; The physical value of the signal is encapsulated into message data encoded as IPC and transmitted by an external communication module.

10. A computing device, comprising: processor; as well as A memory storing a computer program that, when executed by the processor, implements the method as described in any one of claims 1-9.