Rolling storage method and device of electric energy meter and electronic equipment

By constructing a structure for EEPROM data and using check codes for read and write operations, the problem of EEPROM wear leveling is solved, the rolling storage method of electricity meters is simplified, and the maintenance efficiency and versatility of EEPROM data are improved.

CN115878504BActive Publication Date: 2026-06-16NINGBO SANXING MEDICAL & ELECTRIC CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NINGBO SANXING MEDICAL & ELECTRIC CO LTD
Filing Date
2022-12-29
Publication Date
2026-06-16

Smart Images

  • Figure CN115878504B_ABST
    Figure CN115878504B_ABST
Patent Text Reader

Abstract

The application provides a rolling storage method and device of an electric energy meter and electronic equipment. A first structure is constructed for a plurality of types of EEPROM data divided in advance, and a corresponding storage space in the first structure is applied for each type of EEPROM data and each backup application. Maintenance of the EEPROM data is realized by reading the EEPROM data from the first structure and / or writing the EEPROM data into the first structure. The application can improve the maintenance efficiency of the EEPROM data and the generality of the maintenance of each type of EEPROM data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of electricity meter technology, and in particular to a rolling storage method, apparatus, and electronic device for electricity meters. Background Technology

[0002] EEPROM is an important storage medium for storing electricity in energy meters. Currently, most EEPROMs on the market have an erase / write life of 1 million to 4 million cycles. In production, it is necessary to consider the replacement of different EEPROMs. In order to ensure compatibility, the software is generally designed based on 1 million cycles.

[0003] To ensure the reliability of electricity storage, the industry practice is to store data every 1 kWh, combined with power-off storage and timed storage (e.g., hourly). Considering the current 16-year lifespan of electricity meters, the number of power outages is limited, and the wear and tear on the EEPROM can be ignored. Storing data every hour requires approximately 14 times; storing data every 1 kWh means that the same location can only write 1 million kWh within the 1 million-cycle lifespan of the EEPROM. Taking a meter with a base voltage of 220V and a maximum current of 100A as an example, if the meter operates at the base voltage and maximum current throughout its lifespan under extreme conditions, it will generate approximately 3.08 million kWh of electricity; for a three-phase four-wire meter, it will generate 9.24 million kWh. These figures far exceed the lifespan of the EEPROM.

[0004] To meet the lifespan requirements of EEPROMs, i.e., to consider wear leveling, a common approach is to divide the EEPROM into multiple parts, writing to each part a certain number of times before replacing it with the next part, and so on. Specifically, this involves defining two structures: Structure A stores the addresses of the data to be rolled over, backup addresses, etc.; Structure B stores offset address information (the offset address records the current position of the current part). Depending on the type of data to be rolled over, arrays of Structure A and Structure B are ultimately formed. The drawback of this approach is its unfriendly nature to programmers. Whenever a new type of data is added, corresponding data storage space and offset storage space need to be allocated in the EEPROM, and the Structure A and Structure B arrays need to be maintained simultaneously. These steps are already cumbersome enough, and the purpose of arrays is to increase code reusability, which comes at the cost of requiring the array order to match and the need to pass in the corresponding enumeration or address when using it. Summary of the Invention

[0005] In view of this, the purpose of the present invention is to provide a rolling storage method, apparatus and electronic device for electricity meters to alleviate the above-mentioned problems existing in the prior art.

[0006] In a first aspect, embodiments of the present invention provide a rolling storage method for an electricity meter, the method comprising: constructing a first structure for pre-divided EEPROM data of multiple types; wherein the first structure includes offset information and data information; the offset information includes a first value representing the number of copies to be rolled storage and a first check code corresponding to the first value; the data information includes multiple arrays, the number of arrays being equal to the number of copies to be rolled storage, each array including multiple types of EEPROM data and a backup of each type of EEPROM data; requesting corresponding storage space in the first structure for each type of EEPROM data and each backup; wherein the storage space includes data volume and byte position; and when it is necessary to read data from the first structure... When there is a first current EEPROM data with a first preset data volume, the first value and the first check code corresponding to the first current EEPROM data are obtained from the first structure, and the first current EEPROM data is read from the first structure according to the first value and the first check code corresponding to the first current EEPROM data and the first preset data volume; when it is necessary to write a second current EEPROM data with a second preset data volume into the first structure, the first value and the first check code corresponding to the second current EEPROM data are obtained from the first structure, and the second current EEPROM data is written into the first structure according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data volume.

[0007] Secondly, embodiments of the present invention also provide a rolling storage device for an electricity meter, the device comprising: a construction module, configured to construct a first structure for pre-divided multiple types of EEPROM data; wherein the first structure includes offset information and data information; the offset information includes a first value representing the number of copies to be rolled storage and a first check code corresponding to the first value; the data information includes multiple arrays, the number of arrays being equal to the number of copies to be rolled storage, each array including multiple types of EEPROM data and a backup of each type of EEPROM data; an application module, configured to apply for corresponding storage space in the first structure for each type of EEPROM data and each backup; wherein the storage space includes data volume and byte position; and a reading module, configured to read data from the first structure when needed. When a first current EEPROM data with a first preset data amount is read from the first structure, a first value and a first checksum corresponding to the first current EEPROM data are obtained from the first structure, and the first current EEPROM data is read from the first structure according to the first value, the first checksum, and the first preset data amount; the writing module is used to obtain the first value and the first checksum corresponding to the second current EEPROM data from the first structure when it is necessary to write the second current EEPROM data with a second preset data amount into the first structure, and write the second current EEPROM data into the first structure according to the first value, the first checksum, and the second preset data amount.

