Code generation method, computer equipment and storage medium

By automatically determining the target mailbox number and frame number, the code of the CAN communication system is generated, which solves the complexity of code generation and mailbox configuration in the prior art, and improves efficiency and code quality.

CN119225707APending Publication Date: 2024-12-31EVE ENERGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411282111.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-12
Publication Date
2024-12-31

AI Technical Summary

Technical Problem

In CAN-based communication systems, code generation and mailbox configuration are complex and error-prone, resulting in low development efficiency, system stability and performance impacts.

Method used

By obtaining the number of mailboxes and signal parameters, we automatically determine the target mailbox number and frame number in each mailbox in each cycle, generate the code corresponding to the target DBC file, optimize the allocation of mailbox resources, and simplify the development process.

Benefits of technology

Improves code generation efficiency, reduces complex operations, ensures mailbox load balancing, avoids resource waste and insufficient, and improves code quality and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119225707A_ABST
    Figure CN119225707A_ABST
Patent Text Reader

Abstract

The invention provides a code generation method, computer equipment and a storage medium, and the code generation method comprises the steps that a first mailbox number and signal parameters in a target DBC file are acquired, the first mailbox number represents the total number of mailboxes sending signals, each mailbox can be used for transmitting one or more signals, and the signal parameters in the target DBC file are acquired; the signal parameter comprises a period of a signal in each mailbox and a corresponding frame number; determining the number of target mailboxes in each period and the number of frames in each mailbox according to the first mailbox number and the signal parameters; according to the number of the target mailboxes in each period and the number of frames in each mailbox, obtaining signals transmitted by the mailboxes; and generating a code according to the signal transmitted by the mailbox to obtain a code corresponding to the target DBC file. The code generation method provided by the invention can automatically analyze and allocate mailboxes and the number of frames, improves the code generation efficiency, reduces code generation errors, and optimizes resource utilization.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and more specifically, to a code generation method, a computer device, and a storage medium. Background Art

[0002] In the related art, in the development of existing communication systems, especially in systems based on CAN (Controller Area Network), code generation and configuration work involves multiple complex steps. First, developers need to modify each code file to adapt to specific signal quantities and frame configurations. This not only requires developers to have a deep understanding of the working principle of the system, but also takes a lot of time to determine the usage of each mailbox and the transmission cycle of the signal. In order to ensure the correctness of the system, all associated files must be updated synchronously, which increases the possibility of errors and the complexity of maintenance.

[0003] Secondly, multiple mailboxes usually need to be configured within the system, which are responsible for storing and transmitting signals. However, the configuration calculation method of the mailboxes is complex and cumbersome, involving detailed analysis of the signals within each cycle. Calculating and configuring these mailboxes is time-consuming and prone to errors. The existing operation not only reduces development efficiency, but may also lead to inconsistent or incorrect configurations, thus affecting the stability and performance of the system. Summary of the invention

[0004] The purpose of the embodiments of the present application is to provide a code generation method, a computer device and a storage medium to solve the technical problem that the manual configuration of codes and mailboxes in the related art is complex and prone to errors.

[0005] In a first aspect, an embodiment of the present application provides a code generation method, comprising:

[0006] Obtain the first mailbox number and the signal parameters in the target DBC file, wherein the first mailbox number represents the total number of mailboxes for sending signals, each of the mailboxes can be used to transmit one or more signals, and the signal parameters include the period of the signal in each mailbox and the corresponding number of frames;

[0007] Determining the target number of mailboxes and the number of frames in each mailbox in each cycle according to the first number of mailboxes and the signal parameters;

[0008] Acquire a signal transmitted by a mailbox according to the target number of mailboxes in each cycle and the number of frames in each mailbox;

[0009] A code is generated according to the signal transmitted by the mailbox, and a code corresponding to the target DBC file is obtained.

[0010] In one embodiment, the target number of mailboxes in each cycle and the number of frames in each mailbox are determined based on the first number of mailboxes and the signal parameters, including: sorting the period for transmission of each signal from small to large according to the period to obtain a signal list; determining the minimum number of mailboxes in each cycle according to a preset minimum mailbox unit, wherein the preset minimum mailbox unit refers to the minimum number of frames that can be sent by each mailbox each time; determining whether the first number of mailboxes meets the allocation requirements based on the minimum number of mailboxes in each cycle; if the first number of mailboxes does not meet the allocation requirements, performing mailbox allocation on the signal list according to a first preset rule to determine the target number of mailboxes in each cycle in the signal list; if the first number of mailboxes meets the allocation requirements, completing the mailbox allocation to obtain the target number of mailboxes in each cycle; determining the number of frames in each mailbox based on the target number of mailboxes in each cycle.

[0011] In one embodiment, determining whether the first number of mailboxes meets the allocation requirements based on the minimum number of mailboxes in each cycle includes: adding the minimum number of mailboxes in all cycles to obtain the second number of mailboxes; judging whether the second number of mailboxes is greater than the first number of mailboxes; if the second number of mailboxes is greater than the first number of mailboxes, determining that the allocation requirements are not met; if the second number of mailboxes is less than or equal to the first number of mailboxes, determining that the allocation requirements are met.

[0012] In one embodiment, if the first number of mailboxes does not meet the allocation requirements, the signal list is allocated mailboxes according to a first preset rule to determine the target number of mailboxes in each cycle in the signal list, including: determining the maximum number of mailboxes for each cycle according to the preset minimum mailbox unit; allocating the first number of mailboxes according to the preset minimum mailbox unit to obtain a third number of mailboxes and a fourth number of mailboxes, the third number of mailboxes being the number of mailboxes in the first number of mailboxes that complete the allocation of the minimum number of mailboxes for each cycle according to the signal list, and the fourth number of mailboxes being the number of mailboxes in the signal list that do not complete the allocation of the minimum number of mailboxes; when allocating mailboxes according to the fourth number of mailboxes, if the number of frames corresponding to the cycle to be allocated reaches the maximum number of frames corresponding to each cycle in the DBC file, mailbox allocation for the next cycle is performed.

