Code generation method for converting interface parameters based on spreadsheet
Through the conversion interface parameter code generation method based on spreadsheets, the problem of frequent parameters adjustment in the instruction calculation software testing tool is solved, automatic parameter conversion and interaction is realized, the adaptability and accuracy of the test tool is improved, and debugging time is saved.
Patent Information
- Application Number
- CN202510291141.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-12
- Publication Date
- 2025-07-11
AI Technical Summary
In the prior art, the input parameters and output parameters protocols of the instruction calculation software are frequently changed, resulting in a large number of adjustments to the interface parameters of the test tool, which increases the workload and is prone to errors. In addition, a large number of code changes are required during software upgrades, affecting the stability of the software.
The code for converting interface parameters is generated by using a spreadsheet-based method, the interface parameter specification file is generated by reading the interface protocol file, the conversion code is generated by using macro functions, and the variable definition file of the test tool is encapsulated to realize the automatic conversion and interaction of parameters.
It reduces the workload of manually compiling interface codes, improves the accuracy and adaptability of parameter conversion, saves the debugging time of the test tool, and improves the testing efficiency.
Smart Images

Figure CN120295930A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular, to a method for generating codes for converting interface parameters implemented based on a spreadsheet. Background Art
[0002] Instruction calculation software is an important software in a missile weapon system. When testing the specific functions of the instruction calculation software, a large number of parameters need to be input. To implement the functional test of the instruction calculation software, the application party has also developed test tools for the instruction calculation model. When using these test tools, parameter values are input through the interaction interface of the test tool software, and the interface function transmits the input parameter values to the calculation module of the instruction calculation model. The calculation result is then passed to the interface through the interface function to achieve interaction, so as to achieve the visualization and standardization of the test process.
[0003] However, the input parameters of the instruction calculation software and the protocols of the input parameters often change. Therefore, the interface parameters of the test tool need to be adjusted together with the protocol. However, due to the large number of input and output variables involved, the instruction calculation software has strict restrictions on the expression methods and data types of variables. Therefore, each variable needs to fully comply with the protocol limitations. In the development of the test tool, corresponding variable association codes also need to be tailored for all variables, which brings a large amount of workload and repetitive labor to the staff in actual work. At the same time, if the definition and assignment of variables are not rigorous enough during the program compilation process, various errors are likely to occur. If the software is upgraded or the communication protocol is changed, a large number of changes need to be made to the codes related to the parameters, which further increases the workload of the staff and has a great impact on the stability of the software.
[0004] Therefore, a technical solution for converting the interface parameters of the test tool software is needed to improve the adaptability of the input and output parameters of the test tool software to changes. Summary of the Invention
[0005] To achieve the above object, the present application provides a method for generating codes for converting interface parameters implemented based on a spreadsheet. This method is applied to the instruction calculation software accessing the test tool, and the test tool provides an interface to display all parameter information. The code generation method includes the following steps:
[0006] Obtain an interface parameter specification file generated based on the interface protocol file of the instruction calculation software. The content of the interface parameter specification file includes the definitions of the input parameters and output parameters determined in the interface protocol file. A single interface parameter specification file contains multiple parameter information.
[0007] The execution code generation program generates conversion code; the conversion code consists of a function name, a form page, line information, or a function name, parameter elements, and formal parameters; the conversion code includes parameter code and environment code; the environment code is used to generate edit box or drop-down box code for the test tool according to the data type; the parameter code is used to generate parameter definition code that conforms to the execution of the test tool according to the parameter information;
[0008] The conversion code is encapsulated into the function code of the variable definition file of the test tool to form the complete program code; after compiling the complete program code of the test tool, the interaction of input and output data with the interface and the instruction calculation model is realized in the test tool.
[0009] Among them, the parameter information includes: element name, element identifier, data type, unit, limit value, and value range; specifically, the element name is used to describe the meaning of the parameter; the element identifier is the variable name that identifies the parameter in the code of the instruction calculation software and the test tool; the data type is the data type of the variable name in the code of the instruction calculation software test tool; the value range is the assignment range defined by the variable name in the program body.
[0010] Furthermore, the interface protocol file is a spreadsheet file; the code generation program supports implementation through the macro of the spreadsheet file.
[0011] Among them, the steps for the execution code generation program to generate conversion code include:
[0012] Read in the conversion code generation file;
[0013] Calculate the number of parameter information;
[0014] Generate form pages according to the predefined number of elements N per page;
[0015] Extract parameter information line by line and generate conversion code for the parameter information.
[0016] Furthermore, extracting parameter information line by line and generating conversion code for the parameter information includes: judging whether the parameter information is the last piece of parameter; if so, after generating the interface update code, end the operation of generating conversion code; if not, judge whether the current parameter line number is a multiple of N; if so, increment the form page by 1; perform code encapsulation based on the data type, input parameters, and output parameters classification of the parameter information in the interface parameter specification file.
[0017] Among them, the execution code encapsulation supports input parameters and output parameters:
[0018] For the input parameters, the calling function converts the input parameters into the structure of the test tool program. The functions include: using the Fd_StringToDouble function to process parameters of data type double; using the Fl_StringToInt function to process parameters of data type unsigned short or unsigned char and with a value range including 0xXX; using the Fuc_StringToHex function to process parameters of other data types;
[0019] For the output parameters, the calling function outputs the parameters in the test tool structure to the test tool interface. The function includes: the Fs_DataToString function.
[0020] Among them, the calling rules of the Fd_StringToDouble function, the Fuc_StringToHex function, and the Fl_StringToInt function are respectively: Fd_StringToDouble(form page, line number), Fuc_StringToHex(form page, line number), and Fl_StringToInt(form page, line number);
[0021] Among them, the form page is the serial number of the page where it is located determined according to the number of elements per page N and the order of the parameter information in the interface parameter specification file; the line number is the order of the parameter information in the interface parameter specification file.
[0022] The calling rule of the Fs_DataToString function is: Fs_DataToString(parameter element, formal parameter); among them, the formal parameter assigns different values for different data types.
[0023] The implementation process of the present invention is simple to operate: fill in the input and output parameters in the interface protocol into the corresponding interface document according to the standard interface format, parse the interface document to generate the interface code of the test tool interface of the instruction calculation software, encapsulate the generated interface code into a function, and embed it into the code of the instruction calculation software test tool to realize the interaction of the input and output data between the test interface and the instruction calculation model. Compared with the method of manually preparing interface code according to the original communication protocol, this method can reduce a large amount of code copy and paste work, and at the same time improve the accuracy and adaptability of the interface code implementation, thereby saving a large amount of test tool debugging time and improving the test efficiency. Description of the Drawings
[0024] Figure 1 It is a step diagram of generating code for converting interface parameters implemented based on a spreadsheet according to an embodiment of the present invention;
[0025] Figure 2It is a flowchart for generating the code of input parameters provided by an embodiment of the present invention;
[0026] Figure 3 It is a flowchart for generating the code of output parameters provided by an embodiment of the present invention. Detailed implementation manners
[0027] The present invention provides a method for generating the code of conversion interface parameters. This method is implemented through a spreadsheet such as Excel, with simple operations, and can be used for the unified conversion of the interface parameters of test tools developed for instruction calculation software. In the code generation method, interface documents are generated according to the definition specifications of input and output parameters in the interface protocol of the instruction calculation software. Further, the data in each row of each interface document is parsed, and according to the definitions of the parameters and the rules of encapsulation functions therein, the conversion code of each interface parameter is generated. This conversion code can be embedded in the program body of the test tool, and the test program formed after compilation can realize the data interaction among the test tool, the instruction calculation model, and the interaction interface.
[0028] The following will make a detailed description of the specific implementation manners of the present invention in conjunction with the accompanying drawings of the specification.
[0029] The steps for generating the code of the interface parameters implemented based on the spreadsheet are as Figure 1 shown and include:
[0030] Step S110: Obtain an interface parameter specification file generated based on the interface protocol file of the instruction calculation software;
[0031] Generally speaking, the interface protocol file is provided by the developer of the instruction calculation software; the application developer develops a test tool and accesses the instruction calculation software to implement the debugging of this software. When developing the test tool, a variable definition file or a variable definition program body is defined separately to store the definition codes of all parameters, such as function encapsulation codes. When docking different interface protocols, adjust the parameters defined in the variable definition file or the variable definition program body of the test tool. In order to enable the staff to clearly understand the input parameters and output parameters involved in the test process, an interface is provided in the test tool to list all the input parameters and output parameters in a paged manner.
[0032] In the present invention, after obtaining the interface protocol file, the definition content of the interface parameters is extracted from the interface protocol file to form a corresponding interface parameter specification file. At this time, the content of the interface parameter specification file includes the definition content of the input parameters and output parameters determined in the interface protocol file.
[0033] The interface parameter specification file generated in this step is a spreadsheet file such as Excel. Each row of data represents a parameter information, and one interface parameter specification file corresponds to one interface protocol file, and one interface protocol file contains multiple parameter information;
[0034] Specifically, the content of the parameter information includes: element name, element identifier, data type, unit, limit value, and value range. Its structure is shown in Table 1:
[0035] Table 1 Interface Parameter Specification File Format
[0036] Element Name Element Identification Data Type Unit Value Range Variable 1 number1 int M 1.2 ... ... ... ... ...
[0037] Among them, the element name is used to describe the meaning of the parameter;
[0038] The element identifier is the variable name that identifies the parameter in the code of the instruction calculation software and the test tool;
[0039] The data type is the data type of the variable name in the code of the instruction calculation software test tool, and supports: double, unsigned short, unsigned char, and other types;
[0040] The value range is the assignment range defined by the variable name in the program body.
[0041] Step S120: Execute the code generation program to generate conversion code;
[0042] The code generation program supports implementation through the macro of the spreadsheet file. For example, implement this method with VBA code and encapsulate it in the macros of "Generate ☆ Input Parameter Code" and "Generate ☆ Output Parameter Code". By running these two macros, the corresponding input and output interface codes can be generated.
[0043] The conversion code includes parameter code and environment code; the environment code is used to generate the edit box or dropdown box code of the corresponding parameter in the test tool according to the data type; the parameter code is used to generate the parameter definition code for the operation of the test tool according to the parameter information.
[0044] Specifically, the conversion code consists of a function name, a form page, line information, or a function name, parameter elements, and formal parameters;
[0045] Among them, the function name is the name of the function encapsulated in the instruction calculation software test tool. The function is used to compile in the program body embedded in the test tool to achieve data interaction between the model under test and the test interface.
[0046] Specifically, the process of the execution code generation program generating the conversion code includes the following steps:
[0047] 1) Read in the interface parameter specification file;
[0048] 2) Calculate the number of parameter information;
[0049] 3) Generate the form page serial number according to the pre-defined number of elements N per page;
[0050] 4) Extract parameter information line by line and generate conversion code for the parameter information;
[0051] Perform code encapsulation based on the data types, input parameters, and classification of output parameters in the interface parameter specification file; for input parameters and output parameters, the present invention provides different functions and call rules:
[0052] The processing flow of the conversion code for input parameters is as Figure 2 shown: Call functions to convert input parameters to the structure of the test tool program. The corresponding functions include: functions such as Fd_StringToDouble function, Fuc_StringToHex function, and Fl_StringToInt function. The call rules are: Fd_StringToDouble(form page, line number), Fuc_StringToHex(form page, line number), and Fl_StringToInt(form page, line number). For example, the structure of the test tool is zljsin, an input parameter element identifier is D_RdZ1_0T, the "data type" is double, and it is located on line 80 of the interface parameter specification file. Assuming the number of elements per page of the interface is N = 36, that is, the rule that 36 parameters are displayed per page of the test tool interface, it should be displayed on page 3 of the interface. That is, the generated code is: "zljsin.D_RdZ1_0T = Fd_StringToDouble(m_Pages[2], ID++)", where the form page is the serial number of the page where it is located determined according to the number of elements per page N and the order of the parameter information in the interface parameter specification file; the line number is the order of the parameter information in the interface parameter specification file.
[0053] The processing flow of the conversion code for output parameters is as Figure 3 shown: The present invention provides the Fs_DataToString function to output the parameters in the test tool structure to the test tool interface. The call rule is: Fs_DataToString(parameter element, formal parameter); where the formal parameter assigns different values for different data types: when the data type of the output parameter is double, the formal parameter is assigned a value of 2; when the data type of the output parameter is short\unsigned short\unsigned char\long, the formal parameter is assigned a value of 3; in other cases, the formal parameter is assigned a value of 1; for example: an output parameter element identifier is D_Numbers1, the "data type" is double, and it is located on line 40 and should be displayed on page 2 of the interface. That is, the generated code is:
[0054] "m_PagesOut[1]->SetDlgItemText(ID++, Fs_DataToString(D_Numbers1, 1))".
[0055] Before each conversion code processing, determine whether the parameter information is the last piece of parameter. If so, after generating the interface update code, end the operation of generating the conversion code; if not, determine whether the current parameter line number is a multiple of N. If so, increment the form page by 1.
[0056] Since the interface parameter elements of the test tool are paged, generate the handle of this page array in each page loop and call the interface update function code.
[0057] For example, if 4 input parameter pages are generated, four lines of interface page update code are generated:
[0058] m_Pages[0]->UpdateData(TRUE);
[0059] m_Pages[1]->UpdateData(TRUE);
[0060] m_Pages[2]->UpdateData(TRUE);
[0061] m_Pages[3]->UpdateData(TRUE).
[0062] Step S130: Package the conversion code into the function code of the corresponding file of the test tool to form the complete program code.
[0063] At this time, the code generation program can read the variable definition file of the test tool and write the conversion code to the specified position in the variable definition file; or the conversion code can be appended to the line where the corresponding parameter information is located in the interface parameter specification file, and then the plugin extracts data from the interface parameter specification file and writes it to the specified position in the variable definition file.
[0064] Through the above operations, the adaptive conversion of the interface parameters of the test tool can be achieved. The parameter definition program code for adapting different interface protocols is added to the program body of the test tool to form the complete program code; after compiling the complete program code of the test tool, the interaction between the test interface and the input and output data of the instruction calculation model can be achieved in the test tool.
[0065] Compared with the method of manually preparing interface codes according to the original communication protocol, the present invention can reduce a large amount of code copy and paste work, improve the accuracy and adaptability of the application of interface parameters, thereby saving a large amount of debugging time of the test tool and improving the test efficiency.
[0066] The above are only several specific embodiments of the present invention. However, the present invention is not limited thereto, and any changes that can be conceived by those skilled in the art shall fall within the protection scope of the present invention.
Claims
1. A method for generating code of conversion interface parameters implemented based on a spreadsheet, characterized in that Applied to an instruction calculation software access test tool, the test tool provides an interface to display all parameter information; the code generation method includes the following steps: Obtain an interface parameter specification file generated based on the interface protocol file of the instruction calculation software. The content of the interface parameter specification file includes the definitions of input parameters and output parameters determined in the interface protocol file; one interface parameter specification file contains multiple parameter information. Execute a code generation program to generate conversion code; the conversion code consists of a function name, a form page, line information, or a function name, parameter elements, and formal parameters; the conversion code includes parameter code and environment code; the environment code is used to generate the edit box or dropdown box code of the test tool according to the data type; the parameter code is used to generate parameter definition code that conforms to the execution of the test tool according to the parameter information. Encapsulate the conversion code into the function code of the variable definition file of the test tool to form a complete program code; after compiling the complete program code of the test tool, realize the interaction of input and output data with the interface and the instruction calculation model in the test tool.
2. The code generation method according to claim 1, characterized in that The parameter information includes: element name, element identifier, data type, unit, limit value, and value range. Among them, the element name is used to describe the meaning of the parameter. The element identifier is the variable name that identifies the parameter in the code of the instruction calculation software and the test tool. The data type is the data type of the variable name in the code of the instruction calculation software test tool. The value range is the assignment range defined by the variable name in the program body.
3. The code generation method according to claim 1, wherein The interface protocol file is a spreadsheet file; the code generation program supports implementation through macros in the spreadsheet file.
4. The code generation method according to claim 1, wherein The step of executing the code generation program to generate conversion code includes the following steps: Read in the conversion code generation file. Calculate the number of parameter information. Generate a form page according to the predefined number of elements per page N. Extract parameter information line by line and generate conversion code for the parameter information.
5. The code generation method according to claim 4, wherein The step of extracting parameter information line by line and generating conversion code for the parameter information includes: Judge whether the parameter information is the last parameter. If so, generate interface update code and then end the operation of generating conversion code; if not, judge whether the current parameter line number is a multiple of N. If so, increment the form page by 1. Execute code encapsulation based on the data type, input parameters, and output parameter classification of the parameter information in the interface parameter specification file.
6. The code generation method according to claim 5, characterized in that The execution code encapsulation supports input parameters and output parameters: For input parameters, call a function to convert the input parameters to the structure of the test tool program. The functions include: using the Fd_StringToDouble function to process parameters with a data type of double; using the Fl_StringToInt function to process parameters with a data type of unsigned short or unsigned char and a value range including 0xXX; using the Fuc_StringToHex function to process parameters of other data types. For the output parameters, the calling function outputs the parameters in the test tool structure to the test tool interface. The functions include: the Fs_DataToString function.
7. The code generation method according to claim 6, wherein The calling rules of the Fd_StringToDouble function, the Fuc_StringToHex function, and the Fl_StringToInt function are respectively: Fd_StringToDouble(form page, line number), Fuc_StringToHex(form page, line number), and Fl_StringToInt(form page, line number); Among them, the form page is the serial number of the page where it is located determined according to the number of elements per page N and the order of the parameter information in the interface parameter specification file; the line number is the order of the parameter information in the interface parameter specification file.
8. The code generation method according to claim 6, wherein The calling rule of the Fs_DataToString function is: Fs_DataToString(parameter element, formal parameter); where the formal parameter assigns different values for different data types.