JLChen
2020-10-20 c9978ac37e3e9817ab07b25dbb499b28918403fd
hdl_core/src/main/java/com/hdl/sdk/hdl_core/HDLDeviceManger/Core/HDLCommand.java
@@ -16,6 +16,7 @@
import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.GeothermalBackInfo;
import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.Parser.GeothermalParser;
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLight.LightCtrlBackInfo;
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLight.RGBBackInfo;
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLogic.LogicCtrlBackInfo;
import com.hdl.sdk.hdl_core.HDLAppliances.HDLSecurity.Parser.SecurityParser;
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo;
@@ -29,6 +30,7 @@
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.GeothermalFeedBackEvent;
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LightFeedBackEvent;
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent;
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LightRGBCtrlBackEvent;
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.SecurityArmingFeedBackEvent;
import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
import com.hdl.sdk.hdl_core.Util.NetUtil.NetWorkUtil;
@@ -60,6 +62,8 @@
    private static Timer securityCtrlFailTimer = null;//安防模块操作失败Timer
    private static Timer commonSwitchCtrlFailTimer = null;//通用开关失败Timer
    private static Timer lightRgbCtrlFailTimer = null;//RGB失败Timer
    private static Timer lightCCTCtrlFailTimer = null;//CCT失败Timer
    /**
     * 初始化
@@ -73,6 +77,7 @@
    /**
     * 开启bus模式
     * 启用6000端口
     *
     * @param context
     */
    public static void startHomeMode(Context context) {
@@ -86,6 +91,7 @@
    /**
     * 开启RCU模式
     * 启用6008端口
     *
     * @param context
     * @param newRcuIp RCU的IP地址
     */
@@ -107,15 +113,17 @@
    /**
     * 获取本地广播IP
     *
     * @return
     */
    public static String getLocalBroadCastIp(){
    public static String getLocalBroadCastIp() {
        return NetWorkUtil.getLocalBroadCast();
    }
    /**
     * 是否开启SDK日志打印
     * 2019-07-10新增
     *
     * @param bOpen
     */
    public static void setHDLLogOpen(boolean bOpen) {
@@ -133,7 +141,6 @@
//    private static void devicesSearch() {
//        HandleSearch.getRcuIp();
//    }
    /**
@@ -762,8 +769,8 @@
                            && info.getChannelNum() == infos.get(j).getChannelNum()
                    ) {
                        //这里应该是要修复的,暂时未找到。
                         //20190712解决强制转换int类型闪退
                        int  state = HDLUtlis.getIntegerByObject(infos.get(j).getCurStateObject());
                        //20190712解决强制转换int类型闪退
                        int state = HDLUtlis.getIntegerByObject(infos.get(j).getCurStateObject());
                        switch (state) {
                            case -1:
                                curState = 0;
@@ -1139,6 +1146,7 @@
    /**
     * 获取通用开关状态
     *
     * @param info
     */
    public static void getCommonSwitchStateFromNetwork(final AppliancesInfo info) {
@@ -1159,6 +1167,7 @@
    /**
     * 获取安防模块状态
     *
     * @param info
     */
    public static void getSecurityStateFromNetwork(final AppliancesInfo info) {
@@ -1180,6 +1189,7 @@
    /**
     * 安防模块 布防设置
     * 2020-06-23
     *
     * @param info
     */
    public static void securityArmingCtrl(final AppliancesInfo info, int state) {
@@ -1197,7 +1207,7 @@
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        EventBus.getDefault().post(new SecurityArmingFeedBackEvent(info,0, false));
                        EventBus.getDefault().post(new SecurityArmingFeedBackEvent(info, 0, false));
                    }
                }
            }, 5000);
@@ -1231,6 +1241,7 @@
    /**
     * 获取干接点传感器模块状态
     *
     * @param info
     */
    public static void getDryContactSensorStateFromNetwork(final AppliancesInfo info) {
@@ -1281,4 +1292,130 @@
        }
    }
    /**************************************2020-10-20 新增***************************************/
    /**
     * 控制RGB
     *
     * @param info
     */
    public static void lightRGBCtrl(final AppliancesInfo info, int brightness, int rStatus, int gStatus, int bStatus) {
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (info.getBigType() == Configuration.LIGTH_BIG_TYPE) {
            if (lightRgbCtrlFailTimer != null) {
                lightRgbCtrlFailTimer.cancel();
                lightRgbCtrlFailTimer = null;
            }
            byte[] bytes = new byte[]{
                    (byte) info.getChannelNum(),
                    (byte) brightness,
                    (byte) 254,
                    0,
                    0,
                    3,
                    (byte) rStatus,
                    (byte) gStatus,
                    (byte) bStatus,
                    0,
                    0
            };
            addSendData(info, bytes, Configuration.CONTROL);
            lightRgbCtrlFailTimer = new Timer();
            lightRgbCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        HDLLog.info("RGB控制失败");
                        RGBBackInfo mRGBBackInfo = new RGBBackInfo();
                        mRGBBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new LightRGBCtrlBackEvent(mRGBBackInfo, false));
                    }
                }
            }, mRequestTimeout);
        } else {
            HDLLog.info("djlCtrl: 设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
    /**
     * 获取CCT 或者RGB灯状态
     *
     * @param info
     */
    public static void getRGBCCTStateFromNetwork(final AppliancesInfo info) {
        if (info == null) {
            return;
        }
        HDLDeviceManager.isGetDeviceStateSuccess = false;
        switch (info.getDeviceType()) {
            case HDLApConfig.TYPE_LIGHT_RGB:
            case HDLApConfig.TYPE_LIGHT_CCT:
                //发送CCT RGB状态数据
                addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
                break;
            default:
                HDLLog.info("不是安防模块");
                break;
        }
    }
    /**
     * 控制CCT
     *
     * @param info
     */
    public static void lightCCTCtrl(final AppliancesInfo info, int brightness, int cctStatus) {
        HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
        if (info.getBigType() == Configuration.LIGTH_BIG_TYPE) {
            if (lightCCTCtrlFailTimer != null) {
                lightCCTCtrlFailTimer.cancel();
                lightCCTCtrlFailTimer = null;
            }
            byte[] bytes = new byte[]{
                    (byte) info.getChannelNum(),
                    (byte) brightness,
                    (byte) 254,
                    0,
                    0,
                    2,
                    (byte) (cctStatus / 256),
                    (byte) (cctStatus % 256),
                    0,
                    0,
                    0
            };
            addSendData(info, bytes, Configuration.CONTROL);
            lightCCTCtrlFailTimer = new Timer();
            lightCCTCtrlFailTimer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
                        HDLLog.info("RGB控制失败");
                        RGBBackInfo mRGBBackInfo = new RGBBackInfo();
                        mRGBBackInfo.setAppliancesInfo(info);
                        EventBus.getDefault().post(new LightRGBCtrlBackEvent(mRGBBackInfo, false));
                    }
                }
            }, mRequestTimeout);
        } else {
            HDLLog.info("djlCtrl: 设备控制不在范围内"
                    + " LittleType = " + info.getLittleType()
                    + " BigType = " + info.getBigType()
            );
        }
    }
}