[0008] Thirdly, embodiments of the present invention also provide an electronic device, including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the above-described rolling storage method for electricity meters.

[0009] This invention provides a rolling storage method, apparatus, and electronic device for an electricity meter. A first structure (including offset information and data information) is constructed for multiple pre-divided types of EEPROM data, with each type of EEPROM data and each backup application corresponding to a storage space within the first structure. When it is necessary to read first current EEPROM data with a first preset data amount from the first structure, a first value and a first checksum corresponding to the first current EEPROM data are obtained from the first structure, and the first current EEPROM data is read from the first structure according to the first value, the first checksum, and the first preset data amount. When it is necessary to write second current EEPROM data with a second preset data amount into the first structure, a first value and a first checksum corresponding to the second current EEPROM data are obtained from the first structure, and the second current EEPROM data is written into the first structure according to the first value, the first checksum, and the second preset data amount. By employing the above technology, EEPROM data maintenance is achieved through reading and / or writing of structures, thereby improving the efficiency of EEPROM data maintenance. Furthermore, since each structure is an independent object, the reading and / or writing methods for different structures are consistent, thus improving the universality of EEPROM data maintenance for various types.

[0010] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.

[0011] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0012] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0013] Figure 1 This is a flowchart illustrating a rolling storage method for an electricity meter according to an embodiment of the present invention.

[0014] Figure 2 This is an example diagram of the first structure in an embodiment of the present invention;

[0015] Figure 3 This is a flowchart illustrating the process of reading EEPROM data from the storage chain in an embodiment of the present invention.

[0016] Figure 4 This is a flowchart illustrating the process of writing EEPROM data into the storage chain in an embodiment of the present invention;

[0017] Figure 5 This is a schematic diagram of the structure of a rolling storage device for an electricity meter according to an embodiment of the present invention;

[0018] Figure 6 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with the embodiments. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0020] Currently, EEPROM is a crucial storage medium for storing electricity in energy meters. To extend the lifespan of the EEPROM, i.e., to consider wear leveling, a common approach is to divide the EEPROM into multiple parts, writing to each part a certain number of times before replacing it with the next part, and so on. Specifically, this involves defining two structures: Structure A stores the addresses of the data to be rolled over, backup addresses, etc.; Structure B stores offset address information (the offset address records the current position of the stored part). Depending on the type of data to be rolled over, arrays of Structure A and Structure B are ultimately formed. The drawback of this approach is its unfriendly nature to programmers. Whenever a new type of data is added, corresponding data storage space and offset storage space need to be allocated in the EEPROM, and the Structure A and Structure B arrays need to be maintained simultaneously. These steps are already cumbersome enough, and the purpose of arrays is to increase code reusability, which comes at the cost of requiring the array order to match and the need to pass in corresponding enumerations or addresses when using them.

[0021] Based on this, the present invention provides a rolling storage method, apparatus and electronic device for electricity meters, which can alleviate the above-mentioned problems existing in the prior art.

[0022] To facilitate understanding of this embodiment, a rolling storage method for an electricity meter disclosed in this embodiment of the invention will first be described in detail. See [link to relevant documentation]. Figure 1 As shown, the method may include the following steps:

[0023] Step S102: Construct a first structure for the pre-divided multiple types of EEPROM data; wherein, the first structure includes offset information and data information; the offset information includes a first value used to characterize the number of copies to be rolled storage and a first check code corresponding to the first value; the data information includes multiple arrays, the number of arrays being equal to the number of copies to be rolled storage, and each array including multiple types of EEPROM data and a backup of each type of EEPROM data.

[0024] The above types can be customized according to actual needs, and there are no restrictions on them.

[0025] Step S104 involves storing the corresponding storage space in the first structure for each type of EEPROM data and each backup request; wherein the storage space includes the amount of data and the byte position.

[0026] Step S106: When it is necessary to read the first current EEPROM data with a first preset data amount from the first structure, obtain the first value and the first check code corresponding to the first current EEPROM data from the first structure, and read the first current EEPROM data from the first structure according to the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount.

[0027] Step S108: When it is necessary to write the second current EEPROM data with a second preset data amount into the first structure, obtain the first value and the first check code corresponding to the second current EEPROM data from the first structure, and write the second current EEPROM data into the first structure according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount.

