A power collection terminal waveform data multi-level integrity guarantee method and device

By combining edge-triggered mode and ring buffer in the data processing method, the integrity problem of waveform data of power acquisition terminal in high-speed sampling scenarios is solved, and efficient and real-time data integrity protection is achieved. It is suitable for power quality monitoring and fault recording in power systems.

CN123157474APending Publication Date: 2026-11-24HEXING ELECTRICAL CO LTD +4
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611212658.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-11
Publication Date
2026-11-24

AI Technical Summary

Technical Problem

Existing technologies for ensuring the integrity of waveform data from power acquisition terminals in high-speed sampling scenarios suffer from data loss, out-of-order delivery, and latency issues, failing to meet real-time requirements. In particular, the DMA fixed-length circular buffer scheme is unsuitable in USB CDC virtual serial port scenarios, and the file system verification scheme has significant latency, making it unsuitable for power quality alarms and transient detection.

Method used

The system employs edge-triggered mode to monitor the USB CDC virtual serial port, combines a circular buffer with non-blocking loop data reading, ensures data integrity through frame header CRC check, PIID device check, and cycle encoding identification, and uses bitmasks and timeout timers to handle lost data, thus achieving multi-level integrity protection.

Benefits of technology

It significantly reduces CPU utilization and data latency, improves buffer space utilization, reduces frame loss probability, ensures data integrity and real-time performance, and supports efficient power quality monitoring and fault recording.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123157474A_ABST
    Figure CN123157474A_ABST
Patent Text Reader

Abstract

This invention relates to the field of data processing technology, specifically to a method and apparatus for ensuring multi-level integrity of waveform data in a power acquisition terminal. The method includes: monitoring a USB CDC virtual serial port using an edge-triggered mode; triggering an event when the kernel buffer changes from empty to non-empty; entering a non-blocking loop reading mode; continuously reading data until an EAGAIN error is returned; and writing the read data into a circular buffer while reading data from the kernel buffer; parsing the data written to the circular buffer to obtain a subframe aggregation set; obtaining a bitmask based on the subframe aggregation set; determining the data availability status of subframes based on the bitmask; and concatenating the sampled data according to the subframe sequence number when the bitmask indicates that all subframe data are available to obtain complete cycle data. In this way, CPU utilization is reduced by approximately 60% at high data rates (6400Hz sampling), data latency jitter is reduced by approximately 80%, and buffer space utilization is improved by approximately 30%.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of data processing technology, specifically to a method and apparatus for ensuring the multi-level integrity of waveform data from a power acquisition terminal. Background Technology

[0002] In power systems, advanced applications such as power quality monitoring, fault recording, and transient analysis rely on high-precision voltage and current waveform sampling data acquired from AC sampling chips (ADC sampling chips, such as ADE9000, RN8302B, ATT7022, etc.). The intelligent fusion terminal reads discrete sampling point sequences from the sampling chip via SPI or a dedicated high-speed interface, encapsulates them into data frames, and transmits them to the main control application processor through an internal communication channel (usually a USB CDC virtual serial port or UART). The waveform data encapsulated into frames must ensure data integrity—that is, identify and detect problems such as data loss, out-of-order delivery, and misaligned frames.

[0003] Existing technologies mainly develop in the following three directions:

[0004] Option 1: A scheme based on blocking serial port reading and single frame header verification. The terminal controller reads waveform frame data from the virtual serial port through blocking read() or UART RX interrupt, relies on the frame header synchronization byte (such as 0x68 or 0x7E) for frame boundary identification, and verifies the correctness of the frame by accumulating the single byte at the end of the frame (CS checksum). This scheme often uses blocking single read() or simple polling to receive USB CDC data. In high-speed sampling scenarios (such as 128 sampling points per cycle × 50Hz = 6400 sampling points / second, each sampling point is about 8 bytes = 51200 bytes / second raw data rate), untimely reading and dequeueing can cause the kernel USB CDC buffer to overflow and drop frames.

[0005] Option 2: Batch reception scheme based on DMA fixed-length circular buffer. This scheme utilizes the MCU's DMA controller to transfer serial port data to a circular buffer in fixed-length blocks. The host controller periodically checks for DMA transfer completion interrupts and consumes the buffer data. This scheme reduces CPU interrupt load through DMA hardware mechanisms, but it is not suitable for USB CDC virtual serial port scenarios—because the arrival time and block size of USB CDC data are unpredictable (determined by USB frame timing and the host USB controller's scheduling), making fixed-block DMA transmission unsuitable.

[0006] Option 3: Waveform data post-disk verification based on a file system. First, all raw waveform data is written to the flash file system, then read and verified through the file system interface. This solution is non-real-time, with significant latency, and is unsuitable for power quality alarms and transient detection scenarios with high real-time requirements. Summary of the Invention

