package org.ts.ddcs.DataTemplate;

import com.alibaba.fastjson.JSONObject;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;

import java.util.LinkedList;
import java.util.List;

/**
 * 恢复出厂设置
 */
@SuppressWarnings("all")
public class DataTemplateF48 extends  DataTemplate {
    private String dataInfo;
    private byte[] serialNo;
    private byte[] sendPacketTime;
    private byte[] addrFlag;
    private byte[] dataAreaRtuCode;

    @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;
                this.addrFlag = BytesHelp.subBytes(this.dataArea, count, 2); //地址标识符
                count += 2;
                this.dataAreaRtuCode = BytesHelp.subBytes(this.dataArea, count, 5); //遥测站地址
                count += 5;


                JSONObject data = new JSONObject();
                data.put("func", "48");
                List<JSONObject> items = new LinkedList<>();
                JSONObject item = new JSONObject();
                item.put("name", "恢复出厂设置");
                item.put("value", "完成");
                items.add(item);
                data.put("data", items);
                this.dataInfo = data.toJSONString();
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }

    @Override
    public String getDataInfo() {
        return dataInfo;
    }
}