[0028] This invention provides a rolling storage method for an electricity meter. A first structure (including offset information and data information) is constructed for multiple pre-divided types of EEPROM data, with each type of EEPROM data and each backup application corresponding to a storage space within the first structure. When it is necessary to read first current EEPROM data with a first preset data amount from the first structure, a first value and a first checksum corresponding to the first current EEPROM data are obtained from the first structure, and the first current EEPROM data is read from the first structure according to the first value, the first checksum, and the first preset data amount. When it is necessary to write second current EEPROM data with a second preset data amount into the first structure, a first value and a first checksum corresponding to the second current EEPROM data are obtained from the first structure, and the second current EEPROM data is written into the first structure according to the first value, the first checksum, and the second preset data amount. By employing the above technology, EEPROM data maintenance is achieved through reading and / or writing of structures, thereby improving the efficiency of EEPROM data maintenance. Furthermore, since each structure is an independent object, the reading and / or writing methods for different structures are consistent, thus improving the universality of EEPROM data maintenance for various types.

[0029] As one possible implementation, the step of reading the first current EEPROM data from the first structure based on the first value, the first check code, and the first preset data amount corresponding to the first current EEPROM data may include: (11) determining the first position information in the first structure corresponding to the first current EEPROM data based on the first value, the first check code, and the first preset data amount; wherein, the first position information represents the byte position of the first current EEPROM data in the first structure; (12) reading the first current EEPROM data from the first structure based on the first position information.

[0030] For example, the above (11) can be performed as follows:

[0031] (111) Convert the first value corresponding to the first current EEPROM data into the second check code;

[0032] (112) If the second check code is equal to the first check code corresponding to the first current EEPROM data, then the first position information in the first structure corresponding to the first current EEPROM data is calculated based on the first value corresponding to the first current EEPROM data, the first check code, and the first preset data amount.

[0033] (113) If the second check code is not equal to the first check code corresponding to the first current EEPROM data, the first value corresponding to the first current EEPROM data is set to 0, and the first position information in the first structure corresponding to the first current EEPROM data is calculated based on the first value corresponding to the first current EEPROM data, the first check code, and the first preset data amount.

[0034] For example, each array may also include a third checksum corresponding to each type of EEPROM data and a backup of each type of EEPROM data; the first current EEPROM data may include EEPROM data of the first target type or a backup of the first target type of EEPROM data; based on this, the above (12) can be performed as follows:

[0035] (121) Read the third check code corresponding to the EEPROM data of the first target type from the first structure according to the first position information;

[0036] (122) Convert the first current EEPROM data into the fourth check code;

[0037] (123) If the fourth check code is equal to the third check code corresponding to the EEPROM data of the first target type, then the EEPROM data of the first target type is read from the first structure according to the first position information;

[0038] (124) If the fourth check code is not equal to the third check code corresponding to the EEPROM data of the first target type, then the third check code corresponding to the backup of the EEPROM data of the first target type is read from the first structure according to the first position information, and the backup of the EEPROM data of the first target type is converted into the fifth check code.

[0039] (125) If the fifth check code is equal to the third check code corresponding to the EEPROM data of the first target type, then the backup of the EEPROM data of the first target type is read from the first structure according to the first position information.

[0040] As one possible implementation, the step of writing the second current EEPROM data into the first structure according to the first value, the first check code, and the second preset data amount corresponding to the second current EEPROM data may include: (21) determining the second position information in the first structure corresponding to the second current EEPROM data according to the first value, the first check code, and the second preset data amount; wherein, the second position information represents the byte position of the second current EEPROM data in the first structure; (22) writing the second current EEPROM data into the first structure according to the second position information.

[0041] For example, the aforementioned second current EEPROM data may include EEPROM data of the second target type or a backup of EEPROM data of the second target type; based on this, after the aforementioned step of obtaining the first value and the first check code corresponding to the second current EEPROM data from the first structure, the aforementioned rolling storage method of the energy meter may further include: starting to count by a preset rolling counter; wherein, the initial count value of the rolling counter is 0.

[0042] Based on this, the above (21) can be carried out in the following manner:

[0043] (211) Convert the first value corresponding to the second current EEPROM data into the sixth check code;

[0044] (212) If the sixth check code is equal to the first check code corresponding to the second current EEPROM data, then increment the current count value of the rollover counter by 1;

[0045] (213) If the sixth check code is not equal to the first check code corresponding to the second current EEPROM data, then set the first value corresponding to the second current EEPROM data to 0 and increment the current count value of the rollover counter by 1.

[0046] (214) If the count value of the roll-over counter is greater than the number of copies to be rolled over, then the first value corresponding to the second current EEPROM data is incremented by 1 to obtain the corresponding second value; if the second value corresponding to the second current EEPROM data is not greater than the number of copies to be rolled over, then the second position information corresponding to the second current EEPROM data in the first structure is calculated based on the second value corresponding to the second current EEPROM data, the first check code, and the second preset data amount; if the second value corresponding to the second current EEPROM data is greater than the number of copies to be rolled over, then the second value corresponding to the second current EEPROM data is set to 0, and the second position information corresponding to the second current EEPROM data in the first structure is calculated based on the second value corresponding to the second current EEPROM data, the first check code, and the second preset data amount.

[0047] (215) If the count value of the roll-over counter is not greater than the number of copies to be rolled over, the second position information in the first structure corresponding to the second current EEPROM data is calculated based on the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount.

