// Path: spring-server/src/main/java/me/pjq/Utils/Log.java
// public class Log {
//     static String dateFormat = "yyyy-MM-dd hh:mm:ss";
//     static SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
//     static boolean showLog = true;
// 
//     public static void log(String tag, String msg) {
//         if (showLog) {
//             String source = null;
//             try {
//                 StackTraceElement st = Thread.currentThread().getStackTrace()[2];
//                 source = "[" + st.getFileName() + "] - " + st.getMethodName() + "("
//                         + st.getLineNumber() + ")";
//             } catch (Exception e) {
//             }
// 
//             System.out.println(fm.format(new Date()) + " - " + source + ":" + msg);
//         }
//     }
// }
// 
// Path: spring-server/src/main/java/me/pjq/model/Config.java
// public class Config {
//     public String deviceName;
//     public String productKey;
//     public String secret;
//     public String pubTopic;
//     public String subTopic;
// 
//     public String accessKeyId;
//     public String accessKeySecret;
//     public String phone;
//     public String signName;
//     public String templateCode;
//     //10 seconds, interval for SensorStatus update.
//     public long SENSOR_STATUS_UPDATE_INTERVAL;
//     // duration for auto turn off the power via relay control
//     public long RELAY_OFF_INTERVAL;
// 
//     public Config(String deviceName, String productKey, String secret) {
//         this.deviceName = deviceName;
//         this.productKey = productKey;
//         this.secret = secret;
//         //用于测试的topic
//         pubTopic = "/" + productKey + "/" + deviceName + "/update";
//         subTopic = "/" + productKey + "/" + deviceName + "/get";
//     }
// 
//     public static Config getConfigRpiCarHome() {
//         String deviceName = "RpiCarHome";
//         String productKey = "tKB3pmbLvnA";
//         String secret = "fT9ryVgfucZNs2g0VZkj8kzV3eNjY55E";
// 
//         return new Config(deviceName, productKey, secret);
//     }
// 
//     public static Config getConfigRpiCarClient() {
//         String deviceName = "RpiCarClient";
//         String productKey = "tKB3pmbLvnA";
//         String secret = "w7TT5kvx1xdzfVogH7RfUUto4kWoSCq4";
// 
//         return new Config(deviceName, productKey, secret);
//     }
// }


import me.pjq.Utils.Log;
import me.pjq.model.Config;
import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;
package me.pjq;




public enum Constants {
    INSTANCE;
    private static final String TAG = "Constants";
//    public static String deviceName = "RpiCarHome";
//    public static String productKey = "tKB3pmbLvnA";
//    public static String secret = "fT9ryVgfucZNs2g0VZkj8kzV3eNjY55E";

//    public static String deviceName = "RpiCarClient";
//    public static String productKey = "tKB3pmbLvnA";
//    public static String secret = "w7TT5kvx1xdzfVogH7RfUUto4kWoSCq4";

//    public static String aK1="LTAICKNMlWB";
//    public static String aK2="xm7GR";
//    public static String accessKeyId = aK1+aK2;
//    public static String accessKeySecret = "cMgi0pjAewppBdpESDlI3CXZpAKFwc";
//    public static String phone = "18621517768";
//    public static String signName = "树霉派IoT";
//    public static String templateCode = "SMS_110310049";

    //10 seconds, interval for SensorStatus update.
//    public static long SENSOR_STATUS_UPDATE_INTERVAL = 10000;
    // duration for auto turn off the power via relay control
//    public static long RELAY_OFF_INTERVAL = 30 * 1000;

//    public static String pubTopic = "/" + productKey + "/" + deviceName + "/update";
    //用于测试的topic
//    public static String subTopic = "/" + productKey + "/" + deviceName + "/get";

    private static final String CONFIG_FILE = "config.properties";
    private static final String CONFIG_FILE_DEFAULT = "./src/main/resources/config.properties";
    private Config config;

    public Config getConfig() {
        return config;
    }

