Finite state machine control method, device, computer equipment and storage medium

By receiving and processing events of control signals, using the state machine classes and state classes in the event processing class to realize flexible state jump and rollback of finite state machines, solving the problems of inflexible and inefficient state switching in the prior art. Improved control efficiency.

CN115885253BActive Publication Date: 2024-12-17SHENZHEN DEEPROUTE AI CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202080103184.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-12-28
Publication Date
2024-12-17
Estimated Expiration
2040-12-28

AI Technical Summary

Technical Problem

The switching relationship between states of the existing finite state machine control mode requires early registration and does not support dynamic state addition or state rollback, resulting in low control efficiency.

Method used

By receiving control signals, converting them into events, and calling event processing classes for processing. The event processing class includes state machine classes and state classes. The state machine class is used to implement state jump logic, and the state class is used to complete specific business logic processing. The current state determines the event processing and returns to the processing state, thereby determining the processing method of the next state.

Benefits of technology

The flexibility and dynamic nature of the state machine is realized, the addition of new states and state rollback is supported, the control efficiency is improved, and the inefficiency problem caused by inflexible state machine design in traditional methods is avoided.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115885253B_ABST
    Figure CN115885253B_ABST
Patent Text Reader

Abstract

A control method for a finite state machine includes: receiving a control signal; carrying signaling information in the control signal; converting the control signal into an event according to the signaling information; calling an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; when processing an event, if the state machine class determines to accept the processing event according to the current state, then the event is processed with corresponding business logic and the corresponding processing state is returned; according to the processing state, the processing method corresponding to the next state is determined.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a control method, device, computer equipment and storage medium for a finite state machine. Background Art

[0002] With the development of computer technology, finite state machines (FSM) can effectively and conveniently describe the dynamic behavior of systems and components, and are widely used in telecommunication software application development. FSM has a finite number of states, generally including states and transition relationships between states. At present, in software programming engineering, the commonly used way to implement FSM is to use procedural languages, such as C language. The FSM implemented in this way is essentially described by conditional statements.

[0003] However, in the current finite state machine control method, the switching relationship between states usually needs to be registered in advance, and the state machine is not universal and cannot flexibly add states dynamically. At the same time, during runtime, it does not support state rollback based on the current state, that is, it is impossible to dynamically control the jump between different states, which easily leads to low control efficiency. Summary of the invention

[0004] According to various embodiments disclosed in the present application, a control method, an apparatus, a computer device, and a storage medium for a finite state machine are provided.

[0005] A control method for a finite state machine, comprising:

[0006] Receive a control signal; the control signal carries signaling information; according to the signaling information, convert the control signal into an event; call an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class determines to accept and process the event based on the current state, then perform corresponding business logic processing on the event and return the corresponding processing state; and determine the processing method corresponding to the next state based on the processing state.

[0007] A control device for a finite state machine, comprising:

[0008] A receiving module for receiving a control signal; the control signal carries signaling information; a conversion module for converting the control signal into an event according to the signaling information; a calling module for calling an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; a processing module for, when processing the event, if the state machine class determines to accept the processing of the event according to the current state, then performing corresponding business logic processing on the event and returning the corresponding processing state; and a determination module for determining the processing method corresponding to the next state according to the processing state.

[0009] A computer device includes a memory and one or more processors, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the processors, the one or more processors perform the following steps: obtaining product information;

[0010] Receive a control signal; the control signal carries signaling information; according to the signaling information, convert the control signal into an event; call an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class determines to accept and process the event based on the current state, then perform corresponding business logic processing on the event and return the corresponding processing state; and determine the processing method corresponding to the next state based on the processing state.

[0011] One or more computer storage media storing computer readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the following steps: obtaining product information;

[0012] Receive a control signal; the control signal carries signaling information; according to the signaling information, convert the control signal into an event; call an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; when processing the event, if the state machine class determines to accept and process the event based on the current state, then perform corresponding business logic processing on the event and return the corresponding processing state; and determine the processing method corresponding to the next state based on the processing state.

[0013] The details of one or more embodiments of the present application are set forth in the following drawings and description. Other features and advantages of the present application will become apparent from the description, drawings, and claims. BRIEF DESCRIPTION OF THE DRAWINGS

[0014] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0015] Figure 1 An application environment diagram of a control method of a finite state machine in an embodiment;

[0016] Figure 2 A schematic flow chart of a control method of a finite state machine in one embodiment;

[0017] Figure 3 A schematic diagram of a flow chart of determining a processing method corresponding to a next state according to a processing state in an embodiment;