[0048] For example, the above (22) can be performed as follows:

[0049] (221) Determine the target storage space in the first structure based on the second location information;

[0050] (222) Write the second current EEPROM data to the target storage space.

[0051] Based on (221) and (222) above, the above-mentioned rolling storage method for electricity meters may further include: converting the first or second value used to calculate the second position information into a seventh check code; converting the second current EEPROM data into an eighth check code; and writing the seventh check code and the eighth check code into the target storage space.

[0052] To facilitate understanding of the above-mentioned rolling storage method for electricity meters, a specific example is provided below to illustrate the rolling storage method for electricity meters:

[0053] The above-mentioned rolling storage method for electricity meters can be carried out according to the following steps:

[0054] Step 1: Pre-divide the EEPROM data into multiple types (i.e., multiple data types), and define a structure (i.e. the first structure mentioned above) for all types of EEPROM data. This structure includes offset information and data information.

[0055] See Figure 2 As shown, the offset information includes offset (i.e., the first value) and crc1 (i.e., the first checksum). offset occupies 1 byte, and crc1 occupies 2 bytes. offset is the offset of the current number of rollover copies. For example, if 5 rollover copies are needed (simply referred to as "rollover"), then the value of offset varies between 0 and 4. The data information is an array, and the number of array elements is the number of rollover copies (i.e., the number of copies to be rolled over). Figure 2 The array contains rollover 0, rollover 1, rollover..., and each member of the array includes data (the length of data is determined by the specific data type) and crc2 (2 bytes). crc1 and crc2 both use the CRC-16-CCITT algorithm. During storage, the crc1 of the offset and the crc2 of the data are calculated respectively, and crc1 and crc2 are saved to EEPROM.

[0056] Step 2: For each type of EEPROM data, allocate two EEPROM spaces in the EEPROM for that type of EEPROM data. One space is used to store the EEPROM data of that type itself, and the other space is used to store a backup of the EEPROM data of that type.

[0057] Specifically, the allocation of EEPROM space can be accomplished using a pre-written EEPROM space allocation macro. An example of pseudocode for the EEPROM space allocation macro definition is as follows:

[0058]

[0059] Where Type represents the data type of data, and num represents the number of rollover copies.

[0060] You can define an EEPROM_Map structure and define member variables in the structure using the data types from step 1 above.

[0061] For example Figure 2 There are two types of data that need to be stored, with corresponding data types struct A and struct B. The following variables are defined in EEPROM_Map: struct A a, struct A aBak, struct B b, and struct B bBak.

[0062] The position of a structure member can be obtained using offsetof in C language, and the size of a structure member can be obtained using sizeof. With the position and size, members can be read and written. At this point, the EEPROM space allocation for EEPROM data is completed.

[0063] Step 3, define the storage chain.

[0064] Specifically, memory chains can be defined using pre-written memory chain definition macros. An example of the pseudocode for a memory chain definition macro is as follows:

[0065]

[0066]

[0067] When defining a storage chain, the following needs to be defined:

[0068] (1) size, 4 bytes, the size of a rollover data.

[0069] (2) addr, 4 bytes, the starting address (i.e. the starting byte position) of the first EEPROM space.

[0070] (3) addrBak, 4 bytes, the starting address (i.e. the starting byte position) of the second EEPROM space.

[0071] (4) *pCount, a pointer to a 1-byte RAM variable, i.e., the rollover counter.

[0072] (5)regionNum, 1 byte, the number of copies to be rolled over.

[0073] (6) The `read` function reads data from the memory chain. When reading data, it first reads the offset and then finds the corresponding EEPROM address. For example, if the data size is `dataLen` (bytes) and n copies need to be rolled over, then the current EEPROM address is 3 (the size of offset and crc1) + n * `dataLen`. Finally, based on the calculated EEPROM address, it reads the EEPROM data and returns the EEPROM data content.

[0074] (7) The `write` function implements the writing of the memory chain. When writing data, the offset is read first. The initial count value of the rollover counter *pCount is 0. Each time data is written, pCount is incremented by 1. The pCount obtained after incrementing is compared with the number of rollover copies, regionNum. If it is greater than the number of rollover copies, the offset is incremented by 1 (i.e., data is written to the next rollover copy). When the offset is greater than regionNum, the offset is set to 0 (indicating returning to the first rollover copy, thus completing a full rollover cycle). The EEPROM address corresponding to the current data is calculated based on the offset (the calculation method is the same as the `read` function). Finally, the crc1 of the offset and the crc2 of the data are calculated, and the two EEPROM copies are written to the memory space respectively.

[0075] To facilitate the definition of chained variables, the following macros can be used:

[0076]

[0077] Here, `allocation` represents the variable that allocates EEPROM space as defined in `EEPROM_Map`, and `allocationBk` represents the backup of the variable that allocates EEPROM space as defined in `EEPROM_Map`. For example... Figure 2 Data a and its backup aBak can be stored in a storage chain EEPROMRollStorage_CTOR(a, aBak)aStorage. When data a needs to be read from or written to this storage chain, aStorage.read and aStorage.write can be called respectively.

