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;

/**
 * 0xF3
 * RTU 重启
 */
@SuppressWarnings("all")
public class DataTemplateCF3 extends DataTemplate {
    private byte[] serialNo;
    private byte[] sendPacketTime;
    private String dataInfo;

    @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;

                JSONObject data = new JSONObject();
                data.put("func", "F3");
                List<JSONObject> items = new LinkedList<>();
                JSONObject item = new JSONObject();
                item.put("name", "RTU升级完成");
                item.put("value", "已重启");
                items.add(item);
                data.put("data", items);
                this.dataInfo = data.toJSONString();

                if (count != this.dataArea.length) {
                    LogHelper.info("******************* F3 DATA ERROR******************* ");
                }
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }

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