Equipment access adaptation code generation method and system, equipment and medium

The Internet of Things device access adaptation code is generated through declarative description language and Hall logic derivation algorithm, which solves the problem of cumbersome equipment docking and realizes efficient and accurate code generation and software maintenance.

CN120255857APending Publication Date: 2025-07-04GUANGDONG ESHORE TECH
View PDF 0 Cites 1 Cited by

Patent Information

Application Number
CN202410013034.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-02
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

When the IoT platform connects with multiple manufacturers, it lacks unified protocol specifications, resulting in cumbersome and high development costs for device docking and adaptation codes, and it is difficult for the existing technology to efficiently generate device access adaptation codes.

Method used

The declarative description language is used to enter and complete the behavior of the target device, deduce the program flowchart of the target function, and generate implementation code based on preset rules, and use Hall logic to perform logical derivation and code generation.

Benefits of technology

It realizes the reuse of information during access to similar devices, reduces the development workload, improves the accuracy and efficiency of code generation, and provides software maintenance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120255857A_ABST
    Figure CN120255857A_ABST
Patent Text Reader

Abstract

The invention provides a device access adaptation code generation method and system, a device and a medium, and the code generation method comprises the steps: inputting the behavior of a target device based on a declarative description language, and obtaining a first input result; on the basis of a declarative description language, performing complementation description input on the design adapted to the target equipment to obtain a second input result; deducing a program flow chart of a target function of the to-be-implemented code according to the first input result and the second input result; and generating an implementation code of the target function according to the program flow chart of the target function and a preset rule. According to the method, equipment behaviors are modeled through the declarative description language, and when equipment of the same kind is accessed but equipment of different manufacturers is accessed, input information can be repeatedly utilized, so that repeated labor is avoided; and meanwhile, a derivation algorithm is introduced to solve a program flow chart realized by target function codes, the program flow chart can be used as input of code generation and can also be used as a carrier for realizing logic through manual inspection, and the code inspection efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of software development, and particularly to a method for generating access adaptation code for Internet of Things devices. Background Art

[0002] After decades of development, software verification technology has successfully proven its feasibility in software development in multiple fields (including chip instructions, aviation software, etc.).

[0003] By reasonably designing a declarative description language to complement the description of code elements, it is possible to prove whether there are defects in the software. However, due to the high cost of complementing the declarative description, it is not used in general information management software.

[0004] Since the Internet of Things platform needs to interface with multiple manufacturers and a variety of devices, but the industry has not formed a unified protocol specification, only the device capabilities are described through a device model. Then the Internet of Things platform needs to smooth out the differences to provide services to the northbound business system with a unified standard device model. The device access adaptation code is numerous and cumbersome, and the development cost of the device access function is relatively high. Summary of the Invention

[0005] Embodiments of the present invention provide a method, system, device, and medium for generating device access adaptation code to solve the problems existing in the related technologies. The technical solutions are as follows:

[0006] In a first aspect, embodiments of the present invention provide a method for generating device access adaptation code, including:

[0007] Enter the behavior of the target device based on a declarative description language to obtain a first input result;

[0008] Enter the complemented description of the design adapted to the target device based on a declarative description language to obtain a second input result;

[0009] Derive the program flow chart of the target function of the code to be implemented according to the first input result and the second input result;

[0010] Generate the implementation code of the target function according to the program flow chart of the target function and preset rules.

[0011] In an implementation manner, the first input result includes the device state diagram entered when there is a state transition in the target device, the function declarations of the instructions and responses supported by the target device, and the events, messages for reporting data, and instruction responses supported by the target device.

[0012] In an implementation manner, the design includes class design and data class design.

[0013] In one implementation, the second input result includes the class design adapted to the target device entered, the declaration of the data class design, and the declarations of the classes and methods of the relevant dependencies entered.

[0014] In one implementation, the derivation method of the program flow chart is as follows:

[0015] Translate the first input result and the second input result into propositions required by Hoare logic;

[0016] Derive a directed acyclic graph of function call dependencies using the propositions required by Hoare logic;

[0017] Convert the directed acyclic graph into a program flow chart.

[0018] In one implementation, the preset rules include the language rules of the preset target language, the rules of code implementation constraints, and the performance optimization rules.

[0019] In one implementation, it further includes:

[0020] Import the implementation code of the target function into the specified project engineering, so that the generated implementation code is filled into the function implementation corresponding to the specified project engineering one by one, and the generation of the device access adaptation code is completed.

