Power metering data offline detection method and system based on spi bus raw frame

By directly capturing the physical level signal of the SPI bus using a general-purpose digital signal acquisition device and performing offline analysis, the problems of strong hardware dependence and difficulty in tracing errors in existing technologies are solved. This enables flexible and efficient SPI link layer detection and improves the visualization and accuracy of the detection results.

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

Patent Information

Application Number
CN202611164926.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-03
Publication Date
2026-11-27

AI Technical Summary

Technical Problem

Existing technologies for detecting raw data at the SPI link layer of smart grid equipment suffer from problems such as strong hardware dependence, difficulty in tracing errors, poor functional scalability, and low visualization of detection results.

Method used

The physical level signal of the SPI bus is directly captured by a general-purpose digital signal acquisition device. The signal is stored and parsed offline through protocol configuration parameters, realizing protocol parsing, physical quantity conversion, measurement accuracy verification and visualization output. This bypasses dedicated hardware and closed-loop test environment, and enables independent verification of the original sampling data of the SPI link layer.

Benefits of technology

It enables rapid detection in various scenarios, reduces hardware investment and setup cycle, improves fault location efficiency and visualization of detection results, adapts to different manufacturers and protocol versions, and significantly improves R&D iteration efficiency and detection accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123176641A_ABST
    Figure CN123176641A_ABST
Patent Text Reader

Abstract

The application discloses a kind of based on SPI bus original frame electric power measurement data offline detection method and system, this method is directly sampled SPI bus physical level timing signal by general digital acquisition equipment and is converted into offline digital text file;Upper computer is based on preset protocol configuration parameter and carries out frame positioning check and physical quantity conversion, restores voltage / current physical quantity sequence;Finally generate time-domain physical waveform chart and detection report.The system includes the terminal to be measured, general digital acquisition equipment and upper computer.The scheme does not need special receiving hardware, supports offline backtracking and visual troubleshooting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of power metering automation testing technology, specifically to a method and system for directly capturing SPI bus physical level signals using general digital signal acquisition equipment, and performing physical quantity restoration and offline verification of metering accuracy of the original sampled digital signals of voltage and current output by devices such as smart meters and distribution IoT sensors through the SPI interface. Background Technology

[0002] In smart grids and new power systems, smart gateway energy meters and edge computing terminals commonly use SPI (Serial Peripheral Interface) as the data transmission channel with expansion modules. The SPI interface is driven by a high-frequency clock and outputs raw sampled digital signals containing instantaneous values ​​of three-phase voltage and current. Expansion modules rely on this data to calculate key power quality indicators such as grid frequency, harmonics, and voltage deviation. Therefore, the accuracy of the raw data from the SPI link layer directly affects the metering reliability of the entire sensing system.

[0003] Currently, there are two main technical approaches in the industry for detecting this type of data:

[0004] One approach relies on a standard programmable source to construct a closed-loop test environment. It inputs an analog reference signal with known parameters to the device under test (DUT), and then compares the device's output value with the theoretical value. This method can only verify the overall accuracy of the entire link from analog signal input to final numerical output; it cannot independently verify the raw digital frames output from the SPI interface. When errors exceed tolerances, it cannot determine whether the error originates from the analog front-end (ADC, PT, CT) or the digital transmission link (timing errors, data packet loss). Furthermore, this approach depends on a high-precision standard programmable source and a closed-loop test environment, making it unsuitable for testing in scenarios such as early-stage R&D debugging or offline troubleshooting in the absence of a standard source.

[0005] Another approach relies on customized, dedicated hardware fixtures as the receiving end, which parses SPI data to perform accuracy verification. This method can be used in large quantities during mature mass production, but it has a high hardware dependency, requiring custom development of dedicated receiving hardware, which typically takes several weeks. Without matching fixtures during the R&D phase, rapid verification is impossible, and hardware investment costs are high. Furthermore, traditional fixture testing functions are fixed; protocol iterations and new metrics require modifications to hardware logic or firmware, making it difficult to adapt to the rapid iteration pace of R&D. Its troubleshooting efficiency is also low, primarily outputting results in numerical reports, lacking time-domain waveform visualization capabilities, and failing to intuitively present abnormalities such as waveform distortion and data loss. Summary of the Invention

[0006] This application aims to overcome the technical shortcomings of existing power metering equipment SPI output data detection technologies, such as strong hardware dependence, difficulty in error tracing, poor functional scalability, and low visualization of detection results. It provides an offline power metering data detection scheme based on raw SPI bus frames. This scheme directly captures the raw level signals of the SPI bus physical layer using a general-purpose digital signal acquisition device, stores the raw digital frames offline as text files, and then performs protocol parsing, physical quantity conversion, metering accuracy verification, and visualization output on a host computer based on preset protocol configuration parameters. Ultimately, this achieves independent verification of the raw sampling data from the SPI link layer.

[0007] To solve the above-mentioned technical problems, this application provides the following technical solution.

[0008] An offline detection method for power metering data based on SPI bus raw frames is proposed. Its core process includes four main steps: physical signal acquisition and raw digital text generation, protocol parsing and physical quantity conversion, metering accuracy verification, and visualization and report output.

[0009] In the physical signal acquisition stage, the digital sampling probe of the general digital signal acquisition device is physically connected to the signal pin of the SPI hardware interface of the power metering terminal under test. The sampling rate of the acquisition device is set to be no less than several times the clock frequency of the SPI hardware interface so as to accurately reconstruct the SPI physical level timing signal, continuously capture the physical level timing signal covering at least several consecutive power frequency cycles, and convert it into an original digital text file for offline storage.