[0078] For example, see Figure 3 As shown, the process of reading EEPROM data from the memory chain can include:

[0079] Step 301: Read the offset and crc1 from the first EEPROM (i.e., EEPROM data a of the current required type).

[0080] Step 302: Use the CRC-16-CCITT algorithm to convert the offset into CRC (denoted as the first CRC), and determine whether the first CRC is consistent with CRC1.

[0081] If the first CRC is consistent with CRC1, then proceed to step 303; if the first CRC is inconsistent with CRC1, then proceed to steps 304 and 305.

[0082] Step 303: Calculate the EEPROM address addr1 corresponding to the current data (i.e., EEPROM data a) = aAddr + 3 + offset * (dataLen + crc2Len), or calculate the EEPROM address addr2 corresponding to the backup of the current data (i.e., the backup aBak of EEPROM data a) = aBakAddr + 3 + offset * (dataLen + crc2Len); where dataLen is the size of data (i.e., the number of bytes occupied), and crc2Len is the size of crc2 (i.e., the number of bytes occupied).

[0083] Step 304: Read the offset and crc1 from the second EEPROM (i.e., the backup aBak of EEPROM data a).

[0084] Step 305: Use the CRC-16-CCITT algorithm to convert the offset into a CRC (denoted as the second CRC), and determine whether the second CRC is consistent with CRC1.

[0085] If the second CRC is consistent with CRC1, then proceed to step 303; if the second CRC is inconsistent with CRC1, then proceed to step 306, and then proceed to step 303 after completing step 306.

[0086] Step 306: Set the offset to 0.

[0087] After completing step 303, proceed to step 307.

[0088] Step 307: Read the data and crc2 of the first EEPROM.

[0089] Step 308: Use the CRC-16-CCITT algorithm to convert the data into CRC (denoted as the third CRC), and determine whether the third CRC is consistent with CRC2.

[0090] If the third CRC is consistent with CRC2, then proceed to step 309 and end the process; if the third CRC is inconsistent with CRC2, then proceed to steps 310 and 311.

[0091] Step 309, return data.

[0092] Step 310: Read the data and crc2 of the second EEPROM.

[0093] Step 311: Use the CRC-16-CCITT algorithm to convert the data into CRC (denoted as the fourth CRC), and determine whether the fourth CRC is consistent with CRC2.

[0094] If the fourth CRC is consistent with CRC2, then proceed to step 309 and end the process; if the fourth CRC is inconsistent with CRC2, then end the process.

[0095] For example, see Figure 4 As shown, the process of writing EEPROM data into the memory chain can include:

[0096] Step 401: Read the offset and crc1 from the first EEPROM (i.e., EEPROM data a of the current required type).

[0097] Step 402: Use the CRC-16-CCITT algorithm to convert the offset into a CRC (denoted as the fifth CRC), and determine whether the fifth CRC is consistent with CRC1.

[0098] If the fifth CRC matches CRC1, proceed to step 403; if the fifth CRC does not match CRC1, proceed to steps 404 and 405.

[0099] Step 403: Increment the count value of the rollover counter by 1.

[0100] Step 404: Read the offset and crc1 from the second EEPROM (i.e., the backup aBak of EEPROM data a).

[0101] Step 405: Use the CRC-16-CCITT algorithm to convert the offset into a CRC (denoted as the sixth CRC), and determine whether the sixth CRC is consistent with CRC1.

[0102] If the sixth CRC matches CRC1, then proceed to step 403; if the sixth CRC does not match CRC1, then proceed to step 406, and then proceed to step 403 after completing step 406.

[0103] Step 406: Set the offset to 0.

[0104] After completing step 403, proceed to step 407.

[0105] Step 407: Determine whether the count value of the rollover counter is greater than the number of rollover units.

[0106] If the count value of the rollover counter is not greater than the number of rollover units, proceed to step 408; if the count value of the rollover counter is greater than the number of rollover units, proceed to steps 409 and 410.

[0107] Step 408: Calculate the EEPROM address addr1 corresponding to the current data (i.e., EEPROM data a) = aAddr + 3 + offset * (dataLen + crc2Len), or calculate the EEPROM address addr2 corresponding to the backup of the current data (i.e., the backup aBak of EEPROM data a) = aBakAddr + 3 + offset * (dataLen + crc2Len); where dataLen is the size of data (i.e., the number of bytes occupied), and crc2Len is the size of crc2 (i.e., the number of bytes occupied).

[0108] Step 409, increment offset by 1.

[0109] Step 410: Determine if the offset is greater than the number of rollover copies.

[0110] If the offset is greater than the number of rollover copies, then proceed to step 411, and then proceed to step 408 after step 411 is completed; if the offset is not greater than the number of rollover copies, then proceed to step 408.

[0111] Step 411: Set the offset to 0.

[0112] After completing step 408, proceed to step 412, and then the process ends.

[0113] Step 412: Use the CRC-16-CCITT algorithm to convert the offset into CRC1, use the CRC-16-CCITT algorithm to convert the data in the first or second EEPROM into CRC2, and write the first or second EEPROM into the corresponding EEPROM address in the memory chain.

