A method and apparatus for automatically generating I / O service codes for a flight control system.
By using an automatic generation method based on XML Schema and StringTemplate, the flight control system I/O service code is automatically generated through a visual interface. This solves the problem of repetitive manual configuration in I/O service code generation, improves development efficiency, reduces costs, and enhances the portability and reliability of the software.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-11
- Publication Date
- 2026-04-03
AI Technical Summary
The generation of I/O service codes in flight control systems involves a large amount of repetitive manual configuration work, resulting in long software development cycles and high costs.
An automatic generation method based on XML Schema definition files (XSD) and the StringTemplate template engine is adopted. The I/O service attributes input by the user are received through a visual interface, and I/O service code is generated. This includes selecting the bus type and communication method, constructing XPath path expressions for parsing, converting them into preset data types, and assigning template elements to the code template.
It reduces manual configuration work, improves system development efficiency, reduces development time and cost, enhances software portability and reliability, and reduces software coupling.
Smart Images

Figure CN115686490B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of software engineering technology, specifically relating to a method and apparatus for automatically generating IO service code for a flight control system. Background Technology
[0002] To address the increasing complexity of flight control electronic systems, poor system reusability, high coupling between airborne software and hardware, and difficulties in system upgrades and expansion, the Open Group released the FACE (Future Airborne Capability Environment) architecture standard in 2014. The FACE approach enhances software portability by defining a reference architecture and adopting design principles, thereby overcoming obstacles related to modularity, portability, and interoperability.
[0003] The development of source code for flight control computer systems based on the FACE standard has been a research project for many institutions in China. However, current source code development largely involves manual coding, which includes a large amount of repetitive work, resulting in long software development cycles and high costs. Currently, many domestic and international companies and research institutions are focusing on research into automatic code generation technology and the development of corresponding tools.
[0004] Current automatic code generation technologies mainly include model-based automatic code generation and template-based automatic code generation. Both technologies only require modification of the template and model when the generated code needs to be changed, making them easy to maintain. However, template-based automatic code generation lacks framework model support and specific business logic implementation, limiting its applicability. Model-based automatic code generation remains challenging in terms of modeling and exhibits significant code redundancy. Both methods can directly achieve automatic code generation based on the FACE standard, but their inherent limitations still exist.
[0005] In the implementation of code generation methods for I / O configuration, most of the configuration data still needs to be manually added to the code framework, which involves a lot of repetitive work, resulting in long software development cycles and high software development costs. Summary of the Invention
[0006] This invention proposes a method and apparatus for automatically generating IO service codes for a flight control system, solving the problems of manual configuration and high software development costs.
[0007] This invention proposes a method for automatically generating I / O service codes for a flight control system, the method comprising the following steps:
[0008] Step 1: Receive at least one IO service input from the user. The IO service is located between subsystems in the flight control system. The attributes of the IO service include: at least one combination of bus type and communication method.
[0009] Step 2: For each IO service, select the complexType node corresponding to the bus type from the preset XSD file according to the bus type of the IO service, as the candidate set of the IO service; the preset XSD file contains at least one complexType node, one complexType node corresponds to one bus type, and each complexType node includes at least one child node, the child node is the communication method adapted to the bus type;
[0010] Step 3: For each IO service, receive the new IO service attributes selected by the user from the candidate set, and generate an XML file by using each new IO service attribute as a node in the XML file.
[0011] Step 4: Construct an XPath path expression based on the node information in the XML file, and use the DOM4j method to parse the XML file based on the XPath path expression to obtain the parsed file;
[0012] Step 5: Convert the attributes of each IO service node in the parsed file into preset data types to obtain template elements;
[0013] Step 6: Assign the template elements to the code template of the preset I / O service;
[0014] The code template for the default I / O service is generated using the StringTemplate template engine.
[0015] Optionally, converting the attributes in each IO service node of the parsed file into a preset data type includes:
[0016] Filter IO service nodes with different attributes from the parsed file, and convert the attributes of each IO service node with different attributes into preset data types.
[0017] Optionally, I / O services include three types of interface services: connection management interface service, read / write information interface service, and parameter management interface service; the template elements of the read / write information interface service should at least include the bus type; the template elements of the parameter management interface service should at least include the communication method.
[0018] The default I / O service code template is obtained by editing the three types of service interfaces in the StringTemplate template to form a general interface code template.
[0019] Optionally, the method further includes:
[0020] For any IO service, if the complexType node corresponding to the bus type of any IO service does not exist in the preset XSD file;
[0021] In the preset XSD file, create a complexType node corresponding to the bus type of any of the IO services;
[0022] Add the communication method adapted to the bus type to the complexType node.
[0023] Optionally, after selecting the complexType node corresponding to the bus type from a preset XSD file as the candidate set for each IO service, the method further includes:
[0024] Generate a visual interface based on the candidate set;
[0025] Correspondingly, the system receives new IO service attributes selected by the user from the candidate set, including:
[0026] Receive new IO service attributes selected by the user from the candidate set through a visual interface.
[0027] Another aspect of the present invention provides an automatic generation device for I / O service codes of a flight control system, comprising:
[0028] The receiving module is used to receive at least one IO service input by the user. The IO service is located between subsystems in the flight control system. The attributes of the IO service include: at least one combination of bus type and communication method.
[0029] The selection module is used to select, for each IO service, the complexType node corresponding to the bus type from a preset XSD file, as the candidate set for the IO service, based on the bus type of the IO service; the preset XSD file contains at least one complexType node, one complexType node corresponds to one bus type, and each complexType node includes at least one child node, the child node being the communication method adapted to the bus type;
[0030] The generation module is used to receive new IO service attributes selected by the user from the candidate set for each IO service, and generate an XML file by using each new IO service attribute as a node in the XML file.
[0031] The parsing module is used to construct XPath path expressions based on the node information in the XML file, and then use DOM4j methods to parse the XML file based on the XPath path expressions to obtain the parsed file.
[0032] The conversion module is used to convert the attributes of each IO service node in the parsed file into preset data types to obtain template elements;
[0033] The assignment module is used to assign template elements to the code template of a preset I / O service;
[0034] The code template for the default I / O service is generated using the StringTemplate template engine.
[0035] Optionally, the conversion module is specifically used for,
[0036] Filter IO service nodes with different attributes from the parsed file, and convert the attributes of each IO service node with different attributes into preset data types.
[0037] Optionally, I / O services include three types of interface services: connection management interface service, read / write information interface service, and parameter management interface service; the template elements of the read / write information interface service should at least include the bus type; the template elements of the parameter management interface service should at least include the communication method.
[0038] The default I / O service code template is obtained by editing the three types of service interfaces in the StringTemplate template to form a general interface code template.
[0039] Optional features include: creating modules;
[0040] The creation module is used to address the situation where, for any IO service, a complexType node corresponding to the bus type of any IO service does not exist in the preset XSD file.
[0041] In the preset XSD file, create a complexType node corresponding to the bus type of any of the IO services;
[0042] Add the communication method adapted to the bus type to the complexType node.
[0043] Optional features also include: a visualization module;
[0044] The visualization module is used to generate a visual interface based on the candidate set;
[0045] Correspondingly, the generation module is specifically used to receive new IO service attributes selected by the user from the candidate set through a visual interface.
[0046] This invention proposes a method and apparatus for automatically generating I / O service code for a flight control system. Users can configure I / O service parameters through a visual interface, ultimately achieving automatic generation of XML configuration files. Because the visual interface is not only simple and easy to understand but also ensures the accuracy of configuration data and facilitates data updates, users can focus solely on configuring I / O service parameters. They no longer need to manually add I / O service configuration items to the code framework; the system only needs to parse the configuration file to obtain the I / O service configuration data and automatically generate the I / O service interface code. This invention can significantly improve system development efficiency and reduce development time and costs. In the field of flight control embedded systems, the use of the FACE open architecture's I / O configuration file and code automatic generation method helps improve software portability and reliability, and reduces the coupling between software components. Attached Figure Description
[0047] Figure 1 This is a flowchart illustrating the automatic generation method of I / O configuration files and code based on the embedded open architecture of flight controller provided by this invention. Detailed Implementation
[0048] The automatic generation method and apparatus for IO service codes of the flight control system provided by the present invention will be explained below with reference to the accompanying drawings.
[0049] The technical solution of this invention is: an automatic generation technology for I / O configuration files and code based on an embedded open architecture for flight control. This technology analyzes and summarizes the parameters required for I / O connections between the Platform-Specific Services Segment (PSSS) and external devices. For each I / O service, the configuration parameters and data types are determined individually. Based on the analysis results, an XML Schema Definition (XSD) file is designed. Then, the configuration parameters required for each I / O service are visualized by parsing the XSD file. This leads to the automatic generation of XML files storing I / O connection configuration information. A StringTemplate template engine is used to design code templates with different I / O service function code structures. The generated XML file is parsed, and the corresponding StringTemplate template is selected and read based on the parsing results. The template is instantiated to achieve automatic code generation.
[0050] Figure 1 This is a flowchart illustrating the automatic generation method for I / O configuration files and code based on an embedded open architecture for flight controllers provided by this invention. Figure 1As shown below, taking Java as an example, the method for automatically generating IO configuration files and code based on the embedded open architecture of flight controller provided by this invention will be explained and illustrated. The specific steps are as follows:
[0051] Step 1: Based on the W3C (World Wide Web Consortium) recommended standards and the flight control embedded open architecture, design the XSD file that the storage I / O configuration XML file must comply with. First, define a `complexType` node and assign a value to its `name` attribute. This node is the outer complex type node; its child nodes are 9 `element` elements, each representing one of the 9 I / O services. The `name` attribute value of each `element` element is the I / O service name, and the `type` attribute will reference the names of other `complexType` elements.
[0052] Next, the `type` attribute of the IO service node is defined to reference the `complexType` node. This results in nine referenced `complexType` nodes, with each referenced node's name corresponding one-to-one with the `type` attribute value of the I / O service element referencing it; otherwise, it cannot be referenced. The child nodes of each referenced `complexType` node are the configuration items in its corresponding I / O service. If an I / O service has five configuration items, five `element` elements are defined. The `name` attribute value of each `element` element is the configuration item name, and the `type` attribute represents the data type of the configuration item. For common data types such as String and Double, they can be defined directly. If the element's content is restricted to a set of acceptable values, an enumeration constraint should be used, similarly referencing other nodes using `type` to make the structure clearer.
[0053] Finally, define a simpleType node with enumeration constraints, whose child nodes are the various enumeration items, and the name of each referenced node corresponds one-to-one with the type attribute value of the configuration item element that references this node; otherwise, it cannot be referenced.
[0054] Step 2: Parse the I / O configuration XSD file to obtain the required configuration parameters and complete the subsequent bus abstraction preparation. Declare static variable classes and node object classes, and complete the parsing method classes. The specific parsing process is as follows:
[0055] 1) Read XSD data using SAXReader and return a Document format object;
[0056] 2) After reading the Document object, use the getRootElement() method to get the root element, which returns an Element object;
[0057] 3) Construct an XPath expression based on node information. The XPath expression points to a node or set of nodes that meet the conditions. For example, the XPath expression for the complexType node referenced by an I / O service is " / / "+XSDConstants.XSD_DEFAULT_NAMESPACE+":"+XSDConstants.XSD_COMPLEX_TYPE+"[@name=\""+type+"\"]"", where type is the parameter passed in;
[0058] 4) Use DOM4j methods to obtain nodes or node sets based on the constructed XPath path expression. If the XPath path points to a single node, use the function "selectSingleNode" to obtain the node; if the XPath path points to a node set, use the function "selectNodes" to obtain the node set.
[0059] After obtaining the node, retrieve the value of the node's "name" attribute using `attributeValue("name")`, the value of the node's "type" attribute using `attributeValue("type")`, and the value of the node's "value" attribute using `attributeValue("value")`. Then, encapsulate the retrieved information into a node object.
[0060] Step 3: Visualizing Configuration Parameters: Each I / O service has its supported I / O bus, therefore each I / O service has different configuration parameters. Based on the parsing results from Step 2, an operation interface is provided for each I / O service. Enumerated configuration items are displayed in this interface for user selection. As seen in the previous steps, different parameters will parse the corresponding node information. Therefore, only a common operation interface needs to be provided; different input parameters will result in different displayed configuration items. The specific implementation process is as follows:
[0061] 1) Call the XSD parsing method and pass in the IOType parameter to obtain the collection of all configuration item node objects in this I / O service;
[0062] 2) Iterate through the node objects in the collection, get the configuration item name through the getName() method and use it as the interface label name in turn, and get the data type of the configuration item through the getType() method;
[0063] 3) Determine the data type of the configuration item. If the type of a configuration item is a custom type, call the XSD parsing method and pass in the parameter type to get the selectable values of the configuration item.
[0064] 4) Create a new dropdown list for configuration items with data type enumeration restrictions, and add the obtained enumeration values to the dropdown list options. Create a new text box for other common data types. For input values with special requirements, regular expressions or other validation methods can be added to restrict them.
[0065] Now, each I / O service can display the configuration items in the operation interface for users to configure themselves.
[0066] Step 4: After configuring the parameters in the I / O service, an XML file storing the I / O configuration data is finally generated. After filling in the configuration items in the configuration parameter visualization interface and saving, an I / O configuration file is generated. This I / O file stores the configuration data for each I / O service. The specific implementation process is as follows:
[0067] 1) Add an atomic element (atom) to the configuration data of each I / O service in the configuration file, and add attributes id and kind to each atomic element using the addAttribute() method; the attribute id value is generated by UUID (Universally Unique Identifier) so that each atomic element can be uniquely identified, and the attribute kind is assigned a value using the I / O service name;
[0068] 2) Add child elements "attribute" to atomic elements using the addElement("attribute") method. Each child element represents a configuration item for the I / O service. Add an attribute "kind" to each configuration item element using the addAttribute() method, and assign a value to the attribute "kind" using the configuration item name.
[0069] 3) Use the addElement("value") method to add a child element 'value' to each attribute element. Each value element stores the configuration data of its configuration item.
[0070] 4) By obtaining the configuration data of the user in the operation interface, the setText() method is used to set the content of the value element of each configuration item in the I / O configuration file.
[0071] The above steps complete the configuration of each I / O service's configuration items and save the complete configuration results in the I / O configuration file.
[0072] Step 5: When you open the operation interface after configuring the parameters in the previous step, the configuration data from the generated configuration file will be displayed in the operation interface. Perform operations on the data that needs to be changed, and then save again to complete the update operation of the I / O configuration file. When the configuration parameters of certain I / O services need to be changed, you do not need to manually modify the I / O configuration file; you only need to modify the data in the visual operation interface for I / O service parameter configuration and save it. The specific implementation process is as follows:
[0073] 1) When the I / O service operation interface with configured parameters is opened again, the corresponding atomic element in the I / O configuration file is found by ID;
[0074] 2) Obtain the configuration data for each configuration item, and find the attribute element whose name matches the attribute kind value in the I / O configuration file; use the setText() method to update the content of the value element under the attribute element with the reconfigured parameter data.
[0075] Step Six: Use the StringTemplate template engine to complete the template design for the I / O service interface code structure. The following details the specific design scheme for each part of the I / O service interface code template:
[0076] 1) I / O Connection Management Interface Code Template Group. This template group is mainly used for the automatic generation of the declaration section of the I / O connection management interface. First, the namespace FACE is defined, and then the I / O and Read_Callback namespaces are defined separately in the FACE namespace. The I / O namespace mainly contains the initialization function; the connection creation function is declared based on parameters such as connection name, connection mode, connection ID, connection direction, and maximum message size; the connection destruction function can be declared based on the connection ID; the Read_Callback namespace provides the type definition of basic port parameters.
[0077] 2) Read / Write Message Interface Code Template Group. This template group mainly contains two functions: read message and write message. The parameters of the read message function are the connection handle to be read from, the maximum timeout (overtime), and the payload. The payload parameter must be represented in a structured manner, defined by the parameterized type BUS_CONTEXT::PAYLOAD_TYPE. Each I / O service declares its own PAYLOAD_TYPE, and the message is bound to that declaration; through this mechanism, the payload is not represented as a sequence of bytes. The parameters of the write message function are the same as those of the read message function, and will not be described again.
[0078] 3) Bus Parameter Management Interface Code Template Group. This template group is divided into a bus input parameter management interface code template group and an output parameter management interface code template group. The bus input parameter interface code template group includes functions for retrieving bus configuration parameters, initializing the input parameter data, converting the data to a data type conforming to the FACE standard, declaring data conversion functions, and finally creating the input parameter object. The output parameter management interface code template group is similar to the input parameter template group, including functions for retrieving output parameters, initializing output parameters, data conversion functions (converting back to data types supported by the bus device), and finally creating the output parameter object.
[0079] Step Seven: Obtain the parameter configuration data for each I / O service based on the XML file generated in Step Four, completing the I / O configuration file parsing. This development uses the Java language. In Java, compared to other methods of parsing XML files, DOM4j is a convenient, flexible, and open-source library with outstanding performance, powerful functionality, and ease of use. Therefore, DOM4j was chosen for parsing XML files. DOM4j parses XML files through an XML file tree structure; therefore, this paper chooses to use XPath when obtaining node path information, as XPath makes the program structure more concise. The specific process of parsing the XML file is as follows:
[0080] 1) Select and read the XML files for each I / O service, and obtain the Document object;
[0081] 2) Construct an XPath expression based on node information. The XPath expression points to the node or set of nodes that meet the conditions. For example, the XPath expression for all atomic elements is " / project / folder / model[@kind='System'] / / atom".
[0082] 3) Use DOM4j methods to obtain nodes or node sets based on the constructed XPath path expression. If the XPath path points to a single node, use the function "selectSingleNode" to obtain the node; if the XPath path points to a node set, use the function "selectNodes" to obtain the node set.
[0083] Operations on a node or set of nodes will store the relevant information of the element pointed to by that node or set of nodes in the corresponding data structure.
[0084] Step 8: Select and read the corresponding StringTemplate based on the node information. For each template element, assign values to the attributes of its corresponding I / O service template file to instantiate the template. Using the StringTemplate code template designed in Step 7, generate the I / O service interface code according to Step 8. The I / O connection management interface code template group and the read / write information interface code template group are universal for each I / O service supporting a specific I / O bus architecture. The bus parameter management interface code template group sets the parameter types for the corresponding I / O bus architecture. The specific code generation process is as follows:
[0085] 1) Read the StringTemplate template group file that is common to various I / O services, pass in the required parameters, instantiate the common code template, and generate a part of the complete I / O service code;
[0086] 2) Read the bus parameter management interface code template group and obtain the IOGroup object;
[0087] 3) Match the data results parsed in step 7 to the corresponding template files one by one. For example, select the Analog I / O service template file for the Analog I / O service element and obtain its corresponding Analog IO object.
[0088] 4) Then, based on the configuration parameters in the parsed I / O service, assign values to the attributes in the selected template; for example, the Analog I / O service includes configuration data such as maximum value, minimum value, initial value, data buffer precision, data transmission direction, voltage gain, and voltage offset. Assign these configuration data to the Analog IO object in sequence, instantiate the Analog I / O service template file, and a specific code block in the complete I / O service code can be generated.
[0089] 5) Finally, convert the assigned IO object into a string for easy output.
[0090] This completes the generation of the full code for implementing the I / O service.
Claims
1. A method for automatically generating I / O service codes for a flight control system, characterized in that, The method includes the following steps: Step 1: Receive at least one IO service input from the user. The IO service is located between subsystems in the flight control system. The attributes of the IO service include: at least one combination of bus type and communication method. Step 2: For each IO service, select the complexType node corresponding to the bus type from the preset XSD file according to the bus type of the IO service, as the candidate set of the IO service; the preset XSD file contains at least one complexType node, one complexType node corresponds to one bus type, and each complexType node includes at least one child node, the child node is the communication method adapted to the bus type; Step 3: For each IO service, receive the new IO service attributes selected by the user from the candidate set, and generate an XML file by using each new IO service attribute as a node in the XML file. Step 4: Construct an XPath path expression based on the node information in the XML file, and use the DOM4j method to parse the XML file based on the XPath path expression to obtain the parsed file; Step 5: Convert the attributes of each IO service node in the parsed file into preset data types to obtain template elements; Step 6: Assign the template elements to the code template of the preset I / O service; The code template for the default I / O service is generated using the StringTemplate template engine; I / O services include three types of interface services: connection management interface service, read / write information interface service, and parameter management interface service. The template element of the read / write information interface service should at least include the bus type; the template element of the parameter management interface service should at least include the communication method. The default I / O service code template is obtained by editing the three types of interface services in the StringTemplate template to form a general interface code template.
2. The method according to claim 1, characterized in that, The step of converting the attributes of each IO service node in the parsed file into a preset data type includes: Filter IO service nodes with different attributes from the parsed file, and convert the attributes of each IO service node with different attributes into preset data types.
3. The method according to claim 1, characterized in that, The method further includes: For any IO service, if the complexType node corresponding to the bus type of any IO service does not exist in the preset XSD file; In the preset XSD file, create a complexType node corresponding to the bus type of any of the IO services; Add the communication method adapted to the bus type to the complexType node.
4. The method according to claim 1, characterized in that, For each IO service, after selecting the complexType node corresponding to the bus type from a preset XSD file as the candidate set of IO services, the method further includes: Generate a visual interface based on the candidate set; Correspondingly, the system receives new IO service attributes selected by the user from the candidate set, including: Receive new IO service attributes selected by the user from the candidate set through a visual interface.
5. An automatic generation device for I / O service codes of a flight control system, characterized in that, include: The receiving module is used to receive at least one IO service input by the user. The IO service is located between subsystems in the flight control system. The attributes of the IO service include: at least one combination of bus type and communication method. The selection module is used to select, for each IO service, the complexType node corresponding to the bus type from a preset XSD file, as the candidate set for the IO service, based on the bus type of the IO service; the preset XSD file contains at least one complexType node, one complexType node corresponds to one bus type, and each complexType node includes at least one child node, the child node being the communication method adapted to the bus type; The generation module is used to receive new IO service attributes selected by the user from the candidate set for each IO service, and generate an XML file by using each new IO service attribute as a node in the XML file. The parsing module is used to construct XPath path expressions based on the node information in the XML file, and then use DOM4j methods to parse the XML file based on the XPath path expressions to obtain the parsed file. The conversion module is used to convert the attributes of each IO service node in the parsed file into preset data types to obtain template elements; The assignment module is used to assign template elements to the code template of a preset I / O service; The code template for the default I / O service is generated using the StringTemplate template engine; I / O services include three types of interface services: connection management interface service, read / write information interface service, and parameter management interface service. The template element of the read / write information interface service should at least include the bus type; the template element of the parameter management interface service should at least include the communication method. The default I / O service code template is obtained by editing the three types of interface services in the StringTemplate template to form a general interface code template.
6. The apparatus according to claim 5, characterized in that, The conversion module is specifically used for, Filter IO service nodes with different attributes from the parsed file, and convert the attributes of each IO service node with different attributes into preset data types.
7. The apparatus according to claim 5, characterized in that, Also includes: Create a module; The creation module is used to address the situation where, for any IO service, a complexType node corresponding to the bus type of any IO service does not exist in the preset XSD file. In the preset XSD file, create a complexType node corresponding to the bus type of any of the IO services; Add the communication method adapted to the bus type to the complexType node.
8. The apparatus according to claim 5, characterized in that, Also includes: Visualization module; The visualization module is used to generate a visual interface based on the candidate set; Correspondingly, the generation module is specifically used to receive new IO service attributes selected by the user from the candidate set through a visual interface.
Citation Information
Patent Citations
Software interface generating system and method based on extensible markup language (XML) Schema
CN102646039A
Transplantable unit code automatic generation method based on aviation embedded open system architecture
CN111782194A