[0013] In one embodiment, when mailbox allocation is performed according to the fourth mailbox number, the method further includes: if the number of frames corresponding to the period to be allocated does not reach the maximum number of frames corresponding to each period in the DBC file, then continuing to perform mailbox allocation for the period to be allocated that has not reached the maximum number of frames corresponding to each period.

[0014] In one embodiment, determining the number of frames in each mailbox according to the number of target mailboxes in each cycle includes: if the total number of first allocated frame numbers of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, performing frame number allocation for the next cycle; or, if the total number of first allocated frame numbers of all target mailboxes in each cycle is not equal to the maximum number of frames corresponding to each cycle in the DBC file, traversing the number of target mailboxes in each cycle, adding a preset number of frames to the first allocated frame number, and when a preset stop condition is met, determining that the number of frames for each target mailbox in the current cycle has completed frame number allocation, then performing frame number allocation for the next cycle, the preset stop condition being that when the total number of second allocated frame numbers of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, stopping frame number allocation, the second allocated frame number being the number of frames obtained by adding the preset number of frames to the first allocated frame number; when frame number allocation has been completed for each cycle in the signal list, stopping frame number allocation to obtain the number of frames in each mailbox.

[0015] In one embodiment, the obtaining of the signal transmitted by the mailbox according to the number of target mailboxes in each cycle and the number of frames in each mailbox includes: determining the number of mailbox multiplexing times corresponding to each target mailbox according to the number of frames in each mailbox; sorting the number of target mailboxes in each cycle in ascending order according to the number of mailbox multiplexing times corresponding to each target mailbox, to obtain the first header file of the sending signal; obtaining the frame ID corresponding to the number of frames of each target mailbox in each cycle; mapping the frame ID with the first header file to obtain a first execution file, the first execution file including the frame IDs arranged in the order corresponding to the first header file; obtaining the signal to be sent corresponding to the frame ID corresponding to the frame number; mapping the signal to be sent with the first header file to obtain a first parameter file; obtaining the signal transmitted by the mailbox according to the first header file, the first execution file and the first parameter file.

[0016] In one embodiment, the code is generated according to the signal transmitted by the mailbox to obtain the code corresponding to the target DBC file, including: obtaining a second header file of the signal according to the signal and a second preset rule; generating a second execution file corresponding to the second header file according to the signal; generating a second parameter file corresponding to the second header file according to the signal; and obtaining the code corresponding to the target DBC file according to the second header file, the second execution file and the second parameter file.

[0017] In a second aspect, an embodiment of the present application provides a code generation device, the device comprising:

[0018] An acquisition unit, configured to acquire a first mailbox number and a signal parameter in a target DBC file, wherein the first mailbox number represents the total number of mailboxes for sending signals, each of the mailboxes can be used to transmit one or more signals, and the signal parameter includes a period of the signal in each mailbox and a corresponding number of frames;

[0019] a determination unit, configured to determine the target number of mailboxes in each cycle and the number of frames in each mailbox according to the first number of mailboxes and the signal parameter;

[0020] An acquisition unit, configured to acquire a signal transmitted by a mailbox according to the number of target mailboxes in each cycle and the number of frames in each mailbox;

[0021] The determination unit is used to generate a code according to the signal transmitted by the mailbox to obtain the code corresponding to the target DBC file.

[0022] In a third aspect, an embodiment of the present application provides a computer device, comprising a memory and a processor, wherein the memory is connected to the processor, and the processor is used to execute one or more computer programs stored in the memory, and when the processor executes the one or more computer programs, the computer device implements the code generation method as described in the first aspect.

[0023] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the code generation method as described in the first aspect.

[0024] The beneficial effects of the code generation method provided in the embodiment of the present application are as follows: compared with the related art, the present application greatly improves the efficiency of code generation and reduces complex operations by automatically reading the signal parameters and the number of mailboxes in the DBC file, and performing mailbox allocation and frame number allocation; and by determining the target number of mailboxes in each cycle and the number of frames in each mailbox, the allocation of mailbox resources can be optimized to ensure load balancing of each mailbox and avoid resource waste and mailbox shortage problems; further, the required code files are automatically generated according to the target DBC file, which simplifies the development workflow, and because the code generation process is consistent and standardized, the quality and reliability of the generated code are further improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.

[0026] Figure 1 A flowchart of a code generation method provided in an embodiment of the present application;

[0027] Figure 2 A schematic diagram of the structure of a code generation device provided in an embodiment of the present application;

[0028] Figure 3 A schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to make the technical problems, technical solutions and beneficial effects to be solved by the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0030] It should be noted that the terms "first" and "second" are used for descriptive purposes only. These terms are only used to distinguish a first element from another element, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of this application, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0031] It should be noted that the “connection” in the following embodiments should be understood as “electrical connection”, “communication connection”, etc. if the connected circuits, modules, units, etc. transmit electrical signals or data to each other.

[0032] It should be noted that the singular forms "a", "an" and "said / the" may also include plural forms, unless the context clearly indicates otherwise. It should also be understood that the terms "include / comprise" or "have" etc. specify the existence of the stated features, wholes, steps, operations, components, parts or combinations thereof, but do not exclude the possibility of the existence or addition of one or more other features, wholes, steps, operations, components, parts or combinations thereof.

[0033] Please also read Figure 1 Now, a code generation method provided in an embodiment of the present application is described. The code generation method includes:

[0034] S10. Obtain the first mailbox number and the signal parameters in the target DBC file. The first mailbox number represents the total number of mailboxes that send signals. Each mailbox can be used to transmit one or more signals. The signal parameters include the period of the signal in each mailbox and the corresponding number of frames.

[0035] The first mailbox number can be manually set or obtained from the target DBC file, and is not limited here. The first mailbox number represents the total number of mailboxes that send signals. The setting of the first mailbox number directly affects the subsequent mailbox allocation strategy and the communication capability of the signal.