[0007] In order to solve or at least partially solve the defects or deficiencies of the prior art, the present invention proposes a method and device for ensuring the multi-level integrity of waveform data of power acquisition terminals.

[0008] In a first aspect of the present invention, a method for multi-level integrity assurance of waveform data from a power acquisition terminal is provided, applied to a main control application processor running a Linux operating system, wherein the main control application processor is connected to the data acquisition coprocessor via a USB CDC virtual serial port; the method includes:

[0009] S1. The edge-triggered mode is used to monitor the USB CDC virtual serial port. When the kernel buffer state changes from empty to non-empty, an event is triggered, and the non-blocking loop read mode is entered to continuously read data until the EAGAIN error is returned. When reading data in the kernel buffer, the read data is written to the ring buffer.

[0010] S2. Parse the data written to the circular buffer to obtain the subframe aggregation set;

[0011] S3. Obtain the bit mask based on the subframe aggregation set, and determine the data arrival status of the subframes based on the bit mask; when the bit mask indicates that all subframe data are in place, splice the sampled data in the order of the subframe sequence number to obtain the complete cycle data.

[0012] As a preferred embodiment of the present invention, S1 specifically includes:

[0013] S11. The main control application processor calls the epoll_wait() function to listen to the USB CDC virtual serial port. When the kernel buffer state changes from empty to non-empty, an event is triggered, and the inner while(1) loop is entered.

[0014] S12. Call the read() function to read data. If the return value of the read() function is greater than 0, the data read is written to the circular buffer based on the write pointer position, and the write pointer position is moved based on the size of the data written. If the data is written beyond the end of the circular buffer, it wraps back to the beginning of the circular buffer to continue writing data.

[0015] If the read() function returns -1 and errno=EAGAIN, then exit the inner while(1) loop.

[0016] As a preferred embodiment of the present invention, S2 specifically includes:

[0017] S21. Search for the frame header in the circular buffer based on the read pointer position. If the frame header is found, proceed to S22; if the frame header is not found, move the read pointer position based on the write pointer position and exit S21.

[0018] S22. Perform CRC check on the subframe data based on the frame header. If the check passes, proceed to S23; if the check fails, move the read pointer position based on the subframe data size and return to S21.

[0019] S23. Perform PIID device verification on the subframe data based on the frame header. If the verification passes, proceed to S24; if the verification fails, move the read pointer position based on the subframe data size and return to S21.

[0020] S24. Based on the frame header, perform cycle coding identification on the subframe data to determine whether there is cycle loss, and proceed to S25;

[0021] S25. Based on the frame header, identify the subframe sequence number of the subframe data, and store the subframe data of the current subframe into the subframe aggregation set with the cycle code as the key based on the subframe sequence number. Move the read pointer position based on the size of the subframe data, and return to S21.

[0022] In a preferred embodiment of the present invention, in S25, when the size of the subframe data is greater than the size of the data from the frame header to the end of the circular buffer, it is determined that the subframe data is physically divided into two segments. At this time, the data from the frame header to the end of the circular buffer is taken as subframe data segment one, and the data starting from the beginning of the circular buffer is taken as subframe data segment two, such that the sum of the sizes of subframe data segment one and subframe data segment two is equal to the size of the subframe data. Then, subframe data segment one and subframe data segment two are concatenated to obtain the current subframe data.

[0023] As a preferred embodiment of the present invention, S3 specifically includes:

[0024] S31. Obtain the bitmask in the subframe convergence set, determine whether the bitmask is equal to the subframe alignment bitmask, and when the bitmask is equal to the subframe alignment bitmask, determine that all subframe data has arrived.

[0025] S32. Obtain the sampled data of the subframe data in ascending order of subframe number, and then stitch the sampled data together to obtain the complete cycle data.

[0026] As a preferred embodiment of the present invention, S3 further includes:

[0027] S33. When the bit mask is not equal to the subframe to full bit mask, check whether the convergence timeout timer corresponding to the cycle encoding has expired. If the convergence timeout timer expires, it is determined that there is subframe data loss, and subframe data loss processing is performed.

[0028] As a preferred embodiment of the present invention, the subframe data loss processing specifically includes:

[0029] The sampled data of the missing subframe numbers are padded with zeros, and the sampled data are spliced ​​together in the order of the subframe numbers to obtain complete cycle data.

[0030] In a second aspect of the present invention, a multi-level integrity protection device for waveform data of a power acquisition terminal is provided, applied to a main control application processor running a Linux operating system, the main control application processor being connected to the data acquisition coprocessor via a USB CDC virtual serial port; the device includes:

