package com.njcn.csharmonic.offline.mincfg;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;

/**
 * Description:
 * Date: 2024/7/15  19:14【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
public class TagPQDataCmnHh {
    short name;                         /*监测点序号       2    */
    short dataType;                    /*数据类型         2    */
    public int dataTag;                        /* 标记		1：暂态标记 2：无效数据*/
    public RTC_Timer_MS time;                /* 时标		 			*/
    /*2-9k谐波 2.1kHz / 2.3kHZ … 8.9kHz */
    public float[][] hharmRmsList29K;        /*6-35 谐波有效值序列(Uabc/Iabc)		*/
    public float[][] hharmThdList29K;        /*6-35 谐波含有率序列		*/
    public float[] hharmTotalRms29K;        /*6 谐波总有效值			*/
    public float[] hharmTotalThd29K;        /*6 谐波总畸变率			*/
    public float[] hharmMaxRms29K;          /*6 谐波最大有效值		*/
    public float[] hharmMaxThd29K;          /*6 谐波最大畸变率		*/
    public float[] hharmMaxFreq29K;         /*6 谐波最大值频点		*/
    /*2-150k谐波 2kHz / 4kHz … 150kHz */
    public float[][] hharmRmsList2150K;      /*6-75 谐波有效值序列(2-150)	*/
    public float[][] hharmThdList2150K;      /*6-75 谐波含有率序列		*/
    public float[] hharmTotalRms2150K;      /*6 谐波总有效值			*/
    public float[] hharmTotalThd2150K;      /*6 谐波总畸变率			*/
    public float[] hharmMaxRms2150K;        /*6 谐波最大有效值		*/
    public float[] hharmMaxThd2150K;        /*6 谐波最大畸变率		*/
    public float[] hharmMaxFreq2150K;     	/*6 谐波最大值频点 		*/

    public static int getSize() {
        int len = RTC_Timer_MS.GetSize() + 2 * Short.BYTES + 1 * Integer.BYTES + 6 * 35 * 2 * Float.BYTES + 6 * 75 * 2 * Float.BYTES + 6 * 10 * Float.BYTES;
        return len;
    }

    public TagPQDataCmnHh() {
        time = new RTC_Timer_MS();
        hharmRmsList29K = new float[6][35];
        hharmThdList29K = new float[6][35];
        hharmTotalRms29K = new float[6];
        hharmTotalThd29K = new float[6];
        hharmMaxRms29K = new float[6];
        hharmMaxThd29K = new float[6];
        hharmMaxFreq29K = new float[6];
        hharmRmsList2150K = new float[6][75];
        hharmThdList2150K = new float[6][75];
        hharmTotalRms2150K = new float[6];
        hharmTotalThd2150K = new float[6];
        hharmMaxRms2150K = new float[6];
        hharmMaxThd2150K = new float[6];
        hharmMaxFreq2150K = new float[6];
    }

    public boolean setStructBuf(byte[] bArray, int nHaveRead) {
        int nByteSize = bArray.length;
        //int size = getSize();
        if (nByteSize < getSize()){
            return false;
        }


        int iStep = nHaveRead;
        name = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Short.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getShort(); iStep += Short.BYTES;
        dataType = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Short.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getShort(); iStep += Short.BYTES;
        dataTag = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Integer.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getInt(); iStep += Integer.BYTES;
        time.setStructBuf(bArray, iStep);
        iStep += RTC_Timer_MS.GetSize();

        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 35; j++) {
                hharmRmsList29K[i][j] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
            }
        }
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 35; j++) {
                hharmThdList29K[i][j] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
            }
        }
        for (int i = 0; i < 6; i++) {
            hharmTotalRms29K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmTotalThd29K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmMaxRms29K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmMaxThd29K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmMaxFreq29K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 75; j++) {
                hharmRmsList2150K[i][j] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
            }
        }
        for (int i = 0; i < 6; i++) {
            for (int j = 0; j < 75; j++) {
                hharmThdList2150K[i][j] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
            }
        }
        for (int i = 0; i < 6; i++) {
            hharmTotalRms2150K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmTotalThd2150K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmMaxRms2150K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmMaxThd2150K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        for (int i = 0; i < 6; i++) {
            hharmMaxFreq2150K[i] = ByteBuffer.wrap(Arrays.copyOfRange(bArray, iStep, iStep + Float.BYTES)).order(ByteOrder.LITTLE_ENDIAN).getFloat(); iStep += Float.BYTES;
        }
        return true;
    }
}