[0010] In the protocol parsing and physical quantity conversion stage, the host computer reads the preset protocol configuration parameters. These parameters include at least the frame structure parameters, the byte mapping parameters of each physical channel in the data frame, and the physical quantity conversion coefficients of each physical channel. Based on these parameters, the valid SPI data frames are located and verified from the original digital text file. The digital sampling code values ​​of each physical channel are extracted, and then, according to the physical quantity conversion coefficients of each physical channel, the digital sampling code values ​​are converted into time series data with physical dimensions of voltage or current values ​​through the physical quantity conversion formula.

[0011] In the measurement accuracy verification stage, the effective value of each physical channel within the preset calculation window is calculated based on the time series data. The effective value is compared with the preset benchmark physical quantity to calculate the relative error and output the effective value accuracy judgment result. At the same time, the time series data is divided into positive and negative half-waves based on the zero-crossing detection algorithm. The amplitude extreme values ​​of each positive and negative half-wave are extracted. The maximum and minimum amplitude values ​​of each physical channel in the entire waveform are counted. The maximum and minimum values ​​are compared with the preset peak benchmark to calculate the peak relative error and output the peak index verification result.

[0012] In the visualization and report output stage, time-domain physical waveforms of each physical channel are generated with time as the horizontal axis and physical dimensions as the vertical axis. Abnormal features such as data loss, amplitude jumps and phase shifts are automatically marked on the waveforms, and a test report containing waveforms, relative errors, peak verification results and judgment results is output.

[0013] In the above method, the frame structure parameters of the protocol configuration parameters include the frame start flag, frame end flag, length field position and byte order, and check algorithm type; the byte mapping parameters of each physical channel include the start byte offset, data bit width, and data encoding format; the physical quantity conversion coefficients include the scaling factor and zero-point offset. When locating and verifying a valid SPI data frame, the frame start flag is first searched in the original digital text file to locate the potential frame header. Then, the byte length of the current frame is read according to the length field position and byte order. The complete data field from the length field to the check field is extracted. The check value of this data field is then calculated according to the check algorithm type and compared with the corresponding check field in the original digital text file. If they match, it is marked as a valid frame; otherwise, the current frame is discarded and the error frame count is recorded. The physical quantity conversion formula is: the actual physical quantity equals the difference between the digital sampled code value and the zero-point offset multiplied by the scaling factor, where the scaling factor is in volts / least significant bit or amperes / least significant bit, the zero-point offset is in least significant bit, and the actual physical quantity is in volts or amperes.

[0014] In the measurement accuracy verification process, the preset calculation window is a number of power frequency cycles or an integer multiple of a number of power frequency cycles; the effective value is calculated by dividing the time series data into segments according to the preset calculation window, calculating the segmented effective value for the sampling points in each segment using the root mean square formula, and then averaging the multiple segmented effective values ​​to obtain the final effective value.

[0015] When extracting the amplitude extremes of each positive and negative half-wave, the maximum value of the sampling points within each positive half-wave is taken as the peak value of that positive half-wave, and the minimum value of the sampling points within each negative half-wave is taken as the valley value of that negative half-wave. The maximum amplitude of the entire waveform is the maximum value among all the peak values ​​of the positive half-waves, and the minimum amplitude is the minimum value among all the valley values ​​of the negative half-waves.

[0016] The entire process of protocol parsing, physical quantity conversion, metering accuracy verification, and visualization output is executed offline in the host computer. The host computer does not need to maintain a real-time communication connection with the measured power metering terminal when performing the above operations.

[0017] At the system level, this application also provides an offline detection system for power metering data based on SPI bus raw frames for performing the above-described method. The system includes a power metering terminal under test, a general-purpose digital signal acquisition device, and a host computer testing system. The power metering terminal under test has an SPI hardware interface for outputting SPI data frames containing raw sampled digital signals of voltage and / or current. The general-purpose digital signal acquisition device is equipped with a digital sampling probe, which is physically connected to the clock line, data output line, and chip select pin of the SPI hardware interface of the power metering terminal under test. This probe is used to capture the physical level timing signals output by the SPI hardware interface within a specified time period and convert them into raw digital text files. The host computer testing system is communicatively connected to the general-purpose digital signal acquisition device to acquire the raw digital text files and is configured with protocol configuration parameters for performing the protocol parsing, physical quantity conversion, metering accuracy verification, and visualization output steps of the above-described method.

[0018] The general-purpose digital signal acquisition equipment is specifically a logic analyzer or an oscilloscope with a digital channel. Its sampling rate is no less than several times the clock frequency of the SPI hardware interface, and its storage depth is capable of continuously capturing physical level timing signals for at least several consecutive power frequency cycles. The power metering terminal under test is specifically a three-phase smart gateway energy meter or a distribution IoT sensor. Its SPI hardware interface outputs raw sampled digital signals of three-phase voltage, three-phase current, and optional neutral current. The host computer test system allows users to input protocol configuration parameters through a graphical interface. The protocol configuration parameters are stored in the form of a configuration file, which can adapt to power metering terminals of different manufacturers and different protocol versions without modifying the program code of the host computer test system.

[0019] The technical solution adopted in this application, by combining direct acquisition of physical layer digital signals with parameterized software analysis, fundamentally changes the dependence on dedicated receiving hardware and closed-loop testing environment, enabling the testing process to be carried out quickly in various scenarios such as early product development, factory sampling inspection, and offline review of on-site faults, and has wide engineering applicability.

[0020] The present invention provides an offline detection method and system for power metering data based on SPI bus raw frames, which has the following advantages compared with the prior art:

