Data processing method and system of electric energy meter and electronic equipment

By combining FLASH memory and read-only memory in the power meter, the problem of data storage in the power meter is not reliable enough when the power meter is powered off, and more efficient and reliable data storage and recovery are achieved.

CN119536641APending Publication Date: 2025-02-28HOLLEY METERING LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411581647.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-07
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

The data storage of existing power meters is not reliable enough when power is powered off, resulting in data errors and difficulty in recovery, and the multi-backup mechanism increases storage requirements and operational complexity.

Method used

By setting up FLASH memory and read-only memory in the power meter, technical means such as data writing judgment, rewrite count judgment, data block division and power-on protection are used to ensure that the data can be correctly restored after power outage.

Benefits of technology

This method can save storage space, improve data storage efficiency and reliability of power meters when power is frequently lost, and ensure data integrity and correctness.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119536641A_ABST
    Figure CN119536641A_ABST
Patent Text Reader

Abstract

The invention provides a data processing method and system of an electric energy meter and electronic equipment. The data processing method comprises the following steps: judging whether to-be-stored data is successfully written into a FLASH memory or not; if not, judging whether the number of rewriting times is greater than a preset number of rewriting times or not; if yes, the rewriting frequency is increased, and a target backup data block is determined based on a preset data block division rule; setting a backed-up mark on the read-only memory, storing to-be-backed-up data except the to-be-stored data in the target backup data block into the read-only memory, and erasing the target backup data block; when it is detected that the electric energy meter is in the re-power-on state after power failure, whether a backup mark exists in the read-only memory or not is recognized; and if the backed-up mark is identified, reading a data address corresponding to the to-be-backed-up data in the read-only memory, and writing the to-be-backed-up data into the target backup data block. The storage space of the electric energy meter can be saved, and the data storage efficiency and storage reliability of the electric energy meter during frequent power failure can be improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of electric energy meter data processing, and in particular to an electric energy meter data processing method, system and electronic equipment. Background Art

[0002] In the data processing of electric energy meters, the preservation of key data after power failure and recovery after power-on are very critical indicators of product reliability. Most of the data errors that are not caused by device failures during field operation are related to the preservation of key data after power failure and recovery after power-on.

[0003] In the prior art, in order to solve the data storage problem during power failure, many electric energy meters adopt a multi-backup mechanism, that is, data is backed up through multiple storage areas, and after power is turned on, the data in the storage area with the majority consistency is selected for restoration. The multi-backup area mechanism ensures data correctness by the principle of minority obeys majority, but this increases storage requirements and operational complexity. Each time the data to be stored is written, a large storage space is required, resulting in reduced storage efficiency. Summary of the invention

[0004] In view of this, an object of the present invention is to provide a data processing method, system and electronic device for an electric energy meter, which can save storage space and improve the data storage efficiency and storage reliability of the electric energy meter when power failures occur frequently.

[0005] In a first aspect, an embodiment of the present invention provides a data processing method for an electric energy meter, wherein a FLASH memory and a read-only memory are provided in the electric energy meter; the method comprises: determining whether the data to be stored is successfully written into the FLASH memory; if the data to be stored is not successfully written into the FLASH memory, determining whether the number of rewrites is greater than a preset number of rewrites; if the number of rewrites is less than or equal to the number of rewrites, increasing the number of rewrites, and determining a target backup data block corresponding to the data to be stored based on a preset data block division rule; wherein the initial value of the number of rewrites is 0; setting a backed-up flag on the read-only memory, storing the data to be backed up in the target backup data block except the data to be stored in the read-only memory, and erasing the target backup data block; when it is detected that the electric energy meter is in a power-off and then power-on state, identifying whether there is a backed-up flag in the read-only memory; if the backed-up flag is identified, reading the data address corresponding to the data to be backed up in the read-only memory, and writing the data to be backed up into the target backup data block based on the data address.

[0006] Furthermore, the electric energy meter is provided with a random access memory; before the step of judging whether the data to be stored is successfully written into the FLASH memory, the method also includes: obtaining the data length and data starting address corresponding to the data to be stored in the random access memory; determining the data ending address corresponding to the data to be stored based on the data starting address and the data length; determining the first data block number corresponding to the data starting address and the second data block number corresponding to the data ending address based on the data block division rule; judging whether the first data block number and the second data block number are the same; if they are the same, determining the first data block number or the second data block number as the target write data block number, and writing the data to be stored into the target write data block; if they are not the same, determining the first data block number and the second data block number as the target write data block number, determining the data length corresponding to each target write data block number based on the data block division rule, and writing the data to be stored into the target write data block in sequence.

[0007] Furthermore, the step of determining whether the data to be stored is successfully written into the FLASH memory includes: based on a preset data readback method, performing data verification on the data to be stored to generate a data verification result; the data verification result is data consistency or data inconsistency; if the data verification result is data consistency, determining that the data to be stored is successfully written into the FLASH memory; if the data verification result is data inconsistency, determining that the data to be stored is not successfully written into the FLASH memory.

[0008] Furthermore, based on the preset data read-back method, the data to be stored is verified, and the steps of generating data verification results include: S1: obtaining the data to be stored in the random access memory, and based on the data starting address and the preset data block length, obtaining the data to be verified in the target write data block; S2: judging whether the data to be stored is consistent with the data to be verified; S3: if the data to be stored is consistent with the data to be verified, determining that the data verification result is data consistency; S4: if the data to be stored is inconsistent with the data to be verified, increasing the number of retries, and judging whether the increased number of retries is greater than the preset number of retries; if the increased number of retries is less than or equal to the preset number of retries, repeating steps S1-S2 until the increased number of retries is greater than the preset number of retries; determining that the data verification result is data inconsistency; wherein, the initial value of the number of retries is 0.

