package  org.ts.ddcs.dataprocesser.jtDatagram;

import org.ts.ddcs.dataprocesser.DataProcesser;
import org.ts.ddcs.dataprocesser.DataProcesserInterface;
import org.ts.ddcs.dataStream.DataStreamAdapter;
import org.ts.ddcs.datatemplate.DataTemplateInterface;
import org.ts.ddcs.log.LogHelper;
import org.ts.ddcs.util.BytesUtil;

import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 0x0100
 * 设备注册
 */
public class DataProcessorJtAck extends DataProcesser implements DataProcesserInterface {

    @Override
    public void packetReadly(byte[] byteBuff, int pos, int length, DataStreamAdapter dataStreamAdapter, DataTemplateInterface template) {
        String logId = LogHelper.createLogId(dataStreamAdapter.getAdapterKey() + " " + this.getClass().getSimpleName());
        try {
            Date dt = new Date();
            SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMMddHHmmss");
            byte[] packetContext = template.datagramContext();
            byte[] rtuCodeBuff = template.rtuCode();
            String rtuCode = BytesUtil.byte2HexStr(rtuCodeBuff);
            LogHelper.info(logId + " " + " JT 808-功能码:0001 终端通用应答" + "-RTU:" + rtuCode);
            dataStreamAdapter.setCode(rtuCode);
        } catch (Exception e) {
            LogHelper.error(e);
        }
    }
}
