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 DataTemplateSzyCF5 extends DataTemplateSzy2012 {

    private byte[] sendPacketTime;


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


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

    @Override
    public void Stream() {
        try {
            if (this.dataArea != null && this.dataArea.length > 0) {
                int count = 0;
//                this.serialNo = BytesHelp.subBytes(this.dataArea, count, 2); //流水号
//                count += 2;
                this.sendPacketTime = BytesHelp.subBytes(this.dataArea, count, 6); // 发报时间
                byte tmp=this.sendPacketTime[5];
                this.sendPacketTime[5]=this.sendPacketTime[0];
                this.sendPacketTime[0]=tmp;
                tmp=this.sendPacketTime[4];
                this.sendPacketTime[4]=this.sendPacketTime[1];
                this.sendPacketTime[1]=tmp;
                tmp=this.sendPacketTime[3];
                this.sendPacketTime[3]=this.sendPacketTime[2];
                this.sendPacketTime[2]=tmp;
                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(GBConstants.AGREEMENT_KIND_SZY);
                        line.stream(contentView);
                        this.dataItem = line.MacthTemplate();
                    }
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