[0036] In one embodiment of the present application, a mailbox refers to a container or channel reserved for transmitting signals. Each mailbox can carry and transmit one or more signals, and the signals will be sent to the target receiver according to a certain predetermined rule.

[0037] The signal parameters refer to the transmission characteristics of each signal in the mailbox, mainly including the period of the signal and the number of frames corresponding to the period.

[0038] Among them, the signal parameters can be obtained by parsing the target DBC file.

[0039] The DBC file is a standard file format that describes the communication between controllers in a car network, which contains detailed signal definitions and properties. By analyzing this file, the cycle and frame number information of each signal can be extracted.

[0040] Among them, the signal period refers to the time interval between sending signals. Different signals may have different transmission periods, which usually depends on the importance of the signal and the real-time required. Signals are data organized into a specific format and sent through the communication network within the vehicle. Signals can carry a variety of information, such as speed, temperature, etc. Signal transmission is the basis of internal communication in the vehicle, which allows the various components of the vehicle to share status information and instructions. By transmitting and processing these signals, the vehicle can achieve advanced functions such as automated operation and fault detection. Signals can generate code, which is used in the vehicle control system to parse, manage and respond to data. The use of automatically generated code can effectively reduce the workload of existing code writing and improve development efficiency and accuracy.

[0041] Among them, frame is the basic unit of information transmission, which contains the actual data of the signal. Different signals may require different numbers of frames to transmit their data. The number of frames indicates how many data frames each mailbox needs to send in each signal transmission.

[0042] It can be seen that the first mailbox number and signal parameters in this embodiment are the basis for subsequent mailbox allocation, signal acquisition and code generation; the first mailbox number determines the amount of available resources, is the starting point for effective resource allocation, and directly affects the formulation of subsequent mailbox allocation strategies. Without an accurate first mailbox number, resource allocation may become unreasonable, resulting in waste or insufficient resources; and the signal parameters determine the signal sending frequency, the amount of data sent each time and the mailbox to which it is allocated, which is the basis for achieving efficient signal transmission and ensuring accurate data delivery, thereby improving the flexibility and accuracy of the code generation method.

[0043] S20. Determine the target number of mailboxes in each cycle and the number of frames in each mailbox according to the first number of mailboxes and the signal parameters.

[0044] Among them, mailbox allocation means allocating the transmitted signal to the appropriate mailbox so that it can be effectively managed and transmitted during the communication process. The target number of mailboxes refers to the number of mailboxes to which the signal should be allocated for transmission within a cycle. The target number of mailboxes needs to be determined based on the transmission characteristics of the signal and the capacity of the mailbox to ensure that the signal can be effectively transmitted and processed.

[0045] For example, if a signal needs to be transmitted quickly, it may be assigned to a mailbox with a larger capacity to ensure that the data can be sent quickly.

[0046] The number of frames corresponding to the mailbox in the target mailbox number is determined based on the transmission characteristics of the signal and the capacity of the mailbox to ensure that the signal can be effectively transmitted and processed. For example, if a signal only needs to be sent occasionally, it may be assigned to a mailbox with a smaller number of frames to save resources.

[0047] It can be seen that in this embodiment, the target number of mailboxes in each cycle is dynamically determined based on the signal cycle and frame number requirements, thereby optimizing the utilization of the mailboxes, ensuring that high-priority signals can be processed first, and at the same time reducing the idleness and waste of mailbox resources as much as possible. The number of frames that should be included in each mailbox is further determined by the target number of mailboxes, thereby achieving efficient data transmission and ensuring that each signal can be transmitted stably and accurately within its cycle.

[0048] S30, obtaining a mailbox transmission signal according to the target mailbox number in each cycle and the number of frames in each mailbox.

[0049] After confirming the target number of mailboxes in each cycle and the number of frames that each mailbox should contain, the mailboxes and signals can be mapped. This mapping process determines which signals are assigned to the same mailbox and the specific position and space occupied by each signal in the mailbox. The mapping of signals needs to take into account the periodicity, priority and data volume of the signal to ensure that the signal can be effectively transmitted within its defined cycle.

[0050] Furthermore, the data volume of each signal must conform to the number of frames allocated to its mailbox. If the data volume of a signal exceeds the number of frames allocated to it, the signal may need to be split and allocated to multiple mailboxes; if the data volume is less than the number of frames allocated, the mailbox can consider accommodating the data of other signals at the same time to maximize the use of the mailbox space.

[0051] Furthermore, after the signals are mapped to mailboxes and matched to frame quantities, the signal transmission period must also be considered. Each signal is assigned to a specific transmission period according to its periodicity, ensuring that all signals can be transmitted on time within their scheduled period.

[0052] It can be seen that this embodiment can efficiently manage and schedule mailbox resources, ensure that each signal can be correctly processed according to its characteristics and requirements, and improve the accuracy and stability of signal transmission.

[0053] S40. Generate a code according to the signal transmitted by the mailbox, and obtain a code corresponding to the target DBC file.

[0054] Among them, the code that meets the requirements of the target hardware and software framework is automatically generated based on the signals transmitted by the mailbox. This process usually includes creating data structures to store the values ​​of messages and signals, and implementing functions for sending and receiving messages. Code generation uses automated tools to improve efficiency and accuracy.

[0055] The codes corresponding to the target DBC file usually include source code, header file, execution file, parameter file, etc., which define the software implementation of the communication system.

[0056] It can be seen that the process of automatically generating codes based on signals in the DBC file in this embodiment not only improves development efficiency, but also reduces development errors and improves code quality and reliability.