[0018] Figure 4 A schematic diagram of a process flow of obtaining a processing strategy step corresponding to a current state in an embodiment;

[0019] Figure 5 It is a flowchart of the steps of processing the event when the processing strategy returned by the GetStrategy function is to replace the event according to the event, and to create a new state to replace the current state;

[0020] Fig. 6A is a flow chart of a control method of a finite state machine in another embodiment;

[0021] Figure 6B A schematic diagram of a calling relationship when a finite state machine processes an event in one embodiment;

[0022] Figure 7 is a structural block diagram of a control device of a finite state machine in one embodiment;

[0023] Figure 8 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0024] In order to make the technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0025] The control method of the finite state machine provided in the embodiment of the present application can be applied to Figure 1In the application environment shown, terminal 102 communicates with terminal 104 through a network. Terminal 102 receives a control signal sent by terminal 104, and the control signal carries signaling information. Terminal 102 converts the control signal into an event based on the signaling information. Terminal 102 calls an event processing class to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic. When terminal 102 processes an event, if the state machine class determines to accept the processing event based on the current state, the event is processed by the corresponding business logic and the corresponding processing state is returned. Terminal 102 determines the processing method corresponding to the next state based on the processing state. Terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices.

[0026] The following implementation method is applied to the control method of the finite state machine Figure 1 The method is described using a terminal as an example, but it should be noted that in actual applications, the method is not limited to being applied to the above-mentioned terminal.

[0027] like Figure 2 As shown, a flow chart of a control method of a finite state machine in one embodiment, the method specifically comprises the following steps:

[0028] Step 202: Receive a control signal, where the control signal carries signaling information.

[0029] Finite state machine is a tool used to model object behavior. Its main function is to describe the sequence of states that an object goes through during its life cycle and how it responds to various events from the outside world. In computer science, finite state machines are widely used to model application behavior, hardware circuit system design, software engineering, compilers, network protocols, and research on computing and language. The state machine consists of state registers and combinational logic circuits. It can transfer states according to pre-set states based on control signals. It is the control center that coordinates related signal actions and completes specific operations.

[0030] Finite state machine is abbreviated as FSM (Finite State Machine). Finite state machine is a mathematical model that represents a finite number of states and the transitions and actions between these states. Common computers use finite state machines as computing models. For different states of memory, the central processing unit (CPU) reads the memory value to perform calculations and update the state in the memory. The CPU also receives instructions from external input devices (such as keyboards and mice) through the message bus, changes the state in the memory after calculation, outputs the calculation results to external display devices (such as monitors), and stores them persistently on the hard disk. Finite state machine models are also often used in game design. Take the Fruit Ninja game as an example. The state of the fruit in the game is a finite state, and its running trajectory is calculated by a calculation formula that simulates the laws of physical motion. A banana will run along a parabola after being thrown up, and its position change in each frame is a state change, which is determined by a calculation formula. The game also involves complex human-computer interaction events, such as "cutting" the fruit on the screen with your hand. After the fruit perceives this event, it will enter the explosion state according to the program logic.

[0031] Specifically, the terminal can receive a control signal, which carries signaling information. A control signal is a signal used for control, which is used as a medium to control the computer. The control signal can be sent to the terminal by different devices, which may include third-party devices, terminal devices, servers, and IoT devices. Signaling information refers to the specific content of the signal, that is, the control information carried by the control signal. In a wireless communication system, signaling is a control signal required to ensure normal communication in addition to transmitting user information in order to make the entire network work in an orderly manner. That is, signaling is actually a signal used for control.

[0032] Step 204: Convert the control signal into an event according to the signaling information.

[0033] After receiving the control signal sent by different devices, the terminal can convert the control signal into an event according to the signaling information carried in the control signal. An event refers to the response of an object to an external action. When an event occurs in an object, the code corresponding to the event of the object will be executed. This code is called the "event process". The terminal can convert the received signal into an event according to the specific content of the signaling, that is, the terminal abstracts the received signal into an event. An event can contain an event type, an event identifier (i.e., an event id), and an event content (msg). Specifically, the terminal can convert the signal into an internally defined event type, event identifier, and event content according to the specific content of the signaling, and save these values ​​in the event Event structure. The event type and event identifier can be saved as integer variable types, and the event content is the memory address of the signaling saved by the void pointer, so that different signals can be converted into events that can be processed uniformly. The void pointer refers to a special pointer, expressed as a "typeless pointer", which is used in ANSI C to replace "char*" as the type of a general pointer. Since the void pointer has no specific type, it can point to any type of data. That is to say, any type of pointer can be directly assigned to a void pointer without any other related forced type conversion.