[0021] This application completely eliminates the reliance on dedicated receiving hardware fixtures, significantly expanding the applicable testing scenarios. Traditional testing solutions require expansion units or customized test fixtures as data receivers, resulting in long hardware development cycles and high costs. Furthermore, verification is impossible in the early stages of R&D when no suitable fixtures are available. This application requires only a general-purpose logic analyzer or an oscilloscope with a digital channel to directly capture the raw digital pulse signals on the SPI bus via a physical connection, eliminating the need for customized hardware or closed-loop test sources. This solution can be rapidly deployed in various scenarios, including early-stage R&D debugging, factory sampling inspection, and offline troubleshooting, effectively reducing hardware investment and setup time for the testing environment. It offers exceptional deployment flexibility and scenario adaptability.

[0022] This application achieves independent verification of the raw digital frames of the SPI link layer, solving the problem of difficulty in tracing the source of errors. Traditional whole-system testing schemes can only verify the overall accuracy of the entire link from analog input to final numerical output, and cannot distinguish whether the error originates from the analog front-end or the digital transmission link. This application directly acquires the raw digital frames on the SPI bus, bypassing the signal conditioning and AD conversion errors that may be introduced by the analog port secondary sampling in traditional schemes, making it possible to independently evaluate the data transmission quality of the SPI link layer. When an error exceeding the tolerance is detected, it is possible to accurately determine whether the problem lies in the analog front-end or the digital transmission link, effectively improving the efficiency of hardware fault location.

[0023] This application possesses parameterized protocol parsing and modular calculation capabilities, offering flexible and scalable functionality. Traditional tooling testing functions are fixed, requiring modifications to hardware logic or firmware for protocol iterations or the addition of new test metrics, resulting in lengthy adaptation cycles. This application drives the parsing logic through preset protocol configuration parameters, which are imported in the form of configuration files. This allows for adaptation to various data formats from different manufacturers, with different protocol versions and whether or not a neutral channel is included, without modifying program code, reducing the adaptation cycle from weeks to minutes. Furthermore, functions such as RMS calculation, peak value verification, and zero-crossing detection employ a modular design, allowing for the addition of new algorithms such as harmonic analysis based on R&D needs. The test content can be flexibly expanded, significantly improving R&D iteration efficiency.

[0024] This application achieves full-process automation and visualization, significantly improving troubleshooting efficiency. Traditional tooling primarily outputs results in numerical reports, lacking intuitive time-domain waveform display capabilities, and anomaly localization relies on manual frame-by-frame inspection. This application integrates a graphical parameter configuration interface and channel-specific waveform visualization output, enabling one-click automated processing of parameter input, message parsing, value conversion, accuracy determination, and result display. This lowers the professional threshold for testing operations and reduces the error rate of manual analysis and calculation. Simultaneously, the time-domain physical waveform diagram can intuitively present abnormalities such as data loss, phase shift, and waveform distortion, helping testers quickly locate specific problems and significantly improving the efficiency of R&D debugging and fault diagnosis.

[0025] This application, based on digital domain processing and combined with a multi-window aggregation calculation method, effectively reduces measurement uncertainty. By directly acquiring the raw digital frames of the SPI bus, the additional uncertainty components introduced by secondary sampling in traditional analog ports are avoided, and the digital link itself has no additional analog error. Simultaneously, through multi-window aggregation calculation (e.g., further averaging the effective values ​​of 10 power frequency cycles over 150 power frequency cycles), the measurement sample size is effectively increased, significantly reducing Type A uncertainty caused by random fluctuations and improving the confidence of the evaluation results. This allows the scheme to maintain flexibility while achieving high measurement accuracy.

[0026] This application combines economy, flexibility, and accuracy, and can be widely applied to the entire life cycle of equipment such as three-phase smart gateway energy meters, power acquisition terminals, and distribution IoT sensors, including research and development, debugging, factory verification, and on-site sampling inspection. It provides efficient and reliable technical support for the quality control of frequency data of power grid end-point sensing equipment. Attached Figure Description

[0027] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0028] Figure 1 This is a flowchart illustrating an offline detection method for power metering data based on raw frames from the SPI bus.

[0029] Figure 2 This is a schematic diagram of the architecture of an offline detection system for power metering data based on raw frames of the SPI bus.

[0030] Figure 3 This is a sequence diagram of the interaction between the system hardware and other components. Detailed Implementation

[0031] The technical solutions in the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings.

[0032] In the following description, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The following description provides multiple embodiments of this application, which can be substituted or combined with each other. Therefore, this application can also be considered to include all possible combinations of the same and / or different embodiments described. Thus, if one embodiment includes features A, B, and C, and another embodiment includes features B and D, then this application should also be considered to include embodiments containing one or more other possible combinations of A, B, C, and D, even if such embodiments are not explicitly described in the following text.

[0033] The following description provides examples and does not limit the scope, applicability, or examples set forth in the claims. Changes may be made to the function and arrangement of the described elements without departing from the scope of this application. Various processes or components may be appropriately omitted, substituted, or added to the examples. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Furthermore, features described with respect to some examples may be combined into other examples.

[0034] This application proposes an offline detection scheme for power metering data based on raw frames from the SPI bus. The core concept of this scheme is to redesign the traditional test architecture, which relies on dedicated hardware receivers, into a novel test architecture that combines direct physical layer signal acquisition with offline software layer parsing.

[0035] Specifically, the physical level timing signals on the SPI bus are directly captured using general-purpose digital signal acquisition equipment. The raw digital frames are stored offline as text files. Then, the host computer performs protocol parsing, physical quantity conversion, measurement accuracy verification, and visualization output based on preset protocol configuration parameters. In this way, the expansion unit or custom test fixtures can be bypassed, enabling independent verification of the raw digital frames of the SPI link layer.

[0036] This solution requires the cooperation of three hardware entities: the power metering terminal under test, a general-purpose digital signal acquisition device, and a host computer testing system. The power metering terminal under test has an SPI hardware interface, used to output SPI data frames containing raw sampled digital signals of voltage or current. The general-purpose digital signal acquisition device is equipped with a digital sampling probe, which is physically connected to the SPI interface signal pin of the terminal under test, used to capture the physical level timing signals output by the interface within a specified time period. The host computer testing system communicates with the acquisition device, used to acquire the raw digital text file converted by the acquisition device, and performs subsequent parsing, conversion, verification, and display at the software level.

