Data storage method and device, electric energy meter and storage medium

By cyclically writing EEPROM cells in the electricity meter and batch writing Flash cells after the cumulative time reaches a certain length, the contradiction between real-time access and long-term storage in the electricity meter data storage is solved, the real-time preservation and long-term storage of data are realized, and the service life of the Flash cell is extended.

CN120723668AActive Publication Date: 2025-09-30SHIJIAZHUANG KE ELECTRIC

Patent Information

Application Number
CN202511233972.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-09-01
Publication Date
2025-09-30
Estimated Expiration
2045-09-01

AI Technical Summary

Technical Problem

Existing data storage methods for electricity meters cannot simultaneously meet the needs of real-time access efficiency and long-term storage of large amounts of data. EEPROM storage space is limited and costly, while frequent erasure and writing of Flash can easily lead to block failure.

Method used

The data is written to the EEPROM unit in a cycle, and the data is written to the Flash unit in batches after the cumulative time reaches a certain length. The advantages of EEPROM and Flash are combined to achieve real-time preservation and long-term storage of data.

Benefits of technology

Real-time writing of EEPROM cells is achieved, taking into account both real-time access efficiency and long-term storage requirements of Flash cells, thus extending the service life of Flash cells.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120723668A_ABST
    Figure CN120723668A_ABST
Patent Text Reader

Abstract

The invention provides a data storage method and device, an electric energy meter and a storage medium, and belongs to the technical field of data storage, the method comprises the following steps: circularly executing a data writing operation until a stop instruction is received; wherein the data writing operation comprises the following steps of: writing data to be stored into a current writing address of the EEPROM unit in real time, and updating the accumulated duration of writing and the current writing address; in response to the fact that the accumulated duration is larger than or equal to the first duration, determining data written into the EEPROM unit within the accumulated duration as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and resetting the accumulated duration; and in response to the fact that the current write-in address of the EEPROM unit is the first specified address, initializing the current write-in address of the EEPROM unit into a second specified address. According to the data storage method and device, the electric energy meter and the storage medium provided by the invention, the requirements of the electric energy meter on real-time access efficiency and long-term storage of mass data can be met at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of data storage technology, and more specifically, relates to a data storage method and device, an electric energy meter, and a storage medium. Background Art

[0002] During the use of an energy meter, it is necessary to store nearly a year's worth of metering data (such as load curves and power factors), event logs (such as timestamps and detailed parameters of abnormal events such as voltage sags, phase losses, and power outages), and device operation data (such as firmware versions and communication logs). Existing embedded non-volatile memories mainly include EEPROM and Flash. EEPROM can be written frequently, but its storage space is limited and its cost is high. Flash offers large storage space and low cost, but frequent erases and writes can easily lead to block failures.

[0003] Existing data storage methods mainly include: (1) Flash emulation EEPROM solution: frequent writing is achieved through software layer simulation, but it leads to rapid consumption of the EEPROM life of the NOR Flash (typically 100,000 erase and write cycles), and the data is prone to half-written state in the event of abnormal power failure; (2) Pure EEPROM solution: Although it has the advantage of single-byte erase and write (up to a million erase and write cycles), the unit storage cost is as high as 5-8 times that of NOR Flash, which makes it difficult to support large data storage needs.

[0004] The above methods cannot simultaneously meet the needs of real-time access efficiency and long-term storage of large amounts of data. Summary of the Invention

[0005] The purpose of this application is to provide a data storage method and device, an electric energy meter, and a storage medium to simultaneously meet the electric energy meter's requirements for real-time access efficiency and long-term storage of large amounts of data.

[0006] According to a first aspect of an embodiment of the present application, a data storage method is provided, which is applied to an electric energy meter. The electric energy meter includes a controller, an EEPROM unit, and a Flash unit. The method is executed by the controller, and includes: Execute the data writing operation cyclically until a stop instruction is received; The data writing operation includes: Writing the data to be stored to the current write address of the EEPROM unit in real time, and updating the accumulated writing time and the current write address; the accumulated writing time is determined based on the timestamp of the data to be stored; In response to the accumulated time being greater than or equal to a first time, determining the data written into the EEPROM unit within the accumulated time as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and clearing the accumulated time; In response to the current write address of the EEPROM unit being the first designated address, the current write address of the EEPROM unit is initialized to a second designated address.

[0007] According to a second aspect of an embodiment of the present application, a data storage device is provided, which is provided in a controller, wherein the controller is provided in an electric energy meter, wherein the electric energy meter further includes an EEPROM unit and a Flash unit, wherein the device includes a loop module and a data writing module, wherein the loop module is configured to cyclically execute a data writing operation until a stop instruction is received; When performing the data writing operation, the data writing module is used to: Writing the data to be stored to the current write address of the EEPROM unit in real time, and updating the accumulated writing time and the current write address; the accumulated writing time is determined based on the timestamp of the data to be stored; In response to the accumulated time being greater than or equal to a first time, determining the data written into the EEPROM unit within the accumulated time as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and clearing the accumulated time; In response to the current write address of the EEPROM unit being the first designated address, the current write address of the EEPROM unit is initialized to a second designated address.

