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

/**
 * 功能码 F5
 * RTU自身状态上报
 */
@SuppressWarnings("all")
public class DataTemplateCF5 extends DataTemplate {
    private byte[] serialNo;
    private byte[] sendPacketTime;


    @Override
    public String GetViewName() {
        return "状态报";
    }


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

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

    @Override
    public void Stream() {
        try {
            if (dataLen > 0) {
                int count = 0;
                this.serialNo = BytesHelp.subBytes(this.dataArea, count, 2); //流水号
                count += 2;
                this.sendPacketTime = BytesHelp.subBytes(this.dataArea, count, 6); // 发报时间
                count += 6;
                if (this.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);
                        this.dataItem = line.MacthTemplate();
                    }
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
