package org.ts.ddcs.DataTemplate.DtuTemplate;



import org.ts.ddcs.DataItemTemplate.DataItemTemplateInterface;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.Tool.BytesHelp;

import java.util.LinkedList;


/**
 * created by swp on 2017/8/23
 */

public class DtuLinkDataTemplate extends DtuTemplate  {
    private String rtuCode;
    @Override
    public void Stream() {
        try {
            if (dataLen > 0) {
                rtuCode= new String(this.dataArea, "UTF-8");
            }
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }

    @Override
    public boolean Macth(byte[] data) {
        byte[] fc = BytesHelp.subBytes(data, 0, 1);
        if (this.fetureKey.equals(BytesHelp.byte2HexStr(fc))) {
            int count = 0;
            startFlag = BytesHelp.subBytes(data, count, 1);
            count += 1;
            funcCode = BytesHelp.subBytes(data, count, 1);
            count += 1;
            byte[] len = BytesHelp.subBytes(data, count, 1);
            dataLen = (int) len[0];
            count+=1;
            if (dataLen > 0) {
                dataArea = BytesHelp.subBytes(data, count, dataLen);
            }
            count += dataLen;
            crc = BytesHelp.subBytes(data, count, 2);
            count += 2;
            if (data.length == count) {
                this.macth = true;
            } else {
                LogHelper.info("*************************   macth error *********************");
            }
        }
        return this.macth;
    }

    @Override
    public LinkedList<DataItemTemplateInterface> matchDataItem(String tableName, String column) {
        return null;
    }

    @Override
    public LinkedList<DataItemTemplateInterface> matchDataItemByFeature(String feature) {
        return null;
    }
}