[0009] Furthermore, after the step of erasing the target backup data block, the method further includes: re-writing the data to be stored into the target write data block based on the target write data block number and the data length corresponding to the target write data block number.

[0010] Furthermore, the data to be stored is firmware upgrade data; the electric energy meter is connected to a host computer of the peripheral device in communication; before the step of obtaining the data length and data starting address corresponding to the data to be stored in the random access memory, the method also includes: if a firmware upgrade instruction sent by the host computer is received, based on the data block division rules and the data length of the firmware upgrade data, determining the upgrade data block number corresponding to the firmware upgrade data, and erasing the upgrade data block corresponding to the upgrade data block number.

[0011] Furthermore, after the step of writing the data to be backed up into the target backup data block based on the data address, the method also includes: based on a preset data read back method, performing data verification on the data to be backed up; generating a data verification result; the data verification result is data consistency or data inconsistency; if the data verification result is data consistency, the backed up flag in the read-only memory is modified to a no backup flag.

[0012] In a second aspect, an embodiment of the present invention provides a data processing system for an electric energy meter, wherein a FLASH memory and a read-only memory are provided in the electric energy meter; the system comprises: a data write judgment module, used to judge whether the data to be stored is successfully written into the FLASH memory; the data write judgment module is also used to judge whether the number of rewrites is greater than a preset number of rewrites if the data to be stored is not successfully written into the FLASH memory; the data write judgment module is also used to increase the number of rewrites by 1 if the number of rewrites is less than or equal to the number of rewrites, and determine the target backup data block corresponding to the data to be stored based on a preset data block division rule; wherein the initial value of the number of rewrites is 0; a data backup module, used to set a backed-up flag on the read-only memory, store the data to be backed up in the target backup data block except the data to be stored in the read-only memory, and erase the target backup data block; a power-on protection module, used to identify whether there is a backed-up flag in the read-only memory when it is detected that the electric energy meter is in a power-off and then powered on state; a power-on backup module, used to read the data address corresponding to the data to be backed up in the read-only memory if the backed-up flag is identified, and write the data to be backed up into the target backup data block based on the data address.

[0013] In a third aspect, an embodiment of the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method described above when executing the computer program.

[0014] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, on which a computer program is stored, and the program code enables the processor to execute the method as described above.

[0015] The embodiment of the present invention provides a data processing method, system and electronic device of an electric energy meter, wherein a FLASH memory and a read-only memory are provided in the electric energy meter; the method comprises: judging whether the data to be stored is successfully written into the FLASH memory; if the data to be stored is not successfully written into the FLASH memory, judging whether the number of rewrites is greater than the preset number of rewrites; if the number of rewrites is less than or equal to the number of rewrites, increasing the number of rewrites, and determining the target backup data block corresponding to the data to be stored based on the preset data block division rule; wherein the initial value of the number of rewrites is 0; setting a backed-up flag on the read-only memory, storing the data to be backed up in the target backup data block except the data to be stored in the read-only memory, and erasing the target backup data block; when it is detected that the electric energy meter is in a power-off and power-on state, identifying whether there is a backed-up flag in the read-only memory; if the backed-up flag is identified, reading the data address corresponding to the data to be backed up in the read-only memory, and writing the data to be backed up into the target backup data block based on the data address. In this way, the storage space of the electric energy meter can be saved, and the data storage efficiency and storage reliability of the electric energy meter can be improved when power is frequently off.

[0016] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention are realized and obtained by the structures particularly pointed out in the description, claims and drawings.

[0017] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0019] Figure 1 A flow chart of a data processing method for an electric energy meter provided in the first embodiment of the present invention;

[0020] Figure 2 A flow chart of a method for writing data to be stored into a target data block provided in Embodiment 1 of the present invention;

[0021] Figure 3 A flow chart of a method for determining whether the data to be stored is successfully written into the FLASH memory provided in the first embodiment of the present invention;

[0022] Figure 4 A flow chart of a method for generating data verification results provided in Embodiment 1 of the present invention;

[0023] Figure 5 A schematic diagram of a data processing system for an electric energy meter provided in Embodiment 2 of the present invention.

[0024] Icons: 1-data writing judgment module; 2-data backup module; 3-power-on protection module; 4-power-on backup module. DETAILED DESCRIPTION

[0025] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0026] When the energy meter records the load curve according to the preset time period, the length of the data written may be large (for example, capturing multiple data objects), resulting in the data occupying more FLASH memory space. In this case, if the writing process is interrupted by power failure, it may cause data confusion and garbled characters, and cannot be restored.

[0027] For example, when the energy meter writes the third load curve record of 100 bytes at address 200, if power is lost during the writing process, the Flash cannot complete the writing operation. In the old program logic, the unfinished data will be lost, and after the system is restarted, the content in the range of addresses 200 to 250 may be confused due to incomplete writing. Subsequent data will continue to be written to this address, causing more serious data confusion.

[0028] In the actual application of electric energy meters, firmware updates and optimizations are frequently required. When electric energy meters are connected to the network on site, they need to support firmware upgrades by transmitting upgrade packages to multiple devices through broadcasting. Due to cost constraints, firmware data can only be stored in the FLASH memory of the electric energy meter and sent through broadcast frames. For example, in a power line carrier (PLC) environment, 103 bytes of data per frame are sent to the device.