[0008] According to a third aspect of an embodiment of the present application, an electric energy meter is provided, comprising an EEPROM unit, a Flash unit, a controller, a memory, and a computer program stored in the memory and running on the controller, wherein the EEPROM unit and the Flash unit are used to store data to be stored, and the controller implements the steps of the above-mentioned data storage method when executing the computer program.

[0009] In a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above-mentioned data storage method are implemented.

[0010] The data storage method and device, electric energy meter, and storage medium provided by the embodiments of the present application have the following beneficial effects: In an embodiment of the present application, the EEPROM unit can be written in real time to save the data to be stored in real time. In the process of writing the data to be stored into the EEPROM unit, the length of the time window corresponding to the writing data is determined according to the timestamp of the data to be stored, that is, the cumulative duration. When the cumulative duration is greater than or equal to the preset first duration, the data written into the EEPROM unit within the cumulative duration will be written into the Flash unit in batches to achieve long-term preservation of the data to be stored.

[0011] When writing data to be stored to the EEPROM cell, the current write address is updated synchronously. Since data in the EEPROM cell can be written to the Flash cell in batches at regular intervals, when the EEPROM cell is full (i.e., the current write address is the first designated address), data to be stored can be written again starting from the initialization address (i.e., the second designated address), overwriting the previously written data. This cycle allows the latest data to be stored to be written to the EEPROM cell in real time.

[0012] Therefore, this embodiment saves the latest data to be stored in real time based on the EEPROM unit, and writes the data in the EEPROM unit into the Flash unit in batches periodically, which can take into account both the real-time access efficiency and the long-term storage requirements of large amounts of data. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the embodiments or descriptions of the prior art. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0014] Figure 1 A flowchart of a data storage method provided in one embodiment of the present application; Figure 2 A structural block diagram of a data storage device provided in one embodiment of the present application; Figure 3 A schematic block diagram of an electric energy meter provided in one embodiment of the present application. DETAILED DESCRIPTION

[0015] In the following description, specific details such as specific system structures and techniques are provided for purposes of illustration rather than limitation to facilitate a thorough understanding of the embodiments of the present application. However, it will be apparent to those skilled in the art that the present application may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid obscuring the description of the present application with unnecessary detail.

[0016] In order to make the purpose, technical solutions and advantages of this application clearer, specific embodiments will be described below with reference to the accompanying drawings.

[0017] The data storage method provided in the embodiment of the present application is applied to an electric energy meter, which includes a controller, an EEPROM unit and a Flash unit. Figure 1 , Figure 1 This is a flow chart of a data storage method provided in one embodiment of the present application. The method can be executed by a controller and can include: looping through data write operations until a stop command is received. In this embodiment, the stop command can be triggered by the user. For example, the user sends a stop command to the controller by operating a button. The user can also send a firmware upgrade or data freeze command through a remote master station. When the controller responds to the above command, it is necessary to stop executing the data write operation first. In addition, the stop command can also be triggered by an internal program. When the controller detects that the EEPROM unit or Flash unit is unavailable (such as Flash is full or EEPROM is faulty), it automatically stops executing the data write operation.

[0018] The data writing operation includes: S101: writing the data to be stored to the current write address of the EEPROM unit in real time, and updating the accumulated writing time and the current write address; the accumulated time is determined based on the timestamp of the data to be stored.

[0019] For the embodiments of the present application, the data to be stored may include metering data (such as load curves, power factors, etc.), event record data (such as timestamps and detailed parameters of abnormal events such as voltage sags, phase failures, and power outages), and equipment operation data (such as firmware versions, communication logs, etc.). Writing the data to be stored into the EEPROM in real time can ensure that the data to be stored is saved immediately to avoid data loss.

[0020] When writing data to be stored into an EEPROM cell, the length of the time window corresponding to the data being written, i.e., the cumulative duration, can be determined based on the timestamp of the data being stored. For example, if the time at which data was written at midnight on August 15th is used as the starting point for timing, when data at midnight on August 16th is written into the EEPROM cell, the corresponding cumulative duration is 24 hours.

[0021] At the same time, when writing data to the EEPROM cell, the current write address is incremented by the data length to update the current write address. For example, after writing 16 bytes of data to the EEPROM cell, the updated current write address = current write address + 16. This updated current write address is used as the address for the next EEPROM cell write.

[0022] S102: In response to the accumulated time being greater than or equal to the first time, determining the data written into the EEPROM unit within the accumulated time as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and clearing the accumulated time.

[0023] In this embodiment, when the accumulated time is greater than or equal to a first time period (e.g., 24 hours), the data written to the EEPROM cells during that time period (i.e., the target data) is batch-written to the Flash cells, and the accumulated time period is reset to zero. As the controller writes new data to be stored to the EEPROM cells in real time, the accumulated time period increases again. When the accumulated time period again exceeds or equals the first time period, the new data to be stored is batch-written to the Flash cells. This cycle is repeated, enabling the periodic batch transfer of data from the EEPROM cells to the Flash cells. This method leverages the advantages of real-time writing in EEPROM and the efficient long-term storage of Flash, reducing the loss of Flash memory due to frequent erase and write operations.