[0021] In a second aspect, an embodiment of the present invention provides a device access adaptation code generation system that executes the device access adaptation code generation method as described above.

[0022] In a third aspect, an embodiment of the present invention provides an electronic device, which includes: a memory and a processor. Among them, the memory and the processor communicate with each other through an internal connection path. The memory is used to store instructions, and the processor is used to execute the instructions stored in the memory. And when the processor executes the instructions stored in the memory, the processor executes the method in any one of the above aspects.

[0023] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program. When the computer program runs on a computer, the method in any one of the above aspects is executed.

[0024] The advantages or beneficial effects in the above technical solutions at least include:

[0025] The present invention models the device behavior through a declarative description language. When accessing devices of the same type but from different manufacturers, the information already entered can be reused, avoiding repeated labor;

[0026] Meanwhile, a derivation algorithm is introduced to solve the program flowchart of the code implementation of the objective function. It can be used as the input for code generation and also as a carrier for manual inspection of the implementation logic, which is more efficient than manual code inspection and indirectly provides software maintainability.

[0027] The above summary is only for the purpose of the specification and is not intended to be limiting in any way. In addition to the illustrative aspects, embodiments, and features described above, further aspects, embodiments, and features of the present invention will become apparent by reference to the drawings and the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In the drawings, unless otherwise specified, the same reference numerals throughout the several views refer to the same or like parts or elements. These drawings are not necessarily drawn to scale. It should be understood that these drawings only depict some embodiments disclosed in accordance with the present invention and should not be regarded as limiting the scope of the present invention.

[0029] Figure 1 It is a schematic flowchart of a method for generating device access adaptation code according to the present invention;

[0030] Figure 2 It is a schematic flowchart of a program flowchart derived by a derivation algorithm according to the present invention;

[0031] Figure 3 It is a structural block diagram of an electronic device according to an embodiment of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0032] In the following, only some exemplary embodiments are briefly described. As those skilled in the art will recognize, the described embodiments can be modified in various different ways without departing from the spirit or scope of the present invention. Therefore, the drawings and the description are to be regarded as illustrative in nature and not restrictive.

[0033] Embodiment 1

[0034] This embodiment provides a method for generating device access adaptation code. This method is applied to an Internet of Things platform that needs to access an Internet of Things device, and the Internet of Things device to be accessed is marked as the target device. If there are differences between the device model of the target device and the standard device model, or if the target device accesses the southbound cloud and the manufacturer provides its own interface, the access adaptation code is generated by the method of this embodiment, so that the target device and the Internet of Things platform can be successfully docked.

[0035] Refer to Figure 1 As shown, the method for generating device access adaptation code specifically includes the following steps:

[0036] Step S1: Enter the behavior of the target device based on the declarative description language to obtain the first input result;

[0037] Step S2: Enter the supplementary description of the design adapted to the target device based on the declarative description language to obtain the second input result;

[0038] Step S3: Deduce the program flow chart of the target function of the code to be implemented according to the first input result and the second input result;

[0039] Step S4: Generate the implementation code of the target function according to the program flow chart of the target function and the preset rules.

[0040] In this embodiment, the declarative description language is used to describe the behavior of the device, the declaration of functions or class methods, which is compiled by designers or developers according to actual needs, or existing detailed designs can be imported through tools and supplemented and refined on this basis.

[0041] The declarative description language is different from imperative programming. Imperative programming requires developers to tell the computer step by step to perform a series of operations to obtain the desired result. The declarative description language, however, often describes the desired result in a declarative way and does not interfere with the computer's execution process during this period. As for the execution process of obtaining the desired result, it is automatically calculated by the computer according to a certain algorithm by the pre-written program.

[0042] The declarative description language can be used to declare atomic types. For example, the simple value type declaration: used to define basic data types and value ranges, including common numerical types such as integers, floating-point numbers, and strings; represented by a 4-tuple (base_type, reference name, value range, supported arithmetic operations); arithmetic operation declaration: declare supported mathematical calculations and string operations, represented by a 4-tuple: (operator, reference name, supported mathematical calculations, supported string operations); attribute type declaration: describe specific business object attributes, such as: name, title, code, order payment status, represented by a 5-tuple (property_type, reference name, simple value type reference).

[0043] The declarative description language is used to describe device modeling. The device state can be described by declaring the associated state diagram, and the supported instructions, events, and data reporting messages can be described by declaring the associated functions respectively.

