Disclosure of Invention
The invention aims to provide a state machine-based electric energy meter control method and system, which are used for solving the problems of system stability reduction and maintenance cost increase possibly caused by improper priority treatment (especially wrong priority).
In order to achieve the above object, the present invention provides a method comprising:
A state machine-based electric energy meter control method comprises the following steps:
1) Judging whether the received control command corresponds to the state with the highest priority or the current state machine is in the state with the highest priority or not through a state machine, if so, controlling the state machine to be in the state with the highest priority so as to execute the control on the electric energy meter, and if not, executing the step 2);
2) Judging whether a control command corresponds to a state of a priority level reduction stage or a state of the priority level reduction stage exists or not through a state machine, if so, controlling the state machine to be in the state of the priority level reduction stage so as to execute control on the electric energy meter, if not, repeating the step 2), and repeating the step 2 on the basis of the previous repetition until no state with lower priority level exists.
Further, in step 1), if it is determined that there is no case where the received control command corresponds to the control state with the highest priority and there is a case where the current state machine is in the control state with the highest priority, the control state machine is in the control state with the highest priority, and the control command is stored in the corresponding field of the control state of the state machine corresponding to the control command, so that when the state machine is not in the control state with the highest priority, the control command is processed in steps 1) -2) as the received control command.
Further, in step 2), if it is determined that there is no case where the received control command corresponds to the control state of a certain priority-reduced stage and there is a case where the current state machine is in the control state of the priority-reduced stage, the control state machine is in the control state of the priority-reduced stage, and the control command is stored in the corresponding field of the control state of the state machine corresponding to the control command, so that when the state machine is not in the control state of the priority-reduced stage, the control command is processed in steps 1) to 2) as the received control command.
Further, the control states of the state machine include at least two types of overload/overheat protection states, power-preserving states, friendly power-using states and conventional opening and closing control states.
Further, the control state priority is sequentially from high to low, namely an overload/overheat protection state, a power-saving state, a friendly power-using state and a conventional opening and closing control state.
Further, the mode of controlling the state machine to execute the control on the electric energy meter in the state with the highest priority or in the state with a certain priority lowered by one level comprises the step of controlling the state machine to execute the opening or closing action of the electric energy meter according to the control logic of the state machine in the state and the combination of the current state of the state machine and the received control command in the state with the highest priority or in the state with the certain priority lowered by one level.
The beneficial effects of the invention are as follows:
The invention uses the characteristic that the output of the Mealy type state machine is a joint function formed by the current state and the input of the state machine, judges from the highest priority according to the priority sequence of the control state of the Mealy type state machine, specifically judges whether the control command corresponds to the highest priority state (namely, whether the control command corresponding to the highest priority state appears or not) or the current state machine is in the highest priority state (namely, whether the current state is the highest priority state or not), and keeps the state as long as the highest priority state is to be triggered or already exists, otherwise, continuously judges whether the state of the next lower priority is to be triggered or already exists, which is equivalent to realizing the locking of the current state of the state machine, and keeps the state of the state machine in the current state to execute the control of the electric energy meter as long as the priority of the state corresponding to the received control command is not higher than the priority of the state of the current state machine; when the state corresponding to the received control command is higher than the priority of the state in which the current state machine is located, the state of the state machine is switched to the state corresponding to the control command with higher priority to execute the control of the electric energy meter, thereby ensuring that the control of the electric energy meter is not influenced by the control command with lower priority, meanwhile, as long as a certain control command exists, the priority of the state corresponding to the control command is higher than the priority of the control state in which the current Mealy type state machine is located, the Mealy type state machine can still respond to the control command with higher priority of the corresponding state immediately, rather than continuing to execute the current control state, therefore, the problem of improper priority treatment (especially disorder of priority) can be effectively avoided, namely the problem that the current control state of the Mealy type state machine is lower in priority and is executed preferentially can be effectively avoided, and the stability of the system is effectively improved.
In order to achieve the above object, the present invention further provides:
a state machine-based electric energy meter control system comprises a processor, wherein executable program instructions are stored in the processor and are used for being executed to realize the state machine-based electric energy meter control method.
The electric energy meter control system based on the state machine can achieve the same beneficial effects as the electric energy meter control method based on the state machine.
Detailed Description
The present invention will be further described in detail with reference to the drawings and examples, in order to make the objects, technical solutions and advantages of the present invention more apparent.
Electric energy meter control method embodiment based on state machine:
as shown in fig. 1, the present embodiment provides a technical solution of a method for controlling an electric energy meter based on a state machine (specifically, the controlled electric energy meter is an intelligent electric energy meter), which specifically includes the following steps:
1) Judging whether the received control command corresponds to the state with the highest priority or the current state machine is in the state with the highest priority or not through a state machine, if so, controlling the state machine to be in the state with the highest priority so as to execute the control on the electric energy meter, and if not, executing the step 2), wherein the state machines mentioned in the embodiment are all Mealy type state machines;
2) Judging whether a control command corresponds to a state of a priority level reduction stage or a state of the priority level reduction stage exists or not through a state machine, if so, controlling the state machine to be in the state of the priority level reduction stage so as to execute control on the electric energy meter, if not, repeating the step 2), and repeating the step 2) on the basis of the previous repetition until no state with lower priority level exists.
The output signal of the Mealy-type state machine depends not only on the control state in which the current Mealy-type state machine is located, but also on the control command which is currently input to the Mealy-type state machine. Therefore, the embodiment uses the characteristic that the output of the Mealy-type state machine is a joint function formed by the current state and the input of the state machine, and judges from the highest priority according to the priority order of the control states of the Mealy-type state machine, specifically judges whether the control command corresponds to the state with highest priority (namely, whether the control command corresponding to the state with highest priority appears or not) or the current state machine is in the state with highest priority (namely, whether the current state is in the state with highest priority or not), so long as the state with highest priority is to be triggered or already exists, the state is kept, otherwise, whether the state with next lower priority is to be triggered or already exists is continuously judged, which is equivalent to realizing the locking of the current state of the state machine, and if the priority of the state corresponding to the received control command is not higher than the priority of the state where the current state machine is located, the state of the state machine is maintained in the current state where the state is to execute the control of the electric energy meter; when the state corresponding to the received control command is higher than the priority of the state in which the current state machine is located, the state of the state machine is switched to the state corresponding to the control command with higher priority to execute the control of the electric energy meter, thereby ensuring that the control of the electric energy meter is not influenced by the control command with lower priority, meanwhile, as long as a certain control command exists, the priority of the state corresponding to the control command is higher than the priority of the control state in which the current Mealy type state machine is located, the Mealy type state machine can still respond to the control command with higher priority of the corresponding state immediately, rather than continuing to execute the current control state, therefore, the problem of improper priority treatment (especially disorder of priority) can be effectively avoided, namely the problem that the current control state of the Mealy type state machine is lower in priority and is executed preferentially can be effectively avoided, and the stability of the system is effectively improved.
Specifically, the control states of the Mealy-type state machine comprise at least two types of overload/overheat protection states, power-preserving states, friendly power-using states and conventional opening and closing control states. In this embodiment, the Mealy-type state machine includes four control states, which are four key states of overload/overheat protection state, power-saving state, friendly power-using state and conventional switch-off and switch-on control state, respectively.
The control state priority is sequentially from high to low, namely an overload/overheat protection state, a power-saving state, a friendly power-using state and a conventional switching-on/switching-off control state. In this embodiment, the Mealy-type state machine includes four control states, which are respectively an overload/overheat protection state, a power-saving state, a friendly power-using state and a conventional switch-on/off control state, and four key states, where priorities of the four control states are, in order from high to low, the overload/overheat protection state, the power-saving state, the friendly power-using state and the conventional switch-on/off control state. In other embodiments, the control state of the Mealy-type state machine and the priority of the control state can be flexibly set according to requirements.
In summary, the design idea of the scheme is to construct an efficient and safe control state machine based on the Mealy type state machine, and the output signal of the state machine not only depends on the control state of the current Mealy type state machine, but also depends on the control command of the current input Mealy type state machine, namely, in the Mealy type state machine, the output is a joint function of the state and the input. To obtain the output signal of the Mealy-type state machine, it is necessary to know the control state of the current Mealy-type state machine and the control command of the current input Mealy-type state machine, as shown in fig. 3, specifically, taking the case that the Mealy-type state machine includes four control states (overload/overheat protection state, power-preserving state, friendly power-using state and conventional power-off/power-on control state) as an example, the above steps 1) -2) are described in detail:
1) Judging whether the received control command corresponds to the state with the highest priority or the current state machine is in the state with the highest priority or not through a state machine, if so, controlling the state machine to be in the state with the highest priority so as to execute the control on the electric energy meter, and if not, executing the step 2);
And, in step 1), if it is determined that there is no case where the received control command corresponds to the control state having the highest priority and there is a case where the current state machine is in the control state having the highest priority, the control state machine is in the control state having the highest priority, and the control command is stored in the corresponding data field of the control state of the state machine corresponding to the control command, so that when the state machine is not in the control state having the highest priority, the control command is processed in steps 1) -2) as the received control command.
Specifically, in this embodiment, when the control state of the Mealy-type state machine is in the highest priority state (i.e., the overload/overheat protection state), the output of the Mealy-type state machine (i.e., what control state the Mealy-type state machine will enter) depends on the control command of the Mealy-type state machine currently input. Judging whether the control command of the current input Mealy type state machine corresponds to the state with the highest priority of the current Mealy type state machine, if so (namely, the control command is an overload/overheat protection control command), controlling the Mealy type state machine to control an electric energy meter (namely, controlling other related devices to be switched on and off through the electric energy meter) in the state with the highest priority, and if not (namely, the control command is a non-overload/overheat protection control command), maintaining the Mealy type state machine in the overload/overheat protection state, and simultaneously, storing the control command of the current input Mealy type state machine in a corresponding data field of the control state of the Mealy type state machine corresponding to the control command. And storing the control command in a corresponding data field under the condition that the control command currently input into the Mealy type state machine does not correspond to the state with the highest priority of the current Mealy type state machine, so that when the state machine is not in the control state with the highest priority (namely, all control logic in the state with the highest priority of the current Mealy type state machine is executed completely), the control command stored in the corresponding data field is used as the control command input into the Mealy type state machine again to process related steps.
2) Judging whether a control command corresponds to the state of the priority level reduction stage or the current state machine is in the state of the priority level reduction stage or not through a state machine, and if so, controlling the state machine to be in the state of the priority level reduction stage so as to execute control on the electric energy meter;
In step 2), if it is determined that there is no case where the received control command corresponds to the control state of a certain priority-reduced stage and there is a case where the current state machine is in the control state of the priority-reduced stage, the control state machine is in the control state of the priority-reduced stage, and stores the control command in a corresponding field of the control state of the state machine corresponding to the control command, so that when the state machine is not in the control state of the priority-reduced stage, the control command is processed in steps 1) -2) as the received control command.
Specifically, in this embodiment, when the situation in step 1) is absent, that is, when the control state of the Mealy-type state machine is in a control state (such as a power-on state) that is lower in priority by one level than the control state with the highest priority (i.e., an overload/overheat protection state) and the control command currently input to the Mealy-type state machine is not the control command corresponding to the control state with the highest priority (i.e., the overload/overheat protection control command), the output of the Mealy-type state machine (i.e., what control state the Mealy-type state machine will enter) is the control state of the current Mealy-type state machine and the control command currently input to the Mealy-type state machine. Judging whether the control command of the current input Mealy type state machine corresponds to the state that the priority of the current Mealy type state machine is reduced by one level, if so (namely, the control command is a power-saving control command), controlling the Mealy type state machine to execute the control on the electric energy meter in the power-saving state, and if not (namely, the control command is not the power-saving control command), maintaining the Mealy type state machine in the power-saving state, and simultaneously, storing the control command of the current input Mealy type state machine in a corresponding data field of the control state of the Mealy type state machine corresponding to the control command. And storing the control command in a corresponding data field under the condition that the control command of the current input Mealy type state machine does not correspond to the state of the current Mealy type state machine with the lowered priority level, so that when the state machine is not in the state of the lowered priority level (namely, the control logic of the state of the current Mealy type state machine with the lowered priority level is completely executed), the control command stored in the corresponding data field is used as the control command of the input Mealy type state machine again to process related steps.
If not, repeating step 2), and each repetition reduces the priority level by one level based on the previous repetition until no lower-priority state exists.
In this embodiment, on the basis that there is no case where the control command of the current input Mealy type state machine corresponds to the overload/overheat protection state or the current state machine is in the overload/overheat protection state, the control command of the current input Mealy type state machine corresponds to the power-saving state or the current state machine is in the power-saving state, it is determined whether the control command of the current input Mealy type state machine corresponds to the friendly power-saving state, if so (i.e., the control command is the friendly power-saving state control command), the Mealy type state machine is controlled to perform control on the electric energy meter in the friendly power-saving state, and if not (i.e., the control command is not the friendly power-saving control command), the Mealy type state machine is maintained in the friendly power-saving state, and at the same time, the control command of the current input Mealy type state machine is stored in a corresponding data field of the control state of the Mealy type state machine corresponding to the control command. And under the condition that the control command of the current input Mealy type state machine does not correspond to the friendly power utilization state of the current Mealy type state machine, storing the control command in a corresponding data field so as to take the control command stored in the corresponding data field as the control command of the input Mealy type state machine again when the state machine is not in the friendly power utilization state (namely, the control logic of the current Mealy type state machine in the friendly power utilization state is completely executed), and processing related steps.
In this embodiment, based on the condition that there is no control command of the current input Mealy type state machine corresponding to the overload/overheat protection state or the current state machine is in the overload/overheat protection state, the control command of the current input Mealy type state machine corresponding to the power-saving state or the current state machine is in the power-saving state, the control command of the current input Mealy type state machine corresponding to the friendly power-using state or the current state machine is in the friendly power-using state, whether the control command of the current input Mealy type state machine corresponds to the conventional switch-on/off state is determined, and if the control command corresponds to the conventional switch-on/off control command, the Mealy type state machine is controlled to execute the control of the electric energy meter in the conventional switch-on/off state. Based on the above-mentioned judgment of step 1) and step 2), there is no possibility that the control command of the Mealy type state machine is not a conventional opening/closing control command at this time, so there is no case that the relevant command is stored at this time.
As shown in the state machine control flow model diagram of fig. 2, when the Mealy type state machine is performing the control logic corresponding to a certain control state, if the priority of the state corresponding to a certain control command is lower than the state of the current Mealy type state machine, the Mealy type state machine continuously maintains the current state, and stores the control command at the corresponding position, i.e. the Mealy type state machine is not affected by the control command with lower level, and if the priority of the state corresponding to a certain control command is higher than the state of the current Mealy type state machine, the Mealy type state machine will execute the state corresponding to the control command instead, i.e. the Mealy type state machine responds to the control command with higher level in real time. Although the control logic corresponding to the control state of the current Mealy-type state machine is not executed, once a control command with a higher level is encountered, the Mealy-type state machine responds to the control command with a higher priority in real time instead of selecting to continue to execute the control state of the current Mealy-type state machine, so that the problem of improper priority processing can be effectively avoided, namely the problem that the control state of the current Mealy-type state machine is executed preferentially while the priority of the current control state of the Mealy-type state machine is lower can be effectively avoided, and the stability of the system is effectively improved.
Four key states (overload/overheat protection state, power-saving state, friendly power-saving state and conventional switching-on/off control state) included in the Mealy type state machine are specifically designed as configurable modules, and one or more state functions of the four key states are flexibly selected for adaptation according to the requirements of different electric meter types. The electric energy meter control method is designed to utilize the characteristics of a Mealy type state machine, rely on a set of strict and clear flow architecture, accurately analyze and execute received remote control commands through strict and clear logic steps, ensure the accuracy of operation and the safety of a system, select control functions according to different electric meter types, effectively reduce the dependence among functions, improve the flexibility and maintainability of the system, reduce the degree of functional coupling and improve the stability of the system.
The four control states are designed as dynamic optional components, any combination of the four functional states is flexibly integrated according to the unique requirement of a specific instrument type, a set of instruction processing flow which is strictly logically and clearly layered and is constructed by utilizing the characteristics of a Mealy type state machine is combined, remote control instructions are accurately and stably executed, interweaving association among functions is reduced, modularization and decoupling characteristics of a system are enhanced, a series of problems caused by disordered priority order are avoided, user experience is optimized, and a solid foundation is laid for flexibility and reliability of a smart power grid.
State machine based embodiments of a power meter control system:
The embodiment provides a technical solution of an electric energy meter control system based on a Mealy-type state machine, where the system includes a processor, and the processor is configured to implement any one implementation mode of an electric energy meter control method based on a state machine, and specific implementation modes of the embodiment refer to an embodiment of an electric energy meter control method based on a state machine, which is not described herein again.
It should be noted that the above-mentioned embodiments are merely preferred embodiments of the present invention, and the present invention is not limited to the above-mentioned embodiments, but may be modified without inventive effort or equivalent substitution of some of the technical features thereof by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.