package org.ts.ddcs.DataItemTemplate.DataItemTemplateSzy2012;

import org.ts.ddcs.DataItemTemplate.DataItemTemplate;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Tool.StringUtil;

/**
 * AFN C0   C 03
 * 自报 流量参数
 */
@SuppressWarnings("all")
public class DataItemTemplateC0_FlowRate extends DataItemTemplate {

    @Override
    public byte[] Stream(byte[] data) {
        byte[] remain = data;
        if (remain.length < 5) {
            return remain;
        }
        int count = 0;
        this.valueBuff = BytesHelp.subBytes(data, 0, 5);
        count += 5;
        if (!BytesHelp.byte2HexStr(this.valueBuff).equals("FFFFFFFFFF") && !BytesHelp.byte2HexStr(this.valueBuff).equals("AAAAAAAAAA")) {
            byte tmp = this.valueBuff[0];
            this.valueBuff[0] = this.valueBuff[4];
            this.valueBuff[4] = tmp;
            tmp = this.valueBuff[1];
            this.valueBuff[1] = this.valueBuff[3];
            this.valueBuff[3] = tmp;
            String value = BytesHelp.byte2HexStr(this.valueBuff);
            String flag = value.substring(0, 1);
            String v1 = value.substring(1, 2);
            String v2 = value.substring(2, 3);
            String v3 = value.substring(3, 4);
            String v4 = value.substring(4, 5);
            String v5 = value.substring(5, 6);
            String v6 = value.substring(6, 7);
            String v7 = value.substring(7, 8);
            String v8 = value.substring(8, 9);
            String v9 = value.substring(9, 10);
            value = "";
            if (flag.equals("F")) {
                value += "-";
            }
            value += StringUtil.getPrettyNumber(v1 + v2 + v3 + v4 + v5 + v6 + "." + v7 + v8 + v9);
            this.varcharValue = value;
        }
        if (remain.length - count > 0) {
            remain = BytesHelp.subBytes(remain, count, remain.length - count);
        } else {
            remain = new byte[0];
        }
        this.macth = true;
        return remain;
    }

    @Override
    public boolean OutlierData() {
        if (null != this.valueBuff && this.valueBuff.length > 0) {
            String hexValue = BytesHelp.byte2HexStr(this.valueBuff);
            if (hexValue.equals("FFFFFFFFFF") || hexValue.equals("AAAAAAAAAA")) {
                return true;
            }
        }
        return false;
    }

}