[0034] Step 206, call the event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic.

[0035] After the terminal converts the control signal into an event according to the signaling information, the terminal can call the event processing class to process the abstract event. Class is the basis for object-oriented programming (OOP) to implement information encapsulation. Class is a user-defined reference data type, also known as class type. Each class contains a data description and a set of functions for operating data or transmitting messages. An instance of a class is called an object. An event processing class refers to a set of reusable business functions, including some objects and their behaviors, which are called to achieve the purpose of reusing functions. The event processing class can include a state machine class and a state class. The state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic. Specifically, after the terminal converts the signal into an event according to the signaling information, the terminal can call the event processing class to process the converted event. That is, the event processing class in the terminal can inherit from a class (Handler class), and the Handler class contains the HandEvent function. The state machine class is the StateMachine class, and the state class is the State class. Both the StateMachine class and the State class are essentially classes that process events. Therefore, by abstracting an event processing Handler class and providing an abstract interface HandEvent event processing function, the HandEvent function can be implemented in the subclass. Specifically, the HandEvent function in the subclass StateMachine implements the logic of state jump, and the HandEvent function in the subclass State completes the processing of specific business logic. Each state State contains the Enter function, which is used to enter the state, the HandEvent function, which is used to process events that the current state can accept, the Exit function, which is used to exit the state, and the GetStrategy function, which is used to obtain the current state's processing strategy for unacceptable events.

[0036] Step 208, when processing an event, if the state machine class determines to accept the event for processing according to the current state, the event is processed according to the corresponding business logic and the corresponding processing state is returned.

[0037] When the terminal calls the event processing class to process the event, if the state machine class determines to accept the event according to the current state, the event is processed by the corresponding business logic and the corresponding processing status is returned. Specifically, when the terminal calls the Handler class to process the event, if the StateMachine class determines to accept the event according to the current state, the event is processed by the HandEvent function in the subclass State, and the corresponding processing status is returned. That is, the terminal calls the HandEvent function of the current state, processes the event by the corresponding business logic, and returns the corresponding processing status. The processing status is the corresponding status code returned by each state after processing the event, and the status code is the return value of the HandEvent function. That is, the status code refers to the return value of the state processing function, and the StateMachine class can decide the next action based on this return value.

[0038] Step 210, determining a processing method corresponding to the next state according to the processing state.

[0039] After the terminal calls the event processing class to process the event and returns the corresponding processing status, the terminal can continue to call the event processing class and determine the corresponding processing method for the next state based on the returned processing status. For example, the terminal performs corresponding business logic processing on the current event through the HandEvent function in the State subclass. The HandEvent function can return three processing states: DONE_EVENT, CONTINUE_EVENT, and UNKOWN_EVENT based on the processing of the current event. DONE_EVENT means that the current state has completed processing the event and can jump to the next state; CONTINUE_EVENT means that the current state continues to process the event without jumping to another state; UNKOWN_EVENT means that the current state cannot accept the event, and the StateMachine class needs to obtain the strategy of the current state based on the GetStrategy function of the current state, and execute the next steps based on the obtained strategy.

[0040] In the traditional finite state machine control method, when the state jumps, it is necessary to specify the next state to jump in the state machine, so it is inconvenient to add a new state. Each time a state is added, the corresponding code of the state machine needs to be modified. In this embodiment, by receiving a control signal, the control signal carries signaling information, and according to the signaling information, the control signal is converted into an event, and the event processing class is called to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic. When processing an event, if the state machine class determines to accept the processing event according to the current state, the event is processed by the corresponding business logic, the corresponding processing state is returned, and the processing method corresponding to the next state is determined according to the processing state. As a result, by abstracting various different signals into a unified parameter Event to process events and jump between states, the state machine part can be made more general, which is convenient for adding new states without modifying the code of the state machine part, and can flexibly create states and perform state jumps according to the event processing strategy, thereby effectively improving the control efficiency.

[0041] In one embodiment, if Figure 3 As shown, the processing status includes processing completed, continuing processing and not accepting processing. According to the processing status, the steps of determining the processing method corresponding to the next status include:

[0042] Step 302: When the returned processing status is that the processing is completed, jump to the next state to process the event.

[0043] Step 304: When the returned processing status is to continue processing, no state jump is performed, and the HandEvent function of the current state is called to continue processing the event.

[0044] Step 306: When the returned processing status is not accepting processing, the processing strategy corresponding to the current status is obtained.

