Information storage method, device and computer storage medium
By adopting a multi-data block index structure and fault-tolerant mechanism in the FLASH memory of the energy metering system, the problems of information loss and high power consumption of energy equipment after sleep are solved, and efficient, low-power information storage, reading and writing are achieved, extending the The service life of the memory.
Patent Information
- Application Number
- CN202210335688.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-31
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2042-03-31
AI Technical Summary
In the existing energy metering system, energy devices may lose stored accumulated information after sleeping, and the power consumption is high when storing, reading and writing through the file system, and cannot effectively support frequent reading and writing scenarios.
When a data acquisition instruction is detected in the FLASH memory, information is read and written, and a multi-data block index structure and fault-tolerant mechanism are used to avoid additional file system transplantation and improve storage efficiency and reliability.
There is no need to transplant additional file systems, which reduces power consumption in frequent wake-up reading and writing scenarios, improves storage efficiency and reliability of data storage, and extends the service life of FLASH memory.
Smart Images

Figure CN114780026B
Abstract
Description
Technical Field
[0001] The present application relates to the field of storage technology, and in particular to an information storage method, device and computer storage medium. Background Art
[0002] As people's daily living standards improve, their demand for smart cities is increasing, and smart cities are gradually attracting people's attention. Among them, energy is an important part of smart cities. After energy is consumed, the energy metering system will count the consumed energy. Therefore, the metering information in the energy metering system is the basic unit for the digital construction of smart cities.
[0003] Among them, the energy devices in the energy metering system record energy information by recording the cumulative energy consumption. That is, the energy device stores the cumulative information of energy. Each time from sleep to wake up, the energy device needs to use the stored cumulative information as the baseline value, and add it to the incremental data consumed this time to obtain new cumulative information and store it. If the cumulative information is stored in the memory of the energy device, the stored cumulative information may be lost after sleep, and continuous accumulation is impossible. At present, the energy device can store the cumulative information in the form of a specific file in the file system, read the cumulative information by calling the file reading interface, and write new cumulative information. However, the file system method requires additional porting of the file system, and in the scenario of frequent and large-scale writing, the power consumption is high, which may generate additional resource overhead and cannot well support the energy metering scenario of frequent reading and writing. Summary of the invention
[0004] The embodiments of the present application provide an information storage method, device and computer storage medium, which can read the information that has been written and write new information in the FLASH memory when a data acquisition instruction is detected. On the one hand, there is no need to transplant the file system additionally, thereby improving the storage efficiency. On the other hand, the service life and reliability of the FLASH memory can be improved by increasing the FLASH capacity.
[0005] In a first aspect, an embodiment of the present application provides an information storage method, which is applied to a FLASH memory, and the method includes:
[0006] In the case where a first data acquisition instruction is detected, reading the i-th information stored in the FLASH memory, the first data acquisition instruction carrying the first incremental data;
[0007] The i+1th piece of information is written into the FLASH memory, where the i+1th piece of information is determined based on the i-th piece of information and the first incremental data.
[0008] The FLASH memory includes a first data block and a second data block, and each of the data blocks includes N indexes and an information field corresponding to each of the indexes.
[0009] In one implementation, the N indexes have initial values; and the step of writing the i+1th piece of information into the FLASH memory includes:
[0010] Writing the i+1th piece of information into the information domain corresponding to the i+1th index of the first data block and the second data block; 1<=i<=N, i and N are both integers;
[0011] When the i+1th piece of information is successfully written into the information domain corresponding to the i+1th index of the first data block and the second data block, the values of the i+1th index of the first data block and the second data block are modified from the initial values to the preset values.
[0012] In one implementation, the FLASH memory further includes a third data block, and the third data block includes N indexes and an information field corresponding to each of the indexes; and the method further includes:
[0013] If writing the i+1th piece of information into the first data block fails, writing the i+1th piece of information into the information field corresponding to the i+1th index of the third data block;
[0014] When the i+1th piece of information is successfully written into the information field corresponding to the i+1th index of the third data block, the value of the i+1th index in the third data block is modified from the initial value to the preset value.
[0015] In one implementation, after the value of the i+1th index in the third data block is modified from the initial value to the preset value, the method further includes:
[0016] The values of the i indexes before the i+1th index among the N indexes in the third data block are all modified from the initial values to the preset values.
[0017] In one implementation, the i-th piece of information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the first data block, and the i-th index of the first data block is the last index among the N indexes of the first data block whose index value is equal to the preset value.
[0018] In one implementation, when reading information from the information field corresponding to the i-th index of the first data block fails, the i-th information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the second data block.
[0019] In one implementation, the method further includes:
[0020] In the case where a second data acquisition instruction is detected, reading the i+1th piece of information stored in the information field corresponding to the i+1th index in the third data block, the second data acquisition instruction carrying the second incremental data;
[0021] The i+2th piece of information is written into the information domain corresponding to the i+2th index of the first data block and the second data block, and the i+2th piece of information is determined based on the i+1th piece of information and the second incremental data.
[0022] In a second aspect, an embodiment of the present application provides an information storage device, which is applied to a FLASH memory. The information storage device includes:
[0023] A reading unit, configured to read the i-th piece of information stored in the FLASH memory when a first data acquisition instruction is detected, wherein the first data acquisition instruction carries first incremental data;
[0024] A writing unit is used to write the i+1th piece of information into the above-mentioned FLASH memory, where the above-mentioned i+1th piece of information is determined based on the above-mentioned i-th piece of information and the above-mentioned first incremental data.
[0025] In addition, in this aspect, other optional implementations of the information storage device can refer to the relevant content of the first aspect above, and will not be described in detail here.
[0026] In a third aspect, an embodiment of the present application provides a computer device, comprising a memory, a processor, and a transceiver; the processor is respectively connected to the memory and the transceiver, wherein the memory stores a computer program code, and the processor and the transceiver are used to call the program code to execute the method provided by the first aspect and / or any possible implementation of the first aspect.
[0027] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the method provided by the above-mentioned first aspect and / or any possible implementation method of the first aspect.
[0028] In the embodiment of the present application, the i-th piece of information stored in the FLASH memory is read when a data acquisition instruction carrying incremental data is detected, and the i+1-th piece of information is determined based on the i-th piece of information and the incremental data, and then the i+1-th piece of information is written into the FLASH memory. Therefore, this solution does not require additional transplantation of the file system to store cumulative information, avoids additional resource overhead, improves storage efficiency, reduces power consumption in frequent wake-up read and write scenarios, and introduces a fault-tolerant mechanism to increase the reliability of data storage, which can be applied to low-power energy metering scenarios where low-end embedded devices are frequently woken up from sleep for reading and writing. BRIEF DESCRIPTION OF THE DRAWINGS
[0029] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0030] Figure 1 It is a flowchart of an information storage method provided in an embodiment of the present application;
[0031] Figure 2 It is a schematic diagram of energy metering timing of an information storage method provided in an embodiment of the present application;
[0032] Figure 3 This is a schematic diagram of a process of reading data from a FLASH memory provided by an embodiment of the present application;
[0033] Figure 4 This is a schematic diagram of a process of writing data from a FLASH memory provided by an embodiment of the present application;
[0034] Figure 5 This is another schematic diagram of a process of writing data from a FLASH memory provided by an embodiment of the present application;
[0035] Figure 6 is a structural schematic diagram of an information storage device provided in an embodiment of the present application;
[0036] Figure 7 It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0037] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0038] Combine the following Figure 1-Figure 6 An information storage method provided in an embodiment of the present application is schematically illustrated.
[0039] At present, in energy metering systems, energy devices usually store cumulative information, that is, information on the cumulative consumption of a certain type of energy, such as water and electricity consumption. Energy devices can be water meters, electricity meters and other devices. Each time the energy device wakes up from sleep, the energy device needs to obtain the stored cumulative information as a baseline value, and add it to the incremental data consumed this time, so as to obtain new cumulative information and store it for the next use. If the cumulative information in the energy device is stored in the memory of the energy device, the stored cumulative information may be lost after sleep and cannot be accumulated again. If the cumulative information is stored in the file system in the form of a specific file, the cumulative information is read and the new cumulative information is written by calling the file's read interface. This method requires additional porting of the file system, and in the scenario of frequent and large-scale writing, the power consumption is high, and additional resource overhead may be generated.
[0040] Based on the above description, the present application embodiment provides an information storage method, which is applied to a FLASH memory. The information storage method of the present application embodiment can be referred to in Figure 1 , Figure 1 101 is a flowchart of an information storage method provided in an embodiment of the present application. The information storage method may include the following steps 101-102:
[0041] 101. When a first data acquisition instruction is detected, read the i-th information stored in the FLASH memory, wherein the first data acquisition instruction carries first incremental data.
[0042] Specifically, the information storage method in the embodiment of the present application can be applied to a FLASH memory, and can also be applied to an energy device including a FLASH memory. It should be noted that for the convenience of description, an energy device including a FLASH memory is used as an example for explanation. The first data acquisition instruction may refer to an instruction that after the energy device detects the current energy consumption (such as water flowing or electricity consumption), based on the incremental data of this energy consumption (first incremental data), the cumulative information stored in the FLASH memory is used as a reference value, and is accumulated with the incremental data of this consumption to obtain new cumulative information and store it again in the FLASH memory of the energy device. Furthermore, the new cumulative information is stored in the FLASH memory for use the next time the energy device detects a data acquisition instruction, and this is the case each time a data acquisition instruction is detected.
[0043] It is understandable that the information stored in the FLASH memory of the energy device is cumulative information, and is also the latest cumulative information, indicating the energy data that has been consumed. Exemplarily, the energy device may be a water meter, and the FLASH memory of the water meter stores the cumulative water use information, and the incremental data is the water use information when water flow is detected this time, such as the water consumption. Another exemplary example is that the energy device may also be an electric meter, and the FLASH memory of the electric meter stores the cumulative electricity consumption information, and the incremental data is the electricity consumption information when electricity consumption is detected this time, such as the electricity consumption, etc. This application does not limit the specific form of the energy device, which can be determined specifically according to the business scenario.
[0044] Please also read Figure 2 , Figure 2 : is a schematic diagram of energy metering timing of an information storage method provided in an embodiment of the present application. The process of energy equipment performing energy metering (ie, accumulation) each time can be as follows: Figure 2As shown, when a data acquisition instruction (first data acquisition instruction) is detected, the energy device is awakened and reads the i-th information stored in the FLASH memory. The i-th cumulative information may include the cumulative information accumulated when the data acquisition instruction was detected last time. Then, the energy device determines the i+1-th information according to the i-th information and the first incremental data carried by the first data acquisition instruction, and writes the i+1-th information into the FLASH memory. Further, the energy device enters sleep mode to save resources, and the accumulation process ends. Wherein, i can be a positive integer. Optionally, the energy device can also be awakened when a data acquisition instruction (such as a second data acquisition instruction carrying a second incremental data) is detected again, reads the i+1-th information stored in the FLASH memory, determines the i+2-th information according to the second incremental data and the i+1-th data, stores the determined i+2-th information in the FLASH memory, and enters sleep mode, and repeats this process.
[0045] Specifically, for the FLASH memory in the energy device, it is a non-volatile memory, and the information stored has high reliability. The principle of writing information in the FLASH memory, that is, programming the FLASH memory, is to change the data (bit) from 1 to 0, but not from 0 to 1. If the data in the FLASH memory is 1, if you want to write information in the FLASH memory again, you can write directly without erasing. If the data has been written into the FLASH memory, that is, part or all of the data is 0, you need to erase the FLASH memory first. The so-called erasing of the FLASH memory means changing all data (bits) to 1, and all bytes become 0xFF after erasing. The FLASH memory has a certain limit on the number of erase and write times, that is, the number of erase and write times is the life of the FLASH memory. For example, the number of erase and write times of the NOR FLASH memory is 100,000 times, and the life of the NOR FLASH memory is 100,000 erase and write times. In the process of erasing the FLASH memory, it can be erased in sectors or in blocks, which is not limited in this application and can be determined according to the business scenario and the model of the FLASH memory. The so-called sector refers to the smallest operation unit in the FLASH memory, and the so-called block refers to a part including multiple adjacent sectors, so as to facilitate overall reading and writing.
[0046] In a possible implementation, since the FLASH memory has a certain erasing and writing limit, in order to improve the life of the FLASH memory, the FLASH memory in the above energy device may include a first data block (block) for storing information, and the first data block may include two parts, a header and a block body, wherein the header may include block status information, N indexes, and the block body may include an information field corresponding to each index, that is, N information fields, and each information field may be used to store information. Among them, the status information in the header may include two states, namely 0 and non-0 states, which respectively indicate whether the current data block is in use, for example, 0 indicates that it is in use, and non-0 indicates that it is not in use. The N indexes have initial values, which can also be called default values. The initial value of the N indexes is 1. When information is written into the information field corresponding to a certain index, the value of the index is modified from the initial value to a preset value, and the preset value may be 0, that is, modified from 1 to 0, and the index is used to indicate that information has been written into the information field corresponding to the index. From this, it can be seen that if the data block is used as the erase unit, the frequency of the FLASH memory is reduced from writing information once and erasing it once to writing the N information fields in the first data block and then erasing it once. That is, the erase and write life of the FLASH memory is changed from 100,000 times to N 100,000 times, which improves the life of the FLASH memory and makes the FLASH memory expandable.
[0047] Exemplarily, the storage structure of the first data block can be as shown in Table 1, wherein the first data block includes 4096 bytes as an example for explanation, and other storage structures can also be used, and the present application does not limit this. As shown in Table 1, the block header of the first data block includes a 1-byte block state and 504 indexes (N=504), each index occupies 1 bit, that is, the 504 indexes occupy a total of 63 bytes (504 / 8=63), and the block body includes 504 information fields corresponding to the 504 indexes. As shown in Table 1, each information field can be used to store information, that is, to store information 1-information 504. Taking the erase and write life of 100,000 times as an example, the storage structure shown in Table 1 can extend the service life to 504 times, that is, write data 504 times and then erase it. Therefore, by increasing the storage capacity, the service life of the FLASH memory is improved, and it can also better support the energy metering scenario of frequent reading and writing.
[0048]
[0049] Table 1
[0050] Optionally, each information field may include 8 bytes of information, and the storage structure of each information may be as shown in Table 2. Each information may include a timestamp and a value, which may be the accumulated information stored after each consumption mentioned above, and may also include other information, which is not limited in this application.
[0051] Timestamp (4 bytes) Value (4 bytes)
[0052] Table 2
[0053] Specifically, the so-called reading of the i-th information stored in the FLASH memory may be that the information fields corresponding to the 1st index to the i-th index in the first data block and the second data block in the current FLASH memory have all been written with information, and the i-th information written in the information field corresponding to the i-th index, that is, the latest information (the last accumulated information), needs to be read this time, and the i+1th information is determined according to the i-th information and the first incremental data, and the i+1th information is written into the first data block. Among them, i is data greater than or equal to 1 and i is less than or equal to N. Among them, the reading of the i-th information stored in the first data block may be read from the information field corresponding to the i-th index of the first data block, that is, the information in the information field corresponding to the i-th index is read. Specifically, the reading process may be to first read the N indexes of the block header part, and when the index value of the i-th index is read to be the last index in the N indexes whose index value is equal to the preset value, the information stored in the information field corresponding to the i-th index is determined as the information to be read this time, and then the information in the information field corresponding to the i-th index in the block body part is read.
[0054] Exemplarily, for example, the first data block is shown in the structure of Table 1 above, taking i=5 as an example, first read the 504 indexes of the block header, determine that the initial value of the index is 1, and the preset value is 0, then if the value of the 5th index read is the last 0, for example, the 504 indexes are 000001111…111 (a total of 504), and the 5th 0 from left to right is the last 0, then determine that the information to be read is the information in the information domain corresponding to the 5th index from left to right. That is, the information stored in the information domain corresponding to the 5th 0 from left to right.
[0055] The above explanation is based on the example that the 504 indexes are in order from left to right, and the 504 indexes can also be in order from right to left. Exemplarily, the 504 indexes are 1111…11100000 (a total of 504), and the fifth 0 from right to left is the last 0 in the 504 indexes. Then, the information to be read is determined to be the information in the information domain corresponding to the fifth index from right to left, and similarly, the information stored in the information domain corresponding to the fifth 0 from right to left.
[0056] In a possible implementation, in order to ensure the accuracy of the read data, the FLASH memory may include, in addition to the first data block, a second data block having the same storage structure as the first data block, that is, the second data block also includes N indexes and information fields corresponding to each index, and the N information fields can be used to store information. The second data block can maintain completely consistent erase and write operations with the first data block, that is, the data in the second data block can be consistent with the data in the first data block, which is equivalent to the second data block being a backup of the first data block. It can be understood that the first data block and the second data block have different addresses and different identifiers, and the energy device can determine whether it is the first data block or the second data block based on different addresses or different identifiers.
[0057] Please also read Figure 3 , Figure 3 It is a schematic diagram of a process of reading data from a FLASH memory provided by an embodiment of the present application, including but not limited to steps 101a to 101b.
[0058] 101a. Read the i-th piece of information from the information field corresponding to the i-th index of the first data block.
[0059] Specifically, when the energy device reads the ith piece of information, it needs to first know the location where the ith piece of information is stored, that is, to determine which index corresponds to the information domain in which the information stored is the ith piece of information to be read. The energy device can first read the N indexes in the header part of the first data block. When the index value of the ith index read is the last index in the N indexes whose index value is equal to the preset value, the information stored in the information domain corresponding to the ith index is determined as the information to be read this time, and then the information in the information domain corresponding to the ith index in the block body is read. This is because when writing information, after writing information in the information domain corresponding to a certain index in sequence, the value of the index will be modified accordingly, so the location of the information to be read can be determined by reading the value of the index first. Among them, the value of the index is modified from the initial value to the preset value, so the information stored in the information domain corresponding to the last index whose value is the preset value in the sequence of N indexes is the information to be read this time.
[0060] 101b. When reading information from the information field corresponding to the ith index of the first data block fails, read the ith piece of information from the information field corresponding to the ith index of the second data block.
[0061] Among them, the first data block may have a read error, that is, the first data block cannot return the value in the i-th information read, and may directly return an error. In this case, it means that the information reading from the information field corresponding to the i-th index of the first data block fails, and the i-th information is read from the information field corresponding to the i-th index of the second data block. Therefore, the second data block can ensure that the read information is correct to a certain extent, that is, it can be fault-tolerant, that is, it can solve the problem of preventing read errors.
[0062] Optionally, when reading information from the second data block, the value of i may be known, for example, the value of i is 5. Since the storage structure of the second data block is the same as that of the first data block, and the read and write operations of the second data block are the same as those of the first data block, that is, the data can be kept consistent, then the fifth piece of information in the information domain corresponding to the fifth index can be directly read from the second data block according to the i-th index (the fifth index) determined by the first data block. Optionally, when reading information from the second data block, N indexes in the block header information of the second data block may be read first, and when the i-th index is read as the last index of the N indexes of the first data block whose index value is the preset value, the information in the information domain corresponding to the i-th index, that is, the i-th piece of information, is read, that is, the block header portion of the second data block may be read again to determine that the information read is in a specific information domain.
[0063] Furthermore, based on the first incremental data carried by the first acquisition instruction and the value included in the i-th piece of information, which is the cumulative information of the previous energy consumption, and the timestamp, the i+1-th piece of information, that is, the cumulative information of this energy consumption, is determined, and the i+1-th piece of information is written into the above-mentioned first data block and the second data block, such as the above-mentioned sixth piece of information.
[0064] 102. Write the (i+1)th piece of information into the FLASH memory, where the (i+1)th piece of information is determined based on the (i)th piece of information and the first incremental data.
[0065] Specifically, taking the structure of each piece of information as shown in Table 2 as an example, the i+1th value is determined according to the i-th piece of information and the first incremental data, and the timestamp is determined according to the current time information, thereby obtaining the i+1th piece of information, and then the i+1th piece of information can be written into the first data block and the second data block. Among them, the i+1th value in the i+1th piece of information can be the cumulative result of the value in the i-th piece of information and the first incremental data, such as the accumulation of water consumption and the accumulation of electricity consumption.
[0066] Please also read Figure 4 , Figure 4It is a schematic diagram of a process of writing data from a FLASH memory provided by an embodiment of the present application, including but not limited to steps 102a to 102d.
[0067] 102a. Write the (i+1)th piece of information into the information fields corresponding to the (i+1)th indexes of the first data block and the second data block.
[0068] Among them, the i+1th piece of information is written in the next information field of the i-th piece of information in the writing time order in the storage structure shown in the above Table 1, that is, the i+1th piece of information including the current timestamp and value is written into the information field corresponding to the i+1th index in the first data block and the second data block.
[0069] 102b. When the i+1th piece of information is successfully written into the information domain corresponding to the i+1th index of the first data block and the second data block, the values of the i+1th index of the first data block and the second data block are modified from the initial values to preset values.
[0070] Each index corresponds to an information field to identify whether information is written. If information is written, the value of the index is modified from an initial value (such as the initial value is 1) to a preset value (such as the preset value is 0) for subsequent reading.
[0071] In a possible implementation, for the FLASH memory, in addition to the service life, that is, the limit on the number of erase and write times, there is also the problem of fault tolerance, that is, if an error occurs in writing data, it cannot be modified and can only be erased again and rewritten. In an embodiment of the present application, in order to make the FLASH memory have fault-tolerant performance, the FLASH memory may also include a third data block, the storage structure of the third data block may be the same as the storage structure of the first data block and the second data block, and the third data block has an identifier and address different from the first data block and the second data block, so as to identify the third data block and subsequent writing. Among them, the third data block does not have to maintain completely consistent erase and write operations with the first data block. The third data block can be a blank data block, and the third data block is only used for fault-tolerant protection. That is, only when an error occurs in writing the first data block, information is written to the corresponding position in the third data block.
[0072] 102c. When writing the i+1th piece of information into the first data block fails, writing the i+1th piece of information into the information field corresponding to the i+1th index of the third data block.
[0073] Exemplarily, still taking the above i as 5 as an example, the i+1th piece of information is the 6th piece of information. When writing the 6th piece of information in the first data block fails, the 6th piece of information is written in the information field corresponding to the 6th index of the third data block. It should be noted that in the first data block, since the writing of the i-th piece of information fails, there is no need to modify the value of the i-th index in the first data block, that is, the value of the i-th index in the first data block is still the initial value (for example, the initial value is 1). Optionally, although the writing of the first data block fails, the i+1th piece of information is still written into the second data block, and the value of the i+1th index in the second data block can still be modified from the initial value to the preset value.
[0074] 102d. When the i+1th piece of information is successfully written into the information field corresponding to the i+1th index of the third data block, the value of the i+1th index in the third data block is modified from the initial value to the preset value.
[0075] Similarly, the i+1th information in the third data block can be used to indicate that the information domain corresponding to the i+1th index has been written. Optionally, the values of the i indexes before the i+1th index in the N indexes in the third data block can also be modified from the above initial values to the above preset values. Exemplarily, taking i as 5 as an example, in the case where writing the 6th information in the first data block fails, at this time, taking the third data block as a blank data block as an example, the values of the 504 indexes of the third data block are all initial values (for example, the initial value is 1), 111111…111 (504 in total). At this time, the above-determined 6th information is written in the information domain corresponding to the 6th index of the third data block, and the first 6 index values can be 111110, that is, only the value of the 6th index is modified from the initial value (for example, the initial value is 1) to the preset value (for example, the preset value is 0). Further, the values of the first five indexes can also be modified from the initial values to the preset values, thereby obtaining the current index 000000 of the third data block. The 7th index to the 504th index are omitted here, and it can be understood that the values of the 7th index to the 504th index are all 1. It should be noted that the examples here are also given in the order of N indexes from left to right. The present application does not limit the order of N indexes, and it can actually be in the order from right to left. For example, the sixth piece of information determined above is written in the information field corresponding to the sixth index of the third data block, and the first six index values can be 011111. The values of the first five indexes are further modified from the initial values to the preset values, thereby obtaining the index 000000.
[0076] Please also read Figure 5 , Figure 5 This is another flow chart of writing data from a FLASH memory provided by an embodiment of the present application, including but not limited to steps 102e to 102f.
[0077] 102e. When a second data collection instruction is detected, read the (i+1)th piece of information in the information field corresponding to the (i+1)th index stored in the third data block, wherein the second data collection instruction carries the second incremental data.
[0078] It should be noted that since the writing of the i+1th information in the first data block failed, the i+1th information cannot be read from the information field corresponding to the i+1th index of the first data block when the data is read next time. Then, the energy device can directly read the i+1th information from the information field corresponding to the i+1th index of the third data block in the FLASH memory when the data is read next time.
[0079] 102f. Write the (i+2)th piece of information into the information fields corresponding to the (i+2)th indexes of the first data block and the second data block.
[0080] Among them, when the data acquisition instruction is detected next time, the data acquisition instruction carries the second incremental data. The second data acquisition instruction can be triggered by the energy device detecting water flowing or electricity again. Then the energy device determines the i+2th information based on the second incremental data and the i+1th information, and then writes the i+2th information into the first data block and the second data block, and so on. From this point of view, the third data block can prevent write errors from occurring when writing data in the FLASH memory, thereby realizing a fault-tolerant protection mechanism and improving the fault tolerance rate of the FLASH memory.
[0081] In a possible implementation, the energy device can be used as a narrowband Internet of Things (NB-IoT) device, which can communicate through a narrowband (NB) module, for example, it can receive configuration instructions, which are used to configure the number of data blocks and information of the data blocks included in the FLASH memory, such as the number of bytes of each information. The part of the cumulative energy consumption can be implemented by the microcontroller unit (MCU) in the energy device, that is, the NB module is mounted on the MCU and controlled by the MCU, and the NB module is only responsible for the communication business, such as the above-mentioned receiving configuration instructions. Among them, the energy device can also adopt an open central processing unit (OPEN-CPU). The so-called OPEN-CPU refers to an application method in which the module is used as the main processor, and the NB module is used as a module. This method not only processes application layer services but also communications-related services. This method can help reduce product size and shorten product development cycle.
[0082] This application uses the OPEN-CPU method as an example to explain, which can be divided into the OPEN-CPU state for processing application layer services and the communication state for processing communication-related services. The energy device can operate the energy device through physical buttons, virtual buttons, scroll wheels, operations in the application interface, etc. to switch the above two states. After the energy device is powered on, it can receive configuration instructions carrying configuration information, such as AT (Attention) communication instructions, which can be used to configure the number of data blocks in the FLASH memory and the specific configuration of the data blocks, and save the configuration information, such as saving it in a specific location in the FLASH memory, so that when it is powered on next time, it switches to the OPEN-CPU state to read the stored configuration information and configure each data block specifically, and sleeps in the OPEN-CPU state, reads the information stored in the data block, and writes information.
[0083] Among them, it should be noted that the storage space and division area of the FLASH memory are limited. Generally speaking, the more the number of divided data blocks, the higher the reliability and the longer the life of the FLASH memory, but the more storage space is tight. Therefore, in the process of configuring the data blocks, it is necessary to make a compromise between the reliability and life of the FLASH memory and the capacity of the FLASH. It should be further noted that this application uses three data blocks, namely the first data block, the second data block and the third data block as an example for explanation. In order to ensure that the read data is correct, the fourth data block can also be configured to maintain the same erase and write operation as the first data block, and read the data when the first data block and the second data block both fail to read the data. Similarly, the fifth data block can also be configured for writing when the first data block and the third data block both fail to write the data. It can be understood that with each additional data block, the possibility of writing data errors at the same time is smaller, thereby improving fault tolerance.
[0084] In the embodiment of the present application, the i-th piece of information stored in the FLASH memory is read when a data acquisition instruction carrying incremental data is detected, and the i+1-th piece of information is determined based on the i-th piece of information and the incremental data, and then the i+1-th piece of information is written into the FLASH memory. Therefore, this solution does not require additional transplantation of the file system to store cumulative information, avoids additional resource overhead, improves storage efficiency, reduces power consumption in frequent wake-up read and write scenarios, and introduces a fault-tolerant mechanism to increase the reliability of data storage, which can be applied to low-power energy metering scenarios where low-end embedded devices are frequently woken up from sleep for reading and writing.
[0085] See also Figure 6 , Figure 6: is a schematic diagram of the structure of an information storage device provided in an embodiment of the present application. The information storage device 60 includes:
[0086] A reading unit 601 is used to read the i-th information stored in the FLASH memory when a first data acquisition instruction is detected, wherein the first data acquisition instruction carries first incremental data;
[0087] The writing unit 602 is used to write the i+1th piece of information into the FLASH memory, where the i+1th piece of information is determined based on the i-th piece of information and the first incremental data.
[0088] In one implementation, the FLASH memory includes a first data block and a second data block, and each of the data blocks includes N indexes and an information field corresponding to each of the indexes.
[0089] In one implementation, the N indexes have initial values; the writing unit 602 writes the i+1th piece of information into the FLASH memory, specifically for:
[0090] Writing the i+1th piece of information into the information domain corresponding to the i+1th index of the first data block and the second data block; 1<=i<=N, i and N are both integers;
[0091] When the i+1th piece of information is successfully written into the information domain corresponding to the i+1th index of the first data block and the second data block, the values of the i+1th index of the first data block and the second data block are modified from the initial values to the preset values.
[0092] In one implementation, the FLASH memory further includes a third data block, the third data block including N indexes and an information field corresponding to each of the indexes; the writing unit 602 is further configured to write the i+1th piece of information into the information field corresponding to the i+1th index of the third data block when writing the i+1th piece of information into the first data block fails;
[0093] The modification unit 603 is used to modify the value of the i+1th index in the third data block from the initial value to the preset value when the i+1th information is successfully written into the information field corresponding to the i+1th index in the third data block.
[0094] In one implementation, the modification unit 603 is further configured to modify the values of the i indexes before the i+1th index among the N indexes in the third data block from the initial values to the preset values.
[0095] In one implementation, the i-th piece of information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the first data block, and the i-th index of the first data block is the last index among the N indexes of the first data block whose index value is equal to the preset value.
[0096] In one implementation, when reading information from the information field corresponding to the i-th index of the first data block fails, the i-th information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the second data block.
[0097] In one implementation, the reading unit 601 is further configured to read the i+1th piece of information stored in the information field corresponding to the i+1th index in the third data block when a second data collection instruction is detected, and the second data collection instruction carries the second incremental data;
[0098] The writing unit 602 is further used to write the i+2th piece of information in the information field corresponding to the i+2th index of the above-mentioned first data block and the above-mentioned second data block, and the above-mentioned i+2th piece of information is determined based on the above-mentioned i+1th piece of information and the above-mentioned second incremental data.
[0099] According to one embodiment of the present application, Figure 1 Some of the steps involved in the information storage method shown can be Figure 6 The information storage device shown in the figure is executed by each unit. For example, Figure 1 The step 101 shown in FIG. 1 can be performed by Figure 6 The reading unit 601 shown in FIG. 1 is executed, and step 102 can be performed by Figure 6 The write unit 602 is shown to perform.
[0100] Figure 6 The various units in the information storage device shown can be separately or all combined into one or several other units to constitute, or some of the units (some) can also be split into multiple smaller units in function to constitute, which can achieve the same operation without affecting the realization of the technical effects of the embodiments of the present application. The above-mentioned units are divided based on logical functions. In practical applications, the function of a unit can also be implemented by multiple units, or the function of multiple units can be implemented by one unit. In other embodiments of the present application, the information storage device may also include other units. In practical applications, these functions can also be implemented with the assistance of other units, and can be implemented by the collaboration of multiple units.
[0101] According to another embodiment of the present application, the program can be executed by running on a general computing device such as a computer including a central processing unit (CPU), a random access memory medium (RAM), a read-only memory medium (ROM) and other processing elements and storage elements. Figure 1 A computer program (including program code) for each step involved in the corresponding method shown in Figure 6 The information storage device shown in and the information storage method of the embodiment of the present application are implemented. The above computer program can be recorded on, for example, a computer readable recording medium, and loaded into the above computing device through the computer readable recording medium and run therein.
[0102] Based on the same inventive concept, the principles and beneficial effects of solving the problems by the information storage device provided in the embodiment of the present application are similar to the principles and beneficial effects of solving the problems by the information storage device in the method embodiment of the present application. Please refer to the principles and beneficial effects of the implementation of the method. For the sake of concise description, they will not be repeated here.
[0103] See also Figure 7 , Figure 7 A schematic diagram of the structure of a computer device provided in an embodiment of the present application, the computer device at least includes a processor 701, a communication interface 702 and a memory 703. Among them, the processor 701, the communication interface 702 and the memory 703 can be connected via a bus or other means, and the embodiment of the present application takes the bus connection as an example. Among them, the processor 701 (or the central processing unit (CPU)) is the computing core and control core of the computer device, which can parse various instructions in the terminal device and process various data of the terminal device. For example: the CPU can be used to parse the power on and off instructions sent by the user to the terminal device, and control the terminal device to perform power on and off operations; for example: the CPU can transmit various types of interactive data between the internal structures of the terminal device, and so on. The communication interface 702 can optionally include a standard wired interface, a wireless interface (such as WI-FI, a mobile communication interface, etc.), which can be used to send and receive data under the control of the processor 701; the communication interface 702 can also be used for the transmission and interaction of data within the terminal device. The memory 703 (Memory) is a memory device in the terminal device for storing programs and data. It is understandable that the memory 703 here may include the built-in memory of the terminal device, and of course may also include the extended memory supported by the terminal device. The memory 703 provides a storage space, which stores the operating system of the terminal device, including but not limited to: Android system, iOS system, Windows Phone system, etc., which is not limited in this application.
[0104] In one embodiment, the computer device may be an energy device, the computer device may include a FLASH memory, or the computer device may be a FLASH memory. In this case, the processor 701 performs the following operations by running the executable program code in the memory 703:
[0105] In the case where a first data acquisition instruction is detected, reading the i-th information stored in the FLASH memory, the first data acquisition instruction carrying the first incremental data;
[0106] The i+1th piece of information is written into the FLASH memory, where the i+1th piece of information is determined based on the i-th piece of information and the first incremental data.
[0107] In one implementation, the FLASH memory includes a first data block and a second data block, and each of the data blocks includes N indexes and an information field corresponding to each of the indexes.
[0108] In one implementation, the N indexes have initial values; the processor 701 writes the i+1th piece of information into the FLASH memory by running the executable program code in the memory 703, specifically for performing the following operations:
[0109] Writing the i+1th piece of information into the information domain corresponding to the i+1th index of the first data block and the second data block; 1<=i<=N, i and N are both integers;
[0110] When the i+1th piece of information is successfully written into the information domain corresponding to the i+1th index of the first data block and the second data block, the values of the i+1th index of the first data block and the second data block are modified from the initial values to the preset values.
[0111] In one implementation, the FLASH memory further includes a third data block, and the third data block includes N indexes and an information field corresponding to each of the indexes; the processor 701 is further configured to perform the following operations by running the executable program code in the memory 703:
[0112] If writing the i+1th piece of information into the first data block fails, writing the i+1th piece of information into the information field corresponding to the i+1th index of the third data block;
[0113] When the i+1th piece of information is successfully written into the information field corresponding to the i+1th index of the third data block, the value of the i+1th index in the third data block is modified from the initial value to the preset value.
[0114] In one implementation, the processor 701 is further configured to perform the following operations by running the executable program code in the memory 703:
[0115] The values of the i indexes before the i+1th index among the N indexes in the third data block are all modified from the initial values to the preset values.
[0116] In one implementation, the i-th piece of information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the first data block, and the i-th index of the first data block is the last index among the N indexes of the first data block whose index value is equal to the preset value.
[0117] In one implementation, when reading information from the information field corresponding to the i-th index of the first data block fails, the i-th information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the second data block.
[0118] In one implementation, the processor 701 is further configured to perform the following operations by running the executable program code in the memory 703:
[0119] In the case where a second data acquisition instruction is detected, reading the i+1th piece of information stored in the information field corresponding to the i+1th index in the third data block, the second data acquisition instruction carrying the second incremental data;
[0120] The i+2th piece of information is written into the information domain corresponding to the i+2th index of the first data block and the second data block, and the i+2th piece of information is determined based on the i+1th piece of information and the second incremental data.
[0121] Based on the same inventive concept, the principles and beneficial effects of solving the problems provided by the computer device in the embodiment of the present application are similar to the principles and beneficial effects of solving the problems provided by the information storage method in the method embodiment of the present application. Please refer to the principles and beneficial effects of the implementation of the method. For the sake of concise description, they will not be repeated here.
[0122] An embodiment of the present application also provides a computer-readable storage medium, in which one or more program instructions are stored. The one or more program instructions are suitable for being loaded by a processor and executing the information storage method of the method embodiment.
[0123] An embodiment of the present application also provides a computer program product comprising instructions, which, when executed on a computer, enables the computer to execute the information storage method described above in the method embodiment.
[0124] The embodiment of the present application also provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the above-mentioned information storage method.
[0125] The steps in the method of the embodiment of the present application can be adjusted in order, combined and deleted according to actual needs.
[0126] The modules in the device of the embodiment of the present application can be merged, divided and deleted according to actual needs.
[0127] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing related hardware through a program, and the program can be stored in a computer-readable storage medium, and the readable storage medium can include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0128] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Professional and technical personnel may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0129] The terms "first", "second", etc. in the claims, specification and drawings of the present invention are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally includes steps or units that are not listed, or optionally includes other steps or units inherent to these processes, methods, products or devices. Mentioning "embodiment" in this article means that the specific features, structures or characteristics described in conjunction with the embodiment may be included in at least one embodiment of the present invention. Displaying the phrase at various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments. The term "and / or" used in the specification and the appended claims of the present invention refers to any combination of one or more of the items listed in association and all possible combinations, and includes these combinations.
[0130] What is disclosed above is only a preferred embodiment of the present application, and it certainly cannot be used to limit the scope of rights of the present application. Ordinary technicians in this field can understand that all or part of the processes of implementing the above embodiment and equivalent changes made according to the claims of the present application are still within the scope of the present invention.
Claims
1. An information storage method, characterized in that: Applied to a FLASH memory, the FLASH memory includes a first data block and a second data block, each of the data blocks includes N indexes and an information field corresponding to each index; The N indexes have initial values; the method comprises: In the case where a first data acquisition instruction is detected, reading the i-th information stored in the FLASH memory, the first data acquisition instruction carrying the first incremental data; Writing the i+1th piece of information into the information field corresponding to the i+1th index of the first data block and the second data block; 1<=i<=N, i and N are both integers; When the i+1th piece of information is successfully written into the information fields corresponding to the i+1th indexes of the first data block and the second data block, the values of the i+1th indexes of the first data block and the second data block are modified from the initial values to preset values; The i+1th piece of information is determined based on the i-th piece of information and the first incremental data; the i-th piece of information read from the FLASH memory is obtained by reading from the information domain corresponding to the i-th index of the first data block, and the i-th index of the first data block is the last index among the N indexes of the first data block whose index value is equal to the preset value.
2. The method according to claim 1, characterized in that The FLASH memory further includes a third data block, wherein the third data block includes N indexes and an information field corresponding to each of the indexes; and the method further includes: If writing the i+1th piece of information into the first data block fails, writing the i+1th piece of information into the information field corresponding to the i+1th index of the third data block; When the i+1th piece of information is successfully written into the information field corresponding to the i+1th index of the third data block, the value of the i+1th index in the third data block is modified from the initial value to the preset value.
3. The method according to claim 2, characterized in that After modifying the value of the i+1th index in the third data block from the initial value to the preset value, the method further includes: The values of i indexes before the (i+1)th index among the N indexes in the third data block are all modified from the initial values to the preset values.
4. The method according to claim 1, characterized in that: In the case where reading information from the information field corresponding to the i-th index of the first data block fails, the i-th piece of information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the second data block.
5. The method according to claim 2, characterized in that: The method further comprises: In case a second data collection instruction is detected, reading the (i+1)th piece of information stored in the information field corresponding to the (i+1)th index in the third data block, the second data collection instruction carrying the second incremental data; The i+2th piece of information is written into the information field corresponding to the i+2th index of the first data block and the second data block, and the i+2th piece of information is determined based on the i+1th piece of information and the second incremental data.
6. An information storage device, characterized in that: Applied to a FLASH memory, the FLASH memory includes a first data block and a second data block, each of the data blocks includes N indexes and an information field corresponding to each index; The N indexes have initial values; The information storage device comprises: a reading unit, configured to read the i-th piece of information stored in the FLASH memory when a first data acquisition instruction is detected, wherein the first data acquisition instruction carries first incremental data; a writing unit, configured to write an i+1th piece of information into the FLASH memory, wherein the i+1th piece of information is determined according to the i-th piece of information and the first incremental data; The writing unit, when used to write the i+1th piece of information in the FLASH memory, is specifically used to write the i+1th piece of information in the information domain corresponding to the i+1th index of the first data block and the second data block; 1<=i<=N, i and N are both integers; when the i+1th piece of information is successfully written in the information domain corresponding to the i+1th index of the first data block and the second data block, the values of the i+1th index of the first data block and the second data block are modified from the initial value to the preset value; The i-th piece of information read from the FLASH memory is obtained by reading from the information field corresponding to the i-th index of the first data block, and the i-th index of the first data block is the last index among the N indexes of the first data block whose index value is equal to the preset value.
7. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions. When the program instructions are executed by a processor, a computer device having the processor implements the information storage method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Data dumping method and device, electronic device and storage medium
CN109165194A
Data storage processing method and system
CN111857581A
