Lightweight upgrading method for electric energy meter
By obtaining the upgrade plan in the power meter, determining the target address and performing the upgrade operation, the problem of large amount of data during the power meter upgrade is solved, and efficient and lightweight upgrades are achieved.
Patent Information
- Application Number
- CN202411986144.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-31
- Publication Date
- 2025-05-13
AI Technical Summary
In the prior art, the amount of upgrade data during the upgrade of the power meter is large, resulting in an increase in network pressure and a decrease in success rate. In some cases, existing differential upgrade and modular upgrade methods will also generate a large amount of upgrade data.
By obtaining the upgrade plan of the power meter, reading each upgrade item in sequence, determining the target address based on the spatial size relationship of the original instruction set and the new instruction set, and performing corresponding upgrade operations at the target address, realizing a lightweight upgrade of the power meter.
Reduces the amount of data required to be transmitted during an upgrade, improves the upgrade efficiency, reduces the network bandwidth usage, and limits the minimum unit of the upgrade to one byte.
Smart Images

Figure CN119987822A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of electric energy meters, and in particular relates to a lightweight upgrading method for electric energy meters. Background Art
[0002] With the rapid development of smart grids, electric energy meter equipment has become an indispensable and important part of the power distribution network. However, the electric energy meter equipment is deployed at the end of the network and the number is huge, which brings great challenges to the remote upgrade management of the equipment software. The traditional complete upgrade method has a large amount of upgrade package data, which leads to a sharp increase in upstream and downstream network pressure and a significant decrease in the upgrade success rate. In order to cope with network pressure, the existing technology adopts a batch upgrade method, but this method will take longer to complete the upgrade of all meters and is inefficient. For electric energy meters, the construction of smart grids is relatively mature and stable. The feasibility of increasing the success rate and efficiency of upgrades by increasing bandwidth or changing the transmission method is low. Therefore, the upgrade efficiency can be improved by reducing the amount of data required to be transmitted for each upgrade.
[0003] For example, in the prior art, a differential upgrade scheme is used to compare different versions of programs and to perform targeted upgrades on the different parts. Compared with a complete upgrade, this method can reduce the amount of data required to be transmitted during the upgrade. However, when the compiler compilation causes a major change in the program memory layout, the advantage of the differential upgrade is not obvious. For example, a line of code is added to a function, or the size of a global variable is simply modified. The compiler may readjust the code layout during compilation. At this time, a line of code will result in a large amount of differential upgrade data. It can be seen that this method will still generate a large amount of upgrade data when used.
[0004] For example, the "A modular upgrade method and an electric energy meter software system" with the announcement number CN110119281A and the "A modular difference upgrade method and an electric energy meter software system" with the announcement number CN113312078A both divide the internal software of an electric energy meter into modules. The advantage is that the upgrade can be performed according to the modules, which reduces the amount of code for one upgrade. The disadvantage is that the minimum granularity of the upgrade data packet is the size of the module. If the module is too large, the advantage of modular upgrade is lost. If the size of the module is reduced, the number of modules will increase, the division of ROM space will become complicated, maintenance will be difficult, and a large amount of ROM space will be wasted due to alignment problems. Therefore, it is necessary to provide a method with a small amount of data when upgrading an electric energy meter. Summary of the invention
[0005] In view of this, the present invention provides a lightweight upgrade method for an electric energy meter to solve the technical problem of a large amount of upgrade data when upgrading an electric energy meter in the prior art.
[0006] To achieve the above objectives, this application adopts the following scheme: A lightweight upgrade method for an electric energy meter, comprising: Obtaining an upgrade plan for the electric energy meter to be upgraded; wherein the upgrade plan includes at least one upgrade item for upgrading the electric energy meter; each upgrade item includes an upgrade type for upgrading an original instruction set and address information of the original instruction set; the upgrade type includes modifying the instruction set and adding the instruction set, and when the upgrade type is modifying the instruction set or adding the instruction set, the upgrade item also includes a new instruction set to be modified or added; Read each upgrade item in the upgrade plan in turn, and perform the following operations for each upgrade item: According to the address information of the original instruction set corresponding to the current upgrade item, find the space occupied by the original instruction set; Determine the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item; wherein the target address is used to represent the address for adding or modifying the current new instruction set; According to the type of the current upgrade item, a corresponding upgrade operation is performed at the target address.
[0007] Preferably, when the upgrade type of the current upgrade item is to modify the instruction set, determining the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item includes: Determine whether the space occupied by the original instruction set is greater than the space occupied by the current new instruction set corresponding to the current upgrade item; If the space occupied by the original instruction set is not less than the space occupied by the current new instruction set, the address of the original instruction set is determined as the target address; If the space occupied by the original instruction set is smaller than the space occupied by the current new instruction set, the free area in the ROM is queried, and the address of the free area is determined as the target address.
[0008] Preferably, performing a corresponding upgrade operation at the target address includes: If the target address is the address of the original instruction set, the new instruction set is written into the target address, and the redundant bytes not covered by the original instruction set are set as NOP instructions; If the target address is an address of a free area, the new instruction set is written to the target address, and a first jump statement is written at the starting address of the original instruction set, and a second jump statement is written after the new instruction set; wherein the first jump statement is used to jump to the target address, and the second jump statement is used to jump to the next instruction of the original instruction set.
[0009] Preferably, when the upgrade type of the current upgrade item is to add an instruction set, determining the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item includes: According to the space size of the original instruction set, the N instructions before the original instruction set are combined with the original instruction set to form a modified original instruction set; wherein N is an integer greater than or equal to 0, and the value of N satisfies that the modified original instruction set can accommodate a jump statement; Combining the modified original instruction set and the current new instruction set into a modified new instruction set; Determining whether the space occupied by the modified original instruction set is greater than the space occupied by the modified new instruction set; If the space occupied by the modified original instruction set is not greater than the space occupied by the modified new instruction set, determining the address of the modified original instruction set as the target address; If the space occupied by the revised original instruction set is smaller than the space occupied by the revised new instruction set, the free area in the ROM is queried, and the address of the free area is determined as the target address.
[0010] Preferably, performing a corresponding upgrade operation at the target address includes: If the target address is the address of the modified original instruction set, the modified new instruction set is written into the target address, and the redundant bytes not covered in the modified original instruction set are set as NOP instructions; If the target address is the address of the free area, the revised new instruction set is written into the target address, and the third jump statement is written at the starting address of the revised original instruction set, and the fourth jump statement is written after the revised new instruction set; wherein the third jump statement is used to jump to the target address, and the fourth jump statement is used to jump to the next instruction of the revised original instruction set.
[0011] Preferably, if the new instruction set includes new local variables, and the type, quantity or size of the local variables is different from the previous local variables, it further includes: Adjust the stack allocation when the function corresponding to the new local variable is called and the stack release instructions when the function exits.
[0012] Preferably, if a function in the new instruction set changes at least one of the number of function parameters, increases a function return value, or removes a function return value, all call points of the function are adjusted.
[0013] Preferably, if the new instruction set includes a modification of a global variable in the new instruction set, before performing the upgrade operation of modifying the new instruction set, the method further includes: Query the space occupied by the original global variables; Check whether the space occupied by the original global variable is larger than the space occupied by the modified global variable; If the space occupied by the original global variable is not greater than the space occupied by the modified global variable, the storage address of the original global variable in the RAM space is determined as the storage address of the modified global variable; If the space occupied by the original global variable is smaller than the space occupied by the modified global variable, an unused space is selected from the RAM space, and the address of the unused space is determined as the storage address of the modified global variable; For the related instructions that reference the original global variable, the operation address, operation length and operation type are adjusted as needed.
[0014] Preferably, the upgrade type also includes a deletion instruction set; The performing a corresponding upgrade operation at the target address includes: According to the address information of the original instruction set, searching for the original instruction set to be deleted; The ROM address where the original instruction set is located is set to NOP.
[0015] Preferably, the method further comprises: Records the space fragmentation in ROM and RAM generated during the upgrade operation.
[0016] In the above-mentioned lightweight upgrade method for an electric energy meter, the address information of the original instruction set inside the pre-upgraded electric energy meter is stored in the electric energy meter program upgrade system through the upper computer. During the upgrade process of the electric energy meter, this method will read each upgrade item in the upgrade plan in turn, and perform the following operations for each upgrade item: according to the address information of the original instruction set corresponding to the current upgrade item, find the size of the space occupied by the original instruction set, and determine the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item; wherein the target address is used to represent the address for adding or modifying the current new instruction set, and finally, according to the type of the current upgrade item, perform the corresponding upgrade operation at the target address, that is, However, in the above implementation process, the upgrade file constructed by the present application includes the address information of the original instruction set, and the original instruction set that needs to be upgraded during the upgrade is upgraded separately through the address information without affecting the original instruction set that does not need to be upgraded, so that there is no need to upgrade the entire electric energy meter program system, only the part of the original instruction set that needs to be modified needs to be upgraded, and the minimum unit of the upgrade can be limited to one byte. Compared with the upgrade method in the prior art that requires the entire electric energy meter program system to be upgraded, the method provided by the present invention only needs to upgrade the part of the original instruction set that needs to be modified, and the minimum unit of the upgrade can be limited to one byte, which greatly saves the amount of data of the original instruction set to be processed when the meter is upgraded, reduces the upgrade time and bandwidth occupancy, and improves the upgrade efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic diagram of the relocation method of modifying the code to be modified in the instruction set in the present invention.
[0018] Figure 2 Schematic diagram of the address change method of the global variable in the present invention. DETAILED DESCRIPTION
[0019] In order to facilitate the understanding of the present application, the present application will be described more comprehensively below in conjunction with the accompanying drawings. And the preferred implementation of the present application is given. However, the present application can be implemented in many different forms and is not limited to the implementation described herein. On the contrary, the purpose of providing these implementations is to make the disclosure of the present application more thoroughly and comprehensively understood.
[0020] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein in the specification of this application are only for the purpose of describing specific embodiments and are not intended to limit this application. The term "and / or" used herein includes any and all combinations of one or more of the related listed items.
[0021] This embodiment provides a lightweight upgrade method for an electric energy meter, including: Obtaining an upgrade plan for the electric energy meter to be upgraded; wherein the upgrade plan includes at least one upgrade item for upgrading the electric energy meter; each upgrade item includes an upgrade type for upgrading an original instruction set and address information of the original instruction set; the upgrade type includes modifying the instruction set and adding the instruction set, and when the upgrade type is modifying the instruction set or adding the instruction set, the upgrade item also includes a new instruction set to be modified or added; Read each upgrade item in the upgrade plan in turn, and perform the following operations for each upgrade item: According to the address information of the original instruction set corresponding to the current upgrade item, find the space occupied by the original instruction set; Determine the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item; wherein the target address is used to represent the address for adding or modifying the current new instruction set; According to the type of the current upgrade item, a corresponding upgrade operation is performed at the target address.
[0022] In a specific implementation process, first, before the electric energy meter is upgraded, the host computer is connected to the pre-upgraded electric energy meter for communication, and in the electric energy meter upgrade system running in the host computer, according to the running version number of the electric energy meter, the corresponding memory structure information is stored, and the memory structure information specifically includes: the overall space usage of ROM and RAM of each instruction in the pre-upgraded electric energy meter, the starting address and ending address of the used and unused space, the address of each global variable in RAM and the address of the initialization code in ROM and the address referenced by each instruction, as well as the starting address and ending address of each function in ROM; After the new version of the electric energy meter program is released, it is imported into the host computer together with the program memory structure information file (such as the map file generated by Keil). The electric energy meter upgrade system in the host computer compares the program currently running on the electric energy meter and its memory structure information file, and starts to use the upgrade method of this application to build an upgrade plan to form an upgrade plan file. The file content includes the start and end addresses of the original instructions, the size of the new instructions, the write location and other information. Then, the electric energy meter upgrade system issues a command to the pre-upgraded electric energy meter to perform the upgrade operation according to the upgrade plan file. There are only three types of commands issued: delete, modify, and write. After the upgrade of all pre-upgraded electric energy meters is completed, the electric energy meter upgrade system automatically updates the memory structure information file of the current electric energy meter running program according to the upgrade plan file to cope with the next upgrade operation. The upgrade plan includes at least one upgrade item for upgrading the electric energy meter; Each of the above upgrade items includes an upgrade type for upgrading an original instruction set and the address information of the original instruction set, the original instruction set is the instruction set that needs to be modified in this upgrade among the unmodified instruction sets running in the electric energy meter; the upgrade type includes modifying the instruction set and adding the instruction set, and when the upgrade type is modifying the instruction set or adding the instruction set, the upgrade item also includes a new instruction set to be modified or added, and the new instruction set is used to compare the space occupied by the new instruction set with the space occupied by the original instruction set when upgrading the electric energy meter; During the upgrade process of the electric energy meter, this method will read each upgrade item in the upgrade plan in turn, and perform the following operations for each upgrade item: According to the address information of the original instruction set corresponding to the current upgrade item, find the space occupied by the original instruction set; Determine the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item; wherein the target address is used to represent the address for adding or modifying the current new instruction set; Finally, according to the type of the current upgrade item, the corresponding upgrade operation is performed at the target address. In the above implementation process, the upgrade file constructed by the present application includes the address information of the original instruction set, and the original instruction set that needs to be upgraded during the upgrade is upgraded separately through the address information without affecting the original instruction set that does not need to be upgraded. Therefore, there is no need to upgrade the entire electric energy meter program system, only the part of the original instruction set that needs to be modified needs to be upgraded. The minimum unit of the upgrade can be limited to one byte. Compared with the modular upgrade method in the prior art, the method provided by the present invention greatly saves the amount of data of the original instruction set to be processed when the meter is upgraded, reduces the upgrade time and bandwidth occupancy, and improves the upgrade efficiency.
[0023] In this embodiment, the system adopted by the present invention belongs to an embedded and electric energy meter system. The address information of the original instruction set is pre-stored in the electric energy meter program upgrade system of the host computer. When the developer constructs the upgrade code, he uses this as a basis and combines the above method to construct the optimal upgrade plan, and then provides the upgrade plan to the operation and maintenance personnel in the form of an upgrade file in a specified format, for example: an upgrade file in XML format. The operation and maintenance personnel only need to load the upgrade file through the upgrade system to complete the upgrade operation.
[0024] The process of determining the target address is specifically as follows: when the upgrade type of the current upgrade item is to modify the instruction set, determining the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item includes: Determine whether the space occupied by the original instruction set is greater than the space occupied by the current new instruction set corresponding to the current upgrade item; If the space occupied by the original instruction set is not less than the space occupied by the current new instruction set, the address of the original instruction set is determined as the target address; If the space occupied by the original instruction set is smaller than the space occupied by the current new instruction set, the free area in the ROM is queried, and the address of the free area is determined as the target address.
[0025] After the above comparison, the target address of the new instruction set when it is modified is determined. If the space occupied by the new instruction set is smaller than that occupied by the original instruction set, the target address written into the new instruction set is the address of the original instruction set. If the space occupied by the new instruction set is larger than that occupied by the original instruction set, the target address of the new instruction set is determined as the free area in the ROM. This process can realize the target address confirmation when the local instruction set is modified, so that only the original instruction set that needs to be upgraded is modified during the upgrade, and other original instruction sets that do not need to be modified in this upgrade file are not affected.
[0026] The upgrade operation process of modifying the instruction set for the target address is specifically as follows: performing the corresponding upgrade operation at the target address includes: If the target address is the address of the original instruction set, the new instruction set is written into the target address, and the redundant bytes not covered by the original instruction set are set as NOP instructions; If the target address is an address of a free area, the new instruction set is written to the target address, and a first jump statement is written at the starting address of the original instruction set, and a second jump statement is written after the new instruction set; wherein the first jump statement is used to jump to the target address, and the second jump statement is used to jump to the next instruction of the original instruction set.
[0027] Through the above-mentioned upgrade operation, when the space occupied by an original instruction set that needs to be upgraded is smaller than the space occupied by the current new instruction set, and the free area is determined as the target address for writing, it is achieved that when the upgraded program runs to the instruction set, the original instruction set that has not been overwritten (modified) is skipped, and the new instruction set of the item after the upgrade is jumped. The program of the electric energy meter is upgraded by this upgrade method, which avoids the failure of the original instruction set still running due to the original instruction set not being overwritten (modified), and the second jump statement is written after the new instruction set, so that the program can normally jump to the next instruction of the original instruction set after running the new instruction set.
[0028] For example: when the upgrade plan only needs to modify the instruction set, the N instructions in the running of the electric energy meter program upgrade system are the original instruction set, and the initial address and the end address of the original instruction set are confirmed, for example: the binary code corresponding to the assembly instruction of the original instruction set and the occupied space size are: 0x000000E5~0x000000EC occupying 6 bytes, and the M instructions that need to be modified are obtained as the new instruction set, for example: the binary code corresponding to the assembly instruction generated by the new instruction set and the occupied space size are: 5 bytes, then the write address of the M instructions is the write address of the N instructions, and the 1 byte not covered by the new instruction set is set as the NOP instruction; Please see Figure 1 , the original instruction set used is the same as the original instruction set in the above example, the binary code corresponding to the assembly instruction generated by the new instruction set and the occupied space size are: 18 bytes. At this time, due to insufficient space at 0x000000E5, a free address 0x00007FC1 is selected to store the code, and a jump instruction is written at the original 0x000000E5 to jump to 0x00007FC1 for execution, and a jump instruction is written at 0x00007FD4 to return to 0x000000EC for continued execution. It should be noted that: depending on the different write addresses of the new instruction set, the relative address used in the instruction may change, and the relative address value referenced in the new instruction set needs to be adjusted to the correct address.
[0029] The target address confirmation process for adding the instruction set operation is specifically as follows: when the upgrade type of the current upgrade item is to add the instruction set, determining the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item includes: According to the space size of the original instruction set, the N instructions before the original instruction set are combined with the original instruction set to form a modified original instruction set; wherein N is an integer greater than or equal to 0, and the value of N satisfies that the modified original instruction set can accommodate a jump statement; Combining the modified original instruction set and the current new instruction set into a modified new instruction set; Determining whether the space occupied by the modified original instruction set is greater than the space occupied by the modified new instruction set; If the space occupied by the modified original instruction set is not greater than the space occupied by the modified new instruction set, determining the address of the modified original instruction set as the target address; If the space occupied by the revised original instruction set is smaller than the space occupied by the revised new instruction set, the free area in the ROM is queried, and the address of the free area is determined as the target address.
[0030] Specifically, in the process of confirming the target address of the operation of adding an instruction set, after the above comparison, the target address when the new instruction set is added is determined. If the space occupied by the revised new instruction set is smaller than the space occupied by the revised original instruction set, then when the new instruction set is added, the target address written by the revised new instruction set is determined to be the address of the revised original instruction set. If the space occupied by the revised new instruction set is larger than the space occupied by the revised original instruction set, the target address of the revised new instruction set is determined to be the free area in the ROM. Through this process, the target address confirmation when the local instruction set is modified can be realized, so that only the original instruction set that needs to be upgraded is modified during the upgrade, and other original instruction sets that do not need to be modified in this upgrade file are not affected.
[0031] The performing a corresponding upgrade operation at the target address includes: If the target address is the address of the modified original instruction set, the modified new instruction set is written into the target address, and the redundant bytes not covered in the modified original instruction set are set as NOP instructions; If the target address is the address of the free area, the revised new instruction set is written into the target address, and the third jump statement is written at the starting address of the revised original instruction set, and the fourth jump statement is written after the revised new instruction set; wherein the third jump statement is used to jump to the target address, and the fourth jump statement is used to jump to the next instruction of the revised original instruction set.
[0032] Through the above-mentioned upgrade operation, when the space occupied by the revised original instruction set that needs to be upgraded is smaller than the space occupied by the revised new instruction set, and the free area is determined as the target address for writing, it is achieved that when the upgraded program runs to the instruction set, the original instruction set that has not been modified is skipped, and the new instruction set of the upgraded item is jumped. The program of the electric energy meter is upgraded by this upgrade method, which avoids the failure of the original instruction set still running due to the original instruction set not being overwritten (modified), and the second jump statement is written after the new instruction set, so that the program can normally jump to the next instruction of the original instruction set after running the new instruction set.
[0033] For example, when the upgrade plan only needs to add an instruction set, first, obtain the instruction set that needs to be added, and determine the position to add the instruction set, take the first 0 instructions of the added position as the original instruction set, and take the N instructions before the original instruction set and the original instruction set as the revised original instruction set, N is an integer greater than or equal to 0, and the same as the method provided in the above embodiment, record the binary code corresponding to the assembly instructions of the original instruction set and the size of the space occupied; the revised original instruction set and the added new instruction set are combined as the revised new instruction set, and the same as the method provided in the above embodiment, and confirm the binary code corresponding to the assembly instructions generated by the revised new instruction set and the size of the space occupied. It should be noted that: in the above process, the value condition of N is whether the space size of the revised original instruction set can accommodate a jump statement. Then, compare the size of the space occupied by the revised new instruction set with the size of the space occupied by the revised original instruction set. In this example, the space occupied by the revised new instruction set is larger than the space occupied by the revised original instruction set. The write address of the new instruction set needs to be located in the free area in the ROM, and a jump statement is written at the address of the original instruction set to jump to the address of the new instruction set. At the same time, a jump statement is also inserted after the new instruction set to jump back to the next instruction of the original instruction set, and the addition of the instruction set is completed.
[0034] Furthermore, if the new instruction set includes new local variables, and the type, quantity or size of the local variables is different from the previous local variables, it further includes: Adjust the stack allocation when the function corresponding to the new local variable is called and the stack release instructions when the function exits.
[0035] Specifically, if the use of new local variables is added to the new instruction set in the modified instruction set and the added instruction set, the size of the stack space used when the function is called should be expanded. The specific operation is to adjust the stack allocation when the function is called and the stack release instructions when the function exits.
[0036] Furthermore, if a function in the new instruction set changes at least one of the number of function parameters, increases a function return value, or removes a function return value, all call points of the function are adjusted.
[0037] Specifically, if the number of function parameters is changed or the function return value is added or removed, the stack or register of all function call points should be adjusted. The specific adjustment plan is determined according to the function calling convention used by the electric energy meter program.
[0038] Furthermore, if the new instruction set includes a modification of a global variable in the new instruction set, before performing the upgrade operation of modifying the new instruction set, the method further includes: Query the space occupied by the original global variables; Check whether the space occupied by the original global variable is larger than the space occupied by the modified global variable; If the space occupied by the original global variable is not greater than the space occupied by the modified global variable, the storage address of the original global variable in the RAM space is determined as the storage address of the modified global variable; If the space occupied by the original global variable is smaller than the space occupied by the modified global variable, an unused space is selected from the RAM space, and the address of the unused space is determined as the storage address of the modified global variable; For the relevant instructions that reference the original global variable, the operation address, operation length and operation type are adjusted as needed.
[0039] For ease of understanding, the following example is used to illustrate that before modification, that is, the original variable 0x20000100 occupies 2 bytes of space, and after modification, that is, the new variable 0x20000100 occupies 1 byte of space, then the storage address of the new variable in the RAM space does not change; Please see Figure 2 , if before modification, that is, the original global variable 0x20000100 occupies 2 bytes of space, and after modification, that is, the modified global variable 0x20000100 occupies 4 bytes of space, then the storage address of the modified global variable in the RAM space does not change; because directly expanding the variable size at 0x20000100 will directly overwrite subsequent variables, the global variable is adjusted to the free address 0x20000500, and the operation length and operation type of the relevant instructions that reference the modified global variable are adjusted as needed. If the stored RAM address changes, the referenced RAM address must also be adjusted; and the relevant global variable reference instructions are adjusted. The adjustment method can be the modification instruction set, the addition instruction set, and the deletion instruction set. The specific process has been described in the above embodiment and will not be repeated here.
[0040] Furthermore, the upgrade type also includes deleting the instruction set; The performing a corresponding upgrade operation at the target address includes: According to the address information of the original instruction set, searching for the original instruction set to be deleted; The ROM address where the original instruction set is located is set to NOP.
[0041] In this embodiment, when only the instruction set needs to be deleted in the upgrade solution, it is only necessary to determine the deletion instruction set and set the ROM address of the deletion instruction set to NOP.
[0042] The method further includes: recording space fragments generated in the ROM and RAM during the upgrade operation.
[0043] Furthermore, a certain amount of fragmentation occurs in the ROM space and RAM space of the electric energy meter due to the deletion and modification of instructions and global variables. The space of the fragmented part is marked and managed in the upper computer upgrade system and used for the upgrade of other parts, thereby improving the utilization rate of the ROM and RAM space in the electric energy meter program.
[0044] Furthermore, the upgrade is based on BLOCKs, and for the same BLOCK, it is ensured that a single upgrade only requires one erase and write. The modification of the instructions in the same BLOCK is performed once, avoiding frequent erasing of the same ROM during a software upgrade, thereby improving the upgrade efficiency.
[0045] The above description is only a specific implementation mode of the present invention, but the protection scope of the present invention is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or substitutions within the technical scope disclosed by the present invention, and these modifications or substitutions should be included in the protection scope of the present invention.
Claims
1. A lightweight upgrade method for an electric energy meter, characterized in that: include: Obtaining an upgrade plan for the electric energy meter to be upgraded; wherein the upgrade plan includes at least one upgrade item for upgrading the electric energy meter; each upgrade item includes an upgrade type for upgrading an original instruction set and address information of the original instruction set; the upgrade type includes modifying the instruction set and adding the instruction set, and when the upgrade type is modifying the instruction set or adding the instruction set, the upgrade item also includes a new instruction set to be modified or added; Read each upgrade item in the upgrade plan in turn, and perform the following operations for each upgrade item: According to the address information of the original instruction set corresponding to the current upgrade item, find the space occupied by the original instruction set; Determine the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item; wherein the target address is used to represent the address for adding or modifying the current new instruction set; According to the type of the current upgrade item, a corresponding upgrade operation is performed at the target address.
2. The method for lightweight upgrading of electric energy meters according to claim 1, characterized in that: When the upgrade type of the current upgrade item is to modify the instruction set, determining the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item includes: Determine whether the space occupied by the original instruction set is greater than the space occupied by the current new instruction set corresponding to the current upgrade item; If the space occupied by the original instruction set is not greater than the space occupied by the current new instruction set, the address of the original instruction set is determined as the target address; If the space occupied by the original instruction set is smaller than the space occupied by the current new instruction set, the free area in the ROM is queried, and the address of the free area is determined as the target address.
3. The method for lightweight upgrading of electric energy meters according to claim 2, characterized in that: The performing a corresponding upgrade operation at the target address includes: If the target address is the address of the original instruction set, the new instruction set is written into the target address, and the redundant bytes not covered by the original instruction set are set as NOP instructions; If the target address is an address of a free area, the new instruction set is written to the target address, and a first jump statement is written at the starting address of the original instruction set, and a second jump statement is written after the new instruction set; wherein the first jump statement is used to jump to the target address, and the second jump statement is used to jump to the next instruction of the original instruction set.
4. The method for lightweight upgrading of electric energy meters according to claim 1, characterized in that: When the upgrade type of the current upgrade item is to add an instruction set, determining the target address of the current new instruction set according to the size relationship between the space occupied by the original instruction set and the space occupied by the current new instruction set corresponding to the current upgrade item includes: According to the space size of the original instruction set, the N instructions before the original instruction set are combined with the original instruction set to form a modified original instruction set; wherein N is an integer greater than or equal to 0, and the value of N satisfies that the modified original instruction set can accommodate a jump statement; Combining the modified original instruction set and the current new instruction set into a modified new instruction set; Determining whether the space occupied by the modified original instruction set is greater than the space occupied by the modified new instruction set; If the space occupied by the modified original instruction set is not greater than the space occupied by the modified new instruction set, determining the address of the modified original instruction set as the target address; If the space occupied by the revised original instruction set is smaller than the space occupied by the revised new instruction set, the free area in the ROM is queried, and the address of the free area is determined as the target address.
5. The method for lightweight upgrading of electric energy meters according to claim 4, characterized in that: The performing a corresponding upgrade operation at the target address includes: If the target address is the address of the modified original instruction set, the modified new instruction set is written into the target address, and the redundant bytes not covered in the modified original instruction set are set as NOP instructions; If the target address is the address of the free area, the revised new instruction set is written into the target address, and the third jump statement is written at the starting address of the revised original instruction set, and the fourth jump statement is written after the revised new instruction set; wherein the third jump statement is used to jump to the target address, and the fourth jump statement is used to jump to the next instruction of the revised original instruction set.
6. The method for lightweight upgrading of electric energy meters according to claim 1, characterized in that: If the new instruction set includes new local variables, and the type, quantity or size of the local variables is different from the previous local variables, further comprising: Adjust the stack allocation when the function corresponding to the new local variable is called and the stack release instructions when the function exits.
7. The method for lightweight upgrading of electric energy meters according to claim 1, characterized in that: If a function in the new instruction set changes the number of function parameters, increases a function return value, or removes a function return value, all call points of the function are adjusted.
8. The method for lightweight upgrading of electric energy meters according to claim 1, characterized in that: If the new instruction set includes a modification of a global variable in the new instruction set, before performing the upgrade operation of modifying the new instruction set, the method further includes: Query the space occupied by the original global variables; Check whether the space occupied by the original global variable is larger than the space occupied by the modified global variable; If the space occupied by the original global variable is not greater than the space occupied by the modified global variable, the storage address of the original global variable in the RAM space is determined as the storage address of the modified global variable; If the space occupied by the original global variable is smaller than the space occupied by the modified global variable, an unused space is selected from the RAM space, and the address of the unused space is determined as the storage address of the modified global variable; For the related instructions that reference the original global variable, the operation address, operation length and operation type are adjusted as needed.
9. The method for lightweight upgrading of electric energy meters according to claim 1, characterized in that: The upgrade type also includes a deletion instruction set; The performing a corresponding upgrade operation at the target address includes: According to the address information of the original instruction set, searching for the original instruction set to be deleted; The ROM address where the original instruction set is located is set to NOP.
10. The method for lightweight upgrading of electric energy meters according to any one of claims 1 to 9, characterized in that: The method further comprises: Records the space fragmentation in ROM and RAM generated during the upgrade operation.
Citation Information
Patent Citations
Electric energy meter software modular upgrading method and electric energy meter system
CN110119281A
Electric energy meter software modularization difference upgrading method and electric energy meter system
CN113312078A