[0045] After the terminal calls the event processing class to process the event and returns the corresponding processing status, the terminal can continue to call the event processing class to determine the processing method corresponding to the next state according to the processing status returned by the previous step. The processing status includes processing completed, continuing processing, and not accepting processing. Specifically, when the HandEvent function returns the processing status of processing completed based on the processing of the current event, the StateMachine class can jump to the next state to process the event. When the returned processing status is continuing processing, the state jump is not performed, and the StateMachine class calls the HandEvent function of the current state to continue processing the event. When the returned processing status is not accepting processing, the StateMachine class obtains the processing strategy corresponding to the current state. That is, only when the state of UNKOWN_EVENT (not accepting processing) is returned, the StateMachine class will call the GetStrategy function of the current state to obtain the corresponding processing strategy.

[0046] Specifically, when the current event is processed by the HandEvent function, the terminal determines whether the event Event is an event to be processed in the current state according to the event type and event identifier of the event Event by calling the HandEvent function of the State class. If so, the HandEvent function is used to process the current event with specific business logic; if not, it indicates that the current state cannot process the event and returns the processing state of UNKOWN_EVENT. Each state returns the corresponding status code after processing the event. When the processing state of CONTINUE_EVENT is returned, it indicates that the current state can continuously process the event, and there is no need to jump to the state. This can reduce unnecessary state jumps, and there is no need to jump from the current state to the current state. The jumps between different states can be dynamically controlled, thereby effectively improving control efficiency.

[0047] In one embodiment, if Figure 4 As shown, the steps of obtaining the processing strategy corresponding to the current state include:

[0048] Step 402, calling the GetStrategy function to obtain the processing strategy corresponding to the current state, the processing strategy includes ignoring events, replacing events and rolling back events.

[0049] Step 404: When the processing strategy returned by the GetStrategy function is to ignore the event, the event is ignored.

[0050] Step 406, when the processing strategy returned by the GetStrategy function is to replace the event, a new state is created according to the event to replace the current state, and the event is processed.

[0051] Step 408: When the processing strategy returned by the GetStrategy function is a rollback event, the event is processed by restoring to the previous state.

[0052] The terminal calls the event processing class to process the event. When the returned processing status is not accepted, the StateMachine class can obtain the processing strategy corresponding to the current state. Specifically, the StateMachine class can obtain the processing strategy corresponding to the current state by calling the GetStrategy function. The processing strategies include ignoring events (IGNORE), replacing events (REPLACE), and rolling back events (RECOVER). That is, the GetStrategy function can return three strategies, IGNORE, REPLACE, and RECOVER, for the current event. IGNORE means ignoring the current event, REPLACE means creating a new state based on the current event to replace the current state to process the event, and RECOVER means restoring the previous state to process the current event. That is, when the processing strategy returned by the GetStrategy function is to ignore the event, the event is ignored. When the processing strategy returned by the GetStrategy function is to replace the event, a new state is created based on the event to replace the current state and process the event. When the processing strategy returned by the GetStrategy function is to roll back the event, the event is restored to the previous state to process the event. Compared with the traditional finite state machine control method, since there is no saving of the previous state and no dynamic event processing strategy, it is impossible to implement state rollback, and it is also impossible to solve the problem of when the state can be rolled back. In this embodiment, the state jump strategy is implemented in a specific state, so that it can be determined at runtime how to jump to the next state or roll back to the previous state according to the current state. Because the state machine StateMachine saves the previous state, if the current state's event processing strategy is RECOVER, the StateMachine can be rolled back to the previous state, which can realize flexible creation of states and state jumps according to event processing strategies.

[0053] In one embodiment, if Figure 5 As shown, when the processing strategy returned by the GetStrategy function is to replace the event, a new state is created according to the event to replace the current state. The steps for processing the event include:

[0054] Step 502: When the processing strategy returned by the GetStrategy function is to replace the event, the state factory class is called to create a corresponding new state using the CreateState function according to the event type and event identifier of the event.

[0055] Step 504, replace the current state with the new state, and use the new state to process the event.

