Search

CN-122018890-A - Code generation method, device, equipment and medium for vehicle-mounted CAN (controller area network)

CN122018890ACN 122018890 ACN122018890 ACN 122018890ACN-122018890-A

Abstract

The application discloses a code generation method, a device, equipment and a medium for a vehicle-mounted CAN network, which relate to the technical field of embedded communication and comprise the steps of determining a declarative configuration file which is in a JSON format and is used for defining configuration information of a CAN gateway in a target vehicle, checking the declarative configuration file by utilizing the JSON Schema file to obtain a checking result, analyzing the declarative configuration file and generating a target code by utilizing obtained target data and a preset template engine when the checking result shows that the checking result is passed, filling the target code into an initial C code file to obtain a target C code file suitable for the vehicle-mounted CAN network, and driving a universal gateway firmware to trigger preset processing operation for the CAN message by utilizing the target C code file after the universal gateway firmware of the CAN gateway receives the CAN message. The application CAN design an efficient and reliable code generation scheme for the vehicle-mounted CAN network.

Inventors

  • LI BO

Assignees

  • 杭州麦唐科技有限公司

Dates

Publication Date
20260512
Application Date
20260213

Claims (10)

  1. 1. The code generation method for the vehicle-mounted CAN network is characterized by comprising the following steps of: determining a declarative configuration file of configuration information of a CAN gateway in a target vehicle in a JSON format, and checking the declarative configuration file by using a preset JSON Schema file to obtain a checking result; When the verification result shows that verification is passed, analyzing the declarative configuration file, and generating a target code by utilizing target data obtained through analysis and a preset template engine; And filling the target code into an initial C code file to obtain a target C code file suitable for a vehicle-mounted CAN network, so that after a general gateway firmware of the CAN gateway receives the CAN message, the general gateway firmware is driven by the target C code file to trigger a preset processing operation for the CAN message, and the general gateway firmware is a gateway application program configured with general processing logic for the CAN message.
  2. 2. The code generation method for the vehicle-mounted CAN network according to claim 1, wherein the declarative configuration file includes definition information of a CAN bus of the target vehicle and a CAN message transmitted on the CAN bus, configuration information of a unified diagnostic service, parameter information of a vehicle-mounted intrusion detection system, and cycle code verification information of the CAN message.
  3. 3. The code generation method for an on-vehicle CAN network according to claim 1, wherein the verifying the declarative configuration file by using a preset JSON Schema file to obtain a verification result includes: And correspondingly checking the data structure, the field name, the data type and the numerical range of the declarative configuration file by calling a preset checker and utilizing a preset JSON Schema file to obtain a checking result.
  4. 4. The code generation method for an on-vehicle CAN network according to claim 1, wherein the parsing the declarative configuration file and generating an object code using object data obtained by parsing and a preset template engine includes: Analyzing the declaration configuration file based on a recursion mode through a preset code generation engine to obtain target data; Generating, by the preset code generation engine, target code based on the target data and placeholders in a preset template engine.
  5. 5. The code generation method for an on-vehicle CAN network according to claim 1, wherein the generating the object code by using the parsed object data and the preset template engine includes: Converting the target data obtained through analysis into a nested structure body, converting keys in the target data into member names of members in the nested structure body, and converting values in the target data into initial values of the members; Performing assignment on the global structure variable based on the target data in a static initialization mode to obtain an assigned global structure variable; And generating target codes based on a preset template engine, the nested structure, the initial value and the assigned global structure variable.
  6. 6. The code generation method for an on-vehicle CAN network according to claim 1, wherein the filling the object code into an initial C code file to obtain an object C code file applicable to the on-vehicle CAN network includes: generating a header file containing structure, enumeration and global structure variables, and generating a source file for instantiating and initializing the global structure variables; And determining the header file and the source file as initial C code files, and filling the target codes into the header file and the source file in the initial C code files respectively to obtain target C code files suitable for the vehicle-mounted CAN network.
  7. 7. The code generation method for an on-vehicle CAN network according to any one of claims 1 to 6, wherein after the universal gateway firmware of the CAN gateway receives a CAN message, driving the universal gateway firmware to trigger a preset processing operation for the CAN message by using the target C code file, including: after the universal gateway firmware of the CAN gateway receives the CAN message, invoking an interrupt service routine aiming at the universal gateway firmware; determining message configuration information corresponding to the CAN message from a global structure variable of the target C code file based on the identity information and bus information carried by the CAN message by the universal gateway firmware; And determining a processing rule aiming at the CAN message based on the message configuration information through the universal gateway firmware, and carrying out corresponding processing on the CAN message by utilizing the processing rule.
  8. 8. A code generation device for a vehicle-mounted CAN network, comprising: The file verification module is used for determining a declarative configuration file of the configuration information of the CAN gateway in the target vehicle in the JSON format, and verifying the declarative configuration file by using a preset JSON Schema file to obtain a verification result; The code generation module is used for analyzing the declarative configuration file when the verification result shows that the verification is passed, and generating a target code by utilizing target data obtained through analysis and a preset template engine; and the message processing module is used for filling the target code into an initial C code file to obtain a target C code file suitable for a vehicle-mounted CAN network, so that after the universal gateway firmware of the CAN gateway receives the CAN message, the universal gateway firmware is driven by the target C code file to trigger the preset processing operation for the CAN message, and the universal gateway firmware is a gateway application program configured with universal processing logic for the CAN message.
  9. 9. An electronic device, comprising: A memory for storing a computer program; Processor for executing the computer program for implementing the code generation method for an on-board CAN network according to any one of claims 1 to 7.
  10. 10. A computer-readable storage medium for storing a computer program, wherein the computer program when executed by a processor implements the code generation method for an on-board CAN network according to any one of claims 1 to 7.