[0031] The data writing module is configured to listen to the USB CDC virtual serial port in edge-triggered mode. When the kernel buffer state changes from empty to non-empty, an event is triggered, and it enters non-blocking loop reading mode to continuously read data until the EAGAIN error is returned. When reading data in the kernel buffer, the read data is written to the ring buffer.

[0032] The subframe aggregation acquisition module is configured to parse the data written to the circular buffer to obtain the subframe aggregation set;

[0033] The cycle data output module is configured to obtain the bit mask based on the subframe aggregation set, and determine the data arrival status of the subframes based on the bit mask; when the bit mask indicates that all subframe data are in place, the sampled data is spliced ​​together in the order of the subframe sequence number to obtain the complete cycle data.

[0034] In a third aspect of the present invention, a computer program product is provided, including a computer program that, when executed by a processor, implements the method provided according to the first aspect.

[0035] In a fourth aspect of the present invention, an electronic device is provided, including one or more processors and a memory associated with the one or more processors, the memory being used to store program instructions that, when read and executed by the one or more processors, perform the method provided in the first aspect.

[0036] In summary, the present invention has the following beneficial effects:

[0037] A high-efficiency USB CDC data receiving mechanism based on epoll edge triggering and loop reading to EAGAIN: Utilizing Linux epoll's EPOLLET mode, the number of CPU wake-ups is minimized under high-speed sampling data streams—an event is triggered only once when data arrives from nothing. Combined with a while(1) loop non-blocking read() to completely empty the kernel buffer, eliminating data stagnation and accumulated latency. Compared to traditional blocking single read() or level-triggered polling, CPU utilization is reduced by approximately 60% and data latency jitter is reduced by approximately 80% at high data rates (6400Hz sampling).

[0038] A four-tiered integrity assurance system (device-level / cycle-level / subframe-level / verification-level): PIID device verification eliminates data source confusion in multi-device scenarios; wave_id periodicity identification can detect and quantify cycle-level data loss (providing the number of lost complete cycles); frame_id subframe location and bitmask aggregation ensure subframe-level data alignment; CRC frame verification guarantees bit-level data integrity. These four levels of verification progressively form a complete, layered defense for data integrity.

[0039] The circular buffer's ability to stitch cross-boundary newline frames: By using newline awareness to determine whether a frame crosses the end-to-beginning physical boundary of the buffer, and performing memory copy stitching on cross-boundary frames, this mechanism significantly reduces the probability of frame loss due to overflow in the circular buffer—because it does not need to reserve continuous space for "non-boundary" frames for each frame, the buffer's space utilization is improved by approximately 30%.

[0040] The frame_id timeout protection mechanism effectively prevents cascading failures after subframe loss: by maintaining a 100ms timeout timer for each wave_id aggregation slot, the desired state of the frame_id is "reset" promptly after a subframe is lost. This avoids the cascading failure effect in existing schemes where the loss of one subframe causes all subsequent wave_ids to be continuously discarded due to frame_id misalignment, limiting the impact of a single subframe loss to the loss of only one cycle of waveform data.

[0041] A dual-track processing strategy for detecting and zero-padding the output of lost subframes: For wave_ids that are not fully collected within a timeout period, the collected subframes are not discarded; instead, zeros are padded to the missing positions before being merged and output. This strategy ensures that the downstream waveform processing pipeline (FFT / transient detection) does not collapse due to structural defects, while using a "partial data" flag to enable the downstream algorithm to distinguish between complete data and zero-padding data, making appropriate fault-tolerant decisions.

[0042] Further or more detailed beneficial effects will be described in conjunction with specific embodiments in the detailed implementation. Attached Figure Description

[0043] Figure 1 A flowchart of a method for ensuring the multi-level integrity of waveform data in a power acquisition terminal according to an embodiment of the present invention is shown;

[0044] Figure 2 A block diagram of a multi-level integrity protection device for waveform data of a power acquisition terminal according to an embodiment of the present invention is shown;

[0045] Figure 3 A block diagram of an electronic device according to an embodiment of the present invention is shown. Detailed Implementation

[0046] Embodiments of the present invention will now be described in more detail with reference to the accompanying drawings. While some embodiments of the invention are shown in the drawings, it should be understood that the invention can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of the invention. It should be understood that the accompanying drawings and embodiments are for illustrative purposes only and are not intended to limit the scope of protection of the invention.

[0047] In the description of embodiments of the present invention, the term "comprising" and similar terms should be understood as open-ended inclusion, i.e., "including but not limited to". The term "based on" should be understood as "at least partially based on". The term "one embodiment" or "the embodiment" should be understood as "at least one embodiment". The terms "first", "second", etc., may refer to different or the same objects. Other explicit and implicit definitions may also be included below.