[0024] When the accumulated time is less than the first time, step S102 is not performed, and the data to be stored is continued to be written into the EEPROM unit.

[0025] S103: In response to the current write address of the EEPROM unit being the first designated address, initialize the current write address of the EEPROM unit to a second designated address.

[0026] In this embodiment, the first designated address and the second designated address can be pre-set by the user. For example, the first designated address can be the maximum storage address of the EEPROM unit, or other address specified according to actual needs, and the second designated address can be the minimum storage address of the EEPROM unit, or other address specified according to actual needs.

[0027] Since the data in the EEPROM cells can be written to the Flash cells in batches periodically, the EEPROM cells between the first designated address and the second designated address can be written cyclically. When the controller detects that the current write address of the EEPROM reaches the first designated address, it indicates that the storage space is full and the current write address can be reset to the second designated address.

[0028] It can be concluded from the above that in this embodiment, the EEPROM unit can be written in real time to save the data to be stored in real time. In the process of writing the data to be stored into the EEPROM unit, the length of the time window corresponding to the writing data is determined according to the timestamp of the data to be stored, that is, the cumulative duration. When the cumulative duration is greater than or equal to the preset first duration, the data written into the EEPROM unit within the cumulative duration will be written into the Flash unit in batches to achieve long-term preservation of the data to be stored.

[0029] When writing data to be stored to the EEPROM cell, the current write address is updated synchronously. Since data in the EEPROM cell can be written to the Flash cell in batches at regular intervals, when the EEPROM cell is full (i.e., the current write address is the first designated address), data to be stored can be written again starting from the initialization address (i.e., the second designated address), overwriting the previously written data. This cycle allows the latest data to be stored to be written to the EEPROM cell in real time.

[0030] Therefore, this embodiment saves the latest data to be stored in real time based on the EEPROM unit, and writes the data in the EEPROM unit into the Flash unit in batches periodically, which can take into account both the real-time access efficiency and the long-term storage requirements of large amounts of data.

[0031] In one embodiment of the present application, the Flash unit includes multiple data storage pages, the storage length of each data storage page is the first number of bytes, and the EEPROM unit is provided with an index area corresponding to each data storage page; writing target data into the Flash unit includes: dividing the target data into a plurality of target data segments based on the first byte quantity; Starting from the third specified address, the Flash write operation is performed multiple times until all target data are traversed; The i-th Flash write operation includes: Read the i-th target data segment from the EEPROM unit and write the i-th target data segment into the current data storage page of the Flash unit; In response to receiving the write completion information returned by the Flash unit, reading back the data of the current data storage page from the Flash unit to obtain read-back data; Calculate the current Hamming code corresponding to the i-th target data segment, verify the readback data based on the current Hamming code, and if the verification result shows that the readback data has a 1-bit error, write the current Hamming code into the index area corresponding to the current data storage page in the EEPROM unit; In the first Flash write operation, the current data storage page is the data block determined by the third specified address; In other Flash write operations, the current data storage page is the next page of the previous current data storage page.

[0032] In this embodiment, during the accumulation time, the EEPROM unit simultaneously accumulates the number of data records each time a data item is added. When the accumulated time is greater than or equal to the first time, the number of data records is added to the remaining number of records, and the number of data records is cleared. The remaining number of records is multiplied by the length of each data item to obtain the number of bytes of the target data. For example, if the target data includes 100 data items, each of which is 16 bytes long, the total length of the target data is 100 × 16 = 1600 bytes.

[0033] In this embodiment, the physical storage space of the Flash unit may be divided into a plurality of data storage pages. For example, in this embodiment, the storage length of a data storage page is 512 bytes, that is, the number of first bytes is 512.

[0034] Correspondingly, this embodiment divides the target data read from the EEPROM into multiple target data segments of equal length (the number of the first bytes). If, after dividing the multiple target data segments, the remaining data is less than one data storage page, the division of the target data segments is stopped, and the remaining data and the data subsequently written to the EEPROM unit are used together as the target data for the next cumulative time length that is greater than or equal to the first time length.

[0035] Taking the total length of the target data as 1600 bytes as an example, after dividing the target data based on the number of the first bytes, 3 target data segments can be obtained, and 64 bytes are left. In the process of writing the target data into the Flash unit, each time the data of one data storage page is moved, the number of moved records is subtracted from the remaining number of records, and the current read address of the EEPROM unit is saved. After three moves, 64 bytes of data are left, which is less than one data storage page (64<512), and no further move is performed. At this time, the number of remaining records is 4. When the next cumulative duration is greater than or equal to the first duration, the corresponding number of data records is added to the remaining number of records.

[0036] If the power is lost during the migration process, since the number of remaining records is still there, the data migration can be judged based on the remaining number of records after power is restored. If the remaining number of records is zero or less than 32 (512 bytes), it indicates that the migration is complete; if the remaining number of records is greater than or equal to 32, the next address of the currently read address saved previously is used as the re-migration address, and the data migration is restarted starting from the re-migration address.

[0037] On the basis of obtaining the multiple target data segments, the Flash write operation can be performed multiple times in sequence to write the multiple target data segments into the Flash unit in sequence.

