JLChen
2020-03-05 bdec7373b358239521703995c5220e995dee289c
hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLDeviceManager.java
@@ -66,30 +66,19 @@
    public static List<String> rcuIpList = new ArrayList<>();//统计Rcu ip地址列表
    public static List<DevicesData> devicesDataList = new ArrayList<>();//统计搜索列表
    public static List<DevicesData> realDevicesDataList = new ArrayList<>();//统计搜索列表
    private static Context viewContext;
    public static List<ListRemarks> listRemarks = new ArrayList<>();
    public static List<RcuLight> rcuLightList = new ArrayList<>();
    public static List<RcuCurtain> rcuCurtainList = new ArrayList<>();
    public static boolean isLogicCtrl = false;
    public static ConcurrentHashMap<String, Boolean> ctrlSuccessStateHashMap = new ConcurrentHashMap<>();//2019-8-2
//    public static byte[] air1Info = null;
//    public static byte[] air2Info = null;
//    public static byte[] air3Info = null;
//    public static byte[] air4Info = null;
    //        air4Info[开关状态,模式,设置温度,风速,当前温度,是否摆风 ];
    public static boolean isGetRcuIpSuccess = false;
    public static boolean isGetDeviceStateSuccess = false; //判断获取设备状态是否控制成功
//    public static boolean isLightCtrlSuccess = false; //判断灯光是否控制成功
//    public static boolean isCurtainCtrlSuccess = false; //判断窗帘是否控制成功
//    public static boolean isACCtrlSuccess = false; //判断空调是否控制成功
//    public static boolean isSceneCtrlSuccess = false; //判断场景是否控制成功
//    public static boolean isFreshAirCtrlSuccess = false; //判断新风系统是否控制成功
//    public static boolean isGeothermalCtrlSuccess = false; //判断地热模块是否控制成功
    //是否允许被简易编程搜索部分
    private static boolean isAllowEasyProgrammingSearch = false;//是否允许被简易编程搜索
    private static int SDKLocalBigClass = 9; //SDK 当前配置模拟设备的大类,默认为音乐、背景音乐功能
    private static int SDKLocalSmallClass = 1; //SDK 当前配置模拟设备的小类,第三方背景音乐模块
    private static String SDKLocalRemark = "特殊设备"; //SDK 当前配置模拟设备备注
    /**
@@ -100,12 +89,10 @@
    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);
        SDKLocalRemark = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK);
//        HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES;
//        HDLUdpCore.initMulticastSocket6000();
    }
@@ -122,6 +109,32 @@
        HDLUdpCore.closeSocket6000();
    }
    /**
     * 配置简易编程搜索返回的默认参数
     * @param mSDKLocalBigClass
     * @param mSDKLocalSmallClass
     * @param mSDKLocalRemark
     */
    public static void setEasyProgrammingSearchLocalData(int mSDKLocalBigClass, int mSDKLocalSmallClass, String mSDKLocalRemark){
        SDKLocalBigClass = mSDKLocalBigClass;
        SDKLocalSmallClass = mSDKLocalSmallClass;
        if(mSDKLocalRemark != null){
            SDKLocalRemark = mSDKLocalRemark;
        }
        isAllowEasyProgrammingSearch = true;
    }
    public static void setEasyProgrammingSearchLocalData(int mSDKLocalBigClass, int mSDKLocalSmallClass){
        setEasyProgrammingSearchLocalData(mSDKLocalBigClass, mSDKLocalSmallClass,null);
    }
    /**
     * 设置是否允许被简易编程搜索
     * @param isAllow
     */
    public static void setIsAllowEasyProgrammingSearch(boolean isAllow){
        isAllowEasyProgrammingSearch = isAllow;
    }
    /**
     * 处理CommandData并返回搜索或控制的有用信息
@@ -147,6 +160,10 @@
                        handleSearchData(getDatas);
                    }
                }
                break;
            //简易编程设备搜索操作码、设备读取操作码 回复
            case Configuration.DEVICES_SEARCH_COMMAND:
                handleDeviceSearchBackData(getDatas);
                break;
//          控制设备
            case Configuration.LIGHT_CTRL_BACK_COMMAND:
@@ -279,6 +296,64 @@
    /**
     * 回复简易编程搜索非网络设备,返回当前SDK信息
     *
     * @param getDatas
     */
    private static void sendDeviceSearchBackInfo(UdpDataBean getDatas) {
        byte[]  remarkByte = StringUtil.stringtoBytes(SDKLocalRemark);
        byte[] addBytes = new byte[25];
        addBytes[0] = getDatas.addBytes[0];
        addBytes[1] = getDatas.addBytes[1];
        System.arraycopy(remarkByte, 0, addBytes, 2, remarkByte.length > 20 ? 20 : remarkByte.length);
        addBytes[22] = (byte) SDKLocalBigClass;
        addBytes[23] = (byte) SDKLocalSmallClass;
        addBytes[24] = (byte) 1;
        HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_BACK_COMMAND,
                getDatas.sourceSubnetID,
                getDatas.sourceDeviceID,
                addBytes,
                getDatas.port, getDatas.ipAddress);
//        HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_BACK_COMMAND,
//                getDatas.sourceSubnetID,
//                getDatas.sourceDeviceID,
//                addBytes,
//                getDatas.port,  NetWorkUtil.getLocalBroadCast());
    }
    /**
     * 收到简易编程搜索非网络设备
     * @param getDatas
     */
    public static void handleDeviceSearchBackData(UdpDataBean getDatas){
        //判断是否允许被简易编程搜索和回复
        if(!isAllowEasyProgrammingSearch) return;
        if (getDatas.addBytes.length == 2) {
            sendDeviceSearchBackInfo(getDatas);
        } else {
            for (int i = 2, len = getDatas.addBytes.length; i < len; i++) {
                if (i % 2 == 0) {
                    if ((getDatas.addBytes[i] & 0xFF) == Crc.localSubnetID
                            && (getDatas.addBytes[i + 1] & 0xFF) ==  Crc.localDeviceID
                    ) {
                        sendDeviceSearchBackInfo(getDatas);
                        break;
                    }
                }
            }
        }
    }
    /**
     * 处理RCU搜索数据
     *
     * @param getDatas
@@ -342,9 +417,9 @@
        }
        byte[] remarkByte;
        String remarkString = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK);
//        String remarkString = (String) SPUtils.getParam(viewContext, SPUtils.KEY_LOCAL_REMARK, SPUtils.DEFAULT_REMARK);
        remarkByte = StringUtil.stringtoBytes(remarkString);
        remarkByte = StringUtil.stringtoBytes(SDKLocalRemark);
        byte[] addBytes = new byte[53];
        addBytes[0] = getDatas.addBytes[0];
@@ -2540,4 +2615,6 @@
    }
}