[0056] The terminal calls the event processing class to process the event. When the returned processing status is not accepted, the StateMachine class can obtain the processing strategy corresponding to the current state by calling the GetStrategy function. When the processing strategy returned by the GetStrategy function is to replace the event, a new state is created according to the event to replace the current state and process the event. The StateMachine class, i.e., the state machine class, contains a state factory class (i.e., StateFactory class object) and two states. The two states are the current state (cur_state) and the previous state (last_state). StateFactory is a class that creates a specific State class object and is responsible for the creation of specific states, i.e., the StateFactory class is mainly used to create corresponding states according to events. last_state represents the previous state of StateMachine and is used for state rollback. cur_state represents the current state of StateMachine. The function of cur_state is that when StateMachine receives the event Event, StateMacNne first tries to call the HandEvent function of cur_state to process the event Event, and determines the next process according to the processing result of cur_state. For example, the next process can include creating a new state to handle the event, ignoring the current event, and rolling back the state.

[0057] Specifically, when the processing strategy returned by the GetStrategy function is to replace the event, the StateMachine class can call StateFactory, and StateFactory uses the CreateState function to create the corresponding new state according to the event type and event identifier of the current event. Further, StateMachine replaces the current state with the new state and uses the new state to process the event. StateFactory provides a CreateState function to create a specific state, and the function parameter is the event Event. As a result, StateMachine does not need to care about how to create a specific state, but only needs to use the state factory to create the next state, so that flexible creation of the state can be achieved. In addition, encapsulating the state creation process into the state factory class can easily expand the state. When a new state needs to be added, only part of the code in the state factory class needs to be modified, and no changes need to be made to the specific user of the state, StateMachine, which facilitates code expansion and can achieve flexible state creation and state jump according to the event processing strategy.

[0058] In one embodiment, if Fig. 6A As shown, a control method of a finite state machine is provided, and the method is applied to Figure 1 The terminal in is used as an example to illustrate, including the following steps:

[0059] Step 602: Receive a control signal, where the control signal carries signaling information.

[0060] Step 604: Convert the control signal into an event according to the signaling information.

[0061] Step 606: Call the event processing class to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic.

[0062] Step 608, when processing an event, if the state machine class determines to accept the event according to the current state, the HandEvent function of the current state is called to perform corresponding business logic processing on the event and return the corresponding processing state. The processing state is the corresponding status code returned after each state processes the event, and the status code is the return value of the HandEvent function.

[0063] Step 610, when processing an event, if the state machine class determines that the event is not accepted for processing based on the current state, the return state is not accepted for processing; obtain the processing strategy corresponding to the current state, process the event according to the processing strategy, and return the corresponding processing state.

[0064] Step 612, when the returned processing status is that the processing is completed, jump to the next state to process the event; when the returned processing status is to continue processing, no state jump is performed, and the HandEvent function of the current state is called to continue processing the event; when the returned processing status is that the processing is not accepted, the processing strategy corresponding to the current state is obtained.

[0065] like Figure 6B As shown, it is a schematic diagram of the calling relationship when the finite state machine processes an event. After the terminal receives the control signal sent by different devices, the terminal can convert the signal into an event according to the signaling information carried in the control signal. Different devices may include third-party devices, terminal devices, servers, and IoT devices. Further, the terminal can call the event processing class to process the event. The event processing class includes a state machine class and a state class. The state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic. When processing an event, if the state machine class determines to accept the processing event according to the current state, the HandEvent function of the current state is called to perform the corresponding business logic processing on the event and return the corresponding processing state. The processing state is the corresponding status code returned after each state processes the event, and the status code is the return value of the HandEvent function. In addition, when processing an event, if the state machine class determines not to accept the processing event according to the current state, the return state is not accepted for processing. When the returned status is not to be processed, the terminal obtains the processing strategy corresponding to the current state through StateMachine, processes the event according to the obtained processing strategy, and returns the corresponding processing status. Further, when the returned processing status is completed, StateMachine jumps to the next state to process the event; when the returned processing status is to continue processing, StateMachine does not jump to the state, calls the HandEvent function of the current state, and continues to process the event; when the returned processing status is not to be processed, StateMachine continues to obtain the processing strategy corresponding to the current state. An event can contain event type, event identifier (ie event id) and event content (MSG is a structure in Windows programs, in Windows programs, messages are represented by MSG structures). Event type (Event_type) represents a type of event. Event identifier, i.e. event id (Event_id), represents a specific event, so in the processing function of each event, you can flexibly perform corresponding processing according to the event type and event id. For example, in the parent state, you can only care about the event type, and the logic of the specific event can be processed in the child state.

