Method for constructing an extensible storage structure and reading data
By defining the basic and extended data element groups and their verification values in an embedded system, and using the CRC16 algorithm to calculate the integrity verification, the compatibility and credibility problems during storage structure expansion are solved, and dynamic expansion and forward compatibility of data are achieved.
Patent Information
- Application Number
- CN202410886193.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-03
- Publication Date
- 2025-07-22
- Estimated Expiration
- 2044-07-03
AI Technical Summary
In embedded systems, it is difficult for existing storage structures to expand data elements without changing the original data structure, and new elements are easily added to old data being untrusted or waste of storage space.
By defining the basic and extended data element groups and their verification values, the CRC16 algorithm is used to calculate the integrity and perform verification processing when reading data, to realize the function of dynamically expanding data elements.
It realizes dynamic expansion of data elements without affecting the old version of data, ensures the trustworthiness and integrity of the data, supports the storage and reading of new versions of data, and has good forward compatibility.
Smart Images

Figure CN118838749B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data storage in embedded systems, and particularly relates to a method for constructing an extensible storage structure and reading data. Background Art
[0002] In an embedded system, a structure is often used to store relevant data. After mass production of the project, the data structure has been determined. However, when considering expansion later, it is often found that it is very difficult to add new elements to the same structure because the problem of forward compatibility needs to be considered. The usual approach is to first read the relevant data using the structure of the old version of the software when compatible with the structure of the old version of the software, and then assign it to the elements in the structure of the new version of the software, and then recalculate the CRC and store it in the non-volatile flash.
[0003] However, the above data structure still has the following problems when adding elements:
[0004] 1. The CRC of the entire structure is generally stored at the end of the structure. When new data elements are added to the structure, the position of the CRC changes. When reading the data of the old structure with the new structure, the calculated CRC does not match, resulting in the data correctly stored in the old structure being untrustworthy and the data needing to be stored again.
[0005] 2. Reserving some data elements in advance for subsequent expansion of new data will result in waste of a part of the storage space, and this part of the storage space may never be used. Summary of the Invention
[0006] The purpose of the present invention is to provide a method for constructing an extensible storage structure and reading data. By adding new data elements and their check values on the basis of the existing structure and performing corresponding verification processing when reading data, the function of dynamically expanding data elements is realized without changing the original data structure, so as to solve the problems raised in the background art.
[0007] The present invention realizes the above purpose through the following technical solutions:
[0008] In a first aspect, the present invention proposes a method for constructing an extensible storage structure, and the construction method includes defining the following data structures:
[0009] At least one basic data element group, where the basic data element group includes data elements Datax1 - Datax n ;
[0010] A check value Crc1 for verifying the data integrity of the basic data element group;
[0011] A check value Crc, which is used to check the data integrity of the basic data element group and the check value Crc1;
[0012] At least one extended data element group, where the extended data element group contains data elements Datay1 - Datay n , add at least one extended data element group after the check value Crc1;
[0013] A check value Crc2, which is used to check the data integrity of the extended data element group;
[0014] The construction method further includes: after expanding the storage structure, updating the check value Crc so that it checks the data integrity of the basic data element group, the check value Crc1, the extended data element group, and the check value Crc2.
[0015] The further improvement lies in that the check value Crc1, the check value Crc2, and the check value Crc all calculate and check the integrity of the corresponding data through the CRC16 algorithm.
[0016] In a second aspect, the present invention proposes a data reading method for an extensible storage structure, which uses the storage structure constructed by the above construction method to read data. The data reading method includes:
[0017] Use the storage structure to read the target data structure, first verify the check value Crc, and select whether to enter the compatibility processing mode according to the verification result of the check value Crc;
[0018] In the compatibility processing mode, check the check value Crc1 and the check value Crc2 respectively, keep the values of the data element groups that pass the check, clear or set the default values for the extended data element groups that fail the check, and recalculate the check values of each data element and update the check value Crc when storing next time.
[0019] The further improvement lies in that the target data structure includes the at least one basic data element group.
[0020] The further improvement lies in that if the verification result of the check value Crc passes, the data reading process is terminated.
[0021] The beneficial effects of the present invention are as follows:
[0022] 1. The construction method proposed by the present invention enables users to add data elements at any time according to needs, and there will be no data compatibility problems with old versions. Moreover, when the data in the storage space is damaged, it will not cause the entire data to be unavailable, and some data with successful verification can be trusted.
[0023] 2. When the reading method proposed by the present invention reads data, by verifying the total check value and the check values of each data element, it can automatically judge the credibility and integrity of the data, and take corresponding processing measures to ensure the accuracy and reliability of the data; and this reading method has good forward compatibility and can support the storage and reading of new version data without affecting the old version data. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1 It is a flowchart of a method for constructing an extensible storage structure provided in Embodiment 1 of the present application.
[0025] Figure 2 It is a flowchart of a data reading method for an extensible storage structure provided in Embodiment 2 of the present application.
[0026] Figure 3 It is a schematic diagram of the code implementation process of the old version storage structure in the example provided in the specific implementation manner of the present application.
[0027] Figure 4 It is a schematic diagram of the code implementation process of the new version storage structure in the example provided in the specific implementation manner of the present application. SPECIFIC IMPLEMENTATION MANNER
[0028] The following further describes the present application in detail with reference to the drawings. It is necessary to point out here that the following specific implementation manner is only used to further illustrate the present application and cannot be understood as a limitation on the protection scope of the present application. Those skilled in the art can make some non-essential improvements and adjustments to the present application according to the above application content.
[0029] Embodiment 1
[0030] As Figure 1 shown, this embodiment proposes a method for constructing an extensible storage structure. The construction method includes defining the following data structures: defining at least one basic data element group, and the basic data element group includes data elements Datax1 - Datax n ; defining a check value Crc1 for verifying the data integrity of the basic data element group; defining a check value Crc for verifying the data integrity of the data including the basic data element group and the check value Crc1; defining at least one extended data element group, and the extended data element group includes data elements Datay1 - Datay n , adding at least one extended data element group after the check value Crc1; defining a check value Crc2 for verifying the data integrity of the extended data element group.
[0031] The construction method further includes: after expanding the storage structure, updating the check value Crc to check the data integrity of the data including the basic data element group, the check value Crc1, the extended data element group, and the check value Crc2.
[0032] In this embodiment, Datax1 - Datax n are data elements, that is, the data information to be stored. Crc1 is the data check for Datax1 - Datax n and is obtained by CRC16 calculation. Crc is the data check for Datax1 - Datax n and Crc1 and is obtained by CRC16 calculation.
[0033] When the storage structure in the present invention needs to expand its storage capacity, new data elements Datay1 - Datay n are added after Crc1, n as well as the corresponding check value Crc2. At the same time, Crc will be updated to check the entire expanded structure (including Datax1 - Datax n , Crc1, Datay1 - Datay
[0034] It can be understood that the construction method in this embodiment needs to solve the problem that users can add data elements at any time according to their needs, without the problem of data compatibility with old versions, and when the storage space data is damaged, the entire data will not become unavailable, and some data with successful checks can be trusted.
[0035] Correspondingly, the check value Crc1, the check value Crc2, and the check value Crc all calculate and check the integrity of the corresponding data through the CRC16 algorithm.
[0036] According to the above embodiment of the present invention, this embodiment realizes the function of dynamically expanding data elements without changing the original data structure by adding optional data elements and their check values.
[0037] Embodiment 2
[0038] As Figure 2 shown, this embodiment proposes a data reading method for an extensible storage structure, and uses the storage structure constructed by the construction method in Embodiment 1 to read data. The data reading method includes:
[0039] Read the target data structure using the storage structure. First, verify the check value Crc, and select whether to enter the compatibility processing mode according to the verification result of the check value Crc; in the compatibility processing mode, verify the check value Crc1 and the check value Crc2 respectively, retain the values of the data element groups that pass the verification, clear or set the extended data element groups that fail the verification to the default value, and recalculate the check values of each data element when storing next time, and update the check value Crc.
[0040] Further preferably, if the verification result of the check value Crc passes, terminate the data reading process.
[0041] Further preferably, the target data structure includes at least one basic data element group Datax1 - Datax n .
[0042] In some preferred embodiments, the storage structure constructed in Embodiment 1 can be understood as the new version structure data, the target data structure can be understood as the old version structure data, and the above data reading method can be understood as using the new version structure to attempt to read the old version data. Due to the change of the data structure, the Crc check will not pass, indicating that the complete data is not trustworthy. Then, by verifying the values of Crc1 and Crc2 respectively, the trustworthiness of Datax1 - Datax n can be determined, while Datay1 - Datay n is considered untrustworthy due to the failure of the Crc2 check and is cleared. When storing next time, recalculate each Crc value and store it, so as to realize the reading of the old version data and the compatibility with the new version data.
[0043] According to the above embodiments of the present invention, when reading data based on the above data reading method, by verifying the total check value (Crc value) and the check values of each data element, the trustworthiness and integrity of the data can be automatically judged, and corresponding processing measures are taken to ensure the accuracy and reliability of the data; and the reading method has good forward compatibility and can support the storage and reading of the new version data without affecting the old version data.
[0044] Next, a specific example is used to further elaborate on the construction of the extended storage structure and the data reading method in the present invention.
[0045] As an example, the structure initially defined by the user is used as the target data structure, including at least one group of basic data elements Data1-Data4. After mass production of the products related to this structure, when two new elements Data5 and Data6 need to be added for newly developed functions in the future, in order to be backward compatible and not affect the values of the basic data element groups Data1-Data4, based on the design of the above-expandable storage structure of the present invention, specifically, elements Data5 and Data6 and the CRC16 check value Crc2 of Data5 and Data6 are added after Crc1. Crc is the total check of Data1~Data4, Crc1, Data5, Data6 and Crc2. The code implementation process is as Figure 3 and Figure 4 .
[0046] More specifically, in the above example, based on the above data reading method of the present invention: First, use the new version of the structure (expandable storage structure) to read the data of the old version (the target structure of at least one group of basic data elements). The Crc verification will definitely not pass, which means that the complete data read is not trustworthy. At this time, check the values of Crc1 and Crc2 one by one. Under normal circumstances, the calculation of Crc1 is correct, so Data1~Data4 is trustworthy, while Crc2 is incorrect, so Data5 and Data6 are not trustworthy. Clear this data to 0 or set it to the default value, and then recalculate the values of each Crc when storing next time, and then store it again. In this way, the reading of the old version data and the compatibility of the new version data can be automatically completed.
[0047] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A data reading method for an extensible storage structure, characterized in that, The method for constructing the extensible storage structure includes defining the following data structures: At least one group of basic data elements, where the group of basic data elements includes data elements Datax1 - Datax n ; A check value Crc1, which is used to check the data integrity of the basic data element group; A check value Crc, which is used to check the data integrity of the data including the basic data element group and the check value Crc1; At least one extended data element group, the extended data element group including data elements Datay1 - Datay n , and adding at least one extended data element group after the check value Crc1; A check value Crc2, which is used to check the data integrity of the extended data element group; The construction method further includes: after extending the storage structure, updating the check value Crc to make it check the data integrity of the data including the basic data element group, the check value Crc1, the extended data element group and the check value Crc2; The data reading method includes: Using the storage structure to read the target data structure, first verifying the check value Crc, and selecting whether to enter the compatibility processing mode according to the verification result of the check value Crc; In the compatibility processing mode, respectively check the check value Crc1 and the check value Crc2, keep the values of the data element groups that pass the check, clear or set the default values for the extended data element groups that fail the check, and recalculate the check values of each data element and update the check value Crc when storing next time.
2. The data reading method of an extensible storage structure according to claim 1, characterized in that The check value Crc1, the check value Crc2, and the check value Crc all calculate and check the integrity of the corresponding data through the CRC16 algorithm.
3. The data reading method of a scalable storage structure according to claim 1, characterized in that, The target data structure includes the at least one basic data element group.
4. The data reading method of an extensible storage structure according to claim 1, characterized in that, If the verification result of the check value Crc passes, terminate the data reading process.
Citation Information
Patent Citations
Method and apparatus for storing and retrieving error check information
US5630054A
Method and apparatus for CRC rate matching in communications systems
WO2009156798A1