[0057] The beneficial effects of the code generation method provided in the embodiment of the present application are as follows: compared with the related art, the present application greatly improves the efficiency of code generation and reduces complex operations by automatically reading the signal parameters and the number of mailboxes in the DBC file, and performing mailbox allocation and frame number allocation; and by determining the target number of mailboxes in each cycle and the number of frames in each mailbox, the allocation of mailbox resources can be optimized to ensure load balancing of each mailbox and avoid resource waste and mailbox shortage problems; further, the required code files are automatically generated according to the target DBC file, which simplifies the development workflow, and because the code generation process is consistent and standardized, the quality and reliability of the generated code are further improved.

[0058] In one embodiment, the target number of mailboxes in each cycle and the number of frames in each mailbox are determined based on the first number of mailboxes and signal parameters, including: sorting the period for transmission of each signal from small to large to obtain a signal list; determining the minimum number of mailboxes in each cycle based on a preset minimum mailbox unit, the preset minimum mailbox unit refers to the minimum number of frames that each mailbox can send each time; determining whether the first number of mailboxes meets the allocation requirements based on the minimum number of mailboxes in each cycle; if the first number of mailboxes does not meet the allocation requirements, the signal list is allocated to mailboxes according to the first preset rule to determine the target number of mailboxes in each cycle in the signal list, if the first number of mailboxes meets the allocation requirements, the mailbox allocation is completed to obtain the target number of mailboxes in each cycle; the number of frames in each mailbox is determined based on the target number of mailboxes in each cycle.

[0059] Among them, the transmission cycle of each signal and the corresponding number of frames are sorted from small to large according to the cycle to obtain a signal list. The purpose of sorting is to use the cycle length as the basis for priority sorting to ensure that when the mailbox is allocated, the signal with a shorter cycle can be processed first, thereby improving the efficiency and real-time performance of communication. The sorting of the signal list helps the system to efficiently process signals with different cycles and frame numbers.

[0060] Among them, the preset minimum mailbox unit refers to the smallest time unit used to calculate the required number of mailboxes, and the time unit is used to determine how many "mailboxes" are needed to store or process data frames within a given time; the preset minimum mailbox unit can be set to 10ms, and there is no unique limitation here.

[0061] Among them, in the implementation process of determining the minimum number of mailboxes in each cycle according to the preset minimum mailbox unit, the minimum number of mailboxes required to meet the minimum frame transmission is calculated based on the preset minimum mailbox unit and the minimum frame transmission requirements in each cycle. Specifically, the sum of the minimum frame requirements of each cycle is divided by the minimum frame processing capacity of each mailbox (that is, the preset minimum mailbox unit), and the result is rounded up to obtain the minimum number of mailboxes required. It can be expressed by the following formula:

[0062] The minimum number of mailboxes per cycle = round up (the sum of the minimum frame requirements within the cycle / the preset minimum mailbox unit).

[0063] Among them, when determining whether the first number of mailboxes meets the allocation requirements based on the minimum number of mailboxes in each cycle, it is to verify whether the first number of mailboxes meets the minimum mailbox allocation requirements corresponding to all sorted signal cycles. If the first number of mailboxes is not enough to meet the basic allocation requirements, the first preset rule will be triggered for adjustment; the first preset rule may include considerations in multiple dimensions, such as the importance and urgency of the signal, signals that can be combined for transmission, etc., aiming to maximize mailbox usage efficiency and transmission performance.

[0064] It can be seen that in this embodiment, by sorting the signal list and determining the minimum mailbox unit, it is possible to ensure the reasonable allocation of signal transmission tasks, so that each signal can obtain appropriate transmission resources, thereby achieving high efficiency and real-time performance of signal transmission.

[0065] In one embodiment, based on the minimum number of mailboxes in each cycle, determining whether the first number of mailboxes meets the allocation requirements includes: adding the minimum number of mailboxes in all cycles to obtain the second number of mailboxes; judging whether the second number of mailboxes is greater than the first number of mailboxes; if the second number of mailboxes is greater than the first number of mailboxes, determining that the allocation requirements are not met; if the second number of mailboxes is less than or equal to the first number of mailboxes, determining that the allocation requirements are met.

[0066] The second number of mailboxes is obtained by adding the minimum number of mailboxes in all cycles, that is, the total number of mailboxes required to meet the signal transmission requirements in all cycles.

[0067] In the implementation process of adding the minimum number of mailboxes of all cycles to obtain the second number of mailboxes, the minimum number of mailboxes required for each cycle is first calculated, and then the values ​​of the minimum number of mailboxes are added to obtain the second number of mailboxes.

[0068] Among them, the determination of whether the second number of mailboxes is greater than the first number of mailboxes is to determine whether the existing mailbox resources are sufficient to support the signal transmission requirements in all cycles. If the second number of mailboxes is greater than the first number of mailboxes, it means that the current mailbox resources are insufficient to meet the transmission requirements of all signals, and it is necessary to reconsider the allocation of mailbox resources or solve the problem of insufficient resources by increasing mailbox resources; if the second number of mailboxes is less than or equal to the first number of mailboxes, it means that the existing mailbox resources are sufficient to meet the signal transmission requirements in all cycles.

[0069] It can be seen that in this embodiment, by adding the minimum number of mailboxes and comparing it with the first number of mailboxes, the rationality of mailbox allocation can be ensured, ensuring that the transmission requirements of various signals are met efficiently and fairly under the constraint of limited resources.

[0070] In one embodiment, if the first number of mailboxes does not meet the allocation requirements, the signal list is allocated mailboxes according to the first preset rule to determine the target number of mailboxes in each cycle in the signal list, including: determining the maximum number of mailboxes for each cycle according to the preset minimum mailbox unit; allocating the first number of mailboxes according to the preset minimum mailbox unit to obtain a third number of mailboxes and a fourth number of mailboxes, the third number of mailboxes being the number of mailboxes in the first number of mailboxes that complete the allocation of the minimum number of mailboxes for each cycle according to the signal list, and the fourth number of mailboxes being the number of mailboxes in the signal list that do not complete the allocation of the minimum number of mailboxes; when allocating mailboxes according to the fourth number of mailboxes, if the number of frames corresponding to the cycle to be allocated reaches the maximum number of frames corresponding to each cycle in the DBC file, mailbox allocation for the next cycle is performed.