[0044] The declarative description language is used to describe classes, including interface declarations, class definition declarations, and attribute definition declarations. Among them, the interface declaration is used to describe the interfaces in the object-oriented field; it is represented by a 7-tuple (class, reference name, method reference set, extended interface set). The class definition declaration is used to define classes, such as the student class, etc.; it is represented by a 7-tuple (class, reference name, attribute reference set, method reference set, superclass reference, interface set). The attribute definition declaration is used to define attributes or fields. For example, the student business object contains a name attribute; it is denoted as: field definition (reference name, value type, value range, constraint proposition).

[0045] The declarative description language is used to describe functions. Declare the input parameters of the function: used to declare the input parameter list of the methods of the class or library functions; declare the output parameters of the function: used to declare the output parameter list of the methods of the class or library functions; declare the preconditions of the function: used to declare the precondition propositions of the methods of the class or library functions; declare the side effects of the function: used to declare the postcondition propositions of the methods of the class or library functions.

[0046] The declarative description language is used to describe state diagrams, which refer to the state diagrams in the software development field. The state diagram is described by declaring a name, nodes, and directed edges. Among them, the name is the reference name of the state diagram; nodes: used to represent a state; directed edges: pointing from the source node to the target node, with the conditions for state transition attached.

[0047] The declarative description language is used to represent expressions. For example, declare operators, that is, the operators corresponding to common native languages; it can also describe the function call process by declaring function calls.

[0048] In addition, the declarative description language can also declare constants, which are denoted as constant definitions (reference name, numerical type, value, implicative proposition). It can also declare configuration items, which are denoted as: constant definitions (reference name, numerical type, value, implicative proposition).

[0049] Based on the above implementation method of the declarative description language, this embodiment models the behavior of the device, that is, the state migration situation of the target device is entered into the device state diagram, the function declarations of the instructions and responses supported by the target device are entered, and the events, message of the reported data, and instruction responses supported by the target device are entered. So far, the device physical model and device behavior have been entered, and the corresponding first input result is obtained.

[0050] And use the declarative description language of the present invention to complete the description of the detailed design results. In this step, enter the declarations of the detailed design adapted to the target device (including: class design, data class design, etc.), and enter the declarations of related dependent classes and methods. It should be noted that the entered declarations should be consistent with the semantics represented by the detailed design of the device adaptation class. So far, the detailed design related to or dependent on device adaptation has been entered, and then the second input result is obtained.

[0051] Subsequently, use the above-obtained first input result and second input result as the input of the derivation algorithm to derive the program flow chart of the target function of the code to be implemented, and this program flow chart is also the program flow chart in software engineering. Execute the current step for each function of the code to be implemented. In this step, translate the input into the propositions required by Hoare logic, and then use Hoare logic to logically deduce the function call chain and dependent parameters, and then refine it into a complete program flow chart. The more detailed steps are as Figure 2 shown. The key steps of the derivation algorithm principle are as follows:

[0052] Collect the context of the target method, such as: visible class attributes, visible class methods, etc.;

[0053] Import the first input result and the second input result, and translate each statement into a Hoare logic proposition to form a set of Hoare logic propositions;

[0054] Use Hoare logic to derive a function call dependency directed graph, and refine the function call dependency directed graph into a program flow chart; that is, solve the start node and end node of the program flow chart, use the dependency backward deduction method to solve the function / method call nodes from the start node to the end node, and improve the implementation logic of the directed edge as a glue code node to be added to the flow chart, and solve the expression that satisfies the domain of definition of each input parameter of the target edge in-degree node, so as to form a program flow chart.

[0055] Among them, use the function input parameters and the context of the target method as the start node, and the function return parameters as the end node; and the function input parameters, function return parameters, etc. involved in the start node and end node are declared in advance through the declarative description language. In this embodiment, when the start node and end node are determined, the nodes of the function or method call from the start node to the end node are solved according to the dependency backward deduction method. The dependency backward deduction method for solving functions is similar to the rule {P}c{Q} in Hoare logic, and is briefly described as follows: P and Q are first-order logical formulas, representing the pre-condition and post-condition respectively; c represents a section of program source code; its meaning is that assuming the pre-condition P is valid, then after executing the program c, the post-condition Q will be valid.