[0114] The aforementioned rolling storage method for electricity meters offers the following advantages: It is simple to operate; compared to traditional methods, this method encapsulates offset and data information together, with the offset information maintained internally by the read and write interfaces, eliminating the need for upper-layer application management of offset information during rolling storage. It is also easy to maintain; each storage chain is an independent object, and these objects have consistent read and write methods. This improves code reusability and eliminates the need to map arrays to enumerations or addresses.

[0115] Based on the above-described rolling storage method for electricity meters, this embodiment of the invention also provides a rolling storage device for electricity meters, see [link to relevant documentation]. Figure 5 As shown, the device may include the following modules:

[0116] The construction module 502 can be used to construct a first structure for pre-divided EEPROM data of multiple types; wherein, the first structure includes offset information and data information; the offset information includes a first value for representing the number of copies to be rolled over and a first check code corresponding to the first value; the data information includes multiple arrays, the number of arrays being equal to the number of copies to be rolled over, and each array includes multiple types of EEPROM data and a backup of each type of EEPROM data.

[0117] The application module 504 can be used to provide storage space in the first structure corresponding to each type of EEPROM data and each backup application; wherein the storage space includes data volume and byte position.

[0118] The reading module 506 can be used to obtain the first value and the first check code corresponding to the first current EEPROM data from the first structure when it is necessary to read the first current EEPROM data with a first preset data amount from the first structure, and read the first current EEPROM data from the first structure according to the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount.

[0119] The writing module 508 can be used to obtain the first value and the first check code corresponding to the second current EEPROM data from the first structure when it is necessary to write the second current EEPROM data with the second preset data amount into the first structure, and write the second current EEPROM data into the first structure according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount.

[0120] This invention provides a rolling storage device for an electricity meter. A first structure (including offset information and data information) is constructed for multiple pre-divided types of EEPROM data. Each type of EEPROM data and each backup request corresponds to a storage space within the first structure. When it is necessary to read first current EEPROM data with a first preset data amount from the first structure, a first value and a first checksum corresponding to the first current EEPROM data are obtained from the first structure, and the first current EEPROM data is read from the first structure according to the first value, the first checksum, and the first preset data amount. When it is necessary to write second current EEPROM data with a second preset data amount into the first structure, a first value and a first checksum corresponding to the second current EEPROM data are obtained from the first structure, and the second current EEPROM data is written into the first structure according to the first value, the first checksum, and the second preset data amount. By employing the above technology, EEPROM data maintenance is achieved through reading and / or writing of structures, thereby improving the efficiency of EEPROM data maintenance. Furthermore, since each structure is an independent object, the reading and / or writing methods for different structures are consistent, thus improving the universality of EEPROM data maintenance for various types.

[0121] The above-mentioned reading module 506 can also be used to: determine the first position information in the first structure corresponding to the first current EEPROM data based on the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount; wherein, the first position information represents the byte position of the first current EEPROM data in the first structure; and read the first current EEPROM data from the first structure based on the first position information.

[0122] The aforementioned reading module 506 can also be used to: convert the first value corresponding to the first current EEPROM data into a second check code; if the second check code is equal to the first check code corresponding to the first current EEPROM data, then calculate the first position information of the first current EEPROM data in the first structure based on the first value corresponding to the first current EEPROM data, the first check code, and the first preset data amount; if the second check code is not equal to the first check code corresponding to the first current EEPROM data, then set the first value corresponding to the first current EEPROM data to 0, and calculate the first position information of the first current EEPROM data in the first structure based on the first value corresponding to the first current EEPROM data, the first check code, and the first preset data amount.

[0123] Each array may further include a third checksum corresponding to each type of EEPROM data and a backup of each type of EEPROM data; the first current EEPROM data includes EEPROM data of the first target type or a backup of the first target type of EEPROM data; based on this, the above-mentioned reading module 506 may also be used to: read the third checksum corresponding to the first target type of EEPROM data from the first structure according to the first position information; convert the first current EEPROM data into a fourth checksum; if the fourth checksum is equal to the third checksum corresponding to the first target type of EEPROM data, then read the first target type of EEPROM data from the first structure according to the first position information; if the fourth checksum is not equal to the third checksum corresponding to the first target type of EEPROM data, then read the third checksum corresponding to the backup of the first target type of EEPROM data from the first structure according to the first position information, and convert the backup of the first target type of EEPROM data into a fifth checksum; if the fifth checksum is equal to the third checksum corresponding to the first target type of EEPROM data, then read the backup of the first target type of EEPROM data from the first structure according to the first position information.

[0124] The above-mentioned writing module 508 can also be used to: determine the second position information in the first structure corresponding to the second current EEPROM data according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount; wherein, the second position information represents the byte position of the second current EEPROM data in the first structure; and write the second current EEPROM data into the first structure according to the second position information.

[0125] The aforementioned second current EEPROM data may include EEPROM data of the second target type or a backup of EEPROM data of the second target type; based on this, the aforementioned writing module 508 may also be used to: after obtaining the first value and the first check code corresponding to the second current EEPROM data from the first structure, start counting through a preset rolling counter; wherein, the initial count value of the rolling counter is 0.