[0071] Optionally, when performing mailbox allocation according to the fourth number of mailboxes, the method also includes: if the number of frames corresponding to the period to be allocated does not reach the maximum number of frames corresponding to each period in the DBC file, continuing to perform mailbox allocation for the period to be allocated that has not reached the maximum number of frames corresponding to each period.

[0072] The maximum number of mailboxes mentioned above indicates the number of mailboxes required to meet the maximum transmission demand in each cycle.

[0073] Among them, in the implementation process of determining the maximum number of mailboxes for each cycle based on the preset minimum mailbox unit, all signals in each cycle are analyzed to determine the number of frames that each signal needs to transmit in the cycle; for each cycle, the transmission requirements of all signals in the cycle are summarized to determine the maximum transmission requirement. The maximum transmission requirement indicates the maximum number of frames that need to be supported in the cycle under the worst circumstances (that is, when all signals need to be transmitted in the same cycle); based on the preset minimum mailbox unit and the maximum transmission requirement of each cycle, the maximum number of mailboxes required for each cycle is calculated. The specific method is to divide the maximum frame demand of each cycle by the minimum number of frames that each mailbox can handle (that is, the preset minimum mailbox unit), and round up the result. The following formula can be used:

[0074] Maximum number of mailboxes = round up (maximum frame requirement per cycle / preset minimum mailbox unit).

[0075] Among them, the third number of mailboxes is the number of mailboxes in the first number of mailboxes that complete the allocation of the minimum number of mailboxes in each cycle according to the signal list; the fourth number of mailboxes is the number of mailboxes in the signal list that do not complete the allocation of the minimum number of mailboxes.

[0076] Among them, when the mailboxes are allocated according to the fourth mailbox number, it is determined in turn according to the signal list whether the number of frames corresponding to the period to be allocated reaches the maximum number of frames corresponding to each period in the DBC file. If it reaches it, the mailbox allocation for this period is ended, and the allocation for the next period begins. If the maximum number of frames is not reached, mailboxes continue to be allocated for this period until the maximum number of mailboxes for each period is reached or the frame requirements within the period are met. A target number of mailboxes will be determined in each period. The target number not only meets the transmission requirements of the minimum number of frames, but also makes the best use of the available mailbox resources to meet the requirements of the maximum number of frames, thereby optimizing the use of resources and the transmission efficiency of signals.

[0077] It can be seen that in this embodiment, under the condition of limited resources, the efficiency of signal transmission in each cycle is maximized, while ensuring that the transmission requirements of high priority or important signals are given priority and met. In one embodiment, according to the number of target mailboxes in each cycle, the number of frames in each mailbox is determined, including: if the total number of first allocated frames of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, the number of frames for the next cycle is allocated; or, if the total number of first allocated frames of all target mailboxes in each cycle is not equal to the maximum number of frames corresponding to each cycle in the DBC file, the number of target mailboxes in each cycle is traversed, and the number of frames for the first allocated is increased by a preset number of frames. When the preset stop condition is met, it is determined that the number of frames for each target mailbox in the current cycle has been allocated, and the number of frames for the next cycle is allocated. The preset stop condition is that when the total number of second allocated frames of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, the number of frames allocated is stopped, and the second number of allocated frames is the number of frames after the first number of allocated frames is increased by the preset number of frames; when the number of frames for each cycle in the signal list has been allocated, the number of frames allocated is stopped to obtain the number of frames in each mailbox.

[0078] In the process of evenly distributing the maximum number of frames corresponding to each cycle according to the target number of mailboxes in each cycle, the number of frames to be allocated to each mailbox is obtained by dividing the maximum number of frames in each cycle by the target number of mailboxes.

[0079] Furthermore, it is ensured that the workload of each target mailbox is roughly the same during the period, so as to optimize the transmission efficiency of the system.

[0080] Among them, the first allocated frame number refers to the number of frames obtained by evenly distributing the maximum number of frames corresponding to each cycle according to the target number of mailboxes in each cycle; the second allocated frame number refers to the number of frames after the first allocated frame number is increased by the preset frame number; the maximum number of frames corresponding to each cycle represents the maximum number of frames that can be transmitted in each cycle.

[0081] The preset stop condition is that when the total number of second allocated frames of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, the frame number allocation is stopped. The purpose of the preset stop condition is to ensure that the allocation of the frame number reaches the predetermined maximum number of frames, thereby avoiding waste of resources.

[0082] Among them, in the specific implementation of traversing the target mailbox number in each cycle and increasing the preset frame number to the first allocated frame number, during the traversal process, the first allocated frame number of each target mailbox number is adjusted, that is, the preset frame number is increased on the original basis.

[0083] Furthermore, after the preset number of frames is increased, the sum of the number of frames allocated to all target mailboxes in the current cycle will be recalculated to determine whether it is equal to the maximum number of frames corresponding to each cycle specified in the DBC file. If the preset maximum number of frames has not been reached, it may be necessary to continue the traversal process, traverse the target mailboxes and increase the preset number of frames again. This process may need to be repeated multiple times until the preset stop condition is reached.

[0084] It can be seen that in this embodiment, by average distribution, it can be ensured that each target mailbox can obtain an appropriate number of frames. By traversing the number of target mailboxes in each cycle and adding the preset number of frames to the first allocated number of frames, load balancing can be achieved to ensure that the load of each target mailbox is reasonable.