[0056] Use the program flowchart of the objective function as the input of the code generator, and combine the language rules of the preset target language, the rules of code implementation constraints, and the rules of performance optimization to generate the implementation code of the objective function.

[0057] Among them, for the language rules of the preset target language, there are differences among different target languages, but most of the rules are the same. For example: variables need to be declared before use, and the rule of implicit assignment of variable types, etc.; among them, the rules of code implementation constraints come from the visualized description of the input business information, similar to the Hoare triple; among the rules of performance optimization, common ones are: use batch-dependent methods instead of merging after single-element calls. In this step, the default code generation details are controlled by the preset rules. In this step, the language-related details are controlled by the original language rules, such as: variables need to be declared and initialized before use.

[0058] Import the generated implementation code into the project. In this step, fill in the generated implementation code into the corresponding function implementation one by one. So far, the device access adaptation code has been developed.

[0059] The beneficial effect of the present invention is that the access adaptation code is generated through a declarative description language, and the generated code generally does not need to be modified, has high accuracy, and greatly reduces the development workload.

[0060] Embodiment 2

[0061] This embodiment provides a device access adaptation code generation system, and this system executes the device access adaptation code generation method as in Embodiment 1; this system specifically includes:

[0062] A declaration description module, used to input the behavior of the target device based on a declarative description language to obtain a first input result; and input the supplementary description of the design adapted to the target device based on the declarative description language to obtain a second input result;

[0063] A logical derivation module, used to derive the program flowchart of the objective function of the code to be implemented according to the first input result and the second input result;

[0064] A code generation module, used to generate the implementation code of the objective function according to the program flowchart of the objective function and the preset rules.

[0065] In this embodiment, the device behavior is modeled through a declarative description language. When accessing devices of the same type but from different manufacturers, the already input information can be reused to avoid repetitive labor; at the same time, a derivation algorithm is introduced to solve the program flowchart of the objective function code implementation, which can be used not only as the input for code generation but also as a carrier for manual inspection of the implementation logic, with higher efficiency than manual code inspection, and indirectly provides the maintainability of the software.

[0066] For the functions of the modules in the system according to the embodiments of the present invention, reference may be made to the corresponding descriptions in the above methods, which will not be elaborated herein.

[0067] Embodiment III

[0068] Figure 3 A structural block diagram of an electronic device according to an embodiment of the present invention is shown. As Figure 3 shown, the electronic device includes: a memory 100 and a processor 200. The memory 100 stores a computer program that can run on the processor 200. When the processor 200 executes the computer program, the device access adaptation code generation method in the above embodiments is implemented. The number of the memory 100 and the processor 200 can be one or more.

[0069] The electronic device further includes:

[0070] A communication interface 300, configured to communicate with external devices and perform data interaction and transmission.

[0071] If the memory 100, the processor 200, and the communication interface 300 are implemented independently, the memory 100, the processor 200, and the communication interface 300 can be interconnected through a bus and communicate with each other. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of representation, Figure 3 only a thick line is used to represent it in the figure, but it does not mean that there is only one bus or one type of bus.

[0072] Optionally, in specific implementation, if the memory 100, the processor 200, and the communication interface 300 are integrated on a chip, the memory 100, the processor 200, and the communication interface 300 can communicate with each other through an internal interface.

[0073] The embodiments of the present invention provide a computer-readable storage medium that stores a computer program, and when the program is executed by a processor, the method provided in the embodiments of the present invention is implemented.

[0074] The embodiments of the present invention further provide a chip, which includes a processor for calling and running an instruction stored in a memory from the memory, so that a communication device equipped with the chip executes the method provided in the embodiments of the present invention.

[0075] An embodiment of the present invention further provides a chip, including: an input interface, an output interface, a processor, and a memory. The input interface, the output interface, the processor, and the memory are connected through an internal connection path. The processor is configured to execute the code in the memory. When the code is executed, the processor is configured to execute the method provided by the embodiment of the present invention.

[0076] It should be understood that the above-mentioned processor may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. It is worth noting that the processor may be a processor that supports the advanced RISC machines (ARM) architecture.

[0077] Further, optionally, the above-mentioned memory may include a read-only memory and a random access memory, and may also include a non-volatile random access memory. The memory may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may include a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), or a flash memory. The volatile memory may include a random access memory (RAM), which is used as an external cache. By way of example but not limitation, many forms of RAM are available. For example, static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDR SDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM), and direct rambus random access memory (DR RAM).