[0029] Assume that the upgrade package size is 500KB, which needs to be divided into about 4970 data packets for sending. When the network is poor, the device may skip packets during the reception process (for example, the reception order is packets 0, 2, 3...9, and packet 1 is lost). After the broadcast is completed, the system needs to resend the lost packets to complete them. When the old solution processes cross-block data, every time a data packet spans two storage blocks, the system will perform repeated operations of "erase-write-erase-write". If packet D39 spans storage blocks and is lost, the system will affect the subsequent writing of D40 and D41 due to the erase operation, resulting in multiple write failures and even the final verification failure, causing the entire upgrade process to be broadcast again from the beginning, which is time-consuming and inefficient, especially when the network is poor. The upgrade efficiency is even lower.

[0030] This application is applicable to scenarios where the electric energy meter performs power-off protection and data recovery when recording load curve data. This application is also applicable to the firmware upgrade process of the electric energy meter, especially in cases where the network environment is poor and data packets are prone to loss. Based on this application, the storage space of the electric energy meter can be saved, the data storage efficiency and storage reliability of the electric energy meter can be improved when power is frequently lost, and the success rate of the upgrade can be effectively improved.

[0031] To facilitate understanding of this embodiment, the embodiment of the present invention is described in detail below.

[0032] Embodiment 1:

[0033] Figure 1 This is a flow chart of a data processing method for an electric energy meter provided in Embodiment 1 of the present invention.

[0034] The electric energy meter is provided with a FLASH memory and a read-only memory (EEPROM, Electrically ErasableProgrammable Read-Only Memory).

[0035] Reference Figure 1 , a data processing method for an electric energy meter includes:

[0036] Step S101, determining whether the data to be stored is successfully written into the FLASH memory.

[0037] Here, the data to be stored may be load curve data or firmware upgrade data. The firmware upgrade data is a bin file (Binary File), which is a file that stores data in binary format, usually including program code, data, firmware and other information, directly represented in the form of binary numbers.

[0038] The electric energy meter is also provided with a random access memory (RAM).

[0039] Random Access Memory is a high-speed volatile memory that loses data when power is removed. The cache area storing data in RAM allows for fast reading and writing, reducing direct interaction with FLASH, which has a relatively slow read and write speed. The cache area in RAM buffers data and provides a temporary storage space for processing and verification. RAM is much faster than FLASH, so it can speed up the temporary processing of data.

[0040] FLASH memory is a non-volatile memory, usually used to store long-term data, such as firmware, configuration files, logs, user data, etc. Since FLASH has a slow write speed and a limited erase and write life, data is generally first stored in the cache area in RAM, and then written to FLASH in batches after verification or processing.

[0041] After executing the data storage operation, it will check whether the data has been successfully written to the FLASH memory. The purpose of judging whether the writing is successful is to ensure the integrity of the data storage and prevent data loss or errors.

[0042] Specifically, when the electric energy meter records load curve data or stores firmware upgrade data, the data is written into the FLASH memory. After the writing is completed, a read-back comparison check is immediately performed to confirm whether the data is written successfully. If the read-back data is consistent with the original data, the system determines that the writing is successful; otherwise, the writing is judged to have failed and proceed to the next step.

[0043] Reference Figure 2 Before step S101, the method further includes:

[0044] Step S201, obtaining the data length and data start address corresponding to the data to be stored in the random access memory.

[0045] Here, the length of the load curve data to be stored and the start address in the FLASH are obtained from the RAM to determine the data storage range.

[0046] Specifically, the electric energy meter records the load curve data at set time intervals and stores the data in FLASH. The length of the load curve data is relatively small, but it needs to be written frequently, so the writing operation is required to have high efficiency and data integrity.

[0047] In one embodiment, the data to be stored is firmware upgrade data; the electric energy meter is communicatively connected to a host computer of the peripheral device.

[0048] Here, the host computer is used to send the firmware upgrade data uploaded by the user to the electric energy meter. The firmware upgrade data is used to update the function and software version of the electric energy meter. The host computer can be a computer or a remote server.

[0049] The electric energy meter needs to store a large firmware upgrade file (bin file). Usually, the bin file data is received by broadcast packetization and written into FLASH. Due to the large amount of bin file data, the data packet writing process may span multiple data blocks.

[0050] Before step S201, the method further includes:

[0051] If a firmware upgrade instruction is received from the host computer, the upgrade data block number corresponding to the firmware upgrade data is determined based on the data block division rule and the data length of the firmware upgrade data, and the upgrade data block corresponding to the upgrade data block number is erased.

[0052] Here, when the electric energy meter receives the firmware upgrade instruction sent by the host computer, the firmware upgrade process is started. According to the preset data block division rules and the total length of the firmware upgrade data, the specific data block number where the upgrade data needs to be stored is determined. To ensure that the storage space is clean and correct, the system will first erase the corresponding data block to make room for the new firmware data.

[0053] Specifically, suppose that the host computer sends a firmware upgrade instruction to the energy meter, requiring the upgrade of the firmware file, which is 500KB in size. The flash memory of the energy meter has been divided into data blocks of 4KB each. Based on the size of the 500KB firmware file, the system calculates the data block numbers required for the upgrade (for example, from block number 20 to block number 144), and then erases these data blocks in sequence to ensure that these areas can be used to receive new firmware data.

[0054] Step S202, determining a data end address corresponding to the data to be stored based on the data start address and the data length corresponding to the data to be stored.

[0055] Here, the end address of the data in FLASH is calculated based on the start address and data length in FLASH.

