State switching method and device, storage medium and electronic equipment
By layering and automatically allocating the target state in the state machine, the problem of difficulty in state machine design and debugging in complex systems is solved, and the efficiency of state switching results is improved.
Patent Information
- Application Number
- CN202510226452.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-05-30
AI Technical Summary
As the system complexity increases, the interaction relationships of each state are more complex, which increases the difficulty of designing and debugging of the state machine, which in turn affects the efficiency of obtaining state switching results.
By obtaining the behavioral state of the state machine object, the number of state machine layers is determined based on the number of behavioral states and the same state attributes, the target state is allocated according to the preset state number of sub-state machines and the same state attributes of different state machine layers, and the state switching sequence is obtained based on the target switching conditions between target states.
By controlling the number of state machine layers and the number of states of sub-state machines, and automatically allocating the target state with the same state attributes in the behavioral state, the difficulty of designing and debugging of the state machine is simplified and the efficiency of obtaining state switching results is improved.
Smart Images

Figure CN120066622A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of data processing, and particularly to a state switching method, apparatus, storage medium, and electronic device. Background Art
[0002] In practical applications, a state machine is a commonly used abstraction tool for managing and controlling different behaviors and state transitions of complex systems.
[0003] Currently, related technologies usually design a state machine based on the interaction relationships of each state to obtain a state switching result.
[0004] However, with the increase in system complexity, the interaction relationships of each state are relatively complex, increasing the difficulty of designing and debugging the state machine, and thus affecting the efficiency of obtaining the state switching result. Summary of the Invention
[0005] In view of this, this application provides a state switching method, apparatus, storage medium, and electronic device, mainly aiming to improve the technical problem that with the increase in system complexity in the current related technologies, the interaction relationships of each state are relatively complex, increasing the difficulty of designing and debugging the state machine, and thus affecting the efficiency of obtaining the state switching result.
[0006] In a first aspect, this application provides a state switching method, including:
[0007] Obtain the behavioral state of a state machine object;
[0008] Determine the number of layers of the state machine of the state machine object according to the number of the behavioral states and the same state attributes corresponding to the behavioral states;
[0009] Allocate the target states corresponding to the sub-state machines according to the preset number of states corresponding to the sub-state machines in different numbers of layers of the state machine and the same state attributes;
[0010] Obtain the state switching sequence of the state machine object during the application cycle based on the target switching conditions between the target states.
[0011] In a second aspect, this application provides a state switching apparatus, including:
[0012] An obtaining module, configured to obtain the behavioral state of a state machine object;
[0013] A determining module, configured to determine the number of layers of the state machine of the state machine object according to the number of the behavioral states and the same state attributes corresponding to the behavioral states;
[0014] An allocation module, configured to allocate a target state corresponding to the sub-state machine according to the preset number of states corresponding to the sub-state machines in different state machine layers and the same state attribute;
[0015] An acquisition module, configured to acquire a state transition sequence of the state machine object during an application cycle based on a target transition condition between the target states.
[0016] In a third aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the state transition method described in the first aspect is implemented.
[0017] In a fourth aspect, the present application provides an electronic device, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, and when the processor executes the computer program, the state transition method described in the first aspect is implemented.
[0018] In a fifth aspect, the present application provides a computer program product, on which a computer program is stored, and when the computer program is executed by a processor, the state transition method described in the first aspect is implemented.
[0019] By means of the above technical solutions, a state transition method, apparatus, storage medium, and electronic device provided by the present application first acquire the behavioral state of a state machine object; then determine the number of state machine layers of the state machine object according to the number of the behavioral states and the same state attribute corresponding to the behavioral states; then allocate a target state corresponding to the sub-state machine according to the preset number of states corresponding to the sub-state machines in different state machine layers and the same state attribute; and finally acquire a state transition sequence of the state machine object during an application cycle based on a target transition condition between the target states. Compared with the current existing technologies, the present application can count the same state attributes corresponding to each behavioral state involved in the state machine object, set the number of state machine layers according to the number of behavioral states and the same state attribute to perform hierarchical processing on the state machine, then allocate the behavioral states as target states of each sub-state machine according to the preset number of states that can be processed in the sub-state machines in each state machine layer, and finally acquire a state transition sequence generated according to the target transition condition during the application cycle of each target state. By controlling the number of state machine layers and the number of states of each sub-state machine, and combining the same state attribute in the behavioral states to automatically allocate target states for each sub-state machine, the design and debugging difficulty of the state machine is reduced, and thus the efficiency of acquiring the state transition result is improved.
[0020] The above description is only an overview of the technical solution of this application. In order to understand the technical means of this application more clearly, it can be implemented according to the content of the specification. And in order to make the above and other purposes, features and advantages of this application more obvious and understandable, the following specifically gives the specific implementation manners of this application. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The drawings herein are incorporated into and constitute a part of this specification, showing embodiments consistent with this application, and are used together with the specification to explain the principles of this application.
[0022] In order to more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, without creative efforts, other drawings can also be obtained based on these drawings.
[0023] Figure 1 It shows a schematic flowchart of a state switching method provided by an embodiment of this application;
[0024] Figure 2 It shows a schematic structural diagram of a state switching device provided by an embodiment of this application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0025] The following will describe the embodiments of this application in more detail with reference to the drawings. It should be noted that, without conflict, the embodiments in this application and the features in the embodiments can be combined with each other.
[0026] In order to improve the technical problem in the current related technologies that as the system complexity increases, the interaction relationships of various states are relatively complex, increasing the design and debugging difficulties of the state machine, and further affecting the efficiency of obtaining the state switching result. This embodiment provides a state switching method, as Figure 1 shown, the method includes:
[0027] Step 101, obtain the behavior state of the state machine object.
[0028] In some embodiments, the behavior state can be all the states that the state machine object may exhibit during operation, which can be used to reflect the logic or behavior characteristics of the system under different conditions. All behavior states can be accurately obtained by parsing configuration files, code, or other formal descriptions. Specifically, the state machine can dynamically create new states according to input data or external conditions. The state machine object can be described in the form of a state diagram, a state transition table, etc., and can be applied to research related projects such as modeling application behavior, hardware circuit system design, software engineering, compilers, network protocols, and computing and languages.
[0029] Step 102: Determine the number of layers of the state machine object based on the number of behavior states and the same state attributes corresponding to the behavior states.
[0030] In some embodiments, first, the number of behavior states can be counted, and it can be detected whether there are the same state attributes and whether there are similarities among the behavior states, so as to classify the behavior states according to the similarities. The behavior states with the same state attributes can be assigned to the same layer of the state machine. The number of layers of the state machine can include the nested layer number of the sub-state machine, etc. During the design process of the state machine, the number of layers of the state machine can be determined first to facilitate the automatic assignment of behavior states and control the complexity of the state machine. The same state attribute can be some features or attributes shared among multiple behavior states, such as the same switching condition, the same application scenario, the same execution subject, the same switching period, etc.
[0031] Step 103: Allocate the target states corresponding to the sub-state machines according to the preset number of states and the same state attributes corresponding to the sub-state machines in different layers of the state machine.
[0032] In some embodiments, the preset number of states corresponding to each sub-state machine in each layer of the state machine can be set according to the complexity of the state machine to simplify the state interaction relationship inside each sub-state machine. Each state only needs to consider interactivity within a limited range, which helps to reduce the cost of maintaining and expanding the state machine.
[0033] In some embodiments, the target state can be the behavior state inside each sub-state machine. The target states corresponding to each sub-state machine can be less than the preset number of states to reduce the state interaction relationship inside the sub-state machine. They can be allocated according to the same state attribute, that is, there are the same state attributes among the target states inside the sub-state machine and they will not be repeatedly allocated to different sub-state machines. In this way, there is no need for direct interaction between the target states of each sub-state machine, which simplifies the interaction relationship between the sub-state machines and reduces the design and debugging difficulty of the state machine, thereby affecting the efficiency of obtaining the state transition result.
[0034] Step 104: Based on the target switching conditions between the target states, obtain the state transition sequence of the state machine object within the application cycle.
[0035] In some embodiments, according to the specific execution logic of the state machine, the target switching conditions for each target state can be configured. After detecting that the target switching conditions are met, the sub-state machine can switch from the current state to the corresponding target state. In an actual application scenario, a series of input events are sent to the state machine, and based on the target switching conditions, the input and operation processes of the state machine object during the application cycle are simulated. The actual state transitions that occur are observed through the generated state transition sequence to dynamically analyze the state machine object. Herein, the application cycle can be the life cycle of the state machine object during the simulation process, which is convenient for analyzing the state transitions of the state machine object.
[0036] Compared with the current existing technologies, the present application can count the same state attributes corresponding to each behavioral state involved in the state machine object, set the state machine layers according to the number of behavioral states and the same state attributes, so as to perform hierarchical processing on the state machine. Then, according to the preset number of states that can be processed within the sub-state machines in each state machine layer, the behavioral states are assigned as the target states of each sub-state machine. Finally, within the application cycle of each target state, the state transition sequence generated according to the target switching conditions is obtained. By controlling the state machine layers and the number of states of each sub-state machine, and combining the same state attributes in the behavioral states to automatically assign target states to each sub-state machine, the state interaction relationship within each sub-state machine is simplified. Each state only needs to consider interactivity within a limited range, reducing the design and debugging difficulty of the state machine, and thus improving the efficiency of obtaining the state transition result.
[0037] Further optionally, step 102 may specifically include: performing hierarchical analysis on the state machine object according to the number of behavioral states and the same state attributes corresponding to the behavioral states to determine the nested state machine in the state machine object; determining the state machine layer of the state machine object according to the nesting level of the nested state machine.
[0038] In some embodiments, these same state attributes can be used to group the behavioral states and perform hierarchical analysis on the state machine object to identify the nested structure. For example: in a state machine corresponding to a device control system, the states related to "power management" (such as POWER_ON, POWER_OFF) may share the attribute of "power management". Correspondingly, a nested state machine may refer to a situation where within a state machine, some states contain another complete state machine inside, which can be used to represent the hierarchical logic in a complex system. For example: a smart home system may have a top-level state machine, which may contain sub-state machines corresponding to "security mode" and "energy-saving mode" respectively, and each sub-state machine can be configured with corresponding state sets and transition rules.
[0039] In this way, based on the number of behavioral states and the same state attributes, some of these states can be divided into different levels, providing multiple independent sub-state machines and simplifying the interaction relationships between the sub-state machines.
[0040] In a specific application scenario, the complexity of the state machine can be determined according to the number of behavioral states. Then, based on the complexity, the number of levels of nesting required for the state machine can be determined, and each nested state machine can be divided to simplify the complexity of the single-level state machine. The number of levels of nesting of the nested state machine can be used to represent the depth of the nested state machine, and the number of levels of nesting can be used as the number of levels of the state machine for subsequent detailed state deployment and allocation. For example:
[0041] If the number of levels of the state machine is set to 1, it can be set that there is no nesting in the state machine; if the number of levels of the state machine is set to 2, it can be set that there is one level of nesting in the state machine, that is, there is one sub-state machine in the top-level state machine; if the number of levels of the state machine is set to 3, it can be set that there are two levels of nesting in the state machine, that is, there is one sub-state machine in the top-level state machine, and there is also one sub-state machine in the sub-state machine.
[0042] Through this design of state layering, a large number of states are divided into different sub-state machines according to certain settings. The states in the sub-state machine only need to consider the interactions within the sub-state machine where they are located, and the sub-state machine can also nest sub-states, ensuring that each state machine only contains a limited number of states, and each state only needs to consider the interaction logic within its own state machine. The states in different sub-state machines do not need to consider the interaction logic, reducing the costs of maintenance and expansion.
[0043] Optionally, determining the nested state machine in the state machine object may specifically include: obtaining the number of sub-state machines corresponding to the state machine object; if the number of sub-state machines exceeds the preset number of sub-state machines corresponding to the state machine object, performing nesting processing on the sub-state machines to obtain the nested state machine corresponding to the sub-state machines.
[0044] Specifically, according to the hierarchical analysis result of the state machine object, the number of sub-state machines can be obtained, and the preset number of sub-state machines of the state machine object can be set. If the number of sub-state machines exceeds the preset number of sub-state machines, nesting processing is performed on the sub-state machines, multiple sub-state machines are merged, and multiple sub-state machines are combined into one state machine, increasing the number of levels of nesting, and simplifying the interaction relationships between the sub-state machines through multi-level processing.
[0045] Exemplarily, the entire state machine (such as a finite state machine) is divided into three parts: the top-level state machine (main state machine) that controls the entire process externally, the sub-state machines under the main state machine, and the states under the sub-state machines. Among them, the main state machine can have sub-state machines and states simultaneously at the same level. The sub-state machines can also be nested. All state machines, like states, have mechanisms for entry and exit. The specific execution process may include the following steps:
[0046] 1. Enter the main state machine and switch to the default state / sub-state machine.
[0047] 2. The main state machine detects whether the transition state condition is established. If it is established, switch to the corresponding state / sub-state machine, exit the current state / sub-state machine, and enter the target state / sub-state machine.
[0048] 3. When the current state of the main state machine is a sub-state machine, after detecting the transition state condition of the main state machine, detect the transition state condition of the sub-state machine.
[0049] 4. If the sub-state machine transition condition is established, switch to the state under the corresponding sub-state machine, exit the current state / sub-state machine, and enter the target state / sub-state machine.
[0050] Optionally, step 103 may specifically include: obtaining the preset state quantity corresponding to the sub-state machine in different state machine layers, and the sub-states corresponding to the sub-state machine; determining the target state corresponding to the sub-state machine according to the same state attributes and preset state quantity of the sub-states.
[0051] As a possible implementation manner, according to the hierarchical analysis result of the state machine object, the quantity of sub-state machines in each layer can be obtained, and the quantity of sub-state machines corresponding to each state machine layer can be set. If the quantity of sub-state machines in the current layer exceeds the quantity of sub-state machines set in the current layer, then multiple sub-state machines among them can be merged to increase the nesting layer number to simplify the sub-state machines in the current layer.
[0052] In some embodiments, corresponding preset state quantities can be set for each sub-state machine in each state machine layer to control the quantity of states that each sub-state machine can convert, which can be set and modified according to project requirements. And sub-states are allocated to the sub-state machine according to the preset state quantity. Then, under the condition of meeting the preset state quantity, for example, when it is less than or equal to the preset state quantity, it is detected whether there are the same state attributes among the sub-states, and it is detected whether the sub-states with the same state attributes correspond to the same sub-state machine. If it is determined that they correspond to the same sub-state machine, then these sub-states can be determined as the target state of this sub-state machine; if the sub-states with the same state attributes do not correspond to the same sub-state machine, then these sub-states can be adjusted to be controlled by the same sub-state machine, or the sub-state machines corresponding to these sub-states can be merged into one state machine.
[0053] Correspondingly, if the number of sub-states of a certain sub-state machine does not meet the preset number of states, for example, exceeds the preset number of states, a sub-state machine can be nested in this sub-state machine to further determine sub-states with more identical state attributes, and the sub-states with more identical state attributes are assigned to the sub-state machine nested in this sub-state machine to simplify the processing complexity of each layer of the state machine.
[0054] In this way, a part of the states can be grouped into a sub-state machine according to certain identical conditions, and then multiple sub-state machines are combined into a total state machine. Different sub-state machines contain different states, and the same state cannot exist in different sub-state machines. Thus, the complex state machine is simplified through layering, and the maintainability and scalability are greatly improved.
[0055] Optionally, step 104 may specifically include: when it is detected that the sub-state machine meets the target switching condition, switching the sub-state machine to the target state; generating a state switching sequence according to the target switching time of the target state within the application cycle.
[0056] Exemplarily, the state switching sequence may refer to the state changes that occur in a certain order during the operation of the state machine object, and may include, but are not limited to, information such as the time point of state switching, source state, target state, trigger condition, etc. For example: in a network protocol stack, a possible state switching sequence is: CLOSED->LISTEN->SYN_RECEIVED->ESTABLISHED. In a specific application scenario, the StateManager class can be used to manage the state machine and the life cycle of the state.
[0057] As a possible implementation manner, after determining the target state corresponding to the sub-state machine, the target switching condition of the target state can be configured according to the behavior logic of the sub-state. The target switching condition may include the specific conditions or events that trigger the state switching. These conditions can be external inputs (such as user operations, sensor data) or internal logics (such as timer timeout, specific calculation results, for example: transition state conditions).
[0058] In a specific application scenario, the application cycle corresponding to the state machine can be set according to the project requirements. After the state machine starts running, after each sub-state machine detects that it meets the target switching condition, it can automatically switch to the target condition corresponding to the target switching condition. The state machine can generate a state switching sequence according to the target switching time of each target state, indicating the state switching record that occurs in a certain order of the state machine.
[0059] Optionally, the method of this embodiment may further include: comparing the state transition sequence with a preset transition sequence to determine the abnormal sequence in the state transition sequence; updating the sub-state machine corresponding to the abnormal sequence, and regenerating the state transition sequence.
[0060] Among them, the preset transition sequence may refer to the state transition sequence defined according to the design specification or expected behavior, and can be used to represent the path that should be followed during the normal operation of the system. For example: the standard transition sequence for TCP connection establishment is: CLOSED->LISTEN->SYN_SENT->SYN_RECEIVED->ESTABLISHED.
[0061] As a possible implementation, according to the actual application scenario of the state machine object, the preset transition sequence of the behavioral states in the state machine object under normal conditions can be obtained. By comparing the generated state transition sequence with the preset transition sequence, the abnormal sequence in the state transition sequence can be detected. The abnormal sequence may refer to the part in the state transition sequence generated during the actual detection process that is inconsistent with the preset transition sequence. These abnormalities may indicate that the system behavior deviates from the expectation and need further analysis and correction, and may include abnormal states, abnormal transition times, etc. Correspondingly, the sub-state machine that causes the abnormal sequence can be updated, such as modifying the state transition rule, adding new states, deleting redundant states, etc. Using the updated sub-state machine to run the state machine object again, the updated state transition sequence can be obtained, and it can be verified whether it conforms to the preset transition sequence to ensure that its behavior meets the expectation.
[0062] In some embodiments, by monitoring or recording the running process of the state machine object, the actually occurring state transition sequence can be obtained. Through log recording, the current state and trigger event can be recorded during the state transition, or a dynamic analysis tool can capture the state transition process, and then the actually obtained state transition sequence is compared item by item with the preset transition sequence to identify the abnormal sequence. The states in the two sequences can be compared one by one in order to find the mismatched positions and mark the abnormal sequence, and record the part in the actual sequence that does not match the preset sequence;
[0063] Then, according to the context where the abnormal sequence occurs, locate the sub-state machine that causes the abnormality, such as checking which sub-state machine the abnormal state belongs to, or performing nested structure analysis, recursively analyzing the nested structure of the state machine to find the level where the problem lies, and finally update the relevant sub-state machine, repair its state transition rule or logic, and then use the same input event sequence to re-execute the state machine and capture the new state transition sequence process.
[0064] In some embodiments, such as Figure 2As shown in the figure, introducing a hierarchical state machine can simplify the design of the state machine. According to the same scenarios involved in the states, the states are divided. For example, the things to do in one place can be grouped into a living scenario, and the living scenario can also be regarded as a behavioral state. And this behavioral state includes more specific living states. For example, the scenarios corresponding to behaviors such as eating, reading, watching TV, and sleeping are all at home, the scenarios corresponding to behaviors such as shopping in the supermarket, buying things, and paying are all in the supermarket, and the scenarios corresponding to behaviors such as clocking in, working, and getting off work are all in the company. Then, the 10 states involved in life are divided into 3 major categories: home, supermarket, and company. Each category is configured as a corresponding sub-state machine. The main state machine drives the sub-state machine, and the sub-state machine drives the states. Then, it is controlled when the character enters these 3 major categories. When adding a new state, only the category to which it is added and the transition relationship with other states in that category need to be concerned, without worrying about the switching of other categories.
[0065] In this way, using the hierarchical design of states simplifies the complex and numerous state relationships. Each state only needs to consider interactivity within a limited range, solves the coupling between the states of the state machine in a complex system, realizes the decoupling between states, and maintains the scalability and maintainability of the state machine.
[0066] Compared with the current existing technologies, in this embodiment, a part of the states can determine nested state machines according to certain same state attributes, and determine the number of layers of the state machine according to the number of nested layers. Thus, some states with the same conditions are grouped into a sub-state machine. Then, multiple sub-state machines are combined into a total state machine. Different sub-state machines contain different states, and the same state cannot exist in different sub-state machines. The complex state machine is simplified through layering, and the maintainability and scalability are greatly improved.
[0067] Further, as Figure 1 a specific implementation of the method shown, this embodiment provides a state switching device, as Figure 2 shown. The device includes: an acquisition module 31, a determination module 32, and an allocation module 33.
[0068] The acquisition module 31 is configured to acquire the behavioral state of the state machine object;
[0069] The determination module 32 is configured to determine the number of layers of the state machine of the state machine object according to the number of behavioral states and the same state attributes corresponding to the behavioral states;
[0070] The allocation module 33 is configured to allocate the target states corresponding to the sub-state machines according to the preset number of states and the same state attributes corresponding to the sub-state machines in different numbers of layers of the state machine;
[0071] An acquisition module 31, configured to acquire a state transition sequence of a state machine object within an application cycle based on a target transition condition between target states.
[0072] In some examples of this embodiment, a determination module 32 is specifically configured to perform a hierarchical analysis on the state machine object according to the number of behavior states and the same state attributes corresponding to the behavior states, to determine a nested state machine in the state machine object; and determine the number of state machine layers of the state machine object according to the number of nested layers of the nested state machine.
[0073] In some examples of this embodiment, a determination module 32 is specifically configured to acquire the number of sub-state machines corresponding to the state machine object; if the number of sub-state machines exceeds a preset number of sub-state machines corresponding to the state machine object, perform a nesting process on the sub-state machines to obtain a nested state machine corresponding to the sub-state machines.
[0074] In some examples of this embodiment, a storage module 33 is specifically configured to acquire a preset number of states corresponding to the sub-state machines in different numbers of state machine layers, and the sub-states corresponding to the sub-state machines; and determine the target states corresponding to the sub-state machines according to the same state attributes corresponding to the sub-states and the preset number of states.
[0075] In some examples of this embodiment, a storage module 33 is specifically configured to acquire a preset number of states corresponding to the sub-state machines in different numbers of state machine layers, and the sub-states corresponding to the sub-state machines; and determine the target states corresponding to the sub-state machines according to the same state attributes corresponding to the sub-states and the preset number of states.
[0076] In some examples of this embodiment, a determination module 32 is further specifically configured to compare the state transition sequence with a preset transition sequence to determine an abnormal sequence in the state transition sequence; update the sub-state machine corresponding to the abnormal sequence, and regenerate the state transition sequence.
[0077] It should be noted that for other corresponding descriptions of each functional unit involved in the state transition device provided in this embodiment, reference can be made to Figure 1 the corresponding description therein, which will not be elaborated here.
[0078] Based on the method as shown in Figure 1 above, correspondingly, this embodiment further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method as shown in Figure 1 above is implemented.
[0079] Based on the method as shown in Figure 1 above, correspondingly, this embodiment further provides a computer program product, on which a computer program is stored, and when the computer program is executed by a processor, the method as shown in Figure 1 above is implemented.
[0080] Based on such understanding, the technical solution of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (such as a CD-ROM, USB flash drive, mobile hard disk, etc.), and includes several instructions for causing a computer device (such as a personal computer, server, or network device, etc.) to execute the method of the implementation scenario of this application.
[0081] Based on the above as Figure 1 shown in the method, and Figure 2 shown in the virtual device embodiment, in order to achieve the above object, the embodiment of this application also provides an electronic device, which includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to implement the above as Figure 1 shown in the method.
[0082] Optionally, the above-mentioned physical device may further include a user interface, a network interface, a camera, a radio frequency (RF) circuit, sensors, an audio circuit, a WI-FI module, and so on. The user interface may include a display screen (Display), an input unit such as a keyboard (Keyboard), etc., and the optional user interface may further include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), etc.
[0083] Those skilled in the art can understand that the above-mentioned physical device structure provided in this embodiment does not constitute a limitation on the physical device, and may include more or fewer components, or combine some components, or have different component arrangements.
[0084] The storage medium may further include an operating system and a network communication module. The operating system is a program for managing the hardware and software resources of the above-mentioned physical device, and supports the operation of information processing programs and other software and / or programs. The network communication module is used to implement communication between the components inside the storage medium, and communication between other hardware and software in the information processing physical device.
[0085] Through the description of the above embodiments, those skilled in the art can clearly understand that this application can be implemented by means of software plus a necessary general hardware platform, or can also be implemented by hardware. By applying the technical solution of this embodiment, this embodiment can determine a nested state machine according to some identical state attributes for a part of states, and determine the number of layers of the state machine according to the number of nested layers, so as to group some states with the same conditions into a sub-state machine, and then combine multiple sub-state machines into a total state machine. Different sub-state machines contain different states, and the same state cannot exist in different sub-state machines. The complex state machine is simplified by layering, and the maintainability and expandability are greatly improved.
[0086] It should be noted that in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the term "comprising", "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements not only includes those elements, but also includes other elements not expressly listed, or further includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising one..." does not exclude the existence of additional identical elements in the process, method, article or device comprising the element.
[0087] The above are only specific embodiments of this application, enabling those skilled in the art to understand or implement this application. Various modifications to these embodiments will be obvious to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of this application. Therefore, this application will not be limited to these embodiments described herein, but rather to the broadest scope consistent with the principles and novel features claimed herein.
Claims
1. A state switching method, characterized in that: include: Get the behavior status of the state machine object; Determining the number of state machine layers of the state machine object according to the number of the behavior states and the same state attributes corresponding to the behavior states; According to the number of preset states corresponding to the sub-state machines in different state machine layers and the same state attributes, the target state corresponding to the sub-state machine is allocated; Based on the target switching conditions between the target states, a state switching sequence of the state machine object within an application cycle is obtained.
2. The method according to claim 1, characterized in that The determining the number of state machine layers of the state machine object according to the number of the behavior states and the same state attributes corresponding to the behavior states includes: According to the number of the behavior states and the same state attributes corresponding to the behavior states, the state machine object is subjected to hierarchical analysis to determine the nested state machines in the state machine object; The number of state machine levels of the state machine object is determined according to the number of nesting levels of the nested state machine.
3. The method according to claim 2, characterized in that The determining of the nested state machine in the state machine object comprises: Get the number of sub-state machines corresponding to the state machine object; If the number of the sub-state machines exceeds the preset number of sub-state machines corresponding to the state machine object, the sub-state machines are nested to obtain the nested state machines corresponding to the sub-state machines.
4. The method according to claim 1, characterized in that: The allocating target states corresponding to the sub-state machines according to the preset state quantities corresponding to the sub-state machines in different state machine layers and the same state attributes includes: Get the preset state number corresponding to the sub-state machine in different state machine layers, and the sub-state corresponding to the sub-state machine; According to the same state attributes corresponding to the sub-states and the preset state quantity, a target state corresponding to the sub-state machine is determined.
5. The method according to claim 1, characterized in that The acquiring the state switching sequence of the state machine object within the application cycle based on the target switching condition between the target states includes: When detecting that the sub-state machine meets the target switching condition, switching the sub-state machine to the target state; The state switching sequence is generated according to the target switching time of the target state within the application cycle.
6. The method according to claim 1, characterized in that The method further comprises: Comparing the state switching sequence with a preset switching sequence to determine an abnormal sequence in the state switching sequence; The sub-state machine corresponding to the abnormal sequence is updated to regenerate the state switching sequence.
7. A state switching device, characterized in that: include: An acquisition module, configured to acquire the behavior state of the state machine object; A determination module, configured to determine the number of state machine layers of the state machine object according to the number of the behavior states and the same state attributes corresponding to the behavior states; An allocation module is configured to allocate a target state corresponding to the sub-state machine according to the number of preset states corresponding to the sub-state machines in different state machine layers and the same state attribute; The acquisition module is configured to acquire the state switching sequence of the state machine object within the application cycle based on the target switching condition between the target states.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
9. An electronic device comprising a storage medium, a processor, and a computer program stored in the storage medium and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 6 is implemented.
10. A computer program product having a computer program stored thereon, characterized in that: When the computer program product is executed by a processor, the method according to any one of claims 1 to 6 is implemented.