Code generation and compiling method and model for TLV data, and electric energy meter system

By generating model files and code generators, it solves the inconvenience of writing and data storage of uplink communication codes at power terminals, and realizes storage format consistency, saves storage space and improves code stability.

CN120215924APending Publication Date: 2025-06-27QINGDAO ITECHENE TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510283225.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-11
Publication Date
2025-06-27

AI Technical Summary

Technical Problem

The prior art has inconveniences in writing, data analysis and storage of uplink communication codes of power terminals, including inconsistent storage formats, waste of data, and inability to verify data formats. Manual encoding consumes manpower and is prone to errors, and the quality of code generation in large models is unstable.

Method used

Generate model files through protocol documents, use code generators to convert the data structures in the model files into type strings, and generate source code, and finally generate executable programs to implement protocol parsing and processing.

Benefits of technology

It realizes the consistency of storage formats, saves storage space, ensures data format verification, reduces manual encoding time, improves code stability, and supports automatic generation of test cases and adapts to modifications of different protocols.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120215924A_ABST
    Figure CN120215924A_ABST
Patent Text Reader

Abstract

The invention relates to a code generating and compiling method and model for TLV data and an electric energy meter system. S1, generating a model file through the protocol document; s2, code generation; firstly, a data structure in a model file is converted into a type character string; a code generator that then converts the non-data structure into a source code; s3, a final executable program is generated through the source code, and the purpose of protocol analysis and processing is achieved; the device is reasonable in design, compact in structure and convenient to use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a method and model for code generation and compilation for TLV data, and an electric energy meter system. Background Art

[0002] In current power terminals, there are many inconveniences in the code writing, data parsing and storage of upstream communication. In power industry terminals, although the upstream communication protocols in various countries and regions have some commonalities, they are not completely consistent. When dealing with diverse requirements using existing tools, development models, and development manpower, it is stretched thin.

[0003] For example, when storing data, it is usually to directly save the C structure to FLASH or the database according to the memory structure, but this method has the following disadvantages:

[0004] 1) It cannot ensure the consistency of storage formats on different devices (for example, for the same INT16U integer 0x1234, the memory structure is 1234 on a big-endian device, but 3412 on a little-endian device); 2) When the data is variable-length, there is data waste (for example, a string with a maximum length of 128 bytes needs to occupy 128 bytes when stored as a structure); 3) It is impossible to verify whether the data format is correct.

[0005] When writing code and parsing data, it is usually to manually code for each OAD and / or OMD to convert the C structure into the DLMS or DL / T698.45 format, but this method has the following disadvantages: 1) The workload is large and it consumes a lot of manpower; 2) It is error-prone; 3) Test case personnel need to write specifically, and the quality of test cases cannot be guaranteed; 4) Different code libraries need to be rewritten for different protocols.

[0006] When writing code and parsing data, there is also a method of using a large model to generate code, but this method has the following disadvantages: 1) The quality of the output code of the current large model cannot be guaranteed, and there are often various BUGs; 2) The output stability cannot be guaranteed: that is, for the same input, the large model cannot guarantee the same output.

[0007] Explanation of Proprietary Terms:

[0008] Industry Common Concepts (refer to DLMS or DLT698.45):

[0009] Terminal: Refers to power equipment such as concentrators, dedicated transformer terminals, and integrated terminals operating in the power system. Its main function is to collect meters in the power system according to the configuration and upload the data to the communication master station as required.

[0010] DLMS (Device Language Message Specification): DLMS is a protocol standard widely adopted by global electricity meters, water meters, and gas meters.

[0011] Object - Oriented Protocol (DL / T698.45): It refers to the power industry standard DL / T 698.45 - 2017 and the enterprise standard of State Grid Corporation of China Q / GDW 11778 - 2017. This is a communication protocol for the power system with Chinese characteristics based on DLMS.

[0012] Object: In this article, it specifically refers to the data objects in power terminals, such as voltage, current, etc. It contains several attributes and methods.

[0013] Object Identification (OI): The unique name encoding that identifies objects in power terminals. For example, 2000H is used to represent voltage and 2001H is used to represent current.

[0014] Object Attribute Descriptor (OAD): The unique name encoding that represents object attributes. It consists of three parts: OI, attribute, and index. For example, the phased data block (attribute 2) of object voltage (2000H) can be represented by 20000200H, and the voltage of phase A (the first member of the voltage phased data block) can be represented by 20000201H.

[0015] Object Method Descriptor (OMD): The unique name encoding that represents the operable methods of objects. When operating on object methods, parameters can be passed in and return values can be obtained.