[0056] Step S203: Determine the first data block number corresponding to the data start address and the second data block number corresponding to the data end address based on the data block division rule.

[0057] Here, according to the preset data block division rules, the data is mapped to the specific data block in FLASH. According to the storage block division rules of FLASH, the data block number corresponding to the start address and the end address is found to determine whether the data spans multiple storage blocks. For example, FLASH can be divided into multiple data blocks, each of which has a fixed size. According to the start address and the end address, the system can find the corresponding first and last data block numbers.

[0058] Specifically, assuming that the FLASH memory is divided into data blocks of 4 KB each, the start address 200 and the end address 299 are both in the same 4 KB data block, and the data block is numbered 5.

[0059] Step S204, determining whether the first data block number is the same as the second data block number.

[0060] Here, it is determined whether the data to be stored spans more than one data block. If the data block numbers corresponding to the start and end addresses are the same, it means that the data does not span blocks; if they are different, it means that the data spans multiple data blocks.

[0061] Specifically, assuming that the data block numbers corresponding to the start address 200 and the end address 299 are the same (number 5), the data is in one data block.

[0062] Step S205: If they are the same, determine that the first data block number or the second data block number is the target write data block number, and write the data to be stored into the target write data block.

[0063] Here, if the data to be stored is completely located in the same data block, the system will directly set the data block number as the target write block and write the data to be stored into the data block.

[0064] Step S206, if they are not the same, determine the first data block number and the second data block number as the target write data block number, determine the data length corresponding to each target write data block number based on the data block division rule, and write the data to be stored into the target write data block in sequence.

[0065] Here, if the data to be stored spans multiple data blocks, the system will set both the start block and the end block as the target write block. Then, according to the data block division rule, the data to be stored is split into multiple parts and written into the corresponding data blocks in sequence.

[0066] Specifically, when the data to be stored is load curve data, it is assumed that the length of the load curve data of the electric energy meter is 50 bytes, and the starting address planned to be stored in the FLASH is 100. The starting address is 100, and the data length is 50 bytes, so the ending address in the FLASH is 149. Assuming that the size of each data block of the FLASH memory is 4KB, the starting address 100 and the ending address 149 are both located in the data block numbered 0. Therefore, the first data block number and the second data block number are both 0. The starting address and the ending address are both in the data block numbered 0, so the data does not cross blocks. The data block numbered 0 is determined as the target write data block, and 50 bytes of load curve data are written into the range from address 100 to 149 in the FLASH memory.

[0067] When the data to be stored is firmware upgrade data, it is assumed that a bin file data packet is received with a length of 128 bytes, and the starting address planned to be stored in FLASH is 200. The starting address of the data packet is 200 and the length is 128 bytes, so the ending address in FLASH is 327. If the size of each data block of FLASH is 4KB, the starting address 200 and the ending address 327 are both located in the data block numbered 0, so the first and second data blocks are both numbered 0. The starting address and the ending address are both in the data block numbered 0, so the data packet does not cross blocks. Determine the data block numbered 0 as the target write data block, and write the 128-byte bin file data packet to addresses 200 to 327 in the FLASH memory.

[0068] If the data to be stored spans multiple data blocks in the load curve recording or bin file storage scenario, the identification data spans multiple data blocks, and the first and second data block numbers are set as the target write data block numbers. According to the data block division rule, the write data length in each target data block is calculated, and the system writes the data into the corresponding data blocks in sequence.

[0069] For example, if the starting address of the load curve data or firmware upgrade data packet is 3800 and the length is 500 bytes, the data will span two data blocks, number 0 (address 3800) and number 1 (address 4300). The system writes the first 224 bytes to data block number 0 and the remaining 276 bytes to data block number 1 to ensure complete data storage.

[0070] In one embodiment, referring to Figure 3 The steps of step S101 include:

[0071] Step S301 , based on a preset data read-back method, data verification is performed on the data to be stored to generate a data verification result; the data verification result is data consistency or data inconsistency.

[0072] Here, after the data is written into the FLASH memory, the system will read back the data just written and compare it with the original data to ensure the correctness of the writing. The data verification result will indicate whether the data is consistent.

[0073] Step S302: If the data verification result is that the data is consistent, it is determined that the data to be stored is successfully written into the FLASH memory.

[0074] Here, when the verification result is that the data is consistent, it is confirmed that the data to be stored has been successfully written into the FLASH memory, indicating that no error occurs in the writing process.

[0075] Step S303: If the data verification result is that the data is inconsistent, it is determined that the data to be stored is not successfully written into the FLASH memory.

[0076] Here, if the data verification result shows that the data is inconsistent, it is judged that the current data has not been successfully written, which may be caused by power failure, interference, etc. The writing is marked as failed and a re-writing operation is triggered.

[0077] Specifically, when the data to be stored is load curve data, it is assumed that the electric energy meter records 50 bytes of load curve data every 15 minutes and writes it to a specific address in the FLASH. After writing, 50 bytes of data are immediately read back from the address and compared byte by byte with the original load curve data. If the comparison results are exactly the same, the data is considered to be written successfully, otherwise it is judged to be a write failure. If the data is written successfully, the data of the next time period can continue to be recorded in the FLASH. If the write fails, this record is marked as a write failure. Subsequently, the write can be retried according to the preset retry mechanism to ensure the integrity of the load curve data.

