Interface calling method and device, electronic equipment and storage medium
Patent Information
- Application Number
- CN202280098023.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-29
- Publication Date
- 2025-02-25
AI Technical Summary
When generating an interface calling program through a behavior tree, users need to fully understand the structure of the state machine and the definition of behavior nodes, resulting in a poor user experience for interface calling and high professional requirements.
By obtaining the description information of the state machine, determining the state jump information and state sequence information, generating a subtree template in the form of a behavior tree, instantiating the subtree template, and obtaining the interface calling program, reducing the user's understanding of interface standards and behavior node definitions needs.
It improves the user experience of interface calling, reduces the time and professional requirements for understanding interface standards and behavior node definitions, and simplifies the interface calling process.
Smart Images

Figure 00000019_0000 
Figure 00000020_0000 
Figure 00000021_0000
Abstract
Description
Interface calling method, device, electronic device and storage medium Technical Field
[0001] The present application relates to the field of communication technology, and in particular to an interface calling method, device, electronic device and storage medium. Background Art
[0002] A state machine, comprised of state registers and combinational logic circuits, can transition between pre-defined states based on control signals. It serves as the control center for coordinating related signal actions and completing specific operations. In industrial production systems, different modules exchange information through interface calls. The interface call logic can be defined using a state machine. The complexity of the state machine used to define the interface call logic varies depending on the module's functionality. Some state machines include multiple states and complex transition relationships between states. When implementing information exchange between modules, behavior trees can be used to generate interface call routines.
[0003] Currently, when generating an interface call program through a behavior tree, each state included in the state machine used to define the corresponding interface call logic is mapped to a behavior node. The user sets the execution order and execution logic of each behavior node to generate the interface call program for the interface call.
[0004] However, in order for users to set the execution order and execution logic of each behavior node, they need to fully understand the definition of each behavior node and the structure of the state machine, which requires a high level of professionalism from the user, resulting in a poor user experience for interface calls.
[0005] Summary of the Invention
[0006] In order to solve the above technical problems, the embodiments of the present application provide an interface calling method, device, electronic device and storage medium, which can improve the user experience of interface calling.
[0007] According to a first aspect of an embodiment of the present application, an interface calling method is provided, comprising: obtaining description information of a state machine, wherein the state machine is used to define the calling logic of the interface to be called, and the description information is used to describe the structure of the state machine; determining state jump information and state sequence information based on the description information, wherein the state jump information is used to indicate a jump path between at least two states included in the state machine, and the state sequence information is used to indicate an initial state and a target state of the state machine; generating a subtree template in the form of a behavior tree based on the state jump information and the state sequence information; instantiating the subtree template to obtain an interface calling program of the interface to be called; and calling the interface to be called through the interface calling program.
[0008] According to a second aspect of an embodiment of the present application, an interface calling device is provided, comprising: an acquisition module for acquiring description information of a state machine, wherein the state machine is used to define the calling logic of the interface to be called, and the description information is used to describe the structure of the state machine; an extraction module for determining state jump information and state sequence information based on the description information, wherein the state jump information is used to indicate a jump path between at least two states included in the state machine, and the state sequence information is used to indicate an initial state and a target state of the state machine; a generation module for generating a subtree template in the form of a behavior tree based on the state jump information and the state sequence information; an instantiation module for instantiating the subtree template to obtain an interface calling program of the interface to be called; and a calling module for calling the interface to be called through the interface calling program.
[0009] According to the third aspect of the embodiment of the present application, an electronic device is provided, comprising: a processor, a communication interface, a memory and a communication bus, wherein the processor, the memory and the communication interface communicate with each other through the communication bus; the memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform the operation corresponding to the interface calling method in the above-mentioned first aspect.
[0010] According to the fourth aspect of the embodiment of the present application, a computer-readable storage medium is provided, on which computer instructions are stored. When the computer instructions are executed by a processor, the processor executes the interface calling method in the above-mentioned first aspect.
[0011] According to the fifth aspect of the embodiment of the present application, a computer program product is provided, which is tangibly stored on a computer-readable medium and includes computer-executable instructions, which, when executed, enable at least one processor to execute the interface calling method in the above-mentioned first aspect.
[0012] As can be seen from the above technical solution, after obtaining the state jump information and state sequence information of the state machine, a subtree template in the form of a behavior tree is generated based on the state jump information and state sequence information. By instantiating the subtree template, the user can obtain an interface caller, and then use this interface caller to call the interface to be called. By generating a subtree template, the jump path and behavior node definitions before each state in the state machine are solidified in the subtree template. Users do not need to spend a lot of time understanding the interface standards and behavior node definitions. They only need to instantiate the subtree template to obtain the interface caller for calling the interface, thereby improving the user experience of interface calling. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] FIG1 is a flow chart of an interface calling method according to an embodiment of the present application;
[0014] FIG2 is a flow chart of a method for generating a subtree template according to an embodiment of the present application;
[0015] FIG3 is a schematic diagram of a state machine illustration image according to an embodiment of the present application;
[0016] FIG4 is a schematic diagram of a subtree template according to an embodiment of the present application;
[0017] FIG5 is a schematic diagram of a subtree template according to another embodiment of the present application;
[0018] FIG6 is a schematic diagram of an interface calling program according to an embodiment of the present application;
[0019] FIG7 is a schematic diagram of an interface calling program according to another embodiment of the present application;
[0020] FIG8 is a schematic diagram of an interface calling device according to an embodiment of the present application;
[0021] FIG9 is a schematic diagram of an electronic device according to an embodiment of the present application.
[0022] List of reference numerals:
[0023] 100: Interface calling method 200: Subtree template generation method 800: Interface calling device
[0024] 900: Electronic device 801: Acquisition module 802: Extraction module
[0025] 803: Generate module 804: Instantiate module 805: Call module
[0026] 902: Processor 904: Communication interface 906: Memory
[0027] 908: Communication bus 910: Programs 301-316: State of the state machine
[0028] 401-415: Behavior nodes 501-517: Behavior nodes
[0029] 101: Get the description of the state machine
[0030] 102: Determine the state jump information and state sequence information based on the description information
[0031] 103: Generate a subtree template in the form of a behavior tree based on state jump information and state sequence information
[0032] 104: Instantiate the subtree template and obtain the interface caller of the interface to be called
[0033] 105: Call the interface to be called through the interface calling program
[0034] 201: Determine at least one alternative path through a path search algorithm based on the state jump information and the state sequence information
[0035] 202: Generate corresponding alternative subtree templates based on each alternative path
[0036] 203: Select at least one subtree template from each candidate subtree template according to the received template screening instruction DETAILED DESCRIPTION
[0037] As previously mentioned, when generating a caller for an interface that defines call logic through a state machine, each state in the state machine is mapped to a behavior node. The user then sets the execution order and logic between the behavior nodes. Because there may be multiple jump paths between states in the state machine, the user must first understand the jump paths between states in the state machine. This requires a full understanding of the interface standard and the definition of each behavior node in the behavior tree. Therefore, before implementing an interface call, the user needs to spend considerable time understanding the interface standard and the definition of the behavior node, resulting in a poor user experience in experimental interface calls.
[0038] In an embodiment of the present application, state jump information and state sequence information are determined based on the description information of the state machine. The state jump information can indicate the jump path between the various states included in the state machine, and the state sequence information can indicate the initial state and target state of the state machine. A subtree template in the form of a behavior tree can be generated based on the state jump information and state sequence information. By instantiating the subtree template, an interface call program for calling the corresponding interface can be obtained. By generating the subtree template, when implementing an interface call, the user only needs to instantiate the subtree template to obtain the interface call program, eliminating the need to spend a lot of time understanding the interface standard and the definition of the behavior node, thereby improving the user's experience with interface calls.
[0039] The following describes in detail the interface calling method, device, and electronic device provided in the embodiments of the present application.
[0040] FIG1 is a flow chart of an interface calling method according to an embodiment of the present application. As shown in FIG1 , the interface calling method 100 includes the following steps:
[0041] Step 101: Obtain description information of the state machine.
[0042] The calling logic of the interface to be called is defined by a state machine. The state machine description can describe the structure of the state machine. The state machine includes multiple states, and different states can jump when the corresponding trigger conditions are met. Therefore, the state machine can define the calling logic of the interface to be called. The jump path between states defines the calling order of the interface to be called, and the trigger conditions define the operations to be performed by the interface to be called.
[0043] The description information may describe the structure of the state machine. The description information may be text information used to describe the structure of the state machine, or image information used to describe the structure of the state machine. This embodiment of the present application does not limit this.
[0044] Step 102: Determine state jump information and state sequence information according to the description information.
[0045] The state jump information may indicate a jump path between at least two states included in the state machine. For example, if the state machine includes an idle state, an executing state, and a completed state, and the state machine can jump from the idle state to the executing state, and then from the executing state to the completed state, the state jump information may indicate the jump path from the idle state to the executing state, and from the executing state to the completed state.
[0046] The state sequence information can indicate the initial state and target state of the state machine. The initial state is the state that the state machine is in when it starts working. For example, in a state machine that defines a module type package (MTP) format interface, the initial state is the idle state. The target state is the state that the state machine is in when achieving the set goal. For example, in a state machine that defines an MTP format interface, the target state is the execution state.
[0047] Step 103: Generate a subtree template in the form of a behavior tree based on the state jump information and the state sequence information.
[0048] Since state jump information can indicate the jump paths between different states in a state machine, and state sequence information can indicate the initial state and target state of a state machine, the state machine can be mapped into a subtree template in the form of a behavior tree based on the state jump information and state sequence information. The connection relationship of the behavior nodes in the subtree template is determined based on the state jump information, and the execution order of the behavior nodes in the subtree template is determined based on the state sequence information.
[0049] At least some of the behavior nodes included in the subtree template correspond to the states in the state machine. For example, the idle state in the state machine corresponds to the idle state judgment node in the subtree template, and the execution state in the state machine corresponds to the execution completion judgment node in the subtree template.
[0050] In a behavior tree, behavior nodes are executed from left to right. Therefore, in a subtree template, the behavior node corresponding to the initial state is located to the left of the behavior node corresponding to the target state.
[0051] Step 104: Instantiate the subtree template to obtain the interface calling program of the interface to be called.
[0052] The subtree template is a general template for different interfaces that meet the same interface standard. That is, for different modules, if the interfaces of each module adopt the same interface standard, the interface call program corresponding to each module can be generated separately through the subtree template corresponding to the interface standard.
[0053] As a generic template corresponding to a specific interface standard, a subtree template lacks the corresponding interface call parameters, so it's impossible to directly call the interface through the subtree template. After instantiating the subtree template based on the received instantiation data, an interface caller capable of calling the interface to be called can be generated. This instantiation data may include the IP address and module identification information of the module corresponding to the interface to be called.
[0054] Step 105: Call the interface to be called through the interface calling program.
[0055] After obtaining the interface calling program, the interface to be called can be called through the interface calling program to realize information interaction with the functional module corresponding to the interface to be called, send corresponding data to the functional module, or control the functional module to perform corresponding processing.
[0056] In an embodiment of the present application, after obtaining the state jump information and state sequence information of the state machine, a subtree template in the form of a behavior tree is generated based on the state jump information and state sequence information. By instantiating the subtree template, the user can obtain an interface call program, and then use the interface call program to call the interface to be called. By generating the subtree template, the jump path and behavior node definitions before each state in the state machine are solidified in the subtree template. The user does not need to spend a lot of time understanding the interface standards and behavior node definitions. Only by instantiating the subtree template can the interface call program for calling the interface be obtained, thereby improving the user experience of interface calling.
[0057] In one possible implementation, when generating a subtree template based on state jump information and state sequence information, since the state machine may include multiple states, and the same state can jump to different states, multiple subtree templates with different structures can be generated according to different state jump paths, and then the required subtree template can be selected from the multiple generated subtree templates.
[0058] FIG2 is a flow chart of a subtree template generation method according to an embodiment of the present application. As shown in FIG2 , the subtree template generation method 200 includes the following steps:
[0059] Step 201: Determine at least one candidate path using a preset path search algorithm according to state jump information and state sequence information.
[0060] The state jump information indicates the jump path between states in the state machine, and the state sequence information indicates the starting state and the target state. Through the path search algorithm, multiple alternative paths with the initial state as the starting point and the target state as the end point can be determined. The first state and the second state are adjacent in any order in each alternative path. The state jump information defines that the state machine can jump from the first state to the second state.
[0061] The path search algorithm used for searching for alternative paths may be a depth-first search algorithm, a breadth-first search algorithm, etc., which is not limited in the embodiments of the present application.
[0062] Taking the MTP standard interface as an example, the state machine includes the idle state, execute state, completed state, paused state, held state, stopped state, and aborted state. Table 1 below is a representation of state jump information and state sequence information, showing the jump paths between the above states, as well as the initial state and target state.
[0063] Table 1
[0064]
[0065] In Table 1 above, "-" indicates that the corresponding From state cannot jump to the corresponding To state, for example, the idle state cannot jump to the completed state. Non-"-" content indicates that the corresponding From state can jump to the corresponding To state, for example, the completed state can jump to the idle state. Non-"-" content is the jump condition for the corresponding From state to the corresponding To state, for example, the jump condition for jumping from the execution state to the hold state is receiving the hold instruction Hold. The idle state displayed in bold font indicates the initial state, and the execution state displayed in bold font indicates the target state.
[0066] According to Table 1 above, the candidate paths starting from the idle state and ending at the execution state include the idle state-execution state, the idle state-stop state-idle state-execution state, etc. Through the path search algorithm, all candidate paths that meet the conditions can be searched.
[0067] Step 202: Generate a corresponding candidate subtree template according to each candidate path.
[0068] For each candidate path identified, a corresponding candidate subtree template is generated based on the states included in the candidate path and the jump paths between states. Because different candidate paths may not include exactly the same states or have exactly the same jump paths between states, different candidate subtree templates are generated for different candidate paths.
[0069] Step 203: Select at least one subtree template from each candidate subtree template according to the received template screening instruction.
[0070] After generating the alternative subtree templates corresponding to each alternative path, each alternative subtree template can be displayed to the user for screening, and the template screening instructions input by the user can be obtained, and then one or more alternative subtree templates can be selected from each alternative subtree template according to the template screening instructions as the subtree templates for subsequent instantiation.
[0071] The user who screens the candidate subtree templates can be a user with relevant professional knowledge, such as a user who understands the corresponding interface standard. After the subtree template is selected from the candidate subtree templates, it is saved for subsequent use, eliminating the need to regenerate the subtree template each time the interface is called.
[0072] In an embodiment of the present application, based on state jump information and state sequence information, a path search algorithm is used to determine an alternative path that meets the conditions. After generating an alternative subtree template corresponding to each alternative path, the user filters out the subtree template that meets the interface call requirements from each alternative subtree template, ensuring that each alternative subtree template includes a subtree template that meets the interface call requirements, and the user only needs to filter out the subtree template that meets the requirements from the alternative subtree template, ensuring that an interface call program that can call the interface normally can be generated based on the filtered subtree template, while reducing the labor intensity of the user in the subtree template generation process.
[0073] In one possible implementation, the description information of the state machine may be a description document or a description image of the state machine. When the description information is a description document of the state machine, a pre-trained semantic analysis model may be used to perform semantic analysis on the description document of the state machine to obtain state transition information and state sequence information. When the description information is a description image of the state machine, a pre-trained image processing model may be used to analyze the description image of the state machine to obtain state transition information and state sequence information.
[0074] Since the description document of the state machine will describe in detail the states included in the state machine, the jump paths between states and the triggering conditions of state jumps, by performing semantic analysis on the description document of the state machine through a pre-trained semantic analysis model, the jump paths between states in the state machine, as well as the initial state and target state can be determined, and then the state jump information and state sequence information can be obtained.
[0075] The description image of the state machine can also illustrate the states included in the state machine, the jump paths between states, and the triggering conditions for state jumps, etc. By analyzing the description image of the state machine through a pre-trained image processing module, the jump paths between states in the state machine, as well as the initial state and target state can be determined, and then the state jump information and state sequence information can be obtained.
[0076] FIG3 is a schematic diagram illustrating an image of a state machine according to an embodiment of the present application. As shown in FIG3 , the state machine jumps from an idle state 301 to a start state 302 in response to a Start instruction. The start state 302 automatically jumps to an execution state 303. The execution state 303 can automatically jump to a completion state 304. The completion state 304 automatically jumps to a completion state 305. The state machine jumps from the completion state 305 to the reset state 306 in response to a reset instruction Reset. The reset state 306 automatically jumps to the idle state 301. The state machine can jump from the execution state 303 to the completion state 304 in response to a complete instruction Complete. The state machine can also jump from the execution state 303 to the start state 302 in response to a restart instruction. The state machine can jump from the execution state 303 to the pause state 307 in response to the pause instruction Pause, and the pause state 307 can spontaneously jump to the pause state 308. The state machine can jump from the pause state 308 to the resume state 309 in response to the resume instruction Resume, and the resume state 309 can spontaneously jump to the execution state 303.
[0077] The state machine can jump from the start state 302, the execution state 303, the completion state 304, the paused state 307, the paused state 308, the resuming state 309 or the hold released state 312 to the hold execution state 310 in response to the hold instruction Hold, and the hold execution state 310 spontaneously jumps to the hold state 311. The state machine jumps from the hold state 311 to the hold released state 312 in response to the hold release instruction Unhold, and the hold released state 312 spontaneously jumps to the execution state 303.
[0078] The state machine can jump from the idle state 301, the start state 302, the execution state 303, the completing state 304, the completing state 305, the resetting state 306, the paused state 307, the paused state 308, the resuming state 309, the keep executing state 310, the keep state 311 or the keep released state 312 to the stopping state 313 in response to the stop instruction Stop, and the stopping state 313 can spontaneously jump to the stopping state 314. The state machine can jump from the stopping state 314 to the resetting state 306 in response to the reset instruction Rest.
[0079] The state machine can jump from the idle state 301, the start state 302, the execution state 303, the completing state 304, the completing state 305, the resetting state 306, the pausing state 307, the pausing state 308, the resuming state 309, the keep executing state 310, the hold state 311, the hold released state 312, the stopping state 313 or the stopping state 314 to the stopping state 315 in response to the stop instruction Stop, and the stopping state 315 can spontaneously jump to the stopping state 316. The state machine can jump from the stopping state 316 to the resetting state 306 in response to the reset instruction Rest.
[0080] In an embodiment of the present application, the description information of the state machine can be a description document or image of the state machine, thereby making the interface calling method applicable to interfaces using different forms of interface standard descriptions, thereby improving the applicability of the interface calling method. By obtaining state jump information and state sequence information through a pre-trained semantic analysis model or image processing model, the time-consuming manual understanding of the interface standard is eliminated, the efficiency of subtree template generation is improved, and the labor intensity of manual work is reduced.
[0081] In one possible implementation, when generating a subtree template in the form of a behavior tree, a jump condition for a state machine to jump from an execution state to a completion state can be determined based on state jump information, where the jump condition includes at least one of a spontaneous jump and a triggered jump. If the jump condition for the state machine to jump from an execution state to a completion state includes a spontaneous jump, a first subtree template for a spontaneous jump is generated based on the state jump information and the state sequence information. If the jump condition for the state machine to jump from an execution state to a completion state includes a triggered jump, a second subtree template for a triggered jump is generated.
[0082] As shown in Figure 3, the executing state 303 can jump to the completing state 304 spontaneously, or in response to the completion instruction Complete, and the completing state 304 can jump to the completed state 305 spontaneously. Correspondingly, as shown in Table 1 above, the trigger condition for jumping from the executing state to the completed state can be a triggered jump (Complete) or a spontaneous jump (Self-complete).
[0083] Figure 4 is a schematic diagram of a subtree template according to one embodiment of the present application, and Figure 5 is a schematic diagram of a subtree template according to another embodiment of the present application. The subtree template shown in Figure 4 is the first subtree template generated for a spontaneous jump, and behavior node 405 performs the action of determining whether the jump is completed. The subtree template shown in Figure 5 is the second subtree template generated for a triggered jump, and behavior node 505 performs the action of determining whether a completion instruction has been received.
[0084] It should be noted that the above example only takes the jump conditions of one state in the state machine including spontaneous jump and triggered jump as an example. In actual business processing, the state machine may have multiple states with jump conditions including spontaneous jump and triggered jump. When the jump conditions of multiple states include spontaneous jump and triggered jump, more subtree templates can be generated.
[0085] In an embodiment of the present application, according to the jump conditions of the state jump in the state machine, corresponding subtree templates can be generated for spontaneous jumps and triggered jumps respectively. When the user generates an interface calling program based on the subtree template, the user can select the subtree template corresponding to the spontaneous jump or the subtree template corresponding to the triggered jump to generate the interface calling program according to actual business needs, thereby meeting different types of interface calling requirements and improving the applicability of the interface calling method.
[0086] In a possible implementation, the state jump information is used to indicate a jump path between at least two stable states in the state machine, where a stable state refers to a state that the state machine can stably maintain.
[0087] As shown in Figure 3, the Idle state 301, Execution state 303, Completion state 305, Pause state 308, Hold state 311, Stop state 314, and Abort state 316, represented by solid lines, are stable states of the state machine. State transitions from stable states require corresponding instructions to trigger. The Start state 302, Completion state 304, Reset state 306, Pause state 307, Resume state 309, Hold execution state 310, Hold release state 312, Stop state 313, and Abort state 315, represented by dashed lines, are unstable states of the state machine and will spontaneously transition to the corresponding stable state.
[0088] Table 1 above shows the state jump information and state sequence information corresponding to the description information shown in FIG. 3 . It can be seen that the state jump information and state sequence information only show the jump path of the stable state of the state machine.
[0089] In an embodiment of the present application, the state jump information only includes the stable state of the state machine, indicating the jump path between the stable states, while omitting the unstable state of the state machine, ensuring that the subtree template generated based on the state jump information and state sequence information has a simpler structure, making it convenient for users to instantiate the subtree template.
[0090] In one possible implementation, before generating the subtree template, the state transition information may be modified according to the received information modification instruction, and then a subtree template in the form of a behavior tree may be generated based on the modified state transition information and state sequence information. Modifying the state transition information includes at least one of the following:
[0091] (i) Adding a state jump path of the state machine to the state jump information;
[0092] (ii) deleting at least one state transition path of the state machine in the state transition information.
[0093] In an example, the state jump information shown in Table 1 above indicates the jump paths between the idle state, execution state, completion state, pause state, hold state, stop state and abort state. According to actual business needs, the user will not use the method of jumping from the pause state to the execution state during the interface call process. In this case, the jump path from the pause state to the execution state in the state jump information is deleted, and then a subtree template is generated based on the modified state jump information and state sequence information. The generated subtree template is shown in Figure 4. It can be seen that the subtree template shown in Figure 4 does not include a behavior node for executing the jump from the pause state to the execution state.
[0094] It should be noted that adding a state jump path includes modifying the jump conditions between existing states, the jump path between a new state and an existing state, adding a jump path between existing states, and the jump path between new states. Deleting a state jump path includes deleting the jump path between existing states.
[0095] and delete state jump paths, including modifying jump conditions between states, as well as adding and deleting states.
[0096] In an embodiment of the present application, in the process of generating a subtree template, the user can modify the state jump information according to needs. The modification of the state jump information includes adding a new jump path and / or deleting a jump path, and then generating a subtree template based on the modified state jump information and state sequence information, so that the interface calling program generated based on the subtree template can meet the user's needs for calling the interface, thereby meeting the needs of different users and application scenarios.
[0097] In one possible implementation, when instantiating a subtree template and obtaining an interface calling program, the subtree template can be modified according to the received template modification instruction, and then the modified subtree template is instantiated to obtain an interface calling program for the interface to be called. The modification of the subtree template includes at least one of the following:
[0098] (i) adding at least one behavior node to the subtree template;
[0099] (ii) Delete at least one behavior node in the subtree template.
[0100] Figure 6 is a schematic diagram of an interface calling program according to one embodiment of the present application, and Figure 7 is a schematic diagram of an interface calling program according to another embodiment of the present application. The interface calling program shown in Figure 6 is generated based on the first subtree template shown in Figure 4, and the interface calling program shown in Figure 7 is generated based on the second subtree template shown in Figure 5.
[0101] As shown in Figures 4 and 6, before instantiating the first subtree template, behavior nodes 412 to 415 are added to the first subtree template. Behavior node 412 is used to set configuration parameters, behavior node 413 is used to switch operating modes, behavior node 414 is used to select a program, and behavior node 415 is used to set program parameters. After adding behavior nodes 412 to 415 to the first subtree template, the modified first subtree template is instantiated to obtain the interface call program shown in Figure 6.
[0102] As shown in Figures 5 and 7, before instantiating the second subtree template, behavior nodes 514 to 517 are added to the template. Behavior node 514 is used to set configuration parameters, behavior node 515 is used to switch operating modes, behavior node 516 is used to select a program, and behavior node 517 is used to set program parameters. After adding behavior nodes 514 to 517 to the second subtree template, the modified second subtree template is instantiated to obtain the interface caller shown in Figure 7.
[0103] It should be noted that adding a new behavior node includes adding a leaf node, adding a parent node and a leaf node, transferring an existing behavior node to another parent node, etc. Deleting a behavior node includes deleting a leaf node, deleting a parent node and its child nodes, and moving a behavior node from its parent node.
[0104] It should be noted that in Figures 4 to 7, the behavior nodes marked with "?" are used to execute their child nodes in order from left to right. If a child node returns a success, execution of the subsequent child nodes is stopped and a success return is returned to the parent node. If a child node returns a failure, execution of the next child node is executed in order from left to right. If all child nodes return a failure, execution failure is returned to the parent node. In Figures 4 to 7, the behavior nodes marked with "→*" are used to execute their child nodes in order from left to right until all child nodes are executed.
[0105] In an embodiment of the present application, before instantiating the subtree template, the user modifies the subtree template according to actual needs. The modification to the subtree template includes adding behavior nodes and / or deleting behavior nodes, and then instantiating the modified subtree template to obtain an interface calling program to meet the user's personalized needs for interface calling, improve the applicability of the interface calling method, and improve the user's experience of using the interface calling.
[0106] In a possible implementation, after generating a subtree template according to the state jump information and the state sequence information, template code may be filled in each behavior node included in the subtree template, wherein the template code is used to implement the processing logic of the corresponding behavior node.
[0107] Each behavior node is used to perform corresponding operations to implement the corresponding processing logic. The execution of corresponding operations by a behavior node requires the corresponding code implementation. By filling each behavior node included in the subtree template with template code, the behavior node is able to implement its processing logic. When generating interface call programs for different interfaces using the subtree template, the template code in the behavior node is universal. In one example, the template code can be code that complies with the OPCUA protocol.
[0108] In an embodiment of the present application, by filling in the corresponding template code in each behavior node included in the subtree template, each behavior node has the basic ability to implement its processing logic. When the subtree template is instantiated to obtain the interface calling program, the user does not need to fill in the template code for each behavior node each time it is instantiated, which can avoid the user's repetitive work and improve the generation efficiency of the interface calling program.
[0109] In a possible implementation, when instantiating a subtree template to obtain an interface calling program, instantiation data of each behavior node included in the subtree template may be obtained, and then the instantiation data may be filled in each behavior node to obtain the interface calling program.
[0110] In an embodiment of the present application, each behavior node included in the subtree template has been filled with template code. When instantiating the subtree template, it is only necessary to obtain the instantiation data of the interface to be called. The instantiation data may include the IP address of the module corresponding to the interface to be called, module identification information, etc. After filling the instantiation data into the corresponding behavior node, each behavior node has the ability to perform the corresponding action for the interface to be called, thereby obtaining the interface calling program. The user only needs to fill the instantiation data into each behavior node included in the subtree template to obtain the interface calling program, reducing the user's operation steps during the interface calling process and ensuring the user experience during the interface calling process.
[0111] Interface calling device
[0112] FIG8 is a schematic diagram of an interface calling device according to an embodiment of the present application. As shown in FIG8 , the interface calling device 800 includes:
[0113] The acquisition module 801 is used to obtain description information of the state machine, wherein the state machine is used to define the calling logic of the interface to be called, and the description information is used to describe the structure of the state machine;
[0114] Extraction module 802, configured to determine state jump information and state sequence information based on the description information, wherein the state jump information is used to indicate a jump path between at least two states included in the state machine, and the state sequence information is used to indicate an initial state and a target state of the state machine;
[0115] A generation module 803 is used to generate a subtree template in the form of a behavior tree based on the state jump information and the state sequence information;
[0116] The instantiation module 804 is used to instantiate the subtree template and obtain the interface calling program of the interface to be called;
[0117] The calling module 805 is used to call the interface to be called through the interface calling program.
[0118] It should be noted that the information interaction, execution process, etc. between the modules in the above-mentioned interface calling device are based on the same concept as the previous interface calling method embodiment. The specific content can be found in the description in the previous interface calling method embodiment and will not be repeated here.
[0119] electronic devices
[0120] FIG9 is a schematic diagram of an electronic device provided in an embodiment of the present application. The specific embodiments of the present application do not limit the specific implementation of the electronic device. Referring to FIG9 , the electronic device 900 provided in an embodiment of the present application includes: a processor 902, a communications interface 904, a memory 906, and a communication bus 908. Among them:
[0121] The processor 902 , the communication interface 904 , and the memory 906 communicate with each other via a communication bus 908 .
[0122] The communication interface 904 is used to communicate with other electronic devices or servers.
[0123] The processor 902 is used to execute the program 910, and specifically can execute the relevant steps in any of the aforementioned interface calling method embodiments.
[0124] Specifically, the program 910 may include program codes, which include computer operation instructions.
[0125] Processor 902 may be a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the smart device may be processors of the same type, such as one or more CPUs, or may be processors of different types, such as one or more CPUs and one or more ASICs.
[0126] The memory 906 is used to store the program 910. The memory 906 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0127] The program 910 can be specifically used to enable the processor 902 to execute the interface calling method in any of the aforementioned embodiments.
[0128] The specific implementation of each step in program 910 can refer to the corresponding description of the corresponding steps and units in any of the aforementioned interface calling method embodiments, and will not be repeated here. Those skilled in the art will clearly understand that for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding process descriptions in the aforementioned method embodiments, and will not be repeated here.
[0129] In an embodiment of the present application, after obtaining the state jump information and state sequence information of the state machine, a subtree template in the form of a behavior tree is generated based on the state jump information and state sequence information. By instantiating the subtree template, the user can obtain an interface call program, and then use the interface call program to call the interface to be called. By generating the subtree template, the jump path and behavior node definitions before each state in the state machine are solidified in the subtree template. The user does not need to spend a lot of time understanding the interface standards and behavior node definitions. Only by instantiating the subtree template can the interface call program for calling the interface be obtained, thereby improving the user experience of interface calling.
[0130] Computer storage media
[0131] The present application also provides a computer-readable storage medium storing instructions for causing a machine to execute the interface calling method described herein. Specifically, a system or device equipped with a storage medium can be provided, wherein the storage medium stores software program code that implements the functions of any of the above embodiments, and a computer (or CPU or MPU) of the system or device can read and execute the program code stored in the storage medium.
[0132] In this case, the program code read from the storage medium itself can realize the function of any one of the above embodiments, so the program code and the storage medium storing the program code constitute part of this application.
[0133] Examples of storage media for providing program code include floppy disks, hard disks, magneto-optical disks, optical disks (such as CD-ROM, CD-R, CD-RW, DVD-ROM, DVD-RAM, DVD-RW, DVD+RW), magnetic tapes, non-volatile memory cards, and ROMs. Alternatively, the program code can be downloaded from a server computer via a communication network.
[0134] In addition, it should be clear that the functions of any of the above embodiments can be achieved not only by executing the program code read by the computer, but also by enabling the operating system operating on the computer to complete part or all of the actual operations based on the instructions of the program code.
[0135] In addition, it can be understood that the program code read from the storage medium is written into a memory provided in an expansion board inserted into the computer or into a memory provided in an expansion module connected to the computer, and then based on the instructions of the program code, a CPU installed on the expansion board or expansion module is enabled to perform part or all of the actual operations, thereby realizing the functions of any of the above embodiments.
[0136] Computer program product
[0137] The present application also provides a computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions. When executed, the computer-executable instructions cause at least one processor to perform the interface calling methods provided in the aforementioned embodiments. It should be understood that each solution in this embodiment has the corresponding technical effects of the aforementioned method embodiments and will not be further elaborated here.
[0138] It should be noted that not all steps and modules in the above processes and system structure diagrams are required, and certain steps or modules can be omitted according to actual needs. The execution order of each step is not fixed and can be adjusted as needed. The system structure described in the above embodiments can be a physical structure or a logical structure, that is, some modules may be implemented by the same physical entity, or some modules may be implemented by multiple physical entities, or may be implemented by certain components in multiple independent devices.
[0139] In the above embodiments, the hardware module can be implemented mechanically or electrically. For example, a hardware module can include a permanent dedicated circuit or logic (such as a dedicated processor, FPGA or ASIC) to complete the corresponding operation. The hardware module can also include programmable logic or circuits (such as a general-purpose processor or other programmable processors), which can be temporarily set by software to complete the corresponding operation. The specific implementation method (mechanical method, or dedicated permanent circuit, or temporarily set circuit) can be determined based on cost and time considerations.
[0140] The present application has been presented and described in detail above through the accompanying drawings and preferred embodiments. However, the present application is not limited to these disclosed embodiments. Based on the above multiple embodiments, those skilled in the art can know that the code review methods in the above different embodiments can be combined to obtain more embodiments of the present application, and these embodiments are also within the scope of protection of the present application.
Claims
1. An interface calling method (100), comprising: Obtaining description information of a state machine, wherein the state machine is used to define the calling logic of the interface to be called, and the description information is used to describe the structure of the state machine; Determining state jump information and state sequence information according to the description information, wherein the state jump information is used to indicate a jump path between at least two states included in the state machine, and the state sequence information is used to indicate an initial state and a target state of the state machine; generating a subtree template in a behavior tree format according to the state transition information and the state sequence information; Instantiating the subtree template to obtain an interface calling program of the interface to be called; The interface to be called is called through the interface calling program.
2. The method according to claim 1, wherein Generating a subtree template in the form of a behavior tree according to the state jump information and the state sequence information includes: Determining at least one alternative path using a preset path search algorithm according to the state jump information and the state sequence information, wherein the alternative path starts from the initial state and ends at the target state; According to each of the candidate paths, generating a corresponding candidate subtree template; At least one subtree template is selected from each of the candidate subtree templates according to the received template screening instruction.
3. The method according to claim 1, wherein The determining of the state jump information and the state sequence information according to the description information includes: Performing semantic analysis on the description document of the state machine using a pre-trained semantic analysis model to obtain the description information; or, The description information is obtained by analyzing the description image of the state machine through a pre-trained image processing model.
4. The method according to claim 1, wherein Generating a subtree template in the form of a behavior tree according to the state jump information and the state sequence information includes: Determining, according to the state jump information, a jump condition for the state machine to jump from the execution state to the completion state, wherein the jump condition includes at least one of a spontaneous jump and a triggered jump; If the jump condition includes the spontaneous jump, generating a first subtree template in the form of a behavior tree for the spontaneous jump according to the state jump information and the state sequence information; If the jump condition includes the triggered jump, a second subtree template in the form of a behavior tree for the triggered jump is generated according to the state jump information and the state sequence information.
5. The method according to claim 1, wherein The state jump information is used to indicate a jump path between at least two stable states included in the state machine, and the stable state is a state that the state machine can stably maintain.
6. The method according to claim 1, wherein Generating a subtree template in the form of a behavior tree according to the state jump information and the state sequence information includes: According to the received information modification instruction, at least one of the following modifications is performed on the state transition information: (i) adding a state jump path of the state machine to the state jump information; (ii) deleting at least one state jump path of the state machine in the state jump information; A subtree template in a behavior tree format is generated according to the state sequence information and the modified state transition information.
7. The method according to claim 1, wherein The instantiating of the subtree template to obtain the interface calling program of the interface to be called includes: According to the received template modification instruction, at least one of the following modifications is performed on the subtree template: (i) adding at least one behavior node to the subtree template; (ii) deleting at least one behavior node in the subtree template; The modified subtree template is instantiated to obtain an interface calling program of the interface to be called.
8. The method according to any one of claims 1 to 7, wherein The method further includes: filling template codes in each behavior node included in the subtree template, respectively, wherein the template codes are used to implement the processing logic of the corresponding behavior node.
9. The method according to claim 8, wherein The instantiating of the subtree template to obtain the interface calling program of the interface to be called includes: Obtaining instantiation data of each behavior node included in the subtree template; Each instantiation data is filled into the corresponding behavior node in the subtree template respectively to obtain the interface calling program of the interface to be called.
10. An interface calling device (800), comprising: An acquisition module (801) is used to acquire description information of a state machine, wherein the state machine is used to define the calling logic of the interface to be called, and the description information is used to describe the structure of the state machine; An extraction module (802) is configured to determine state jump information and state sequence information based on the description information, wherein the state jump information is used to indicate a jump path between at least two states included in the state machine, and the state sequence information is used to indicate an initial state and a target state of the state machine; A generation module (803) is used to generate a subtree template in the form of a behavior tree according to the state jump information and the state sequence information; An instantiation module (804) is used to instantiate the subtree template and obtain an interface calling program of the interface to be called; The calling module (805) is used to call the interface to be called through the interface calling program.
11. An electronic device (900), comprising: A processor (902), a communication interface (904), a memory (906), and a communication bus (908), wherein the processor (902), the communication interface (904), and the memory (906) communicate with each other via the communication bus (908); The memory (906) is used to store at least one executable instruction, and the executable instruction enables the processor (902) to execute an operation corresponding to the interface calling method (100) according to any one of claims 1 to 9.
12. A computer-readable storage medium having computer instructions stored thereon, wherein when the computer instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 9.
13. A computer program product tangibly stored on a computer-readable medium and comprising computer-executable instructions which, when executed, cause at least one processor to perform the method according to any one of claims 1 to 9.