[0016] Interface Class (IC): Objects with shared common characteristics can be grouped into an interface class. For example, objects such as voltage and current that have phases can be grouped into the phased variable class. Summary of the Invention

[0017] Generally speaking, the technical problem to be solved by the present invention is to provide a method and model for code generation and compilation for TLV data, and an electric energy meter system. The present invention aims at the idea of automatic code generation for DLT698 and DLMS protocols, the file format of model files, the format of type strings, and the parsing / execution method.

[0018] To solve the above problems, the technical solutions adopted by the present invention are:

[0019] A method for code generation and compilation for TLV data, characterized in that the method comprises the following steps;

[0020] S1. Generate a model file through a protocol document;

[0021] S2. Code generation; First, convert the data structure in the model file into a type string; Then, a code generator that converts non-data structures into source code;

[0022] S3. Generate a final executable program through the source code to achieve the purpose of protocol parsing and processing.

[0023] Further, in step S1, during model file generation; the following steps are executed;

[0024] S1-1. First, determine whether the user has an AI large model running environment; if so, process the original protocol file through the AI large model and generate a model file; otherwise, execute S1-2;

[0025] S1-2. First, determine whether the user has a model generation tool with a graphical interface; if so, manually read the original protocol file and generate a model file by dragging and dropping through the user interface; otherwise, execute S1-3;

[0026] S1-3. First, manually read the original protocol file; then, write the model file.

[0027] Further, in step S2, the following steps are executed;

[0028] S2.1. The code generator parses the input parameters to obtain parsing options and the model file to be parsed;

[0029] S2.2. Traverse the model file. If all model files have been traversed, execute step S2.3; otherwise, execute S2.2.1 to parse each model file;

[0030] S2.2.1. Parse the model file and convert it into an xml tree structure in memory;

[0031] S2.2.2. Traverse the xml tree to obtain all interface classes and / or object identifiers, and all OADs and / or OMDs associated with the interface classes and / or object identifiers;

[0032] S2.2.3. First, convert the type and subtype nesting relationship of each OAD and / or OMD into a type string; then, return the type string to step S2.2 for re-judgment;

[0033] S2.3. Reconstruct the correspondence between objects and interface classes, and associate objects with the interface classes they inherit;

[0034] S2.4, Generate the C language structure definitions corresponding to each OAD and / or OMD;

[0035] S2.5, Generate the C language model initialization code, traverse the interface classes, and determine whether all interface classes have been traversed; if all have been traversed, execute step S2.6; otherwise, execute step S2.5.1;

[0036] S2.5.1, Traverse the attributes of the interface class, and write the interface class initialization code and the type string of the corresponding OAD into the source code;

[0037] S2.5.2, Traverse the interface class methods, and write the interface class initialization code and the type strings of the incoming parameters and return values of the corresponding OMD into the source code;

[0038] S2.5.3, Traverse all object identifiers associated with the interface class, and convert the attributes and methods of the object identifiers and write them into the source code;

[0039] S2.6, Generate common components; the common components include a data storage interface and / or an uplink communication protocol parser;

[0040] S2.7, Generate test cases and test code.

[0041] 4. The code generation and compilation method for TLV data according to claim 1, characterized in that: in step S3; the following steps are executed;

[0042] S3.1, Compile the test code to generate a test program;

[0043] S3.2, Run the test program to verify whether all test cases can pass;

[0044] S3.3, Integrate the source code generated in step S2 with the production environment test;

[0045] S3.4, Compile the integrated source code into an executable program to generate the executable program.

[0046] Furthermore, after step S3, when a frame of application layer message is received, the processing flow is as follows:

[0047] S4, Uplink protocol parsing;

[0048] S4.1, Parse the DLMS or DLT698 message to obtain the data unit PDU;

[0049] S4.2, First, parse the data unit PDU; then make a judgment; for non-parameter setting or non-parameter reading or non-operation messages, perform user-defined processing;

[0050] S4.3, Group Response Frame;

[0051] S4.4, Return the response frame to the master station.

[0052] Furthermore, in step S S4.2;

[0053] For non-parameter settings, execute step S4.2.set;

[0054] For non-parameter reading, execute step S4.2.get;

[0055] For non-operation messages, execute step S4.2.act.

[0056] Furthermore, when executing step S4.2.set;

[0057] S4.2.set.1, Parse the OAD and Data from the setting message;

[0058] S4.2.set.2, Load the type string corresponding to the OAD;

[0059] S4.2.set.3, Perform format verification on the Data according to the type string;

