package org.ts.ddcs.DataItemTemplate;

import org.ts.ddcs.Tool.BytesHelp;
import org.ts.ddcs.Tool.StringUtil;

import java.math.BigDecimal;

/**
 * ff33
 * 流量计4，1小时内5分钟时段流量
 */
public class DataItemTemplateEXT_33 extends DataItemTemplate {
    @Override
    public byte[] Stream(byte[] data) {
        byte[] remain = data;
        if (this.macth) {
            return remain;
        }
        int count = 0;
        String flag = BytesHelp.byte2HexStr(remain, count, 2);
        count += 2;
        if (flag.equals(this.feture)) {
            byte[] len = BytesHelp.subBytes(remain, count, 1);
            count += 1;
            int dataTotalLen = len[0] >> 3;
            int decimalLen = len[0] & 7;
            byte[] buff = BytesHelp.subBytes(remain, count, dataTotalLen);
            String hexStr = BytesHelp.byte2HexStr(buff);
            for (int i = 0; i < 12; i++) {
                String v = hexStr.substring(i * 10, (i + 1) * 10);
                StringBuffer dataStr = new StringBuffer(v);
                dataStr.insert(6, ".");
                String value = StringUtil.getPrettyNumber(dataStr.toString());
                this.bigDecimalValue = new BigDecimal(value);
            }
            count += dataTotalLen;
            remain = BytesHelp.subBytes(remain, count, remain.length - count);
            this.macth = true;
        }
        return remain;
    }
}