[0037] The following sections will provide a detailed explanation of this solution from two dimensions: methodology and system structure.

[0038] For information on testing methods, please refer to [link / reference]. Figure 1 , Figure 1 This is a flowchart illustrating an offline detection method for power metering data based on raw SPI bus frames, provided in an embodiment of this application. In this embodiment, the method includes the following steps:

[0039] Step S1, Physical signal capture and raw digital text generation:

[0040] The digital sampling probe of the general digital signal acquisition device is physically connected to the signal pin of the SPI hardware interface of the power metering terminal under test. The sampling rate of the general digital signal acquisition device is set to be no less than several times the clock frequency of the SPI hardware interface, so as to accurately reconstruct the SPI physical level timing signal, continuously capture the physical level timing signal covering at least several consecutive power frequency cycles, convert the physical level timing signal into an original digital text file and store it offline.

[0041] Step S2, Protocol parsing and physical quantity conversion:

[0042] The host computer reads the preset protocol configuration parameters, which include at least frame structure parameters, byte mapping parameters of each physical channel in the data frame, and physical quantity conversion coefficients of each physical channel. Based on the protocol configuration parameters, the valid SPI data frame is located and verified from the original digital text file, and the digital sampling code value of each physical channel is extracted. According to the physical quantity conversion coefficients of each physical channel, the digital sampling code value is converted into time series data with physical dimensions of voltage or current value.

[0043] Step S3, Measurement accuracy verification:

[0044] Based on time series data, the effective value of each physical channel within a preset calculation window is calculated. The preset calculation window is a number of power frequency cycles or an integer multiple of a number of power frequency cycles. The effective value is compared with a preset reference physical quantity, the relative error is calculated, and the accuracy judgment result of the effective value of each physical channel is output according to the preset error threshold.

[0045] Furthermore, based on the zero-crossing detection algorithm, the time series data is divided into positive and negative half-waves, the amplitude extreme values ​​of each positive and negative half-wave are extracted, the maximum and minimum amplitude values ​​of each physical channel in the entire waveform are counted, the maximum and minimum values ​​are compared with the preset peak benchmark, the peak relative error is calculated, and the peak index verification results of each physical channel are output according to the preset peak error threshold.

[0046] Step S4, Visualization and Report Output:

[0047] Using time as the horizontal axis and physical units as the vertical axis, a time-domain physical waveform diagram of each physical channel is generated. At least one of the following abnormal features is automatically marked on the waveform diagram: data loss due to frame verification failure or frame sequence number jump, amplitude jump with amplitude change exceeding a preset threshold between adjacent sampling points, and phase offset with phase deviation between each physical channel exceeding a preset threshold. A detection report containing waveform diagram, relative error, peak verification result and judgment result is output.

[0048] The technical approach of this method, starting from physical signal acquisition and ending with the automated output of the test report, comprises four main steps, namely steps S1 to S4 mentioned above. The following provides a detailed description of the method of this application in conjunction with each step.

[0049] In step S1, physical signal capture and raw digital text generation are performed.

[0050] Specifically, the digital sampling probe of the general-purpose digital signal acquisition device is physically connected to the signal pins of the SPI hardware interface of the power metering terminal under test. This SPI interface is typically a standard four-wire interface, including a clock line (SCK), a data output line (MISO), a data input line (MOSI), and a chip select line (CS).

[0051] In this solution, since the sampled data pushed out by the terminal under test is being detected, the main signal lines involved are SCK, MISO, and CS. During connection, it is necessary to ensure reliable contact between the probe and each pin, and to complete the common ground connection.

[0052] The sampling rate of the general-purpose digital signal acquisition device is then set. The sampling rate should be chosen based on the principle of accurately reconstructing the SPI physical level timing signal, and should generally be no less than several times the SPI hardware interface clock frequency. The acquisition device continuously captures physical level timing signals covering at least several consecutive power frequency cycles within a specified time period, converts the captured physical level timing signals into raw digital text files, and stores them offline. The raw digital text file is typically in hexadecimal text format.

[0053] In step S2, protocol parsing and physical quantity conversion are performed.

[0054] This step specifically includes two sub-processes: frame positioning and verification, and the conversion of digital code values ​​to physical quantities. First, the host computer obtains the original digital text file generated in step S1.

[0055] To ensure the parsing process is compatible with terminals from different manufacturers and using different protocol versions, the host computer has pre-defined protocol configuration parameters. These parameters are imported all at once in the form of a configuration file, without requiring modification to the host computer's program code. The protocol configuration parameters include at least frame structure parameters, byte mapping parameters for each physical channel in the data frame, and physical quantity conversion coefficients for each physical channel.

[0056] The frame structure parameters mainly include the frame start flag, frame end flag, length field position and byte order, and checksum algorithm type. The byte mapping parameters for each physical channel mainly include the starting byte offset, data bit width, and data encoding format of each physical channel in the data field. The physical quantity conversion factors mainly include the scaling factor and zero-point offset for each physical channel. All of the above parameters are derived from the hardware design specifications and factory calibration values ​​of the device under test and serve as the basis for physical layer signal reconstruction.

[0057] Based on the read protocol configuration parameters, the host computer first performs frame location and integrity verification from the original digital text file.

[0058] The specific execution process is as follows: Search for the frame start marker in the original digital text file to locate potential frame headers; read the byte length of the current frame based on the position of the length field and the byte order; extract the complete data field from the length field to the check field; calculate the check value of this data field according to the check algorithm type, and compare the calculated check value with the corresponding check field in the original digital text file. If they match, the frame is marked as a valid frame; otherwise, the current frame is discarded and the error frame count is recorded.