[0060] S4.2.set.4, Judge whether the verification is successful;

[0061] S4.2.set.4.Y, If successful, save it to the database or FLASH and return success;

[0062] S4.2.set.4.N, Otherwise, return type mismatch;

[0063] When executing step S4.2.get;

[0064] S4.2.get.1, Parse the OAD from the reading message;

[0065] S4.2.get.2, Load the Data corresponding to the OAD from the database or FLASH;

[0066] S4.2.get.3, Return the loaded Data;

[0067] When executing step S4.2.act;

[0068] S4.2.act.1, Parse the parameters in the form of OMD and / or Data from the operation message;

[0069] S4.2.act.2, Load the type string of the parameters and return values corresponding to the OMD, as well as the execution callback function of the OMD;

[0070] S4.2.act.3, convert the parameter into the C structure format according to the type string of the parameter;

[0071] S4.2.act.4, call the callback function and pass in the parameter in the C structure format;

[0072] S4.2.act.5, convert the return value of the callback function into the Data format according to the type string of the return value;

[0073] S4.2.act.6, return the return value of the callback function in the Data format.

[0074] A code generation and compilation model for TLV data is built based on the above method.

[0075] An electric energy meter system is equipped with the above model.

[0076] The present invention ensures storage consistency. The format in memory may change, but the format is determined and unchanged after being converted into the Data stored in the FLASH. The present invention saves storage space. The data format verification during reading and writing of the present invention ensures consistency with the expected data format. Compared with manual coding, the present invention generates code quickly and saves labor. The present invention has good stability: for a determined protocol or model file, the output is determined code. The test cases of the present invention can be automatically generated. For different but similar-format protocols, the present invention can be adapted by only modifying part of the model file. Brief Description of the Drawings

[0077] Figure 1 It is a schematic diagram of the overall process of the present invention.

[0078] Figure 2 It is a schematic structural diagram of the present invention.

[0079] Figure 3 It is a schematic structural diagram of the present invention.

[0080] Figure 4 It is a schematic structural diagram of the present invention.

[0081] Figure 5 It is a schematic diagram of the usage structure of the present invention. Detailed Embodiments

[0082] As Figures 1-5 , the present invention proposes a method and a model, including the following steps;

[0083] S1, generate a model file through a protocol document;

[0084] S2, code generation; First, convert the data structure in the model file into a type string; then, convert the non-data structure into a code generator for source code;

[0085] S3. Generate the final executable program through the source code to achieve the purpose of protocol parsing and processing.

[0086] S1. Model file generation; specifically, such as Figure 2 ;

[0087] S1-1. First, determine whether the user has an AI large model running environment; if so, process the original protocol file through the AI large model and generate a model file; otherwise, execute S1-2.

[0088] S1-2. First, determine whether the user has a model generation tool with a graphical interface; if so, manually read the original protocol file and generate a model file by dragging and dropping through the user interface; otherwise, execute S1-3.

[0089] S1-3. First, manually read the original protocol file provided by the power grid company; then, write the model file manually or through AI.

[0090] S2. Code generation, convert the model file into source code; such as Figure 3 ;

[0091] S2.1. The code generator parses the input parameters to obtain the parsing options and the model file to be parsed.

[0092] S2.2. Traverse the model file. If all model files have been traversed, execute step S2.3; otherwise, execute S2.2.1 to parse each model file.

[0093] S2.2.1. Parse the model file and convert it into an xml tree structure in memory.

[0094] S2.2.2. Traverse the xml tree to obtain all interface classes and / or object identifiers, and all OADs and / or OMDs associated with the interface classes and / or object identifiers.

[0095] S2.2.3. First, convert the nesting relationship of the type and subtype of each OAD and / or OMD into a type string; then, return the type string to step S2.2 for rejudgment.

[0096] S2.3. Reconstruct the correspondence between objects and interface classes, and associate the objects with the interface classes inherited by the objects.

[0097] S2.4. Generate the C language structure definition corresponding to each OAD and / or OMD.

[0098] S2.5, Generate the initialization source code of the C language model, traverse the interface classes, and determine whether all interface classes have been traversed; if all have been traversed, execute step S2.6; otherwise, execute step S2.5.1;

[0099] S2.5.1, Traverse the attributes of the interface class, and write the interface class initialization code and the type string of the corresponding OAD into the source code in S2.5;

[0100] S2.5.2, Traverse the interface class methods, and write the interface class initialization code and the type strings of the input parameters and return values of the corresponding OMD into the source code in S2.5;