[0126] The aforementioned write module 508 can also be used to: convert the first value corresponding to the second current EEPROM data into a sixth checksum; if the sixth checksum is equal to the first checksum corresponding to the second current EEPROM data, increment the current count value of the rollover counter by 1; if the sixth checksum is not equal to the first checksum corresponding to the second current EEPROM data, set the first value corresponding to the second current EEPROM data to 0 and increment the current count value of the rollover counter by 1; if the count value of the rollover counter is greater than the number of copies to be rolled over, increment the first value corresponding to the second current EEPROM data by 1 to obtain a corresponding second value; if the second value corresponding to the second current EEPROM data is not greater than the number of copies to be rolled over, then based on the second value corresponding to the second current EEPROM data... The second position information corresponding to the second current EEPROM data in the first structure is calculated based on the first checksum and the second preset data amount. If the second value corresponding to the second current EEPROM data is greater than the number of copies to be rolled over, the second value corresponding to the second current EEPROM data is set to 0, and the second position information corresponding to the second current EEPROM data in the first structure is calculated based on the second value corresponding to the second current EEPROM data, the first checksum, and the second preset data amount. If the count value of the rollover counter is not greater than the number of copies to be rolled over, the second position information corresponding to the second current EEPROM data in the first structure is calculated based on the first value corresponding to the second current EEPROM data, the first checksum, and the second preset data amount.

[0127] The above-mentioned writing module 508 can also be used to: determine the target storage space in the first structure according to the second location information; and write the second current EEPROM data into the target storage space.

[0128] The above-mentioned writing module 508 can also be used to: convert the first value or the second value used to calculate the second position information into a seventh check code; convert the second current EEPROM data into an eighth check code; and write the seventh check code and the eighth check code into the target storage space.

[0129] The rolling storage device for electricity meters provided in this embodiment of the invention has the same implementation principle and technical effect as the aforementioned rolling storage method embodiment for electricity meters. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.

[0130] This invention provides an electronic device, specifically, the electronic device includes a processor and a storage device; the storage device stores a computer program, and the computer program, when run by the processor, executes the rolling storage method of the electricity meter as described in any of the above embodiments.

[0131] Figure 6 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. The electronic device 100 includes: a processor 60, a memory 61, a bus 62, and a communication interface 63. The processor 60, the communication interface 63, and the memory 61 are connected through the bus 62. The processor 60 is used to execute executable modules, such as computer programs, stored in the memory 61.

[0132] The memory 61 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 63 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc.

[0133] Bus 62 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.

[0134] The memory 61 is used to store programs. After receiving an execution instruction, the processor 60 executes the program. The method executed by the device for defining the flow process disclosed in any of the foregoing embodiments of the present invention can be applied to the processor 60 or implemented by the processor 60.

[0135] Processor 60 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 60 or by instructions in software form. Processor 60 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly embodied in the execution of a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. The storage medium is located in memory 61. Processor 60 reads the information in memory 61 and, in conjunction with its hardware, completes the steps of the above method.

[0136] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for rolling storage of electricity in an energy meter, characterized in that, The method includes: A first structure is constructed for pre-divided EEPROM data of multiple types; wherein, the first structure includes offset information and data information; the offset information includes a first value representing the number of copies of the type of EEPROM data that needs to be rolled over and a first check code corresponding to the first value, the first value being the offset of the current number of copies to be rolled over; the data information includes multiple arrays, the number of arrays being equal to the number of copies to be rolled over, each array including multiple types of EEPROM data and a backup corresponding one-to-one with each type of EEPROM data in the array; Each type of EEPROM data and each backup request corresponds to a storage space in the first structure; wherein, the storage space includes the amount of data and the byte position; When it is necessary to read the first current EEPROM data with a first preset data amount from the first structure, the first value and the first check code corresponding to the first current EEPROM data are obtained from the first structure, and the first current EEPROM data is read from the first structure according to the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount. When it is necessary to write the second current EEPROM data with a second preset data amount into the first structure, the first value and the first check code corresponding to the second current EEPROM data are obtained from the first structure, and the second current EEPROM data is written into the first structure according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount.

2. The method according to claim 1, characterized in that, The steps for reading the first current EEPROM data from the first structure based on the first value and the first checksum corresponding to the first current EEPROM data and the first preset data amount include: The first position information in the first structure corresponding to the first current EEPROM data is determined based on the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount; wherein, the first position information represents the byte position of the first current EEPROM data in the first structure; The first current EEPROM data is read from the first structure based on the first position information.

3. The method according to claim 2, characterized in that, The step of determining the first position information in the first structure corresponding to the first current EEPROM data based on the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount includes: Convert the first value corresponding to the first current EEPROM data into a second check code; If the second check code is equal to the first check code corresponding to the first current EEPROM data, then the first position information of the first current EEPROM data in the first structure is calculated based on the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount. If the second check code is not equal to the first check code corresponding to the first current EEPROM data, then the first value corresponding to the first current EEPROM data is set to 0, and the first position information in the first structure corresponding to the first current EEPROM data is calculated based on the first value corresponding to the first current EEPROM data, the first check code, and the first preset data amount.