[0085] In one embodiment, based on the number of target mailboxes in each cycle and the number of frames in each mailbox, it includes: determining the number of mailbox multiplexing times corresponding to each target mailbox number based on the number of frames in each mailbox; sorting the number of target mailboxes in each cycle in ascending order according to the number of mailbox multiplexing times corresponding to each target mailbox number to obtain a first header file for sending a signal; obtaining a frame ID corresponding to the number of frames for each target mailbox number in each cycle; mapping the frame ID with the first header file to obtain a first execution file, the first execution file including frame IDs arranged in the order corresponding to the first header file; obtaining a signal to be sent corresponding to the frame ID corresponding to the frame number; mapping the signal to be sent with the first header file to obtain a first parameter file; obtaining a signal transmitted by the mailbox based on the first header file, the first execution file and the first parameter file.

[0086] Among them, the frame ID represents the unique identifier of each frame, which is used to distinguish different messages; the header file (HeaderFile) represents the basic configuration information containing the sorted target mailbox number, providing guidance for data transmission; the execution file (Execution File) represents the header file, which contains the arranged frame IDs and is used to guide the actual transmission order of the frames; the parameter file (Parameter File) represents the specific parameters of the signal to be sent, which is mapped with the header file to jointly guide the transmission of the signal; the number of mailbox multiplexing refers to the number of times each target mailbox number is multiplexed during the signal transmission process.

[0087] Among them, the number of target mailboxes in each cycle is sorted in ascending order according to the number of mailbox multiplexing times corresponding to each target mailbox number. This is to ensure that during the signal transmission process, mailboxes with smaller mailbox multiplexing times can be processed first, thereby improving the signal response speed.

[0088] The signal to be sent is the specific content of the frame, including data and control information. In the process of mapping the frame ID with the first header file to obtain the first execution file, the first execution file includes the frame IDs arranged in the order corresponding to the first header file, and creates an empty execution file. The empty execution file will be used to store the frame ID sorting based on the order of the first header file; traverse the first header file to match the frame ID, and find the corresponding frame ID from the frame ID list according to the mapping rule; add the matched frame ID to the empty execution file in the order found. This step is repeated until all the target mailboxes are processed and the first execution file is obtained.

[0089] The signal to be sent is further mapped to the first header file to obtain a first parameter file. Also according to the correspondence between the signal to be sent and the frame ID, the signal to be sent is placed in the first header file in sequence to obtain the first parameter file.

[0090] Among them, in the process of obtaining the signal transmitted by the mailbox according to the first header file, the first execution file and the first parameter file, the frame ID arranged in the first execution file is used in conjunction with the specific parameters in the first parameter file to generate a sending configuration for each frame. The sending configuration includes the ID of the target mailbox number of each signal, the sending time, the priority and necessary sending parameters; according to the sorting of the target mailbox numbers in the first header file, the sending order of the signal is determined to generate the final mailbox transmission signal.

[0091] It can be seen that in this embodiment, by determining the number of mailbox reuses corresponding to each target mailbox number, the mailbox resources can be used more effectively, and the frame ID corresponding to the number of frames of each target mailbox number is further mapped with the three files, ensuring the consistency and standardization of the code generation process and improving the quality and reliability of the code.

[0092] In one embodiment, a code is generated according to a signal transmitted by an email to obtain a code corresponding to a target DBC file, including: obtaining a second header file of the signal according to the signal and a second preset rule; generating a second execution file corresponding to the second header file according to the signal; generating a second parameter file corresponding to the second header file according to the signal; and obtaining a code corresponding to the target DBC file according to the second header file, the second execution file, and the second parameter file.

[0093] Among them, the second preset rule is to arrange the signals in the time order of receiving them to obtain a sequence, and obtain the second header file of the signal according to the sequence; the second header file contains the header information of the signal, such as source address, destination address, protocol type, etc., and defines the basic properties and transmission rules of the signal; the second execution file contains the execution instructions and operations of the signal; the second parameter file contains the parameters and configuration information of the signal, and the parameters and configuration information of the signal will affect the processing and transmission process of the signal.

[0094] It can be seen that in this embodiment, the required code files are automatically generated according to the signal, which simplifies the development workflow, and because the code generation process is consistent and standardized, the quality and reliability of the generated code are further improved.

[0095] As another aspect of the embodiment of the present application, the embodiment of the present application provides a code generation device. The code generation can be a software module, which includes a number of instructions stored in a memory, and the processor can access the memory and call the instructions for execution to complete the code generation method described in the above embodiments.

[0096] See also Figure 2 , Figure 2 It is a structural diagram of a code generation device provided in an embodiment of the present application.

[0097] like Figure 2 As shown, the code generating device 200 includes:

[0098] An acquisition unit 201 is used to acquire a first mailbox number and a signal parameter in a target DBC file, wherein the first mailbox number indicates the total number of mailboxes for sending signals, each mailbox can be used to transmit one or more signals, and the signal parameter includes a period of a signal in each mailbox and a corresponding number of frames;

[0099] A determination unit 202, configured to determine the target number of mailboxes in each cycle and the number of frames in each mailbox according to the first number of mailboxes and the signal parameter;

[0100] The acquisition unit 201 is further used to determine the number of target mailboxes and the number of frames in each mailbox in each cycle;

[0101] The determining unit 202 is further configured to generate a code according to a signal transmitted by the mailbox, and obtain a code corresponding to the target DBC file.

[0102] The beneficial effects of the code generation method provided in the embodiment of the present application are as follows: compared with the related art, the present application greatly improves the efficiency of code generation and reduces complex operations by automatically reading the signal parameters and the number of mailboxes in the DBC file, and performing mailbox allocation and frame number allocation; and by determining the target number of mailboxes in each cycle and the number of frames in each mailbox, the allocation of mailbox resources can be optimized to ensure load balancing of each mailbox and avoid resource waste and mailbox shortage problems; further, the required code files are automatically generated according to the target DBC file, which simplifies the development workflow, and because the code generation process is consistent and standardized, the quality and reliability of the generated code are further improved.