[0048] This invention proposes a multi-level integrity assurance method for waveform data from a power acquisition terminal. This method is applied to a main control application processor running a Linux operating system. The main control application processor is connected to the data acquisition coprocessor via a USB CDC virtual serial port. Figure 1 As shown, the method includes:

[0049] S1. The edge-triggered mode is used to monitor the USB CDC virtual serial port. When the kernel buffer state changes from empty to non-empty, an event is triggered, and the system enters a non-blocking loop read mode to continuously read data until the EAGAIN error is returned. When reading data from the kernel buffer, the read data is written to the ring buffer.

[0050] This embodiment uses the power quality monitoring and fault recording services of a smart converged terminal as an example. The cross-sampling chip (such as ADIADE9000) synchronously samples the three-phase voltage and three-phase current at a fixed sampling rate (typically 128 points per cycle), generating a raw sampling data stream of 6 channels × 2 bytes × 6400 points / second ≈ 76.8KB / s. The sampled data is transmitted to an independent microcontroller (MCU, cross-sampling coprocessor) via the cross-sampling chip's SPI interface.

[0051] The MCU packages the raw sampled data (adding fields such as PIID device identifier, wave_id cycle number, frame_id subframe number, timestamp, channel mask, and CRC checksum), and then transmits it to the main control application processor (running on a Linux operating system) via its USB CDC interface in the form of a virtual serial port. A complete cycle has 128 sampling points, which the MCU divides into 4 parts (32 points each) and sends in 4 batches. Each part is a subframe of data, and each subframe includes the PIID device identifier, wave_id cycle number, frame_id subframe number, sampled data, and CRC checksum.

[0052] Assuming the current fault recording cycle is the 100th cycle (wave_id = 0x0064), the MCU will sequentially package and send the following 4 subframes:

