A data storage method and device, an electric energy meter, and a storage medium
By cyclically writing data to the EEPROM unit of the electricity meter and then batch writing it to the Flash unit after a certain cumulative time, combined with Hamming code and CRC check, the contradiction between real-time access and long-term storage in electricity meter data storage is resolved, and the efficiency and reliability of data storage are improved.
Patent Information
- Application Number
- CN202511233972.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-01
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-09-01
AI Technical Summary
Existing electricity meter data storage methods 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 flash writes and erases can easily lead to block failure.
The system cyclically writes data to the EEPROM unit and then writes the data to the Flash unit in batches after a certain cumulative time. Combining the real-time writing capability of the EEPROM unit with the long-term storage capability of the Flash unit, the system uses Hamming code verification and CRC verification to ensure data accuracy and reduce the frequency of Flash erasure and rewriting.
It achieves a balance between real-time access efficiency and long-term storage of electricity meter data, extends the lifespan of the Flash unit, and reduces the risk of data loss.
Smart Images

Figure CN120723668B_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of data storage technology, and more specifically, relates to a data storage method and apparatus, an electricity meter, and a storage medium. Background Technology
[0002] During the use of electricity meters, it is necessary to store nearly a year's worth of metering data (such as load curves, power factor, etc.), event log data (such as timestamps and detailed parameters of abnormal events such as voltage swells and dips, phase loss, and power outages), and equipment operation data (such as firmware version, communication logs, etc.). Existing embedded non-volatile memories mainly include EEPROM and Flash. EEPROM can be written to frequently, but its storage space is limited and its cost is high; Flash has a large storage space and low cost, but frequent erasure and writing can easily lead to block failure.
[0003] Existing data storage methods mainly include: (1) Flash simulated EEPROM scheme: Frequent writing is achieved through software layer simulation, but it leads to the rapid consumption of NOR Flash erase and write life (typically 100,000 erase and write limit), and data half-write state is easy to occur when abnormal power failure occurs;
[0004] (2) Pure EEPROM solution: Although it has the advantage of single-byte erase and write (up to millions of erase and write cycles), the unit storage cost is 5-8 times that of NORFlash, making it difficult to support the storage needs of large data volumes.
[0005] 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
[0006] The purpose of this application is to provide a data storage method and device, an electricity meter, and a storage medium to simultaneously meet the electricity meter's requirements for real-time access efficiency and long-term storage of large amounts of data.
[0007] A first aspect of this application provides a data storage method applied to an electricity meter, the electricity meter including a controller, an EEPROM unit, and a Flash unit, the method being executed by the controller, the method comprising:
[0008] The data write operation is executed repeatedly until a stop command is received;
[0009] The data writing operation includes:
[0010] The system writes data to be stored to the current write address of the EEPROM unit in real time and updates the cumulative writing duration and the current write address; the cumulative duration is determined based on the timestamp of the data to be stored.
[0011] In response to the cumulative duration being greater than or equal to a first duration, the data written to the EEPROM unit within the cumulative duration is determined as target data, the target data is read from the EEPROM unit, the target data is written to the Flash unit, and the cumulative duration is cleared to zero;
[0012] In response to the current write address of the EEPROM unit being a first specified address, the current write address of the EEPROM unit is initialized to a second specified address.
[0013] A second aspect of this application provides a data storage device disposed in a controller, the controller being disposed in an energy meter, the energy meter further comprising an EEPROM unit and a Flash unit, the device comprising a loop module and a data writing module, the loop module being used to repeatedly perform data writing operations until a stop command is received;
[0014] When performing the data write operation, the data write module is used to:
[0015] The system writes data to be stored to the current write address of the EEPROM unit in real time and updates the cumulative writing duration and the current write address; the cumulative duration is determined based on the timestamp of the data to be stored.
[0016] In response to the cumulative duration being greater than or equal to a first duration, the data written to the EEPROM unit within the cumulative duration is determined as target data, the target data is read from the EEPROM unit, the target data is written to the Flash unit, and the cumulative duration is cleared to zero;
[0017] In response to the current write address of the EEPROM unit being a first specified address, the current write address of the EEPROM unit is initialized to a second specified address.
[0018] A third aspect of this application provides an electricity meter, including an EEPROM unit, a Flash unit, a controller, a memory, and a computer program stored in the memory and running on the controller. The EEPROM unit and the Flash unit are used to store data to be stored, and the controller executes the computer program to implement the steps of the above-described data storage method.
[0019] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the data storage method described above.
[0020] The beneficial effects of the data storage method and apparatus, electricity meter, and storage medium provided in this application embodiment are as follows:
[0021] In this embodiment, the EEPROM unit can be written in real time to save the data to be stored in real time. During the process of writing the data to be stored to the EEPROM unit, the length of the time window corresponding to the data to be written 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 to the EEPROM unit within the cumulative duration will be written to the Flash unit in batches to realize the long-term storage of the data to be stored.
[0022] During the process of writing data to be stored into 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 periodically, when the data in the EEPROM cell is full (i.e., the current write address is the first specified address), the writing of data to be stored can continue from the initial address (i.e., the second specified address), overwriting the previously written data. This process is repeated to ensure that the latest data to be stored is written to the EEPROM cell in real time.
[0023] 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 on a regular basis, which can take into account both the need for real-time access efficiency and the need for long-term storage of large amounts of data. Attached Figure Description
[0024] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0025] Figure 1 A schematic flowchart illustrating a data storage method according to an embodiment of this application;
[0026] Figure 2 A structural block diagram of a data storage device provided in an embodiment of this application;
[0027] Figure 3 This is a schematic block diagram of an electricity meter provided in an embodiment of this application. Detailed Implementation
[0028] In the following description, specific details such as particular system architectures and techniques are set forth for illustrative purposes and not for limitation, in order to provide a thorough understanding of the embodiments of this application. However, those skilled in the art will understand that this application may also be implemented in other embodiments without these specific details. In other instances, detailed descriptions of well-known systems, apparatuses, circuits, and methods have been omitted so as not to obscure the description of this application with unnecessary detail.
[0029] To make the objectives, technical solutions, and advantages of this application clearer, the following description will be provided in conjunction with the accompanying drawings and specific embodiments.
[0030] This application provides a data storage method applied to an electricity meter. The electricity meter includes a controller, an EEPROM unit, and a Flash unit. Please refer to [link / reference needed]. Figure 1 , Figure 1 This is a flowchart illustrating a data storage method according to an embodiment of this application. The method can be executed by a controller and may include: repeatedly performing data write operations until a stop command is received. In this embodiment, the stop command can be triggered by a user. For example, the user can send a stop command to the controller via an operation button, or the user can issue commands such as firmware upgrades or data freezes via a remote master station. When the controller responds to the above commands, it needs to stop executing the data write operation first. Alternatively, the stop command can also be triggered by an internal program. When the controller detects that the EEPROM unit or Flash unit is unavailable (e.g., Flash is full, EEPROM is faulty), it automatically stops executing the data write operation.
[0031] The data write operation includes:
[0032] S101: Write the data to be stored to the current write address of the EEPROM unit in real time, and update the cumulative writing duration and the current write address; the cumulative duration is determined based on the timestamp of the data to be stored.
[0033] In the embodiments of this application, the data to be stored may include metering data (such as load curves, power factors, etc.), event log data (such as timestamps and detailed parameters of abnormal events such as voltage sags and dips, phase loss, power outages, etc.), and equipment operation data (such as firmware version, 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 and avoid data loss.
[0034] During the process of writing data to be stored into the EEPROM unit, 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 to be stored. For example, if the time point of writing data at 00:00 on August 15th is taken as the starting point of the timing, when writing data at 00:00 on August 16th into the EEPROM unit, the corresponding cumulative duration is 24 hours.
[0035] Meanwhile, during the process of writing data to be stored into the EEPROM cell, the current write address is incremented according to the data length to update the current write address. For example, after writing 16 bytes of data into the EEPROM cell, the updated current write address = current write address + 16, and the updated current write address is used as the address for the next write operation into the EEPROM cell.
[0036] S102: In response to the cumulative duration being greater than or equal to the first duration, the data written to the EEPROM unit within the cumulative duration is determined as the target data, the target data is read from the EEPROM unit, the target data is written to the Flash unit, and the cumulative duration is cleared to zero.
[0037] In this embodiment, when the cumulative duration is greater than or equal to a first duration (e.g., 24 hours), the data written to the EEPROM unit (i.e., the target data) within that period (cumulative duration) is written in batches to the Flash unit, and the cumulative duration is reset to zero. As the controller writes new data to be stored to the EEPROM unit in real time, the cumulative duration increases again. When the cumulative duration is again greater than or equal to the first duration, the new data to be stored is written in batches to the Flash unit. This cycle repeats, periodically transferring data from the EEPROM unit to the Flash unit in batches. This method fully utilizes the advantages of real-time writing from EEPROM and efficient long-term storage from Flash, reducing the wear and tear from frequent Flash erase and write operations.
[0038] If the cumulative duration is less than the first duration, step S102 is not executed, and the data to be stored is written to the EEPROM unit.
[0039] S103: In response to the current write address of the EEPROM cell being the first specified address, initialize the current write address of the EEPROM cell to the second specified address.
[0040] In this embodiment, the first specified address and the second specified address can be preset by the user. For example, the first specified address can be the maximum storage address of the EEPROM unit, or other addresses specified according to actual needs. The second specified address can be the minimum storage address of the EEPROM unit, or other addresses specified according to actual needs.
[0041] Since data in the EEPROM unit can be written to the Flash unit in batches periodically, the EEPROM unit between the first specified address and the second specified address can be written cyclically. When the controller detects that the current write address of the EEPROM has reached the first specified address, it indicates that the storage space is full and the current write address can be reset to the second specified address.
[0042] As can be seen from the above, in this embodiment, the EEPROM unit can be written in real time to save the data to be stored in real time. During the process of writing the data to be stored to the EEPROM unit, the length of the time window corresponding to the data to be written 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 to the EEPROM unit within the cumulative duration will be written to the Flash unit in batches to realize the long-term storage of the data to be stored.
[0043] During the process of writing data to be stored into 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 periodically, when the data in the EEPROM cell is full (i.e., the current write address is the first specified address), the writing of data to be stored can continue from the initial address (i.e., the second specified address), overwriting the previously written data. This process is repeated to ensure that the latest data to be stored is written to the EEPROM cell in real time.
[0044] 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 on a regular basis, which can take into account both the need for real-time access efficiency and the need for long-term storage of large amounts of data.
[0045] In one embodiment of this application, the Flash unit includes multiple data storage pages, each data storage page having a storage length equal to the number of bytes in the first data storage page, and the EEPROM unit has an index area corresponding to each data storage page; writing target data into the Flash unit includes:
[0046] The target data is divided into multiple target data segments based on the number of bytes in the first byte.
[0047] Starting from the third specified address, perform multiple Flash write operations until all target data has been traversed;
[0048] The i-th Flash write operation includes:
[0049] 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;
[0050] In response to receiving the write completion information returned by the Flash unit, the data of the current data storage page is read back from the Flash unit to obtain the read-back data;
[0051] Calculate the current Hamming code corresponding to the i-th target data segment, and verify the readback data based on the current Hamming code. If the verification result shows that there is a 1-bit error in the readback data, write the current Hamming code into the index area corresponding to the current data storage page in the EEPROM unit.
[0052] In the first Flash write operation, the current data storage page is the data block determined by the third specified address;
[0053] In other Flash write operations, the current data storage page is the next page after the previous current data storage page.
[0054] In this embodiment, within the accumulated time period, the EEPROM unit synchronously increments the data record count for each additional data entry. When the accumulated time period is greater than or equal to the first time period, the data record count is added to the remaining record count, and the data record count is simultaneously cleared. The remaining record count is then multiplied by the length of each data entry to obtain the target data in bytes. For example, if the target data includes 100 data entries, each with a length of 16 bytes, then the total length of the target data is 100 × 16 = 1600 bytes.
[0055] In this embodiment, the physical storage space of the Flash unit can be divided into multiple data storage pages. For example, in this embodiment, the storage length of the data storage page is 512 bytes, that is, the number of the first byte is 512.
[0056] Correspondingly, in this embodiment, the target data read from the EEPROM is divided into multiple target data segments of equal length (number of first bytes). If, after dividing the 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, together with the data subsequently written to the EEPROM unit, is used as the target data for the next cumulative duration greater than or equal to the first duration.
[0057] Taking a target data length of 1600 bytes as an example, after dividing the target data based on the number of the first byte, three target data segments can be obtained, leaving 64 bytes. During the process of writing the target data into the Flash unit, for each data storage page 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 remain, which is less than one data storage page (64 < 512), so no further moves are made. At this point, the remaining number of records is 4. When the next accumulated duration is greater than or equal to the first duration, the corresponding number of data records is added to the remaining number of records.
[0058] If a power outage occurs during the data transfer process, the remaining number of records will still be available. After power is restored, the data transfer can be judged based on the remaining number of records. If the remaining number of records is zero or less than 32 (512 bytes), the data transfer is complete. If the remaining number of records is greater than or equal to 32, the next address after the previously saved current read address will be used as the address to start the data transfer again.
[0059] Based on obtaining multiple target data segments, Flash write operations can be performed sequentially multiple times to write the multiple target data segments into the Flash cell in turn.
[0060] Specifically, in the first Flash write operation, the first target data segment is read from the EEPROM unit and written to the current data storage page of the Flash unit. The current data storage page can be determined based on a third specified address. This third specified address can be preset by the user, or it can be determined during power-on restart when the controller first executes an initialization process, reads the last write address from a specific location in the Flash, and uses the address following that address as the third specified address.
[0061] For example, the physical address range of a Flash cell is 0x00000000~0x00800000, and each data storage page is 512 bytes long (0x200). When power-on and restarting, the last write address is read from a specific location in the Flash, which is 0x0000FFFF. The third specified address is 0x00010000, which corresponds to the 128th storage page of the Flash cell (because 0x00010000 ÷ 0x200 = 128). That is, in the first Flash write operation, the current data storage page is the 128th data storage page.
[0062] In the second Flash write operation, the second target data segment is read from the EEPROM unit and written to the current data storage page of the Flash unit. The current data storage page is the page following the previous current data storage page, which is the 129th data storage page.
[0063] After each Flash write operation is completed, the controller receives a write completion message from the Flash cell. At this time, the controller reads back the data of the current data storage page from the Flash cell to obtain the read-back data.
[0064] 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 readback data. At the same time, it calculates the current Hamming code corresponding to the first target data segment and verifies the readback data based on the current Hamming code.
[0065] Each EEPROM unit contains an index area corresponding to each data storage page; for example, the first data storage page corresponds to the first index area. When verifying readback data based on the current Hamming code, if the verification result shows a 1-bit error in the readback data, it is not necessary to rewrite the first target data segment into the Flash unit. Instead, the current Hamming code is written to the corresponding index area in the EEPROM unit. 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. Using this method, the number of repeated erases and writes to the Flash unit can be reduced, extending the lifespan of the Flash unit.
[0066] If the verification result shows that the readback data is correct, the Hamming code writing operation will not be performed to reduce the operation time.
[0067] Hamming code is a type of code with error detection and correction capabilities. The number of check bits k in a Hamming code must satisfy the formula: Where n is the number of data bits, which is 4096 bits (512 bytes) in this embodiment. For 4096 bits of data, 13 check bits are required.
[0068] Assuming the 13-bit Hamming code stored in the EEPROM is the "original parity bit", 512 bytes of data read from a data storage page in the Flash unit need to have the "current parity bit" recalculated. The error is located by the difference between the "original parity bit" and the "current parity bit". The specific process is as follows:
[0069] (1) After reading data from a data storage page of the Flash cell, reconstruct the "sequence to be verified":
[0070] The 512 bytes (4096 bits) read from a data storage page in the Flash unit are the "data bits to be checked", which need to be reconstructed with the 13 "original check bits" stored in the EEPROM into a complete "Haming code sequence" (4109 bits).
[0071] 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、26 =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 verified" (4096 bits in total).
[0072] (2) Calculate the "current check bit":
[0073] Based on the reconstructed Hamming code sequence, the 13 parity bits (referred to as the "current parity bits") are recalculated. The calculation rule is as follows:
[0074] Each parity bit is responsible for verifying a specific data bit at a particular position. Specifically, the i-th parity bit (i starting from 0) verifies all data bits where the i-th bit in the binary representation is 1. For example:
[0075] 0th parity bit (position 1=2) 0 ): Verify the data bits (bits 1, 3, 5, 7, 9, ...) where the 0th bit is 1 in all binary positions;
[0076] First check bit (position 2=2) 1 ): Verify the data bits whose first bit is 1 in all binary positions (bits 2, 3, 6, 7, 10, 11, ...).
[0077] This continues until the 12th parity bit (position 4096=2). 12 ).
[0078] 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".
[0079] (3) Compare the "original check bit" with the "current check bit" to locate the error:
[0080] The 13-bit "original check bit" stored in the EEPROM is XORed bit by bit with the recalculated 13-bit "current check bit" to obtain a 13-bit "error indicator code". The verification result of the readback data is determined based on the "error indicator code".
[0081] If all error indicator codes are 0: No errors were found in the readback data, and the comparison passed;
[0082] If the error indicator code is not all zeros: its value (binary) indicates the position where the error occurred (counting from 1). For example, the error indicator code is 0000000000011 (binary), which corresponds to 3 in decimal, indicating that there is an error in the 3rd bit of data.
[0083] If the error indicator code cannot correspond to a unique position (or the XOR result is chaotic), it indicates that there is an error of more than 2 bits in the data, and Hamming code cannot correct the error in this case.
[0084] 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. This avoids the fragmentation problem of cross-page writing and improves 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 using Hamming code. This allows for the timely detection of 1-bit errors and the recording of error correction information for subsequent automatic error correction, ensuring the accuracy of the stored data.
[0085] In one embodiment of this application, the data storage method further includes:
[0086] In response to receiving a data read instruction for a Flash cell, starting from the fourth specified address, the stored data of multiple data storage pages in the Flash cell is read sequentially;
[0087] After reading the stored data of each data storage page, the first Hamming code is read from the index area corresponding to that data storage page in the EEPROM unit. If the first Hamming code is a preset Hamming code, the stored data is corrected based on the first Hamming code.
[0088] In this embodiment, the data reading command 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 command to read the historical data stored in the Flash unit. The data reading command 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 historical frozen data of the electricity meter and device operation log), they can send a command through the management system or debugging tools to read the original data stored in the Flash for viewing or verification.
[0089] Correspondingly, the fourth specified address can be an address obtained by an internal program based on a specific event, such as reading the most recent fault record during fault diagnosis, or it can be an address entered by the user through a tool.
[0090] In this embodiment, for each data storage page, there are two bytes of space in the index area corresponding to that data storage page in the EEPROM unit for storing Hamming code. When no writing is performed, the default value of each byte is 0xff, so the preset Hamming code is two bytes of 0xff.
[0091] After reading the stored data from each data storage page, the first Hamming code can be read from the index area corresponding to that data storage page in the EEPROM unit. If the first Hamming code is not the preset Hamming code, it indicates that there is a 1-bit error when writing the data to that data storage page. At this time, after reading the stored data from that data storage page, the stored data can be corrected based on the first Hamming code. Specifically, the Hamming code verification steps described in the above embodiment can be used to obtain the "error indicator code" based on the first Hamming code (equivalent to the "original check code"). Assuming the error indicator code is 0000000000011 (binary), corresponding to decimal 3, it indicates that there is an error in the 3rd bit of data. By inverting the 3rd bit of the read stored data, the error correction of the stored data can be achieved.
[0092] As can be seen from the above, after reading the stored data from each data storage page in the Flash unit, this embodiment can read the first Hamming code from the index area corresponding to the data storage page in the EEPROM unit. If it is determined that there is a 1-bit error in the stored data according to the first Hamming code, the stored data can be corrected based on the first Hamming code, thereby reducing the number of repeated erases and writes of the Flash and extending the life of the Flash.
[0093] In one embodiment of this application, after verifying the readback data based on the current Hamming code, the method further includes:
[0094] If the verification result shows that there are more than 2 bits of errors in the readback data, then the i-th target data segment is read again from the EEPROM unit and rewritten into the current data storage page of the Flash unit.
[0095] In this embodiment, after verifying the readback data of the Flash unit based on the current Hamming code, if it is determined that there is an error of more than 2 bits (exceeding the error correction capability of the Hamming code), a rewrite mechanism is triggered. Specifically, the i-th target data segment is read again from the EEPROM unit and rewritten into the current data storage page of the Flash unit, overwriting the original erroneous data. After the rewrite is completed, a readback verification can be performed again to ensure that the data is stored correctly. If there is still an error of more than 2 bits after multiple rewrites, in order to avoid multiple rewrites occupying controller resources and bus bandwidth, resulting in device response delay, the number of rewrites can be set, for example, the number of rewrites can be set to 3. If there is still an error of more than 2 bits after more than 3 rewrites, it indicates that there is a hardware error in the data storage page. 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.
[0096] As can be seen from the above, this embodiment addresses errors of 2 bits or more that Hamming codes cannot correct by rewriting the Flash unit after reading the EEPROM data again, thereby ensuring the accuracy of the written data.
[0097] In one embodiment of this application, after writing the i-th target data segment to the current data storage page of the Flash unit, the method further includes:
[0098] Calculate the current CRC checksum corresponding to the i-th target data segment;
[0099] Write the current CRC checksum into the index area corresponding to the current data storage page in the EEPROM unit.
[0100] In this embodiment, after writing the i-th target data segment into the current data storage page of the Flash unit, the current CRC checksum corresponding to the i-th target data segment can be calculated, and the current CRC checksum and the current Hamming code can be stored together in the index area corresponding to the current data storage page in the EEPROM unit.
[0101] 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, of which 2 bytes are used to store Hamming code and 2 bytes are used to store CRC check code.
[0102] As can be seen from the above, this embodiment performs dual verification on the written data of the Flash unit based on the current CRC checksum and the current Hamming code, which can ensure the accuracy of data writing.
[0103] In one embodiment of this application, the method for determining the first duration includes:
[0104] If the verification result shows that the number of write errors during data readback is greater than N in M consecutive Flash write operations, the first duration is determined as the first value; where M and N are both natural numbers, and M≥N;
[0105] If the verification results show that the number of write errors during data readback in M consecutive data write operations is less than or equal to N, the first duration is determined based on the average utilization of the controller within the second duration.
[0106] In this embodiment, if the number of errors exceeds N in M consecutive Flash write operations, it indicates a high Flash cell 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 does not exceed N in M consecutive Flash write operations, it indicates a low Flash cell write error rate. In this case, the first duration can be adjusted based on the controller's average usage over a second duration (e.g., 10 days). Here, M and N are preset constants, and those skilled in the art can flexibly design the specific values of M and N according to actual needs, for example, setting M=10 and N=3.
[0107] Specifically, the average utilization rate of the controller within the second time period is the average utilization rate of the controller within the second time period. The uptime function can be called periodically in the controller program (based on the Linux system), for example, at 3:00 pm every day. The uptime function is called to obtain the utilization rate of the controller, calculate the average utilization rate of multiple controllers within the second time period, and obtain the average utilization rate of the controller within the second time period.
[0108] Based on this, when the system where the controller is located is running smoothly, there are fewer fault records and the data acquisition frequency will decrease, resulting in less data processing volume and low utilization of the controller. In this case, the first duration can be increased to reduce the number of Flash writes. When the system where the controller is located is under heavy load (such as high electricity consumption in summer), abnormal situations are more likely to occur, and the data acquisition frequency will increase, resulting in more data processing volume and high utilization of the controller. In this case, the first duration can be reduced to ensure timely data storage.
[0109] As can be seen from the above, this embodiment dynamically adjusts the first duration based on the Flash cell write error rate and the controller's average utilization rate within the second duration, which can minimize the number of Flash writes while ensuring data storage requirements.
[0110] In one embodiment of this application, determining the first duration based on the controller's average usage over a second duration includes:
[0111] If the average utilization rate of the controller during the second time period is greater than the first threshold, the first time period will be set to the second value.
[0112] If the average utilization rate of the controller during the second duration is less than or equal to the first threshold, the first duration is set to the third value; wherein the first value, the second value, and the third value increase sequentially.
[0113] In this embodiment, a first threshold can be preset, such as 50%. When the average usage rate of the controller in the second time period is greater than the first threshold, 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, such as 24 hours. When the average usage rate of the controller in the second time period is less than or equal to the first threshold, 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, such as 48 hours.
[0114] As can be seen from the above, this embodiment dynamically adjusts the specific value of the first duration based on the average utilization rate of the controller within the second duration, which can make the data storage more in line with actual needs.
[0115] Corresponding to the data storage method in the above embodiment, Figure 2 This is a structural block diagram of a data storage device according to an embodiment of this application. The device is disposed in a controller, which is disposed in an electricity meter. The electricity meter also includes an EEPROM unit and a Flash unit. For ease of explanation, only the parts relevant to the embodiment of this application are shown. References Figure 2 The data storage device 20 includes a loop module 21 and a data writing module 22. The loop module 21 is used to repeatedly perform data writing operations until a stop command is received.
[0116] When performing a data write operation, the data write module 22 is used for:
[0117] The system writes the data to be stored to the current write address of the EEPROM cell in real time and updates the cumulative writing duration and the current write address; the cumulative duration is determined based on the timestamp of the data to be stored.
[0118] In response to the cumulative duration being greater than or equal to the first duration, the data written to the EEPROM unit within the cumulative duration is determined as the target data, the target data is read from the EEPROM unit, the target data is written to the Flash unit, and the cumulative duration is cleared to zero;
[0119] In response to the current write address of the EEPROM cell being the first specified address, the current write address of the EEPROM cell is initialized to the second specified address.
[0120] In one embodiment of this application, the Flash unit includes multiple data storage pages, each data storage page having a storage length equal to the number of bytes in the first data storage page, and the EEPROM unit has an index area corresponding to each data storage page; the data writing module 22 is further configured to:
[0121] The target data is divided into multiple target data segments based on the number of bytes in the first byte.
[0122] Starting from the third specified address, perform multiple Flash write operations until all target data has been traversed;
[0123] The i-th Flash write operation includes:
[0124] 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;
[0125] In response to receiving the write completion information returned by the Flash unit, the data of the current data storage page is read back from the Flash unit to obtain the read-back data;
[0126] Calculate the current Hamming code corresponding to the i-th target data segment, and verify the readback data based on the current Hamming code. If the verification result shows that there is a 1-bit error in the readback data, write the current Hamming code into the index area corresponding to the current data storage page in the EEPROM unit.
[0127] In the first Flash write operation, the current data storage page is the data block determined by the third specified address;
[0128] In other Flash write operations, the current data storage page is the next page after the previous current data storage page.
[0129] In one embodiment of this application, the data writing module 22 is further configured to:
[0130] In response to receiving a data read instruction for a Flash cell, starting from the fourth specified address, the stored data of multiple data storage pages in the Flash cell is read sequentially;
[0131] After reading the stored data of each data storage page, the first Hamming code is read from the index area corresponding to that data storage page in the EEPROM unit. If the first Hamming code is a preset Hamming code, the stored data is corrected based on the first Hamming code.
[0132] In one embodiment of this application, the data writing module 22 is further configured to:
[0133] If the verification result shows that there are more than 2 bits of errors in the readback data, then the i-th target data segment is read again from the EEPROM unit and rewritten into the current data storage page of the Flash unit.
[0134] In one embodiment of this application, the data writing module 22 is further configured to:
[0135] Calculate the current CRC checksum corresponding to the i-th target data segment;
[0136] Write the current CRC checksum into the index area corresponding to the current data storage page in the EEPROM unit.
[0137] In one embodiment of this application, the data writing module 22 is further configured to:
[0138] If the verification result shows that the number of write errors during data readback is greater than N in M consecutive Flash write operations, the first duration will be determined as the first value; where M and N are both natural numbers.
[0139] If the verification results show that the number of write errors during data readback in M consecutive data write operations is less than or equal to N, the first duration is determined based on the average utilization of the controller within the second duration.
[0140] In one embodiment of this application, the data writing module 22 is further configured to:
[0141] If the average utilization rate of the controller during the second time period is greater than the first threshold, the first time period will be set to the second value.
[0142] If the average utilization rate of the controller during the second duration is less than or equal to the first threshold, the first duration is set to the third value; wherein the first value, the second value, and the third value increase sequentially.
[0143] See Figure 3 , Figure 3 This is a schematic block diagram of an electricity meter 300 provided in one embodiment of this application. Figure 3The electricity meter 300 in this embodiment 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. The memory 304 is typically a random access memory (RAM) used to temporarily store instructions, variables, and intermediate data during program execution, supporting high-speed read / write, and data is immediately lost after power failure. The EEPROM units 306 and Flash units 307 are used to store metering data, event log data, and device operation data generated during meter operation, and the data is not lost after power failure. The controllers 301, input devices 302, output devices 303, and memory 304 communicate with each other via a communication bus 305. The memory 304 stores computer programs, including program instructions. The controllers 301 execute the program instructions stored in the memory 304. The controllers 301 are configured to call the program instructions to execute the functions of each module / unit in the above-described device embodiments, for example... Figure 2 The functions of the loop module 21 and the data writing module 22 are shown.
[0144] It should be understood that, in the embodiments of this application, the controller 301 may be a central processing unit (CPU), or it may be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), 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.
[0145] Input device 302 may include a touchpad, a fingerprint sensor (for collecting the user's fingerprint information and fingerprint orientation information), a microphone, etc., and output device 303 may include a display (LCD, etc.), a speaker, etc.
[0146] The memory 304 may include read-only memory and random access memory, and provides instructions and data to the controller 301. A portion of the memory 304 may also include non-volatile random access memory. For example, the memory 304 may also store preset constants such as a first duration and a first threshold.
[0147] In specific implementations, the controller 301, input device 302, and output device 303 described in the embodiments of this application can execute the implementation method described in the data storage method provided in the embodiments of this application, or they can execute the implementation method of the electricity meter described in the embodiments of this application, which will not be repeated here.
[0148] In another embodiment of this application, a computer-readable storage medium is provided. This computer-readable storage medium stores a computer program, which includes program instructions. When executed by a processor, the program instructions implement all or part of the processes in the methods described above. Alternatively, the computer program can instruct related hardware to complete the process. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include any entity or device capable of carrying computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a random access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.
[0149] The computer-readable storage medium can be an internal storage unit of the electricity meter in any of the foregoing 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, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electricity meter. Furthermore, the computer-readable storage medium can include both internal storage units and external storage devices of the electricity meter. 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 will be output.
[0150] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this application.
[0151] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working process of the electricity meter and unit described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0152] In the several embodiments provided in this application, it should be understood that the disclosed energy meter and method can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, modules may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the mutual coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces or units, or it may be an electrical, mechanical, or other form of connection.
[0153] The units described as separate components may or may not be physically separate. 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 can be selected to achieve the purpose of the embodiments of this application, depending on actual needs.
[0154] Furthermore, the functional modules in the various embodiments of this application can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0155] The above are merely specific embodiments of this application, but the scope of protection of this 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 these modifications or substitutions should all be covered within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
Claims
1. A data storage method, applied to an electricity meter, characterized in that, The energy meter includes a controller, an EEPROM unit, and a Flash unit. The method is executed by the controller and includes: The data write operation is executed repeatedly until a stop command is received; The data writing operation includes: The system writes data to be stored to the current write address of the EEPROM unit in real time and updates the cumulative writing time and the current write address; the cumulative writing time is determined based on the timestamp of the data to be stored. In response to the cumulative duration being greater than or equal to a first duration, the data written to the EEPROM unit within the cumulative duration is determined as target data, the target data is read from the EEPROM unit, written to the Flash unit, and the cumulative duration is cleared to zero; wherein, the Flash unit includes multiple data storage pages, each data storage page has a storage length of a first byte, and the EEPROM unit is provided with an index area corresponding to each data storage page; the step of writing the target data to the Flash unit includes: The target data is divided into multiple target data segments based on the first byte count; Starting from the third specified address, perform multiple Flash write operations until all target data has been 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, the data of the current data storage page is read back from the Flash unit to obtain the read-back data; Calculate the current Hamming code corresponding to the i-th target data segment, and verify the readback data based on the current Hamming code. If the verification result shows that there is a 1-bit error in the readback data, then 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 storage page determined by the third specified address; In other Flash write operations, the current data storage page is the next page after the previous current data storage page; The methods for determining the first duration include: If the verification result shows that the number of write errors in the readback data is greater than N in M consecutive Flash write operations, the first duration is set to the first value; where 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 is less than or equal to N in M consecutive data write operations, the first duration is determined based on the average utilization of the controller in the second duration. In response to the current write address of the EEPROM unit being a first specified address, the current write address of the EEPROM unit is initialized to a second specified address.
2. The data storage method as described in claim 1, characterized in that, Also includes: In response to receiving a data read instruction for the Flash unit, starting from the fourth specified address, the stored data of multiple data storage pages in the Flash unit is read sequentially; After reading the stored data of each data storage page, the 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 Hamming code other than the preset Hamming code, the stored data is corrected based on the first Hamming code.
3. The data storage method as described in claim 1, characterized in that, After verifying the readback data based on the current Hamming code, the method further includes: If the verification result shows that there are more than 2 bits of errors in the readback data, then 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.
4. The data storage method as described in claim 1, characterized in that, After writing the i-th target data segment to the current data storage page of the Flash unit, the method further includes: Calculate the current CRC checksum corresponding to the i-th target data segment; Write the current CRC checksum into the index area corresponding to the current data storage page in the EEPROM unit.
5. A data storage method as described in claim 1, characterized in that, Determining the first duration based on the controller's average usage over the second duration includes: If the average utilization rate of the controller during the second time period is greater than the first threshold, the first time period is set to the second value. If the average utilization rate of the controller during the second duration is less than or equal to the first threshold, the first duration is set to a third value; wherein the first value, the second value, and the third value increase sequentially.
6. A data storage device, disposed in a controller, characterized in that, The controller is installed in the energy meter, which also includes an EEPROM unit and a Flash unit. The device includes a loop module and a data writing module. The loop module is used to repeatedly perform data writing operations until a stop command is received. When performing the data write operation, the data write module is used to: The system writes data to be stored to the current write address of the EEPROM unit in real time and updates the cumulative writing time and the current write address; the cumulative writing time is determined based on the timestamp of the data to be stored. In response to the cumulative duration being greater than or equal to a first duration, the data written to the EEPROM unit within the cumulative duration is determined as target data, the target data is read from the EEPROM unit, written to the Flash unit, and the cumulative duration is cleared to zero; wherein, the Flash unit includes multiple data storage pages, each data storage page has a storage length of a first byte, and the EEPROM unit is provided with an index area corresponding to each data storage page; the step of writing the target data to the Flash unit includes: The target data is divided into multiple target data segments based on the first byte count; Starting from the third specified address, perform multiple Flash write operations until all target data has been 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, the data of the current data storage page is read back from the Flash unit to obtain the read-back data; Calculate the current Hamming code corresponding to the i-th target data segment, and verify the readback data based on the current Hamming code. If the verification result shows that there is a 1-bit error in the readback data, then 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 storage page determined by the third specified address; In other Flash write operations, the current data storage page is the next page after the previous current data storage page; The methods for determining the first duration include: If the verification result shows that the number of write errors in the readback data is greater than N in M consecutive Flash write operations, the first duration is set to the first value; where 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 is less than or equal to N in M consecutive data write operations, the first duration is determined based on the average utilization of the controller in the second duration. In response to the current write address of the EEPROM unit being a first specified address, the current write address of the EEPROM unit is initialized to a second specified address.
7. An electricity meter, characterized in that, The method includes an EEPROM unit, a Flash unit, a controller, a memory, and a computer program stored in the memory and running on the controller. The EEPROM unit and the Flash unit are used to store data to be stored. When the controller executes the computer program, it implements the steps of the method as described in any one of claims 1 to 5.
8. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Flash data storage method for intelligent electric energy meter
CN102339254A
Intelligent electric energy meter event storage method
CN116382578A