4. The method according to claim 3, characterized in that, Each array also includes a third checksum corresponding to each type of EEPROM data and a backup of each type of EEPROM data; the first current EEPROM data includes either EEPROM data of the first target type or a backup of the EEPROM data of the first target type. The steps for reading the first current EEPROM data from the first structure based on the first location information include: The third check code corresponding to the EEPROM data of the first target type is read from the first structure based on the first location information; Convert the first current EEPROM data into a fourth checksum; If the fourth check code is equal to the third check code corresponding to the EEPROM data of the first target type, then the EEPROM data of the first target type is read from the first structure according to the first position information; If the fourth check code is not equal to the third check code corresponding to the EEPROM data of the first target type, then the third check code corresponding to the backup of the EEPROM data of the first target type is read from the first structure according to the first position information, and the backup of the EEPROM data of the first target type is converted into the fifth check code. If the fifth check code is equal to the third check code corresponding to the EEPROM data of the first target type, then the backup of the EEPROM data of the first target type is read from the first structure according to the first position information.

5. The method according to claim 1, characterized in that, The step of writing the second current EEPROM data into the first structure according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount includes: The second position information corresponding to the second current EEPROM data in the first structure is determined based on the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount; wherein, the second position information represents the byte position of the second current EEPROM data in the first structure; The second current EEPROM data is written into the first structure according to the second position information.

6. The method according to claim 5, characterized in that, The second current EEPROM data includes EEPROM data of the second target type or a backup of EEPROM data of the second target type; After obtaining the first value and the first checksum corresponding to the second current EEPROM data from the first structure, the method further includes: Counting begins with a preset rollover counter; wherein the initial count value of the rollover counter is 0. The step of determining the second location information in the first structure corresponding to the second current EEPROM data based on the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount includes: Convert the first value corresponding to the second current EEPROM data into the sixth check code; If the sixth check code is equal to the first check code corresponding to the second current EEPROM data, then the current count value of the rollover counter is incremented by 1; If the sixth check code is not equal to the first check code corresponding to the second current EEPROM data, then the first value corresponding to the second current EEPROM data is set to 0, and the current count value of the rollover counter is incremented by 1; If the count value of the rollover counter is greater than the number of copies to be rolled over, then the first value corresponding to the second current EEPROM data is incremented by 1 to obtain the corresponding second value; if the second value corresponding to the second current EEPROM data is not greater than the number of copies to be rolled over, then the second position information of the second current EEPROM data in the first structure is calculated based on the second value corresponding to the second current EEPROM data, the first checksum, and the second preset data amount; if the second value corresponding to the second current EEPROM data is greater than the number of copies to be rolled over, then the second value corresponding to the second current EEPROM data is set to 0, and the second position information of the second current EEPROM data in the first structure is calculated based on the second value corresponding to the second current EEPROM data, the first checksum, and the second preset data amount. If the count value of the roll-over counter is not greater than the number of copies to be rolled over, then the second position information of the second current EEPROM data in the first structure is calculated based on the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount.

7. The method according to claim 6, characterized in that, The step of writing the second current EEPROM data into the first structure according to the second location information includes: The target storage space in the first structure is determined based on the second location information; Write the second current EEPROM data into the target storage space.

8. The method according to claim 7, characterized in that, The method further includes: The first or second value used to calculate the second location information is converted into a seventh check code; Convert the second current EEPROM data into the eighth checksum; Write the seventh and eighth check codes into the target storage space.

9. A rolling storage device for an electricity meter, characterized in that, The device includes: A construction module is used to construct a first structure for pre-divided EEPROM data of multiple types; wherein, the first structure includes offset information and data information; the offset information includes a first value representing the number of copies of the type of EEPROM data that needs to be rolled over and a first check code corresponding to the first value, the first value being the offset of the current number of copies to be rolled over; the data information includes multiple arrays, the number of arrays being equal to the number of copies to be rolled over, each array including multiple types of EEPROM data and a backup corresponding one-to-one with each type of EEPROM data in the array; The application module is used to allocate storage space in the first structure corresponding to each type of EEPROM data and each backup application; wherein, the storage space includes data volume and byte position; The reading module is used to obtain the first value and the first check code corresponding to the first current EEPROM data from the first structure when it is necessary to read the first current EEPROM data with a first preset data amount from the first structure, and read the first current EEPROM data from the first structure according to the first value and the first check code corresponding to the first current EEPROM data and the first preset data amount. The writing module is used to obtain the first value and the first check code corresponding to the second current EEPROM data from the first structure when it is necessary to write the second current EEPROM data with the second preset data amount into the first structure, and write the second current EEPROM data into the first structure according to the first value and the first check code corresponding to the second current EEPROM data and the second preset data amount.

10. An electronic device, characterized in that, The method includes a processor and a memory, the memory storing computer-executable instructions executable by the processor, the processor executing the computer-executable instructions to implement the method of any one of claims 1 to 8.