[0078] When the data to be stored is firmware upgrade data, each bin file consists of multiple small data packets, which need to be written one by one into the FLASH memory of the electric energy meter, and after each write, the integrity and correctness of the data packet need to be ensured. Assume that the electric energy meter receives a 128-byte bin file data packet and writes the data packet to a specific address in the FLASH (for example, address 3000). After the write is completed, 128 bytes of data are read back from address 3000, and the read-back data is compared byte by byte with the original data packet. If each byte matches, a data consistency verification result is generated, indicating that the data packet is written successfully; otherwise, a data inconsistency verification result is generated. If the data is written successfully, the write success is recorded, and the next data packet of the bin file is prepared to continue the write operation. If the write fails, the write failure of this data packet is marked, and a retry operation is triggered. The electric energy meter may re-request the data packet to ensure that this part of the bin file can be correctly written into the FLASH to avoid errors in the subsequent upgrade process.

[0079] In one embodiment, referring to Figure 4 , the steps of step S301 include:

[0080] Step S1: obtaining data to be stored in a random access memory, and obtaining data to be verified in a target write data block based on a data start address and a preset data block length.

[0081] Here, firstly, the data to be stored (e.g., load curve recording data or bin file data packet) and its length are obtained from the RAM, and the starting address of the data in the FLASH memory is recorded. Then, according to the starting address and data length, the written data of the same length is read from the target write data block of the FLASH as the data to be verified for comparison.

[0082] Specifically, assume that the energy meter is going to write a 128-byte load curve data to the address 1000 in the FLASH memory. The system obtains the 128-byte data from the RAM and reads back the 128-byte data of the same length from the FLASH address 1000 to 1127 as the data to be verified, so as to compare with the data to be stored.

[0083] Step S2: Determine whether the data to be stored is consistent with the data to be verified.

[0084] Here, the data to be stored in the RAM is compared byte by byte with the data to be verified read back from the FLASH to confirm whether the writing is successful.

[0085] Specifically, the 128 bytes of load curve data to be written in the RAM are compared byte by byte with the 128 bytes of data read back from FLASH addresses 1000 to 1127. If all bytes match, the data are consistent, otherwise the data are inconsistent.

[0086] Step S3: If the data to be stored is consistent with the data to be verified, the data verification result is determined to be data consistency.

[0087] Here, if the comparison results are consistent, the data verification result is determined to be data consistency, indicating that the data has been correctly written and no further operation is required.

[0088] Specifically, in the comparison, if the data to be stored and the data to be verified are completely consistent, the data verification result is determined to be set as data consistency. The data record to be stored is considered to have been successfully written into the FLASH.

[0089] Step S4: If the data to be stored is inconsistent with the data to be verified, increase the number of retries and determine whether the increased number of retries is greater than the preset number of retries; if the increased number of retries is less than or equal to the preset number of retries, repeat steps S1-S2 until the increased number of retries is greater than the preset number of retries; determine that the data verification result is inconsistent data; wherein, the initial value of the number of retries is 0.

[0090] Here, if the comparison result shows that the data is inconsistent, the number of retries is increased by 1, and it is determined whether the preset maximum number of retries has been reached (pre-set according to the actual situation, which can be set to 3). If the number of retries has not reached the upper limit, S1 and S2 are repeated, and the data is read back from the FLASH again and compared. If the number of retries exceeds the preset upper limit and is still inconsistent, the data verification result is set to inconsistent and the retry is terminated.

[0091] Specifically, suppose that the 64th byte in the FLASH is found inconsistent with the data in the RAM in the first comparison. Increase the number of retries from 0 to 1, and read back 128 bytes from FLASH addresses 1000 to 1127 and compare again. If there is still inconsistency after 3 retries, set the verification result as data inconsistency and record the write failure.

[0092] Step S102: If the data to be stored is not successfully written into the FLASH memory, it is determined whether the number of rewrite times is greater than a preset number of rewrite times.

[0093] Here, when writing fails, check whether the current rewrite times exceed the preset maximum retry times (which can be preset according to actual conditions, and can be set to 3). If the rewrite times exceed the maximum retry times, the current write operation is abandoned, error information is recorded, or further fault processing is triggered. The maximum retry times are set to prevent the system from affecting the storage life or system performance due to unlimited rewrites.

[0094] Specifically, assuming that the preset upper limit of the number of rewrites is 3, after detecting the first write failure, it will be determined whether the current number of rewrites is less than 3. If it is less than 3, it will proceed to the next step of rewriting; if it is equal to or greater than 3, it will abandon the writing and record the error.

[0095] Step S103, if the number of rewrite times is less than or equal to the number of rewrite times, increase the number of rewrite times, and determine the target backup data block corresponding to the data to be stored based on the preset data block division rule; wherein the initial value of the number of rewrite times is 0.

[0096] Here, if the number of rewrites is less than a preset value, the number of rewrites is increased by 1, and the target backup data block to which the data to be stored needs to be written is determined according to the data block division rule.

[0097] Specifically, assuming that the current rewrite count is 1, which is less than the preset rewrite count of 3, the rewrite count is increased to 2. The target backup data block to which the data to be stored needs to be written is determined according to the data block division rule. For example, the data can be allocated to the backup data block numbered 5.

[0098] Step S104, setting a backed-up flag on the read-only memory, storing the data to be backed up except the data to be stored in the target backup data block into the read-only memory, and erasing the target backup data block.

[0099] Here, before attempting to rewrite, the existing valid data in the target data block will be backed up first to avoid data loss caused by the erase operation. The data is stored in a read-only memory (such as EEPROM), and the backed-up flag is set to indicate the backup status, and then the target data block is erased to prepare for writing the new data to be stored.

