JLChen
2019-11-26 d6d95564b016c281bfa2e8c2454db8d71083e858
hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java
@@ -4,6 +4,9 @@
import android.content.Intent;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.hdl.sdk.hdl_core.Config.Configuration;
import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig;
import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.AirCtrlBackInfo;
@@ -95,12 +98,16 @@
    public static void init(Context context) {
        viewContext = context;
//        HDLUdpCore.initMulticastSocket();
        HandleSearch.rcuIp = (String) SPUtils.getParam(context, SPUtils.KEY_RCU_IP_, "");
        Crc.localSubnetID = (int) SPUtils.getParam(context, SPUtils.KEY_SUB_ID_, 254);
        Crc.localDeviceID = (int) SPUtils.getParam(context, SPUtils.KEY_DEVICE_ID, 80);
//        HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES;
//        HDLUdpCore.initMulticastSocket6000();
    }
    /**
@@ -213,7 +220,7 @@
                        SPUtils.setParam(viewContext, SPUtils.KEY_HDL_RCU_IP, getDatas.ipAddress);
                    }
                    handleSearchData(getDatas);
                    HandleSearch.deviceListCallBack();//手动添加设备成功立刻返回
                    HandleSearch.OnDeviceListGetSuccessCallBack();//手动添加设备成功立刻返回
                    HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_DEVICE_BACK_COMMAND,
                            Crc.localSubnetID,
                            Crc.localDeviceID,
@@ -230,7 +237,7 @@
                break;
            case Configuration.MANUAL_ADD_REMARK_COMMAND:
                handleRemarkCurStateData(getDatas);
                HandleSearch.deviceListCallBack();//手动添加备注成功立刻返回
                HandleSearch.OnDeviceListGetSuccessCallBack();//手动添加备注成功立刻返回
                HDLCommand.cusSendCommand(Configuration.MANUAL_ADD_REMARK_BACK_COMMAND,
                        Crc.localSubnetID,
                        Crc.localDeviceID,
@@ -839,7 +846,7 @@
                                setDeviceCtrlSuccessStateWithInfo(infos.get(appIndex), true);
                                for (int oldAirInedx = 0; oldAirInedx < oldAirInfo.length; oldAirInedx++) {
                                    if (oldAirInedx == 0) {
//                                        if (oldAirInfo[0] != newAirInfo[8]) {//2019 去掉相同开关状态判断,解决开状态下,调用开命令状态下,不停重发问题
                                        if (oldAirInfo[0] != newAirInfo[8]) {//2019 去掉相同开关状态判断,解决开状态下,调用开命令状态下,不停重发问题
                                            oldAirInfo[0] = newAirInfo[8];
                                            curAirInfo = new byte[]{AirCtrlParser.airSwich, newAirInfo[8]};
                                            if (curAirInfo.length > 1) {
@@ -853,7 +860,7 @@
                                                EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, true));
                                            }
//                                        }
                                        }
                                    } else if (oldAirInedx == 1) {
//                        int mode = ((newAirInfo[4] & 0xf0) >> 4);
                                        int mode = newAirInfo[9] & 0xff;
@@ -2413,4 +2420,78 @@
        if(success == null) success = false;
        return success;
    }
    /**
     * 保存设备数据列表
     * 根据需要,实时保存当前数据
     * 2019-10-14
     * @return boolean
     */
    public static boolean saveDevicesDataList() {
        try {
            Gson gson = new Gson();
            String jsonStr = gson.toJson(devicesDataList); //将List转换成Json
//            HDLLog.info("saveDevicesDataList:  \n" + jsonStr);
            SPUtils.setParam(viewContext, SPUtils.KEY_DEVICE_DATA_LIST, jsonStr);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
    /**
     * 加载本地设备数据列表
     *
     * @return devicesDataList
     */
    public static List<DevicesData> getLocalDevicesDataList() {
        try {
            String getJsonStr = SPUtils.getParam(viewContext, SPUtils.KEY_DEVICE_DATA_LIST, "").toString();
//            HDLLog.I("getJsonStr:  \n" + getJsonStr);
            if (!TextUtils.isEmpty(getJsonStr))  //防空判断
            {
                Gson gson = new Gson();
                devicesDataList = gson.fromJson(getJsonStr, new TypeToken<List<DevicesData>>() {
                }.getType()); //将json字符串转换成List集合
            }
        } catch (JsonSyntaxException e) {
            e.printStackTrace();
        }
        if (devicesDataList == null) devicesDataList = new ArrayList<>();
        List<DevicesData> devicesDataList2 = devicesDataList;
        setRemarkList();//加载备注list
        if (!TextUtils.isEmpty(HandleSearch.rcuIp)) {//判断之前是否为RUC模式
            HandleSearch.curSearchMode = HandleSearch.GET_RCU_DEVICES;
            HDLUdpCore.closeSocket6000();
            HDLUdpCore.init6008();
        }else {
            HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES;
            HDLUdpCore.closeSocket6008();
            HDLUdpCore.init6000();
        }
        return devicesDataList2;
    }
    private static void setRemarkList(){
        listRemarks.clear();
        for (int j = 0; j < devicesDataList.size(); j++) {
            if (devicesDataList.get(j).getAppliancesInfoList().get(0).getBigType() != Configuration.AUDIO_BIG_TYPE) {
                for (int i = 0, len = devicesDataList.get(j).getAppliancesInfoList().size(); i < len; i++) {
                    ListRemarks listRemarksTemp = new ListRemarks();
                    listRemarksTemp.setCallBack(false);
                    listRemarksTemp.setAppliancesInfo(devicesDataList.get(j).getAppliancesInfoList().get(i));
                    listRemarks.add(listRemarksTemp);
                }
            }
        }
    }
}