[0038] Specifically, during the first Flash write operation, the first target data segment is read from the EEPROM cell and written to the current data storage page of the Flash cell. The current data storage page can be determined based on a third designated address. The third designated address can be pre-set by the user, or upon power-on reset, the controller first performs an initialization process, reads the last written address from a specific location in the Flash, and uses the next address after that address as the third designated address.

[0039] For example, the physical address range of the Flash unit is 0x00000000 to 0x00800000, and each data storage page is 512 bytes long (0x200). During power-on and restart, the last write address read from a specific location in the Flash is 0x0000FFFF. The third specified address is 0x00010000, which corresponds to the 128th storage page of the Flash unit (because 0x00010000 ÷ 0x200 = 128). That is, in the first Flash write operation, the current data storage page is the 128th data storage page.

[0040] In the second Flash write operation, the second target data segment is read from the EEPROM cell and written to the current data storage page of the Flash cell. The current data storage page is the next page of the previous current data storage page, that is, the 129th data storage page.

[0041] After each Flash write operation is completed, the controller receives a write completion message returned by the Flash unit. At this time, the controller reads back the data of the current data storage page from the Flash unit to obtain read-back data. For example, after the first Flash write operation is completed, the controller reads back the data of the 128th data storage page of the Flash unit to obtain the read-back data. At the same time, it calculates the current Hamming code corresponding to the first target data segment and verifies the read-back data based on the current Hamming code.

[0042] The EEPROM cell has an index area corresponding to each data storage page. For example, the first data storage page corresponds to the first index area. When verifying the readback data based on the current Hamming code, if the verification result indicates a single-bit error in the readback data, there is no need to rewrite the first target data segment to the Flash cell. Instead, the current Hamming code is written to the corresponding index area in the EEPROM cell. When data is subsequently read from that data storage page, error correction can be performed based on the Hamming code stored in the corresponding index area. This method can reduce the number of repeated erases and writes to the Flash cell, extending the life of the Flash cell.

[0043] If the verification result shows that the read-back data is correct, the Hamming code writing operation is not performed to reduce the operation time.

[0044] Among them, Hamming code is a code with error detection and correction capabilities. The number of check bits k of the Hamming code must satisfy the formula: , where n is the number of data bits, which in this embodiment is 4096 bits (512 bytes). For 4096 bits of data, 13 check bits are required.

[0045] Assuming the 13-bit Hamming code stored in the EEPROM is the "original check digit," the "current check digit" needs to be recalculated for the 512-byte data read from a data storage page of the Flash unit. The error is located by the difference between the "original check digit" and the "current check digit." The specific process is as follows: (1) After reading data from a data storage page of the Flash unit, reconstruct the "sequence to be verified": The 512 bytes (4096 bits) read from a data storage page of the Flash unit are the "data bits to be checked" and need to be reconstructed into a complete "Hamming code sequence" (4109 bits) with the 13-bit "original check bits" stored in the EEPROM.

[0046] Among them, the 13 "original check bits" are located at: 2 0 =1, 2 1 =2, 2 2 =4, 2 3 =8, 2 4 =16,2 5 =32, 2 6 =64,2 7 =128, 2 8 =256, 2 9 =512,2 10 =1024, 2 11 =2048, 2 12=4096 bits; the remaining positions (3, 5, 6, 7, 9, ..., 4109 bits) are "data bits to be checked" (a total of 4096 bits).

[0047] (2) Calculate the “current check digit”: According to the reconstructed Hamming code sequence, the 13-bit check bit (called "current check bit") is recalculated. The calculation rule is: Each check bit is responsible for checking the data bit at a specific position. Specifically, the i-th check bit (i starts from 0) checks all data bits where the i-th bit in the binary representation is 1. For example: Parity bit 0 (position 1 = 2 0 ): Check all binary positions where the 0th bit is 1 (bits 1, 3, 5, 7, 9, ...); 1st check digit (position 2=2 1 ): Check that the first bit in all binary positions is 1 (bits 2, 3, 6, 7, 10, 11, ...); And so on, until the 12th check digit (position 4096=2 12 ).

[0048] XOR the values ​​of all bits corresponding to the i-th check bit in sequence, and the result is the i-th "current check bit".

[0049] (3) Compare the “original check digit” with the “current check digit” to locate the error: The 13-bit "original check bit" stored in the EEPROM is XORed with the recalculated 13-bit "current check bit" bit by bit to obtain a 13-bit "error indicator code". The check result of the readback data is determined based on the "error indicator code": If the error indicator codes are all 0: the readback data has no errors and the comparison passes; If the error indicator code is not all 0: its value (binary) indicates the position where the error occurred (counting starts from 1). For example, the error indicator code is 0000000000011 (binary), which corresponds to decimal 3, indicating that there is an error in the third bit of data.

[0050] If the error indicator code cannot correspond to a unique position (or the XOR result is chaotic), it indicates that there are more than 2 bits of errors in the data, and the Hamming code cannot correct the error.