[0101] S2.5.3, Traverse all object identifiers associated with the interface class, and convert the attributes and methods of the object identifiers and write them into the source code in S2.5; as described in S2.5.1 and S2.5.2;

[0102] S2.6, Generate common components; the common components include a data storage interface and / or an uplink communication protocol parser; copy the common components to the database;

[0103] S2.7, Generate test cases and test code;

[0104] S3, Generate an executable program, generate an executable program from the source code;

[0105] S3.1, Compile the test code to generate a test program;

[0106] S3.2, Run the test program to verify whether all test cases can pass;

[0107] S3.3, Integrate the source code generated in step S2 with the production environment test, that is, copy it into the source code of the production environment;

[0108] S3.4, Compile the integrated source code into an executable program to generate the executable program;

[0109] When implementing the present invention, when receiving a frame of application layer message, the processing flow is as follows:

[0110] S4, Uplink protocol parsing;

[0111] S4.1, Parse the DLMS or DLT698 message to obtain the data unit PDU;

[0112] S4.2, First, parse the data unit PDU; then make a judgment; for non-parameter setting or non-parameter reading or non-operation messages, perform user-defined processing;

[0113] For non-parameter setting, execute step S4.2.set;

[0114] For non-parametric reading, execute step S4.2.get;

[0115] For non-operation messages, execute step S4.2.act;

[0116] When executing step S4.2.set;

[0117] S4.2.set.1, for the setting message, parse out OAD and Data;

[0118] S4.2.set.2, load the type string corresponding to the OAD;

[0119] S4.2.set.3, perform format verification on Data according to the type string;

[0120] S4.2.set.4, judge whether the verification is successful;

[0121] S4.2.set.4.Y, if successful, save it to the database or FLASH and return success;

[0122] S4.2.set.4.N, otherwise, return type mismatch;

[0123] When executing step S4.2.get;

[0124] S4.2.get.1, for the reading message, parse out OAD;

[0125] S4.2.get.2, load the Data corresponding to the OAD from the database or FLASH;

[0126] S4.2.get.3, return the loaded Data;

[0127] When executing step S4.2.act;

[0128] S4.2.act.1, for the operation message, parse out the parameters in the format of OMD and / or Data;

[0129] S4.2.act.2, load the type string of the parameters and return values corresponding to the OMD, as well as the execution callback function of the OMD;

[0130] S4.2.act.3, convert the parameters into the C structure format according to the type string of the parameters;

[0131] S4.2.act.4, call the callback function and pass in the parameters in the C structure format;

[0132] S4.2.act.5, according to the type string of the return value, convert the return value of the callback function into the Data format;

[0133] S4.2.act.6, return the return value of the callback function in Data format;

[0134] S4.3, group response frame;

[0135] S4.4, return the response frame to the master station.

[0136] A code generation and compilation model for TLV data, built based on the above method.

[0137] A system equipped with the above system.

[0138] The present invention is fully described for clearer disclosure, and the prior art will not be listed one by one.

[0139] Nomenclature in the present invention:

[0140] Model file: In this article, it specifically refers to a custom xml format file used to describe the data structures of interface classes, object identifiers, object attributes, object methods and their corresponding relationships.

[0141] Code generation: In this article, code generation specifically refers to the process of converting the input model file into a C language source file, and the code generator specifically refers to the software that executes this process.

[0142] Virtual machine: In this article, it specifically refers to a program that runs type strings (TypeString). Similar to the Java virtual machine.

[0143] Type string (typeString): A custom byte stream, similar to the bytecode of Java, used to describe the data types and structures of OAD, or the data types and structures of the incoming parameters of OMD, or the data types and structures of the return values of OMD.

[0144] Data data type: A self-parsing data format in TLV format defined by DLMS (or DL / T 698.45). In this article, when "Data" or "Data data type" appears alone, it specifically refers to this data type. For its definition, please refer to Section 7.3.1 of "Object-Oriented Power Usage Information Data Exchange Protocol (20220130).pdf" (DL / T 698.45-2017) or Section 4.3.1 of "DLMS Blue Book Edition 14".

[0145] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than limiting them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; as those skilled in the art, it is obvious to combine multiple technical solutions of the present invention. These modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. The technical content not described in detail in the present invention is well-known technology.

Claims

1. A code generation and compilation method for TLV data, characterized in that: The method comprises the following steps: S1, generate model files through protocol documents; S2, code generation; first, the data structures in the model file are converted into type strings; then, the code generator that converts non-data structures into source code; S3, generates the final executable program through the source code to complete the purpose of protocol parsing and processing.

