package org.ts.ddcs.DataItemTemplate.DataItemTemplateSzy2012;

import org.ts.ddcs.DataItemTemplate.DataItemTemplate;

import org.ts.ddcs.Entity.WqRiverEntity;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Tool.StringUtil;


/**
 * AFN C0   C 04
 * 自报 流速参数
 */
@SuppressWarnings("all")
public class DataItemTemplateC0_FlowSpeed extends DataItemTemplate {

    @Override
    public byte[] Stream(byte[] data) {
        byte[] remain = data;
        if (remain.length < 3) {
            return remain;
        }
        int count = 0;
        this.valueBuff = BytesHelp.subBytes(data, 0, 3);
        count += 3;
        byte tmp = this.valueBuff[0];
        this.valueBuff[0] = this.valueBuff[2];
        this.valueBuff[2] = tmp;
        String value = BytesHelp.byte2HexStr(this.valueBuff);
        if (!value.equals("FFFFFF")) {
            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);
            value = "";
            if (flag.equals("F")) {
                value += "-";
            }
            value += StringUtil.getPrettyNumber(v1 + v2 + "." + v3 + v4 + v5);
            this.varcharValue = value;
        }
        if (data.length - count > 0) {
            remain = BytesHelp.subBytes(remain, count, data.length - count);
        } else {
            remain = new byte[0];
        }
        this.macth = true;
        return remain;
    }

    @Override
    public void SetEntity(Object entity) {
        WqRiverEntity wqRiverEntity = (WqRiverEntity) entity;
        wqRiverEntity.setSPEED(this.varcharValue);
    }

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

}