[0051] As can be seen from the above, this embodiment writes the target data in segments based on the storage length of the data storage page of the Flash unit, which conforms to the block-level operation characteristics of the Flash unit, can avoid the fragmentation problem of cross-page writing, and improve the efficiency of batch data writing; at the same time, the byte length of the target data segment is fixed. After each target data segment is written, it is convenient to read back the data for verification through Hamming code, which can promptly detect 1-bit errors and record error correction information for subsequent automatic error correction, thereby ensuring the accuracy of stored data.

[0052] In one embodiment of the present application, the data storage method further includes: In response to receiving a data read instruction for the Flash unit, sequentially reading stored data of a plurality of data storage pages in the Flash unit starting from a fourth designated address; After reading the stored data of each data storage page, a first Hamming code is read from the index area corresponding to the data storage page in the EEPROM unit. If the first Hamming code is a preset Hamming code, error correction is performed on the stored data based on the first Hamming code.

[0053] In this embodiment, the data reading instruction for the Flash unit can be triggered by an internal program. For example, scenarios such as device power-on initialization, data reporting, and fault diagnosis will trigger the reading instruction of the historical data stored in the Flash unit. The data reading instruction for the Flash unit can also be triggered by the user. For example, when the user needs to obtain key data stored in the device (such as the historical frozen data of the electricity meter and the device operation log), the user can send an instruction through the management system or debugging tool to read the original data stored in the Flash for viewing or verification.

[0054] Correspondingly, the fourth designated address may be an address obtained by an internal program according to a specific event, such as reading the most recent fault record during fault diagnosis. The fourth designated address may also be an address input by a user through a tool.

[0055] In this embodiment, for each data storage page, there is a two-byte space in the index area corresponding to the data storage page in the EEPROM unit for storing the Hamming code. When not written, the default value of each byte is 0xff, so the preset Hamming code is two bytes of 0xff.

[0056] After reading the stored data from each data storage page, a first Hamming code can be read from the index area corresponding to the data storage page in the EEPROM cell. If the first Hamming code is not the preset Hamming code, this indicates that a 1-bit error occurred during the data write of the data storage page. In this case, after reading the stored data from the data storage page, the stored data can be error-corrected based on the first Hamming code. Specifically, the Hamming code verification steps described in the above embodiment can be used to obtain an "error indication code" based on the first Hamming code (equivalent to the "original check code"). Assuming the error indication code is 0000000000011 (binary), which corresponds to 3 in decimal, indicating an error in the third data bit, the third bit of the read stored data can be inverted to achieve error correction of the stored data.

[0057] From the above, it can be concluded that, in this embodiment, after reading the stored data from each data storage page in the Flash unit, the first Hamming code can be read from the index area corresponding to the data storage page in the EEPROM unit. If it is determined according to the first Hamming code that the stored data has a 1-bit error, the stored data can be corrected based on the first Hamming code, thereby reducing the number of repeated erasing and writing of the Flash and extending the service life of the Flash.

[0058] In one embodiment of the present application, after verifying the readback data based on the current Hamming code, the method further includes: If the check result shows that the readback data has more than 2 bits of errors, the i-th target data segment is read again from the EEPROM unit and the i-th target data segment is rewritten into the current data storage page of the Flash unit.

