A method and related apparatus for generating a multi-protocol data conversion program.
By automatically generating multi-protocol data conversion programs, the problems of low encoding efficiency and high error rate in the conversion of heterogeneous network protocols in vehicles are solved, and efficient and accurate protocol conversion is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- NEUSOFT REACH AUTOMOBILE TECH (SHENYANG) CO LTD
- Filing Date
- 2026-03-05
- Publication Date
- 2026-06-02
Smart Images

Figure CN122137897A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of vehicle-mounted heterogeneous network protocol conversion technology, and in particular to a method and apparatus for generating a multi-protocol data conversion program. Background Technology
[0002] With the rapid development of intelligent connected vehicle technology, the communication architecture of in-vehicle software systems is becoming increasingly complex, requiring data interaction between different functional modules using various heterogeneous protocols. For example, in the communication scenarios of in-vehicle central computing platforms, it is often necessary to convert business data carried by the SOME / IP (Scalable service-Oriented Middleware over IP) protocol into other protocol formats such as DDS (Data Distribution Service) and IPC (Inter-Process Communication) to achieve cross-module and cross-domain data transmission and collaboration. Since the business data carried by each protocol is usually defined in the form of complex structures, a single structure can contain dozens to hundreds or even thousands of data fields. Different protocols have significant differences in data structure, field definition, and serialization methods. Therefore, achieving data transmission and interoperability between different protocols presents high complexity and technical challenges.
[0003] Traditional methods primarily employ manual coding and result comparison for protocol conversion testing. Specifically, testers must manually write multi-protocol data conversion programs (i.e., test code). The core task involves writing assignment code line by line for thousands of fields between the source and target protocols. Due to the complex and heterogeneous structure definitions of different protocols, this process is inefficient and highly susceptible to human error, resulting in incorrect field assignments, omissions, or type mismatches. During testing, the manually written program calls the converter of the protocol under test, logs the output data, and finally, the output log is manually compared with the original input data to verify the correctness of the conversion result.
[0004] Therefore, how to automatically generate multi-protocol data conversion programs, improve coding efficiency and quality, and reduce human error has become one of the urgent technical problems to be solved in the field of vehicle heterogeneous network protocol conversion technology. Summary of the Invention
[0005] To address the aforementioned issues, this application provides a method for generating multi-protocol data conversion programs, which efficiently generates such programs and reduces human error.
[0006] The embodiments of this application disclose the following technical solutions: This application provides a method for generating a multi-protocol data conversion program, including: The first aspect of this application provides a method for generating a multi-protocol data conversion program, comprising: Based on the name of the target structure in the initial configuration file, the object code of the target structure is generated; the initial configuration file includes the hierarchical level of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchical level of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol; the target structure is the highest-level structure corresponding to the original protocol and the highest-level structure corresponding to the target protocol. From the initial configuration file, determine the parameters in the lowest-level structure corresponding to the target protocol as the parameters to be assigned values; Based on the initial configuration file, generate parameter assignment code for the parameters to be assigned; Based on the object code of the target structure and the parameter assignment code, a multi-protocol data conversion program is generated.
[0007] In one optional implementation, generating the parameter assignment code for the parameter to be assigned based on the initial configuration file includes: Based on the mapping relationship in the initial configuration file, determine the parameter in the original protocol that corresponds to the parameter to be assigned, and use it as the source parameter of the parameter to be assigned; Based on the relationship between the data type of the parameter to be assigned and the data type of the source parameter, the parameter assignment code is generated.
[0008] In one optional implementation, generating the parameter assignment code based on the relationship between the data type of the parameter to be assigned and the data type of the source parameter includes: For each parameter to be assigned a value, determine whether there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter; If there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter, then the parameter assignment code is generated based on the determination result of whether the data type of the parameter to be assigned and the data type of the source parameter are the same. If the data type of the parameter to be assigned and the data type of the corresponding source parameter do not have a corresponding data type conversion relationship, an error report is generated.
[0009] In one optional implementation, generating the parameter assignment code based on the determination result of whether the data type of the parameter to be assigned and the data type of the source parameter are the same includes: If the determination result indicates that the data type of the parameter to be assigned is different from the data type of the source parameter, then the source parameter is converted to generate a conversion result and the code of the conversion result is assigned to the parameter to be assigned, which serves as the parameter assignment code. If the determination result indicates that the data type of the parameter to be assigned is the same as the data type of the source parameter, then the data content of the corresponding source parameter is copied to the code of the parameter to be assigned, and used as the parameter assignment code.
[0010] In one alternative implementation, it also includes: Determine whether the parameter to be assigned that is being processed is the last parameter to be assigned that has not yet been processed in the lowest-level structure of the original protocol; If it is the last parameter to be assigned a value, and the data type of each parameter to be assigned a value in the lowest-level structure of the target protocol is consistent with the data type of the corresponding source parameter, and the number of parameters in the lowest-level structure of the target protocol is consistent with the number of parameters in the lowest-level structure of the original protocol, then the memcpy statement is used as the parameter assignment code.
[0011] In one alternative implementation, it also includes: Output the parameters in the target protocol that were not successfully assigned values as the first alarm message.
[0012] In one alternative implementation, it also includes: Output the parameters in the original protocol that are not mapped to the target protocol as the second alarm information.
[0013] A second aspect of this application provides an apparatus for generating a multi-protocol data conversion program, comprising: The structure object determination module is used to generate object code for the target structure based on the name of the target structure in the initial configuration file. The initial configuration file includes the hierarchical level of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchical level of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol. The target structure is the highest-level structure corresponding to the original protocol and the highest-level structure corresponding to the target protocol. The parameter to be assigned module determines the parameters in the lowest-level structure corresponding to the target protocol from the initial configuration file as the parameters to be assigned. The parameter assignment code generation module is used to generate parameter assignment code for the parameter to be assigned based on the initial configuration file. The multi-protocol data conversion program determination module is used to generate a multi-protocol data conversion program based on the object code of the target structure and the parameter assignment code.
[0014] A third aspect of this application provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in any implementation of the first aspect.
[0015] A fourth aspect of this application provides an electronic device, comprising: A memory on which computer programs are stored; A processor for executing the computer program in the memory to implement the steps of the method described in any implementation of the first aspect.
[0016] Compared with the prior art, this application has the following beneficial effects: This application provides an automatic generation method for a multi-protocol data conversion program, comprising: generating object code for the target structure based on the name of the target structure in an initial configuration file; determining all parameters in the lowest-level structure corresponding to the target protocol from the initial configuration file as parameters to be assigned; generating parameter assignment code for the parameters to be assigned based on the initial configuration file; and automatically generating a complete and executable multi-protocol data conversion program by combining the object code of the target structure and the parameter assignment code. This application's solution automatically generates code based on protocol structure and mapping relationships, thereby effectively avoiding problems such as assignment errors, omissions, and type mismatches that occur in traditional manual coding, significantly improving coding efficiency and code quality, and reducing human error. Attached Figure Description
[0017] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0018] Figure 1 A flowchart illustrating an automatic generation method for a multi-protocol data conversion program provided in this application embodiment; Figure 2 A schematic diagram of an initial configuration file in Excel format provided for an embodiment of this application; Figure 3 A flowchart illustrating another method for automatically generating a multi-protocol data conversion program provided in an embodiment of this application; Figure 4 This is a schematic diagram of an automatic generation device for a multi-protocol data conversion program provided in an embodiment of this application. Detailed Implementation
[0019] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the scope of protection of the present application.
[0020] Figure 1 A flowchart illustrating an automatic generation method for a multi-protocol data conversion program provided in this application embodiment. (In conjunction with...) Figure 1 As shown, this application provides a method for automatically generating a multi-protocol data conversion program, comprising: S101, Based on the name of the target structure in the initial configuration file, generate the object code of the target structure.
[0021] The initial configuration file in this application includes the hierarchy of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchy of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol.
[0022] The original protocol is the source protocol to be converted, and the target protocol is the protocol to be generated. The initial configuration file can be an Excel file or a structured data file such as XML, JSON, or YAML.
[0023] Figure 2 This is a schematic diagram of an initial configuration file in Excel format provided in an embodiment of this application. Figure 2 The document clearly illustrates the organizational hierarchy of the original and target protocols. For example, the first-level structure of the original protocol, "LANES INFO ST," includes the second-level structure, "CAM FAILURE INFO," which in turn includes the third-level specific parameter, "CAM TEMPORARY FAILURE."
[0024] Figure 2The document clearly shows the data types corresponding to the parameters of the original and target protocols. For example, the data type of the parameter "LANES Alive Counter" in the original protocol is int16_t, and the corresponding parameter "hadasradi_Reserved" in the target protocol is also of data type int16_t; other parameters in the target protocol, such as "hadasradi_TIMESTAMP_SYNC_LANES_SEC", have the data type int32_t.
[0025] Figure 2 The document clearly demonstrates the one-to-one correspondence between the original protocol and the target protocol. For example, "CAMTEMPORARY FAILURE" in the original protocol is mapped to "hadasradi_CAM_TEMPORARY_FAILURE" in the target protocol, and "LANES Alive Counter" in the original protocol is mapped to "hadasradi_Reserved" in the target protocol.
[0026] The target structure in this application is the highest-level structure corresponding to both the original protocol and the target protocol. Figure 2 For example, Figure 2 The highest-level structure corresponding to the original protocol (Input) is Structure1, and the highest-level structure corresponding to the target protocol (Output) is Structure1.
[0027] This step means using a Python script to parse the initial configuration file, identify the highest-level structure of the original protocol and the target protocol, and predefine the corresponding structure object in the generated code based on its structure name.
[0028] For example, according to Figure 2 The configuration shown can generate object definition code for Structure1 obj_input_Structure1; and Structure1 obj_output_Structure1.
[0029] It should be noted that defining these top-level structure objects provides the necessary object reference foundation for subsequent access to and assignment of their nested substructures and final parameters, thereby supporting the automated construction of the entire protocol data conversion program.
[0030] S102, determine the parameters in the lowest-level structure corresponding to the target protocol from the initial configuration file, and use them as parameters to be assigned values.
[0031] This step means: traversing the initial configuration file from the target protocol side until locating the lowest-level structure that no longer contains substructures, and identifying all data fields (i.e., atomic parameters) defined within it as objects that need to be assigned values. These parameters are the basic units for actual data transformation and mapping. For example, in... Figure 2 In this context, the lowest-level structure of the target protocol (Output) is the parameter contained in the third-level "CAM FAILURE INFO", which is the parameter to be assigned in this step.
[0032] S103, Based on the initial configuration file, generate parameter assignment code for the parameter to be assigned.
[0033] As can be seen from the preceding text, the initial configuration file in this application includes the hierarchical level of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchical level of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol.
[0034] In one optional implementation, based on the initial configuration file, parameter assignment code for the parameter to be assigned is generated, including: First, based on the mapping relationship, the parameter corresponding to the parameter to be assigned in the original protocol is determined and used as the source parameter of the parameter to be assigned.
[0035] Specifically, each parameter to be assigned is traversed, and the parameter name and its structure hierarchy path in the original protocol are found by mapping the parameters in the original protocol and the parameters in the target protocol in the initial configuration file.
[0036] For example, for the target protocol parameter "hadasradi_CAM_TEMPORARY_FAILURE", its corresponding source parameter can be determined to be "CAM TEMPORARY FAILURE" in the original protocol based on the mapping relationship, and the parameter is located in the original protocol structure "CAM FAILURE INFO".
[0037] Secondly, based on the relationship between the data type of the parameter to be assigned and the data type of the source parameter, the parameter assignment code is generated.
[0038] A1. For each parameter to be assigned a value, determine whether there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter.
[0039] In this application, data type conversion relationships refer to the ability to convert between two data types. For example, if one data type is int32 and the other is float, there is a data type conversion relationship between int32 and float. Conversely, if one data type is string and the other is bool, there is no data type conversion relationship between string and bool.
[0040] A2, if there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter, then the parameter assignment code is generated based on the determination result of whether the data type of the parameter to be assigned and the data type of the source parameter are the same.
[0041] If the determination result indicates that the data type of the parameter to be assigned is different from the data type of the source parameter, then the source parameter is converted to generate a conversion result, and the code of the conversion result is assigned to the parameter to be assigned, which serves as the parameter assignment code.
[0042] by Figure 2 For example, if the source parameter is of type int32 and the parameter to be assigned is of type float, although their data types are different, int32 can be converted to float. The code that performs the data type conversion on the source parameter, generates the conversion result, and assigns the result to the parameter to be assigned is used as the parameter assignment code.
[0043] If the determination result indicates that the data type of the parameter to be assigned is the same as the data type of the source parameter, then the data content of the corresponding source parameter is copied to the code of the parameter to be assigned, and used as the parameter assignment code.
[0044] A3. If the data type of the parameter to be assigned and the data type of the corresponding source parameter do not have a corresponding data type conversion relationship, an error report is generated.
[0045] For example, if data type conversion between the data type of the parameter to be assigned and the corresponding data type of the source parameter is not allowed, that is, if the data type does not meet the assignment requirements, for example, the data type of the original source parameter is string, but the data type of the target protocol is bool, which does not meet the data type conversion requirements, an error will be reported and the process will exit directly.
[0046] Using the methods in A1-A3, assignment code for each parameter to be assigned can be generated.
[0047] In one optional implementation, the method for generating the multi-protocol data conversion program provided in this application further includes the following steps: B1, determine whether the parameter to be assigned that is being processed is the last parameter to be assigned that has not yet been processed in the lowest level structure of the original protocol.
[0048] B2, if it is the last parameter to be assigned, and the data type of each parameter to be assigned in the lowest-level structure of the target protocol is consistent with the data type of the corresponding source parameter, and the number of parameters in the lowest-level structure of the target protocol is consistent with the number of parameters in the lowest-level structure of the original protocol, then the memcpy statement is used as the parameter assignment code.
[0049] Data type consistency means that the type names, lengths, and alignments are all the same. The number of parameters is the same, meaning that the number of fields in the structure in the original protocol is exactly the same as the number of fields in the structure in the target protocol.
[0050] When both of the above conditions are met, it indicates that the memory layout of the structure in the original protocol and the structure in the target protocol are compatible, and a memcpy statement can be generated. The form of the memcpy statement is: memcpy(&Dstruct1, &Sstruct1, sizeof(Dstruct1)).
[0051] The `memcpy` statement directly copies the entire memory contents of the original protocol's structure, such as `Sstruct1`, byte-by-byte into the target protocol's structure, such as `Dstruct1`, without needing to generate separate assignment code for each field. This approach not only significantly reduces the number of lines of code generated but also avoids assignment order errors or omissions that might occur when writing assignments field by field, while simultaneously improving program efficiency by leveraging the contiguous access characteristics of memory.
[0052] B3, if it is not the last parameter to be assigned a value, then the parameter assignment code for that parameter is generated using the methods in A1-A3.
[0053] In one optional implementation, parameters in the target protocol that were not successfully assigned codes can also be statistically output as the first alarm message.
[0054] In one optional implementation, parameters in the original protocol that are not mapped to the target protocol can also be counted and output as a second alarm message.
[0055] S104, Based on the object code of the target structure and the parameter assignment code, generate a multi-protocol data conversion program.
[0056] This step integrates the target structure object definition code generated in S101 with the parameter assignment code generated in S103 according to the data conversion logic order to construct a complete conversion function body. Based on this, the necessary program framework, including function definitions, header file references, and variable declarations, is added and encapsulated as independent, compilable modules or functions. The final generated program can receive original protocol data input, automatically execute data mapping and conversion logic between structures, and output data conforming to the target protocol format, thus forming a complete multi-protocol data conversion program that can be directly used in protocol conversion scenarios.
[0057] In summary, this application uses a Python script to read the macro protocol element mapping relationship in the initial configuration file, automatically generates assignment code, and automatically generates code when the multi-protocol data conversion mapping is completed. When the mapping table changes, the automated script can generate code with one click and report the errors in the table. This eliminates the need for manual coding, thus improving coding efficiency.
[0058] To further understand the technical solution in this application, the following will be combined with... Figure 3 The method for generating the multi-protocol data conversion program provided in this application will be explained again.
[0059] Figure 3 This paper systematically describes the automated generation process of a multi-protocol data conversion program. Its core lies in automatically generating directly compileable and executable data conversion code by parsing the structure definitions in the initial configuration file layer by layer, combined with data type matching verification and overall memory copying optimization strategies. The process begins with reading configuration information, proceeds through hierarchical traversal, conditional branching, and code generation optimization, ultimately forming a complete conversion program.
[0060] Specifically, the initial configuration file is first read, and the highest-level structures corresponding to the original protocol and the target protocol are generated as objects based on the initial configuration file (object code for generating the target structure). Then, the target protocol configuration is traversed, processing layer by layer down to the lowest-level structure (traversing the target protocol to determine the parameters to be assigned), and the parameters in that structure are processed one by one. For each target parameter, it is first determined whether its data type can be converted to the corresponding parameter in the original protocol: if not, an alarm log is output and the process is skipped; if so, it is determined whether the two data types are completely consistent. If they are not completely consistent, assignment code with type casting is generated; if they are completely consistent, direct assignment code is generated.
[0061] After processing each parameter in the current lowest-level structure, it checks if it is the last parameter of that structure. If not, it continues processing the next parameter in the structure. If so, it checks if the number and data types of all parameters in this lowest-level structure of the original and target protocols are completely identical. If they are identical, it deletes the parameter-by-parameter assignment code already generated for that structure and generates a memcpy statement to copy the entire structure. If they are not completely identical, the process ends. The entire process, through layer-by-layer and parameter-by-parameter checks and code generation, ultimately automatically outputs a complete multi-protocol data conversion program.
[0062] Based on the same inventive concept, this application also provides a device for generating a multi-protocol data conversion program. Figure 4 This is a schematic diagram of a device for generating a multi-protocol data conversion program, provided in an embodiment of this application. (In conjunction with...) Figure 4 As shown, the multi-protocol data conversion program generation apparatus 400 provided in this application includes: The structure object determination module 401 is used to generate object code for the target structure based on the name of the target structure in the initial configuration file; the initial configuration file includes the hierarchical level of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchical level of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol; the target structure is the highest-level structure corresponding to the original protocol and the highest-level structure corresponding to the target protocol. The parameter to be assigned module 402 is used to determine the parameters in the lowest level structure corresponding to the target protocol from the initial configuration file as the parameters to be assigned. The parameter assignment code generation module 403 is used to generate parameter assignment code for the parameter to be assigned based on the initial configuration file. The multi-protocol data conversion program determination module 404 is used to generate a multi-protocol data conversion program based on the object code of the target structure and the parameter assignment code.
[0063] In one alternative implementation, the parameter assignment code generation module 403 includes: The source parameter determination submodule is used to determine the parameter in the original protocol corresponding to the parameter to be assigned, based on the mapping relationship, and use it as the source parameter of the parameter to be assigned. The parameter assignment code generation submodule is used to generate the parameter assignment code based on the relationship between the data type of the parameter to be assigned and the data type of the source parameter.
[0064] In one alternative implementation, the parameter assignment code generation submodule includes: The conversion relationship judgment unit is used to determine whether there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter for each parameter to be assigned. The first parameter assignment code generation unit is used to generate the parameter assignment code based on the determination result of whether the data types of the parameter to be assigned and the corresponding data types of the source parameter are the same if there is a corresponding data type conversion relationship between the data types of the parameter to be assigned and the corresponding data types of the source parameter. The second parameter assignment code generation unit is used to generate an error report if there is no corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter.
[0065] In one alternative implementation, the first parameter assignment code generation unit includes: The first code generation subunit is used to perform data type conversion on the source parameter to generate a conversion result and assign the conversion result to the code of the parameter to be assigned if the determination result indicates that the data type of the parameter to be assigned is different from the data type of the source parameter, as the parameter assignment code; The second code generation subunit is used to copy the data content of the corresponding source parameter to the code of the parameter to be assigned if the determination result indicates that the data type of the parameter to be assigned is the same as the data type of the source parameter, and use it as the parameter assignment code.
[0066] In one alternative implementation, the multi-protocol data conversion program generation apparatus 400 further includes: The loop judgment unit is used to determine whether the parameter to be assigned that is being processed is the last parameter to be assigned that has not yet been processed in the lowest level structure of the original protocol. The third code generation subunit is used to assign the memcpy statement as the parameter assignment code if the parameter to be assigned is the last parameter to be assigned, and the data type of each parameter to be assigned in the lowest-level structure of the target protocol is consistent with the data type of the corresponding source parameter, and the number of parameters in the lowest-level structure of the target protocol is consistent with the number of parameters in the lowest-level structure of the original protocol.
[0067] In one alternative implementation, the multi-protocol data conversion program generation apparatus 400 further includes: The first alarm information generation module is used to output the parameters in the target protocol that have not been successfully assigned codes as the first alarm information.
[0068] In one alternative implementation, the multi-protocol data conversion program generation apparatus 400 further includes: The first alarm information generation module is used to output parameters in the original protocol that are not mapped to the target protocol as the second alarm information.
[0069] Based on the automatic generation method and apparatus for protocol data conversion programs provided in the foregoing embodiments, this application also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements some or all of the steps in the automatic generation method for protocol data conversion programs mentioned above.
[0070] Based on the automatic generation method and apparatus for protocol data conversion programs provided in the foregoing embodiments, this application also provides an electronic device, including: A memory on which computer programs are stored; A processor is configured to execute the computer program in the memory to implement some or all of the steps in the automatic generation method of the protocol data conversion program provided in the foregoing embodiments.
[0071] It should be noted that the various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, for the device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiments. The device embodiments described above are merely illustrative, and the units described as separate components may or may not be physically separate. The components indicated as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment solution according to actual needs. Those skilled in the art can understand and implement this without creative effort.
[0072] The above description is merely one specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A method for generating a multi-protocol data conversion program, characterized in that, The method includes: Based on the name of the target structure in the initial configuration file, the object code of the target structure is generated; the initial configuration file includes the hierarchical level of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchical level of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol; the target structure is the highest-level structure corresponding to the original protocol and the highest-level structure corresponding to the target protocol. From the initial configuration file, determine the parameters in the lowest-level structure corresponding to the target protocol as the parameters to be assigned values; Based on the initial configuration file, generate parameter assignment code for the parameters to be assigned; Based on the object code of the target structure and the parameter assignment code, a multi-protocol data conversion program is generated.
2. The method according to claim 1, characterized in that, The step of generating parameter assignment code for the parameters to be assigned based on the initial configuration file includes: Based on the mapping relationship in the initial configuration file, determine the parameter in the original protocol that corresponds to the parameter to be assigned, and use it as the source parameter of the parameter to be assigned; Based on the relationship between the data type of the parameter to be assigned and the data type of the source parameter, the parameter assignment code is generated.
3. The method according to claim 2, characterized in that, The step of generating the parameter assignment code based on the relationship between the data type of the parameter to be assigned and the data type of the source parameter includes: For each parameter to be assigned a value, determine whether there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter; If there is a corresponding data type conversion relationship between the data type of the parameter to be assigned and the data type of the corresponding source parameter, then the parameter assignment code is generated based on the determination result of whether the data type of the parameter to be assigned and the data type of the source parameter are the same. If the data type of the parameter to be assigned and the data type of the corresponding source parameter do not have a corresponding data type conversion relationship, an error report is generated.
4. The method according to claim 3, characterized in that, The step of generating the parameter assignment code based on the determination result of whether the data type of the parameter to be assigned and the data type of the source parameter are the same includes: If the determination result indicates that the data type of the parameter to be assigned is different from the data type of the source parameter, then the source parameter is converted to generate a conversion result and the code of the conversion result is assigned to the parameter to be assigned, which serves as the parameter assignment code. If the determination result indicates that the data type of the parameter to be assigned is the same as the data type of the source parameter, then the data content of the corresponding source parameter is copied to the code of the parameter to be assigned, and used as the parameter assignment code.
5. The method according to any one of claims 1-4, characterized in that, Also includes: Determine whether the parameter to be assigned that is being processed is the last parameter to be assigned that has not yet been processed in the lowest-level structure of the original protocol; If it is the last parameter to be assigned a value, and the data type of each parameter to be assigned a value in the lowest-level structure of the target protocol is consistent with the data type of the corresponding source parameter, and the number of parameters in the lowest-level structure of the target protocol is consistent with the number of parameters in the lowest-level structure of the original protocol, then the memcpy statement is used as the parameter assignment code.
6. The method according to any one of claims 1-4, characterized in that, Also includes: Output the parameters in the target protocol that were not successfully assigned values as the first alarm message.
7. The method according to any one of claims 1-4, characterized in that, Also includes: Output the parameters in the original protocol that are not mapped to the target protocol as the second alarm information.
8. An apparatus for generating a multi-protocol data conversion program, characterized in that, The device includes: The structure object determination module is used to generate object code for the target structure based on the name of the target structure in the initial configuration file. The initial configuration file includes the hierarchical level of the structure corresponding to the parameters in the original protocol, the data type of the parameters in the original protocol, the hierarchical level of the structure corresponding to the parameters in the target protocol, the data type of the parameters in the target protocol, and the mapping relationship between the parameters in the original protocol and the parameters in the target protocol. The target structure is the highest-level structure corresponding to the original protocol and the highest-level structure corresponding to the target protocol. The parameter to be assigned module is used to determine the parameters in the lowest level structure corresponding to the target protocol from the initial configuration file as the parameters to be assigned. The parameter assignment code generation module is used to generate parameter assignment code for the parameter to be assigned based on the initial configuration file. The multi-protocol data conversion program determination module is used to generate a multi-protocol data conversion program based on the object code of the target structure and the parameter assignment code.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the steps of the method described in any one of claims 1-7.
10. An electronic device, characterized in that, include: A memory on which computer programs are stored; A processor for executing the computer program in the memory to implement the steps of the method according to any one of claims 1-7.