Policy code generation method and device, electronic equipment and readable storage medium
By automatically generating strategy code using formal statements, the inefficiency and error-prone nature of ECU strategy development are solved, enabling more efficient and accurate strategy code generation and debugging.
Patent Information
- Application Number
- CN202411279943.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2044-09-12
AI Technical Summary
In the existing technology, the development of electronic control unit (ECU) strategies relies on handwritten code, which leads to low efficiency, error-proneness and debugging difficulties, and requires high programming skills and embedded software development experience from developers.
This paper provides a strategy code generation method that obtains predefined formal statements, receives input data and generates formal code, expands and fills in the inclusion relationship between conceptual details, and automatically generates strategy code, thereby reducing development difficulty and improving efficiency and accuracy.
It enables automated generation of strategy code, reducing development difficulty, improving efficiency and accuracy, and simplifying the debugging process.
Smart Images

Figure CN119396369B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, in particular to a strategy code generation method and device, electronic equipment and readable storage medium. BACKGROUND
[0002] In the field of software development, the strategy development for electronic control unit (ECU) often relies on developers to manually write a large amount of code. However, it is found in practice that this process is not only complex and time-consuming, but also has a high requirement on the programming skills and embedded software development experience of the developers. Therefore, manually writing code inevitably brings problems such as low efficiency, error-prone and difficult debugging. SUMMARY
[0003] The purpose of the embodiments of the present application is to provide a strategy code generation method and device, electronic equipment and readable storage medium, which can allow developers to intuitively describe the strategy by using formal grammar, and automatically generate strategy code for ECU to use, so as to make the strategy development more difficult, improve the efficiency, make the debugging more simple and convenient, and improve the accuracy.
[0004] The first aspect of the present application provides a strategy code generation method, comprising:
[0005] obtaining a predefined formal statement, the formal statement defining all concept details for strategy execution;
[0006] receiving input data of the formal statement, and generating corresponding formal code based on the input data and the formal statement;
[0007] generating a containing relationship between the concept details based on the formal code;
[0008] expanding the formal rule code in the formal code to obtain rule expansion code;
[0009] filling the concept details based on the rule expansion code and the containing relationship between the concept details to obtain strategy code.
[0010] In the above implementation process, the method can automatically generate corresponding strategy code based on the data input by the developer based on the formal statement, so that the developer no longer needs to directly write the strategy code, thereby facilitating the improvement of the acquisition efficiency and quality of the strategy code.
[0011] Further, the filling of the concept details based on the rule expansion code and the containing relationship between the concept details to obtain strategy code comprises:
[0012] Based on the inclusion relationship between the concept details, an attribute tuple corresponding to the rule expansion code is acquired;
[0013] The attribute tuple is substituted into the precondition and the calculation expression in the rule expansion code to obtain intermediate code;
[0014] A function emission sequence when the result of the calculation expression is true is generated in the intermediate code to obtain policy code.
[0015] In the above implementation process, the method can perform corresponding code filling based on the precondition, the calculation expression and the function emission sequence included in the rule, so as to declare the detailed structure of the policy code and refine the acquisition process of the policy code.
[0016] Further, the method further comprises:
[0017] Acquiring all concept details for policy execution;
[0018] Based on the pre-processing macro definition command and the concept detail definition formal statement.
[0019] In the above implementation process, the method can predefine the formal statement based on the pre-processing macro definition command, so that the developer directly inputs data with the formal statement in the use process.
[0020] Further, the concept details include one or more of a conceptized signal name, a signal identifier value, a period, a timeout threshold, a mathematical maximum value, a mathematical minimum value, a logic maximum value, a logic minimum value, a signal initial value, an error value, a rule set, a mapping table, a signal maximum enumeration value, a function, a function identifier value, a code block, a code block identifier value and a data structure.
[0021] In the above implementation process, the method limits a large number of concept details, which can be used for corresponding definition in the formal statement, so that the developer can more easily develop the policy code using the formal statement.
[0022] Further, the method further comprises:
[0023] Receiving an input signal, the input signal including a corresponding signal identifier, a signal value and a signal timestamp;
[0024] Matching a signal object corresponding to the signal identifier;
[0025] Judging whether the signal timestamp is before the update timestamp of the signal object;
[0026] When the signal timestamp is before the update timestamp of the signal object, returning a data processing error indication.
[0027] In the implementation process, the method proposes a signal verification process before the policy code is called, which can make the calling of the policy code effective and reasonable.
[0028] Further, the method further comprises:
[0029] When the signal timestamp is not before the update timestamp of the signal object, it is determined whether the signal value is the same as the current value of the signal object;
[0030] When the signal value is the same as the current value of the signal object, the update timestamp of the signal object is updated based on the signal timestamp, and a data processing success indication is returned.
[0031] In the implementation process, the method can automatically exclude the interference of historical signals, and directly update the data when the value does not change, thereby avoiding invalid calling of the policy code.
[0032] Further, the method further comprises:
[0033] When the signal value is not the same as the current value of the signal object, the current value of the signal object is recorded;
[0034] The current value of the signal object is updated based on the signal value;
[0035] The update timestamp of the signal object is updated based on the signal timestamp.
[0036] In the implementation process, the method can update the signal when the signal value changes, and further trigger the use of the policy code.
[0037] Further, the method further comprises:
[0038] It is determined whether the signal value and the current value of the signal object belong to the same class;
[0039] When the signal value and the current value of the signal object do not belong to the same class, the signal timestamp is recorded as a signal change timestamp.
[0040] In the implementation process, the method can further perform same class judgment on the signal value, and automatically record the class change timestamp in the case of class change, for use in subsequent other processes.
[0041] Further, the method further comprises:
[0042] Obtaining a policy code corresponding to the signal object; the policy code at least comprises a first rule;
[0043] It is determined whether the preconditions of the first rule are met;
[0044] verifying whether the expression statement of the first rule is true when the precondition of the first rule is satisfied;
[0045] triggering a corresponding functional emission sequence when the expression statement of the first rule is true.
[0046] In the implementation process, the method can determine whether to trigger a corresponding functional emission sequence by judging the precondition and the expression statement, thereby ensuring the correct application of the functional emission sequence.
[0047] Further, when the policy code further includes a second rule, the triggering of the corresponding functional emission sequence is followed by, or when the expression statement of the first rule is not true, further comprising:
[0048] determining whether to continue the rule evaluation;
[0049] verifying whether the precondition of the second rule is satisfied when the rule evaluation is to be continued;
[0050] verifying whether the expression statement of the second rule is true when the precondition of the second rule is satisfied;
[0051] triggering a corresponding functional emission sequence when the expression statement of the second rule is true.
[0052] In the implementation process, the method can automatically determine whether to perform the evaluation of the next rule when facing multiple rules, thereby realizing the correct application of the policy code with multiple rules.
[0053] Further, the triggering of the corresponding functional emission sequence is followed by further comprising:
[0054] returning a data processing success indication.
[0055] In the implementation process, the method can give a corresponding indication to enable the device or the user to understand the current data processing situation.
[0056] The second aspect of the present application provides a policy code generation device, which comprises:
[0057] a first acquisition unit configured to acquire a predefined formal statement, the formal statement defining all concept details for policy execution;
[0058] a first generation unit configured to receive input data of the formal statement, and generate a corresponding formal code based on the input data and the formal statement;
[0059] a second generating unit, configured to generate a containing relationship between the concepts and the details based on the formalized code;
[0060] an unfolding unit, configured to unfold a formal rule code in the formalized code to obtain rule unfolded code;
[0061] a third generating unit, configured to fill the concepts and the details based on the rule unfolded code and the containing relationship between the concepts and the details to obtain policy code.
[0062] Further, the third generating unit comprises:
[0063] an obtaining sub-unit, configured to obtain an attribute tuple corresponding to the rule unfolded code based on the containing relationship between the concepts and the details;
[0064] a substituting sub-unit, configured to substitute the attribute tuple into a precondition and a calculation expression in the rule unfolded code to obtain intermediate code;
[0065] a generating sub-unit, configured to generate a function emitting sequence when a result of the calculation expression is true in the intermediate code to obtain the policy code.
[0066] Further, the policy code generating apparatus further comprises:
[0067] The first obtaining unit is further configured to obtain all concepts and details for policy execution.
[0068] a defining unit, configured to define a formal statement based on a pre-processing macro definition command and the concepts and the details.
[0069] Further, the concepts and the details comprise one or more of a conceptized signal name, a signal identification value, a period, a timeout threshold, a mathematical maximum value, a mathematical minimum value, a logic maximum value, a logic minimum value, a signal initial value, an error value, a rule set, a mapping table, a signal maximum enumeration value, a function, a function identification value, a code block, a code block identification value, and a data structure.
[0070] Further, the policy code generating apparatus further comprises:
[0071] a receiving unit, configured to receive an input signal, the input signal comprising a corresponding signal identifier, a signal value, and a signal timestamp;
[0072] a matching unit, configured to match a signal object corresponding to the signal identifier;
[0073] a first judging unit, configured to judge whether the signal timestamp is before an update timestamp of the signal object;
[0074] An indicating unit is configured to return a data processing error indication when the signal timestamp is prior to the update timestamp of the signal object.
[0075] Further, the policy code generation apparatus further comprises:
[0076] A second judging unit is configured to judge whether the signal value is the same as the current value of the signal object when the signal timestamp is not prior to the update timestamp of the signal object.
[0077] An updating unit is configured to update the update timestamp of the signal object based on the signal timestamp and return a data processing success indication when the signal value is the same as the current value of the signal object.
[0078] Further, the policy code generation apparatus further comprises:
[0079] A recording unit is configured to record the current value of the signal object when the signal value is not the same as the current value of the signal object.
[0080] The updating unit is further configured to update the current value of the signal object based on the signal value.
[0081] The updating unit is further configured to update the update timestamp of the signal object based on the signal timestamp.
[0082] Further, the policy code generation apparatus further comprises:
[0083] A third judging unit is configured to judge whether the signal value and the current value of the signal object belong to the same category.
[0084] The recording unit is further configured to record the signal timestamp as a signal change timestamp when the signal value and the current value of the signal object do not belong to the same category.
[0085] Further, the policy code generation apparatus further comprises:
[0086] A second obtaining unit is configured to obtain a policy code corresponding to the signal object; the policy code at least comprises a first rule.
[0087] A fourth judging unit is configured to judge whether a precondition of the first rule is satisfied.
[0088] A verifying unit is configured to verify whether an expression statement of the first rule is true when the precondition of the first rule is satisfied.
[0089] An exciting unit is configured to excite a corresponding function emission sequence when the expression statement of the first rule is true.
[0090] Further, when the policy code further comprises a second rule, the policy code generation apparatus further comprises:
[0091] a fifth judging unit, configured to judge whether to continue rule evaluation after the triggering unit triggers the corresponding function emission sequence, or when the expression statement of the first rule is not established;
[0092] The fourth judging unit is further configured to judge whether the precondition of the second rule is satisfied when the rule evaluation is to be continued.
[0093] The verification unit is further configured to verify whether the expression statement of the second rule is established when the precondition of the second rule is satisfied.
[0094] The triggering unit is further configured to trigger the corresponding function emission sequence when the expression statement of the second rule is established.
[0095] Further, the indication unit is further configured to return a data processing success indication after the triggering unit triggers the corresponding function emission sequence.
[0096] The third aspect of the present application provides an electronic device, comprising a memory and a processor, the memory is used to store a computer program, and the processor runs the computer program to make the electronic device execute the policy code generation method in any one of the first aspect of the present application.
[0097] The fourth aspect of the present application provides a computer readable storage medium, which stores computer program instructions, and the computer program instructions are read and run by a processor to execute the policy code generation method in any one of the first aspect of the present application.
[0098] The beneficial effects of the present application are that: the method and device allow the developer to use formal statements to describe the policy and give the text output, and then interpret the policy into C language policy code through the code generation mechanism, which is used for the ECU. Among them, the use of formal statements can avoid the efficiency and accuracy problems caused by a large number of handwritten policy codes, and can also reduce the development difficulty of the developer based on more intuitive description. Therefore, the method and device can reduce the acquisition difficulty and debugging difficulty of the policy code, and can also improve the acquisition efficiency and accuracy of the policy code. BRIEF DESCRIPTION OF DRAWINGS
[0099] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings needed to be used in the embodiments of the present application will be briefly introduced as follows. It should be understood that the following drawings only show some of the embodiments of the present application, and therefore should not be regarded as a limitation on the scope, and for those of ordinary skill in the art, other related drawings can also be obtained without creative labor on the basis of these drawings.
[0100] Figure 1 A flowchart of a strategy code generation method provided by the embodiment of the present application is shown in the figure.
[0101] Figure 2 A schematic diagram of the quantity relationship between concepts and details provided by the embodiment of the present application is shown in the figure.
[0102] Figure 3 A flowchart of another strategy code generation method provided by the embodiment of the present application is shown in the figure.
[0103] Figure 4 A flowchart of still another strategy code generation method provided by the embodiment of the present application is shown in the figure.
[0104] Figure 5 A structural schematic diagram of a strategy code generation device provided by the embodiment of the present application is shown in the figure.
[0105] Figure 6 A structural schematic diagram of another strategy code generation device provided by the embodiment of the present application is shown in the figure. DETAILED DESCRIPTION
[0106] The technical solutions in the embodiments of the present application will be described in detail below with reference to the drawings in the embodiments of the present application.
[0107] It should be noted that: similar reference numerals and letters represent similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings. Meanwhile, in the description of the present application, the terms "first", "second", etc. are only used for distinguishing description, and cannot be understood as indicating or implying relative importance.
[0108] Embodiment 1
[0109] Please refer to Figure 1 , Figure 1 A flowchart of a strategy code generation method provided by the embodiment is shown in the figure. The strategy code generation method includes:
[0110] S101, a pre-defined formalized sentence is obtained, and the formalized sentence defines all concept details for policy execution.
[0111] In this embodiment, all concept details refer to all relevant content defined by the developer through formalized statements, including configuration conditions, signal names, signal values, resolutions, function names, tuples, rules, etc. These concept details are the basis for policy execution, and through them, the execution conditions, execution process, and execution results of a policy can be completely described.
[0112] S102, receive input data of the formalized statement, and generate corresponding formalized code based on the input data and the formalized statement.
[0113] S103, based on the formalized code, generate a containing relationship between the concept details.
[0114] In this embodiment, the containing relationship between the concept details refers to the containing or contained relationship between the various concepts defined (such as signals, functions, rules, etc.). For example, a rule can contain multiple signals as preconditions, a rule can trigger multiple functions, etc. This member containing relationship describes the logical connection and dependency relationship between different concepts, and is an important part of the policy execution logic.
[0115] Please refer to Figure 2 , Figure 2 The quantity relationship between the concept details is shown in the schematic diagram.
[0116] S104, expand the formalized rule code in the formalized code to obtain rule expansion code.
[0117] S105, based on the rule expansion code and the containing relationship between the concept details, fill in the concept details to obtain policy code.
[0118] In this embodiment, the execution subject of the method can be a computer, a server, or other computing devices, which are not limited in this embodiment.
[0119] In this embodiment, the execution subject of the method can also be a smart phone, a tablet computer, or other smart devices, which are not limited in this embodiment.
[0120] As can be seen, by implementing the policy code generation method described in this embodiment, the developer can intuitively describe the policy using formalized syntax, and automatically generate policy code for ECU, so that the difficulty of policy development is lower, the efficiency is improved, the debugging is more convenient, and the accuracy is higher.
[0121] Embodiment 2
[0122] Please refer to Figure 3 , Figure 3 A flowchart of a policy code generation method provided in this embodiment is shown. The policy code generation method includes:
[0123] S201, acquire all concept details for policy execution.
[0124] In this embodiment, the concept details include one or more of the following: signal name of the concept, signal identification value, period, timeout threshold, mathematical maximum value, mathematical minimum value, logical maximum value, logical minimum value, signal initial value, error value, rule set, mapping table, signal maximum enumeration value, function, function identification value, code block, code block identification value, and data structure.
[0125] In this embodiment, the concept details can also include configuration conditions, which are used to represent the premise of policy execution; that is, a specific vehicle model as a prerequisite for the execution of a specific policy.
[0126] The signal name in the concept details is used to identify internal original signals, external original signals, internal high-order data, external high-order signals, etc.
[0127] The signal value (all signal-related values) in the concept details is used to represent the corresponding value of all signals, integer, enumeration, etc.
[0128] The resolution in the concept details is used to represent the signal value type accuracy; wherein, signal value = original data * resolution.
[0129] The function name in the concept details is used to represent the function associated with the result generated after policy execution.
[0130] The tuple in the concept details contains a set of attribute values of the custom concept, which can be used by the rule.
[0131] In this embodiment, the rule is a description form of the policy; wherein, the policy code is the specific code related to the rule. At the same time, the policy code is applied to the pipeline: wherein, the pipeline refers to the pipeline code for executing the rule, which has fixed logic, and the change amount is described by the signal name and the configuration condition (for details, please refer to Embodiment 3).
[0132] S202, define formal statements based on pre-processing macro definition commands and concept details.
[0133] For example, the definition of the formal statement can refer to the following code content:
[0134]
[0135]
[0136]
[0137] S203, acquire a predefined formalized sentence, the formalized sentence defines all concept details for policy execution.
[0138] S204, receive input data of the formalized sentence, and generate corresponding formalized code based on the input data and the formalized sentence.
[0139] For example, the formalized code can be as follows:
[0140] ① FUNC_EOL (ACC, {LOW, DISABLE}, {MID, ENABLE}, {HIGH, ENABLE})
[0141] The formalized code defines the configuration condition of the policy, specifically, the high, medium and low three vehicle models are configured for the advanced cruise control function, at this time the policy is equipped only on the high and medium configuration vehicle models. It can be seen that this sentence can select the vehicle model configuration file through the code engineering construction system, complete the same engineering to support multiple vehicle models. Wherein ACC represents "Adaptive Cruise Control", that is, the adaptive cruise control system.
[0142] ② VAL_DEF (AIRBAG_ON, 1)
[0143] The formalized code defines the signal value type definition, which specifically defines the value as 1 when the airbag fault alarm function is activated.
[0144] ③ SIG_DEF (AIRBAG, AIRBAG_OFF, 100, 1000, AIRBAG_LOGIC_MIN, AIRBAG_LOGIC_MAX, AIRBAG_FLASH, COMMON_VBAD)
[0145] The formalized code defines the airbag fault signal, which specifically defines the signal name, internal simulation initial signal value, period, timeout, mathematical maximum value, mathematical minimum value, logic maximum value, logic minimum value, initial signal value, and error value.
[0146] ④ RULE_DEF (RULE_AIRBAG_HIT, PRE_COND, <statement>< FUNC_CASE_NAME >, … )
[0147] The formalized code defines a rule, specifically including giving a rule name, a precondition, an expression statement (rules can be nested referenced), and a rule trigger object. The "…" is a variable-length parameter, which can contain multiple FUNC_CASE_NAME, used to trigger multiple function objects.
[0148] ⑤CUSTOM_DEF(AIRBAG_HITCH_ATTR,AIRBAG_HITCH,…)
[0149] The formalized code defines a user-defined concept, specifically defining an airbag attribute type, and defining a concept variable for this type, followed by variable-length attribute parameter values, which need to be used by the user-defined expression statement in Rule.
[0150] ⑥RES_DEF(RES_XXX,1 / 10 / 100)
[0151] The formalized code defines a numerical resolution type for function definition.
[0152] ⑦FUNC_DEF(AIRBAG_ON,SIG_A,VAL_A,RES_AAA)
[0153] The formalized code defines a function function, which gives the name and the secondary signal output involved in the function.
[0154] S205, based on the formalized code, generating the inclusion relationship between the concept details.
[0155] S206, expanding the formalized rule code in the formalized code to obtain rule expansion code.
[0156] S207, based on the inclusion relationship between the concept details, obtaining the attribute tuple corresponding to the rule expansion code.
[0157] In this embodiment, the attribute tuple refers to a user-defined concept containing attribute values, which is used for rule use. In the formalized description, the attribute tuple can be used to further fill the concept details, and promote the generation of policy code.
[0158] S208, substituting the attribute tuple into the precondition and calculation expression in the rule expansion code to obtain the intermediate code.
[0159] S209, generating a function emission sequence in the intermediate code when the result of the calculation expression is true to obtain the policy code.
[0160] For example, the method can first define all concept details through formalized statements, and then generate related formalized codes such as signal type, value type, configuration condition, resolution, and further form the containing relationship between members of concepts. At this time, according to the RULE definition, the preconditions, calculation expressions, etc. are expanded, and the attribute tuple RULE expression is substituted in turn based on the above containing relationship, and the function transmission sequence when the expression is TURE is generated, so as to obtain the complete strategy code.
[0161] In this embodiment, the execution subject of the method can be a computer, a server, or other computing devices, which are not limited in this embodiment.
[0162] In this embodiment, the execution subject of the method can also be a smart phone, a tablet computer, or other smart devices, which are not limited in this embodiment.
[0163] It can be seen that by implementing the strategy code generation method described in this embodiment, the processes of defining formalized statements and the processes of defining interrelated and referenced processes can be refined, and the formalized language method can be applied to the strategy code generation process, so that the developer can intuitively describe the strategy by using the formalized syntax, and automatically generate the strategy code for the ECU, thereby making the strategy development more difficult, improving the efficiency, making the debugging more simple, and making the accuracy higher.
[0164] Embodiment 3
[0165] Please refer to Figure 4 , Figure 4 A flowchart of a strategy code generation method provided in this embodiment is shown. The strategy code generation method includes:
[0166] S301, receiving an input signal, the input signal including a corresponding signal identifier, a signal value, and a signal timestamp.
[0167] S302, matching a signal object corresponding to the signal identifier.
[0168] S303, determining whether the signal timestamp is before the update timestamp of the signal object, if yes, executing step S304; if no, executing step S305.
[0169] S304, returning a data processing error indication and ending the flow.
[0170] S305, determining whether the signal value is the same as the current value of the signal object, if yes, executing step S306; if no, executing step S307.
[0171] S306, updating the update timestamp of the signal object based on the signal timestamp, and returning a data processing success indication, and then ending the flow.
[0172] S307, record the current value of the signal object.
[0173] As an optional implementation, the method further comprises:
[0174] determining whether the signal value and the current value of the signal object belong to the same class;
[0175] when the signal value and the current value of the signal object do not belong to the same class, then record the signal timestamp as the signal change timestamp.
[0176] S308, update the current value of the signal object based on the signal value.
[0177] S309, update the update timestamp of the signal object based on the signal timestamp.
[0178] S310, obtain a policy code corresponding to the signal object; the policy code at least comprises a first rule.
[0179] In this embodiment, the generated policy code can be added to the pipeline processing process shown in this embodiment.
[0180] S311, determine whether the precondition of the first rule is met, if yes, execute step S312; if no, end the process.
[0181] S312, verify whether the expression statement of the first rule is true, if yes, execute step S313; if no, end the process.
[0182] S313, trigger the corresponding functional emission sequence.
[0183] As an optional implementation, when the policy code further comprises a second rule, after triggering the corresponding functional emission sequence, or when the expression statement of the first rule is not true, further comprising:
[0184] determine whether to continue the rule evaluation;
[0185] when the rule evaluation is to be continued, determine whether the precondition of the second rule is met;
[0186] when the precondition of the second rule is met, verify whether the expression statement of the second rule is true;
[0187] when the expression statement of the second rule is true, trigger the corresponding functional emission sequence.
[0188] S314, return a data processing success indication.
[0189] For example, the following pseudo code shows the key processing process in this embodiment:
[0190] / / pipeline processing procedure
[0191] ret_t deal(id_t id, val_t val, time_t ts) {
[0192] signal_t *psig = lut_find(id);
[0193] do {
[0194] if (ts < update(psig)) {
[0195] return RET_NOK;
[0196] }
[0197] if (val == get_val(psig)) {
[0198] ts_update(psig, ts);
[0199] return RET_OK;
[0200] } else {
[0201] old_val(psig, get_val(psig));
[0202] }
[0203] bool_t same_class = val_same_range(psig, val);
[0204] set_val(psig, val);
[0205] ts_update(psig, ts);
[0206] if (FALSE == same_class) {
[0207] ts_since(psig, ts);
[0208] }
[0209] } while (0);
[0210] rule_t *const *rules = get_rules(psig);
[0211] for (int idx = 0; NULL!= rules[idx]; ++idx) {
[0212] if (NULL!= rules[idx]->eval) {
[0213] rule_ret_t ret_eval = rules[idx]->eval();
[0214] if (RULE_EVAL_RET_TRUE_NEXT == ret_eval) {
[0215] rules[idx]->emit();
[0216] continue;
[0217] } else if (RULE_EVAL_RET_TRUE_STOP == ret_eval) {
[0218] rules[idx]->emit();
[0219] break;
[0220] } else if (RULE_EVAL_RET_FALSE_NEXT == ret_eval) {
[0221] continue;
[0222] } else if (RULE_EVAL_RET_FALSE_STOP == ret_eval) {
[0223] break;
[0224] }
[0225] } else {
[0226] break;
[0227] }
[0228] }
[0229] return RET_OK
[0230] It can be seen that the method can complete the whole process of triggering the policy code to automatically execute and emit the second-order signal by the three steps of signal generation, rule triggering and function emission.
[0231] In the embodiment, the execution subject of the method can be a computer, a server or other computing device, and the embodiment does not make any limitation on this.
[0232] In this embodiment, the execution subject of the method can also be a smart phone, a tablet computer or the like smart device, and the embodiment is not limited in this regard.
[0233] It can be seen that the policy code generation method described in this embodiment can detect the received data based on the pipeline mode, and automatically invoke the policy code for policy application when the conditions are met, so that the policy code can be applied in the vehicle.
[0234] Embodiment 4
[0235] Please refer to Figure 5 , Figure 5 A structural schematic diagram of a policy code generation device provided in this embodiment is shown in the figure. As shown in the figure, the policy code generation device comprises: Figure 5
[0236] The first acquisition unit 410 is configured to acquire a predefined formal statement, the formal statement defining all concept details for policy execution;
[0237] The first generation unit 420 is configured to receive input data of the formal statement, and generate corresponding formal code based on the input data and the formal statement;
[0238] The second generation unit 430 is configured to generate a containing relationship between the concept details based on the formal code;
[0239] The expansion unit 440 is configured to expand the formal rule code in the formal code to obtain rule expansion code;
[0240] The third generation unit 450 is configured to fill the concept details based on the rule expansion code and the containing relationship between the concept details, to obtain the policy code.
[0241] In this embodiment, the explanation and description of the policy code generation device can refer to the description in Embodiment 1, Embodiment 2 or Embodiment 3, and the embodiment will not be described again.
[0242] It can be seen that the policy code generation device described in this embodiment can allow the developer to intuitively describe the policy by using the formal grammar, and automatically generate the policy code for use by the ECU, so that the difficulty of policy development is lower, the efficiency is improved, the debugging is more convenient, and the accuracy is higher.
[0243] Embodiment 5
[0244] Please refer to Figure 6 , Figure 6 A structural schematic diagram of a policy code generation device provided in this embodiment is shown in the figure. As shown in the figure, the policy code generation device comprises: Figure 6
[0245] The first obtaining unit 410 is configured to obtain a predefined formal statement, the formal statement defining all concept details for policy execution.
[0246] The first generating unit 420 is configured to receive input data of the formal statement, and generate corresponding formal code based on the input data and the formal statement.
[0247] The second generating unit 430 is configured to generate a containing relationship between the concept details based on the formal code.
[0248] The expanding unit 440 is configured to expand the formal rule code in the formal code to obtain rule expansion code.
[0249] The third generating unit 450 is configured to fill the concept details based on the rule expansion code and the containing relationship between the concept details to obtain policy code.
[0250] As an optional implementation, the third generating unit 450 includes:
[0251] The obtaining sub-unit 451 is configured to obtain an attribute tuple corresponding to the rule expansion code based on the containing relationship between the concept details.
[0252] The substituting sub-unit 452 is configured to substitute the attribute tuple into the precondition and the calculation expression in the rule expansion code to obtain intermediate code.
[0253] The generating sub-unit 453 is configured to generate a function emission sequence when the result of the calculation expression is true in the intermediate code to obtain the policy code.
[0254] As an optional implementation, the policy code generation apparatus further includes:
[0255] The first obtaining unit 410 is further configured to obtain all concept details for policy execution.
[0256] The defining unit 460 is configured to define the formal statement based on a preprocessing macro definition command and the concept details.
[0257] In this embodiment, the concept details include one or more of a concepted signal name, a signal identification value, a period, a timeout threshold, a mathematical maximum value, a mathematical minimum value, a logic maximum value, a logic minimum value, a signal initial value, an error value, a rule set, a mapping table, a signal maximum enumeration value, a function, a function identification value, a code block, a code block identification value, and a data structure.
[0258] As an optional implementation, the policy code generation apparatus further includes:
[0259] The receiving unit 470 is configured to receive an input signal, the input signal comprising a corresponding signal identifier, a signal value and a signal timestamp;
[0260] The matching unit 480 is configured to match a signal object corresponding to the signal identifier;
[0261] The first judging unit 490 is configured to judge whether the signal timestamp is before an update timestamp of the signal object;
[0262] The indicating unit 500 is configured to return a data processing error indication when the signal timestamp is before the update timestamp of the signal object.
[0263] As an optional implementation, the policy code generation apparatus further comprises:
[0264] The second judging unit 510 is configured to judge whether the signal value is the same as a current value of the signal object when the signal timestamp is not before the update timestamp of the signal object;
[0265] The updating unit 520 is configured to update the update timestamp of the signal object based on the signal timestamp and return a data processing success indication when the signal value is the same as the current value of the signal object.
[0266] As an optional implementation, the policy code generation apparatus further comprises:
[0267] The recording unit 530 is configured to record the current value of the signal object when the signal value is not the same as the current value of the signal object.
[0268] The updating unit 520 is further configured to update the current value of the signal object based on the signal value.
[0269] The updating unit 520 is further configured to update the update timestamp of the signal object based on the signal timestamp.
[0270] As an optional implementation, the policy code generation apparatus further comprises:
[0271] The third judging unit 540 is configured to judge whether the signal value and the current value of the signal object belong to the same category.
[0272] The recording unit 530 is further configured to record the signal timestamp as a signal change timestamp when the signal value and the current value of the signal object do not belong to the same category.
[0273] As an optional implementation, the policy code generation apparatus further comprises:
[0274] The second obtaining unit 550 is configured to obtain a policy code corresponding to the signal object; the policy code at least comprises a first rule.
[0275] The fourth judging unit 560 is configured to judge whether the precondition of the first rule is satisfied.
[0276] The verifying unit 570 is configured to verify whether the expression statement of the first rule is true when the precondition of the first rule is satisfied.
[0277] The triggering unit 580 is configured to trigger the corresponding functional emission sequence when the expression statement of the first rule is true.
[0278] As an optional implementation, when the policy code further comprises a second rule, the policy code generation apparatus further comprises:
[0279] The fifth judging unit 590 is configured to judge whether to continue the rule evaluation after the triggering unit 580 triggers the corresponding functional emission sequence, or when the expression statement of the first rule is not true.
[0280] The fourth judging unit 560 is further configured to judge whether the precondition of the second rule is satisfied when the rule evaluation is to be continued.
[0281] The verifying unit 570 is further configured to verify whether the expression statement of the second rule is true when the precondition of the second rule is satisfied.
[0282] The triggering unit 580 is further configured to trigger the corresponding functional emission sequence when the expression statement of the second rule is true.
[0283] As an optional implementation, the indicating unit 500 is further configured to return the data processing success indication after the triggering unit 580 triggers the corresponding functional emission sequence.
[0284] In this embodiment, the explanation and description of the policy code generation apparatus can refer to the description in Embodiment 1, Embodiment 2 or Embodiment 3, and the description will not be repeated herein.
[0285] It can be seen that the policy code generation apparatus described in this embodiment can allow the developer to intuitively describe the policy by using the formal grammar, and automatically generate the policy code for the ECU, so that the difficulty of policy development is lower, the efficiency is improved, the debugging is more convenient, and the accuracy is higher.
[0286] The electronic device provided in the embodiment of the present application comprises a memory and a processor, the memory is configured to store a computer program, and the processor is configured to run the computer program to enable the electronic device to execute the policy code generation method in Embodiment 1, Embodiment 2 or Embodiment 3 of the present application.
[0287] The embodiment of the present application provides a computer readable storage medium, which stores computer program instructions, and when the computer program instructions are read and run by a processor, the strategy code generation method in the embodiment 1, the embodiment 2 or the embodiment 3 is executed.
[0288] In several embodiments provided in the present application, it should be understood that the disclosed apparatus and method can also be implemented by other manners. The apparatus embodiment described above is only schematic, for example, the flow chart and the block diagram in the drawings show the possible implementation architecture, function and operation of the apparatus, method and computer program product according to the embodiments of the present application. In this regard, each block in the flow chart or the block diagram can represent a module, a program segment or a part of code, which contains one or more executable instructions for implementing the specified logic function. It should also be noted that, in some alternative implementation manners, the functions noted in the blocks can also occur in different order from that noted in the drawings. For example, two consecutive blocks can actually be executed substantially in parallel, and sometimes they can also be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or the flow chart, and the combination of the blocks in the block diagram and / or the flow chart, can be implemented by a dedicated hardware-based system for implementing the specified function or action, or can be implemented by a combination of special-purpose hardware and computer instructions.
[0289] In addition, each functional module in the embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0290] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer readable storage medium. Based on such understanding, the technical solutions of the present application can be embodied in the form of a software product, and the computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the embodiments of the present application. The foregoing storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0291] The above merely provides an example of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, and thus, once an item is defined in one drawing, it need not be further defined and explained in subsequent drawings.
[0292] The above merely provides an example of the present application and is not intended to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, and thus, once an item is defined in one drawing, it need not be further defined and explained in subsequent drawings.
[0293] It should be noted that the relational terms herein such as first and second and the like are used solely to distinguish one from another entity or action without necessarily requiring or implying any actual relationship or order between such entities or actions. Moreover, the terms "comprises", "comprising", or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but can include other elements not expressly listed or inherent to such process, method, article, or apparatus. An element proceeded by "comprises... a" does not, without more constraints, exclude the existence of additional identical elements in the process, method, article, or apparatus that comprises the element.< / statement>
Claims
1. A method of policy code generation, characterized by, The method comprises: acquiring a predefined formalized statement, the formalized statement defining all concept details for policy execution; wherein the concept details include one or more of a conceptual signal name, a signal identification value, a period, a timeout threshold, a mathematical maximum value, a mathematical minimum value, a logical maximum value, a logical minimum value, a signal initial value, an error value, a rule set, a mapping table, a signal maximum enumeration value, a function, a function identification value, a code block, a code block identification value, and a data structure; receiving input data of the formalized statement, and generating corresponding formalized code based on the input data and the formalized statement; generating a containing relationship between the concept details based on the formalized code; expanding formalized rule code in the formalized code to obtain rule expansion code; performing concept detail filling based on the rule expansion code and the containing relationship between the concept details to obtain policy code.
2. The policy code generation method of claim 1, wherein, The concept detail filling based on the rule expansion code and the containing relationship between the concept details to obtain policy code comprises: acquiring an attribute tuple corresponding to the rule expansion code based on the containing relationship between the concept details; substituting the attribute tuple into antecedent conditions and calculation expressions in the rule expansion code to obtain intermediate code; generating a function emission sequence in the intermediate code when a result of the calculation expression is true to obtain policy code.
3. The policy code generation method of claim 1, wherein, The method further comprises: acquiring all concept details for policy execution; defining a formalized statement based on a preprocessing macro definition command and the concept details.
4. The method of claim 1, wherein, The method further comprises: receiving an input signal, the input signal including a corresponding signal identifier, a signal value, and a signal timestamp; matching a signal object corresponding to the signal identifier; determining whether the signal timestamp is before an update timestamp of the signal object; when the signal timestamp is before the update timestamp of the signal object, returning a data processing error indication.
5. The method of claim 4, wherein, The method further comprises: when the signal timestamp is not before the update timestamp of the signal object, determining whether the signal value is the same as a current value of the signal object; when the signal value is the same as the current value of the signal object, updating the update timestamp of the signal object based on the signal timestamp, and returning a data processing success indication.
6. The method of claim 5, wherein, The method further comprises: when the signal value is not the same as the current value of the signal object, recording the current value of the signal object; updating the current value of the signal object based on the signal value; updating the update timestamp of the signal object based on the signal timestamp.
7. The policy code generation method of claim 6, wherein, The method further comprises: determining whether the signal value and the current value of the signal object belong to the same category; when the signal value and the current value of the signal object do not belong to the same category, recording the signal timestamp as a signal change timestamp.
8. The method of claim 6, wherein, The method further comprises: acquiring policy code corresponding to the signal object; the policy code at least including a first rule; determining whether an antecedent condition of the first rule is satisfied; when the antecedent condition of the first rule is satisfied, verifying whether an expression statement of the first rule is true; When the expression statement of the first rule is true, a corresponding functional emission sequence is triggered.
9. The method of claim 8, wherein, When the policy code further comprises a second rule, the triggering of the corresponding functional emission sequence is followed by, or when the expression statement of the first rule is not true, further comprising: determining whether to continue rule evaluation; when the rule evaluation is to be continued, determining whether the precondition of the second rule is satisfied; when the precondition of the second rule is satisfied, verifying whether the expression statement of the second rule is true; when the expression statement of the second rule is true, triggering a corresponding functional emission sequence.
10. The method of claim 8, wherein, The triggering of the corresponding functional emission sequence is followed by, further comprising: returning a data processing success indication.
11. A policy code generation apparatus characterized by comprising: The policy code generation apparatus comprises: a first acquisition unit configured to acquire a predefined formal statement, the formal statement defining all conceptual details for policy execution; wherein the conceptual details comprise one or more of a conceptual signal name, a signal identification value, a period, a timeout threshold, a mathematical maximum value, a mathematical minimum value, a logical maximum value, a logical minimum value, a signal initial value, an error value, a rule set, a mapping table, a signal maximum enumeration value, a function, a function identification value, a code block, a code block identification value, and a data structure; a first generation unit configured to receive input data of the formal statement, and generate a corresponding formal code based on the input data and the formal statement; a second generation unit configured to generate a containing relationship between the conceptual details based on the formal code; an unfolding unit configured to unfold a formal rule code in the formal code to obtain a rule unfolded code; a third generation unit configured to perform conceptual detail filling based on the rule unfolded code and the containing relationship between the conceptual details to obtain a policy code.
12. An electronic device, comprising: The electronic device comprises a memory and a processor, the memory is configured to store a computer program, and the processor is configured to run the computer program to enable the electronic device to perform the policy code generation method in any one of claims 1 to 10.
13. A readable storage medium, characterized by, The readable storage medium stores computer program instructions, and the computer program instructions are read and run by a processor to perform the policy code generation method in any one of claims 1 to 10.
Citation Information
Patent Citations
Carrier rocket test data interpretation method and system based on formalized description
CN109582692A