[0103] In one embodiment, in determining the target number of mailboxes and the number of frames in each mailbox in each cycle based on the first number of mailboxes and signal parameters, the determination unit 202 is also used to: sort the period for transmission of each signal from small to large to obtain a signal list; determine the minimum number of mailboxes for each cycle based on a preset minimum mailbox unit, where the preset minimum mailbox unit refers to the minimum number of frames that can be sent by each mailbox each time; determine whether the first number of mailboxes meets the allocation requirements based on the minimum number of mailboxes for each cycle; if the first number of mailboxes does not meet the allocation requirements, allocate mailboxes to the signal list according to the first preset rule to determine the target number of mailboxes in each cycle in the signal list; if the first number of mailboxes meets the allocation requirements, complete the mailbox allocation to obtain the target number of mailboxes in each cycle; determine the number of frames in each mailbox based on the target number of mailboxes in each cycle.

[0104] In one embodiment, in determining whether the first number of mailboxes meets the allocation requirements based on the minimum number of mailboxes in each cycle, the determination unit 202 is also used to: add the minimum number of mailboxes in all cycles to obtain the second number of mailboxes; determine whether the second number of mailboxes is greater than the first number of mailboxes; if the second number of mailboxes is greater than the first number of mailboxes, determine that the allocation requirements are not met; if the second number of mailboxes is less than or equal to the first number of mailboxes, determine that the allocation requirements are met.

[0105] In one embodiment, if the first number of mailboxes does not meet the allocation requirements, the signal list is allocated mailboxes according to the first preset rule to determine the target number of mailboxes in each cycle in the signal list, and the determination unit 202 is also used to: determine the maximum number of mailboxes for each cycle according to the preset minimum mailbox unit; allocate the first number of mailboxes according to the preset minimum mailbox unit to obtain a third number of mailboxes and a fourth number of mailboxes, the third number of mailboxes being the number of mailboxes in the first number of mailboxes that complete the allocation of the minimum number of mailboxes for each cycle according to the signal list, and the fourth number of mailboxes being the number of mailboxes in the signal list that do not complete the allocation of the minimum number of mailboxes; when allocating mailboxes according to the fourth number of mailboxes, if the number of frames corresponding to the cycle to be allocated reaches the maximum number of frames corresponding to each cycle in the DBC file, mailbox allocation for the next cycle is performed.

[0106] In one embodiment, when mailbox allocation is performed according to the fourth number of mailboxes, the determination unit 202 is also used to: if the number of frames corresponding to the period to be allocated does not reach the maximum number of frames corresponding to each period in the DBC file, continue to allocate mailboxes for the period to be allocated that has not reached the maximum number of frames corresponding to each period.

[0107] In one embodiment, in determining the number of frames in each mailbox according to the number of target mailboxes in each cycle, the determination unit 202 is also used to: if the total number of first allocated frame numbers of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, then perform frame number allocation for the next cycle; or, if the total number of first allocated frame numbers of all target mailboxes in each cycle is not equal to the maximum number of frames corresponding to each cycle in the DBC file, then traverse the number of target mailboxes in each cycle, add a preset number of frames to the first allocated frame number, and when a preset stop condition is met, determine that the number of frames for each target mailbox in the current cycle has completed frame number allocation, then perform frame number allocation for the next cycle, the preset stop condition is that when the total number of second allocated frame numbers of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, stop frame number allocation, the second allocated frame number is the number of frames after the preset number of frames is added to the first allocated frame number; when the frame number allocation for each cycle in the signal list has been completed, stop frame number allocation to obtain the number of frames in each mailbox.

[0108] In one embodiment, based on the number of target mailboxes in each cycle and the number of frames in each mailbox, the acquisition unit 201 is also used to: determine the number of mailbox multiplexing times corresponding to each target mailbox number based on the number of frames in each mailbox; sort the number of target mailboxes in each cycle in ascending order according to the number of mailbox multiplexing times corresponding to each target mailbox number, and obtain a first header file for sending the signal; obtain the frame ID corresponding to the number of frames for each target mailbox number in each cycle; map the frame ID with the first header file to obtain a first execution file, the first execution file including the frame IDs arranged in the order corresponding to the first header file; obtain the signal to be sent corresponding to the frame ID corresponding to the frame number; map the signal to be sent with the first header file to obtain a first parameter file; and obtain the signal transmitted by the mailbox based on the first header file, the first execution file and the first parameter file.

[0109] In one embodiment, in generating code according to a signal transmitted by an email and obtaining a code corresponding to a target DBC file, the determination unit 202 is also used to: obtain a second header file of the signal according to the signal and a second preset rule; generate a second execution file corresponding to the second header file according to the signal; generate a second parameter file corresponding to the second header file according to the signal; and obtain the code corresponding to the target DBC file according to the second header file, the second execution file, and the second parameter file.

[0110] It should be noted that the above-mentioned code generation device can execute the code generation method provided in the embodiment of this application, and has the functional modules and beneficial effects corresponding to the execution method. For technical details not fully described in the code generation implementation, please refer to the code generation method provided in the embodiment of this application.

[0111] See also Figure 3 , Figure 3 Schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 3 As shown, the computer device 300 includes a processor 301 and a memory 302. The processor 301 is in communication connection with the memory 302.

[0112] The processor 301 is configured to support the computer device to execute the corresponding functions in the code generation method in the above method embodiment. The processor 301 can be a central processing unit (CPU), a network processor (NP), a hardware chip or any combination thereof. The above hardware chip can be an application specific integrated circuit (ASIC), a programmable logic device (PLD) or a combination thereof. The above PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.

[0113] Specifically, the processor 301 may include a sending card, a receiving card and a driving chip.

[0114] The memory 302 is used to store program codes, etc. The memory 302 may include a volatile memory (VM), such as a random access memory (RAM); the memory 302 may also include a non-volatile memory (NVM), such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD); the memory 302 may also include a combination of the above-mentioned types of memories.

[0115] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. The computer program includes program instructions. When the program instructions are executed by a computer, the computer executes the code generation method as described in the above embodiment.

[0116] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0117] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims

1. A code generation method, characterized in that: include: Obtain the first mailbox number and the signal parameters in the target DBC file, wherein the first mailbox number represents the total number of mailboxes for sending signals, each of the mailboxes can be used to transmit one or more signals, and the signal parameters include the period of the signal in each mailbox and the corresponding number of frames; Determining the target number of mailboxes and the number of frames in each mailbox in each cycle according to the first number of mailboxes and the signal parameters; Acquire a signal transmitted by a mailbox according to the target number of mailboxes in each cycle and the number of frames in each mailbox; A code is generated according to the signal transmitted by the mailbox, and a code corresponding to the target DBC file is obtained.

2. The code generation method according to claim 1, characterized in that: Determining the target number of mailboxes in each cycle and the number of frames in each mailbox according to the first number of mailboxes and the signal parameter comprises: Sort the transmission period of each signal from small to large according to the period to obtain a signal list; Determine the minimum number of mailboxes per cycle according to a preset minimum mailbox unit, wherein the preset minimum mailbox unit refers to the minimum number of frames that can be sent by each mailbox at a time; Determining whether the first number of mailboxes meets the allocation requirement according to the minimum number of mailboxes in each cycle; If the first number of mailboxes does not meet the allocation requirements, the signal list is allocated to mailboxes according to a first preset rule to determine the target number of mailboxes in each cycle in the signal list; if the first number of mailboxes meets the allocation requirements, the mailbox allocation is completed to obtain the target number of mailboxes in each cycle; The number of frames in each mailbox is determined according to the target number of mailboxes in each cycle.

3. The code generation method according to claim 2, characterized in that: The determining, according to the minimum number of mailboxes in each cycle, whether the first number of mailboxes meets the allocation requirement includes: Add the minimum number of mailboxes in all cycles to obtain the second number of mailboxes; Determining whether the number of the second mailboxes is greater than the number of the first mailboxes; If the number of the second mailboxes is greater than the number of the first mailboxes, it is determined that the allocation requirement is not met; If the number of the second mailboxes is less than or equal to the number of the first mailboxes, it is determined that the allocation requirements are met.

4. The code generation method according to claim 2, characterized in that: If the first number of mailboxes does not meet the allocation requirement, the signal list is allocated to mailboxes according to a first preset rule to determine the target number of mailboxes in each period of the signal list, including: Determining the maximum number of mailboxes per cycle according to the preset minimum mailbox unit; The first number of mailboxes is allocated to the mailboxes according to the preset minimum mailbox unit to obtain a third number of mailboxes and a fourth number of mailboxes, wherein the third number of mailboxes is the number of mailboxes in the first number of mailboxes that complete the allocation of the minimum number of mailboxes for each cycle according to the signal list, and the fourth number of mailboxes is the number of mailboxes in the signal list that do not complete the allocation of the minimum number of mailboxes; When mailbox allocation is performed according to the fourth number of mailboxes, if the number of frames corresponding to the period to be allocated reaches the maximum number of frames corresponding to each period in the DBC file, mailbox allocation for the next period is performed.

5. The code generation method according to claim 4, characterized in that: When performing mailbox allocation according to the fourth number of mailboxes, the method further includes: If the number of frames corresponding to the period to be allocated does not reach the maximum number of frames corresponding to each period in the DBC file, mailbox allocation continues to be performed on the period to be allocated that does not reach the maximum number of frames corresponding to each period.

6. The code generation method according to claim 2, characterized in that: Determining the number of frames in each mailbox according to the target number of mailboxes in each cycle includes: If the total number of first allocated frames of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, the frame number allocation for the next cycle is performed; or, If the total number of first allocated frames of all target mailboxes in each cycle is not equal to the maximum number of frames corresponding to each cycle in the DBC file, then traverse the number of target mailboxes in each cycle, add a preset number of frames to the first allocated frame number, and when the preset stop condition is met, determine that the frame number allocation for each target mailbox in the current cycle has been completed, then perform frame number allocation for the next cycle, and the preset stop condition is that when the total number of second allocated frames of all target mailboxes in each cycle is equal to the maximum number of frames corresponding to each cycle in the DBC file, stop frame number allocation, and the second allocated frame number is the frame number after the preset number of frames is added to the first allocated frame number; When the frame quantity allocation has been completed for each cycle in the signal list, the frame quantity allocation is stopped to obtain the frame quantity in each mailbox.

7. The code generation method according to any one of claims 1 to 6, characterized in that: The step of obtaining a signal transmitted by a mailbox according to the number of target mailboxes in each cycle and the number of frames in each mailbox comprises: Determine the number of mailbox multiplexing times corresponding to each target number of mailboxes according to the number of frames in each mailbox; The target mailbox numbers in each cycle are sorted in ascending order according to the mailbox multiplexing times corresponding to each target mailbox number, to obtain the first header file of the sending signal; Obtaining the frame ID corresponding to the number of frames of each target mailbox number in each cycle; Mapping the frame ID with the first header file to obtain a first execution file, wherein the first execution file includes the frame IDs arranged in a sequence corresponding to the first header file; Obtain a signal to be sent corresponding to a frame ID corresponding to the frame number; Mapping the signal to be sent with the first header file to obtain a first parameter file; A signal transmitted by a mailbox is obtained according to the first header file, the first execution file and the first parameter file.

8. The code generation method according to any one of claims 1 to 6, characterized in that: The step of generating a code according to the signal transmitted by the mailbox to obtain a code corresponding to the target DBC file includes: According to the signal and a second preset rule, obtaining a second header file of the signal; Generate a second execution file corresponding to the second header file according to the signal; Generate a second parameter file corresponding to the second header file according to the signal; According to the second header file, the second execution file and the second parameter file, the code corresponding to the target DBC file.

9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory is connected to the processor, and the processor is used to execute one or more computer programs stored in the memory. When the processor executes the one or more computer programs, the computer device implements the code generation method according to any one of claims 1 to 8.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the processor executes the code generation method according to any one of claims 1 to 8.