Battery test equipment power failure data protection method and device based on multi-level cache
Patent Information
- Application Number
- CN202610871621.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-16
- Publication Date
- 2026-08-18
- Estimated Expiration
- 2046-06-16
AI Technical Summary
[0007]本发明提供一种基于多级缓存的电池测试设备掉电数据保护方法、装置及存储介质,用以解决现有技术中电池测试设备掉电时数据易丢失、实时性与可靠性难以兼顾、多通道写入冲突、缺乏分级保护以及写入原子性无法保证等缺陷
[0018] The battery testing equipment power-loss data protection method, device, and storage medium based on multi-level caching of the present invention have the following beneficial effects: The present invention, through a multi-level caching collaborative protection mechanism, initiates data saving within a very short time (e.g., within 50 milliseconds) after power-loss detection is triggered, effectively reducing the risk of data loss due to power failure; through a hierarchical caching strategy of real-time data buffer queue, historical data buffer queue, and power-loss protection cache, memory buffering effectively reduces I/O frequency, ensuring the test control cycle is unaffected; through independent cache queues for each channel and mutex lock protection, large-scale multi-channel parallel writing is supported without resource conflicts; through the separate processing of real-time data and historical data, resource allocation optimization and priority protection of critical data are achieved; through append writing and dual data synchronization mechanisms, the complete retention of written data during power failure is ensured, guaranteeing the atomicity of writing.
Smart Images

