package org.well.well.core.util;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by test203 on 2019/5/23.
 */
public class MeterDecoderUtil {


    public static Map<String, String> decodeStr(String str) {
        Map<String, String> meterMap = new HashMap<String, String>();
        meterMap.put("temp",subString(str,"w01010-Rtd=",",w01010-Flag="));
        meterMap.put("PH",subString(str,"w01001-Rtd=",",w01001-Flag="));
        meterMap.put("conductivity",subString(str,"w01014-Rtd=", ",w01014-Flag="));
        meterMap.put("DO",subString(str,"w01009-Rtd=",",w01009-Flag="));
        meterMap.put("turbidity",subString(str,"w01012-Rtd=",",w01012-Flag="));
        meterMap.put("COD",subString(str,"w01018-Rtd=",",w01018-Flag="));
        meterMap.put("AN",subString(str,"w21003-Rtd=",",w21003-Flag="));
        meterMap.put("TP",subString(str,"w21011-Rtd=",",w21011-Flag="));
        meterMap.put("TN",subString(str,"w21001-Rtd=",",w21001-Flag="));
        meterMap.put("devCode",subString(str.substring(str.indexOf("MN=")),"MN=",";"));
        meterMap.put("DataTime",subString(str.substring(str.indexOf("DataTime=")),"DataTime=",";"));
        return meterMap;
    }


    public static String subString(String str, String strStart, String strEnd) {
        int strStartIndex = str.indexOf(strStart);
        int strEndIndex = str.indexOf(strEnd);
        return  (strStartIndex < 0||strEndIndex < 0)?"":
                str.substring(strStartIndex, strEndIndex).substring(strStart.length());
    }

}