2. The code generation and compilation method for TLV data according to claim 1, characterized in that: In step S1, the model file is generated; Follow these steps; S1-1, first, determine whether the user has an AI big model operating environment; if yes, process the original protocol file through the AI ​​big model and generate a model file; otherwise, execute S1-2; S1-2. First, determine whether the user has a model generation tool with a graphical interface; if so, manually read the original protocol file and generate a model file by dragging and dropping the user interface; otherwise, execute S1-3; S1-3, first, manually read the original protocol file; then, write the model file.

3. The code generation and compilation method for TLV data according to claim 1, characterized in that: In step S2, the following steps are performed: S2.1, the code generator parses the input parameters, obtains the parsing options and the model file to be parsed; S2.2, traverse the model files. If all model files have been traversed, execute step S2.3; Otherwise, execute S2.2.1 to parse each model file; S2.2.1, parse the model file and convert the XML tree structure in memory; S2.2.2, traverse the XML tree, obtain all interface classes and / or object identifiers, and the OADs and / or OMDs associated with all interface classes and / or object identifiers; S2.2.3, first, convert the type of each OAD and / or OMD and the nested relationship of the subtype into a type string; then, return the type string to step S2.2 for further judgment; S2.3, rebuild the correspondence between the object and the interface class, and associate the object with the interface class inherited by the object; S2.4, generating a C language structure definition corresponding to each OAD and / or OMD; S2.5, generate C language model initialization source code, traverse the interface classes, and determine whether all interface classes have been traversed; if they have been traversed, execute step S2.6; Otherwise, execute step S2.5.1; S2.5.1, traverse the attributes of the interface class, and write the interface class initialization code and the corresponding OAD type string into the source code in S2.5; S2.5.2, traverse the interface class methods, and write the interface class initialization code and the type string of the corresponding OMD input parameters and return values ​​into the source code; S2.5.3, traverse all object identifiers associated with the interface class, convert the attributes and methods of the object identifiers, and write them into the source code; S2.6, generating common components; the common components include data storage interfaces and / or uplink communication protocol parsing; S2.7, generate test cases and test codes.

4. The code generation and compilation method for TLV data according to claim 1, characterized in that: In step S3; Follow these steps; S3.1, compile the test code and generate the test program; S3.2, run the test program to verify whether all test cases can be passed; S3.3, integrating the source code generated in step S2 with the production environment test; S3.4, compile the integrated source code into an executable program to generate an executable program.

5. The code generation and compilation method for TLV data according to claim 1, characterized in that: After step S3, when a frame of application layer message is received, the processing flow is as follows: S4, uplink protocol analysis; S4.1, parse DLMS or DLT698 message and obtain data unit PDU; S4.2, first, the data unit PDU is parsed; then judgment is made; user-defined processing is performed on non-parameter setting or non-parameter reading or non-operation messages; S4.3, group response frame; S4.4, returns the response frame to the master station.

6. The code generation and compilation method for TLV data according to claim 1, characterized in that: In step SS4.2; For non-parameter settings, execute step S4.2.set; For non-parameter reading, execute step S4.2.get; For non-operation messages, execute step S4.2.act.

7. The code generation and compilation method and model for TLV data and the electric energy meter system according to claim 6 are characterized in that: When executing step S4.2.set; S4.2.set.1, parse the setting message to get OAD and Data; S4.2.set.2, load the type string corresponding to OAD; S4.2.set.3, perform format check on Data according to the type string; S4.2.set.4, determine whether the verification is successful; S4.2.set.4.Y, if successful, save to database or FLASH and return success; S4.2.set.4.N, otherwise, the return type does not match; When executing step S4.2.get; S4.2.get.1, parse the OAD from the read message; S4.2.get.2, load the corresponding OAD data from the database or FLASH; S4.2.get.3, returns the loaded Data; When executing step S4.2.act; S4.2.act.1, parse the operation message to obtain parameters in OMD and / or Data format; S4.2.act.2, load the type string of the corresponding OMD parameters and return values, as well as the execution callback function of OMD; S4.2.act.3, convert the parameter into a C structure format according to the parameter type string; S4.2.act.4, call the callback function and pass in the parameters in C structure format; S4.2.act.5, convert the return value of the callback function into Data format according to the type string of the return value; S4.2.act.6, returns the callback function return value in Data format.

8. A code generation and compilation model for TLV data, characterized in that: Built based on the method described in claim 1.

9. An electric energy meter system, characterized in that: The model according to claim 8 is mounted thereon.