Description

Code generation method, device, equipment and medium for vehicle-mounted CAN (controller area network) Technical Field The invention relates to the technical field of embedded communication, in particular to a code generation method, device, equipment and medium for a vehicle-mounted CAN (controller area network). Background In a modern automobile electronic and electric architecture, a CAN (i.e., controller Area Network, controller area network) bus is widely used for connecting various electronic control units (i.e., ECUs, electronic Control Unit), with the intelligent development of vehicles, the number of ECUs is increased to form a multi-domain CAN subnetwork, a CAN gateway is used as a core component for message routing and interaction among subnetworks, and functional logic of the CAN gateway is defined by a communication matrix. Traditional CAN gateway software development relies on manual interpretation of a communication matrix, and manual code writing realizes functions of message receiving and transmitting, signal packaging and unpacking, route judgment and the like, so that the process is tedious and error-prone, repeated modification test is needed when the communication matrix is frequently changed, and the efficiency is extremely low. The existing improvement scheme adopts commercial tools to combine DBC (namely Database CAN, CAN Database file) files to generate partial codes, but has the obvious defects that the function coverage is incomplete, only a signal packing unpacking function CAN be generated, the gateway routing logic, message filtering and other core functions still need manual coding, the flexibility is insufficient, the DBC format is fixed, the self-defining functions such as IDS (namely Intrusion Detection System, intrusion detection system) parameter configuration and cyclic code verification cannot be supported, the configuration information is dispersed and difficult to manage, the format is limited, the binding tools are ecological, the multi-bus scenes such as Ethernet cannot be adapted, the generated codes are easy to be incompatible with the existing project architecture, the integration difficulty is high, the configuration and the code separation are carried out, and the development and maintenance burden is further increased. Therefore, how to design an efficient and reliable code generation scheme for the vehicle-mounted CAN network is a technical problem to be solved currently. Disclosure of Invention In view of the above, an object of the present invention is to provide a code generation method, apparatus, device, and medium for an in-vehicle CAN network, which CAN improve the efficiency and reliability of code generation for the in-vehicle CAN network. The specific scheme is as follows: in a first aspect, the present application provides a code generation method for a vehicle-mounted CAN network, including: determining a declarative configuration file of configuration information of a CAN gateway in a target vehicle in a JSON format, and checking the declarative configuration file by using a preset JSON Schema file to obtain a checking result; When the verification result shows that verification is passed, analyzing the declarative configuration file, and generating a target code by utilizing target data obtained through analysis and a preset template engine; And filling the target code into an initial C code file to obtain a target C code file suitable for a vehicle-mounted CAN network, so that after a general gateway firmware of the CAN gateway receives the CAN message, the general gateway firmware is driven by the target C code file to trigger a preset processing operation for the CAN message, and the general gateway firmware is a gateway application program configured with general processing logic for the CAN message. Optionally, the declaration configuration file includes the target vehicle CAN bus and definition information of the CAN message transmitted on the CAN bus, configuration information of unified diagnostic service, parameter information of the vehicle-mounted intrusion detection system, and cyclic code verification information of the CAN message. Optionally, the verifying the declarative configuration file by using a preset JSON Schema file to obtain a verification result includes: And correspondingly checking the data structure, the field name, the data type and the numerical range of the declarative configuration file by calling a preset checker and utilizing a preset JSON Schema file to obtain a checking result. Optionally, the parsing the declarative configuration file, and generating the object code by using the object data obtained by parsing and a preset template engine includes: Analyzing the declaration configuration file based on a recursion mode through a preset code generation engine to obtain target data; Generating, by the preset code generation engine, target code based on the target data and placeholders in a preset template engin