[0053] Subframe 0: The first 32 points (protocol header: PIID (4 bytes) + wave_id = 0x0064 (2 bytes) + frame_id = 0 (1 byte); sampling data: sampling points 0 to 31 (containing 32 points each of Ua, Ub, Uc, Ia, Ib, and Ic, totaling 384 bytes); protocol tail: CRC checksum (2 bytes).

[0054] Subframe 1: Points 33 to 64 (Header: PIID (4 bytes) + wave_id = 0x0064 (2 bytes) + frame_id = 1 (1 byte); Sample data: Points 32 to 63 (384 bytes in total); Tail: CRC checksum (2 bytes)).

[0055] Subframe 2: Points 65-96 (Header: PIID (4 bytes) + wave_id = 0x0064 (2 bytes) + frame_id = 2 (1 byte); Sample data: Points 64 to 95 (384 bytes in total); Tail: CRC checksum (2 bytes).

[0056] Subframe 3: The last 32 points (protocol header: PIID (4 bytes) + wave_id = 0x0064 (2 bytes) + frame_id = 3 (1 byte); sampling data: sampling points 96 to 127 (384 bytes in total); protocol tail: CRC checksum (2 bytes)).

[0057] In this embodiment, S1 specifically includes:

[0058] S11. The main control application processor calls the epoll_wait() function to listen to the USB CDC virtual serial port. When the kernel buffer state changes from empty to non-empty, an event is triggered, and the inner while(1) loop is entered.

[0059] In this embodiment, it is assumed that the MCU sends four subframes (2048 bytes) instantaneously. The kernel buffer changes from "empty" to "non-empty", triggering an edge transition (only triggered once). The main control application processor enters a while(1) loop to start reading data.

[0060] S12. Call the read() function to read data. If the return value of the read() function is greater than 0, the data read is written to the circular buffer based on the write pointer position, and the write pointer position is moved based on the size of the data written. If the data is written beyond the end of the circular buffer, it wraps back to the beginning of the circular buffer to continue writing data.

[0061] If the read() function returns -1 and errno=EAGAIN, then exit the inner while(1) loop.

[0062] Assume the read() function reads a maximum of 1000 bytes at a time. The kernel buffer has write and read pointers, which are initially located at the same position.

[0063] The first call to the read() function reads 1000 bytes, so the return value is 1000. When the return value is 1000, which is greater than 0, 1000 bytes are written to the circular buffer starting from the write pointer position (assuming that the data written at this time has not exceeded the end of the circular buffer), and then the write pointer is moved to the end of the written data.

[0064] The second call to the read() function reads 1000 bytes, so the return value is 1000. Since the return value is 1000, which is greater than 0, the write pointer continues to write 1000 bytes to the circular buffer. If the data written exceeds the end of the circular buffer, the excess data will continue to be written from the beginning of the circular buffer, and the write pointer will be moved to the end of the written data.

[0065] The third call to the read() function reads 48 bytes, so the return value is 48. When the return value is 48, which is greater than 0, 48 bytes are written to the circular buffer starting from the write pointer position, and then the write pointer is moved to the end of the written data.

[0066] The fourth call to the read() function reads 0 bytes, so the return value is -1 and errno = EAGAIN. At this point, the main application processor knows that the data in the kernel buffer has been read (i.e., emptied), so it exits the inner while(1) loop directly.

[0067] S2. Parse the data written to the circular buffer to obtain the subframe aggregation set.

[0068] In this embodiment, S2 specifically includes:

[0069] S21. Search for the frame header in the circular buffer based on the read pointer position. If the frame header is found, proceed to S22; if the frame header is not found, move the read pointer position based on the write pointer position and exit S21.

[0070] Four subframes of data have already been written into the circular buffer (the subframe numbers of these four subframes are not necessarily ordered as 0, 1, 2, 3; they could be ordered as 2, 3, 0, 1). The main control application processor starts scanning the data from the position of the read pointer. Under normal circumstances, it can find the frame header of the first subframe and then proceed to step S22.

[0071] S22. Perform CRC check on the subframe data based on the frame header. If the check passes, proceed to S23; if the check fails, move the read pointer position based on the subframe data size and return to S21.

[0072] After locating the frame header of the first subframe data, the main control application processor can obtain the first subframe data. Based on the first subframe data, a CRC-16 can be calculated. This CRC-16 is compared with the CRC at the end of the first subframe data. If they match, it means that the data was not damaged during USB transmission, the verification passes, and the process proceeds to S23.

[0073] If the verification fails, the read pointer is moved to the end of the first subframe data and S21 is returned.

[0074] In this embodiment, it is assumed that the CRC check of the first subframe data fails, and after returning to S21, the second subframe data is found, and the CRC check of the second subframe data passes.

[0075] S23. Perform PIID device verification on the subframe data based on the frame header. If the verification passes, proceed to S24; if the verification fails, move the read pointer position based on the subframe data size and return to S21.

[0076] The main control application processor can extract the PIID (Peripheral Interface Identifier) ​​of the second subframe data, and then compare the extracted PIID with the pre-set PIID. If the two match, it means that the device sending the data is correct, the verification is successful, and the process proceeds to S24.

[0077] If the verification fails, the read pointer is moved to the end of the second subframe data and S21 is returned.

[0078] In this embodiment, it is assumed that the PIID device verification of the second subframe data fails. After returning to S21, the third subframe data is found. The CRC verification of the third subframe data passes and the PIID device verification also passes.

[0079] S24. Based on the frame header, perform cycle encoding identification on the subframe data to determine whether there is cycle loss, and proceed to S25.

[0080] The main control application processor can extract the cycle code of the third subframe data. Assuming the previous cycle number was 0x0063, the expected current cycle code is 0x0064. If the current cycle code is 0x0064, then there is no cycle loss. If the current cycle code is 0x0065, then there is a cycle loss, and the cycle code of the lost cycle is 0x0064. In this case, the main control application processor will record the lost cycle.

[0081] This embodiment assumes that the cycle code extracted based on the data of the third subframe is 0x0064, and there is no cycle loss.

[0082] S25. Based on the frame header, identify the subframe sequence number of the subframe data, and store the subframe data of the current subframe into the subframe aggregation set with the cycle code as the key based on the subframe sequence number. Move the read pointer position based on the size of the subframe data, and return to S21.

[0083] The main control application processor can extract the subframe number of the third subframe data. Assuming the subframe number of the third subframe data is "0", the subframe data with subframe number "0" is stored in the subframe aggregation set with a cycle code of 0x0064. The subframe aggregation set also contains a bitmask with a 4-bit code value. Assuming the first bit value corresponds to subframe number "0", the second bit value corresponds to subframe number "1", the third bit value corresponds to subframe number "2", and the fourth bit value corresponds to subframe number "3", initially, the bitmask is "0000". When subframe data with a certain subframe number is stored in the subframe aggregation set, the corresponding bit value in the bitmask changes from 0 to 1. In this embodiment, when the subframe data with subframe number "0" is stored in the subframe aggregation set with a cycle code of 0x0064, the bitmask of the subframe aggregation set with a cycle code of 0x0064 becomes "1000". Then the read pointer is moved to the end of the third subframe data and returned to S21.

[0084] This embodiment assumes that after returning to S21, the main control application processor finds the fourth subframe data, and the CRC check of the fourth subframe data passes, the PIID device check passes, and there is no cycle loss. The main control application processor can extract the subframe sequence number of the fourth subframe data. Assuming the subframe sequence number of the fourth subframe data is "1", the subframe data with subframe sequence number "1" is stored in the subframe aggregation set with cycle code 0x0064. At this time, the bitmask of the subframe aggregation set with cycle code 0x0064 becomes "1100". Then, the read pointer is moved to the end of the fourth subframe data, and S21 is returned. After returning to S21, assuming the main control application processor cannot find the frame header, the read pointer is moved to the position of the write pointer, and S21 is exited. The acquisition of the entire subframe aggregation set is completed.

[0085] Additionally, when reading subframe data, if the size of the subframe data is greater than the size of the data from the frame header to the end of the circular buffer, it is determined that the subframe data has been physically divided into two segments. In this case, the data from the frame header to the end of the circular buffer is taken as subframe data segment one, and the data starting from the beginning of the circular buffer is taken as subframe data segment two, ensuring that the sum of the sizes of subframe data segment one and subframe data segment two equals the size of the subframe data. Then, subframe data segment one and subframe data segment two are concatenated to obtain the current subframe data.

[0086] S3. Obtain the bit mask based on the subframe aggregation set, and determine the data arrival status of the subframes based on the bit mask; when the bit mask indicates that all subframe data are in place, splice the sampled data in the order of the subframe sequence number to obtain the complete cycle data.

[0087] In this embodiment, S3 specifically includes:

[0088] S31. Obtain the bitmask in the subframe convergence set, determine whether the bitmask is equal to the subframe alignment bitmask, and when the bitmask is equal to the subframe alignment bitmask, determine that all subframe data has arrived.

[0089] This embodiment assumes that the subframe alignment bitmask is "1111" (or hexadecimal "0x0F"). Assuming the current bitmask is "1111", which is equal to "1111", then it is determined that all subframe data has arrived.

[0090] S32. Obtain the sampled data of the subframe data in ascending order of subframe number, and then stitch the sampled data together to obtain the complete cycle data.

[0091] When all subframe data are received, the main control application processor retrieves the sampled data from the subframe aggregation set in the order of subframe number 0→1→2→3 and splices the sampled data into a complete single-cycle 6-channel waveform data block, which is then output to the downstream waveform processing pipeline.

[0092] S3 in this embodiment also includes:

[0093] S33. When the bit mask is not equal to the subframe to full bit mask, check whether the convergence timeout timer corresponding to the cycle encoding has expired. If the convergence timeout timer expires, it is determined that there is subframe data loss, and subframe data loss processing is performed.

[0094] In this embodiment, a convergence timeout timer (100ms) is set for each subframe convergence set. When the convergence timeout timer expires, if the bitmask is still not equal to the subframe full bitmask, it is determined that there is subframe data loss, and subframe data loss processing is performed.

[0095] In this embodiment, the subframe data loss processing specifically includes:

[0096] The sampled data of the missing subframe numbers are padded with zeros, and the sampled data are spliced ​​together in the order of the subframe numbers to obtain complete cycle data.

[0097] Assuming the current bitmask is "1110", it means that the data of the subframe with subframe number "3" is lost. At this time, all the data values ​​of the sampled data with subframe number "3" are represented by "0". Finally, all the sampled data are spliced ​​together in the order of subframe number 0→1→2→3 to obtain the complete cycle data.

[0098] For example, due to the instantaneous high load on the main control CPU (multiple containerized applications running simultaneously), the USB CDC kernel buffer briefly overflowed, causing the loss of the subframe with wave_id=0x0050 and frame_id=2.

[0099] When the convergence slot with wave_id=0x0050 reached its 100ms timeout, it only received three subframes with frame_id={0, 1, 3} (bitmask=0b1011). The timeout handling logic executed as follows: all positions of the 384 bytes of sampled data corresponding to frame_id=2 were set to zero, and the data was concatenated into 1536 bytes in the order of frame_id 0→1→2→3, and output to the downstream FFT analysis module with the "PARTIAL_WAVEFORM" flag appended.

[0100] The timeout clears the convergence slot and bitmask for wave_id=0x0050, and the frame_id expectation state machine is reset. The next arriving subframe (wave_id=0x0051, frame_id=0) is normally accepted into the new convergence slot, no longer affected by the previous loss of frame_id=2. Without this timeout protection, the subsequent frame_id=0 would be incorrectly expected as frame_id=2 (because frame_id=1 was followed by the expectation of frame_id=2), causing all four subframes of wave_id=0x0051 to be dropped consecutively, resulting in a cascading failure lasting approximately 40 cycles.

[0101] This invention proposes a multi-level integrity protection device for waveform data in a power acquisition terminal. It is applied to a main control application processor running a Linux operating system, and the main control application processor is connected to the data acquisition coprocessor via a USB CDC virtual serial port. Figure 2 As shown, the device includes:

[0102] The data writing module is configured to listen to the USB CDC virtual serial port in edge-triggered mode. When the kernel buffer state changes from empty to non-empty, an event is triggered, and it enters non-blocking loop reading mode to continuously read data until the EAGAIN error is returned. When reading data in the kernel buffer, the read data is written to the ring buffer.

[0103] The subframe aggregation acquisition module is configured to parse the data written to the circular buffer to obtain the subframe aggregation set;

[0104] The cycle data output module is configured to obtain the bit mask based on the subframe aggregation set, and determine the data arrival status of the subframes based on the bit mask; when the bit mask indicates that all subframe data are in place, the sampled data is spliced ​​together in the order of the subframe sequence number to obtain the complete cycle data.

[0105] Figure 3A block diagram of an electronic device 300 according to some embodiments of the present invention is shown. The device 300 includes a processor 301, which performs various appropriate actions and processes based on computer program instructions loaded into random access memory (RAM) 303 according to computer program instructions stored in read-only memory (ROM) 302. Various programs and data required for the operation of the device 300 may also be stored in RAM 303. The processor 301, ROM 302, and RAM 303 are interconnected via a bus 304. An input / output (I / O) interface 305 is also connected to the bus 304.

[0106] The various processes and procedures described above, such as method 100, can be executed by processor 301. For example, in some embodiments, method 100 may be implemented as a software program tangibly contained in a machine-readable medium. In some embodiments, part or all of the software program may be loaded and / or installed on device 300 via ROM 302. When the software program is loaded into RAM 303 and executed by processor 301, one or more actions of method 100 described above may be performed.

[0107] The functions described above in this document can be performed at least in part by one or more hardware logic components. For example, exemplary types of hardware logic components that can be used, without limitation, include: field programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload programmable logic devices (CPLDs), and so on.

[0108] The program code used to implement the methods of the present invention can be written in any combination of one or more programming languages. This program code can be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing device, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code can be executed entirely on the machine, partially on the machine, as a standalone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.

[0109] This invention can be a method, apparatus, system, and / or program product. The program product may include a machine-readable storage medium on which machine-readable program instructions for performing various aspects of the invention are loaded. The machine-readable program instructions described herein can be downloaded from the machine-readable storage medium to various computing / processing devices, or downloaded via a network, such as the Internet, a local area network, a wide area network, and / or a wireless network, to an external computer or external storage device. The network may include copper transmission cables, fiber optic transmissions, wireless transmissions, routers, firewalls, switches, gateway computers, and / or edge servers. A network adapter card or network interface in each computing / processing device receives the machine-readable program instructions from the network and forwards them for storage in the machine-readable storage medium of the respective computing / processing device.

[0110] Machine program instructions used to perform the operations of this invention may be assembly instructions, instruction set architecture (ISA) instructions, machine instructions, machine-dependent instructions, microcode, firmware instructions, state setting data, or source code or object code written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Smalltalk, C++, etc., and conventional procedural programming languages ​​such as the "C" language or similar programming languages. The machine-readable program instructions may be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer via any type of network—including a local area network (LAN) or a wide area network (WAN)—or may be connected to an external computer (e.g., via the Internet using an Internet service provider). In some embodiments, electronic circuitry, such as programmable logic circuitry, field-programmable gate arrays (FPGAs), or programmable logic arrays (PLAs), is personalized by utilizing state information from the machine-readable program instructions. This electronic circuitry can execute the machine-readable program instructions to implement various aspects of the invention.

[0111] In the context of this invention, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. Machine-readable media can include, but are not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing. Furthermore, although the operations are depicted in a specific order, this should be understood as requiring that such operations be performed in the specific order shown or in sequential order, or requiring that all illustrated operations be performed to achieve the desired result. In certain environments, multitasking and parallel processing may be advantageous. Similarly, while several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the invention. Certain features described in the context of individual embodiments may also be implemented in combination in a single embodiment. Conversely, various features described in the context of a single embodiment may also be implemented individually or in any suitable sub-combination in multiple embodiments.

[0112] Although the subject matter has been described using language specific to structural features and / or methodological logic, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or actions described above. Rather, the specific features and actions described above are merely illustrative examples of implementing the claims.

Claims

1. A method for ensuring the multi-level integrity of waveform data from a power acquisition terminal, characterized in that, A main control application processor running a Linux operating system is used, wherein the main control application processor is connected to the acquisition coprocessor via a USB CDC virtual serial port; the method includes: S1. The edge-triggered mode is used to monitor the USB CDC virtual serial port. When the kernel buffer state changes from empty to non-empty, an event is triggered, and the non-blocking loop read mode is entered to continuously read data until the EAGAIN error is returned. When reading data in the kernel buffer, the read data is written to the ring buffer. S2. Parse the data written to the circular buffer to obtain the subframe aggregation set; S3. Obtain the bit mask based on the subframe aggregation set, and determine the data arrival status of the subframes based on the bit mask; when the bit mask indicates that all subframe data are in place, splice the sampled data in the order of the subframe sequence number to obtain the complete cycle data.

2. The method according to claim 1, characterized in that, S1 specifically includes: S11. The main control application processor calls the epoll_wait() function to listen to the USB CDC virtual serial port. When the kernel buffer state changes from empty to non-empty, an event is triggered, and the inner while(1) loop is entered. S12. Call the read() function to read data. If the return value of the read() function is greater than 0, the data read is written to the circular buffer based on the write pointer position, and the write pointer position is moved based on the size of the data written. If the data is written beyond the end of the circular buffer, it wraps back to the beginning of the circular buffer to continue writing data. If the read() function returns -1 and errno=EAGAIN, then exit the inner while(1) loop.

3. The method according to claim 1, characterized in that, S2 specifically includes: S21. Search for the frame header in the circular buffer based on the read pointer position. If the frame header is found, proceed to S22; if the frame header is not found, move the read pointer position based on the write pointer position and exit S21. S22. Perform CRC check on the subframe data based on the frame header. If the check passes, proceed to S23; if the check fails, move the read pointer position based on the subframe data size and return to S21. S23. Perform PIID device verification on the subframe data based on the frame header. If the verification passes, proceed to S24; if the verification fails, move the read pointer position based on the subframe data size and return to S21. S24. Based on the frame header, perform cycle encoding identification on the subframe data to determine whether there is cycle loss, and proceed to S25; S25. Based on the frame header, identify the subframe sequence number of the subframe data, and store the subframe data of the current subframe into the subframe aggregation set with the cycle code as the key value based on the subframe sequence number. Move the read pointer position based on the size of the subframe data and return to S21.

4. The method according to claim 3, characterized in that, In step S25, when the size of the subframe data is greater than the size of the data from the frame header to the end of the circular buffer, it is determined that the subframe data is physically divided into two segments. At this time, the data from the frame header to the end of the circular buffer is taken as subframe data segment one, and the data starting from the beginning of the circular buffer is taken as subframe data segment two, such that the sum of the sizes of subframe data segment one and subframe data segment two is equal to the size of the subframe data. Then, subframe data segment one and subframe data segment two are concatenated to obtain the current subframe data.

5. The method according to claim 3, characterized in that, S3 specifically includes: S31. Obtain the bitmask in the subframe convergence set, determine whether the bitmask is equal to the subframe alignment bitmask, and when the bitmask is equal to the subframe alignment bitmask, determine that all subframe data has arrived. S32. Obtain the sampled data of the subframe data in ascending order of subframe number, and then stitch the sampled data together to obtain the complete cycle data.

6. The method according to claim 5, characterized in that, S3 further includes: S33. When the bit mask is not equal to the subframe to full bit mask, check whether the convergence timeout timer corresponding to the cycle encoding has expired. If the convergence timeout timer expires, it is determined that there is subframe data loss, and subframe data loss processing is performed.

7. The method according to claim 6, characterized in that, The subframe data loss handling specifically includes: The sampled data of the missing subframe numbers are padded with zeros, and the sampled data are spliced ​​together in the order of the subframe numbers to obtain complete cycle data.

8. A multi-level integrity protection device for waveform data of a power acquisition terminal, characterized in that, A main control application processor running a Linux operating system is used, wherein the main control application processor is connected to the acquisition coprocessor via a USB CDC virtual serial port; the device includes: The data writing module is configured to listen to the USB CDC virtual serial port in edge-triggered mode. When the kernel buffer state changes from empty to non-empty, an event is triggered, and it enters non-blocking loop reading mode to continuously read data until the EAGAIN error is returned. When reading data in the kernel buffer, the read data is written to the ring buffer. The subframe aggregation acquisition module is configured to parse the data written to the circular buffer to obtain the subframe aggregation set; The cycle data output module is configured to obtain the bit mask based on the subframe aggregation set, and determine the data arrival status of the subframes based on the bit mask; when the bit mask indicates that all subframe data are in place, the sampled data is spliced ​​together in the order of the subframe sequence number to obtain the complete cycle data.

9. A computer program product, characterized in that, Includes a computer program, which, when executed by a processor, implements the steps of the method according to any one of claims 1-7.

10. An electronic device, characterized in that, It includes one or more processors and memory associated with the one or more processors, the memory being used to store program instructions that, when read and executed by the one or more processors, perform the steps of the method according to any one of claims 1-7.