[0100] Specifically, if the target data block 5 contains other key data in addition to the load curve data to be written, the system will first transfer these data to the EEPROM to prevent the original data from being lost when erasing data block 5. At the same time, the "backed up" flag is set on the read-only memory, and then the erasing operation of data block 5 is performed.

[0101] In one embodiment, after the step of erasing the target backup data block in step S104, the method further includes:

[0102] Based on the target write data block number and the data length corresponding to the target write data block number, the data to be stored is re-written into the target write data block.

[0103] Here, after erasing the target backup data block, the data to be stored is rewritten to the data block according to the target data block number and data length, ensuring that the data to be stored can be completely written to the designated location after the data block is cleared.

[0104] Specifically, assume that the electric energy meter records 50 bytes of load curve data in a time period, and writes data block number 5 in the FLASH, with a starting address of 1000 and a length of 50 bytes. After writing and reading back for verification, it is found that the written data is inconsistent with the original data, which may be caused by power failure or interference. The load curve data needs to be rewritten according to the steps.

[0105] Based on the pre-recorded data block number and data length, it is determined that the target data block number is 5 and the data length is 50 bytes.

[0106] Locate the target data block 5 in FLASH and rewrite the 50-byte load curve data from RAM to addresses 1000 to 1049.

[0107] After the rewrite is completed, read back and compare again to ensure data consistency. If the comparison is successful, it is confirmed that the data has been stored completely.

[0108] Assume that when the electric energy meter is upgrading its firmware, it receives a 128-byte data packet through the network, and plans to write the target data block number to the FLASH as 8, the starting address as 2000, and the data length as 128 bytes. After the first write and read back verification, the data is found to be inconsistent, so the data packet needs to be rewritten.

[0109] Based on the pre-recorded data block number and data length, it is determined that the target data block number is 8 and the data length is 128 bytes.

[0110] Locate the target data block 8 in FLASH and rewrite the 128-byte bin file data packet from RAM to FLASH address 2000 to 2127.

[0111] After rewriting, read back and check again to confirm data consistency. If the check is consistent, the data packet is stored successfully and the next data packet can be received and stored.

[0112] Step S105, when it is detected that the electric energy meter is in a power-on state after power failure, it is identified whether there is a backup flag in the read-only memory.

[0113] Here, if the electric energy meter loses power during the rewriting process, when it is powered on again, it checks whether there is a backup mark in the read-only memory to confirm whether the data needs to be restored. If the backup mark exists, it means that the previous writing operation is not completed, and the data recovery operation will be performed.

[0114] Specifically, suppose that during the process of writing the load curve, the electric energy meter loses power and then powers on again. After detecting that the electric energy meter restarts, check whether there is a backup flag in the EEPROM. If there is such a flag, it means that the backup data of the target data block 5 has been stored in the EEPROM and needs to be restored from it.

[0115] Step S106: if the backup flag is identified, read the data address corresponding to the data to be backed up in the read-only memory, and write the data to be backed up into the target backup data block based on the data address.

[0116] Here, if the system detects a backup flag in the read-only memory, it means that the original data block has been backed up before power failure. The backup data and its corresponding address are obtained from the read-only memory and restored to the target data block to ensure data integrity.

[0117] Specifically, after the electric energy meter detects the existence of the backup flag in the EEPROM, it reads the key data and storage address backed up in the EEPROM, and rewrites the data into the target data block 5 of the FLASH to ensure that the data is not lost due to power failure. After the write is successful, the backup flag will be cleared to complete the data recovery operation.

[0118] In one embodiment, after the step of writing the to-be-backed-up data into the target backup data block based on the data address in step S106, the method further includes:

[0119] Based on the preset data read-back method, data verification is performed on the backup data; a data verification result is generated; and the data verification result is data consistency or data inconsistency.

[0120] Here, after the writing of the data to be backed up is completed, the written data is read back from the target backup data block by a preset data read-back method, and compared with the original data to be backed up, and a verification result of data consistency or data inconsistency is generated according to the comparison result.

[0121] Specifically, assume that when the electric energy meter performs power-off protection, it backs up key operation data (such as the latest load curve data) to the target backup data block address 2000. After writing, the data at address 2000 is read back and compared byte by byte with the original load curve data. If the read-back data is completely consistent, a data consistency verification result is generated; otherwise, a data inconsistency result is generated.

[0122] If the data verification result is that the data is consistent, the backed-up flag in the read-only memory is changed to a no-backup flag.

[0123] Here, if the data verification result shows that the data is consistent, indicating that the data has been successfully backed up, the flag status in the read-only memory will be updated, and the "backed up" flag will be changed to the "not backed up" flag.

[0124] The embodiment of the present invention provides a data processing method for an electric energy meter, in which a FLASH memory and a read-only memory are provided; the method comprises: judging whether the data to be stored is successfully written into the FLASH memory; if the data to be stored is not successfully written into the FLASH memory, judging whether the number of rewrites is greater than the preset number of rewrites; if the number of rewrites is less than or equal to the number of rewrites, increasing the number of rewrites, and determining the target backup data block corresponding to the data to be stored based on the preset data block division rule; wherein the initial value of the number of rewrites is 0; setting a backed-up flag on the read-only memory, storing the data to be backed up in the target backup data block except the data to be stored in the read-only memory, and erasing the target backup data block; when it is detected that the electric energy meter is in a power-off and power-on state, identifying whether there is a backed-up flag in the read-only memory; if the backed-up flag is identified, reading the data address corresponding to the data to be backed up in the read-only memory, and writing the data to be backed up into the target backup data block based on the data address. In this way, the storage space of the electric energy meter can be saved, and the data storage efficiency and storage reliability of the electric energy meter can be improved when power is frequently off.

