State machine diagram generation method and device, storage medium and electronic device
By obtaining the current state of the target device and generating the initial state machine diagram based on the state machine diagram template, the problem of low efficiency in generating the state machine diagram in the prior art is solved, real-time update and efficient generation of the state machine diagram are realized.
Patent Information
- Application Number
- CN202411387200.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-30
- Publication Date
- 2025-02-11
AI Technical Summary
In the prior art, the efficiency of generating state machine diagrams is inefficient and requires relying on third-party visualization software. Developers need to be familiar with their development language and build a development environment.
By obtaining the current state of the target device, an initial state machine diagram is generated based on the state machine diagram template, and the sub-state machine diagram and state jump conditions are updated according to the current state and the state machine diagram mask to achieve real-time update of the state machine diagram.
It improves the efficiency of state machine diagram generation, avoids dependence on third-party visualization software, simplifies the development process, and realizes the state of the target device at each moment in the state machine diagram template.
Smart Images

Figure CN119417935A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of state machine diagrams, and in particular, to a method, device, storage medium and electronic device for generating a state machine diagram. Background Art
[0002] A state machine diagram is a dynamic diagram that describes the various states that an object goes through during its life cycle and the reasons that cause the object's state changes.
[0003] In related technologies, generating state machine diagrams often requires the use of third-party visualization software. Such visualization software requires developers to be familiar with its development language and build a development environment.
[0004] Due to this control, there is a problem of low efficiency in generating state machine diagrams in the related art.
[0005] Currently, no effective solution has been proposed for the above-mentioned problems existing in the related technologies. Summary of the invention
[0006] Embodiments of the present invention provide a method, device, storage medium and electronic device for generating a state machine diagram, so as to at least solve the problem of low efficiency in generating a state machine diagram existing in the related art.
[0007] According to an embodiment of the present invention, a method for generating a state machine diagram is provided, comprising: obtaining a current state of a target device at a current moment; determining a first sub-state machine diagram included in an initial state machine diagram and corresponding to the current moment, and determining a second sub-state machine diagram included in the initial state machine diagram, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes multiple sub-state machine diagrams, the sub-state machine diagrams are used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the multiple sub-state machine diagrams are connected by a state jump condition; updating the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram; updating the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask.
[0008] According to another embodiment of the present invention, a state machine diagram generation device is provided, comprising: an acquisition module, used to acquire the current state of a target device at a current moment; a determination module, used to determine a first sub-state machine diagram included in an initial state machine diagram and corresponding to the current moment, and to determine a second sub-state machine diagram included in the initial state machine diagram, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes multiple sub-state machine diagrams, the sub-state machine diagrams are used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the multiple sub-state machine diagrams are connected by a state jump condition; a first update module, used to update the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram; a second update module, used to update the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask.
[0009] According to yet another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the steps of any one of the above method embodiments when run.
[0010] According to yet another embodiment of the present invention, there is provided an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0011] According to yet another embodiment of the present invention, a computer program product is provided, including a computer program, and when the computer program is executed by a processor, the steps of the method described in each embodiment of the present application are implemented.
[0012] Through the present invention, the current state of the target device at the current moment is obtained; the first sub-state machine diagram corresponding to the current moment included in the initial state machine diagram is determined, and the second sub-state machine diagram included in the initial state machine diagram is determined, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes multiple sub-state machine diagrams, the sub-state machine diagram is used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the multiple sub-state machine diagrams are connected by a state jump condition; based on the current state and a preset state machine diagram mask, the first sub-state machine diagram is updated in the initial state machine diagram, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram; based on the state machine diagram mask, the second sub-state machine diagram and the state jump condition in the initial state machine diagram are updated. Since the initial state machine diagram can be generated according to the state machine diagram template, and the first sub-state machine diagram is updated in the initial state machine diagram according to the current state of the target device at the current moment and the state machine diagram mask, and the second sub-state machine diagram of the initial state machine diagram is updated according to the state machine diagram mask, the state of the target device at each moment can be displayed in real time in the initial state machine diagram, and the state of the target device at each moment is continuously updated in the state machine diagram template. Therefore, the problem of low efficiency in generating state machine diagrams existing in related technologies can be solved, thereby achieving the effect of improving the efficiency of generating state machine diagrams. BRIEF DESCRIPTION OF THE DRAWINGS
[0013] Figure 1 It is a hardware structure block diagram of a mobile terminal of a method for generating a state machine diagram according to an embodiment of the present invention;
[0014] Figure 2 is a flow chart of a method for generating a state machine diagram according to an embodiment of the present invention;
[0015] Figure 3 is a schematic diagram of a state machine diagram template according to an embodiment of the present invention;
[0016] Figure 4 is a schematic diagram of a configuration file according to an embodiment of the present invention;
[0017] Figure 5 is a schematic diagram of a state machine diagram template generated according to a configuration file according to an embodiment of the present invention;
[0018] Figure 6 is a flow chart of a method for generating a state machine diagram according to a specific embodiment of the present invention;
[0019] Figure 7 It is a structural block diagram of a device for generating a state machine diagram according to an embodiment of the present invention. DETAILED DESCRIPTION
[0020] Hereinafter, embodiments of the present invention will be described in detail with reference to the accompanying drawings and in combination with the embodiments.
[0021] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence.
[0022] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 1 FIG. 1 is a hardware structure diagram of a mobile terminal of a method for generating a state machine diagram according to an embodiment of the present invention. Figure 1 As shown, the mobile terminal may include one or more ( Figure 1 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 1 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 1 More or fewer components as shown, or with Figure 1 Different configurations are shown.
[0023] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the method for generating the state machine diagram in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, to implement the above method. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories may be connected to the mobile terminal via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0024] The transmission device 106 is used to receive or send data via a network. The specific example of the above network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 can be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0025] In this embodiment, a method for generating a state machine diagram is provided. Figure 2 is a flow chart of a method for generating a state machine diagram according to an embodiment of the present invention, such as Figure 2 As shown, the process includes the following steps:
[0026] Step S202, obtaining the current state of the target device at the current moment;
[0027] Optionally, the target device may be a device included in the car, such as a radio, a multimedia player, a gear controller, a central control terminal of the car, etc., and the present invention is not limited to this. The current state of the target device may be acquired in real time, and step S204 is executed when the current state changes from the state at the previous moment. Of course, step S204 may also be executed after the current state is acquired.
[0028] Optionally, acquiring the current state of the target device at the current moment may include acquiring the current state of the target device at the current moment in real time, or acquiring the current state of the target device at the current moment according to a predetermined time period, or acquiring the current state of the target device at the current moment upon receiving an acquisition instruction.
[0029] Step S204, determining a first sub-state machine diagram included in the initial state machine diagram and corresponding to the current moment, and determining a second sub-state machine diagram included in the initial state machine diagram, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes multiple sub-state machine diagrams, the sub-state machine diagrams are used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the multiple sub-state machine diagrams are connected by a state jump condition;
[0030] In the above embodiment, the state machine may include a state register and a combinational circuit, which can transfer states according to a preset state according to a control signal, and is a control center that coordinates related signal actions and completes specific operations. A state machine diagram is a dynamic diagram used to describe the various states that an object goes through during its life cycle, as well as the reasons that cause the object's state changes.
[0031] In the above embodiment, in the initial state, that is, when the state machine diagram is generated, a configuration file for generating a state machine diagram template can be loaded to generate a state machine diagram template in a visual interface. The state machine diagram template can include the title of the state machine diagram, the format of the state machine diagram, and the sub-state machine diagram at each moment included in the state machine diagram. That is, the state machine diagram template can include multiple sub-state machine diagrams. The schematic diagram of the state machine diagram template can be found in the attached Figure 3 ,like Figure 3 As shown, the state machine diagram template may include sub-state machine diagrams and state jump conditions. The sub-state machine diagram may include S_1, S_2, S_3, S_4, S_5, S_6, S_7, and S_8, and one sub-state machine diagram represents the state at a moment. For example, S_1 can represent the state of the target device at moment T1, S_2 represents the state of the target device at moment T2, S_3 represents the state of the target device at moment T3, S_4 represents the state of the target device at moment T4, S_5 represents the state of the target device at moment T5, S_6 represents the state of the target device at moment T6, S_7 represents the state of the target device at moment T7, and S_8 represents the state of the target device at moment T8. When the state machine diagram is initially generated, the state machine diagram template determines the initial state machine diagram. At this time, S_1, S_2, S_3, S_4, S_5, S_6, S_7, and S_8 can display the initial state. When the current moment is moment T1, the first sub-state machine diagram included in the initial state machine diagram can be determined, that is, Figure 3 At this time, it can be determined that the second sub-state machine diagram included in the initial state machine diagram is empty. When the current time is T2, the first sub-state machine diagram is S_2, and at this time, the second sub-state machine diagram is S_1. When the current time is T3, the first sub-state machine diagram is S_3, and at this time, the second sub-state machine diagram is S_1 and S_2. The state jump condition can be attached Figure 3 The arrow between the two sub-state machine diagrams in .
[0032] In the above embodiment, the state machine diagram template may include a fixed number of sub-state machine diagrams, each of which corresponds to a moment, so the state of the target device at a fixed number of moments can be obtained. For example, when the state machine diagram template includes 8 sub-state machine diagrams, the state of the target device at 8 different moments can be obtained. Of course, the state machine diagram template may also include a non-fixed number of sub-state machine diagrams, so the state of a non-fixed number of target devices can be obtained.
[0033] In the above embodiment, the state machine diagram template can be displayed in the visualization interface, and the visualization interface can display a state machine diagram template of a fixed size. When the state machine diagram template includes a non-fixed number of sub-state machine diagrams, and the visualization interface can only display a fixed number of sub-state machine diagrams, the sub-state machine diagrams in the state machine diagram template can be updated in batches. For example, when only 8 sub-state machine diagrams can be displayed at a time in the state machine diagram template, as the acquisition time changes, from T1-T8, S_1-S_8 can be displayed, and as the acquisition time increases, at T9, S_9-S_16 can be displayed, and the sub-state machine diagrams of S_1-S_8 are combined into one diagram, scaled down, and displayed in a fixed area of the visualization interface.
[0034] Step S206, updating the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram;
[0035] In the above embodiment, the state machine diagram mask can be used to describe the sub-state machine diagram, that is, it can be used to indicate the meaning when the sub-state machine diagram is in different states, or to indicate that when the sub-state machine diagram is in a certain state, the sub-state machine diagram is adjusted to a form corresponding to the state. The state machine diagram mask can also include the title of the state machine diagram and the format information of the state machine diagram. Among them, the format information of the state machine diagram can include a dividing line, a state description of each state, etc. Figure 3 , the title can be State Machine Visual interface, and the state description can include Red: error state, Green: active state, Yellow: critical state, Black: inactive state. Figure 3 The dotted line in the figure is the dividing line, which is used to separate the title and state description from the sub-state diagram.
[0036] In the above embodiment, a subgraph for replacing the first sub-state machine graph can be generated according to the current state, and the state of the subgraph is determined, and the subgraph is adjusted according to the state description corresponding to the state in the state machine graph mask to obtain a replacement sub-state machine graph for replacing the first sub-state machine graph. For example, if the current state is an error state, the color of the subgraph is adjusted to red.
[0037] Step S208: updating the second sub-state machine diagram and the state transition condition in the initial state machine diagram based on the state machine diagram mask.
[0038] In the above embodiment, due to the change of time, the first sub-state machine diagram included in the initial state machine diagram needs to be updated, and because the state of the second sub-state machine diagram has also changed, the second sub-state machine diagram also needs to be adjusted and updated according to the state description in the state machine diagram mask. For example, the current time is T2, and the state of S_2 is activated at this time, then the sub-diagram generated by the current state can be adjusted to green. At this time, the second sub-state machine diagram at T1 is already in a critical state, so the second sub-state machine diagram can be adjusted to yellow. And the state jump condition between the two is adjusted to yellow. If there is T0 before T1, the state of the state machine diagram at T0 is an unactivated state, so the sub-state machine diagram at T0 can be adjusted to black.
[0039] Through the present invention, the current state of the target device at the current moment is obtained; the first sub-state machine diagram corresponding to the current moment included in the initial state machine diagram is determined, and the second sub-state machine diagram included in the initial state machine diagram is determined, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes multiple sub-state machine diagrams, the sub-state machine diagram is used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the multiple sub-state machine diagrams are connected by a state jump condition; based on the current state and a preset state machine diagram mask, the first sub-state machine diagram is updated in the initial state machine diagram, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram; based on the state machine diagram mask, the second sub-state machine diagram and the state jump condition in the initial state machine diagram are updated. Since the initial state machine diagram can be generated according to the state machine diagram template, and the first sub-state machine diagram is updated in the initial state machine diagram according to the current state of the target device at the current moment and the state machine diagram mask, and the second sub-state machine diagram of the initial state machine diagram is updated according to the state machine diagram mask, the state of the target device at each moment can be displayed in real time in the initial state machine diagram, and the state of the target device at each moment is continuously updated in the state machine diagram template. Therefore, the problem of low efficiency in generating state machine diagrams existing in related technologies can be solved, thereby achieving the effect of improving the efficiency of generating state machine diagrams.
[0040] Optionally, the execution subject of the above steps may be a background processor, or other devices with similar processing capabilities, but is not limited thereto.
[0041] In an exemplary embodiment, updating the first sub-state machine diagram in the initial state machine diagram based on the current state and a pre-set state machine diagram mask includes: determining the configuration information included in the current state; generating a third sub-state machine diagram based on the configuration information; determining the first format of the third sub-state machine diagram based on the state machine diagram mask; adjusting the format of the third sub-state machine diagram to the first format to obtain a fourth sub-state machine diagram; and replacing the first sub-state machine diagram with the fourth sub-state machine diagram. In this embodiment, the configuration information of the current state can be determined, and the third sub-state machine diagram can be generated from the configuration information. The configuration information may include the center point position coordinates of the third sub-state machine diagram, the identifier of the third sub-state machine diagram, the shape parameter information of the third sub-state machine diagram, and label characters. The shape parameter information may include the size information of the shape, for example, when the shape is a rectangle, it may include the length and width values of the shape, and when the shape is a circle, it may include the radius. The label characters may be the characters filled in the third sub-state machine diagram. For example, the attached Figure 3 The state of the third sub-state machine diagram can be determined, and the first format of the third sub-state machine diagram can be determined in the state machine diagram mask according to the state. For example, when the state of the third sub-state machine diagram is an activated state, the first format can be green. The color of the third sub-state machine diagram is adjusted to green to obtain a fourth sub-state machine diagram, and the first sub-state machine diagram is updated using the fourth sub-state machine diagram.
[0042] In an exemplary embodiment, updating the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask includes: determining the second format of the second sub-state machine diagram and the third format of the state jump condition based on the state machine diagram mask; adjusting the format of the second sub-state machine diagram to the second format to obtain the fifth sub-state machine diagram; updating the second sub-state machine diagram using the fifth sub-state machine diagram; and adjusting the format of the state jump condition in the initial state machine diagram to the third format. In this embodiment, the state of each sub-state machine diagram included in the second sub-state machine diagram can be determined, the second format corresponding to the state of each sub-state machine diagram can be determined according to the state machine diagram mask, the third format corresponding to the state jump condition can be determined, the format of the state jump condition can be adjusted to the third format, the format of the second sub-state machine diagram can be adjusted to the second format to obtain the fifth sub-state machine diagram, and the second sub-state machine diagram can be updated using the fifth sub-state machine diagram. For example, when the second sub-state machine diagram includes S_1 and S_2, the state jump conditions at this time are the arrows between S_1 and S_2 and the arrows between S_2 and S_3. At this time, according to the state machine diagram mask, it can be determined that the format of the state jump conditions is the same as that of S_2, which is a critical state. Therefore, the arrow between S_2 and S_3 can be jumped to yellow. Adjust S_2 to yellow. The state of S_1 is inactive, so the arrow between S_1 and S_2 is inactive, and adjust S_1 and the arrows between S_1 and S_2 to black.
[0043] In an exemplary embodiment, determining the second format of the second sub-state machine diagram based on the state machine diagram mask includes: determining the corresponding relationship between the state and format of the state machine diagram included in the state machine diagram mask, wherein the corresponding relationship includes that the error state corresponds to the first display format, the critical state corresponds to the second display format, the activated state corresponds to the third display format, and the inactivated state corresponds to the fourth display format, the first display format, the second display format, the third display format, and the fourth display format are different formats, the activated state is the state at the current moment, the critical state is the state at the first moment, the first moment is the moment before the current moment, the inactivated state is the state of all moments before the first moment, and the error state is the state when an error occurs in the state of the target device; determining the target state of each diagram included in the second sub-state machine diagram; and determining the second format corresponding to the target state based on the corresponding relationship. In this embodiment, the error state includes that there is an error in the state of the target device. The activated state represents the current state of the target device, the critical state is the state before the current state, and the inactivated state represents all states before the critical state. For example, when the activated state is S_4, the critical state is S_3, and the unactivated states are S_1 and S_2. Different states may correspond to different display formats. Each state corresponds to a different display format. The first display format may be red, the second display format may be yellow, the third display format may be green, and the fourth display format may be black. It should be noted that the above colors are only exemplary, and other colors may also be displayed, and the present invention is not limited to this.
[0044] In an exemplary embodiment, determining the second sub-state machine diagram included in the initial state machine diagram includes: determining the sixth sub-state machine diagram of the target device included in the initial state machine diagram at a first moment, wherein the first moment is a moment before the current moment; determining the seventh sub-state machine diagram of the target device included in the initial state machine diagram at a second moment, wherein the second moment is a moment before the first moment; determining the sixth sub-state machine diagram and the seventh sub-state machine diagram as the second sub-state machine diagram. In this embodiment, continue to refer to the attached Figure 3 , when the first sub-state machine diagram is S_4, the sixth sub-state machine diagram can be S_3, and the seventh sub-state machine diagram is S_2.
[0045] In an exemplary embodiment, before determining the first sub-state machine diagram included in the initial state machine diagram corresponding to the current moment, the method further includes: obtaining a configuration file for generating the state machine diagram template; determining the visualization interface parameters and state machine diagram parameters included in the configuration file; generating a visualization interface based on the visualization interface parameters; generating the sub-state machine diagram based on the state machine diagram parameters on the visualization interface to obtain the state machine diagram template. In this embodiment, a configuration file of a state machine diagram can be loaded, and the configuration file can include visualization interface parameters and state machine diagram hyperparameters. Visual interface parameters can describe the visualization interface, including the width and length values of the interface; state machine diagram parameters can be used to describe the state machine diagram, including the state names, center point coordinates, rectangular box width and height values, and label characters of all states. The state machine diagram character sequence template can be generated according to the state machine diagram configuration parameters. The width and height values of the two-dimensional template are the interface width and height values agreed in the configuration parameters. Each state is filled into the template character by character according to the position, size and rectangular frame label style agreed in the configuration parameters (empty characters are not involved in filling the layout area). The state jump condition is constructed with "arrow" style character graphics according to the pre- and post-states agreed in the configuration parameters. The state machine diagram character sequence template is completed. The configuration file diagram can be found in the attached Figure 4 The schematic diagram of the state machine diagram template generated according to the configuration file can be found in the attached Figure 5 .
[0046] In the above embodiment, the configuration file may be a file input by a user, and the user may dynamically adjust the configuration file in the visual interface to allow the user to dynamically adjust the layout, size, position, character labels and other content items of the state machine diagram.
[0047] In an exemplary embodiment, before determining the first sub-state machine diagram included in the initial state machine diagram corresponding to the current moment, the method further includes: rendering the state machine diagram title information and the state machine diagram format information included in the state machine diagram mask into the initial state machine diagram. In this embodiment, the current state machine diagram character sequence mask can be rendered. The rendering content includes title information (for example, displaying the character sequence as "State Machine VisualInterface"), state description (for example, describing that red represents an error state, yellow represents a critical state, and green represents an activated state), a separator line (used to separate the description area and the content area), and a state jump condition (rendered in yellow according to the state description), and is printed on a graphical terminal after the rendering is completed.
[0048] The following describes the method for generating a state machine diagram in conjunction with a specific implementation method:
[0049] Figure 6is a flow chart of a method for generating a state machine diagram according to a specific embodiment of the present invention, such as Figure 6 As shown, the process includes:
[0050] Step S602, loading a state machine diagram configuration file, and generating a state machine diagram character sequence template (corresponding to the above-mentioned state machine diagram template) according to the state machine diagram configuration parameters.
[0051] Specifically, the state machine diagram configuration file can be loaded. The configuration file can be divided into two groups of parameters. The first group of parameters describes the visual interface, including the width and length values of the interface; the second group of parameters describes the state machine diagram, including the state name, center point coordinates, rectangle width and height values, label characters, preceding states, and succeeding states of all states. The state machine diagram character sequence template is generated according to the state machine diagram configuration parameters. The width and height values of the two-dimensional template are the interface width and height values agreed in the configuration parameters. Each state is filled into the template character by character according to the position, size, and rectangle label style agreed in the configuration parameters (empty characters are not involved in filling the layout area). The state jump condition is constructed with "arrow" style character graphics according to the states agreed in the configuration parameters. Thus, the state machine diagram character sequence template is completed.
[0052] Step S604, determine whether the instance process is terminated, if the determination result is yes, execute step S606, if the determination result is no, execute step S608.
[0053] Specifically, the state machine diagram visualization process can be judged in real time based on the semaphore whether it is terminated, and if so, the process is terminated, otherwise it continues. The semaphore can be an input instruction, and when the termination instruction is received, the process is terminated.
[0054] Step S606, end.
[0055] Step S608, obtaining the previous moment state and the current moment state, and updating the corresponding state and jump conditions based on the state machine diagram character sequence template to obtain the current moment state machine diagram character sequence mask.
[0056] Specifically, the previous state and current state can be obtained through message communication means (between processes or within processes), and the corresponding state and jump conditions can be updated based on the state machine diagram character sequence template to obtain the current state machine diagram character sequence mask.
[0057] Step S610, rendering the character sequence mask of the state machine diagram at the current moment, and printing it on a graphical terminal.
[0058] Specifically, the character sequence mask of the state machine diagram at the current moment can be rendered. The rendered content includes the title (for example, the character sequence displayed is "State Machine Visual Interface"), the state description (for example, red represents an error state, yellow represents a previous state, and green represents a current state), a separator line (used to separate the description area and the content area), the previous state (rendered in yellow according to the state description), the current state (rendered in green according to the state description), and the state jump condition (rendered in yellow according to the state description). After the rendering is completed, it is printed on the graphical terminal.
[0059] In the aforementioned embodiment, a state machine diagram is constructed with a two-dimensional character sequence according to a state machine diagram character sequence template and a state machine diagram character sequence mask. After rendering, the state machine diagram character sequence can intuitively display the state machine diagram to meet the visualization requirements. The state machine diagram is visualized in real time only by a graphical terminal. This method is more versatile and easy to use; it does not rely on other third-party visualization software, which not only reduces the difficulty of operation for developers, but also releases the hardware resources additionally introduced by the third-party visualization software.
[0060] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, a magnetic disk, or an optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present invention.
[0061] In this embodiment, a device for generating a state machine diagram is also provided, which is used to implement the above-mentioned embodiments and preferred implementation modes, and the descriptions that have been made will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the devices described in the following embodiments are preferably implemented in software, the implementation of hardware, or a combination of software and hardware, is also possible and conceivable.
[0062] Figure 7 is a structural block diagram of a device for generating a state machine diagram according to an embodiment of the present invention, such as Figure 7 As shown, the device comprises:
[0063] The acquisition module 72 is used to acquire the current state of the target device at the current moment;
[0064] A determination module 74 is used to determine a first sub-state machine diagram included in an initial state machine diagram and corresponding to the current moment, and to determine a second sub-state machine diagram included in the initial state machine diagram, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes a plurality of sub-state machine diagrams, the sub-state machine diagrams are used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the plurality of sub-state machine diagrams are connected by a state jump condition;
[0065] A first updating module 76, configured to update the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram;
[0066] The second updating module 78 is used to update the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask.
[0067] In an exemplary embodiment, the first update module 76 can update the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask in the following manner: determine the configuration information included in the current state; generate a third sub-state machine diagram based on the configuration information; determine a first format of the third sub-state machine diagram based on the state machine diagram mask; adjust the format of the third sub-state machine diagram to the first format to obtain a fourth sub-state machine diagram; and replace the first sub-state machine diagram with the fourth sub-state machine diagram.
[0068] In an exemplary embodiment, the second update module 78 can update the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask in the following manner: determine the second format of the second sub-state machine diagram and the third format of the state jump condition based on the state machine diagram mask; adjust the format of the second sub-state machine diagram to the second format to obtain the fifth sub-state machine diagram; use the fifth sub-state machine diagram to update the second sub-state machine diagram; adjust the format of the state jump condition in the initial state machine diagram to the third format.
[0069] In an exemplary embodiment, the second update module 78 can determine the second format of the second sub-state machine diagram based on the state machine diagram mask in the following manner: determine the correspondence between the state and format of the state machine diagram included in the state machine diagram mask, wherein the correspondence includes that the error state corresponds to the first display format, the critical state corresponds to the second display format, the activation state corresponds to the third display format, and the inactivation state corresponds to the fourth display format, the first display format, the second display format, the third display format and the fourth display format are different formats, the activation state is the state at the current moment, the critical state is the state at the first moment, the first moment is the moment before the current moment, the inactivation state is the state of all moments before the first moment, and the error state is the state when an error occurs in the state of the target device; determine the target state of each diagram included in the second sub-state machine diagram; determine the second format corresponding to the target state based on the correspondence.
[0070] In an exemplary embodiment, the determination module 74 can determine the second sub-state machine diagram included in the initial state machine diagram in the following manner: determine the sixth sub-state machine diagram of the target device included in the initial state machine diagram at the first moment, wherein the first moment is the moment before the current moment; determine the seventh sub-state machine diagram of the target device included in the initial state machine diagram at the second moment, wherein the second moment is the moment before the first moment; determine the sixth sub-state machine diagram and the seventh sub-state machine diagram as the second sub-state machine diagram.
[0071] In an exemplary embodiment, the device can be used to obtain a configuration file for generating the state machine diagram template before determining the first sub-state machine diagram included in the initial state machine diagram corresponding to the current moment; determine the visualization interface parameters and state machine diagram parameters included in the configuration file; generate a visualization interface based on the visualization interface parameters; generate the sub-state machine diagram based on the state machine diagram parameters on the visualization interface to obtain the state machine diagram template.
[0072] In an exemplary embodiment, the device can also be used to render the state machine diagram title information and state machine diagram format information included in the state machine diagram mask into the initial state machine diagram before determining the first sub-state machine diagram included in the initial state machine diagram corresponding to the current moment.
[0073] It should be noted that the above modules can be implemented by software or hardware. For the latter, it can be implemented in the following ways, but not limited to: the above modules are all located in the same processor; or the above modules are located in different processors in any combination.
[0074] An embodiment of the present invention further provides a computer-readable storage medium, in which a computer program is stored, wherein the computer program is configured to execute the steps of any of the above method embodiments when running.
[0075] In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to, various media that can store computer programs, such as a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk.
[0076] An embodiment of the present invention further provides an electronic device, including a memory and a processor, wherein a computer program is stored in the memory, and the processor is configured to run the computer program to execute the steps in any one of the above method embodiments.
[0077] In an exemplary embodiment, the electronic device may further include a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.
[0078] An embodiment of the present invention further provides a computer program product, including a computer program, which implements the steps of the method in each embodiment of the present application when the computer program is executed by a processor.
[0079] For specific examples in this embodiment, reference may be made to the examples described in the above embodiments and exemplary implementation modes, and this embodiment will not be described in detail herein.
[0080] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.
[0081] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for generating a state machine diagram, characterized in that: include: Get the current status of the target device at the current moment; Determine a first sub-state machine diagram included in an initial state machine diagram and corresponding to the current moment, and determine a second sub-state machine diagram included in the initial state machine diagram, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes multiple sub-state machine diagrams, the sub-state machine diagrams are used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the multiple sub-state machine diagrams are connected by a state jump condition; updating the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram; The second sub-state machine diagram and the state transition condition in the initial state machine diagram are updated based on the state machine diagram mask.
2. The method according to claim 1, characterized in that Updating the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask comprises: Determining configuration information included in the current state; Generate a third sub-state machine diagram based on the configuration information; determining a first format of the third sub-state machine diagram based on the state machine diagram mask; Adjusting the format of the third sub-state machine diagram to the first format to obtain a fourth sub-state machine diagram; The first sub-state machine diagram is replaced with the fourth sub-state machine diagram.
3. The method according to claim 1, characterized in that Updating the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask includes: Determining a second format of the second sub-state machine diagram and a third format of the state jump condition based on the state machine diagram mask; Adjusting the format of the second sub-state machine diagram to the second format to obtain a fifth sub-state machine diagram; Updating the second sub-state machine diagram using the fifth sub-state machine diagram; The format of the state transition condition in the initial state machine diagram is adjusted to the third format.
4. The method according to claim 3, characterized in that Determining a second format of the second sub-state machine diagram based on the state machine diagram mask includes: Determine a correspondence between states and formats of the state machine diagram included in the state machine diagram mask, wherein the correspondence includes that an error state corresponds to a first display format, a critical state corresponds to a second display format, an activation state corresponds to a third display format, and an inactivation state corresponds to a fourth display format, the first display format, the second display format, the third display format, and the fourth display format are different formats, the activation state is a state at a current moment, the critical state is a state at a first moment, the first moment is a moment before the current moment, the inactivation state is a state at all moments before the first moment, and the error state is a state when an error occurs in the state of the target device; determining a target state for each diagram included in the second sub-state machine diagram; The second format corresponding to the target state is determined based on the corresponding relationship.
5. The method according to claim 1, characterized in that: Determining a second sub-state machine diagram included in the initial state machine diagram comprises: Determine a sixth sub-state machine diagram of the target device at a first moment included in the initial state machine diagram, wherein the first moment is a moment before the current moment; Determine a seventh sub-state machine diagram of the target device included in the initial state machine diagram at a second moment, wherein the second moment is a moment before the first moment; The sixth sub-state machine diagram and the seventh sub-state machine diagram are determined as the second sub-state machine diagram.
6. The method according to claim 1, characterized in that Before determining the first sub-state machine diagram included in the initial state machine diagram and corresponding to the current moment, the method further includes: Obtaining a configuration file for generating the state machine diagram template; Determining visualization interface parameters and state machine diagram parameters included in the configuration file; Generate a visualization interface based on the visualization interface parameters; The sub-state machine diagram is generated on the visualization interface based on the state machine diagram parameters to obtain the state machine diagram template.
7. The method according to claim 1, characterized in that Before determining the first sub-state machine diagram included in the initial state machine diagram and corresponding to the current moment, the method further includes: The state machine diagram title information and the state machine diagram format information included in the state machine diagram mask are rendered into the initial state machine diagram.
8. A device for generating a state machine diagram, characterized in that: include: The acquisition module is used to obtain the current state of the target device at the current moment; A determination module, used to determine a first sub-state machine diagram included in an initial state machine diagram and corresponding to the current moment, and to determine a second sub-state machine diagram included in the initial state machine diagram, wherein the initial state machine diagram is a state machine diagram generated based on a state machine diagram template, the state machine diagram template includes a plurality of sub-state machine diagrams, the sub-state machine diagrams are used to represent the state of the target device at different moments, the sub-state machine diagram displays a preset initial character when not updated, the second sub-state machine diagram is an updated state machine diagram, and any two adjacent sub-state machine diagrams included in the plurality of sub-state machine diagrams are connected by a state jump condition; A first updating module, configured to update the first sub-state machine diagram in the initial state machine diagram based on the current state and a preset state machine diagram mask, wherein the state machine diagram mask is used to indicate the state of the sub-state machine diagram included in the initial state machine diagram; The second updating module is used to update the second sub-state machine diagram and the state jump condition in the initial state machine diagram based on the state machine diagram mask.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method according to any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to run the computer program to perform the method according to any one of claims 1 to 7.