Method and device for detecting utilization rate of electricity meter stack
By detecting stack usage at the end of the meter cycle through a pure computer program, the resource consumption and missing detection problems of existing meter stack usage detection methods are solved, and stack usage detection with strong applicability and fast speed is realized.
Patent Information
- Application Number
- CN202410574322.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-10
- Publication Date
- 2024-08-27
AI Technical Summary
The existing meter stack usage detection method consumes a lot of processor resources for real-time monitoring, may cause stack overflow to be unable to be processed in time, and has the risk of missing detection, and is not suitable for most meter processors.
Stack usage detection is implemented through a pure computer program. The stack usage is detected at the end of the loop. It takes up little processor resources and is suitable for microprocessors of mainstream architecture. It traverses and polls the entire stack variable storage space to avoid missed detection.
It implements simple and reliable stack usage detection, has strong applicability and is suitable for microprocessors of mainstream architecture. No additional hardware is required, ensuring fast processing speed and avoiding missed detection when stack overflow occurs.
Smart Images

Figure CN118550790A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of electric meter equipment in the electric power grid industry, and more specifically to an electric meter stack usage rate detection method and equipment. Background Art
[0002] The electric energy meter is an instrument used to measure and meter the consumption of electric energy. It can accurately measure the amount of electric energy used. At present, the traditional electromagnetic electric energy meter is gradually being replaced by the smart electric energy meter. Compared with the electromagnetic electric energy meter, the smart electric energy meter uses a microprocessor to collect the user's current and voltage in real time, and analyzes and processes it through the processor to realize the calculation of forward and reverse, peak and valley or four-quadrant electric energy, which makes the collection of electric energy more accurate and the analysis of power grid quality more convenient.
[0003] The data generated during the operation of the electric energy meter is stored in the stack. The stack is a group of structures with the same data type and has a certain capacity limit. When the stored data exceeds the capacity limit, that is, the stack usage rate is too high, a stack overflow will occur, causing abnormal meter data and serious consequences.
[0004] Existing electricity meters generally use the following scheme to detect stack usage: (1) preset a string of fixed flags at the bottom of the stack and detect in real time whether the fixed flags have been modified. If modification is detected, the operation is stopped; (2) set the end of the stack to the memory protection unit area. Once the stack pointer accesses this area, an access exception will be triggered, thereby interrupting the program.
[0005] The above-mentioned solution for detecting stack usage has at least the following three shortcomings, in other words, which are the technical problems to be solved by the present invention: 1. Real-time monitoring consumes too much processor resources. Once a serious stack overflow occurs, it cannot be processed in time, and the processor becomes stuck and cannot be operated, and monitoring cannot continue; 2. Local variables generated during program execution will directly skip the preset monitoring or protection area, which may lead to the risk of missed detection; 3. There are few types of memory protection units that support stack detection and cannot be adapted to most electric meter processors.
[0006] In summary, a stack usage detection solution that can be implemented by a pure computer program without additional hardware and with simple principles and steps is urgently needed to address the deficiencies of the prior art. Summary of the invention
[0007] The present invention provides a method and device for detecting the usage rate of an electric meter stack, which, through a pure computer program solution, achieves the following: 1. The stack usage rate is detected at the end of each cycle, without the need to monitor the stack status in real time, with simple principles and steps, less processor resources occupied, and fast processing speed; 2. No additional hardware is required, and the detection function is realized by a pure computer program, which has strong applicability and can be used for any microprocessor of mainstream architecture, and is relatively easy to implement and promote; 3. The variable storage space of the entire stack is traversed and polled, and no detection is missed.
[0008] The specific technical solutions adopted by the present invention to solve the above technical problems are as follows: In a first aspect, an embodiment of the present specification provides a method for obtaining the usage rate of an electric meter stack, wherein the stack is used to store task data of the electric meter when executing a main loop task, and the stack includes a plurality of memory units for storing the task data pointing from the bottom of the stack to the top of the stack, and a top pointer for marking the position of the top of the stack; the task data enters and exits the stack through the top of the stack in a last-in-first-out manner.
[0009] The method includes: S1. offset the stack top pointer toward the stack bottom by one or more memory units to divide the storage space in the stack into a reserved storage space and a main loop variable storage space, wherein the reserved storage space includes a plurality of memory units from the address pointed to by the stack top pointer to the stack top, and the main loop variable storage space includes a plurality of memory units from the stack bottom to the address pointed to by the stack top pointer; S2. When the main loop starts, the initial mark value is written to all memory cells of the main loop variable storage space; S3. When the main loop ends, poll the stored data in the main loop variable storage space to find the latest updated memory unit address as the offset address; S4. Based on the offset size of the offset address and the size of the main loop variable storage space, obtain the stack usage rate of the electric meter.
[0010] Further as a preferred solution, the reserved storage space is used to store key local variables generated during the main cycle task to ensure the normal operation of the main cycle task.
[0011] As a further preferred solution, each time the electric meter enters the main cycle task, the operation of writing the initial mark value is executed.
[0012] As a further preferred solution, the latest updated data to be found is data that is different from the initial mark value, but whose adjacent data is equal to the initial mark value.
[0013] As a further preferred solution, the stack usage rate of the electric meter is the ratio of the offset size of the offset address to the size of the main loop variable storage space.
[0014] According to a second aspect of an embodiment of the present application, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the method steps provided in the first aspect or in any optional manner of the first aspect are implemented.
[0015] According to a third aspect of the embodiments of the present application, there is also provided an electronic device, including: One or more processors, and a memory associated with the one or more processors, the memory being used to store program instructions, and the program instructions, when read and executed by the one or more processors, execute the method steps provided in the above-mentioned first aspect or in any optional manner of the first aspect.
[0016] The main beneficial effects of the above technical solution are: The stack usage rate is detected at the end of each cycle. The principle and steps are simple and will not miss any detection. The detection is reliable while ensuring the processing speed. It has strong applicability and is suitable for microprocessors with mainstream architectures. It is easy to implement. No additional hardware is required and it can be implemented purely by computer software.
[0017] Further or more detailed beneficial effects will be described in detail in conjunction with specific examples in the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The present invention will be further described below in conjunction with the accompanying drawings: Figure 1 The figure is a flow chart of the method steps of the present invention. DETAILED DESCRIPTION
[0019] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the specific implementation modes of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the implementation modes of the present invention.
[0020] Example 1 A method for obtaining the usage rate of an electric meter stack, wherein the stack is used to store task data of the electric meter when executing a main cycle task, and the stack includes a plurality of memory units for storing the task data pointing from the bottom of the stack to the top of the stack, and a top pointer for marking the position of the top of the stack; the task data enters and exits the stack through the top of the stack in a last-in-first-out manner.
[0021] Specifically, the smart meter in this embodiment includes a microprocessor, a memory, etc., which can measure and calculate the amount of electricity consumed and other parameters, and can transmit the analyzed and processed data to the outside. The meter microprocessor is usually set to execute a main task that is continuously cyclical, so as to continuously record and analyze the electricity consumption. The data acquired and analyzed during the execution of the main task is stored in a data stack, which is a data structure of a group of the same data type. The stack includes a fixed stack bottom and a stack top for data entry and exit. The stack top position is marked by a stack top pointer. There are multiple memory units for storage between the two. Task data enters and exits the stack through the stack top in a first-out, last-in manner. In this embodiment, the meter microprocessor uses an ICF (Linker configuration file link control) file to control the position and movement of the stack top pointer.
[0022] (1) Step 1 of the method of the present invention: before the main loop starts, the stack top pointer is offset toward the stack bottom by one or more memory units.
[0023] Specifically, the storage space in the stack is divided into two parts with the offset stack top pointer as the boundary: the address pointed to by the offset stack top pointer to the address pointed to by the original stack top, and the multiple memory units between the two are reserved storage space; the multiple memory units between the fixed stack bottom and the address pointed to by the stack top pointer are the main loop variable storage space.
[0024] (2) Step 2 of the method of the present invention: When the main loop starts, the initial mark value is written to all memory cells of the main loop variable storage space. That is to say, once the main loop task starts, the memory space from the offset stack top pointer to the stack bottom is filled with the same initial mark value by the program method of the present invention. If the value on the memory cell is the initial mark value, it means that the memory cell still maintains the initial state before the task starts in this main task cycle, and the memory space is not used. In some embodiments, the initial mark value can be selected as 0XFF. In other embodiments, other extremely uncommon values can also be selected as mark values.
[0025] Furthermore, the main task of the electric meter is a continuous cycle process. Whenever a cycle is restarted, the program method of the present invention will execute the operation of writing the initial mark value, that is, all the data in the main loop variable storage space will be initialized again. Once the task main loop is entered, this operation is performed. At this time, the main task has not started to run. Initializing the main loop variable storage space will not affect the operation of the main loop, and the electric meter will not generate program operation errors. In addition, each loop is reinitialized, aiming to detect the stack usage rate for each loop to ensure that multiple loops are not detected or stack overflow has occurred but is not discovered and processed in time.
[0026] Furthermore, the reserved storage space does not perform the operation of writing the initial mark value, and the data in the reserved storage space will not be cleared or manually changed in all main task loops. The reserved storage space is used for key local variables generated during the execution of the main task. The key local variables are key data for the normal operation of the main task loop of the electric meter, such as the flag variable for whether the main loop continues to execute, the identifier of the function in the main loop, etc. In order for the electric meter to normally complete the set main loop task, the reserved storage space is not affected by the initialization operation of the embodiment of the present invention in each loop.
[0027] In addition, the main loop variable storage space is used for other local variables relative to the key local variables generated during the execution of the main loop. These local variables only act on the currently executed task. Whenever the task execution ends, the stack in the storage space is released, and the initialization operation of the main loop variable storage space in the next loop will not affect the continued operation of the main loop.
[0028] (3) Step 3 of the method of the present invention: When the main loop ends, poll the stored data in the main loop variable storage space to find the most recently updated memory unit address as the offset address.
[0029] Specifically, when a task is executed, if a memory cell of the stack is used, the value of the memory cell will change. The program of the present invention searches the stored data in the main loop variable storage space in sequence to find the latest updated memory cell, that is, the value of the memory cell has changed and is different from the initial mark value, but the memory cell adjacent to the memory cell is still the initial mark. Due to the nature of the stack, the storage of data by the main task of the electric meter is linear and orderly. If the adjacent memory cell is the initial mark value, then the memory cell whose value has changed must be the last unit to change, that is, the use of the stack memory cell by this task stops here. The address of the latest updated memory cell is obtained as the offset address. The memory cells corresponding to the addresses before the offset address are all occupied by the task, so the offset size of the offset address is the size of the occupied memory cell.
[0030] Furthermore, due to the nature of the electric meter, it is necessary to monitor the power consumption continuously for a long time, and the analysis results must be accurate and well-founded. To ensure long-term uninterrupted power-on to execute the main cycle task, the execution results need to be accurate and error-free, and to minimize failures. Therefore, it is necessary to ensure that the detection of the stack usage rate in each cycle cannot be omitted. After detecting the stack overflow, the microprocessor needs to have a fast processing speed and respond in time. The embodiment of the present invention adopts a method of traversing the main cycle variable storage space, and the discontinuous large arrays generated in the main cycle can also be searched one by one, without missing any data that may overflow the stack, ensuring the accuracy of the stack detection. In addition, at the end of each main cycle, the polling search work is performed to promptly discover possible overflows, ensuring the timely response of the detection program. Finally, in order to adapt to the long-term continuous working nature of the electric meter, the method of this embodiment only traverses the polling once at the end of a cycle, saving the computing resources of the microprocessor.
[0031] (4) Step 4 of the method of the present invention: After the main loop ends, the stack usage rate of the electric meter is obtained based on the offset size of the offset address and the size of the main loop variable storage space.
[0032] Specifically, after the microprocessor of the electric meter obtains the offset address in the above step, the stack usage rate of the electric meter can be calculated. The stack usage rate of the electric meter is the ratio of the offset size of the offset address to the size of the main loop variable storage space.
[0033] In some embodiments, the main loop program of the electric meter task includes a main task, and the stack usage rate is calculated only once after the task is completed in each loop, and the usage rate is the stack usage rate detection result of this loop.
[0034] In some embodiments, the main loop of the electric meter task includes multiple tasks, such as a first task and a second task. When executing the first task, the main loop variable storage space of the stack is allocated to the first task for use, occupying a portion of the stack; after the first task ends, this portion of the stack is released, and the value of the occupied storage unit has changed from the initial mark value. Then the second task is executed, and the main loop variable storage space of the stack is allocated to the second task for use, which also occupies a portion of the stack and changes the values of some memory units; the memory units that are still initially marked may be changed, and the memory units that have changed when executing the first task may also be changed. After the main loop ends, the latest updated memory unit is traversed and queried to obtain its offset address, thereby calculating the stack usage rate of this loop. The obtained stack usage rate is calculated by taking the value of the largest occupied stack size among multiple tasks.
[0035] Example 2 An embodiment of the present invention provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the stack usage detection method provided in Embodiment 1 of the present invention is implemented, for example, and the method includes: Before the main loop starts, the stack top pointer is offset to the bottom of the stack by one or more memory units; When the main loop starts, the initial mark value is written to all memory cells of the main loop variable storage space; When the main loop ends, the stored data in the main loop variable storage space is polled to find the latest updated memory unit address as the offset address; After the main loop ends, the stack usage rate of the electric meter is obtained based on the offset size of the offset address and the size of the main loop variable storage space.
[0036] Example 3 In addition, an embodiment of the present invention provides an electronic device, comprising: one or more processors, and a memory associated with the one or more processors, wherein the memory is used to store program instructions, and when the program instructions are read and executed by the one or more processors, the stack usage detection method and steps provided in Example 1 are executed.
[0037] The beneficial effects that this embodiment may produce include: 1. The stack usage rate is detected at the end of each main task cycle of the electric meter. Unlike previous solutions that require real-time monitoring of the stack status, this embodiment can detect the usage rate of the entire task process at a specific node. The principle and steps are simple, occupy less processor resources, and have a fast processing speed.
[0038] 2. It has strong applicability and uses computer software. It can be used for any microprocessor with mainstream architecture. There is no need to install other detection structures or registers and other hardware, which controls costs and is easier to implement and promote.
[0039] 3. The entire main loop variable storage space is traversed and polled. When the local variables generated by the main task are discontinuous, they can also be detected, avoiding missed detection when the stack overflows, and the meter works more reliably.
[0040] The above is only a preferred embodiment of the present invention and does not limit the scope of the present invention. A person of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment method can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The aforementioned storage medium includes: various media that can store program codes, such as ROM and RAM. In the absence of conflict, the technical features in this embodiment and the implementation scheme can be combined arbitrarily.
[0041] Computer program code for performing the operations of the present invention may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0042] It should be understood by those skilled in the art that the above steps of the present invention can be implemented by a general-purpose computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, optionally, they can be implemented by a program code executable by a computer device, so that they can be stored in a storage device and executed by the computing device, or they can be made into individual integrated circuit modules, or multiple 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.
[0043] The embodiments described above are merely preferred embodiments of this specification and are not intended to limit the scope of this specification. Without departing from the design spirit of this specification, various modifications and improvements made to the technical solutions of this specification by ordinary technicians in this field should fall within the scope of protection determined by the claims of this specification.
Claims
1. A method for obtaining the usage rate of an electric meter stack, wherein the stack is used to store task data of the electric meter when executing a main cycle task, and the stack includes a plurality of memory units for storing the task data and a stack top pointer for marking the position of the stack top, from the stack bottom to the stack top; the task data enters and exits the stack through the stack top in a last-in-first-out manner; the method include: The stack top pointer is offset toward the stack bottom by one or more memory units, so as to divide the storage space in the stack into a reserved storage space and a main loop variable storage space, wherein the reserved storage space includes a plurality of memory units from the address pointed to by the stack top pointer to the stack top, and the main loop variable storage space includes a plurality of memory units from the stack bottom to the address pointed to by the stack top pointer; When the main loop starts, the initial mark value is written to all memory cells of the main loop variable storage space; When the main loop ends, the stored data in the main loop variable storage space is polled to find the latest updated memory unit address as the offset address; Based on the offset size of the offset address and the size of the main loop variable storage space, the stack usage rate of the electric meter is obtained.
2. The method according to claim 1, Features: The reserved storage space is used to store key local variables generated during the main cycle task to ensure the normal operation of the main cycle task.
3. The method according to claim 1, further comprising: include: Whenever the meter enters the main loop task, it executes the operation of writing the initial tag value.
4. The method according to claim 1, Features: The latest updated data is different from the initial mark value, but the adjacent data thereof is equal to the data of the initial mark value.
5. The method according to claim 1, Features: The stack usage rate of the electric meter is the ratio of the offset size of the offset address to the size of the main loop variable storage space.
6. A computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method according to any one of claims 1 to 5.
7. An electronic device, include: one or more processors, and A memory associated with the one or more processors, the memory being used to store program instructions, wherein when the program instructions are read and executed by the one or more processors, the steps of the method according to any one of claims 1 to 5 are executed.