[0125] Embodiment 2:

[0126] Figure 5 A schematic diagram of a data processing system for an electric energy meter provided in Embodiment 2 of the present invention.

[0127] The electric energy meter is provided with a FLASH memory and a read-only memory.

[0128] Reference Figure 5 , the data processing system of the electric energy meter includes:

[0129] The data writing judgment module 1 is used to judge whether the data to be stored is successfully written into the FLASH memory.

[0130] The data writing judgment module 1 is also used to judge whether the rewriting times are greater than the preset rewriting times if the data to be stored is not successfully written into the FLASH memory.

[0131] The data writing judgment module 1 is also used to increase the number of rewrites by 1 if the number of rewrites is less than or equal to the number of rewrites, and determine the target backup data block corresponding to the data to be stored based on the preset data block division rule; wherein the initial value of the number of rewrites is 0.

[0132] The data backup module 2 is used to set a backed-up flag on the read-only memory, store the data to be backed up except the data to be stored in the target backup data block into the read-only memory, and erase the target backup data block.

[0133] The power-on protection module 3 is used to identify whether there is a backup flag in the read-only memory when it is detected that the electric energy meter is in a power-on state after power failure.

[0134] The power-on backup module 4 is used to read the data address corresponding to the data to be backed up in the read-only memory if the backup flag is identified, and write the data to be backed up into the target backup data block based on the data address.

[0135] In one embodiment, a random access memory is provided in the electric energy meter. The data writing judgment module 1 is also used for:

[0136] Obtain the data length and data start address corresponding to the data to be stored in the random access memory.

[0137] Based on the data start address and the data length corresponding to the data to be stored, the data end address corresponding to the data to be stored is determined.

[0138] Based on the data block division rule, a first data block number corresponding to the data start address and a second data block number corresponding to the data end address are determined.

[0139] It is determined whether the first data block number and the second data block number are the same.

[0140] If they are the same, it is determined that the first data block number or the second data block number is the target write data block number, and the data to be stored is written into the target write data block.

[0141] If they are not the same, determine the first data block number and the second data block number as the target write data block number, determine the data length corresponding to each target write data block number based on the data block division rule, and write the data to be stored into the target write data block in sequence.

[0142] In one embodiment, the data writing judgment module 1 is further used for:

[0143] Based on the preset data read-back method, data verification is performed on the data to be stored to generate a data verification result; the data verification result is data consistency or data inconsistency.

[0144] If the data verification result is that the data is consistent, it is determined that the data to be stored is successfully written into the FLASH memory.

[0145] If the data verification result is that the data is inconsistent, it is determined that the data to be stored is not successfully written into the FLASH memory.

[0146] In one embodiment, the data writing judgment module 1 is further used for:

[0147] S1: Acquire the data to be stored in the random access memory, and based on the data start address and the preset data block length, acquire the data to be verified in the target write data block.

[0148] S2: Determine whether the data to be stored is consistent with the data to be verified.

[0149] S3: If the data to be stored is consistent with the data to be verified, determine that the data verification result is consistent.

[0150] S4: If the data to be stored is inconsistent with the data to be verified, increase the number of retries and determine whether the increased number of retries is greater than the preset number of retries; if the increased number of retries is less than or equal to the preset number of retries, repeat steps S1-S2 until the increased number of retries is greater than the preset number of retries; determine that the data verification result is inconsistent data; wherein, the initial value of the number of retries is 0.

[0151] In one embodiment, the data backup module 2 is further used for:

[0152] Based on the target write data block number and the data length corresponding to the target write data block number, the data to be stored is re-written into the target write data block.

[0153] In one embodiment, the data to be stored is firmware upgrade data; the electric energy meter is in communication connection with the host computer of the peripheral device. The data writing judgment module 1 is also used for:

[0154] If a firmware upgrade instruction is received from the host computer, the upgrade data block number corresponding to the firmware upgrade data is determined based on the data block division rule and the data length of the firmware upgrade data, and the upgrade data block corresponding to the upgrade data block number is erased.

[0155] In one embodiment, the data writing judgment module 1 is further used for:

[0156] Based on the preset data read-back method, data verification is performed on the backup data; a data verification result is generated; and the data verification result is data consistency or data inconsistency.

[0157] If the data verification result is that the data is consistent, the backed-up flag in the read-only memory is changed to a no-backup flag.

[0158] An embodiment of the present invention provides a data processing system for an electric energy meter, in which the storage space of the electric energy meter can be saved, and the data storage efficiency and storage reliability of the electric energy meter can be improved when power failures occur frequently.

[0159] An embodiment of the present invention further provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the data processing method for the electric energy meter provided in the above embodiment are implemented.

[0160] An embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the steps of the data processing method of the electric energy meter in the above embodiment are executed.

[0161] The computer program product provided in the embodiment of the present invention includes a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be found in the method embodiment and will not be repeated here.

[0162] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0163] In addition, in the description of the embodiments of the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", and "connected" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, or it can be the internal communication of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0164] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., which can store program codes.

[0165] In the description of the present invention, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer", etc., indicating the orientation or positional relationship, are based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as limiting the present invention. In addition, the terms "first", "second", and "third" are used for descriptive purposes only, and cannot be understood as indicating or implying relative importance.