[0059] After frame location and verification are completed, the digital sample code values ​​of each physical channel are extracted sequentially from the data field of each valid frame according to the byte mapping parameters of each physical channel. The digital sample code values ​​are usually represented in two's complement or sign-magnitude form.

[0060] Then, based on the physical quantity conversion coefficients of each physical channel, the digital sampling code values ​​are converted into time series data with physical quantity dimensions, namely voltage or current values, using the following physical quantity conversion formula:

[0061] Actual physical quantity = (digital sampling code value - zero offset) × scaling factor

[0062] In this formula, the unit of the proportionality coefficient is volts / least significant bit (V / LSB) or amperes / least significant bit (A / LSB), the unit of the zero offset is least significant bit (LSB), and the unit of the actual physical quantity is volts (V) or amperes (A).

[0063] This conversion process maps purely digital code values ​​to actual voltage or current physical quantities, providing a data foundation with clear physical meaning for subsequent measurement accuracy verification. The resulting time series data for each channel represents the instantaneous voltage and current physical quantities output by the measured terminal during the acquisition period.

[0064] In step S3, a measurement accuracy verification is performed.

[0065] This step is specifically divided into three parts: valid value verification, peak value verification, and frequency calculation.

[0066] Regarding valid value verification, the host computer calculates the valid value of each physical channel within a preset calculation window based on the time series data obtained in step S2. The preset calculation window is a number of power frequency cycles or an integer multiple of a number of power frequency cycles, and its specific length can be selected according to the metrological specifications or user requirements.

[0067] The effective value is calculated as follows: the time series data is segmented according to a preset calculation window, and the effective value of each segment is calculated using the root mean square formula for the sampling points within each segment. Then, the arithmetic mean of multiple segmental effective values ​​is taken to obtain the final effective value. The final effective value is compared with a preset reference physical quantity to calculate the relative error, and the accuracy judgment result of the effective value of each physical channel is output according to the preset error threshold.

[0068] For peak value verification, the host computer uses a zero-crossing detection algorithm to segment the time series data into positive and negative half-waves. This algorithm traverses adjacent sampling points to locate the zero-crossing points where the sampled value changes from positive to negative or vice versa, thus achieving precise segmentation of the waveform's positive and negative half-waves. For each positive half-wave, the maximum value of its internal sampling points is taken as the peak value; for each negative half-wave, the minimum value of its internal sampling points is taken as the valley value. Then, the maximum and minimum amplitude values ​​of each physical channel in the entire waveform are calculated. The maximum amplitude is the maximum among all positive half-wave peaks, and the minimum amplitude is the minimum among all negative half-wave valleys. The obtained maximum and minimum amplitude values ​​are compared with a preset peak benchmark to calculate the relative peak error. Based on a preset peak error threshold, the peak value verification results for each physical channel are output.

[0069] In step S4, visualization and report output are performed.

[0070] In this step, the host computer generates time-domain physical waveform diagrams for each physical channel, with time as the horizontal axis and physical quantities as the vertical axis. The vertical axis of the waveform diagram directly indicates the units of voltage and current (V / A), allowing the observer to intuitively judge the amplitude and phase characteristics of the waveform.

[0071] While generating the waveform, the host computer automatically marks abnormal features on the waveform. These abnormal features include at least the following three situations:

[0072] Firstly, data loss due to frame verification failure or frame sequence number jump will be represented by signal loss within a specific time interval on the waveform diagram, marked with blank marks or specific symbols.

[0073] Secondly, amplitude jumps between adjacent sampling points that exceed a preset threshold usually correspond to glitches or error codes during data transmission and are highlighted to indicate this.

[0074] Third, if the phase deviation between each physical channel exceeds a preset threshold, this indicates an abnormal phase relationship between the phase voltages or currents and is indicated by a color warning.

[0075] Finally, the host computer outputs a test report including waveforms, relative error of effective values, peak value verification results, and judgment results. The test report can be output in PDF or Excel file format for testing personnel to archive or further analyze.

[0076] The entire process of protocol parsing, physical quantity conversion, metering accuracy verification, and visualization output in steps S2 to S4 is executed offline in the host computer. The host computer does not need to maintain a real-time communication connection with the power metering terminal under test when performing these operations. This means that testers can complete the accuracy retrospective verification of sampling data from any past time period using only the original digital text file stored offline in step S1, even without an on-site testing environment.

[0077] This offline execution mode is particularly suitable for debugging scenarios in the early stages of product development when there are no supporting tooling, pre-shipment sampling inspection scenarios, and offline reproduction scenarios after on-site failures, significantly improving the flexibility and applicability of testing. Protocol configuration parameters are entered by users through a graphical interface and imported into the host computer in the form of a configuration file. The entire adaptation process can be completed in just a few minutes without modifying the host computer's program code, enabling this solution to quickly adapt to terminals under test from different manufacturers and with different protocol versions.

[0078] For information about the detection system, please refer to [link / reference]. Figure 2 , Figure 2 This application provides an architecture block diagram of an offline power metering data detection system based on SPI bus raw frames, which is used to perform the above-described detection method in an embodiment of the application. The system includes:

[0079] The measured power metering terminal has an SPI hardware interface, which is used to output SPI data frames containing raw sampled digital signals of voltage and / or current through the SPI hardware interface.

[0080] A general-purpose digital signal acquisition device is equipped with a digital sampling probe. The digital sampling probe is physically connected to the clock line SCK, data output line MISO, and chip select line CS pin of the SPI hardware interface of the power metering terminal under test. It is used to capture the physical level timing signal output by the SPI hardware interface within a specified time period and convert the physical level timing signal into a raw digital text file.