[0066] The following is an example of an unmanned vehicle. After the system receives a signal, that is, when the terminal receives a signal sent by the IoT device vehicle A, the terminal can convert the signal into an internal event A according to the control information carried in the signal. Further, the terminal can call the state machine to process the event A. The state machine determines whether the current event A can be accepted and processed according to the current state. If it is determined that the event A can be accepted and processed, the HandEvent function of the current state is called to perform corresponding business logic processing on the event A and return the corresponding processing status. For example, the state of vehicle A can include normal operation and failure. The state machine can determine whether the current event A can be accepted and processed according to the current state, that is, determine whether the state of vehicle A corresponding to event A is normal operation or failure. When the state machine determines that event A is accepted and processed according to the current state, that means that the state of vehicle A corresponding to event A is normal operation, the next process will be entered. If it is determined that event A is not accepted and processed, it means that the state of vehicle A corresponding to event A is a failure, and event A cannot be accepted and processed, and the process of obtaining the processing strategy is entered, and event A is processed according to the obtained processing strategy, and the corresponding processing status is returned. For example, when the processing strategy obtained by the state machine is a replacement event (REPLACE), the state machine can call the state factory to create a new state to handle the event A and return the corresponding processing state. If none of the above steps can effectively handle the event A, then ignore the event A. When vehicle A is running normally, it can receive a command task, which includes task start, task pause, task cancellation, and task end. The state machine can realize the state jump when the vehicle A is running normally, that is, control vehicle A to execute the command task start, task pause, task cancellation, or task end. That is, the system can define a large parent state, save a state machine in the parent state to complete the jump of the sub-state, realize the nesting of the state machine, and conveniently and flexibly add sub-states to the parent state. For the user of the state machine, the performance is the same, so complex nesting can be performed internally without worrying about affecting the user of the state machine.

[0067] In this embodiment, all signals are abstracted as events, and the event processing class can flexibly perform corresponding processing according to the event type or event identifier. For example, in the parent state, only the event type is concerned, and the specific event is processed in the child state, thereby realizing flexible creation of states and state jumps according to the event processing strategy. At the same time, the state can also be rolled back according to the strategy at runtime, and the jump between different states can be dynamically controlled, which effectively improves the control efficiency.

[0068] In one of the embodiments, the event handling class is a Handler class, which is a computer term and a Java subclass and inheritance interface. The Handler class may include subclasses StateMachine class and State class, and both StateMachine class and State class inherit from the Handler class. A Handler pointer pointing to the StateMachine class is saved in the State class, and the Handler pointer is used to realize the nesting of parent-child state machines. Since both the StateMachine class and the State class inherit from the abstract event handling class, namely the Handler class, a StateMachine class can be injected into the State class, so that each Handler class can be flexibly combined to support the nesting of state machines. The decoration mode can be used to save a Handler pointer pointing to the StateMachine class in the State, so that another state machine is nested in the state, that is, the decoration mode is conveniently used to realize the infinite nesting of parent-child state machines. In the control method of the traditional finite state machine, the nesting of states is supported but the nesting of state machines is not supported, and the switching of child states needs to be maintained in the parent state, which makes the boundary between the state and the state machine unclear and somewhat confusing in concept. In this embodiment, the outside world can use only a pointer to the Handler class without having to care about the specific processing class, which is convenient for code expansion. Modifying part of the code in the state factory class will not affect the user of the Handler. Since StateMachine and State both inherit from Handler, the relationship between StateMachine and State can be flexibly combined to achieve the combination of parent-child states and the state jump of child states.

[0069] It should be understood that although Figure 1 The steps in the flowchart of -6 are shown in sequence as indicated by the arrows, but these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified in this document, there is no strict order restriction for the execution of these steps, and these steps can be executed in other orders. Moreover, Figure 1 -At least part of the steps in 6 may include multiple steps or multiple stages. These steps or stages are not necessarily executed at the same time, but can be executed at different times. The execution order of these steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least part of the steps or stages in other steps.

[0070] In one embodiment, if Figure 7As shown, a control device of a finite state machine is provided, including: a receiving module 702, a conversion module 704, a calling module 706, a processing module 708 and a determining module 710, wherein:

[0071] The receiving module 702 is used to receive a control signal, where the control signal carries signaling information.

[0072] The conversion module 704 is used to convert the control signal into an event according to the signaling information.

[0073] The calling module 706 is used to call the event processing class to process the event, wherein the event processing class includes a state machine class and a state class, the state machine class is used to implement the logic of state jump, and the state class is used to complete the processing of specific business logic.

[0074] The processing module 708 is used to process the event, if the state machine class determines to accept the event according to the current state, then perform corresponding business logic processing on the event and return the corresponding processing state.

[0075] The determination module 710 is used to determine the processing method corresponding to the next state according to the processing state.

