package com.handset.serialportsensor.utils;

import android.util.Log;

import com.google.common.base.Splitter;
import com.handset.serialportlib.ByteUtils;

import java.util.Collections;

public class SplitUtils {
    private static final String logTag = "HANDSET-JE002-EX";

    public static Iterable<String> split(String raw) {
        try {
            if (raw.length() == 22) {
                return Splitter.fixedLength(22).split(raw);
            } else if (raw.length() == 28) {
                return Splitter.fixedLength(28).split(raw);
            } else if(raw.length() > 28){
                byte[] bytes = ByteUtils.hexStrToBytes(raw);
                int len = bytes[8] & 0xff;
                int resLen = 18 + len * 2 + 4;
                Log.i(logTag, "split len: " + len + ", resLen: " + resLen);
                return Splitter.fixedLength(resLen).split(raw);
            } else return Collections.emptyList();
        } catch (Exception e) {
            return Collections.emptyList();
        }
    }
}