[0078] In the above embodiments, it may be implemented in whole or in part by software, hardware, firmware, or any combination thereof. When implemented using software, it may be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions according to the present invention are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium.

[0079] In the description of this specification, the descriptions referring to terms such as "one embodiment", "some embodiments", "example", "specific example", or "some examples", etc. mean that the specific features, structures, materials, or characteristics described in connection with the embodiment or example are included in at least one embodiment or example of the present invention. Moreover, the specific features, structures, materials, or characteristics described can be combined in a suitable manner in any one or more embodiments or examples. In addition, without contradiction, those skilled in the art can combine and combine the different embodiments or examples described in this specification and the features of different embodiments or examples.

[0080] In addition, the terms "first" and "second" are used for descriptive purposes only and cannot be construed as indicating or implying relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In the description of the present invention, "a plurality of" means two or more unless otherwise specifically defined.

[0081] Any process or method description represented in the flowchart or described in other ways herein can be understood to represent a module, segment, or portion of code including one or more executable instructions for implementing a specific logical function or process. And the scope of the preferred embodiments of the present invention includes additional implementations, where the functions can be executed in a substantially simultaneous manner or in a reverse order according to the involved functions, rather than in the order shown or discussed.

[0082] The logic and / or steps represented in the flowchart or described in other ways herein, for example, can be considered as a sequenced list of executable instructions for implementing a logical function, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, apparatus, or device (such as a computer-based system, a system including a processor, or other systems that can fetch and execute instructions from the instruction execution system, apparatus, or device), or in combination with these instruction execution systems, apparatus, or devices.

[0083] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. All or part of the steps of the method in the above embodiments can be completed by a program instructing relevant hardware, and this program can be stored in a computer-readable storage medium. When this program is executed, it includes one or a combination of the steps of the method embodiment.

[0084] In addition, each functional unit in various embodiments of the present invention may be integrated into one processing module, may exist separately as individual physical units, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the above-mentioned integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium. The storage medium may be a read-only memory, a magnetic disk, an optical disc, or the like.

[0085] As described above, the above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art within the technical scope disclosed by the present invention can easily think of various changes or substitutions, and these should all be covered within the protection scope of the present invention. Therefore, the protection scope of the present invention should be subject to the protection scope of the claims.

Claims

1. A method for generating device access adaptation code, characterized in that Including: Enter the behavior of the target device based on a declarative description language to obtain a first entry result; Complete the description entry of the design adapted to the target device based on the declarative description language to obtain a second entry result; Derive the program flow chart of the target function of the code to be implemented according to the first entry result and the second entry result; Generate the implementation code of the target function according to the program flow chart of the target function and preset rules.

2. The method for generating an access adaptation code for a device according to claim 1, wherein The first entry result includes the device state diagram entered when there is a state transition in the target device, the function declarations of the instructions and responses supported by the target device, and the events, reported data messages, and instruction responses supported by the target device.

3. The method for generating device access adaptation code according to claim 1, wherein The design includes class design and data class design.

4. The method for generating an access adaptation code for a device according to claim 1, wherein The second entry result includes the declarations of the class design and data class design adapted to the target device entered, and the declarations of related dependent classes and methods entered.

5. The method for generating device access adaptation code according to claim 1, wherein The derivation method of the program flow chart is as follows: Translate the first entry result and the second entry result into propositions required by Hoare logic; Derive a dependency directed graph of function calls using the propositions required by Hoare logic; Convert the dependency directed graph into the program flow chart.

6. The method for generating device access adaptation code according to claim 1, characterized in that, The preset rules include language rules of the preset target language, rules for code implementation constraints, and performance optimization rules.

7. The method for generating an access adaptation code for a device according to claim 1, wherein Also included: Import the implementation code of the target function into a specified project engineering, so that the generated implementation code is filled into the function implementation corresponding to the specified project engineering one by one, and the generation of device access adaptation code is completed.

8. A device access adaptation code generation system, characterized in that, Execute the device access adaptation code generation method according to any one of claims 1 to 7.

9. An electronic device, characterized in that, Including: A processor and a memory, wherein instructions are stored in the memory, and the instructions are loaded and executed by the processor to implement the device access adaptation code generation method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, A computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the device access adaptation code generation method according to any one of claims 1 to 7 is implemented.

Citation Information

Cited By

  • Method for synchronizing multiple hardware engines and computer readable storage medium

    CN121833054A