[0059] In this embodiment, after verifying the readback data of the Flash unit based on the current Hamming code, if it is determined that there are more than 2-bit errors (exceeding the Hamming code's error correction capability), a rewrite mechanism is triggered. Specifically, the i-th target data segment is read again from the EEPROM unit and rewritten to the current data storage page of the Flash unit, overwriting the original erroneous data. After the rewrite is complete, a readback verification can be performed again to ensure that the data is correctly stored. If more than 2-bit errors still exist after multiple rewrites, the rewrite count can be set, for example, to 3, to avoid multiple rewrites occupying controller resources and bus bandwidth and causing device response delays. If more than 2-bit errors still exist after more than 3 rewrites, it indicates that the data storage page has a hardware error. The data storage page is marked as a "bad block" and the address mapping mechanism is enabled to skip the bad block and write the data to the next available data storage page.

[0060] As can be seen from the above, this embodiment rewrites the Flash unit by reading the EEPROM data again for errors of more than 2 bits that cannot be corrected by the Hamming code, thereby ensuring the accuracy of the written data.

[0061] In one embodiment of the present application, after writing the i-th target data segment into the current data storage page of the Flash unit, the method further includes: Calculate the current CRC check code corresponding to the i-th target data segment; The current CRC check code is written into the index area corresponding to the current data storage page in the EEPROM unit.

[0062] In this embodiment, after the i-th target data segment is written to the current data storage page of the Flash unit, the current CRC check code corresponding to the i-th target data segment can also be calculated, and the current CRC check code and the current Hamming code can be saved together in the index area corresponding to the current data storage page in the EEPROM unit.

[0063] For example, in this embodiment, the index area corresponding to the current data storage page in the EEPROM unit includes 4 bytes of storage space, wherein 2 bytes are used to store the Hamming code and 2 bytes are used to store the CRC check code.

[0064] It can be concluded from the above that this embodiment performs double verification on the data written into the Flash unit based on the current CRC check code and the current Hamming code, thereby ensuring the accuracy of data writing.

[0065] In one embodiment of the present application, a method for determining the first duration includes: If the verification result shows that the number of write errors in the readback data during M consecutive Flash write operations is greater than N, the first duration is determined to be a first value; wherein M and N are both natural numbers, and M ≥ N; If the verification result shows that the number of write errors in the readback data during the M consecutive data write operations is less than or equal to N, the first duration is determined based on the average usage rate of the controller during the second duration.

[0066] In this embodiment, if the number of errors during M consecutive Flash write operations exceeds N, it indicates a high Flash unit write error rate. In this case, the first duration can be set to a smaller first value, such as 12 hours, to avoid large data write errors. If the number of errors during M consecutive Flash write operations does not exceed N, it indicates a low Flash unit write error rate. In this case, the first duration can be adjusted based on the average usage of the controller over a second time period (e.g., 10 days). M and N are both preset constants. Those skilled in the art can flexibly design specific values ​​for M and N based on actual needs, for example, setting M=10 and N=3.

[0067] Specifically, the average usage rate of the controller in the second time period is the average usage rate of the controller in the second time period. The uptime function can be called regularly in the controller program (based on the Linux system). For example, at 3:00 p.m. every day, the uptime function is called to obtain the usage rate of the controller, and the average usage rate of multiple controllers in the second time period is calculated to obtain the average usage rate of the controller in the second time period.

[0068] On this basis, when the system where the controller is located runs smoothly, the corresponding fault record data is small, and the data collection frequency will decrease. The controller's data processing volume is small, and the controller utilization rate is low. At this time, the first duration can be increased and the number of Flash writes can be reduced; when the system where the controller is located is heavily loaded (such as high electricity consumption in summer), abnormal situations are prone to occur, and the data collection frequency will increase. The controller's data processing volume is large, and the controller utilization rate is high. At this time, the first duration can be reduced and data storage can be performed in a timely manner.

[0069] As can be seen from the above, this embodiment dynamically adjusts the first duration based on the Flash unit write error rate and the average usage rate of the controller in the second duration, which can minimize the number of Flash writes while ensuring data storage requirements.

[0070] In one embodiment of the present application, determining the first duration based on an average usage rate of the controller within the second duration includes: If the average usage rate of the controller during the second time period is greater than the first threshold, setting the first time period to a second value; If the average usage rate of the controller in the second time period is less than or equal to the first threshold, the first time period is set to a third value; wherein the first value, the second value and the third value increase in sequence.

[0071] In this embodiment, a first threshold value can be set in advance, for example, 50%. When the average usage rate of the controller in the second time period is greater than the first threshold value, it indicates that the average usage rate of the controller in the second time period is high. At this time, the first time period can be set to a second value, for example, 24 hours; when the average usage rate of the controller in the second time period is less than or equal to the first threshold value, it indicates that the average usage rate of the controller in the second time period is low. At this time, the first time period can be set to a third value, for example, 48 hours.

[0072] It can be concluded from the above that this embodiment dynamically adjusts the specific value of the first duration based on the average usage rate of the controller in the second duration, so that data storage can better meet actual needs.

[0073] A data storage method corresponding to the above embodiment, Figure 2 This is a structural block diagram of a data storage device provided in one embodiment of the present application. The device is provided in a controller, which is provided in an electric energy meter. The electric energy meter also includes an EEPROM unit and a Flash unit. For ease of explanation, only the parts related to the embodiment of the present application are shown. Figure 2 , a data storage device 20 includes a circulation module 21 and a data writing module 22, the circulation module 21 is used to cyclically perform a data writing operation until a stop instruction is received; When performing a data writing operation, the data writing module 22 is used to: Writing the data to be stored to the current write address of the EEPROM unit in real time and updating the accumulated writing time and the current write address; the accumulated writing time is determined based on the timestamp of the data to be stored; In response to the accumulated time being greater than or equal to the first time, determining the data written into the EEPROM unit during the accumulated time as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and clearing the accumulated time; In response to the current write address of the EEPROM cell being the first designated address, the current write address of the EEPROM cell is initialized to a second designated address.

[0074] In one embodiment of the present application, the Flash unit includes multiple data storage pages, the storage length of each data storage page is the first number of bytes, and an index area corresponding to each data storage page is provided in the EEPROM unit; the data writing module 22 is further used to: dividing the target data into a plurality of target data segments based on the first byte quantity; Starting from the third specified address, the Flash write operation is performed multiple times until all target data are traversed; The i-th Flash write operation includes: Read the i-th target data segment from the EEPROM unit and write the i-th target data segment into the current data storage page of the Flash unit; In response to receiving the write completion information returned by the Flash unit, reading back the data of the current data storage page from the Flash unit to obtain read-back data; Calculate the current Hamming code corresponding to the i-th target data segment, verify the readback data based on the current Hamming code, and if the verification result shows that the readback data has a 1-bit error, write the current Hamming code into the index area corresponding to the current data storage page in the EEPROM unit; In the first Flash write operation, the current data storage page is the data block determined by the third specified address; In other Flash write operations, the current data storage page is the next page of the previous current data storage page.

[0075] In one embodiment of the present application, the data writing module 22 is further configured to: In response to receiving a data read instruction for the Flash unit, sequentially reading stored data of a plurality of data storage pages in the Flash unit starting from a fourth designated address; After reading the stored data of each data storage page, a first Hamming code is read from the index area corresponding to the data storage page in the EEPROM unit. If the first Hamming code is a preset Hamming code, error correction is performed on the stored data based on the first Hamming code.

[0076] In one embodiment of the present application, the data writing module 22 is further configured to: If the check result shows that the readback data has more than 2 bits of errors, the i-th target data segment is read again from the EEPROM unit and the i-th target data segment is rewritten into the current data storage page of the Flash unit.

[0077] In one embodiment of the present application, the data writing module 22 is further configured to: Calculate the current CRC check code corresponding to the i-th target data segment; The current CRC check code is written into the index area corresponding to the current data storage page in the EEPROM unit.

[0078] In one embodiment of the present application, the data writing module 22 is further configured to: If the verification result shows that the number of write errors in the readback data during M consecutive Flash write operations is greater than N, the first time duration is determined to be a first value; wherein M and N are both natural numbers; If the verification result shows that the number of write errors in the readback data during the M consecutive data write operations is less than or equal to N, the first duration is determined based on the average usage rate of the controller during the second duration.

[0079] In one embodiment of the present application, the data writing module 22 is further configured to: If the average usage rate of the controller during the second time period is greater than the first threshold, setting the first time period to a second value; If the average usage rate of the controller in the second time period is less than or equal to the first threshold, the first time period is set to a third value; wherein the first value, the second value and the third value increase in sequence.

[0080] See also Figure 3 , Figure 3 This is a schematic block diagram of an electric energy meter 300 provided in one embodiment of the present application. Figure 3 The electric energy meter 300 in the embodiment shown may include: one or more controllers 301, one or more input devices 302, one or more output devices 303 and one or more memories 304, EEPROM units 306 and Flash units 307. Among them, the memory 304 is usually a random access memory (RAM), which is used to temporarily store instructions, variables and intermediate data during program operation, supports high-speed reading and writing, and the data is immediately lost after power failure; the EEPROM unit 306 and the Flash unit 307 are used to store metering data, event record data and equipment operation data generated during the operation of the meter, and the data is not lost after power failure. The above-mentioned controller 301, input device 302, output device 303 and memory 304 communicate with each other through the communication bus 305. The memory 304 is used to store computer programs, and the computer programs include program instructions. The controller 301 is used to execute the program instructions stored in the memory 304. Among them, the controller 301 is configured to call program instructions to execute the functions of each module / unit in the above-mentioned device embodiments, such as Figure 2 The functions of the circulation module 21 and the data writing module 22 are shown.

[0081] It should be understood that in the embodiment of the present application, the controller 301 may be a central processing unit (CPU), and the controller 301 may also be other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc.

[0082] The input device 302 may include a touchpad, a fingerprint collection sensor (for collecting user fingerprint information and fingerprint direction information), a microphone, etc. The output device 303 may include a display (LCD, etc.), a speaker, etc.

[0083] The memory 304 may include a read-only memory and a random access memory, and provide instructions and data to the controller 301. A portion of the memory 304 may also include a non-volatile random access memory. For example, the memory 304 may also store preset constants such as a first duration and a first threshold.

[0084] In a specific implementation, the controller 301, input device 302, and output device 303 described in the embodiment of the present application can execute the implementation method described in a data storage method provided in the embodiment of the present application, and can also execute the implementation method of the electric energy meter described in the embodiment of the present application, which will not be repeated here.

[0085] In another embodiment of the present application, a computer-readable storage medium is provided. The computer-readable storage medium stores a computer program. The computer program includes program instructions. When the program instructions are executed by a processor, all or part of the process of the method in the above embodiment is implemented. The computer program can also be used to instruct related hardware to complete the process. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of each of the above method embodiments are implemented. The computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium can include: any entity or device capable of carrying computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium.

[0086] The computer-readable storage medium can be the internal storage unit of the electricity meter in any of the aforementioned embodiments, such as the electricity meter's hard drive or memory. The computer-readable storage medium can also be an external storage device of the electricity meter, such as a plug-in hard drive, a Smart Media Card (SMC), a Secure Digital (SD) card, a flash memory card, etc. Furthermore, the computer-readable storage medium can include both the electricity meter's internal storage unit and an external storage device. The computer-readable storage medium is used to store computer programs and other programs and data required by the electricity meter. The computer-readable storage medium can also be used to temporarily store data that has been output or is about to be output.

[0087] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0088] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the electric energy meter and unit described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0089] In the several embodiments provided in this application, it should be understood that the disclosed electric energy meter and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of units is merely a logical function division. In actual implementation, there may be other division methods, such as modules can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces or units, or can be an electrical, mechanical or other form of connection.