Figure CN122387754B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of battery testing technology, and more particularly to a method, apparatus, and storage medium for power-off data protection of battery testing equipment based on multi-level caching. Background Technology
[0002] In scenarios such as lithium battery formation and capacity testing, battery module and battery pack testing, and electric vehicle battery management system testing, battery testing equipment needs to record key parameters such as voltage, current, capacity, and energy in real time over a long period of time. For example, aging tests and cycle life tests often last for several days or even weeks, and their test data has extremely high cumulative value. If the equipment suddenly loses power during testing, the test data being collected and transmitted cannot be reliably saved, which will result in the loss of data integrity for the entire testing cycle, and may even require restarting the long-cycle test, causing a significant waste of manpower, time, and equipment resources.
[0003] The existing power-loss data protection solutions for battery testing equipment mainly include the following: One approach is a temporary storage scheme based on Random Access Memory (RAM) caching. During testing, data is temporarily stored in RAM and automatically erased upon power failure, relying solely on an external uninterruptible power supply (UPS) for data security. The drawback of this scheme is that data is lost immediately upon power failure, it lacks local persistence capabilities, and it is highly dependent on external power supplies.
[0004] Secondly, there is the scheme of periodically polling and writing to external storage. This scheme writes data to the external storage medium at fixed time intervals (e.g., every minute). Its drawback is that, in extreme cases, all data within a time interval (e.g., 1 minute) may be lost; at the same time, increasing the write frequency to reduce data loss will trigger frequent input / output (I / O) operations, thus affecting the real-time performance of test control. The two constitute an irreconcilable contradiction.
[0005] Third, a simple buffering scheme with a single cache layer. This scheme uses only a single cache (such as a pure memory buffer), lacks a secondary confirmation mechanism when power is lost, and the data frame being written may be truncated, resulting in incomplete data.
[0006] Therefore, a new solution is needed. Summary of the Invention
[0007] This invention provides a method, device, and storage medium for protecting power-loss data in battery testing equipment based on multi-level caching, in order to solve the defects in the prior art such as easy data loss when battery testing equipment loses power, difficulty in balancing real-time performance and reliability, multi-channel write conflicts, lack of hierarchical protection, and inability to guarantee write atomicity.
[0008] According to a first aspect of the present invention, a method for power-loss data protection in a battery testing device based on multi-level caching is provided, the method comprising: S1. Under normal operating conditions of the battery testing equipment, the collected battery test data is written into the real-time data buffer queue for caching; when the preset transfer conditions are met, the data in the real-time data buffer queue is transferred to the historical data buffer queue, and the historical data buffer queue sends the battery test data to the host computer. S2. Continuously monitor the power status of the battery testing equipment. When a change in the power status is detected, determine whether the current event is a power failure or a power-on recovery event. S3. When a power failure event is detected, the data acquisition and testing process of the battery testing equipment are suspended, and the breakpoint status information of each test channel is saved. S4. Transfer the data to be sent in the historical data buffer queue to the power-loss protection buffer through a whole assignment operation; wherein, before the whole assignment operation is completed, the data in the historical data buffer queue remains valid; after confirming that the power-loss protection buffer has obtained complete data, the corresponding data in the historical data buffer queue is released. S5. The data in the power failure protection cache is appended to the historical data file in the non-volatile storage medium, and a data synchronization operation is performed to write the data in the power failure protection cache to the non-volatile storage medium; wherein, the power failure protection process is maintained by the energy storage element. S6. When a power-on recovery event is determined, the historical data file is read and its integrity is verified. The buffer status information and the data to be transmitted are restored according to the data that has passed the verification. The transmission resume flag is set so that the data that has not been sent can be transmitted to the host computer. S7. Restore the test process and data acquisition of each test channel based on the breakpoint status information.
[0009] In a preferred embodiment of the present invention, the method further includes: during the writing of the non-volatile storage medium, the real-time data buffer queue continuously receives newly generated battery test data; the real-time data buffer queue, the historical data buffer queue, and the power-loss protection cache are respectively set in different storage areas; the preset transfer condition includes the accumulated data amount of the historical data buffer queue reaching a preset data amount threshold.
[0010] In a preferred embodiment of the present invention, step S4 includes: keeping the data in the historical data buffer queue from being released before the data in the historical data buffer queue is completely copied to the power failure protection cache; and releasing the storage resources occupied by the historical data buffer queue after the copying is completed.
[0011] In a preferred embodiment of the present invention, the data synchronization operation includes: flushing the data to be written from the user space buffer to the system cache; and then writing the data in the system cache to a non-volatile storage medium through a storage synchronization instruction.
[0012] In a preferred embodiment of the present invention, the historical data file includes: a file header including an identifier field; a data area including at least one historical data record; and a file footer including a data bar number segment. The integrity verification includes: determining whether the historical data file is valid based on the identifier field, and parsing the historical data record based on the storage format of the data bar number segment and the data area.
[0013] In a preferred embodiment of the present invention, the historical data file further includes a data description structure header; the data description structure header includes a length field, a command field, an index field, and a sequence field; the integrity verification further includes: determining whether the historical data file is complete based on the consistency relationship between the file length, the data description structure header information, and the data area length.
[0014] In a preferred embodiment of the present invention, the method further includes: when a power failure event is determined, pausing the test process of each channel of the battery test equipment, stopping the generation of new battery test data, and saving the breakpoint data by each channel; when a power-on recovery event is determined, resuming the test process and data acquisition of each channel after a preset recovery delay; wherein each channel is configured with an independent real-time data buffer queue and a historical data buffer queue, and the write operation of the historical data file is protected by a mutex lock.
[0015] In a preferred embodiment of the present invention, the historical data buffer queue is implemented using a fixed-capacity circular buffer. When the power failure protection process determines that a power failure event has occurred, it saves the write pointer offset, read pointer offset, and buffer start address of the circular buffer. In the power-on recovery event, the length of unsent data is calculated based on the saved write pointer offset, read pointer offset, and buffer capacity, and the transmission resumes from the breakpoint corresponding to the read pointer position. The logical order of the unsent data is restored based on the saved read pointer offset and write pointer offset.
[0016] According to a second aspect of the present invention, a power-loss data protection device for a battery testing equipment based on multi-level caching is also provided, for implementing the method described above, comprising: The data buffer module is used to write the collected battery test data into the real-time data buffer queue, and transfer it to the historical data buffer queue and send it to the host computer in batches when the preset batch sending conditions are met. The power failure detection module is used to continuously monitor the power status of the battery testing equipment. When a change in the power status is detected, it determines whether the current event is a power failure or a power-on recovery event. The power-down protection module is used to pause the data acquisition and testing process of the battery testing equipment when a power-down event is detected, save the breakpoint status information of each test channel, transfer the data to be sent in the historical data buffer queue to the power-down protection cache through a whole assignment operation, append the data in the power-down protection cache to the historical data file in the non-volatile storage medium, and perform a data synchronization operation to write the data in the power-down protection cache to the non-volatile storage medium; wherein, the power supply is maintained by the energy storage element during the power-down protection process; The data recovery module is used to read the historical data file and perform integrity verification when a power-on recovery event is determined. Based on the verified data recovery buffer status information and the data to be continued, the module sets the continue flag to continue the transmission of the data that has not been sent to the host computer.
[0017] According to a third aspect of the present invention, a computer-readable storage medium is also provided, on which a computer program is stored, wherein the computer program, when executed by a processor, implements the steps of the power-loss data protection method for a battery testing device based on multi-level caching as described above.
[0018] The battery testing equipment power-loss data protection method, device, and storage medium based on multi-level caching of the present invention have the following beneficial effects: The present invention, through a multi-level caching collaborative protection mechanism, initiates data saving within a very short time (e.g., within 50 milliseconds) after power-loss detection is triggered, effectively reducing the risk of data loss due to power failure; through a hierarchical caching strategy of real-time data buffer queue, historical data buffer queue, and power-loss protection cache, memory buffering effectively reduces I / O frequency, ensuring the test control cycle is unaffected; through independent cache queues for each channel and mutex lock protection, large-scale multi-channel parallel writing is supported without resource conflicts; through the separate processing of real-time data and historical data, resource allocation optimization and priority protection of critical data are achieved; through append writing and dual data synchronization mechanisms, the complete retention of written data during power failure is ensured, guaranteeing the atomicity of writing. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort: Figure 1This is a flowchart illustrating the power-loss data protection method for battery testing equipment based on multi-level caching provided by the present invention. Figure 2 This is a schematic diagram of the power failure protection system architecture of the battery testing equipment provided by the present invention; Figure 3 This is a schematic diagram of the power-off protection timing of the battery testing equipment provided by the present invention; Figure 4 This is a schematic diagram of the power-off data protection device for a battery testing equipment based on multi-level caching provided by the present invention; Figure 5 This is a schematic diagram of the physical structure of the electronic device provided by the present invention. Detailed Implementation
[0020] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0021] Existing battery testing equipment's power-loss data protection technologies either rely on external uninterruptible power supplies and lack local persistence capabilities, or use periodic polling for writing, resulting in data loss windows and affecting real-time performance, or use a single cache layer without a secondary confirmation mechanism. Generally, they are unable to guarantee the integrity of test data and the atomicity of writing during sudden power outages, and are prone to write conflicts during multi-channel parallel testing.
[0022] To address the aforementioned issues, this invention proposes a power-loss data protection method for battery testing equipment based on multi-level caching. In this method, during normal operation, battery test data is sequentially buffered through a real-time data buffer queue and a historical data buffer queue, and then sent in batches to the host computer. Power-loss events and power-on recovery events are identified by continuously monitoring the power status. During a power outage, data acquisition is paused, breakpoint status information is saved, and the data to be sent from the historical data buffer queue is copied to the power-loss protection cache before being released. This cache is then appended to a non-volatile storage medium, and data synchronization is performed. During power-on recovery, the historical data file is read and its integrity is verified. The buffer state and the data to be transmitted are restored and transmitted. Finally, the testing process for each channel is restored. Power is maintained by energy storage components throughout the entire power-loss protection process.
[0023] In the description of the embodiments of the present invention, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of indicated technical features. In the description of the embodiments of the present invention, "a plurality of" means two or more, unless otherwise explicitly defined.
[0024] Figure 1 This is a flowchart illustrating the power-loss data protection method for battery testing equipment based on multi-level caching provided by the present invention, as shown below. Figure 1 As shown, the method includes the following steps S1-S7.
[0025] Step S1: Under normal operating conditions of the battery testing equipment, the collected battery test data is written into the real-time data buffer queue for caching; when the preset transfer conditions are met, the data in the real-time data buffer queue is transferred to the historical data buffer queue, and the historical data buffer queue sends the battery test data to the host computer.
[0026] Specifically, battery test data refers to key parameter data collected in real time during battery charge and discharge testing, which may include, but is not limited to, fields such as voltage, current, capacity, energy, recording time, step time, absolute time, cycle number, step number, step number, and step name. In some implementations of this invention, each piece of battery test data can be organized using a structure of mixed historical data items, which includes main channel data and additional data of variable length such as auxiliary voltage, auxiliary temperature, summary information, single-cell voltage, and single-cell temperature.
[0027] Under normal operating conditions, the collected battery test data is first temporarily stored in a real-time data buffer queue. The real-time data buffer queue is used to receive raw data generated at high frequencies. Its enqueue operation only involves pointer appending and length accumulation, and the time consumption can be controlled in the microsecond range. This completely decouples the data enqueue operation from the test control cycle (e.g., 10 milliseconds) and avoids the impact of data acquisition on the real-time performance of test control.
[0028] When a preset transfer condition is met, data in the real-time data buffer queue is transferred to the historical data buffer queue. In some implementations, the preset transfer condition is triggered by a data volume threshold rather than a timer. For example, the cumulative data volume threshold of the historical data buffer queue can be set to 20 megabytes (MB), or the transfer can be triggered when the accumulated data volume of the historical data buffer queue reaches a preset proportion of its maximum capacity. Using a data volume threshold trigger avoids the fixed loss window caused by polling writes at fixed time intervals, while reducing unnecessary I / O operation frequency.
[0029] After being transferred to the historical data buffer queue, the data management module sends the battery test data to the host computer in batches. The two-level buffer separation design decouples data reception from data transmission, avoiding frequent I / O operations that could affect the real-time performance of test control.
[0030] It should be noted that, in this embodiment of the invention, the real-time data buffer queue and the historical data buffer queue can be implemented using data structures such as deques, linked lists, or fixed-capacity circular buffers. When implemented using standard containers such as deques, the transfer operation can be completed using the container's assignment operator; when implemented using a circular buffer, the transfer can be achieved through pointer ownership transfer, as detailed in step S4 and the description of related alternative implementations of the circular buffer below.
[0031] Step S2: Continuously monitor the power status of the battery testing equipment. When a change in the power status is detected, determine whether the current event is a power outage or a power-on recovery event.
[0032] Specifically, in some possible implementations, power status monitoring is achieved through dry contact detection. The system continuously monitors the power status through hardware dry contact signals, triggering a determination when the dry contact status changes. For example, when the dry contact status changes from 0 to 1 (i.e., a power failure signal is detected), the current event is determined to be a power failure; when the dry contact status returns from 1 to 0, the current event is determined to be a power-on recovery event.
[0033] Furthermore, power failure detection can continuously monitor the dry contact status through a detection function. When the dry contact status changes, a judgment is made based on the new status value after the transition: if the new status value is a preset value indicating power failure (e.g., 1), it is determined as a power failure event and the data saving process is immediately triggered; if the new status value is a preset value indicating power restoration (e.g., 0), it is determined as a power-on recovery event. The response time of power failure detection mainly depends on the mechanical response speed of the dry contact, and is generally less than 50 milliseconds.
[0034] Using dry contact state changes for power-down detection offers several advantages over direct voltage detection: First, electrical isolation: with no direct wire connection between the two sides of the dry contact, faults such as surges, reverse polarity, and lightning strikes from the main power supply side cannot be transmitted to the main control unit. Second, common-mode interference immunity: the detection circuit and the main control unit share no common ground path, effectively suppressing ground loop interference and common-mode voltage interference. Third, hardware reuse: the dry contact can share the same detection circuit with the overall safety system (such as gate control, emergency stop, and safety doors), reducing material costs. Fourth, fail-safe performance: the short-circuit or open-circuit failure modes of the dry contact are known states, preventing uncertain detection results. Fifth, response speed: the dry contact is purely mechanically or magnetically driven, eliminating the response delay of voltage detection integrated circuits, allowing for immediate interruption upon power failure. Furthermore, compared to power-down detection methods based on voltage sampling, dry contact detection does not require continuous analog-to-digital conversion and can directly trigger the power-down protection process based on state transitions, thereby reducing processor resource consumption and improving the real-time performance and deterministic response of power-down detection.
[0035] In other implementations, power status monitoring can also be achieved through voltage detection. For example, a power-down process can be triggered when the system voltage drops to a first preset threshold (e.g., 10 volts), and the energy storage element can take over power supply after the system voltage drops to a second preset threshold (e.g., around 7 volts). This invention does not limit the specific means of power status monitoring.
[0036] Step S3: When a power failure event is determined, the data acquisition and testing process of the battery testing equipment is paused, and the breakpoint status information of each test channel is saved.
[0037] Specifically, once a power outage event is detected, the system immediately suspends the testing process of all test channels and stops generating new battery test data. This ensures that subsequent data copying and persistence operations target a defined and stable data set, avoiding inconsistencies caused by continuously generating new data during the storage process. Each test channel saves breakpoint status information, which may include the current cycle number, step number, step execution time, completed capacity and energy, negative pressure control status, and other information for resuming testing after a breakpoint, so that testing can continue from the point of interruption after power-on recovery.
[0038] In multi-channel parallel testing scenarios, each channel independently saves its own breakpoint state information without interference. After pausing the test process, the system enters a data freeze state; no new test data is generated during the power-down protection period, thus ensuring that the data set to be saved remains consistent during the saving process.
[0039] Step S4: Transfer the data to be sent in the historical data buffer queue to the power-loss protection buffer through a whole assignment operation; wherein, before the whole assignment operation is completed, the data in the historical data buffer queue remains valid; after confirming that the power-loss protection buffer has obtained complete data, the corresponding data in the historical data buffer queue is released.
[0040] Specifically, the power-loss protection cache is a dedicated buffer area for temporarily handling incoming and outgoing data during power outages. It is located in a different storage area from the real-time data buffer queue and the historical data buffer queue. The core of this step is to use a complete assignment operation to transfer the data. After confirming that the data has been completely transferred to the power-loss protection cache, the corresponding data in the historical data buffer queue is then released.
[0041] Unlike move operations, assignment operations do not clear or release data in the source queue until the data copy is complete. That is, the data in the historical data buffer queue is not released until the data in the historical data buffer queue is completely copied to the power-loss protection buffer; only after the copy is complete are the storage resources occupied by the historical data buffer queue released. This avoids data loss due to further power fluctuations during the data transfer process—even if power supply changes again during the copy process, the integrity of the data set is still guaranteed because the source data is retained until the copy is confirmed to be complete.
[0042] In one implementation, the overall assignment operation is achieved by transferring the reference relationships and management information of the data object, without copying the data object itself, thereby reducing data transfer overhead and improving data transfer efficiency. After the assignment is completed, the power-down protection cache gains access to the data object, and the historical data buffer queue releases the corresponding data management relationship. Since the data object remains valid until the source queue is released, the integrity of the data to be saved can be guaranteed even if an abnormal situation occurs during the assignment process.
[0043] It should be noted that since the test process was paused and new test data generation stopped in step S3, the data set processed in this step is the data set that was generated but not yet transmitted when the power failure occurred. When power is restored during data transfer and persistence, the current data saving process continues until completion without interruption due to power restoration. After the data is saved, the system resumes the test process and data acquisition after a preset recovery delay to ensure that historical data saving, data recovery, and resume transmission have all been completed.
[0044] Step S5: The data in the power failure protection cache is appended to the historical data file in the non-volatile storage medium, and a data synchronization operation is performed to write the data in the power failure protection cache to the non-volatile storage medium; wherein, the power failure protection process is maintained by the energy storage element.
[0045] Specifically, after the data is transferred to the power-loss protection cache, the system immediately executes the write process on the non-volatile storage medium. In some implementations, the non-volatile storage medium is flash memory. The write process may include: first, opening the historical data file (e.g., the historical.dat file located in the log directory) in binary append mode; then writing the data description structure header, which may include length fields, command fields, index fields, sequence fields, and other information for subsequent continuation; next, writing the data buffer in the power-loss protection cache; and finally, closing the file after the write is complete. Using append write mode avoids overwriting already written historical data, thus ensuring the complete preservation of the written data.
[0046] To ensure data is actually written to disk, this step performs a data synchronization operation. This data synchronization operation can include two levels of synchronization: First, the data to be written is flushed from the user-space buffer to the system cache (e.g., by calling a file stream flush operation); second, the data in the system cache is forcibly written to non-volatile storage medium using a storage synchronization command (e.g., by calling a system synchronization command). In some implementations, the storage synchronization command can be executed asynchronously to avoid blocking and waiting. The purpose of this two-level synchronization is to ensure that data in the kernel buffer is actually written to the storage medium, thereby overcoming the problem that simply relying on user-space flushing cannot guarantee data persistence to disk.
[0047] Regarding power supply assurance, energy storage elements maintain power during the power outage protection process. In one embodiment, the energy storage element is implemented using a supercapacitor. The capacity of the supercapacitor is configured based on the amount of data to be saved, processor power consumption, non-volatile storage medium write time, and system safety margin to ensure that the processor and non-volatile storage medium can still maintain the power supply time required to complete the power outage protection process after the main power supply fails. Through the coordinated operation of the energy storage element and a multi-level caching mechanism, the reliable writing of data to be saved to the non-volatile storage medium can be ensured.
[0048] Combining steps S3 to S5, the overall processing flow for power failure signal detection can be described as follows: a power failure signal is detected (e.g., dry contact closure, corresponding power failure flag set to 1); all channel processes are paused; breakpoint data is saved for each channel; historical data queues are saved to the power failure protection cache; file stream flushing is performed to flush the data to the kernel buffer; and system synchronization instructions are executed to force the kernel buffer data to be written to non-volatile storage media.
[0049] Step S6: When a power-on recovery event is determined, the historical data file is read and its integrity is verified. The buffer status information and data to be continued are restored based on the data that has passed the verification, and the resumption flag is set to continue the transmission of the data that has not been sent to the host computer.
[0050] Specifically, the restored buffer state information may include: restoring the logical order of data to be sent; restoring the data read position; restoring the data sending status; restoring the resume flag status; and restoring the correspondence between the historical data buffer and the data to be sent. After restoration, the system continues to execute the unfinished data upload task according to the restored sending status.
[0051] Specifically, when the dry contact status is restored (or the power status is determined to be a power-on recovery event), the system reads the historical data file and performs an integrity check. In some implementations, the structure of the historical data file is as follows: The overall file structure can be divided into three parts: file header, data area, and file footer. The file header can be of fixed length (e.g., 4 bytes) and is used to store an identification field (i.e., a storage flag, such as 0xAAAA5555); the data area is of variable length and is used to store at least one historical data record (i.e., mixed historical data type data); the file footer can be of fixed length (e.g., 4 bytes) and is used to store data bar number fields (e.g., the number of data bars represented by integers).
[0052] The data area may further include a fixed-length header (e.g., 54 bytes) and several data items arranged in a circular pattern. The header may include the historical database name (e.g., 40 bytes, UTF-8 format), channel number (e.g., 2 bytes), and the data bar number field for this packet (e.g., 4 bytes). Each data item may include a fixed part and a variable part. The fixed part (e.g., approximately 280 bytes) may include fields such as the main channel data byte length, sequence number, recording time, step time, absolute time, cycle sequence number, step sequence number, step number, step name, voltage, and current. The variable part may include variable-length data such as auxiliary voltage, auxiliary temperature, summary information, individual unit voltage, and individual unit temperature. A complete data frame can be represented as: file header + header information + data item 1 + data item 2 + ... + data item N + file footer.
[0053] The integrity verification may include: first, determining the validity of the historical data file based on the identifier field (save flag) in the file header; second, parsing the historical data records one by one according to the data bar number segments in the file tail and the storage format and order of the data area, thereby ensuring a complete match between reading and writing. Furthermore, when the historical data file contains a data description structure header, the integrity verification may also include: determining the integrity of the historical data file based on the consistency relationship between the file length, the data description structure header information, and the data area length, for example, verifying whether the length of the historical data file is equal to the sum of the data description structure header length and the preset maximum historical data length.
[0054] After successful verification, the system restores the buffer status information (e.g., historical data buffer information) and the data to be transmitted (e.g., historical data buffer) based on the verified data, and sets the transmission resume flag (e.g., sets the resume flag to true) to enable the transmission resume mechanism, resending any incomplete data to the host computer. During the data verification process, historical data files are only deleted after the reading is complete; if an anomaly occurs, a prompt is given and the file is retained for subsequent correction and recovery, thus preventing secondary data loss due to recurring anomalies during the recovery process.
[0055] Step S7: Restore the test process and data acquisition of each test channel according to the breakpoint status information.
[0056] Specifically, after the resume mechanism is enabled and the buffer state is restored, the system restores the test process and data acquisition of each test channel according to the breakpoint status information of each test channel saved in step S3, thus realizing breakpoint resume testing. In some implementations, to ensure that the system power supply and status are completely stable, a preset recovery delay (e.g., 30 seconds) can be allowed after a power-on recovery event is determined before restoring the test process and data acquisition of each channel, to ensure that all previous data has been written and that resume testing and status restoration are ready.
[0057] The following is combined Figure 2 The system architecture of this invention will be described. For example... Figure 2 As shown, this system adopts a power-loss protection architecture that combines dry contact detection with multi-level caching, which can be divided into the following layers: The power failure detection layer continuously monitors the power status through hardware dry contact signals. When the dry contact status changes from 0 to 1, the power failure protection process is triggered. The first-level cache layer (memory) transfers the entire queue of historical data waiting to be sent to the power-loss protection cache through an atomic assignment operation after a power failure. After the assignment is completed, the source queue is cleared and memory resources are released. The secondary cache layer (non-volatile storage medium) immediately appends the data to the historical data file after it is transferred to the power-loss protection cache, and the energy storage element maintains power supply to ensure that the file writing is completed. The power-on recovery layer reads historical data files to verify integrity when the dry contact status is restored, restores buffer status information and data to be transmitted, and sets the transmission resume flag to enable the subsequent transmission resume mechanism.
[0058] The following is combined Figure 3 The power-down protection timing of this invention will be explained. For example... Figure 3 As shown, the entire power-loss protection process involves four main components: the battery testing module, the data management module, the non-volatile storage medium (Flash storage), and the host computer.
[0059] Under normal circumstances, battery test data is buffered and sent in batches through the data management module, and finally transmitted to the host computer. When a power failure occurs, after the dry contact detects the power failure signal, the data management module immediately performs data saving: first, the entire historical data buffer queue is transferred to the power failure protection cache, then the historical data file is appended, and finally, two-level data synchronization disk flushing is performed; Upon power-up, after the dry contacts are restored, the data management module reads the historical data file from the non-volatile storage medium and verifies its integrity. After reading, it sets the resume transmission flag to enable the resume transmission mechanism and resends the data to the host computer. Throughout the process, the battery testing module pauses data acquisition when power is lost and resumes acquisition after power is restored.
[0060] The following further explains the real-time guarantee mechanism for multi-level cache separation involved in this invention. In some implementations, the multi-level cache can be functionally divided into three layers: The data receiving layer (first-level cache) adopts a lock-free enqueue mechanism. After the data is generated, it is directly written to the first-level cache (i.e., the real-time data buffer queue). The enqueue operation only involves pointer appending and length accumulation, and the time consumption is controlled in the microsecond level, so that the test control cycle (e.g., 10 milliseconds) is completely decoupled from the data enqueue operation. The trigger transfer layer (second-level cache) is triggered by a data volume threshold. For example, the trigger condition is that the cumulative length reaches a preset proportion of the maximum length of the buffer. The threshold check can be performed by an independent background thread at a preset period (e.g., 100 milliseconds). When triggered, the data object reference relationship and management information are transferred without copying the data object itself, thereby reducing the data transfer overhead.
[0061] The persistent layer (third-level cache) adopts an asynchronous write mechanism to non-volatile storage media. The lock granularity only covers pointer operations. The lock is released immediately after the pointer transfer is completed, and the write operation is performed in a lock-free state, thereby ensuring that the first-level cache can still receive data normally during the write operation.
[0062] In some implementations, the historical data buffer queue can be implemented using a fixed-capacity circular buffer instead of a dynamic linked list. In the event of a power failure, only the current read / write pointer position needs to be recorded; there is no need to copy all data. Its advantages are deterministic memory allocation and better real-time performance; its disadvantage is the potential for overflow due to the fixed capacity, which can be mitigated by appropriately setting the buffer size.
[0063] In the implementation using a circular buffer, the following information needs to be saved during power failure: write pointer position (the offset of the address to be written to the next data item relative to the beginning address of the buffer), read pointer position (the offset of the address to be sent to the next data item relative to the beginning address of the buffer), and the beginning address of the buffer (a fixed address or an absolute address of the memory chip). From this, the length of unsent data can be calculated using the following relationship: Unsent data length = (Write pointer - Read pointer + Buffer size) % Buffer size.
[0064] Accordingly, the power-on recovery process may include: reading the saved buffer start address, write pointer, and read pointer from the non-volatile storage medium; calculating the length of unsent data based on the write pointer, read pointer, and buffer capacity; restoring the physical address of the buffer based on the buffer start address; and resuming transmission from the breakpoint corresponding to the read pointer position when the length of unsent data is greater than 0, and restoring the logical order of the unsent data based on the saved read pointer and write pointer. This method can achieve breakpoint resumption without copying the complete data content, by saving and restoring only a small amount of pointer information.
[0065] In other implementations, dual non-volatile storage media (such as dual Flash chips) can be used for mirror backup. During writing, data is written to both media simultaneously, and during reading, the consistency of the two copies of data can be verified. The advantage is higher reliability, but the trade-off is increased hardware costs.
[0066] The following describes the power-loss data protection device for battery testing equipment based on multi-level caching provided by the present invention. The device described below and the method described above can be referred to in correspondence.
[0067] Figure 4 This is a schematic diagram of the power-loss data protection device for battery testing equipment based on multi-level caching provided by the present invention, as shown in the figure. Figure 4 As shown, the device includes: The data buffer module 410 is used to write the collected battery test data into the real-time data buffer queue, and transfer it to the historical data buffer queue and send it to the host computer in batches when the preset batch sending conditions are met. The power failure detection module 420 is used to continuously monitor the power status through dry contacts and determine a power failure event or a power-on recovery event when the dry contact status changes. The power-down protection module 430 is used to pause the data acquisition and testing process of the battery testing equipment when a power-down event is detected, save the breakpoint status information of each test channel, transfer the data to be sent in the historical data buffer queue to the power-down protection cache through a whole assignment operation, append the data in the power-down protection cache to the historical data file in the non-volatile storage medium, and perform a data synchronization operation to write the data in the power-down protection cache to the non-volatile storage medium; wherein, the power supply is maintained by the energy storage element during the power-down protection process; The data recovery module 440 is used to read the historical data file, perform integrity verification, restore the historical data buffer information and set the resume flag when a power-on recovery event is determined, so as to resume the transmission of data that has not been completely sent.
[0068] Based on the above embodiments, the data buffer module is specifically used to: set the real-time data buffer queue, the historical data buffer queue and the power-loss protection cache in different storage areas; use the amount of data accumulated in the historical data buffer queue reaching a preset data amount threshold as a preset batch sending condition; and during the writing of non-volatile storage media, enable the real-time data buffer queue to continuously receive newly generated battery test data.
[0069] Based on the above embodiments, the power-loss protection module is specifically used to: keep the source data from being released before the data in the historical data buffer queue is completely copied to the power-loss protection cache, and release the storage resources occupied by the source queue after the copying is completed; and when performing the disk flushing operation, first refresh the data to be written from the user space buffer to the system cache area, and then write the data in the system cache area to the non-volatile storage medium through the storage synchronization instruction.
[0070] Based on the above embodiments, the power failure protection module is also used to: suspend the test process of each channel and save the breakpoint status information of each channel when a power failure event is determined; each channel is configured with an independent real-time data buffer queue and a historical data buffer queue, and the write operation of the historical data file is protected by a mutex lock.
[0071] Based on the above embodiments, the data recovery module is specifically used to: determine the validity of the file according to the identifier field in the historical data file; parse the historical data record according to the data bar number segment and the data area storage format; and when the historical data file contains a data description structure header, determine whether the file is complete according to the consistency relationship between the file length, the data description structure header information and the data area length; after the verification passes, set the resume transmission flag to continue transmitting the data; and after a preset recovery delay, restore the test process and data acquisition of each channel according to the breakpoint status information.
[0072] Figure 5 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 5As shown, the electronic device may include: a processor 510, a communications interface 520, a memory 530, and a communication bus 540, wherein the processor 510, the communications interface 520, and the memory 530 communicate with each other through the communication bus 540. The processor 510 can call logical instructions in the memory 530 to execute a power-loss data protection method for battery testing equipment based on multi-level caching, the method including: S1. Under normal operating conditions of the battery testing equipment, the collected battery test data is written into the real-time data buffer queue for caching; when the preset transfer conditions are met, the data in the real-time data buffer queue is transferred to the historical data buffer queue, and the historical data buffer queue sends the battery test data to the host computer. S2. Continuously monitor the power status of the battery testing equipment. When a change in the power status is detected, determine whether the current event is a power failure or a power-on recovery event. S3. When a power failure event is detected, the data acquisition and testing process of the battery testing equipment are suspended, and the breakpoint status information of each test channel is saved. S4. Transfer the data to be sent in the historical data buffer queue to the power-loss protection buffer through a whole assignment operation; wherein, before the whole assignment operation is completed, the data in the historical data buffer queue remains valid; after confirming that the power-loss protection buffer has obtained complete data, the corresponding number in the historical data buffer queue is released. S5. The data in the power failure protection cache is appended to the historical data file in the non-volatile storage medium, and a data synchronization operation is performed to write the data in the power failure protection cache to the non-volatile storage medium; wherein, the power failure protection process is maintained by the energy storage element. S6. When a power-on recovery event is determined, the historical data file is read and its integrity is verified. The buffer status information and the data to be transmitted are restored according to the data that has passed the verification. The transmission resume flag is set so that the data that has not been sent can be transmitted to the host computer. S7. Restore the test process and data acquisition of each test channel based on the breakpoint status information.
[0073] Furthermore, the logical instructions in the aforementioned memory 530 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0074] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can execute the battery test equipment power-down data protection method based on multi-level caching provided by the above methods.
[0075] In another aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the power-down data protection method for battery testing equipment based on multi-level caching provided by the above methods.
[0076] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. 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. Those skilled in the art can understand and implement this without any creative effort.
[0077] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0078] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for power-loss data protection in battery testing equipment based on multi-level caching, characterized in that, include: S1. Under normal operating conditions of the battery testing equipment, the collected battery test data is written into the real-time data buffer queue for caching; When the preset transfer conditions are met, the data in the real-time data buffer queue is transferred to the historical data buffer queue, and the battery test data is sent to the host computer by the historical data buffer queue; the preset transfer conditions include the accumulated data amount in the historical data buffer queue reaching a preset data amount threshold. S2. Continuously monitor the power status of the battery testing equipment. When a change in the power status is detected, determine whether the current event is a power failure or a power-on recovery event. S3. When a power failure event is detected, the data acquisition and testing process of the battery testing equipment is suspended, the generation of new battery test data is stopped, and the breakpoint status information of each test channel is saved. S4. Transfer the data to be sent in the historical data buffer queue to the power-loss protection cache through a whole assignment operation; wherein, before the whole assignment operation is completed, the data in the historical data buffer queue remains valid; after confirming that the power-loss protection cache has obtained complete data, the corresponding data in the historical data buffer queue is released; the real-time data buffer queue, the historical data buffer queue and the power-loss protection cache are respectively set in different storage areas; S5. The data in the power failure protection cache is appended to the historical data file in the non-volatile storage medium, and a data synchronization operation is performed simultaneously: the data to be written is flushed from the user space buffer to the system cache area; then, the data in the system cache area is written to the non-volatile storage medium through a storage synchronization instruction; wherein, during the power failure protection process, the power supply is maintained by the energy storage element; wherein, each test channel is configured with an independent real-time data buffer queue and a historical data buffer queue, and the write operation to the historical data file is protected by a mutex lock; S6. When a power-on recovery event is determined, the historical data file is read and its integrity is verified. The buffer status information and the data to be transmitted are restored according to the data that has passed the verification. The transmission resume flag is set so that the data that has not been sent can be transmitted to the host computer. S7. After a preset recovery delay, the test process and data acquisition of each test channel are restored according to the breakpoint status information.
2. The method according to claim 1, characterized in that, Step S4 includes: Before the data in the historical data buffer queue is completely copied to the power failure protection cache, the data in the historical data buffer queue shall not be released; Once the copying is complete, release the storage resources occupied by the historical data buffer queue.
3. The method according to claim 1, characterized in that, The historical data files include: The file header includes an identification field; The data area includes at least one historical data record; The end of the file includes a data bar number field; The integrity verification includes: determining whether the historical data file is valid based on the identifier field, and parsing the historical data records according to the storage format of the data bar number segment and the data area.
4. The method according to claim 3, characterized in that, The historical data file also includes a data description structure header; The data description structure header includes a length field, a command field, an index field, and a sequence field; The integrity verification also includes: determining whether the historical data file is complete based on the consistency relationship between the file length, the data description structure header information, and the data area length.
5. The method according to claim 1, characterized in that, The historical data buffer queue is implemented using a fixed-capacity circular buffer. When the power failure protection process determines that a power failure event has occurred, it saves the write pointer offset, read pointer offset, and buffer start address of the circular buffer. In the power-on recovery event, the length of unsent data is calculated based on the saved write pointer offset, read pointer offset, and buffer capacity, and the transmission resumes from the breakpoint corresponding to the read pointer position. The logical order of the unsent data is restored based on the saved read pointer offset and write pointer offset.
6. A power-loss data protection device for a battery testing equipment based on multi-level caching, used to implement the method according to any one of claims 1 to 5, characterized in that, include: The data buffer module is used to write the collected battery test data into the real-time data buffer queue, and transfer it to the historical data buffer queue and send it to the host computer in batches when the preset batch sending conditions are met. The power failure detection module is used to continuously monitor the power status of the battery testing equipment. When a change in the power status is detected, it determines whether the current event is a power failure or a power-on recovery event. The power loss protection module is used to pause the data acquisition and testing process of the battery testing equipment when a power loss event is detected, save the breakpoint status information of each test channel, transfer the data to be sent in the historical data buffer queue to the power loss protection cache through a whole assignment operation, append the data in the power loss protection cache to the historical data file in the non-volatile storage medium, and at the same time perform a data synchronization operation: refresh the data to be written from the user space buffer to the system cache area; Then, the data in the system cache is written to the non-volatile storage medium through the storage synchronization command; during the power failure protection process, the energy storage element maintains the power supply. The data recovery module is used to read the historical data file and perform integrity verification when a power-on recovery event is determined. Based on the verified data recovery buffer status information and the data to be continued, the module sets the continue flag to continue the transmission of the data that has not been sent to the host computer.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the power-off data protection method for a battery testing device based on multi-level caching as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Power failure protection system and power failure protection method
CN120428921A
Hardware monitoring device and method based on PCIe expansion card
CN122152633A