Power distribution automation terminal based on SD card file type database and control method
By employing SD card storage modules and FATFS file systems in power distribution automation terminals, combined with embedded time-series databases and real-time monitoring mechanisms, the trade-off between data storage capacity, speed, and cost is resolved, achieving efficient data access and adaptive storage management, and improving system stability and data integrity.
Patent Information
- Application Number
- CN202510043079.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-10
- Publication Date
- 2025-11-11
- Estimated Expiration
- 2045-01-10
AI Technical Summary
Existing power distribution automation terminals have trade-offs in terms of data storage capacity, speed, and cost, and cannot simultaneously meet the needs of large data volumes and fast access.
It employs an SD card storage module combined with a FATFS file system and an embedded time-series database. The database management module enables real-time monitoring and adaptive parameter adjustment, while power management and error detection mechanisms ensure data integrity and reliability.
It significantly improves data storage reliability and access efficiency, enables rapid querying of large-scale time-series data and adaptive storage space management, and ensures system stability and data integrity in harsh environments.
Smart Images

Figure CN119960691B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the technical field of power distribution automation, and in particular to a power distribution automation terminal and control method based on an SD card file database. Background Technology
[0002] With the continuous development of power systems and the increasing demand for intelligent systems, distribution automation terminals are playing an increasingly important role in power monitoring, fault diagnosis, and data analysis. These terminals need to store large amounts of historical files, alarm records, fault records, and logs to support efficient data analysis and decision-making. However, with technological advancements, the requirements for data storage capacity and access speed are becoming increasingly stringent, and traditional storage methods are gradually failing to meet current needs.
[0003] Currently, conventional power distribution automation terminals typically use EEPROM (Electrically Erasable Programmable Read-Only Memory) and ferroelectric memory for data storage. EEPROM has the advantage of low cost, but it is slow and has limited capacity; ferroelectric memory, while fast and reliable, is more expensive and also has limited capacity. These two storage methods are suitable for traditional power distribution automation systems with small data volumes, but they become inadequate when faced with ever-increasing data volumes.
[0004] When storing large amounts of data or improving data access speed, using multiple EEPROMs or ferroelectric memories significantly increases the material cost of the product and adds complexity to the programming. Furthermore, while high-capacity Flash memory can provide ample storage space, it lacks the byte-level read / write capabilities of EEPROMs and ferroelectric memories, making it difficult to directly replace existing storage solutions. Therefore, existing storage methods present a clear trade-off between capacity, speed, and cost, failing to simultaneously meet the demands of modern power distribution automation terminals for large data volumes and rapid access; this situation requires further improvement. Summary of the Invention
[0005] To address the issue that existing storage methods suffer from significant trade-offs in capacity, speed, and cost, failing to simultaneously meet the demands of modern power distribution automation terminals for large data volumes and rapid access, this application provides a power distribution automation terminal and control method based on an SD card file-based database, employing the following technical solution:
[0006] In a first aspect, this application provides a power distribution automation terminal based on an SD card file-based database, comprising:
[0007] SD card storage module, used to provide SD card storage space;
[0008] The file system interface module is connected to the SD card storage module and is used to manage storage using the FATFS file system, establish a file system based on the SD card storage space, and obtain a standardized file access interface.
[0009] The database management module, connected to the file system interface module, is used to establish an embedded time-series database according to the file access interface. By defining a configuration structure that includes the database file path, starting address, maximum storage space, maximum number of files, maximum number of records, and record length, it realizes the storage of data records in time sequence.
[0010] The database configuration module, connected to the database management module, is used to monitor the storage status of the data records and automatically adjust the database parameters under preset conditions to form an optimized storage management strategy.
[0011] The data operation interface module, connected to the database management module and the database configuration module, is used to implement the functions of sequential writing, random reading, and querying starting from any number of records based on the storage management strategy.
[0012] By adopting the above technical solution, this application first provides basic storage space through the SD card storage module, then uses the file system interface module to achieve standardized access to the FATFS file system, then the database management module establishes a database structure that supports time-series storage, and simultaneously works with the database configuration module to achieve real-time monitoring of storage status and adaptive parameter adjustment. Finally, the data operation interface module provides flexible data access methods. Compared with traditional Flash, the SD card storage module has higher reliability and longer service life. The FATFS file system provides a complete file management mechanism, ensuring the integrity of the file system even in the event of a sudden power outage. The database management module strictly controls storage boundaries through configuration structure, avoiding data out-of-bounds and chaos problems. The database configuration module monitors the storage status in real time, and when storage pressure is detected, it automatically adjusts the maximum number of records and record length, realizing reasonable allocation of storage space, avoiding excessive resource consumption by a single data type, and significantly improving the data storage reliability and access efficiency of the power distribution automation terminal.
[0013] Optionally, the embedded time-series database includes a bidirectional index table, and the database management module performs the following steps:
[0014] Parse the query request parameters to determine the starting position and the number of entries;
[0015] The bidirectional index table is used to traverse backwards from the starting position until the number of records of the specified number of entries is obtained, thus obtaining a result set.
[0016] The result set is returned to the caller.
[0017] By adopting the above technical solution, this application first parses the user's query request parameters to obtain the specific retrieval requirements, then uses a bidirectional index table to quickly locate the starting position of the target data, then efficiently traverses along the index direction to obtain a specified number of records, and finally returns the complete result set to the caller; the bidirectional link structure realizes fast location and efficient traversal at any position, which improves the data query performance by orders of magnitude, especially in the scenario of diverse queries of large-scale time series data.
[0018] Optionally, the database configuration module includes an intelligent adjustment submodule, which performs the following steps:
[0019] Real-time monitoring of the storage status of the data records, including used space and remaining space, to obtain the current storage utilization rate;
[0020] Based on the current storage utilization and predefined rules, assess whether it is necessary to adjust the maximum number of records or the record length, and determine the adjustment requirements.
[0021] Based on the adjustment requirements, calculate the new maximum number of records and record length according to the predetermined algorithm, and update the maximum number of records and record length in the configuration structure;
[0022] The database management module is notified to apply the updated maximum number of records and record length, so that the database management module can make corresponding adjustments based on the updated maximum number of records and record length.
[0023] By adopting the above technical solution, the traditional fixed parameter configuration method cannot effectively adapt to the dynamic changes in data storage needs faced by the power distribution automation terminal during long-term operation, often leading to problems such as uneven storage space utilization or storage overflow. This application first calculates the real-time storage utilization rate by continuously monitoring the used space and remaining space, then determines whether the storage parameters need to be adjusted based on predefined evaluation rules, then uses an intelligent algorithm to calculate the optimal number of records and length parameters, and finally applies the new parameters to the database management and makes them effective in real time. Based on the intelligent adjustment mechanism of real-time monitoring, especially in the dynamic optimization of storage parameters, adaptive balance is achieved, which significantly improves the efficiency of storage space utilization.
[0024] Optionally, it also includes a power management module, which performs the following steps:
[0025] Monitor the voltage level of the power supply, and activate emergency protection measures once a sudden voltage drop or impending power outage is detected;
[0026] The emergency protection measures trigger the synchronization process of all unsubmitted data to ensure that the data in the cache is saved to the SD card storage module.
[0027] Perform a safe shutdown procedure and save the system state;
[0028] After power is restored, the system automatically loads the status of the most recent successful operation based on the system status and continues the normal working process.
[0029] By adopting the above technical solution, since the power distribution automation terminal operates in a complex power environment and often faces abnormal situations such as voltage fluctuations and sudden power outages, this application first detects abnormalities in a timely manner by continuously monitoring the power supply voltage level. Then, when a voltage abnormality is detected, a data synchronization mechanism is immediately activated to write the cached data to the SD card. Next, a safe shutdown procedure is executed to save the complete system state. Finally, after power is restored, the most recent correct operating state can be automatically loaded to continue working. This achieves early warning and rapid response to power outage risks, and also ensures data integrity through multi-level protection strategies, significantly improving the data reliability and system stability of the power distribution terminal in harsh working environments.
[0030] Optionally, the file system interface module includes an error detection and correction submodule, which performs the following steps:
[0031] Error detection is performed during each data write or read process, and the detection results are obtained.
[0032] Based on the detection results, redundant information is used for correction to obtain correct data. For errors that cannot be corrected, an alarm mechanism is triggered and corresponding protective measures are taken.
[0033] By adopting the above technical solution, since the distribution automation terminal may be affected by factors such as electromagnetic interference and storage medium aging during data reading and writing, traditional data storage solutions often lack effective error detection and repair mechanisms, resulting in the inability to guarantee data integrity and reliability. This application first embeds an error detection algorithm in each data access operation to monitor data integrity in real time, and then automatically repairs the detected errors based on a pre-designed redundancy information mechanism. For serious errors that exceed the repair capacity, an alarm is triggered in time and protection measures are activated to ensure system safety and improve the data reliability of the distribution terminal in harsh environments.
[0034] Optionally, the data operation interface module includes a memory cache submodule, which performs the following steps:
[0035] During the initialization phase, a fixed-size cache space is allocated in memory;
[0036] When writing data, the data is first stored in the cache space and marked as data to be persisted.
[0037] Periodically or when the cache reaches a certain threshold, the data to be persisted is written to the SD card storage module in batches;
[0038] When power instability is detected, the process of synchronizing the data to be persisted to the SD card storage module is immediately triggered.
[0039] By adopting the above technical solution, this application first pre-allocates a fixed-size memory cache space when the system starts up, then quickly writes newly generated data into the cache and marks its status, and then uses an intelligent scheduling algorithm to write the accumulated data into the SD card in batches at appropriate times. At the same time, it can immediately trigger data synchronization to ensure safety when a power abnormality is detected. It not only significantly improves the write performance through the caching strategy, but also effectively extends the life of the storage medium through batch operations and intelligent scheduling mechanisms.
[0040] Secondly, this application provides a power distribution automation control method based on an SD card file-based database, comprising the following steps:
[0041] Provides SD card storage space;
[0042] The FATFS file system is used for storage management. A file system is established based on the storage space of the SD card to obtain a standardized file access interface.
[0043] An embedded time-series database is established based on the file access interface. By defining a configuration structure that includes the database file path, starting address, maximum storage space, maximum number of files, maximum number of records, and record length, data records stored in time sequence are realized.
[0044] Monitor the storage status of the data records and automatically adjust the database parameters under preset conditions to form an optimized storage management strategy;
[0045] Based on the storage management strategy, the functions of sequential writing, random reading, and querying starting from any number of records are realized.
[0046] Optionally, the method may also include the following steps:
[0047] Construct a bidirectional index table;
[0048] Parse the query request parameters to determine the starting position and the number of entries;
[0049] The bidirectional index table is used to traverse backwards from the starting position until the number of records of the specified number of entries is obtained, thus obtaining a result set.
[0050] The result set is returned to the caller.
[0051] Optionally, the method may also include the following steps:
[0052] Real-time monitoring of the storage status of the data records, including used space and remaining space, to obtain the current storage utilization rate;
[0053] Based on the current storage utilization and predefined rules, assess whether it is necessary to adjust the maximum number of records or the record length, and determine the adjustment requirements.
[0054] Based on the adjustment requirements, calculate the new maximum number of records and record length according to the predetermined algorithm, and update the maximum number of records and record length in the configuration structure;
[0055] The database management module is notified to apply the updated maximum number of records and record length, so that the database management module can make corresponding adjustments based on the updated maximum number of records and record length.
[0056] Optionally, the method may also include the following steps:
[0057] Monitor the voltage level of the power supply, and activate emergency protection measures once a sudden voltage drop or impending power outage is detected;
[0058] The emergency protection measures trigger the synchronization process of all unsubmitted data to ensure that the data in the cache is saved to the SD card storage module.
[0059] Perform a safe shutdown procedure and save the system state;
[0060] After power is restored, the system automatically loads the status of the most recent successful operation based on the system status and continues the normal working process.
[0061] In summary, this application includes at least one of the following beneficial technical effects:
[0062] 1. This application first provides basic storage space through an SD card storage module, then uses a file system interface module to achieve standardized access to the FATFS file system, and then uses a database management module to establish a database structure that supports time-series storage. Simultaneously, it works with a database configuration module to achieve real-time monitoring of storage status and adaptive parameter adjustment. Finally, it provides flexible data access methods through a data operation interface module. Compared with traditional Flash memory, the SD card storage module has higher reliability and a longer lifespan. The FATFS file system provides a complete file management mechanism, ensuring file system integrity even during sudden power outages. The database management module strictly controls storage boundaries through configuration structures, avoiding data overflow and chaos. The database configuration module monitors storage status in real time, and when storage pressure is detected, it automatically adjusts the maximum number of records and record length, achieving reasonable allocation of storage space and preventing a single data type from consuming too many resources. This significantly improves the data storage reliability and access efficiency of the power distribution automation terminal.
[0063] 2. This application first parses the user's query request parameters to obtain the specific retrieval requirements, then uses a bidirectional index table to quickly locate the starting position of the target data, then efficiently traverses along the index direction to obtain a specified number of records, and finally returns the complete result set to the caller; the bidirectional link structure realizes fast location and efficient traversal at any position, which improves the data query performance by orders of magnitude, especially in the scenario of diverse queries of large-scale time series data;
[0064] 3. Due to the dynamic changes in data storage requirements faced by distribution automation terminals during long-term operation, traditional fixed parameter configuration methods cannot effectively adapt to these changes, often leading to problems such as uneven storage space utilization or storage overflow. This application first calculates the real-time storage utilization rate by continuously monitoring the used and remaining space, then determines whether storage parameters need to be adjusted based on predefined evaluation rules, then uses an intelligent algorithm to calculate the optimal number and length parameters of records, and finally applies the new parameters to database management and makes them effective in real time. Based on the intelligent adjustment mechanism of real-time monitoring, especially in the dynamic optimization of storage parameters, adaptive balancing is achieved, which significantly improves the efficiency of storage space utilization. Attached Figure Description
[0065] Figure 1 This is a schematic diagram of a power distribution automation terminal based on an SD card file database according to an embodiment of this application;
[0066] Figure 2 This is a flowchart illustrating the steps performed by the database management module in an embodiment of this application;
[0067] Figure 3 This is a flowchart illustrating the steps executed by the intelligent adjustment submodule in an embodiment of this application;
[0068] Figure 4 This is a flowchart illustrating the steps performed by the power management module in an embodiment of this application;
[0069] Figure 5 This is a flowchart illustrating the steps performed by the error detection and correction submodule in an embodiment of this application.
[0070] Figure 6 This is a flowchart illustrating the steps executed by the memory caching submodule in an embodiment of this application.
[0071] Figure 7 This is a flowchart illustrating a power distribution automation control method based on an SD card file database, as described in an embodiment of this application. Detailed Implementation
[0072] The terminology used in the following embodiments of this application is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to include the plural expressions as well, unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in this application refers to any or all possible combinations including one or more of the listed items.
[0073] Hereinafter, the terms "first" and "second" are used for descriptive purposes only and should not be construed as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature, and in the description of the embodiments of this application, unless otherwise stated, "multiple" means two or more.
[0074] The embodiments of this application will now be described in further detail with reference to the accompanying drawings.
[0075] Firstly, this application provides a power distribution automation terminal based on an SD card file-based database, referring to... Figure 1 ,include:
[0076] SD card storage module, used to provide SD card storage space.
[0077] The SD card storage module uses an industrial-grade SD card as the basic storage medium, communicates with the main controller through the standard SD bus protocol, supports 4-wire mode data transmission, and has power failure protection and data backup functions, making it suitable for long-term stable operation in industrial environments.
[0078] The file system interface module connects to the SD card storage module and is used for storage management using the FATFS file system. It establishes a file system based on the SD card storage space to obtain a standardized file access interface.
[0079] The file system interface module is based on FATFS and provides a standardized file access interface. It manages storage space using a cluster chain approach, supports multi-partition management and long filenames, and improves read / write efficiency through a file system caching mechanism, reducing the number of direct accesses to the SD card.
[0080] Specifically, this embodiment configures a sector size of 512 bytes and a cluster size of 32KB to create an independent data storage directory. Upon system startup, the file system is automatically detected and mounted, and the necessary directory structure is created. The module accesses data through standard file operation functions, supports simultaneous operations on multiple data files, and implements mutual exclusion control for file read and write operations.
[0081] The database management module connects to the file system interface module and is used to establish an embedded time-series database.
[0082] The database management module implements a lightweight time-series database based on a configuration structure. Storage parameters are defined through the database configuration structure, including key information such as the database file path, starting address, maximum storage space, maximum number of files, maximum number of records, and record length, enabling time-series storage and management of data.
[0083] Specifically, this embodiment initializes the database instance through a registration function, setting the maximum number of files to 100 and the maximum number of records per file to 10,000. Data is written in an append-only manner, automatically overwriting the oldest record when the storage limit is reached. Records include information such as timestamps, data types, and data lengths, supporting the storage and retrieval of fixed-length records.
[0084] The database configuration module, connected to the database management module, is used to monitor the storage status of data records and automatically adjust database parameters under preset conditions to form an optimized storage management strategy.
[0085] The database configuration module is responsible for monitoring the database's operational status, including information such as storage space utilization and the number of records. It automatically adjusts configuration parameters according to preset storage policies to ensure efficient database operation and handles faults in abnormal situations.
[0086] Specifically, this embodiment implements a dynamic file management mechanism. When the number of records in a single file reaches the upper limit or the file size exceeds a preset threshold (e.g., 50MB), a new file is automatically created to continue storage. The system periodically checks storage space usage and triggers a data cleanup process when available space is below 20%, prioritizing the cleanup of the oldest historical data.
[0087] The data operation interface module connects to the database management module and the database configuration module. It is used to implement sequential writing, random reading, and querying starting from any number of records based on storage management strategies.
[0088] The data operation interface module provides standardized data access methods, supporting sequential data writing and flexible querying. Write operations employ a buffer mechanism to improve writing efficiency; query operations support forward or reverse reading from any position, meeting diverse data retrieval needs.
[0089] Specifically, in this embodiment, the write operation is implemented through an append function, supporting both single-row and batch data writing. The query operation allows specifying the starting position and the number of records, supporting searches based on time range, record type, and other conditions. The system provides a return value and error code for each operation, facilitating exception handling and status monitoring. The data buffer size is configurable, with a default setting of 64KB to balance memory usage and operational efficiency.
[0090] In one embodiment, refer to Figure 2 The embedded time-series database includes a bidirectional index table, and the database management module performs the following steps:
[0091] S210. Parse the query request parameters to determine the starting position and the number of entries.
[0092] In this embodiment, a doubly linked list structure is used to implement the index table. Each index node contains the physical location, timestamp, and data length information of the record. When the system receives a query request, it first verifies the validity of the request parameters, including whether the starting position is out of bounds and whether the number of requests exceeds the limit, to ensure the security of the query operation.
[0093] Specifically, when a query request is received, the system first extracts the starting position parameter (e.g., the 100th record) and the number of records to be retrieved (e.g., 50 records) from the request. The system checks whether the starting position is less than the current total number of records, and ensures that the number of records requested does not exceed the system's configured single query limit (default is 1000 records). If the parameter validation passes, these parameters are converted into traversal parameters for the internal index table.
[0094] S220. Use a bidirectional index table to traverse backwards from the starting position until the number of entries is obtained, and get the result set.
[0095] In this embodiment, the bidirectional index table supports fast traversal in both directions. The system locates the target node in the index table based on the starting position, and then traverses in the specified direction. During the traversal, the system reads the actual data content from the storage medium based on the physical location information recorded in the index node and organizes it into a unified record format.
[0096] Specifically, the system first quickly locates the starting record using the index table. For example, to query 50 records starting from record 100, the system will directly jump to the index node of record 100. Then, the system begins the traversal process. For each index node, the system reads the actual data content it points to, including measurement values, timestamps, and other information. The system performs integrity checks on the read data to ensure its validity. The traversal process ends when the number of records read reaches the requested number of entries, or when the end of the index table is reached.
[0097] S230. Return the result set to the caller.
[0098] In one embodiment, refer to Figure 3 The database configuration module includes an intelligent tuning submodule, which performs the following steps:
[0099] S310: Monitor the storage status of data records in real time, including used space and remaining space, and obtain the current storage utilization rate.
[0100] This embodiment establishes a storage space monitoring mechanism that periodically scans the storage status of database files. The system obtains the total size, used space, and available space of the current database files through the file system interface and calculates the storage space utilization rate. The monitoring process is executed as a low-priority task to avoid affecting the system's normal data storage operations.
[0101] Specifically, the system performs a storage status check every 30 minutes and calculates the current storage utilization rate. For example, if the database file size is 100MB and the used space is 75MB, then the current storage utilization rate is 75%. The system records the detection results in the status log, including information such as detection time, total space, used space, remaining space, and storage utilization rate, for subsequent analysis and decision-making.
[0102] S320. Based on the current storage utilization and predefined rules, assess whether it is necessary to adjust the maximum number of records or the record length, and determine the adjustment requirements.
[0103] In this embodiment, multi-level storage utilization thresholds are set to trigger different levels of adjustment strategies. The system compares the current storage utilization with the preset thresholds, combines historical storage trend analysis, determines whether parameter adjustments are needed, and determines the direction and magnitude of the adjustments.
[0104] Specifically, the system sets three key thresholds: a warning threshold (80%), an emergency threshold (90%), and a danger threshold (95%). When storage utilization exceeds the warning threshold, the system begins to assess the need for adjustments. For example, if the current storage utilization is 85% and has shown a continuous upward trend recently, the system will mark it as requiring mild parameter adjustments; if the emergency threshold is reached, it will mark it as requiring a more aggressive adjustment plan.
[0105] S330. Based on the adjustment requirements, calculate the new maximum number of records and record length according to the predetermined algorithm, and update the maximum number of records and record length in the configuration structure.
[0106] In this embodiment, a progressive adjustment algorithm is used to calculate new parameter values according to different levels of adjustment requirements.
[0107] Specifically, when parameter adjustments are required, the system first calculates the ideal adjustment ratio for the number of records. For example, in a mild adjustment mode, the system reduces the maximum number of records by 10%; in an emergency adjustment mode, it reduces it by 20%. Simultaneously, the system assesses the optimization potential for record length, and if redundant fields exist, the record length is reduced accordingly. The calculation of new parameters ensures that each record retains at least a basic timestamp and key data fields, typically no less than 64 bytes.
[0108] S340. Notify the database management module to apply the updated maximum number of records and record length, so that the database management module can make corresponding adjustments based on the updated maximum number of records and record length.
[0109] This embodiment implements a secure parameter update mechanism to ensure that parameter adjustment does not affect ongoing data operations. The system employs a dual-buffer strategy: new parameter configurations are first written to a temporary buffer, and the actual parameter switch is only performed after all ongoing operations have been confirmed to be complete.
[0110] Specifically, the system sends parameter update notifications to the database management module via a message queue, containing information on the new maximum number of records and record length. Upon receiving the notification, the database management module waits for the current write operation to complete before loading the new parameters into the configuration structure. If the current number of records exceeds the new maximum number of records, the system automatically cleans up the oldest records until the new limits are met. The entire adjustment process is logged in the system log for subsequent operational analysis and problem localization.
[0111] In one embodiment, refer to Figure 4 It also includes a power management module, which performs the following steps:
[0112] S410: Monitor the power supply voltage level and activate emergency protection measures if a sudden voltage drop or impending power outage is detected.
[0113] In this embodiment, an independent voltage monitoring circuit is used to sample the power supply voltage in real time via a high-precision ADC. The system has multiple voltage alarm thresholds. When the voltage is detected to be below the warning threshold or shows a rapid downward trend, a protection mechanism is immediately triggered to ensure data security.
[0114] S420: Trigger the synchronization process of all uncommitted data according to emergency protection measures to ensure that the data in the cache is saved to the SD card storage module.
[0115] This embodiment establishes a hierarchical data caching mechanism, including memory caching and SD card caching. When a power failure is detected, the system first suspends the writing of new data, and then synchronizes the data in memory to the SD card according to the priority of data importance.
[0116] Specifically, the system categorizes cached data into three priorities: critical configuration data (such as system parameters), real-time acquired data, and historical statistical data. When the synchronization process is triggered, the system first writes the critical configuration data to a specific sector of the SD card, then synchronizes the real-time acquired data, and finally synchronizes the historical statistical data. The system utilizes the power supply provided by the remaining capacitors to complete these operations.
[0117] S430: Perform a safe shutdown procedure and save the system state.
[0118] This embodiment implements a state preservation mechanism that saves the system's operating state, data index information, and key parameters to a specific area of the SD card before shutdown. The system state information is stored using a dual-backup method and supplemented with a CRC checksum to ensure data integrity and reliability.
[0119] Specifically, the system packages information such as the current operating mode, database index position, and timestamp of the last successful operation into a status data packet. The status data is stored in a specific format, containing 16 bytes of header information (identifier and checksum) and 64 bytes of status data. The system reserves two 1KB status storage areas on the SD card, using these two areas alternately for status saving to prevent loss of status information due to sudden power outages.
[0120] S440: After power is restored, the system will automatically load the status of the most recent successful operation based on the system status and continue the normal working process.
[0121] In this embodiment, a state recovery mechanism is established. When the system starts, it first loads and verifies the integrity of the state information. If the state information is found to be valid, the system operating environment is restored according to the saved parameters; if the state information is invalid or corrupted, a safe mode is started, and the system is reinitialized using the default configuration.
[0122] In one embodiment, refer to Figure 5 The file system interface module includes an error detection and correction submodule, which performs the following steps:
[0123] S510. Perform error detection during each data write or read process and obtain the detection results.
[0124] This embodiment employs a multi-level error detection mechanism to monitor and verify data in real time. During data writing, the system adds CRC checksums and Hamming codes to data blocks, forming data packets with error detection and correction capabilities. During data reading, the system first verifies data integrity, then performs bit error detection, and finally outputs the detection results.
[0125] Specifically, the system calculates a 32-bit CRC checksum for each 512-byte data block and adds a 7-bit Hamming code for single-bit error correction. During write operations, the system divides the data into multiple blocks for processing, with each block calculating its checksum independently. During read operations, the system first verifies the CRC checksum; if an error is detected, it performs further analysis using the Hamming code. The system categorizes the detection results into three types: no error, correctable error, and uncorrectable error, and records the occurrence frequency and location information for each type of error.
[0126] S520. Based on the test results, use redundant information to perform corrections to obtain correct data.
[0127] In this embodiment, for correctable errors, the system uses Hamming codes for automatic correction; for detected uncorrectable errors, the system marks the error location and attempts to restore data from the backup data area. Simultaneously, the system assesses the severity of the error and initiates data protection procedures if necessary.
[0128] Specifically, when a single-bit error is detected, the system automatically corrects the error using a Hamming code algorithm. For multi-bit errors, the system first attempts to recover data from a preset backup area. If the backup data also contains errors, a warning message is sent to the system. The system records detailed error information, including error type, time of occurrence, and data block location. When the error rate exceeds a preset threshold (e.g., more than 10 correctable errors per hour or uncorrectable errors occur), the system automatically reduces read / write speeds and sends a warning message to the administrator. Storage areas that frequently experience errors are marked as dangerous areas by the system to prevent subsequent write operations from using those areas.
[0129] In one embodiment, refer to Figure 6 The data operation interface module includes a memory cache submodule, which performs the following steps:
[0130] S610, during the initialization phase, allocates a fixed-size cache space in memory.
[0131] In this embodiment, a circular buffer structure is adopted. When the system starts, the cache space is dynamically allocated according to the available memory size and data processing requirements. The cache space is divided into multiple data blocks of equal size. Each data block contains a status flag to identify the usage status and data validity of the data block.
[0132] S620: When writing data, the data is first stored in the cache space and marked as data to be persisted.
[0133] This embodiment implements a fast write mechanism, where new data is first written to the memory cache and the write result is returned immediately. The system uses a two-pointer technique to track the data status: the write pointer points to the next available data block, and the synchronization pointer marks the range of data to be synchronized, ensuring the order and integrity of the data.
[0134] Specifically, when a write request is received, the system first checks if the data block pointed to by the write pointer is available. If the data size exceeds the capacity of a single data block, the system automatically stores the data in multiple consecutive data blocks. After the write is complete, the system updates the data block's status flag to "pending synchronization" and records the write time. If the cache space is insufficient, the system triggers an emergency synchronization operation, writing some of the data to be synchronized to the SD card to free up cache space.
[0135] S630 periodically or when the cache reaches a certain threshold, writes the data to be persisted to the SD card storage module in batches.
[0136] In this embodiment, an adaptive synchronization strategy is adopted. The system monitors cache utilization and data write frequency, and dynamically adjusts the synchronization triggering conditions. When the cache utilization reaches a preset threshold, or when the accumulated amount of data to be synchronized reaches the optimal size for batch writing, the system automatically starts the synchronization process.
[0137] Specifically, the system sets two trigger conditions: cache utilization reaches 75% or the accumulated data to be synchronized exceeds 512KB. The synchronization process proceeds according to the storage order of data blocks, synchronizing a maximum of 64 data blocks at a time. The system merges consecutive data blocks into larger data packets for writing, improving the write efficiency of the SD card. After synchronization is complete, the system updates the data block status to "synchronized," moves the synchronization pointer, and releases the synchronized cache space.
[0138] S640: When power instability is detected, the process of synchronizing the data to be persisted to the SD card storage module is immediately triggered.
[0139] In this embodiment, an emergency synchronization mechanism is established. The system obtains power status information through a power monitoring module. When an abnormal power voltage is detected or an emergency synchronization signal is received, the system immediately suspends the writing of new data and prioritizes processing the data to be synchronized in the cache, ensuring that data is not lost due to power failure.
[0140] Specifically, when the system detects that the power supply voltage is below a threshold, it immediately initiates an emergency synchronization process. The system calculates the total size of all data to be synchronized and estimates the available synchronization time based on the remaining power. If the amount of data to be synchronized is large, the system will prioritize synchronizing critical data (such as system configuration information and recently written data). The synchronization process uses a dedicated emergency write mode, disabling the SD card's caching mechanism and directly writing the data to the physical sectors. Although the write speed is slower, this ensures data reliability.
[0141] Secondly, this application provides a power distribution automation control method based on an SD card file-based database. The power distribution automation control method based on an SD card file-based database of this application will be described below in conjunction with the aforementioned power distribution automation terminal based on an SD card file-based database.
[0142] Reference Figure 7 A power distribution automation control method based on an SD card file database includes the following steps:
[0143] S710 provides SD card storage space;
[0144] S720 uses the FATFS file system for storage management, and establishes a file system based on the SD card storage space to obtain a standardized file access interface.
[0145] S730: An embedded time-series database is established based on the file access interface. By defining a configuration structure that includes the database file path, starting address, maximum storage space, maximum number of files, maximum number of records, and record length, data records stored in time sequence are realized.
[0146] S740 monitors the storage status of data records and automatically adjusts database parameters under preset conditions to form an optimized storage management strategy;
[0147] The S750, based on storage management strategies, enables sequential writing, random reading, and querying starting from any number of records.
[0148] In one embodiment, the method further includes the following steps:
[0149] Construct a bidirectional index table;
[0150] Parse the query request parameters to determine the starting position and the number of entries;
[0151] Use a bidirectional index table to traverse backwards from the starting position until the number of entries is obtained, and then obtain the result set;
[0152] Return the result set to the caller.
[0153] In one embodiment, the method further includes the following steps:
[0154] Real-time monitoring of the storage status of data records, including used space and remaining space, to obtain the current storage utilization rate;
[0155] Based on the current storage utilization and predefined rules, assess whether it is necessary to adjust the maximum number of records or the record length, and determine the adjustment requirements.
[0156] Based on the adjustment requirements, calculate the new maximum number of records and record length according to the predetermined algorithm, and update the maximum number of records and record length in the configuration structure;
[0157] The database management module is notified to apply the updated maximum number of records and record length, so that the database management module can make corresponding adjustments based on the updated maximum number of records and record length.
[0158] In one embodiment, the method further includes the following steps:
[0159] Monitor the voltage level of the power supply, and activate emergency protection measures once a sudden voltage drop or impending power outage is detected;
[0160] The emergency protection measures trigger the synchronization process of all uncommitted data to ensure that the data in the cache is saved to the SD card storage module.
[0161] Perform a safe shutdown procedure and save the system state;
[0162] After power is restored, the system will automatically load the status of the most recent successful operation based on the system status and continue the normal working process.
[0163] In one embodiment, the method further includes the following steps:
[0164] Error detection is performed during each data write or read process, and the detection results are obtained.
[0165] Based on the test results, redundant information is used for correction to obtain correct data. For errors that cannot be corrected, an alarm mechanism is triggered and corresponding protective measures are taken.
[0166] In one embodiment, the method further includes the following steps:
[0167] During the initialization phase, a fixed-size cache space is allocated in memory;
[0168] When writing data, the data is first stored in the cache space and marked as data to be persisted.
[0169] Periodically or when the cache reaches a certain threshold, the data to be persisted is written to the SD card storage module in batches;
[0170] When power instability is detected, the process of synchronizing the data to be persisted to the SD card storage module is immediately triggered.
[0171] It should be understood that the sequence number of each step in the above embodiments does not imply the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of this application.
[0172] The above are all preferred embodiments of this application, and are not intended to limit the scope of protection of this application. Therefore, all equivalent changes made in accordance with the structure, shape and principle of this application should be covered within the scope of protection of this application.
Claims
1. A power distribution automation terminal based on an SD card file-based database, characterized in that, include: SD card storage module, used to provide SD card storage space; The file system interface module is connected to the SD card storage module and is used to manage storage using the FATFS file system, establish a file system based on the SD card storage space, and obtain a standardized file access interface. The database management module, connected to the file system interface module, is used to establish an embedded time-series database according to the file access interface. By defining a configuration structure that includes the database file path, starting address, maximum storage space, maximum number of files, maximum number of records, and record length, it realizes the storage of data records in time sequence. The database configuration module, connected to the database management module, is used to monitor the storage status of the data records and automatically adjust the database parameters under preset conditions to form an optimized storage management strategy. The data operation interface module is connected to the database management module and the database configuration module, and is used to implement the functions of sequential writing, random reading and querying starting from any number of records based on the storage management strategy. The embedded time-series database includes a bidirectional index table, and the database management module performs the following steps: Parse the query request parameters to determine the starting position and the number of entries; The bidirectional index table is used to traverse backwards from the starting position until the number of records of the specified number of entries is obtained, thus obtaining a result set. Return the result set to the caller; The database configuration module includes an intelligent adjustment submodule, which performs the following steps: Real-time monitoring of the storage status of the data records, including used space and remaining space, to obtain the current storage utilization rate; Based on the current storage utilization and predefined rules, assess whether it is necessary to adjust the maximum number of records or the record length, and determine the adjustment requirements. Based on the adjustment requirements, calculate the new maximum number of records and record length according to the predetermined algorithm, and update the maximum number of records and record length in the configuration structure; The database management module is notified to apply the updated maximum number of records and record length, so that the database management module can make corresponding adjustments based on the updated maximum number of records and record length.
2. The power distribution automation terminal based on an SD card file-type database according to claim 1, characterized in that, It also includes a power management module, which performs the following steps: Monitor the voltage level of the power supply, and activate emergency protection measures once a sudden voltage drop or impending power outage is detected; The emergency protection measures trigger the synchronization process of all unsubmitted data to ensure that the data in the cache is saved to the SD card storage module. Perform a safe shutdown procedure and save the system state; After power is restored, the system automatically loads the status of the most recent successful operation based on the system status and continues the normal working process.
3. The power distribution automation terminal based on an SD card file-type database according to claim 1, characterized in that, The file system interface module includes an error detection and correction submodule, which performs the following steps: Error detection is performed during each data write or read process, and the detection results are obtained. Based on the detection results, redundant information is used for correction to obtain correct data. For errors that cannot be corrected, an alarm mechanism is triggered and corresponding protective measures are taken.
4. The power distribution automation terminal based on an SD card file database according to claim 1, characterized in that, The data operation interface module includes a memory cache submodule, which performs the following steps: During the initialization phase, a fixed-size cache space is allocated in memory; When writing data, the data is first stored in the cache space and marked as data to be persisted. Periodically or when the cache reaches a certain threshold, the data to be persisted is written to the SD card storage module in batches; When power instability is detected, the process of synchronizing the data to be persisted to the SD card storage module is immediately triggered.
5. A power distribution automation control method based on an SD card file database, characterized in that, Includes the following steps: Provides SD card storage space; The FATFS file system is used for storage management. A file system is established based on the storage space of the SD card to obtain a standardized file access interface. An embedded time-series database is established based on the file access interface. By defining a configuration structure that includes the database file path, starting address, maximum storage space, maximum number of files, maximum number of records, and record length, data records stored in time sequence are realized. Monitor the storage status of the data records and automatically adjust the database parameters under preset conditions to form an optimized storage management strategy; Based on the storage management strategy, the functions of sequential writing, random reading, and querying starting from any number of records can be realized; The method also includes the following steps: Construct a bidirectional index table; Parse the query request parameters to determine the starting position and the number of entries; The bidirectional index table is used to traverse backwards from the starting position until the number of records of the specified number of entries is obtained, thus obtaining a result set. Return the result set to the caller; The method also includes the following steps: Real-time monitoring of the storage status of the data records, including used space and remaining space, to obtain the current storage utilization rate; Based on the current storage utilization and predefined rules, assess whether it is necessary to adjust the maximum number of records or the record length, and determine the adjustment requirements. Based on the adjustment requirements, calculate the new maximum number of records and record length according to the predetermined algorithm, and update the maximum number of records and record length in the configuration structure; The database management module is notified to apply the updated maximum number of records and record length, so that the database management module can make corresponding adjustments based on the updated maximum number of records and record length.
6. The power distribution automation control method based on an SD card file database according to claim 5, characterized in that, The method also includes the following steps: Monitor the voltage level of the power supply, and activate emergency protection measures once a sudden voltage drop or impending power outage is detected; The emergency protection measures trigger the synchronization process of all unsubmitted data to ensure that the data in the cache is saved to the SD card storage module. Perform a safe shutdown procedure and save the system state; After power is restored, the system automatically loads the status of the most recent successful operation based on the system status and continues the normal working process.
Citation Information
Patent Citations
Object storage data storage management method, device and equipment
CN114153392A
Data access method, electronic device, and computer readable storage medium
WO2024061129A1