[0090] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.

[0091] In addition, the functional modules in the various embodiments of the present application may be integrated into a processing module, or each module may exist physically separately, or two or more modules may be integrated into a single module. The above-mentioned integrated modules may be implemented in the form of hardware or software functional modules.

[0092] The above are only specific embodiments of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and such modifications or substitutions should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

Claims

1. A data storage method, applied to an electric energy meter, characterized in that: The electric energy meter includes a controller, an EEPROM unit, and a Flash unit. The method is executed by the controller, and the method includes: Execute the data writing operation cyclically until a stop instruction is received; The data writing operation includes: Writing the data to be stored to the current write address of the EEPROM unit in real time, and updating the accumulated writing time and the current write address; the accumulated writing time is determined based on the timestamp of the data to be stored; In response to the accumulated time being greater than or equal to a first time, determining the data written into the EEPROM unit within the accumulated time as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and clearing the accumulated time; In response to the current write address of the EEPROM unit being the first designated address, the current write address of the EEPROM unit is initialized to a second designated address.

2. A data storage method according to claim 1, characterized in that: The Flash unit includes a plurality of data storage pages, the storage length of each of the data storage pages is the first number of bytes, and the EEPROM unit is provided with an index area corresponding to each of the data storage pages; Writing the target data into the Flash unit includes: dividing the target data into a plurality of target data segments based on the first number of bytes; Starting from the third specified address, the Flash write operation is performed multiple times until all target data are traversed; The i-th Flash write operation includes: Reading an i-th target data segment from the EEPROM unit, and writing the i-th target data segment into a current data storage page of the Flash unit; In response to receiving the write completion information returned by the Flash unit, reading back the data of the current data storage page from the Flash unit to obtain read-back data; Calculating a current Hamming code corresponding to the i-th target data segment, verifying the readback data based on the current Hamming code, and if the verification result shows that the readback data has a 1-bit error, writing the current Hamming code into an index area corresponding to a current data storage page in the EEPROM unit; In the first Flash write operation, the current data storage page is the data storage page determined by the third designated address; In other Flash write operations, the current data storage page is the next page of the previous current data storage page.