[0081] The host computer testing system is connected to a general digital signal acquisition device to acquire raw digital text files and is configured with protocol configuration parameters to execute steps S2 to S4 of the above detection method.

[0082] At the system level, the implementation of this solution relies on the coordinated operation of three hardware entities: the power metering terminal under test, the general digital signal acquisition equipment, and the host computer testing system.

[0083] The measured power metering terminal is a power metering device with an SPI hardware interface. Its function is to collect the voltage and current signals of the power grid in real time and push the sampled data out in the form of digital frames through the SPI interface.

[0084] The terminal can specifically be a three-phase smart gateway energy meter or a distribution IoT sensor, etc. In actual operation, the signals output through the SPI interface of these devices typically include three-phase voltage and three-phase current; some devices also include data from the neutral current channel. The SPI interface of the measured power metering terminal follows a standard four-wire communication protocol. Its data frame format, number of sampling points, and channel arrangement are determined by the device's own hardware design and communication protocol specifications. Different device manufacturers or different product models from the same manufacturer may have different SPI protocol frame formats, but this solution can achieve adaptation through preset protocol configuration parameters.

[0085] General-purpose digital signal acquisition equipment is a measuring instrument with digital sampling capabilities, specifically a logic analyzer or an oscilloscope with digital channels. This equipment is equipped with a digital sampling probe, which can be directly and physically connected to the SPI hardware interface signal pin of the power metering terminal under test.

[0086] In practice, the clock line (SCK), data output line (MISO), and chip select line (CS) are typically connected. If necessary, the data input line (MOSI) and common ground line (GND) can also be connected. The function of a general-purpose digital signal acquisition device is to capture the physical level timing signals output by the SPI hardware interface within a specified time period and convert these physical level timing signals into raw digital text files.

[0087] To meet the requirements of this solution for accurate reconstruction of physical level timing signals, the sampling rate of the general-purpose digital signal acquisition equipment should be no less than several times the clock frequency of the SPI hardware interface, and its storage depth should be able to continuously capture physical level timing signals for at least several consecutive power frequency cycles.

[0088] As a preferred implementation, the sampling rate can be selected to be more than 5 times the SPI clock frequency, and the storage depth can be selected to be able to continuously capture signal quantities of at least 150 power frequency cycles.

[0089] The host computer testing system is a general-purpose computer device equipped with testing software. This device communicates with general-purpose digital signal acquisition equipment to obtain raw digital text files from the acquisition equipment. The host computer testing system is configured with testing software, which includes a protocol parsing engine, a physical quantity conversion module, a measurement calculation module, and a visualization module. The testing software allows users to input protocol configuration parameters through a graphical interface, which are stored in configuration files. Users can flexibly switch configurations according to the data format of different tested terminals without modifying the program code. After obtaining the raw digital text file, the host computer testing system executes steps S2 to S4 as described above, according to the user-preset protocol configuration parameters.

[0090] See Figure 3 During system operation, the following data flow and action logic are formed among the three components: The power metering terminal under test continuously outputs SPI data frames, and the general-purpose digital signal acquisition device captures and stores the physical level signals of these data frames in real time through a physical connection. After data acquisition is completed, the host computer test system reads the raw digital text file generated by the acquisition device offline and executes all calculation and visualization logic. In this process, the host computer test system does not need to establish a real-time communication link with the power supply or the terminal under test; it can complete the entire testing process solely based on the offline stored text file. This decoupled "acquisition-analysis" system architecture allows this solution to be quickly deployed in any environment equipped with acquisition equipment and a host computer.

[0091] In a preferred embodiment, the sampling frequency in step S1 should be as high as possible. As a feasible example, "several times" can be specifically selected as no less than 5 times the SPI hardware interface clock frequency. This multiplier has been verified in experiments to fully reconstruct the physical level timing signals of typical frequencies (1MHz to 10MHz) on the SPI bus, ensuring accurate restoration of the timing relationship between sampling points. In practical application scenarios, the frequency of the logic analyzer may be higher, such as 100MHz. In this case, the sampling frequency should be adjusted accordingly, such as increasing it to 10 times.

[0092] "Several consecutive power frequency cycles" can be specifically selected as at least 150 consecutive power frequency cycles. This duration can cover a sufficient number of power frequency cycle samples, ensuring sufficient statistical stability for subsequent RMS calculations and peak value statistics. "Several power frequency cycles or integer multiples of several power frequency cycles" in step S3 can be specifically selected as 10 power frequency cycles or 150 power frequency cycles. 10 power frequency cycles correspond to 200 milliseconds, suitable for rapid verification; 150 power frequency cycles correspond to 3 seconds, suitable for higher-precision statistical evaluation. The selection is based on the general metrological specifications for power quality measurement.

[0093] The following is a specific embodiment to further illustrate the implementation process of this solution.

[0094] The tested object is a three-phase smart energy meter with a rated voltage of 220V and a rated current of 5A.

[0095] This energy meter pushes raw sampled data of three-phase voltage and three-phase current to the outside world via an SPI interface with a clock frequency of 7.25MHz. The sampling communication protocol it follows consists of a 1-byte 0x68 header, a two-byte command character, a two-byte length field in little-endian format, followed by a cycle data field and a check field, and a 0x16 end-of-frame character. The protocol specifies that each channel's sampled value is in 24-bit two's complement format, and each power frequency cycle contains 256 sampling points.

[0096] According to the factory calibration parameters of this energy meter, the voltage channel conversion factor is 1.47008, and the current channel conversion factor is 6.59769, meaning that the physical quantity value corresponding to each LSB is 1.47008 × 10⁻⁶. -9 V and 6.59769×10 -9 A. When converting, use 10 to the power of 9 as the decimal place offset.