[0076] In one of the embodiments, the calling module is also used to call the HandEvent function of the current state, perform corresponding business logic processing on the event, and return the corresponding processing status, wherein the processing status is the corresponding status code returned after each state processes the event, and the status code is the return value of the HandEvent function.

[0077] In one of the embodiments, the device further includes: a jump module and an acquisition module.

[0078] The jump module is used to jump to the next state to process the event when the returned processing status is completed. The call module is also used to not jump to the state when the returned processing status is continue processing, call the HandEvent function of the current state, and continue processing the event. The acquisition module is used to obtain the processing strategy corresponding to the current state when the returned processing status is not accepted for processing.

[0079] In one embodiment, the calling module is also used to call the GetStrategy function to obtain the processing strategy corresponding to the current state, and the processing strategy includes ignoring events, replacing events, and rolling back events. The processing module is also used to ignore the event when the processing strategy returned by the GetStrategy function is to ignore the event; when the processing strategy returned by the GetStrategy function is to replace the event, a new state is created according to the event to replace the current state and process the event; when the processing strategy returned by the GetStrategy function is to roll back the event, the event is restored to the previous state.

[0080] In one embodiment, the calling module is further used to call the state factory class when the processing strategy returned by the GetStrategy function is to replace the event, and use the CreateState function to create a corresponding new state according to the event type and event identifier of the event. The processing module is also used to replace the current state with the new state and use the new state to process the event.

[0081] In one embodiment, the processing module is further used to return the state of not accepting the processing if the state machine class determines that the event is not accepted for processing according to the current state when processing the event. The acquisition module is also used to obtain the processing strategy corresponding to the current state, process the event according to the processing strategy, and return the corresponding processing state.

[0082] In one of the embodiments, the device further includes: a saving module.

[0083] The save module is used to save a Handler pointer pointing to the StateMachine class in the State class. The Handler pointer is used to implement the nesting of parent-child state machines.

[0084] For the specific definition of the control device of the finite state machine, please refer to the definition of the control method of the finite state machine mentioned above, which will not be repeated here. Each module in the control device of the finite state machine can be implemented in whole or in part by software, hardware and a combination thereof. Each of the above modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to each of the above modules.

[0085] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Figure 8As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, an operator network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a control method of a finite state machine is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.

[0086] Those skilled in the art will understand that Figure 8 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0087] A computer device includes a memory and one or more processors, the memory storing computer-readable instructions, and one or more non-volatile storage media storing computer-readable instructions. When the computer-readable instructions are executed by the one or more processors, the one or more processors implement the steps of the finite state machine control method provided in any embodiment of the present application.

[0088] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing related hardware through computer-readable instructions, and the computer-readable instructions can be stored in a non-volatile computer-readable storage medium. When the computer-readable instructions are executed, they can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).

[0089] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0090] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.

Claims

1. A control method of a finite state machine, comprising: receiving a control signal; The control signal carries signaling information; According to the signaling information, the control signal is converted into an event; wherein the event refers to the response of an object to an external action, and the event includes an event type, an event identifier, and an event content, wherein the event type and the event identifier are stored in integer variable types, and the event content is a memory address of the signaling stored in a void pointer; Calling an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; each class in the event processing class includes a data description and a set of functions for operating data or transmitting messages; the event processing class includes a HandEvent function; When processing the event, if the state machine class determines to accept the event according to the current state, the HandEvent function of the current state is called to perform corresponding business logic processing on the event and return the corresponding processing state; wherein the processing state is the corresponding status code returned by each state after processing the event, and the status code is the return value of the HandEvent function; And, when the returned processing status is that the processing is completed, jump to the next state to process the event; when the returned processing status is to continue processing, no state jump is performed, and the HandEvent function of the current state is called to continue processing the event; and when the returned processing status is not accepted for processing, the processing strategy corresponding to the current state is obtained, and the processing strategy includes ignoring events, replacing events, and rolling back events.

2. The method according to claim 1, wherein: The event processing class includes an Enter function, which is a function for entering a state.

3. The method according to claim 1, wherein: The event processing class includes an Exit function, and the Exit function is a function used for exit status.

4. The method according to claim 1, wherein: The event processing class includes a GetStrategy function; the process of obtaining the processing strategy corresponding to the current state includes: Call the GetStrategy function to obtain the processing strategy corresponding to the current state; when the processing strategy returned by the GetStrategy function is to ignore the event, the event is ignored; when the processing strategy returned by the GetStrategy function is to replace the event, a new state is created according to the event to replace the current state and process the event; and when the processing strategy returned by the GetStrategy function is to roll back the event, the previous state is restored to process the event.