3. A data storage method according to claim 2, characterized in that: Also includes: In response to receiving a data read instruction for the Flash unit, sequentially reading stored data of a plurality of data storage pages in the Flash unit starting from a fourth designated address; After reading the stored data of each data storage page, a first Hamming code is read from the index area corresponding to the data storage page in the EEPROM unit, and if the first Hamming code is a Hamming code other than the preset Hamming code, error correction is performed on the stored data based on the first Hamming code.

4. A data storage method according to claim 2, characterized in that: After verifying the read-back data based on the current Hamming code, the method further includes: If the check result shows that the read-back data has more than 2 bits of errors, the i-th target data segment is read again from the EEPROM unit, and the i-th target data segment is rewritten into the current data storage page of the Flash unit.

5. A data storage method according to claim 2, characterized in that: After writing the i-th target data segment into the current data storage page of the Flash unit, the method further includes: Calculate the current CRC check code corresponding to the i-th target data segment; The current CRC check code is written into the index area corresponding to the current data storage page in the EEPROM unit.

6. A data storage method according to claim 2, characterized in that: The method for determining the first duration includes: If the verification result shows that the number of write errors in the readback data during M consecutive Flash write operations is greater than N, the first duration is set to a first value; wherein M and N are both natural numbers, and M≥N; If the verification result shows that the number of write errors in the readback data during the M consecutive data write operations is less than or equal to N, the first duration is determined based on the average usage rate of the controller during the second duration.

7. A data storage method according to claim 6, characterized in that: Determining the first duration based on an average usage rate of the controller within the second duration includes: If the average usage rate of the controller during the second time period is greater than the first threshold, setting the first time period to a second value; If the average usage rate of the controller in the second time period is less than or equal to the first threshold, the first time period is set to a third value; wherein the first value, the second value and the third value increase in sequence.

8. A data storage device, provided in a controller, characterized in that: The controller is arranged in an electric energy meter, the electric energy meter further comprising an EEPROM unit and a Flash unit, the device comprising a circulation module and a data writing module, the circulation module being configured to cyclically execute a data writing operation until a stop instruction is received; When performing the data writing operation, the data writing module is used to: Writing the data to be stored to the current write address of the EEPROM unit in real time, and updating the accumulated writing time and the current write address; the accumulated writing time is determined based on the timestamp of the data to be stored; In response to the accumulated time being greater than or equal to a first time, determining the data written into the EEPROM unit within the accumulated time as target data, reading the target data from the EEPROM unit, writing the target data into the Flash unit, and clearing the accumulated time; In response to the current write address of the EEPROM unit being the first designated address, the current write address of the EEPROM unit is initialized to a second designated address.

9. An electric energy meter, characterized in that: The method comprises an EEPROM unit, a Flash unit, a controller, a memory, and a computer program stored in the memory and running on the controller, wherein the EEPROM unit and the Flash unit are used to store data to be stored, and when the controller executes the computer program, the steps of the method according to any one of claims 1 to 7 are implemented.

10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Flash data storage method for intelligent electric energy meter

    CN102339254A

  • Intelligent electric energy meter event storage method

    CN116382578A

  • Intelligent electric energy meter data storage method capable of improving curve data storage reliability

    CN117742589A

  • Ultrasonic water meter data storage method and ultrasonic water meter

    CN120104068A

  • Semiconductor disk system having a plurality of flash memories

    US5603001A

Cited By

  • Data recording system for mining protection device and control method

    CN121641125A