Industrial control data reliable writing method and system based on SD NAND memory chip
By analyzing power status and parsing metadata logs, and merging cached data, the problem of locating the interruption point in data writing during power failure in industrial control systems was solved, and reliable data status recovery was achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- SHEN ZHEN XINCUN TECH CO LTD
- Filing Date
- 2026-06-24
- Publication Date
- 2026-07-21
Smart Images

Figure CN122431619A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial control data storage technology, and in particular to a reliable method and system for writing industrial control data based on SD NAND memory chips. Background Technology
[0002] Currently, in the field of industrial control, production equipment needs to continuously write operational data into storage chips to support production decisions and safety monitoring. Due to the complex industrial environment, power supply quality is affected by factors such as equipment start-up and shutdown, and load fluctuations, posing a risk of voltage instability or even sudden power outages. As a result, the data writing process is threatened with interruption at any time, posing a serious threat to the data security of industrial control systems.
[0003] In existing technologies, industrial control systems typically employ periodic backups or post-write verification to ensure data storage reliability. This approach restores the data state during system recovery by reading the most recent backup data and re-performing the write operations. However, this solution is primarily designed for routine operating environments and fails to adequately consider the unique challenges of power outages in high-frequency data writing scenarios in industrial settings. When a power outage occurs, the system cannot promptly capture the latest write location and status flags of metadata, making it impossible to accurately determine which data has been written and which was interrupted during recovery, thus leading to data inconsistency issues.
[0004] Existing technologies have the problem that industrial control systems cannot accurately capture the metadata writing status in the event of a power outage, resulting in unreliable data writing recovery. Summary of the Invention
[0005] This invention provides a reliable method and system for writing industrial control data based on SD NAND storage chips, in order to solve the technical problem in the prior art that industrial control systems cannot accurately capture the metadata writing status in power failure scenarios, resulting in unreliable data writing recovery.
[0006] Firstly, to address the aforementioned technical problems, this invention provides a reliable method for writing industrial control data based on an SD NAND flash memory chip, comprising: Acquire voltage data sequences, currently being written data streams, metadata logs, log blocks, and auxiliary buffer data from the power supply side of the industrial control system; Perform power state analysis on the voltage data sequence to determine power state indicators; When the power status indicator is unstable, the data stream is copied to obtain a backup data stream, and the metadata log is parsed to obtain the metadata write location; The log block is verified based on the metadata writing location. If the verification result is incomplete, the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. Obtain the baseline verification value and historical transaction log index, perform verification calculation on the complete log copy to obtain the log copy verification value, compare the log copy verification value with the baseline verification value bit by bit to obtain the copy difference rate, and determine the recovery starting point position based on the copy difference rate. Based on the recovery starting point position, the backup data stream is intercepted to obtain the data stream to be reconstructed. The data stream to be reconstructed is segmented to obtain data stream segments. Adjacent data stream segments are compared to obtain the difference rate. When the difference rate is greater than a preset segment threshold, a completion operation is performed to obtain a continuous data chain. Log replay is performed on the continuous data chain to obtain the data write state before the interruption. The index of the data write state before the interruption is reconstructed to obtain the complete data structure.
[0007] Secondly, the present invention provides a reliable industrial control data writing device based on an SD NAND memory chip, comprising: The data acquisition module is used to acquire the voltage data sequence of the power supply terminal, the data stream currently being written, the metadata log, the log block, and the auxiliary buffer data in the industrial control system. The status analysis module is used to perform power status analysis on the voltage data sequence and determine power status indicators; The data backup module is used to perform a copy operation on the data stream to obtain a backup data stream when the power status indicator is unstable, and to parse the fields of the metadata log to obtain the metadata write location. The log verification module is used to verify the log block according to the metadata writing location. When the verification result is incomplete, the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. The difference detection module is used to obtain the baseline verification value and the historical transaction log index, perform verification calculation on the complete log copy to obtain the log copy verification value, compare the log copy verification value with the baseline verification value bit by bit to obtain the copy difference rate, and determine the recovery starting position based on the copy difference rate. The data reconstruction module is used to intercept the backup data stream based on the recovery starting point position to obtain the data stream to be reconstructed, segment the data stream to be reconstructed to obtain data stream segments, compare adjacent data stream segments to obtain the difference rate, and perform a completion operation when the difference rate is greater than a preset segment threshold to obtain a continuous data chain. The data storage module is used to perform log replay on the continuous data chain to obtain the data write status before the interruption, and to reconstruct the index of the data write status before the interruption to obtain the complete data structure.
[0008] Compared with the prior art, the present invention has the following beneficial effects: (1) This invention collects the voltage data sequence of the power supply terminal and performs standard deviation calculation. Based on the comparison result of the voltage fluctuation standard deviation and the preset fluctuation threshold, the power supply status index is determined. When the power supply status index is unstable, the data stream copy operation is immediately triggered and the metadata log is parsed. Thus, the metadata writing position is captured in advance before the power failure occurs, avoiding the problem in the prior art that the metadata status is lost due to power failure and the data writing interruption point cannot be accurately located. This invention achieves accurate locking of the data writing interruption position.
[0009] (2) The present invention verifies the log block based on the metadata writing location. When the verification result is incomplete, the byte sequence written to the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. The complete log copy is then compared with the benchmark verification value to obtain the copy difference rate. When the copy difference rate exceeds the preset difference threshold, the recovery starting point is determined by traversing and searching the historical transaction log index. This solves the problem in the prior art that the incomplete log block makes it impossible to determine a reliable recovery starting point, and achieves accurate positioning of the data recovery starting point.
[0010] (3) This invention extracts and segments the backup data stream based on the recovery starting point position, performs difference calculation on the segment feature values of adjacent data stream segments to obtain the difference rate, and performs a completion operation on the data stream segments before and after the power outage interruption point when the difference rate exceeds the preset segment threshold to obtain a continuous data chain. Then, by sorting the continuous data chain in descending order of timestamps and replaying the write operation records one by one, the data writing state before the interruption is restored, thereby solving the problem that the writing state cannot be completely reconstructed due to the discontinuous data stream after the power outage in the prior art, and realizing the reliable recovery of the data writing state. Attached Figure Description
[0011] Figure 1 This is a schematic diagram of the reliable writing method for industrial control data based on SD NAND storage chips provided in the first embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of a reliable industrial control data writing system based on an SD NAND storage chip provided in the second embodiment of the present invention. Detailed Implementation
[0012] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0013] Reference Figure 1 The first embodiment of the present invention provides a reliable method for writing industrial control data based on SD NAND memory chips, including the following steps: S11, acquire the voltage data sequence of the power supply in the industrial control system, the data stream currently being written, the metadata log, the log block, and the auxiliary buffer data; S12, Perform power state analysis on the voltage data sequence to determine power state indicators; S13, when the power status indicator is unstable, the data stream is copied to obtain a backup data stream, and the metadata log is parsed to obtain the metadata write location; S14, the log block is verified according to the metadata writing location. When the verification result is incomplete, the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. S15, obtain the baseline verification value and the historical transaction log index, perform verification operation on the complete log copy to obtain the log copy verification value, compare the log copy verification value with the baseline verification value bit by bit to obtain the copy difference rate, and determine the recovery starting position based on the copy difference rate. S16, based on the recovery starting point position, the backup data stream is intercepted to obtain the data stream to be reconstructed, the data stream to be reconstructed is segmented to obtain data stream segments, adjacent data stream segments are compared to obtain the difference rate, and when the difference rate is greater than a preset segment threshold, a completion operation is performed to obtain a continuous data chain. S17, perform log replay on the continuous data chain to obtain the data writing status before the interruption, and reconstruct the index of the data writing status before the interruption to obtain the complete data structure.
[0014] In step S11, the voltage data sequence at the power supply end of the industrial control system, the data stream currently being written, the metadata log, the log block, and the auxiliary buffer data are acquired, including: The voltage data sequence is acquired by a voltage sensor in the industrial control system at a preset sampling frequency. The data stream currently being written, the metadata log, and the log block are obtained through the storage controller in the industrial control system. The auxiliary cache data is obtained through the cache management unit in the industrial control system.
[0015] In one implementation, the voltage data sequence is acquired via a voltage sensor deployed at the power supply bus access point of the industrial control system. The preset sampling frequency is determined based on the physical response characteristics of power fluctuations in the industrial environment. Common types of power disturbances in industrial control systems, such as voltage dips caused by inductive load start-stop and voltage distortions caused by inverter harmonics, typically have transient durations between 10 and 50 milliseconds. According to the Nyquist sampling theorem, to fully capture the shortest transient process, the sampling frequency must be no less than twice the reciprocal of the transient duration, i.e., no less than 40 Hz. Considering the need to reserve sufficient waveform detail margin in practical engineering, the preset sampling frequency is set to 100 Hz, i.e., a voltage sample value is acquired every 10 milliseconds. Those skilled in the art will understand that this sampling frequency is not a fixed value and can be adjusted within the range of 50 Hz to 200 Hz according to the actual requirements of power fluctuation response accuracy in the industrial environment. 200 Hz can be selected for scenarios with high response accuracy requirements, while 50 Hz can be selected for scenarios with limited system resources.
[0016] Specifically, the voltage sensor continuously performs data acquisition during system operation, outputting a voltage sample value in volts every 10 milliseconds. The voltage sample values output at each sampling time are arranged sequentially according to the acquisition time, forming the voltage data sequence. In this embodiment, the voltage data sequence consists of 300 consecutive voltage sample values, corresponding to a 3-second sampling window. This window length is empirically set based on the longest duration of power disturbances in industrial settings, and can cover the complete process of most voltage fluctuation events. The voltage data sequence is updated in a sliding manner when each new sample value arrives, discarding the earliest sample value and appending the latest sample value to maintain a constant sequence length of 300 sample values.
[0017] In one implementation, the storage controller manages all data read / write interactions between the industrial control system and the SD NAND flash memory chip, and is responsible for acquiring the data stream, metadata log, and log blocks through the storage controller. Specifically, the data stream refers to the raw data sequence currently being written to the SD NAND flash memory chip by the industrial control system. Its content includes real-time operating data such as equipment operating parameters, sensor data acquisitions, and control commands generated during industrial production. The storage controller obtains the current content of the data stream by reading its internal write buffer. The metadata log is a descriptive information record associated with the data stream write operation, stored in a dedicated metadata partition of the SD NAND flash memory chip. Each record contains two fields: a timestamp field, recording the system time of the write operation with millisecond precision; and an operation type field, recording the type identifier of the write operation, including three values: write start, write complete, and write interrupted. The storage controller obtains the current content of the metadata log by sending a read command to the metadata partition. The log block is a contiguous physical storage area specifically allocated within the SD NAND flash memory chip. It is used to store complete operation records of each write operation, including the starting address of the written data, the write length, and verification information of the written content. The storage controller performs a sequential read operation on the log block through the bus interface to obtain all operation record content stored in the current log block.
[0018] In one implementation, the auxiliary cache area data is obtained through the cache management unit. The auxiliary cache area is a temporary storage region with a fixed address range pre-allocated in the system memory of the industrial control system. In this embodiment, its capacity is set to 4MB. This capacity value is determined after statistical analysis of the maximum data volume of a single write operation in the industrial field, and it can completely accommodate all intermediate state data from the start to the completion of a write operation. The cache management unit is responsible for the unified management of address allocation and data reading / writing of the auxiliary cache area. Specifically, during each write operation, the storage controller appends the intermediate progress data that has not yet been written to disk to the auxiliary cache area. Each append update updates the write timestamp to record the latest intermediate state time. During step S11, after receiving the data acquisition instruction, the cache management unit reads all written content sequentially from the starting address of the auxiliary cache area according to the write timestamp from earliest to latest. The reading result is output as the auxiliary cache area data for use in the subsequent step S14 when performing log block integrity repair.
[0019] In step S12, power state analysis is performed on the voltage data sequence to determine power state indicators, including: Each sampled value in the voltage data sequence is determined as a voltage sampled value, and an arithmetic average is performed on all the voltage sampled values to obtain the voltage average value. The difference between each voltage sample value and the average voltage is calculated to obtain a difference sequence. The square of each difference in the difference sequence is then calculated to obtain a squared difference sequence. The mean of the squared differences is calculated by performing a mean operation on the squared difference sequence, and the standard deviation of the voltage fluctuation is obtained by performing a square root operation on the mean of the squared differences. When the standard deviation of the voltage fluctuation is greater than the preset fluctuation threshold and the duration is greater than the preset duration, the power supply status index is determined to be unstable; otherwise, it is determined to be stable.
[0020] In one implementation, regarding the determination of each sampled value in the voltage data sequence as a voltage sampled value, in this embodiment, the voltage data sequence is continuously acquired by the voltage sensor described in step S11 at a sampling frequency of 100Hz, containing a total of 300 voltage sampled values, denoted as the 1st to the 300th voltage sampled values. The unit of each voltage sampled value is volts, and the data type is a single-precision floating-point number. The voltage data sequence is updated in a sliding manner when each new sampled value arrives, discarding the earliest sampled value and appending the latest sampled value to maintain a constant sequence length of 300 sampled values.
[0021] Specifically, for calculating the average voltage, all 300 voltage samples are summed sequentially to obtain a total voltage sample value. This total is then divided by 300 to obtain the average voltage, measured in volts. The average voltage reflects the overall voltage level at the power supply terminal within the current sampling window and serves as a reference for subsequent difference calculations. Based on this, for calculating the difference sequence and the squared difference sequence, for each of the 300 voltage samples, the average voltage is subtracted to obtain the corresponding difference. This calculation is performed 300 times. The 300 differences are arranged in chronological order of sampling time to form the difference sequence. Each difference in the difference sequence reflects the degree to which the voltage deviates from the mean at the corresponding sampling time; a positive value indicates that the voltage is higher than the mean at that time, and a negative value indicates that it is lower than the mean. Subsequently, for each difference in the difference sequence, it is multiplied by itself to obtain the corresponding squared difference. This calculation is performed 300 times. The 300 squared differences are arranged in chronological order of sampling time to form the squared difference sequence. The purpose of squaring is to eliminate the effect of positive and negative differences canceling each other out, so that each deviation participates in subsequent statistical calculations in the form of a non-negative value.
[0022] Furthermore, regarding the calculation of the mean of the squared differences and the standard deviation of voltage fluctuations, all 300 squared differences in the squared difference sequence are summed sequentially to obtain a total sum of squared differences. This total sum is then divided by 300 to obtain the mean of the squared differences. The mean of the squared differences represents the variance of the voltage sample value relative to the average voltage value, reflecting the overall dispersion of voltage fluctuations within the current sampling window. The arithmetic square root operation is performed on the mean of the squared differences to obtain the standard deviation of voltage fluctuations, in volts. The standard deviation of voltage fluctuations has the same dimensions as the original voltage data and can directly reflect the actual fluctuation amplitude of the power supply voltage within the current sampling window.
[0023] In one implementation, the preset fluctuation threshold can be determined based on the nominal effective voltage value U_n of the industrial site power supply system, and is set to 5% to 10% of U_n. For example, the preset fluctuation threshold can be set to 3 volts. Those skilled in the art will understand that this threshold can be adjusted within the range of 2 to 5 volts according to the power quality characteristics of different industrial sites. For scenarios with poor power quality, it can be appropriately relaxed to 5 volts, while for precision manufacturing scenarios with strict power quality requirements, it can be tightened to 2 volts.
[0024] It should be noted that the preset duration is determined based on the shortest effective disturbance duration of power supply disturbances in industrial environments. In industrial environments, voltage fluctuations lasting less than 20 milliseconds are usually caused by momentary start-ups and shutdowns of equipment, which are short-lived disturbances within the normal range and do not pose a substantial threat to data writing; however, voltage anomalies lasting more than 20 milliseconds indicate a continuous deterioration in power supply quality and a risk of power outage. Therefore, the preset duration is set to 20 milliseconds.
[0025] In this embodiment, the complete execution process of the determination logic is as follows: when each new sampled value arrives, the standard deviation of voltage fluctuation in the current window is recalculated, and the standard deviation of voltage fluctuation is compared with 3 volts. If the standard deviation of voltage fluctuation is greater than 3 volts, the moment of exceeding the threshold is recorded, and the duration of continuous exceeding the threshold is accumulated; if the duration of continuous exceeding the threshold reaches 20 milliseconds, the power status indicator is determined to be unstable, triggering the subsequent step S13 to perform data protection operation; if the standard deviation of voltage fluctuation is not greater than 3 volts, the continuous exceeding threshold timer is reset to zero, the power status indicator is determined to be stable, and the system continues to operate normally.
[0026] In step S13, when the power status indicator is unstable, a backup data stream is obtained by copying the data stream, and the metadata log is parsed to obtain the metadata write location, including: When the power status indicator is unstable, the data stream is copied to the backup storage space of the industrial control system according to a preset copy cycle to obtain the backup data stream; Read the timestamp field and operation type field from the metadata log to obtain the timestamp field value and operation type field value; The timestamp field value and the operation type field value are parsed to obtain the metadata writing location.
[0027] In one implementation, regarding the copying of the data stream to the backup storage space to obtain the backup data stream, the backup storage space in this embodiment is not a volatile storage medium such as system memory, but a non-volatile storage area independent of the current write target (the data partition of the SD NAND storage chip). Specifically, the backup storage space can be a dedicated backup partition pre-divided within the SD NAND storage chip (e.g., divided by the physical block address within the chip, isolated from the data partition and metadata partition), or it can be another non-volatile storage chip independently configured in the industrial control system (such as serial flash memory, ferroelectric memory, etc.). The capacity of the backup storage space is set to twice the maximum write volume of the data stream to ensure that it can fully accommodate continuously generated write data during periods of power instability.
[0028] The preset replication cycle is determined based on a comprehensive evaluation of the duration of power instability and the data write rate. Specifically, the maximum normal data write rate in the industrial environment is statistically analyzed, and the amount of data generated every 5 milliseconds at this rate is calculated. It is confirmed that the spare storage space can withstand continuous replication for 50 milliseconds without overflowing, and based on this, the preset replication cycle is set to 5 milliseconds. Those skilled in the art will understand that this replication cycle can be adjusted within the range of 2 to 10 milliseconds according to the actual data write rate. In scenarios with higher write rates, it can be shortened to 2 milliseconds, and in scenarios with lower write rates, it can be extended to 10 milliseconds.
[0029] Specifically, when the power status indicator output in step S12 is unstable, the storage controller immediately triggers a replication operation. Starting from the current write position of the data stream, it reads all data content in the data stream that has not yet been written to disk and writes it to the aforementioned non-volatile spare storage space in the original byte order, completing the first replication. The time of completion of this replication is recorded as the replication start timestamp. Thereafter, an incremental replication is performed every 5 milliseconds, appending newly generated data stream content after the last replication completion time to the spare storage space until the power status indicator returns to stability or the system experiences a power outage. All replicated data content is arranged consecutively in the spare storage space according to the replication time order, forming the backup data stream.
[0030] It is important to note that because the backup storage space uses non-volatile media, even in the event of a complete system power outage (including the loss of all system memory data), the backup data stream will remain intact in the backup storage space and will not be lost. After the system is powered on again, the recovery process can directly read the backup data stream from this non-volatile backup storage space and perform operations such as truncation, segmentation, completion, and log replay to reliably restore the data state before the power outage. If the backup storage space uses a non-volatile chip independent of the main storage chip, the chip must be initialized and enabled after the system is powered on; if a dedicated backup partition inside the SD NAND chip is used, the data can be read directly using the partition address offset.
[0031] In one implementation, the metadata log is parsed to obtain the metadata write location. The metadata log is stored in the metadata partition of the SD NAND storage chip, and each record contains two fields: a timestamp field and an operation type field.
[0032] It should be noted that under unstable power conditions, the metadata log itself may be in an incomplete write state. Therefore, before parsing the metadata log, this system first performs integrity checks on the log records in the metadata partition. Specifically, the metadata log uses a write-ahead logging mechanism, with each log record accompanied by a 32-bit cyclic redundancy check value during writing, and the log partition is written using atomic sector writing (the minimum unit of each write is 512 bytes, and the total length of the log record is padded to an integer multiple of 512 bytes). When the storage controller reads the metadata log, it checks the checksum of each record in order: if the checksum of a record is correct, the record is considered complete and valid; if the checksum is incorrect, the record and all subsequent records are considered corrupted due to power failure, and the system ignores the corrupted records, using only the last complete and valid log record as the basis for parsing.
[0033] Specifically, to address the extreme case of overall corruption of the metadata log partition, while performing the backup data stream copying operation in step S13, the system simultaneously writes the latest state of the metadata currently maintained in memory (including the timestamp of the most recent write operation, the write start address, and the operation type) to the metadata backup area of the non-volatile spare storage space. The metadata backup area and the backup data stream are stored on the same non-volatile medium but in independent address ranges. When all log records read from the metadata partition of the SD NAND chip fail to be verified or there are no valid records, the system directly reads the most recently synchronized metadata state from the metadata backup area as an alternative source for the metadata write location.
[0034] In this embodiment, while triggering the replication operation, the storage controller sends a read command to the metadata partition, reads each record in the metadata log in ascending order of record write time, performs a read operation on the timestamp field of each record to obtain the timestamp field value corresponding to the record, in millisecond-level Unix timestamps, and performs a read operation on the operation type field to obtain the operation type field value corresponding to the record, which takes one of three values: write start, write complete, or write interrupted.
[0035] Furthermore, regarding the determination of the metadata write location, the operation type field value of each read record is judged one by one. Considering only complete records that pass verification, the first entry with an operation type field value of "write start" and no corresponding write completion record after it is found; this record is confirmed to correspond to an incomplete write operation. The timestamp field value of this record is extracted as the initiation time of this incomplete write operation. Combined with the write address pointer maintained internally by the storage controller, the data write start address corresponding to this initiation time is determined as the metadata write location, expressed as a byte offset, for use in subsequent step S14 to locate the log block based on the metadata write location. If no complete write start record is found in the metadata log partition (i.e., all valid records are completed in pairs), it indicates that the power outage occurred precisely between two write operations, and recovery is unnecessary. If the metadata log partition is completely damaged but the metadata backup area is valid, the metadata write location is determined based on the status of the backup area.
[0036] In step S14, the log block is verified based on the metadata write location. If the verification result is incomplete, the log block is merged with the data in the auxiliary buffer to obtain a complete log copy, including: The log block is read byte by byte according to the metadata writing location to obtain the log block byte sequence; Perform a verification operation on the byte sequence of the log block to obtain the log block verification value; The log block verification value is compared with the pre-stored benchmark verification value. If the log block verification value is inconsistent with the pre-stored benchmark verification value, the verification result is incomplete. When the verification result is incomplete, the byte sequence already written in the log block is truncated to obtain the written byte sequence; The written byte sequence is merged with the data in the auxiliary buffer at the field level to obtain the complete log copy.
[0037] In one implementation, to obtain the log block byte sequence by reading the log block byte by byte based on the metadata write position, in this embodiment, the storage controller uses the byte offset corresponding to the metadata write position output in step S13 as the starting address, and performs read operations sequentially byte by byte in the log block of the SD NAND storage chip, reading one byte at a time, until the end address of the log block. All read results are arranged in the read order to form the log block byte sequence. The log block byte sequence completely reflects all the stored content in the current log block from the metadata write position to the end, including normally committed write records and incomplete records that were not fully written due to power failure.
[0038] Specifically, regarding the execution process of the verification operation, this embodiment employs a cyclic redundancy check (CRC) algorithm to perform the verification operation on the log block byte sequence. Starting with the first byte of the log block byte sequence, the value of the current verification register is XORed with the value of that byte sequentially. The XOR result is then shifted and XORed again under the constraint of the verification polynomial, updating the value of the verification register. This process is repeated until the last byte of the log block byte sequence has been processed. The final value of the verification register is then output as the log block verification value, which is represented as a 32-bit unsigned integer.
[0039] Furthermore, regarding the comparison of the log block checksum with the pre-stored baseline checksum, the pre-stored baseline checksum is the result obtained by the industrial control system performing the same checksum operation on the byte sequence of the log block in the current state after each complete write operation is successfully completed, and this result is persistently stored in the dedicated checksum partition of the SD NAND storage chip. In this embodiment, the storage controller reads the baseline checksum stored after the most recent successful write operation from the dedicated checksum partition and compares it bit by bit with the log block checksum. If all 32 bits of the two values are completely identical, it is determined that the log block content is consistent with the most recent successful completion state, and the checksum result is determined to be complete; if any bit is inconsistent, it is determined that the log block has undergone content changes without proper commit after the most recent write operation, the checksum result is determined to be incomplete, and subsequent merge and repair operations are performed.
[0040] In one implementation, when the verification result is incomplete, the written byte sequence in the log block is extracted to obtain the written byte sequence. In this embodiment, the storage controller determines the actual disk termination position of the interrupted write operation in the log block based on the timestamp field value corresponding to the record where the write started, which is the most recent operation type field value in the metadata log, and in conjunction with the historical write address pointer maintained internally by the storage controller. The specific execution process is as follows: starting from the beginning position of the byte sequence in the log block, the data is continuously read until the byte corresponding to the actual disk termination position is reached. All bytes within this range are arranged sequentially to form the written byte sequence. The written byte sequence represents the valid data portion actually written to the storage medium before the power outage during this interrupted write operation, and is the basic data source for subsequent merging and repair.
[0041] It should be noted that, in the process of performing a field-level merging operation on the written byte sequence and the auxiliary buffer data to obtain the complete log copy, the auxiliary buffer data is obtained by the cache management unit in step S11. Its content consists of intermediate progress data of the interrupted write operation that had not yet been written to disk before the power outage, logically constituting the two parts of the same complete write operation, before and after the written byte sequence. The execution process of the field-level merging operation requires first parsing the written byte sequence and the auxiliary buffer data according to the field boundaries of the log records, identifying the complete and incomplete field units contained in each; then, taking the last field boundary of the written byte sequence as the starting point, the field content immediately following it in the auxiliary buffer data is sequentially appended to the written byte sequence, and byte-level padding is performed on the cross-segment fields at the splicing point, merging the byte content belonging to the same field in the two data segments into a complete field value; finally, all the merged field content is rearranged according to the write time order to form the complete log copy.
[0042] In this embodiment, the field-level merging operation is performed according to the following rules. Each log record has a fixed field structure, consisting of a 4-byte transaction ID, an 8-byte timestamp, a 4-byte operation type, a 4-byte write length, and a variable-length write content (the length is determined by the write length field). The system uses this structure as the parsing unit. First, the system parses each field sequentially starting from the beginning of the written byte sequence. If the end of a field exceeds the end of the sequence, the field is marked as a "segment-crossing incomplete field," and its associated transaction ID and the number of missing bytes are recorded. Then, the system parses the data in the auxiliary buffer starting from the beginning, obtaining the position of its first field and its associated transaction ID. Next, the system compares the transaction ID of the segment-crossing incomplete field in the two data segments with the transaction ID of the first record in the auxiliary buffer data. If they are the same, it is determined that they belong to the same write operation. The system extracts bytes of the same length as the number of missing bytes from the auxiliary buffer data and appends them to the end of the written byte sequence, completing the field concatenation. If the two are different, they are determined to be different write operations. The written byte sequence is directly included as part of the complete log copy, and the data in the auxiliary buffer is appended as an independent record sequence without further field-level merging. After merging, the system further compares the timestamps of the two data segments. If the timestamp of the first record in the auxiliary buffer is more than 10 milliseconds later than the timestamp of the last record in the written byte sequence, a data gap is determined to exist. Instead of direct merging, the break point is marked and handled by subsequent completion operations. If the time difference is within 10 milliseconds (including overlap), the duplicate bytes are skipped and only the new content is appended.
[0043] Specifically, a CRC-32 checksum is calculated for each merged record and compared with the pre-stored checksum attached to the record. If the checksum passes, the record is included in the complete log copy; if the checksum fails, the record is discarded and a warning log is recorded. All records that pass the checksum are arranged in timestamp order to form the complete log copy. It should be noted that the field boundaries of the log records are determined according to a predefined log record format specification. In this embodiment, each log record is stored using a fixed field width format, specifically as follows: the first 8 bytes are a timestamp field, storing a millisecond-level Unix timestamp; bytes 9 to 12 (4 bytes) are an operation type field, storing a type identifier indicating whether writing has started, completed, or interrupted; bytes 13 to 16 (4 bytes) are a write length field, storing the number of bytes of data written for this record; bytes 17 onwards are the write content field, the length of which is determined by the value of the write length field; the total length of each log record is 16 bytes plus the number of bytes indicated by the write length field. When performing field-level merge operations, the system parses the written byte sequence and the auxiliary buffer data field by field according to the above fixed format, and identifies the complete field units and incomplete field units that span segments contained in each, so as to ensure that the field boundaries of each record in the merged complete log copy are consistent with the original log record format.
[0044] In step S15, a baseline verification value and a historical transaction log index are obtained. The complete log replica is compared with the baseline verification value to obtain the replica difference rate. When the replica difference rate is greater than a preset difference threshold, the historical transaction log index is retrieved to determine the recovery starting point position, including: Perform a verification operation on the complete log copy to obtain the log copy verification value; The log replica verification value is compared bit by bit with the baseline verification value to obtain the difference bit sequence; The replica difference rate is obtained by calculating the ratio of the number of differing bits in the differing bit sequence to the total number of bits in the benchmark check value. When the replica difference rate is greater than the preset difference threshold, the historical transaction log index is traversed and searched in order of the write timestamp from the nearest to the oldest to obtain a candidate list of stable write points. A snapshot verification value is obtained by performing a verification operation on the data status record corresponding to each candidate write point in the candidate list of stable write points. The snapshot verification value is compared with the pre-stored snapshot verification value corresponding to the candidate write point. When the snapshot verification value is consistent with the pre-stored snapshot verification value, the candidate write point is determined as the recovery start point position.
[0045] In one implementation, the complete log copy is output in step S14, and its content is a complete write operation record sequence after field-level merging and repair. The storage controller performs a verification operation on the complete log copy using the same cyclic redundancy check (CRC) algorithm as in step S14. The specific execution process is as follows: starting from the first byte of the complete log copy, the value of the current verification register is XORed with the value of the byte sequentially byte by byte. The XOR result is then shifted and XORed again under the constraint of the verification polynomial, updating the value of the verification register. This operation is repeated until the last byte of the complete log copy is processed. The final value of the verification register is then output as the log copy verification value, which is represented as a 32-bit unsigned integer. Using the same verification algorithm as step S14 ensures that the log copy verification value and the baseline verification value are generated under the same calculation rule system, thereby guaranteeing the validity and comparability of subsequent bit-by-bit comparisons.
[0046] It should be noted that after calculating the log copy checksum, the system performs a bit-by-bit comparison operation. The baseline checksum is the checksum read from the dedicated checksum partition of the SD NAND storage chip after the most recent successful write operation. In this embodiment, the log copy checksum and the baseline checksum are compared sequentially, starting from the highest bit, for each pair of corresponding bits, for a total of 32 comparison operations: if the two values are the same at a certain bit, the comparison result for that bit is recorded as 0; if the two values are different at a certain bit, the comparison result for that bit is recorded as 1. All 32 comparison results are arranged in descending order of bit position to form the difference bit sequence, the length of which is fixed at 32 bits. The more bits with a value of 1 in the difference bit sequence, the greater the deviation of the complete log copy from the baseline state.
[0047] Further, the replication difference rate is calculated as follows: The total number of bits with a value of 1 in the difference bit sequence is counted to obtain the number of difference bits; this number is then divided by 32 to obtain the replication difference rate, which is a decimal between 0 and 1. When the replication difference rate is 0, it indicates that the complete log replica is completely consistent with the baseline state, and no recovery operation is required; when the replication difference rate is greater than 0, it indicates that the complete log replica has varying degrees of content deviation, and further assessment is needed to determine whether it exceeds the acceptable range.
[0048] In one implementation, the preset difference threshold is set to 0.3. This embodiment uses the CRC-32 checksum algorithm, which can detect 100% of burst errors of any length not exceeding 32 bits. Converting the threshold of 0.3 to a difference of approximately 9 bits (32 × 0.3 ≈ 9.6, rounded down to 9), this allows for a checksum difference of no more than 9 bits. Since 9 bits is still within the burst error detection capability of CRC-32, while exceeding 9 bits still allows detection, the probability of missed detection increases slightly. Therefore, 9 bits are used as the safety boundary for triggering recovery.
[0049] It should be noted that when the replica difference rate is greater than 0.3, the system determines that the complete log replica has an unacceptable content deviation and initiates the retrieval process for the recovery starting point. The historical transaction log index is an index record automatically maintained by the industrial control system after each write operation is successfully completed. Each index record contains three items: the write timestamp of the completion time of the write operation, the storage address of the data status record corresponding to the log block after the write operation, and the pre-stored snapshot verification value generated when the write operation was completed. The storage controller starts from the record with the latest timestamp in the historical transaction log index and reads each index record sequentially in ascending order of write timestamp. It extracts the write timestamp and storage address corresponding to each record and adds them to the candidate list one by one until all records in the historical transaction log index have been traversed, thus forming the candidate list of stable write points. The reason for retrieving in ascending order of timestamp is to prioritize verifying the write point closest to the current time, minimizing the number of write operations that need to be re-executed during data recovery and reducing the recovery cost.
[0050] In this embodiment, verification begins with the first candidate write point in the stable write point candidate list (i.e., the candidate write point with the latest timestamp). Based on the storage address recorded in the historical transaction log index for this candidate write point, all bytes of the data status record corresponding to the candidate write point are read from the SD NAND storage chip. The read bytes are then subjected to the same cyclic redundancy check algorithm as described above to perform a verification operation, obtaining the snapshot verification value. Subsequently, the pre-stored snapshot verification value corresponding to the candidate write point is read from the historical transaction log index. The snapshot verification value is compared bit by bit with the pre-stored snapshot verification value: if all 32 bits are completely identical, the data status record of the candidate write point is determined to be complete and reliable, and the write timestamp and storage address of the candidate write point are determined as the recovery starting point position, stopping the verification of subsequent candidate write points; if any bit is inconsistent, the data status record of the candidate write point is determined to be corrupted, and the record is skipped. The above verification process is repeated for the next candidate write point in the stable write point candidate list until the first candidate write point that passes verification is found.
[0051] It should be noted that, in extreme cases, if all candidate write points in the stable write point candidate list fail the verification, it indicates that all write states recorded in the historical transaction log index are corrupted. In this case, the system determines the recovery starting point position according to the following priority order: First priority: Read the checkpoint position written during the last normal shutdown from the system restore point preset in the metadata partition of the SD NAND storage chip. This restore point is automatically updated after N write transactions are completed during normal system operation and is stored using atomic write method (single page write, 512-byte alignment) to ensure its integrity in power failure scenarios; Second priority: If the system restore point in the metadata partition is also corrupted, read the most recently synchronized metadata state from the metadata backup area in the spare storage space (non-volatile) mentioned in step S13, including the recovery starting point position at that time; Third priority: If both of the above are invalid, the system sets the recovery starting point position to the starting address (offset of 0) of the data partition of the SD NAND storage chip and rebuilds the data index in a full scan manner.
[0052] In step S16, the backup data stream is intercepted based on the recovery starting point position to obtain the data stream to be reconstructed. The data stream to be reconstructed is segmented to obtain data stream segments. Adjacent data stream segments are compared to obtain a difference rate. When the difference rate is greater than a preset segment threshold, a completion operation is performed to obtain a continuous data chain, including: The backup data stream is intercepted starting from the recovery start point to obtain the data stream to be reconstructed; The data stream to be reassembled is sequentially segmented using a preset time window length as the segmentation unit to obtain multiple data stream segments; For each data stream segment, feature extraction is performed to obtain segment feature values. The difference between the segment feature values of adjacent data stream segments is calculated to obtain the difference rate. When the difference rate is greater than the preset segment threshold, the position between the corresponding adjacent segments is marked as a power outage interruption point, and the last complete data stream segment before the power outage interruption point is marked as a reliable cutoff point. Skipping the power outage interruption point, the data stream segments after the trusted cutoff point are concatenated with the previous data stream segments in timestamp order to obtain a continuous data chain. In one implementation, the backup data stream is formed by the storage controller continuously writing to the spare storage space at a 5-millisecond replication cycle in step S13. Its content is all data stream content from the moment the power status indicator turns unstable to the moment of power outage, arranged continuously in replication time order. The execution process of the interception operation is as follows: The storage controller uses the write timestamp corresponding to the recovery start point position output in step S15 as the starting mark, locates the byte offset position corresponding to the write timestamp in the backup data stream, and continuously reads from this position to the last byte of the backup data stream. The read results are arranged in the original byte order to form the data stream to be reconstructed. The data stream to be reconstructed represents all data content actually generated by the system but not yet completely written to disk within the time window from the recovery start point to the moment of power outage, and is the original input for subsequent segmentation and continuity detection.
[0053] It should be noted that after the interception operation is completed, the system performs a segmentation operation on the data stream to be reconstructed. The preset time window length is determined based on the minimum complete transaction unit length of industrial field data writing. A complete write transaction in an industrial control system typically includes three stages: equipment status acquisition, data encoding, and verification appending. Combined with the 100Hz sampling frequency in this embodiment, the data volume corresponding to each complete write transaction is approximately 500 bytes. Accordingly, the preset time window length is set to 500 bytes. Those skilled in the art will understand that this length can be adjusted within the range of 200 bytes to 2000 bytes depending on the actual data volume of the write transaction. 2000 bytes can be selected for scenarios with a large write transaction data volume, and 200 bytes can be selected for scenarios with a small write transaction data volume. Specifically, the storage controller starts from the starting byte of the data stream to be reconstructed, divides every 500 bytes into a data stream segment. If the last segment is less than 500 bytes, the remaining bytes are used to form a separate data stream segment. Each data stream segment is marked with its starting byte offset and ending byte offset in the data stream to be reconstructed, as well as the corresponding timestamp range, and arranged sequentially to form the multiple data stream segments.
[0054] Furthermore, after segmentation, the system performs feature extraction on each data stream segment. In this embodiment, the feature extraction process involves sequentially summing all bytes of each data stream segment to obtain the accumulated byte value of that segment; dividing the accumulated byte value by the actual number of bytes in the segment to obtain the average byte value of that segment; multiplying the average byte value by the actual number of bytes in the segment to obtain the weighted cumulative value of that segment; and outputting the weighted cumulative value as the segment's feature value. This segment feature value comprehensively reflects the content intensity and data volume of the data stream segment, effectively amplifying content abrupt changes caused by power outages between adjacent segments.
[0055] In one implementation, after feature extraction, the system performs a difference operation on each pair of adjacent segments in the plurality of data stream segments. The segment feature value of the latter segment is subtracted from the segment feature value of the former segment to obtain a difference value. The absolute value of this difference is then divided by the segment feature value of the former segment to obtain the difference rate, which is a non-negative decimal reflecting the relative deviation in content features between the two adjacent data stream segments. This operation is performed sequentially on all pairs of adjacent segments in the plurality of data stream segments, resulting in a total number of segments minus a difference rate value.
[0056] It should be noted that during feature extraction, if all bytes of a data stream segment contain zero values, the segment feature value will be zero. To avoid meaningless calculations in subsequent difference operations by using zero-value segment feature values as divisors, the system checks the segment feature value of the previous segment before performing the difference rate calculation: if the segment feature value of the previous segment is zero, the difference rate is directly set to 1, indicating an anomaly in data continuity at that position. This anomaly point will be skipped in subsequent operations to ensure that all-zero segments are not incorrectly classified as continuous data due to calculation anomalies, while also ensuring that the difference rate calculation yields meaningful results under any input conditions.
[0057] It should be noted that the preset segment threshold is determined based on the Nyquist frequency and maximum permissible distortion of the data sampling in the industrial control system. In this embodiment, the voltage sensor sampling frequency is 100Hz, and according to the sampling theorem, the highest recoverable signal frequency in the data stream is 50Hz. The permissible relative change rate between adjacent data stream segments is set to no more than 25%, i.e., the preset segment threshold is 0.25.
[0058] In this embodiment, when the difference rate of a pair of adjacent segments is greater than 0.25, the system determines that there is a data continuity break between the pair of adjacent segments, marks the boundary position of the pair of adjacent segments as a power outage interruption point, and marks the last complete data stream segment before the interruption point as a reliable cutoff point. The system does not perform any interpolation or data generation operations, directly skips the power outage interruption point, that is, it discards the first data stream segment after the interruption point, and only splices all data stream segments before the reliable cutoff point with the segments after the interruption point that have not been skipped in timestamp order. If there are multiple power outage interruption points, the above marking and skipping operations are performed on each interruption point in sequence.
[0059] It should be noted that after processing all interruption points, the system concatenates all retained data stream segments (including complete segments before the interruption points and segments after the interruption points that were not skipped) in timestamp order to form the continuous data chain. It should also be noted that this continuous data chain does not contain any pseudo-data generated through interpolation or mathematical estimation; it only contains original data segments from the backup data stream. Data gaps corresponding to skipped interruption points are explicitly marked as missing for subsequent manual inspection or system log recording, but this does not affect the authenticity and reliability of the recovered data.
[0060] In step S17, log replay is performed on the continuous data chain to obtain the data write state before the interruption. The data write state before the interruption is then indexed and reconstructed to obtain the complete data structure, including: Each data record in the continuous data chain is sorted in descending order by timestamp to obtain the reverse operation sequence; Each write operation record in the reverse operation sequence is replayed one by one to obtain the data write state before the interruption; The data write state before the interruption is divided into nodes to obtain a node set. The node set is then indexed to construct a complete data structure.
[0061] In one implementation, the continuous data chain is output in step S16. The system first extracts the timestamp field from each data record in the continuous data chain. The timestamp field is represented by a millisecond-level Unix timestamp, recording the time when the write operation corresponding to that data record occurred. After extraction, the system rearranges all data records in descending order of timestamp value, with data records with larger timestamp values placed first and data records with smaller timestamp values placed last, forming the reverse operation sequence.
[0062] It should be noted that after sorting, the system performs a replay operation on the reverse operation sequence, taking the first write operation record in the reverse operation sequence, reading its operation type field and write content field, and determining the operation category corresponding to the record based on the value of the operation type field: if the operation type field value is "write start", a corresponding write buffer is allocated in memory for the record, the byte content of its write content field is written to the write buffer, and the starting address of the buffer and the current number of bytes written are recorded; if the operation type field value is "write complete", all bytes in the corresponding write buffer are marked as confirmed, and the completion flag of the buffer is updated; if the operation type field value is "write interrupted", the byte content in the corresponding write buffer is retained up to the position indicated by the number of bytes written, the buffer content after that position is cleared to zero, and the buffer is marked as interrupted. The above operations are repeated for each write operation record in the reverse operation sequence until all records are processed.
[0063] In this embodiment, after each record is replayed, the system summarizes the contents of all write buffers in the current memory into an overall state snapshot. This snapshot reflects the actual data content of all ongoing or completed write operations in the industrial control system up to the time corresponding to that record. After all records in the reverse operation sequence have been replayed, the system outputs the final summarized state snapshot as the pre-interruption data write state. The pre-interruption data write state includes all write buffer contents at the last reliable moment before the power outage, as well as the operation status flags corresponding to each buffer, and serves as the basic data source for subsequent index reconstruction.
[0064] Furthermore, after log replay is completed, the system performs node partitioning on the data write state before the interruption. The system traverses all write buffers in the data write state before the interruption, and based on the starting address and the number of bytes written for each write buffer, divides the storage address range covered by each write buffer into independent storage nodes. Each storage node corresponds to the address range of a write buffer and carries the operation status flag (confirmed or interrupted) and the actual byte content of that buffer. All storage nodes are aggregated to form the node set. In this embodiment, the granularity of node partitioning is based on a single write buffer as the smallest unit, without further subdividing within a single buffer, to ensure that the data unit represented by each node semantically corresponds to a complete write transaction, maintaining consistency between node boundaries and write operation boundaries.
[0065] In one implementation, the node set is indexed to construct a complete data structure. The system uses the starting address of each node in the node set as the key and the byte content and operation status flag carried by each node as the index value. All nodes are arranged in ascending order of starting address value to establish an address-ordered linear index structure. The node with the smallest starting address in the node set is taken as the root node of the index, and its starting address, byte content length, and operation status flag are written into the first record of the index table. Subsequent nodes are then taken and written into the index table in ascending order of starting address. Each record contains three fields: the starting address of the node, the byte content length, and the operation status flag. For nodes in the index table whose operation status flag is "interrupted," an additional truncation position marker field is added to record the actual number of valid bytes of the node, so that subsequent write operations can accurately continue writing from the truncation position, rather than overwriting from the node's starting position. After all nodes are written to the index table, the system performs an integrity check on the index table to confirm that the sum of the starting address and byte content length of all nodes does not exceed the upper limit of the available storage capacity of the SD NAND storage chip. After the check passes, the index table is determined as the complete data structure output.
[0066] It should be noted that for nodes whose operation status flag is "confirmed" in the complete data structure, their byte content can be directly used to restore the data to disk; for nodes whose operation status flag is "interrupted and truncated", their valid byte content is also retained. Only the part after the truncated position is rewritten and overwritten in subsequent write operations, rather than being discarded entirely, so as to retain the data content that was successfully written before the power failure to the greatest extent and reduce the scope of data loss caused by power failure recovery.
[0067] Reference Figure 2 The second embodiment of the present invention provides a reliable industrial control data writing system based on SD NAND memory chips, comprising: The data acquisition module is used to acquire the voltage data sequence of the power supply terminal, the data stream currently being written, the metadata log, the log block, and the auxiliary buffer data in the industrial control system. The status analysis module is used to perform power status analysis on the voltage data sequence and determine power status indicators; The data backup module is used to perform a copy operation on the data stream to obtain a backup data stream when the power status indicator is unstable, and to parse the fields of the metadata log to obtain the metadata write location. The log verification module is used to verify the log block according to the metadata writing location. When the verification result is incomplete, the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. The difference detection module is used to obtain the baseline verification value and the historical transaction log index, perform verification calculation on the complete log copy to obtain the log copy verification value, compare the log copy verification value with the baseline verification value bit by bit to obtain the copy difference rate, and determine the recovery starting position based on the copy difference rate. The data reconstruction module is used to intercept the backup data stream based on the recovery starting point position to obtain the data stream to be reconstructed, segment the data stream to be reconstructed to obtain data stream segments, compare adjacent data stream segments to obtain the difference rate, and perform a completion operation when the difference rate is greater than a preset segment threshold to obtain a continuous data chain. The data storage module is used to perform log replay on the continuous data chain to obtain the data write status before the interruption, and to reconstruct the index of the data write status before the interruption to obtain the complete data structure.
[0068] It should be noted that the industrial control data reliable writing system based on SD NAND storage chip provided in this embodiment of the invention is used to execute all the process steps of the industrial control data reliable writing method based on SD NAND storage chip in the above embodiment. The working principle and beneficial effect of the two are one-to-one, so they will not be described again.
[0069] It should be noted that the device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the device embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.
[0070] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.
Claims
1. A reliable method for writing industrial control data based on SD NAND flash memory chips, characterized in that, include: Acquire voltage data sequences, currently being written data streams, metadata logs, log blocks, and auxiliary buffer data from the power supply side of the industrial control system; Perform power state analysis on the voltage data sequence to determine power state indicators; When the power status indicator is unstable, the data stream is copied to obtain a backup data stream, and the metadata log is parsed to obtain the metadata write location; The log block is verified based on the metadata writing location. If the verification result is incomplete, the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. Obtain the baseline verification value and the historical transaction log index, perform verification calculation on the complete log copy to obtain the log copy verification value, compare the log copy verification value with the baseline verification value bit by bit to obtain the copy difference rate, and when the copy difference rate is greater than a preset difference threshold, search the historical transaction log index to determine the recovery starting position. Based on the recovery starting point position, the backup data stream is intercepted to obtain the data stream to be reconstructed. The data stream to be reconstructed is segmented to obtain data stream segments. Adjacent data stream segments are compared to obtain the difference rate. When the difference rate is greater than a preset segment threshold, a completion operation is performed to obtain a continuous data chain. Log replay is performed on the continuous data chain to obtain the data write state before the interruption. The index of the data write state before the interruption is reconstructed to obtain the complete data structure.
2. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, The acquisition of voltage data sequences at the power supply end of the industrial control system, the currently being written data stream, metadata logs, log blocks, and auxiliary buffer data includes: The voltage data sequence is acquired by a voltage sensor in the industrial control system at a preset sampling frequency. The data stream currently being written, the metadata log, and the log block are obtained through the storage controller in the industrial control system. The auxiliary cache data is obtained through the cache management unit in the industrial control system.
3. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, The step of performing power state analysis on the voltage data sequence to determine power state indicators includes: Each sampled value in the voltage data sequence is determined as a voltage sampled value, and an arithmetic average is performed on all the voltage sampled values to obtain the voltage average value. The difference between each voltage sample value and the average voltage is calculated to obtain a difference sequence. The square of each difference in the difference sequence is then calculated to obtain a squared difference sequence. The mean of the squared differences is calculated by performing a mean operation on the squared difference sequence, and the standard deviation of the voltage fluctuation is obtained by performing a square root operation on the mean of the squared differences. When the standard deviation of the voltage fluctuation is greater than the preset fluctuation threshold and the duration is greater than the preset duration, the power supply status index is determined to be unstable; otherwise, it is determined to be stable.
4. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, When the power status indicator is unstable, a backup data stream is obtained by copying the data stream, and the metadata log is parsed to determine the metadata write location, including: When the power status indicator is unstable, the data stream is copied to the backup storage space of the industrial control system according to a preset copy cycle to obtain the backup data stream; Read the timestamp field and operation type field from the metadata log to obtain the timestamp field value and operation type field value; The timestamp field value and the operation type field value are parsed to obtain the metadata writing location.
5. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, The step of verifying the log block based on the metadata write location, and merging the log block with the auxiliary cache data when the verification result is incomplete to obtain a complete log copy, includes: The log block is read byte by byte according to the metadata writing location to obtain the log block byte sequence; Perform a verification operation on the byte sequence of the log block to obtain the log block verification value; The log block verification value is compared with the pre-stored benchmark verification value. If the log block verification value is inconsistent with the pre-stored benchmark verification value, the verification result is incomplete. When the verification result is incomplete, the byte sequence already written in the log block is truncated to obtain the written byte sequence; The written byte sequence is merged with the data in the auxiliary buffer at the field level to obtain the complete log copy.
6. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, The steps include: obtaining the baseline verification value and historical transaction log index; performing verification calculations on the complete log replica to obtain the log replica verification value; comparing the log replica verification value with the baseline verification value bit by bit to obtain the replica difference rate; and determining the recovery starting point position based on the replica difference rate. Perform a verification operation on the complete log copy to obtain the log copy verification value; The log replica verification value is compared bit by bit with the baseline verification value to obtain the difference bit sequence; The replica difference rate is obtained by calculating the ratio of the number of differing bits in the differing bit sequence to the total number of bits in the benchmark check value. When the replica difference rate is greater than the preset difference threshold, the historical transaction log index is traversed and searched in order of the write timestamp from the nearest to the oldest to obtain a candidate list of stable write points. A snapshot verification value is obtained by performing a verification operation on the data status record corresponding to each candidate write point in the candidate list of stable write points. The snapshot verification value is compared with the pre-stored snapshot verification value corresponding to the candidate write point. When the snapshot verification value is consistent with the pre-stored snapshot verification value, the candidate write point is determined as the recovery start point position.
7. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, The process involves intercepting the backup data stream based on the recovery starting point position to obtain a data stream to be reconstructed; segmenting the data stream to be reconstructed to obtain data stream segments; comparing adjacent data stream segments to obtain a difference rate; and performing a completion operation when the difference rate is greater than a preset segment threshold to obtain a continuous data chain, including: The backup data stream is intercepted starting from the recovery start point to obtain the data stream to be reconstructed; The data stream to be reassembled is sequentially segmented using a preset time window length as the segmentation unit to obtain multiple data stream segments; For each data stream segment, feature extraction is performed to obtain segment feature values. The difference between the segment feature values of adjacent data stream segments is calculated to obtain the difference rate. When the difference rate is greater than the preset segment threshold, the position between the corresponding adjacent segments is marked as a power outage interruption point, and the last complete data stream segment before the power outage interruption point is marked as a reliable cutoff point. Skip the power outage interruption point, and concatenate the data stream segments after the trusted cutoff point with the previous data stream segments in timestamp order to obtain a continuous data chain.
8. The reliable industrial control data writing method based on SD NAND storage chip according to claim 1, characterized in that, The process involves replaying the logs of the continuous data chain to obtain the data write state before the interruption, and then reconstructing the index of the data write state before the interruption to obtain the complete data structure, including: Each data record in the continuous data chain is sorted in descending order by timestamp to obtain the reverse operation sequence; Each write operation record in the reverse operation sequence is replayed one by one to obtain the data write state before the interruption; The data write state before the interruption is divided into nodes to obtain a node set. The node set is then indexed to construct a complete data structure.
9. A reliable industrial control data writing system based on SD NAND memory chips, characterized in that, include: The data acquisition module is used to acquire the voltage data sequence of the power supply terminal, the data stream currently being written, the metadata log, the log block, and the auxiliary buffer data in the industrial control system. The status analysis module is used to perform power status analysis on the voltage data sequence and determine power status indicators; The data backup module is used to perform a copy operation on the data stream to obtain a backup data stream when the power status indicator is unstable, and to parse the fields of the metadata log to obtain the metadata write location. The log verification module is used to verify the log block according to the metadata writing location. When the verification result is incomplete, the log block is merged with the data in the auxiliary cache area to obtain a complete log copy. The difference detection module is used to obtain the baseline verification value and the historical transaction log index, perform verification calculation on the complete log copy to obtain the log copy verification value, compare the log copy verification value with the baseline verification value bit by bit to obtain the copy difference rate, and determine the recovery starting position based on the copy difference rate. The data reconstruction module is used to intercept the backup data stream based on the recovery starting point position to obtain the data stream to be reconstructed, segment the data stream to be reconstructed to obtain data stream segments, compare adjacent data stream segments to obtain the difference rate, and perform a completion operation when the difference rate is greater than a preset segment threshold to obtain a continuous data chain. The data storage module is used to perform log replay on the continuous data chain to obtain the data write status before the interruption, and to reconstruct the index of the data write status before the interruption to obtain the complete data structure.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the program implements the steps of the method described in any one of claims 1 to 8.