5. The method according to claim 4, wherein: When the processing strategy returned by the GetStrategy function is to replace an event, a new state is created according to the event to replace the current state, and the event is processed, including: When the processing strategy returned by the GetStrategy function is to replace the event, the state factory class is called, and the corresponding new state is created using the CreateState function according to the event type and event identifier of the event; and the current state is replaced with the new state, and the event is processed using the new state.

6. The method according to claim 1, wherein: The method further comprises: When processing the event, if the state machine class determines that the event is not acceptable for processing based on the current state, the return state is that the processing is not accepted; the processing strategy corresponding to the current state is obtained; and according to the processing strategy, the event is processed and the corresponding processing state is returned.

7. The method according to claim 1, wherein: The method further comprises: The event handling class is the Handler class, which includes subclasses StateMachine class and State class; both the StateMachine class and the State class inherit from the Handler class; and a Handler pointer pointing to the StateMachine class is stored in the State class, and the Handler pointer is used to realize the nesting of parent-child state machines.

8. A control device for a finite state machine, comprising: A receiving module, used for receiving a control signal; The control signal carries signaling information; A conversion module, configured to convert the control signal into an event according to the signaling information; wherein the event refers to a response of an object to an external action, and the event includes an event type, an event identifier, and an event content, wherein the event type and the event identifier are stored in integer variable types, and the event content is a memory address of the signaling stored in a void pointer; A calling module is used to call an event processing class to process the event; wherein the event processing class includes a state machine class and a state class; the state machine class is used to implement the logic of state jump; the state class is used to complete the processing of specific business logic; each class in the event processing class contains a data description and a set of functions for operating data or transmitting messages; the event processing class contains a HandEvent function; A processing module, used for, when processing the event, if the state machine class determines to accept the processing of the event according to the current state, the calling module is also used to call the HandEvent function of the current state, perform corresponding business logic processing on the event, and return the corresponding processing state; wherein the processing state is the corresponding status code returned by each state after processing the event, and the status code is the return value of the HandEvent function; A jump module, used for jumping to the next state to process the event when the returned processing state is that the processing is completed; The calling module is also used for calling the HandEvent function of the current state to continue processing the event without state jump when the returned processing state is to continue processing; and an acquisition module, which is used to acquire the processing strategy corresponding to the current state when the returned processing state is not accepting processing, and the processing strategy includes ignoring events, replacing events and rolling back events.

9. The control device of the finite state machine according to claim 8, wherein: The device also includes: the event processing class includes an Enter function, and the Enter function is a function used to enter a state.

10. The control device of the finite state machine according to claim 8, wherein: The device also includes: the event processing class includes an Exit function, and the Exit function is a function used for exiting the state.

11. The control device of the finite state machine according to claim 8, wherein: The event processing class includes a GetStrategy function; the device also includes: The calling module is also used to call the GetStrategy function to obtain the processing strategy corresponding to the current state; the return module is used to ignore the event when the processing strategy returned by the GetStrategy function is to ignore the event; the creation module is used to create a new state to replace the current state according to the event and process the event when the processing strategy returned by the GetStrategy function is to replace the event; and the recovery module is used to restore to the previous state to process the event when the processing strategy returned by the GetStrategy function is to roll back the event.

12. The control device of the finite state machine according to claim 11, wherein: The device also includes: The calling module is also used to call the state factory class when the processing strategy returned by the GetStrategy function is to replace the event, and use the CreateState function to create a corresponding new state according to the event type and event identifier of the event; and the replacement module is used to replace the current state with the new state and use the new state to process the event.

13. The control device of the finite state machine according to claim 8, wherein: The device also includes: The determination module is used to return the status of not accepting the processing if the state machine class determines that the event is not acceptable for processing based on the current state when processing the event; the acquisition module is also used to obtain the processing strategy corresponding to the current state; and the processing module is also used to process the event according to the processing strategy and return the corresponding processing status.

14. The control device of the finite state machine according to claim 8, wherein: The device also includes: The saving module is used to save a Handler pointer pointing to the StateMachine class in the State class, and the Handler pointer is used to realize the nesting of parent-child state machines.

15. A computer device comprising a memory and one or more processors, wherein the memory stores computer-readable instructions, and when the computer-readable instructions are executed by the one or more processors, the one or more processors execute the steps of the method according to any one of claims 1 to 7.

16. One or more computer storage media storing computer readable instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps of the method of any one of claims 1 to 7.