    private Constants() {
        try {
            config = getAllProperties();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    //读取Properties的全部信息
    public static HashMap<String, String> getAllProperties(String filePath) throws IOException {
        Properties pps = new Properties();
        InputStream in = new BufferedInputStream(new FileInputStream(filePath));
        pps.load(in);
        Enumeration en = pps.propertyNames(); //得到配置文件的名字
        HashMap<String, String> map = new HashMap<>();

        while (en.hasMoreElements()) {
            String strKey = (String) en.nextElement();
            String strValue = pps.getProperty(strKey);
            strValue = new String(strValue.getBytes("ISO-8859-1"), "utf-8");
// Path: spring-server/src/main/java/me/pjq/Utils/Log.java
// public class Log {
//     static String dateFormat = "yyyy-MM-dd hh:mm:ss";
//     static SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS");
//     static boolean showLog = true;
// 
//     public static void log(String tag, String msg) {
//         if (showLog) {
//             String source = null;
//             try {
//                 StackTraceElement st = Thread.currentThread().getStackTrace()[2];
//                 source = "[" + st.getFileName() + "] - " + st.getMethodName() + "("
//                         + st.getLineNumber() + ")";
//             } catch (Exception e) {
//             }
// 
//             System.out.println(fm.format(new Date()) + " - " + source + ":" + msg);
//         }
//     }
// }
// 
// Path: spring-server/src/main/java/me/pjq/model/Config.java
// public class Config {
//     public String deviceName;
//     public String productKey;
//     public String secret;
//     public String pubTopic;
//     public String subTopic;
// 
//     public String accessKeyId;
//     public String accessKeySecret;
//     public String phone;
//     public String signName;
//     public String templateCode;
//     //10 seconds, interval for SensorStatus update.
//     public long SENSOR_STATUS_UPDATE_INTERVAL;
//     // duration for auto turn off the power via relay control
//     public long RELAY_OFF_INTERVAL;
// 
//     public Config(String deviceName, String productKey, String secret) {
//         this.deviceName = deviceName;
//         this.productKey = productKey;
//         this.secret = secret;
//         //用于测试的topic
//         pubTopic = "/" + productKey + "/" + deviceName + "/update";
//         subTopic = "/" + productKey + "/" + deviceName + "/get";
//     }
// 
//     public static Config getConfigRpiCarHome() {
//         String deviceName = "RpiCarHome";
//         String productKey = "tKB3pmbLvnA";
//         String secret = "fT9ryVgfucZNs2g0VZkj8kzV3eNjY55E";
// 
//         return new Config(deviceName, productKey, secret);
//     }
// 
//     public static Config getConfigRpiCarClient() {
//         String deviceName = "RpiCarClient";
//         String productKey = "tKB3pmbLvnA";
//         String secret = "w7TT5kvx1xdzfVogH7RfUUto4kWoSCq4";
// 
//         return new Config(deviceName, productKey, secret);
//     }
// }


// Path: spring-server/src/main/java/me/pjq/Constants.java
import me.pjq.Utils.Log;
import me.pjq.model.Config;
import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Properties;

package me.pjq;




public enum Constants {
    INSTANCE;
    private static final String TAG = "Constants";
//    public static String deviceName = "RpiCarHome";
//    public static String productKey = "tKB3pmbLvnA";
//    public static String secret = "fT9ryVgfucZNs2g0VZkj8kzV3eNjY55E";

//    public static String deviceName = "RpiCarClient";
//    public static String productKey = "tKB3pmbLvnA";
//    public static String secret = "w7TT5kvx1xdzfVogH7RfUUto4kWoSCq4";

//    public static String aK1="LTAICKNMlWB";
//    public static String aK2="xm7GR";
//    public static String accessKeyId = aK1+aK2;
//    public static String accessKeySecret = "cMgi0pjAewppBdpESDlI3CXZpAKFwc";
//    public static String phone = "18621517768";
//    public static String signName = "树霉派IoT";
//    public static String templateCode = "SMS_110310049";

    //10 seconds, interval for SensorStatus update.
//    public static long SENSOR_STATUS_UPDATE_INTERVAL = 10000;
    // duration for auto turn off the power via relay control
//    public static long RELAY_OFF_INTERVAL = 30 * 1000;

//    public static String pubTopic = "/" + productKey + "/" + deviceName + "/update";
    //用于测试的topic
//    public static String subTopic = "/" + productKey + "/" + deviceName + "/get";

    private static final String CONFIG_FILE = "config.properties";
    private static final String CONFIG_FILE_DEFAULT = "./src/main/resources/config.properties";
    private Config config;

    public Config getConfig() {
        return config;
    }

    private Constants() {
        try {
            config = getAllProperties();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    //读取Properties的全部信息
    public static HashMap<String, String> getAllProperties(String filePath) throws IOException {
        Properties pps = new Properties();
        InputStream in = new BufferedInputStream(new FileInputStream(filePath));
        pps.load(in);
        Enumeration en = pps.propertyNames(); //得到配置文件的名字
        HashMap<String, String> map = new HashMap<>();

        while (en.hasMoreElements()) {
            String strKey = (String) en.nextElement();
            String strValue = pps.getProperty(strKey);
            strValue = new String(strValue.getBytes("ISO-8859-1"), "utf-8");
            Log.log(TAG, strKey + "=" + strValue);