[0097] When conducting the test, step S1 is performed first.

[0098] Connect the digital sampling probe of a logic analyzer to the SCK, MISO, and CS pins of the SPI interface of the energy meter, and establish a common ground connection. Set the logic analyzer's sampling rate to 100MHz, which is approximately 13.8 times the SPI clock frequency of 7.25MHz, enabling accurate reconstruction of the SPI physical level timing signal. Set the trigger mode to CS falling edge active, and continuously acquire the physical level timing signal for 5 seconds after starting capture, then terminate the acquisition. Use the logic analyzer's built-in SPI protocol decoding function to convert the captured physical level timing signal into a hexadecimal text file, and export it to the communicating host computer for storage.

[0099] The host computer is equipped with the detection software described in this solution. The operator enters the protocol configuration parameters in the graphical interface. In the frame structure parameters, the frame header is entered as 0x68, the frame trailer as 0x16, the length field is located two bytes after the command character and is in little-endian format, and the checksum algorithm is cumulative summation.

[0100] In the byte mapping parameters for each physical channel, the starting offset byte for phase A voltage is entered as 10, phase B voltage as 13, phase C voltage as 16, phase A current as 19, phase B current as 22, and phase C current as 25. The bit width for each is 24 bits, and the encoding format is two's complement. In the physical quantity conversion coefficients, the conversion coefficient for the voltage channel is entered as 1.47008, and the conversion coefficient for the current channel is entered as 6.59769, with a uniform decimal offset of 10 to the power of 9. After completing the above input, save the configuration file to the host computer.

[0101] Next, proceed to step S2.

[0102] The detection software reads a hexadecimal text file and performs frame location and verification according to the configured frame structure parameters. The software searches for 0x68 in the text file to locate the frame header, reads the frame byte length based on the length field, extracts the data field, calculates the cumulative sum, and compares it with the frame tail check field. If they match, the frame is marked as valid; frames that fail the check are automatically discarded. From the data field of each valid frame, the detection software extracts the 24-bit two's complement digital sampling code value for each channel according to the configured channel byte offset and bit width. The code value is in hexadecimal format. For example, the extracted code value for a certain sampling point of phase A voltage is 16D5C5 (hexadecimal), which is 1496517 in decimal. According to the physical quantity conversion formula, the actual voltage value of this sampling point is:

[0103] U 实际 =1496517×1.47008÷10 9 =220.00V.

[0104] In the same manner, the detection software sequentially converts all sampling points of each valid frame to obtain the instantaneous voltage and current value sequence of each channel.

[0105] Then, step S3 is executed. The detection software uses a calculation window of 200 milliseconds (i.e., 10 power frequency cycles) to segment the voltage and current sequences. For each segment, the effective value is calculated using the root mean square formula, and then the effective values ​​of each segment are arithmetically averaged to obtain the final effective value for each channel. The calculated effective value is 220.05V for phase A, 220.01V for phase B, and 219.92V for phase C.

[0106] The detection software simultaneously performs peak value verification on both the voltage and current sequences, and uses a zero-crossing detection algorithm to segment the positive and negative half-waves, extracting the peak value of each positive half-wave and the trough value of each negative half-wave. Statistically, the maximum peak value of the positive half-wave of phase A voltage is 311.1V, and the minimum trough value is -311.0V.

[0107] The testing software compares the aforementioned effective and peak values ​​with the user-preset nominal value of 220V and peak reference of 311.1V, respectively, and calculates the relative errors. The relative errors for the effective value of phase A voltage are 0.02%, phase B voltage is 0.005%, and phase C voltage is -0.04%. All three are less than the preset error threshold of 0.5%, therefore the output effective value judgment result is qualified. The relative error of the peak value index is also within the preset threshold range, and the output peak value verification result is qualified.

[0108] Finally, step S4 is executed. The detection software plots the time-domain physical waveforms of the three-phase voltage and three-phase current with time as the horizontal axis and voltage and current as the vertical axes. The waveforms, with V and A as the vertical axis units, clearly show the amplitude and phase relationship of each phase voltage and current.

[0109] For example, in the waveform graph, the detection software automatically marks a slight amplitude jump detected at 2000ms and highlights it in yellow. The detection software ultimately outputs a complete detection report, which includes the waveform graph, a table of effective values ​​for each channel, peak value verification results, an error statistics table, and a pass / fail conclusion.

[0110] The above specific embodiments fully demonstrate the entire process of this solution from step S1 to step S4, and fully verify that this solution can independently and accurately verify the original sampling data of the SPI link layer without relying on dedicated receiving hardware.

[0111] This application directly captures the physical level timing signals on the SPI bus using a general-purpose digital signal acquisition device. Through offline parsing and parameterized configuration, it achieves comprehensive verification of the effective and peak values ​​of the SPI output data from the power metering terminal. The system side uses the physical entity combination of the terminal under test, the acquisition device, and the host computer as the implementation carrier, while the method side uses the complete process from step S1 to step S4 as the execution main line. Together, they constitute an offline detection technology architecture with low hardware dependency, wide applicability, and flexible functional expansion. This architecture can be widely applied in the research and development, debugging, factory sampling inspection, and field fault review of equipment such as three-phase smart gateway energy meters and distribution IoT sensors. By transforming the dependency on hardware receiving fixtures into the flexibility of software configuration, this solution significantly improves detection efficiency and engineering applicability while ensuring measurement accuracy. Any modifications, equivalent substitutions, or improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.

[0112] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0113] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0114] Those skilled in the art will understand that all or part of the steps in the various methods of the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage device, which may include: a flash drive, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk, etc.

[0115] The foregoing description is merely an exemplary embodiment of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Those skilled in the art will readily conceive of embodiments of this disclosure upon considering the specification and practicing the disclosure herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described herein. The specification and embodiments are to be considered exemplary only, and the scope and spirit of this disclosure are defined by the claims.