[0166] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A data processing method for an electric energy meter, characterized in that: The electric energy meter is provided with a FLASH memory and a read-only memory; the method comprises: Determine whether the data to be stored is successfully written into the FLASH memory; If the data to be stored is not successfully written into the FLASH memory, determining whether the number of rewrites is greater than a preset number of rewrites; If the number of rewrite times is less than or equal to the number of rewrite times, increase the number of rewrite times, and determine the target backup data block corresponding to the data to be stored based on a preset data block division rule; wherein the initial value of the number of rewrite times is 0; Setting a backed-up flag on the read-only memory, storing the data to be backed up in the target backup data block except the data to be stored in the read-only memory, and erasing the target backup data block; When it is detected that the electric energy meter is in a power-on state after power failure, identifying whether the backup flag exists in the read-only memory; If the backed-up flag is identified, the data address corresponding to the data to be backed up in the read-only memory is read, and the data to be backed up is written into the target backup data block based on the data address.

2. The data processing method of the electric energy meter according to claim 1, characterized in that: The electric energy meter is provided with a random access memory; Before the step of determining whether the data to be stored is successfully written into the FLASH memory, the method further includes: Obtaining the data length and data starting address corresponding to the data to be stored in the random access memory; Determine a data end address corresponding to the data to be stored based on the data start address and the data length corresponding to the data to be stored; Based on the data block division rule, determine a first data block number corresponding to the data start address and a second data block number corresponding to the data end address; Determining whether the first data block number and the second data block number are the same; If they are the same, determining that the first data block number or the second data block number is a target write data block number, and writing the data to be stored into the target write data block; If they are not the same, determine that the first data block number and the second data block number are the target write data block numbers, determine the data length corresponding to each target write data block number based on the data block division rule, and write the data to be stored into the target write data blocks in sequence.

3. The data processing method of the electric energy meter according to claim 2, characterized in that: The step of determining whether the data to be stored is successfully written into the FLASH memory comprises: Based on a preset data readback method, data verification is performed on the data to be stored to generate a data verification result; the data verification result is data consistency or data inconsistency; If the data verification result is that the data are consistent, it is determined that the data to be stored is successfully written into the FLASH memory; If the data verification result is that the data is inconsistent, it is determined that the data to be stored is not successfully written into the FLASH memory.

4. The data processing method of the electric energy meter according to claim 3, characterized in that: The step of performing data verification on the data to be stored based on the preset data readback method and generating a data verification result includes: S1: Acquire the data to be stored in the random access memory, and acquire the data to be verified in the target write data block based on the data start address and the preset data block length; S2: Determine whether the data to be stored is consistent with the data to be verified; S3: If the data to be stored is consistent with the data to be verified, determining that the data verification result is data consistency; S4: If the data to be stored is inconsistent with the data to be verified, increase the number of retries and determine whether the increased number of retries is greater than the preset number of retries; if the increased number of retries is less than or equal to the preset number of retries, repeat steps S1-S2 until the increased number of retries is greater than the preset number of retries; determine that the data verification result is data inconsistency; wherein the initial value of the number of retries is 0.

5. The data processing method of the electric energy meter according to claim 2, characterized in that: After the step of erasing the target backup data block, the method further includes: Based on the target write-in data block number and the data length corresponding to the target write-in data block number, the to-be-stored data is re-written into the target write-in data block.

6. The data processing method of the electric energy meter according to claim 2, characterized in that: The data to be stored is firmware upgrade data; the electric energy meter is in communication connection with a host computer of the peripheral device; Before the step of obtaining the data length and the data start address corresponding to the data to be stored in the random access memory, the method further includes: If a firmware upgrade instruction sent by the host computer is received, the upgrade data block number corresponding to the firmware upgrade data is determined based on the data block division rule and the data length of the firmware upgrade data, and the upgrade data block corresponding to the upgrade data block number is erased.

7. The data processing method of the electric energy meter according to claim 1, characterized in that: After the step of writing the to-be-backed-up data into the target backup data block based on the data address, the method further includes: Based on a preset data readback method, data verification is performed on the data to be backed up; a data verification result is generated; the data verification result is data consistency or data inconsistency; If the data verification result shows that the data is consistent, the backed-up flag in the read-only memory is modified to a no-backup flag.

8. A data processing system for an electric energy meter, characterized in that: The electric energy meter is provided with a FLASH memory and a read-only memory; the system comprises: A data writing judgment module is used to judge whether the data to be stored is successfully written into the FLASH memory; The data writing judgment module is further used to judge whether the rewriting times are greater than the preset rewriting times if the data to be stored is not successfully written into the FLASH memory; The data writing judgment module is further configured to increase the rewriting number by 1 if the rewriting number is less than or equal to the rewriting number, and determine the target backup data block corresponding to the data to be stored based on a preset data block division rule; wherein the initial value of the rewriting number is 0; A data backup module, used for setting a backed-up flag on the read-only memory, storing the data to be backed up in the target backup data block except the data to be stored in the read-only memory, and erasing the target backup data block; A power-on protection module, used for identifying whether the backup flag exists in the read-only memory when detecting that the electric energy meter is in a power-on state after power failure; The power-on backup module is used to read the data address corresponding to the data to be backed up in the read-only memory if the backup mark is identified, and write the data to be backed up into the target backup data block based on the data address.

9. An electronic device, characterized in that: It comprises a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and is characterized in that when the processor executes the computer program, the data processing method of the electric energy meter described in any one of claims 1 to 7 is implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and when the computer instructions are executed by a processor, the data processing method of the electric energy meter according to any one of claims 1 to 7 is implemented.