package org.ts.ddcs.DataTemplate;

import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.utils.GBConstants;

/*
 * created by swp on 2017/8/15
 * 2014 规约报文数据模板
 * 0x31
 * 均匀时段水文信息报
 */
@SuppressWarnings("all")
public class DataTemplateF31 extends DataTemplate {
    private byte[] serialNo;
    private byte[] sendPacketTime;
    private byte[] addrFlag;
    private byte[] dataAreaRtuCode;
    private byte[] siteKind;
    private byte[] collectTimeFlag;
    private byte[] collectTime;

    DataTemplateF31(){
        this.needCheckOutlierData=true;
    }

    @Override
    public String GetViewName() {
        return "均匀时段水文信息报";
    }


    @Override
    public byte[] SerialNo() {
        return this.serialNo;
    }

    @Override
    public byte[] SendPacketTime() {
        return this.sendPacketTime;
    }

    @Override
    public byte[] SiteKind() {
        return this.siteKind;
    }

    @Override
    public byte[] CollectTime() {
        return this.collectTime;
    }

    @Override
    public void Stream() {
        try {
            if (dataLen > 0 && dataLen == dataArea.length) {
                int count = 0;
                serialNo = BytesHelp.subBytes(dataArea, count, 2); //流水号
                count += 2;
                sendPacketTime = BytesHelp.subBytes(dataArea, count, 6); // 发报时间
                count += 6;
                addrFlag = BytesHelp.subBytes(dataArea, count, 2); //地址标识符
                count += 2;
                dataAreaRtuCode = BytesHelp.subBytes(dataArea, count, 5); //遥测站地址
                count += 5;
                siteKind = BytesHelp.subBytes(dataArea, count, 1);//遥测站分类码
                count += 1;
                collectTimeFlag = BytesHelp.subBytes(dataArea, count, 2); //采集时间
                count += 2;
                collectTime = BytesHelp.subBytes(dataArea, count, 5); //采集时间
                count += 5;

                if (dataArea.length - count > 0) {
                    byte[] contentView = BytesHelp.subBytes(dataArea, count, dataArea.length - count);
                    if (null != contentView && contentView.length > 0) {
                        DataItemTemplateLine line = DataTemplateManager.newInstance().createItemTemplateLine();
                        line.stream(contentView);
                        dataItem = line.MacthTemplate();
                    }
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