Claims

1. A method for offline detection of power metering data based on SPI bus raw frames, characterized in that, Includes the following steps: Step S1, Physical signal capture and raw digital text generation: The digital sampling probe of the general digital signal acquisition device is physically connected to the signal pin of the SPI hardware interface of the power metering terminal under test. The sampling rate of the general digital signal acquisition device is set to be no less than several times the clock frequency of the SPI hardware interface, so as to accurately reconstruct the SPI physical level timing signal, continuously capture the physical level timing signal covering at least several consecutive power frequency cycles, convert the physical level timing signal into an original digital text file and store it offline. Step S2, Protocol parsing and physical quantity conversion: Read the preset protocol configuration parameters in the host computer. The protocol configuration parameters include at least frame structure parameters, byte mapping parameters of each physical channel in the data frame, and physical quantity conversion coefficients of each physical channel. Based on the protocol configuration parameters, locate and verify valid SPI data frames from the original digital text file, and extract the digital sampling code values ​​of each physical channel. Based on the physical quantity conversion coefficients of each physical channel, the digital sampling code value is converted into time series data with physical quantity dimensions, namely voltage or current values. Step S3, Measurement accuracy verification: Based on the time series data, the effective value of each physical channel within a preset calculation window is calculated. The preset calculation window is a number of power frequency cycles or an integer multiple of a number of power frequency cycles. The effective value is compared with a preset reference physical quantity, the relative error is calculated, and the accuracy judgment result of the effective value of each physical channel is output according to the preset error threshold. Furthermore, the time series data is divided into positive and negative half-waves based on the zero-crossing detection algorithm, the amplitude extreme values ​​of each positive and negative half-wave are extracted, the maximum and minimum amplitude values ​​of each physical channel in the entire waveform are counted, the maximum and minimum values ​​are compared with the preset peak benchmark, the peak relative error is calculated, and the peak index verification results of each physical channel are output according to the preset peak error threshold. Step S4, Visualization and Report Output: Using time as the horizontal axis and the physical units as the vertical axis, a time-domain physical waveform diagram of each physical channel is generated. At least one of the following abnormal features is automatically marked on the waveform diagram: data loss due to frame verification failure or frame sequence number jump, amplitude jump with amplitude change exceeding a preset threshold between adjacent sampling points, and phase offset with phase deviation between each physical channel exceeding a preset threshold. A detection report containing the waveform diagram, the relative error, the peak verification result, and the judgment result is output.

2. The method according to claim 1, characterized in that, In step S1, the sampling rate of the general digital signal acquisition device is not less than 5 times the clock frequency of the SPI hardware interface, and it continuously captures physical level timing signals for at least 150 power frequency cycles. In step S3, the preset calculation window is 10 power frequency cycles or 150 power frequency cycles.

3. The method according to claim 1, characterized in that, In step S1, the general-purpose digital signal acquisition device is a logic analyzer or an oscilloscope with a digital channel, whose storage depth is capable of continuously capturing physical level timing signals for at least 3 seconds; the original digital text file is in hexadecimal text file format.

4. The method according to claim 1, characterized in that, In step S2, the frame structure parameters include a frame start flag, a frame end flag, the position and byte order of the length field, and the verification algorithm type; the byte mapping parameters of each physical channel include the starting byte offset, data bit width, and data encoding format of each physical channel in the data field; and the physical quantity conversion coefficients include the scaling factor and zero offset of each physical channel.

5. The method according to claim 1, characterized in that, In step S2, the protocol configuration parameters are entered by the user through a graphical interface, and the protocol configuration parameters are imported all at once in the form of a configuration file.

6. The method according to claim 1, characterized in that, In step S3, the effective value is calculated as follows: the time series data is segmented according to the preset calculation window, the effective value of each segment is calculated by the root mean square formula for the sampling points in each segment, and the arithmetic mean of multiple segment effective values ​​is then calculated to obtain the final effective value.

7. The method according to claim 1, characterized in that, In step S3, when extracting the amplitude extreme values ​​of each positive and negative half-wave, the maximum value of the sampling points in each positive half-wave is taken as the peak value of the positive half-wave, and the minimum value of the sampling points in each negative half-wave is taken as the valley value of the negative half-wave; the maximum amplitude value of the entire waveform is the maximum value among all the peak values ​​of the positive half-wave, and the minimum amplitude value is the minimum value among all the valley values ​​of the negative half-wave.

8. The method according to claim 1, characterized in that, Steps S2 to S4 are all executed offline in the host computer. The host computer does not need to maintain a real-time communication connection with the measured power metering terminal when executing steps S2 to S4.

9. An offline detection system for power metering data based on SPI bus raw frames, characterized in that, The system for performing the method according to any one of claims 1 to 8 comprises: The measured power metering terminal has an SPI hardware interface for outputting SPI data frames containing raw sampled digital signals of voltage and / or current through the SPI hardware interface. A general-purpose digital signal acquisition device is equipped with a digital sampling probe, which is physically connected to the clock line SCK, data output line MISO, and chip select line CS pin of the SPI hardware interface of the power metering terminal under test. The digital sampling probe is used to capture the physical level timing signal output by the SPI hardware interface within a specified time period and convert the physical level timing signal into a raw digital text file. The host computer testing system is communicatively connected to the general digital signal acquisition device, used to acquire the original digital text file, and is configured with protocol configuration parameters to execute steps S2 to S4 of the method according to any one of claims 1 to 8.

10. The system according to claim 9, characterized in that, The measured power metering terminal is a three-phase smart gateway energy meter or a power distribution IoT sensor, whose SPI hardware interface outputs raw sampled digital signals of three-phase voltage, three-phase current and optional neutral current.