package com.hdl.sdk.ttl.HDLDeviceManger.Core; import android.content.Context; import com.hdl.sdk.ttl.Config.Configuration; import com.hdl.sdk.ttl.Config.MCUConstants; import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig; import com.hdl.sdk.ttl.HDLAppliances.HDLAirCondition.AirCtrlBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLAirCondition.Parser.AirCtrlParser; import com.hdl.sdk.ttl.HDLAppliances.HDLAudio.HDLAudio; import com.hdl.sdk.ttl.HDLAppliances.HDLCommonSwitch.CommonSwitchBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLCurtain.CurtainCtrlBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLCurtain.Parser.CurtainCtrlParser; import com.hdl.sdk.ttl.HDLAppliances.HDLLight.LightCtrlBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLLogic.LogicCtrlBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLSecurity.Parser.SecurityParser; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.DeviceStateBean; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.MCUDataBean; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.AirFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.CommonSwitchCtrlBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.CurtainFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DeviceStateEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.EventCode; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LightFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.MCUFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.SecurityArmingFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.UpdateRemarkFeedBackEvent; import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLUtlis; import com.hdl.sdk.ttl.Utils.LogUtils.HDLLog; import com.hdl.sdk.ttl.Utils.SPUtils.SPUtils; import org.greenrobot.eventbus.EventBus; import java.util.ArrayList; import java.util.List; import java.util.Timer; import java.util.TimerTask; /** * Modify by JLChen on 2019/6/27 */ public class HDLCommand { public static int mRequestTimeout = 5000;//默认请求超时时间 private static Timer getStateFailTimer = null;//获取设备状态失败Timer private static Timer lightCtrlFailTimer = null;//控制灯光失败Timer private static Timer curtainCtrlFailTimer = null;//控制窗帘失败Timer private static Timer acCtrlFailTimer = null;//控制空调失败Timer private static Timer sceneCtrlFailTimer = null;//控制场景失败Timer private static Timer remarkUpdateFailTimer = null;//更新备注失败Timer private static Timer mcuCtrlFailTimer = null;//MCU操作失败Timer private static Timer securityCtrlFailTimer = null;//安防模块操作失败Timer private static Timer commonSwitchCtrlFailTimer = null;//通用开关失败Timer // /** // * 初始化 SDK // * // * @param context // */ // public static void init(Context context, String mPathname, int mBaudrate) { // HDLDeviceManager.init(context); // HDLSerialPortCore.initHDLSerialPort(mPathname, mBaudrate); // } // // /** // * 是否开启SDK日志打印 // * // * @param bOpen // */ // public static void setHDLLogOpen(boolean bOpen) { // HDLLog.setHDLLogOpen(bOpen); // } // /** // * 释放资源 // */ // public static void release() { // HDLDeviceManager.release(); // } /** * 获取家居设备 */ public static void getHomeDevices() { HandleSearch.getHomeDevices(); } /** * 发现新设备搜索,不会清空原设备列表数据 */ public static void getNewHomeDevices() { HandleSearch.getNewHomeDevices(); } /** * 取消搜索等定时器 */ public static void cancelSearching() { HandleSearch.isSearching = false; if (HandleSearch.searchTimer != null) { HandleSearch.searchTimer.cancel(); HandleSearch.searchTimer = null; } if (HandleSearch.searchTwiceTimer != null) { HandleSearch.searchTwiceTimer.cancel(); HandleSearch.searchTwiceTimer = null; } if (HandleSearch.searchFailTimer != null) { HandleSearch.searchFailTimer.cancel(); HandleSearch.searchFailTimer = null; } if (HandleSearch.remarkTimer != null) { HandleSearch.remarkTimer.cancel(); HandleSearch.remarkTimer = null; } } /** * 修改更新模块备注名 * * @param mSubnetID 子网号 * @param mDeviceID 设备号 * @param remakeBytes 20190701 */ public static void updateModuleRemark(int mSubnetID, int mDeviceID, byte[] remakeBytes) { /***备注名字限制为20字节以内*/ if (remakeBytes.length > 20) return; HDLDeviceManager.isUpdateRemarkSuccess = false; if (remarkUpdateFailTimer != null) { remarkUpdateFailTimer.cancel(); remarkUpdateFailTimer = null; } byte[] updateBytes = new byte[20]; System.arraycopy(remakeBytes, 0, updateBytes, 0, remakeBytes.length); cusSendCommand(Configuration.MODULE_UPDATE_REMARK_COMMAND, mSubnetID, mDeviceID, updateBytes); remarkUpdateFailTimer = new Timer(); remarkUpdateFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.isUpdateRemarkSuccess) { EventBus.getDefault().post(new UpdateRemarkFeedBackEvent(false)); } } }, mRequestTimeout); } // /** // * 修改某回路备注名 // * @param newName 20190701 // */ // public static void updateLoopRemark(final AppliancesInfo info, String newName) { // byte[] updateBytes = new byte[20]; // byte[] remakeBytes = HDLStringUtils.stringtoBytes(newName); // System.arraycopy(remakeBytes, 0, updateBytes, 0, remakeBytes.length); // // cusSendCommand(Configuration.DEVICES_MODIFY_COMMAND, // info.getDeviceSubnetID(), info.getDeviceDeviceID(), updateBytes); // } /** * 控制灯光 * * @param info * @param state */ public static void lightCtrl(final AppliancesInfo info, int state) { // HDLDeviceManager.isLightCtrlSuccess = false; HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (lightCtrlFailTimer != null) { lightCtrlFailTimer.cancel(); lightCtrlFailTimer = null; } if ((!(state >= 0 && state <= 100)) || (info.getBigType() != Configuration.LIGTH_BIG_TYPE) || info.getChannelNum() == 0 ) { HDLLog.I("djlCtrl: " + "灯光设备控制不在范围内或不是灯光设备" + " \nstate = " + state + " \nLittleType = " + info.getLittleType() + " \nBigType = " + info.getBigType() ); return; } byte[] bytes; switch (info.getLittleType()) { case 0: case 1: //可能有区别 bytes = new byte[]{(byte) info.getChannelNum(), (byte) state, 0, 0}; break; case 9: bytes = new byte[]{(byte) info.getPhysicsChannelNum(), (byte) state, 0, 0}; break; case 10: bytes = new byte[]{(byte) info.getPhysicsChannelNum(), (byte) state, 0, 0}; break; default: bytes = new byte[]{0}; break; } //酒店的是物理回路号,需要测试。可能会出现问题 // HDLDeviceManager.curCtrlLightType = I.getDeviceType(); // byte[] bytes = new byte[]{(byte) I.getChannelNum(), (byte) state, 0, 0}; addSendData(info, bytes, Configuration.CONTROL); lightCtrlFailTimer = new Timer(); lightCtrlFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { LightCtrlBackInfo lightCtrlBackInfo = new LightCtrlBackInfo(); lightCtrlBackInfo.setAppliancesInfo(info); lightCtrlBackInfo.setChannelNum(info.getChannelNum()); EventBus.getDefault().post(new LightFeedBackEvent(lightCtrlBackInfo, false)); } } }, mRequestTimeout); } /** * 控制窗帘 * * @param info * @param state */ public static void curtainCtrl(final AppliancesInfo info, int state) { // HDLDeviceManager.isCurtainCtrlSuccess = false; HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (curtainCtrlFailTimer != null) { curtainCtrlFailTimer.cancel(); curtainCtrlFailTimer = null; } byte[] bytes; if (info.getBigType() == Configuration.CURTAIN_BIG_TYPE) { if (info.getLittleType() == 1 || info.getLittleType() == 0) { //这里是判断卷帘电机和开合帘电机 int newChannelNum; if (state == CurtainCtrlParser.curtainOff || state == CurtainCtrlParser.curtainOn || state == CurtainCtrlParser.curtainPause) { newChannelNum = info.getChannelNum(); } else { newChannelNum = info.getChannelNum() + 16; } bytes = CurtainCtrlParser.getCurtainAddByte(newChannelNum, state); } else { bytes = CurtainCtrlParser.getCurtainAddByte(info.getChannelNum(), state); } addSendData(info, bytes, Configuration.CONTROL); curtainCtrlFailTimer = new Timer(); curtainCtrlFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { CurtainCtrlBackInfo curtainCtrlBackInfo = new CurtainCtrlBackInfo(); curtainCtrlBackInfo.setAppliancesInfo(info); curtainCtrlBackInfo.setNum(info.getChannelNum()); EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, false)); } } }, mRequestTimeout); } else { HDLLog.I("djlCtrl; 不是窗帘设备" + " \nstate = " + state + " \nLittleType = " + info.getLittleType() + " \nBigType = " + info.getBigType() ); } } /** * 控制空调 * * @param info * @param type * @param state // * @param bCelsius 判断摄氏度 还是 华氏度(℉) */ public static void airCtrl(final AppliancesInfo info, int type, int state) { // HDLDeviceManager.isACCtrlSuccess = false; HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (acCtrlFailTimer != null) { acCtrlFailTimer.cancel(); acCtrlFailTimer = null; } if (info.getBigType() == Configuration.AIR_BIG_TYPE) { if (info.getDeviceType() == HDLApConfig.TYPE_AC_PANEL) { addSendData(info, AirCtrlParser.getAirPanelAddByte(type, state), Configuration.CONTROL); } else { byte[] airbytes = AirCtrlParser.getAcAddByte(info, type, state); if (airbytes != null) { addSendData(info, airbytes, Configuration.CONTROL); } } acCtrlFailTimer = new Timer(); acCtrlFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo(); airCtrlBackInfo.setAppliancesInfo(info); EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, false)); } } }, mRequestTimeout); } else { HDLLog.I("空调设备控制不在范围内" + " LittleType = " + info.getLittleType() + " BigType = " + info.getBigType() ); } } /** * 控制通用开关 * * @param info */ public static void commonSwitchCtrl(final AppliancesInfo info, int state) { HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (info.getBigType() == Configuration.COMMON_SWITCH_BIG_TYPE) { if (commonSwitchCtrlFailTimer != null) { commonSwitchCtrlFailTimer.cancel(); commonSwitchCtrlFailTimer = null; } byte[] bytes = new byte[]{(byte) info.getChannelNum(), (byte) state}; addSendData(info, bytes, Configuration.CONTROL); commonSwitchCtrlFailTimer = new Timer(); commonSwitchCtrlFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { HDLLog.I("通用开关控制失败"); CommonSwitchBackInfo mCommonSwitchBackInfo = new CommonSwitchBackInfo(); mCommonSwitchBackInfo.setAppliancesInfo(info); EventBus.getDefault().post(new CommonSwitchCtrlBackEvent(mCommonSwitchBackInfo, false)); } } }, mRequestTimeout); } else { HDLLog.I("djlCtrl: 通用开关设备控制不在范围内" + " LittleType = " + info.getLittleType() + " BigType = " + info.getBigType() ); } } /** * 获取通用开关状态 * @param info */ public static void getCommonSwitchStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_COMMON_SWITCH: //发送获灯光状态数据 addSendData(info, new byte[0], Configuration.STATE); break; default: HDLLog.I("不是通用开关设备"); break; } } /** * 安防模块 布防设置 * 2019-7-29 * @param info */ public static void securityArmingCtrl(final AppliancesInfo info, int state) { // HDLDeviceManager.isSecurityCtrlSuccess = false; HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (securityCtrlFailTimer != null) { securityCtrlFailTimer.cancel(); securityCtrlFailTimer = null; } if (info.getBigType() == Configuration.SECURITY_BIG_TYPE) { byte[] sendbytes = SecurityParser.getArmingByte(info, state); addSendData(info, sendbytes, Configuration.CONTROL); securityCtrlFailTimer = new Timer(); securityCtrlFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { EventBus.getDefault().post(new SecurityArmingFeedBackEvent(info,0, false)); } } }, 5000); } else { HDLLog.I("安防模块不在范围内" + " LittleType = " + info.getLittleType() + " BigType = " + info.getBigType() ); } } /** * 安防模块 报警设置 * 2019-7-29 * @param info * @param state 发送的报警内容,只报警一种 */ public static void securitySendAlarm(final AppliancesInfo info, int state) { if (info.getBigType() == Configuration.SECURITY_BIG_TYPE) { byte[] sendbytes = SecurityParser.getAlarmByte(info, state); cusSendCommand(Configuration.SECURITY_ALARM_CTRL_COMMAND, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendbytes); } else { HDLLog.I("不是安防模块" + " LittleType = " + info.getLittleType() + " BigType = " + info.getBigType() ); } } /** * 控制逻辑模块 * * @param info */ public static void logicCtrl(final AppliancesInfo info) { // HDLDeviceManager.isSceneCtrlSuccess = false; HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (info.getBigType() == Configuration.LOGIC_BIG_TYPE || info.getBigType() == Configuration.GLOBAL_LOGIC_BIG_TYPE) { if (info.getLogicMode() == null) { // HDLSerialPortCore.sendTestCMD(HDLTest.CODE_LOGIC_MODE_NULL, HDLTest.EXCEPTION_TEST_PORT); return; } else { addSendData(info, new byte[]{(byte) info.getLogicMode().getAreaNum(), (byte) info.getLogicMode().getAreaSceneNum()}, Configuration.CONTROL); } if (sceneCtrlFailTimer != null) { sceneCtrlFailTimer.cancel(); sceneCtrlFailTimer = null; } sceneCtrlFailTimer = new Timer(); sceneCtrlFailTimer.schedule(new TimerTask() { @Override public void run() { if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { HDLLog.I("逻辑控制失败"); LogicCtrlBackInfo logicCtrlBackInfo = new LogicCtrlBackInfo(); logicCtrlBackInfo.setAppliancesInfo(info); EventBus.getDefault().post(new LogicFeedBackEvent(logicCtrlBackInfo, false)); } } }, mRequestTimeout); } else { HDLLog.I("djlCtrl: 逻辑模块设备控制不在范围内" + " LittleType = " + info.getLittleType() + " BigType = " + info.getBigType() ); } } // 获取单一回路设备状态 // 读取设备状态 // public static void getDeviceState(final AppliancesInfo I) { // HDLDeviceManager.isGetDeviceStateSuccess = false; // switch (I.getBigType()) { // case Configuration.LIGTH_BIG_TYPE: // addSendData(I, new byte[]{}, Configuration.STATE); // break; // case Configuration.CURTAIN_BIG_TYPE: // if (I.getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) { // addSendData(I, new byte[]{(byte) I.getChannelNum()}, Configuration.STATE); // } else { // addSendData(I, new byte[]{(byte) (I.getChannelNum() + 16)}, Configuration.STATE); // } // break; // case Configuration.AIR_BIG_TYPE: // addSendData(I, new byte[]{AirCtrlParser.airSwich}, Configuration.STATE); //// addSendData(I,new byte[]{AirCtrlParser.refTem},Configuration.STATE); // addSendData(I, new byte[]{AirCtrlParser.airSpeed}, Configuration.STATE); // addSendData(I, new byte[]{AirCtrlParser.airMode}, Configuration.STATE); //// addSendData(I,new byte[]{AirCtrlParser.heatTem},Configuration.STATE); //// addSendData(I,new byte[]{AirCtrlParser.autoTem},Configuration.STATE); // break; // } // // if (I.getBigType() == Configuration.AIR_BIG_TYPE) { // return; // } // if (getStateFailTimer != null) { // getStateFailTimer.cancel(); // getStateFailTimer = null; // } // getStateFailTimer = new Timer(); // getStateFailTimer.schedule(new TimerTask() { // @Override // public void run() { // if (!HDLDeviceManager.isGetDeviceStateSuccess) { // EventBus.getDefault().post(new DeviceStateEvent(I, false)); // } // } // }, mRequestTimeout); // // } /** * 控制窗帘 * * @param info */ public static void curtainGetState(final AppliancesInfo info) { byte[] bytes = new byte[1]; if (info.getBigType() == Configuration.CURTAIN_BIG_TYPE) { if (info.getLittleType() == 1 || info.getLittleType() == 0) { //这里是判断卷帘电机和开合帘电机 int newChannelNum; int state = HDLUtlis.getIntegerByObject(info.getCurState()); if (state == CurtainCtrlParser.TYPE_STATE_PAUSE || state == CurtainCtrlParser.TYPE_STATE_OPEN || state == CurtainCtrlParser.TYPE_STATE_CLOSE) { newChannelNum = info.getChannelNum(); } else { newChannelNum = info.getChannelNum() + 16; } bytes[0] = (byte) newChannelNum; } else { bytes[0] = (byte) info.getChannelNum(); } addSendData(info, bytes, Configuration.STATE); } else { HDLLog.I("djlCtrl; 不是窗帘设备" + " \nLittleType = " + info.getLittleType() + " \nBigType = " + info.getBigType() ); } } // // /** // * 网络上获取单一设备状态 // * 通过发送查询指令获取 // * 空调状态读取(目前仅支持通用空调面板) // * // * @param info // */ // public static void getDeviceStateFromNetwork(final AppliancesInfo info) { // if (info == null) { // return; // } // HDLDeviceManager.isGetDeviceStateSuccess = false; // switch (info.getDeviceType()) { // case HDLApConfig.TYPE_LIGHT_DIMMER: // case HDLApConfig.TYPE_LIGHT_RELAY: // case HDLApConfig.TYPE_LIGHT_MIX_DIMMER: // case HDLApConfig.TYPE_LIGHT_MIX_RELAY: // //发送获灯光状态数据 // addSendData(info, new byte[0], Configuration.STATE); // break; // // case HDLApConfig.TYPE_CURTAIN_GLYSTRO: // case HDLApConfig.TYPE_CURTAIN_ROLLER: // case HDLApConfig.TYPE_CURTAIN_MODULE: // addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); // break; // // case HDLApConfig.TYPE_AC_HVAC: // case HDLApConfig.TYPE_AC_COOLMASTER: // case HDLApConfig.TYPE_AC_INFRARED: // case HDLApConfig.TYPE_AC_PANEL: // //暂不支持 // // break; // // default: // break; // // } // } /** * 获取窗帘设备状态 * @param info */ public static void getCurtainDeviceStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_CURTAIN_GLYSTRO: case HDLApConfig.TYPE_CURTAIN_ROLLER: case HDLApConfig.TYPE_CURTAIN_MODULE: addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); break; default: HDLLog.I("不是窗帘设备"); break; } } /** * 获取灯光设备状态 * @param info */ public static void getLightDeviceStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_LIGHT_DIMMER: case HDLApConfig.TYPE_LIGHT_RELAY: case HDLApConfig.TYPE_LIGHT_MIX_DIMMER: case HDLApConfig.TYPE_LIGHT_MIX_RELAY: //发送获灯光状态数据 addSendData(info, new byte[0], Configuration.STATE); break; default: HDLLog.I("不是灯光设备"); break; } } /** * 获取逻辑 场景号 * @param info */ public static void getLogicDeviceStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_LOGIC_MODULE: case HDLApConfig.TYPE_GLOBAL_LOGIC_MODULE: //发送获取场景号 addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); break; default: HDLLog.I("不是逻辑设备"); break; } } /** * 获取安防模块状态 * @param info */ public static void getSecurityStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_SECURITY_MODULE: //发送获安防模块状态数据 addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); break; default: HDLLog.I("不是安防模块"); break; } } /** * 获取传感器模块状态 * @param info */ public static void getSensorStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_SENSOR_DRY_CONTACT: case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR: case HDLApConfig.TYPE_SENSOR_TEMP: case HDLApConfig.TYPE_SENSOR_HUMIDITY: case HDLApConfig.TYPE_SENSOR_ILLUMINACE: case HDLApConfig.TYPE_SENSOR_VOC: case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5: case HDLApConfig.TYPE_SENSOR_C02: case HDLApConfig.TYPE_SENSOR_LPG: case HDLApConfig.TYPE_SENSOR_CO_H2: case HDLApConfig.TYPE_SENSOR_CH4: case HDLApConfig.TYPE_SENSOR_SMOG: case HDLApConfig.TYPE_SENSOR_WIND_SPEED: case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE: case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW: case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE: case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH: case HDLApConfig.TYPE_SENSOR_RAIN_FALL: case HDLApConfig.TYPE_SENSOR_WEIGHT: case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH: case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED: case HDLApConfig.TYPE_SENSOR_SHAKE: case HDLApConfig.TYPE_SENSOR_VOLTAGE: case HDLApConfig.TYPE_SENSOR_ELECTRICITY: case HDLApConfig.TYPE_SENSOR_POWER: case HDLApConfig.TYPE_SENSOR_FLOODING: case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET: case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON: //发送获传感器模块状态数据 byte[] sendDatabyte = new byte[]{ (byte) info.getBigType(), (byte) info.getLittleType(), (byte) info.getChannelNum() }; addSendData(info, sendDatabyte, Configuration.STATE); break; default: HDLLog.I("不是传感器模块"); break; } } /** * 获取干接点传感器模块状态 * @param info */ public static void getDryContactSensorStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_SENSOR_DRY_CONTACT: case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR: case HDLApConfig.TYPE_SENSOR_TEMP: case HDLApConfig.TYPE_SENSOR_HUMIDITY: case HDLApConfig.TYPE_SENSOR_ILLUMINACE: case HDLApConfig.TYPE_SENSOR_VOC: case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5: case HDLApConfig.TYPE_SENSOR_C02: case HDLApConfig.TYPE_SENSOR_LPG: case HDLApConfig.TYPE_SENSOR_CO_H2: case HDLApConfig.TYPE_SENSOR_CH4: case HDLApConfig.TYPE_SENSOR_SMOG: case HDLApConfig.TYPE_SENSOR_WIND_SPEED: case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE: case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW: case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE: case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH: case HDLApConfig.TYPE_SENSOR_RAIN_FALL: case HDLApConfig.TYPE_SENSOR_WEIGHT: case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH: case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED: case HDLApConfig.TYPE_SENSOR_SHAKE: case HDLApConfig.TYPE_SENSOR_VOLTAGE: case HDLApConfig.TYPE_SENSOR_ELECTRICITY: case HDLApConfig.TYPE_SENSOR_POWER: case HDLApConfig.TYPE_SENSOR_FLOODING: case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET: case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON: //发送获传感器模块状态数据 byte[] sendDatabyte = new byte[]{ (byte) 1, (byte) info.getChannelNum() }; addSendData(info, sendDatabyte, Configuration.STATE); break; default: HDLLog.I("不是传感器模块"); break; } } /** * 获取HVAC空调设备状态 * @param info */ public static void getHVACDeviceStateFromNetwork(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_AC_HVAC: // case HDLApConfig.TYPE_AC_PANEL: //发送HVAC状态数据 addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); break; default: HDLLog.I("不是HVAC空调设备"); break; } } /** * 获取单一设备状态 * 从SDK本地获取 * * @param info */ public static void getDeviceStateFromLocal(final AppliancesInfo info) { if (info == null) { return; } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_LIGHT_DIMMER: case HDLApConfig.TYPE_LIGHT_RELAY: case HDLApConfig.TYPE_LIGHT_MIX_DIMMER: case HDLApConfig.TYPE_LIGHT_MIX_RELAY: int lightState = getLightState(info); info.setCurState(lightState); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; case HDLApConfig.TYPE_CURTAIN_GLYSTRO: case HDLApConfig.TYPE_CURTAIN_ROLLER: case HDLApConfig.TYPE_CURTAIN_MODULE: int curtainState = getCurtainState(info); info.setCurState(curtainState); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; case HDLApConfig.TYPE_AC_HVAC: case HDLApConfig.TYPE_AC_COOLMASTER: case HDLApConfig.TYPE_AC_INFRARED: case HDLApConfig.TYPE_AC_PANEL: //2019-8-21 增加判空 byte[] acState = getACState(info); if (acState != null && acState.length >= 4) { info.setArrCurState(new byte[]{AirCtrlParser.airSwich, acState[0]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); info.setArrCurState(new byte[]{AirCtrlParser.airMode, acState[1]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); switch (acState[1] & 0xff) { case AirCtrlParser.airModeRefTem: info.setArrCurState(new byte[]{AirCtrlParser.refTem, acState[2]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; case AirCtrlParser.airModeHeatTem: info.setArrCurState(new byte[]{AirCtrlParser.heatTem, acState[2]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; case AirCtrlParser.airModeAuto: info.setArrCurState(new byte[]{AirCtrlParser.autoTem, acState[2]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; case AirCtrlParser.airModeDehum: info.setArrCurState(new byte[]{AirCtrlParser.autoTem, acState[2]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; default: break; } if ((acState[1] & 0xff) != AirCtrlParser.airModeDehum) { info.setArrCurState(new byte[]{AirCtrlParser.airSpeed, acState[3]}); EventBus.getDefault().post(new DeviceStateEvent(info, true)); } } break; case HDLApConfig.TYPE_SECURITY_MODULE://2019-7-29 byte[] ArrCurState = getSecurityState(info); info.setArrCurState(ArrCurState); EventBus.getDefault().post(new DeviceStateEvent(info, true)); break; // case HDLApConfig.TYPE_SENSOR_DRY_CONTACT://屏蔽20190703 // case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR: // case HDLApConfig.TYPE_SENSOR_TEMP: // case HDLApConfig.TYPE_SENSOR_HUMIDITY: // case HDLApConfig.TYPE_SENSOR_ILLUMINACE: // case HDLApConfig.TYPE_SENSOR_VOC: // case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5: // case HDLApConfig.TYPE_SENSOR_C02: // case HDLApConfig.TYPE_SENSOR_LPG: // case HDLApConfig.TYPE_SENSOR_CO_H2: // case HDLApConfig.TYPE_SENSOR_CH4: // case HDLApConfig.TYPE_SENSOR_SMOG: // case HDLApConfig.TYPE_SENSOR_WIND_SPEED: // case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE: // case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW: // case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE: // case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH: // case HDLApConfig.TYPE_SENSOR_RAIN_FALL: // case HDLApConfig.TYPE_SENSOR_WEIGHT: // case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH: // case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED: // case HDLApConfig.TYPE_SENSOR_SHAKE: // case HDLApConfig.TYPE_SENSOR_VOLTAGE: // case HDLApConfig.TYPE_SENSOR_ELECTRICITY: // case HDLApConfig.TYPE_SENSOR_POWER: // case HDLApConfig.TYPE_SENSOR_FLOODING: // case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET: // case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON: // //发送获取传感器所有数据 // addSendData(info, new byte[]{(byte) info.getBigType(), (byte) info.getLittleType(), (byte) info.getChannelNum()}, Configuration.STATE); // break; default: break; } } /** * 获取所有设备状态 * * @return */ public static List getAllDevicesState() { List deviceStateBeanList = new ArrayList<>(); for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) { List appliancesInfos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0; j < appliancesInfos.size(); j++) { if (appliancesInfos.get(j).getBigType() == Configuration.LIGTH_BIG_TYPE || appliancesInfos.get(j).getBigType() == Configuration.CURTAIN_BIG_TYPE || appliancesInfos.get(j).getBigType() == Configuration.AIR_BIG_TYPE ) { DeviceStateBean deviceStateBean = new DeviceStateBean(); deviceStateBean.setDeviceSubnetID(appliancesInfos.get(j).getDeviceSubnetID()); deviceStateBean.setDeviceDeviceID(appliancesInfos.get(j).getDeviceDeviceID()); deviceStateBean.setBigType(appliancesInfos.get(j).getBigType()); deviceStateBean.setLittleType(appliancesInfos.get(j).getLittleType()); deviceStateBean.setDeviceType(appliancesInfos.get(j).getDeviceType()); deviceStateBean.setChannelNum(appliancesInfos.get(j).getChannelNum()); if (deviceStateBean.getBigType() == Configuration.AIR_BIG_TYPE) { if (appliancesInfos.get(j).getArrCurState() != null) { deviceStateBean.setArrCurState(appliancesInfos.get(j).getArrCurState()); } } else { deviceStateBean.setCurState(appliancesInfos.get(j).getIntCurState()); } deviceStateBeanList.add(deviceStateBean); } } } // //更新所有设备状态 2019-07-03去掉 // HandleSearch.refreshAllDevicesState(); if (!deviceStateBeanList.isEmpty()) { return deviceStateBeanList; } else { return null; } } /** * 获取灯光状态 * * @param info * @return */ private static int getLightState(final AppliancesInfo info) { int curState = 0; outter: for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) { if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID() && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID() ) { List infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0, len2 = infos.size(); j < len2; j++) { if (info.getBigType() == infos.get(j).getBigType() && info.getLittleType() == infos.get(j).getLittleType() && info.getChannelNum() == infos.get(j).getChannelNum() ) { curState = HDLUtlis.getIntegerByObject(infos.get(j).getCurState()); break outter; } } } } return curState; } /** * 获取窗帘状态 * * @param info * @return */ private static int getCurtainState(final AppliancesInfo info) { int curState = 0; outter: for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) { if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID() && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID() ) { List infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0, len2 = infos.size(); j < len2; j++) { if (info.getBigType() == infos.get(j).getBigType() && info.getLittleType() == infos.get(j).getLittleType() && info.getChannelNum() == infos.get(j).getChannelNum() ) { //这里应该是要修复的,暂时未找到。 //2019-07 修改 int mCurState = HDLUtlis.getIntegerByObject(infos.get(j).getCurState()); switch (mCurState) { case -1: curState = 0; break; case -2: curState = 1; break; case -3: curState = 2; break; default: curState = mCurState; break; } break outter; } } } } return curState; } /** * 获取空调状态 * * @param info * @return */ private static byte[] getACState(final AppliancesInfo info) { byte[] curState = new byte[0]; outter: for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) { if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID() && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID() ) { List infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0, len2 = infos.size(); j < len2; j++) { if (info.getBigType() == infos.get(j).getBigType() && info.getLittleType() == infos.get(j).getLittleType() && info.getChannelNum() == infos.get(j).getChannelNum() ) { switch (info.getDeviceType()) { case HDLApConfig.TYPE_AC_HVAC: case HDLApConfig.TYPE_AC_PANEL: curState = infos.get(j).getArrCurState(); break; default: break; } break outter; } } } } return curState; } /** * 获取安防模块本地状态 * * @param info * @return */ private static byte[] getSecurityState(final AppliancesInfo info) { byte[] curState = new byte[0]; outter: for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) { if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID() && HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID() ) { List infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList(); for (int j = 0, len2 = infos.size(); j < len2; j++) { if (info.getBigType() == infos.get(j).getBigType() && info.getLittleType() == infos.get(j).getLittleType() && info.getChannelNum() == infos.get(j).getChannelNum() ) { curState = infos.get(j).getArrCurState(); break outter; } } break outter; } } return curState; } /** * 背景音乐控制 * * @param info * @param type */ public static void audioCtrl(AppliancesInfo info, int type) { byte[] musicBytes; int command; switch (type) { case HDLAudio.SET_AUDIO_PLAYSTOP: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x53, 0x54, 0x4F, 0x50, 0x0D}; break; case HDLAudio.SET_AUDIO_PLAYPAUSE: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{42, 83, 49, 80, 76, 65, 89, 80, 65, 85, 83, 69, 0x0D}; break; case HDLAudio.SET_NEXT_SONG: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x0D}; break; case HDLAudio.SET_PRE_SONG: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x0D}; break; case HDLAudio.GET_AUDIO_MODE: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x4D, 0x4F, 0x44, 0x45, 0x3F, 0x0D}; break; case HDLAudio.SET_AUDIO_MODE_UP: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2B, 0x0D}; break; case HDLAudio.SET_AUDIO_MODE_DOWN: command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2D, 0x0D}; break; case HDLAudio.GET_AUDIO_CURRRENT_INFO: command = Configuration.AUDIO_CTRL_READ_COMMAND; //*Z1STAUS?归为键 musicBytes = new byte[]{0x2A, 0x5A, 0x31, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x3F, 0x0D}; break; case HDLAudio.SET_PRE_LIST: HDLAudio.isSetPreNextList = true; command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x4C, 0x49, 0x53, 0x54, 0x0D}; break; case HDLAudio.SET_NEXT_LIST: HDLAudio.isSetPreNextList = true; command = Configuration.AUDIO_CTRL_READ_COMMAND; musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x0D}; break; case HDLAudio.TEXT: command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND; musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, 0x54, 0x30, 0x30, 0x31, 0x30, 0x30, 0x32, 0x31, 0x0D}; break; default: command = 0; musicBytes = null; break; } if (musicBytes != null) { // String sendData = ""; // for(int i = 0,len = musicBytes.length;i= 0 && mValue < 255; } /** * 提供第三方调用设置本地子网号、设备号 范围0 - 254 * * @param context * @param mSubnetID * @param mDeviceID */ public static boolean saveSubnetAndDeviceID(Context context, int mSubnetID, int mDeviceID) { try { if (getIfValueInScope(mSubnetID) && getIfValueInScope(mDeviceID)) { Crc.localSubnetID = mSubnetID; Crc.localDeviceID = mDeviceID; SPUtils.setParam(context, SPUtils.KEY_SUB_ID, mSubnetID); SPUtils.setParam(context, SPUtils.KEY_DEVICE_ID, mDeviceID); return true; } else { throw new SecurityException("====saveSubnetAndDeviceID ID范围0-254======="); } } catch (Exception e) { e.printStackTrace(); return false; } } /** * 单设备发送命令 * 目前控制发送次数为3次 * 发一条,补发3条,间隔500ms * * @param info * @param addBytes * @param type */ private static void addSendData(final AppliancesInfo info, byte[] addBytes, final int type) { final Crc sendDatas = new Crc(info.getStateCommand(), info.getDeviceSubnetID(), info.getDeviceDeviceID(), addBytes); sendDatas.count = 0; final Timer sendCycleTimer = new Timer(); sendCycleTimer.schedule(new TimerTask() { @Override public void run() { //2019-07 控制发送次数 if (sendDatas.count >= 4) { sendCycleTimer.cancel(); } else { sendDatas.count++; if (type == Configuration.STATE) { sendDatas.command = info.getStateCommand(); sendDatas.isCtrlSuccess = HDLDeviceManager.isGetDeviceStateSuccess; } else if (type == Configuration.CONTROL) { sendDatas.command = info.getCtrlCommand(); HDLLog.I("getDeviceKey: " + info.getDeviceKey());//2019-8-2 sendDatas.isCtrlSuccess = HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info); // switch (info.getBigType()) { // case Configuration.LIGTH_BIG_TYPE: // sendDatas.isCtrlSuccess = HDLDeviceManager.isLightCtrlSuccess; // break; // case Configuration.CURTAIN_BIG_TYPE: // sendDatas.isCtrlSuccess = HDLDeviceManager.isCurtainCtrlSuccess; // break; // case Configuration.AIR_BIG_TYPE: // sendDatas.isCtrlSuccess = HDLDeviceManager.isACCtrlSuccess; // break; // case Configuration.LOGIC_BIG_TYPE: // sendDatas.isCtrlSuccess = HDLDeviceManager.isSceneCtrlSuccess; // break; // case Configuration.SECURITY_BIG_TYPE: // sendDatas.isCtrlSuccess = HDLDeviceManager.isSecurityCtrlSuccess; // break; // default: // sendDatas.isCtrlSuccess = false; // } } if (!sendDatas.isCtrlSuccess) { HDLLog.I("控制发送第" + sendDatas.count + "次"); cusSendCommand(sendDatas.command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendDatas.addBytes); } else { sendCycleTimer.cancel(); } } } }, 1, 500); } /** * 发送广播或点对点命令 * * @param command 操作码 * @param subnetID 子网号 * @param deviceID 设备号 * @param addBytes 附加数据 */ public static void cusSendCommand(int command, int subnetID, int deviceID, byte[] addBytes) { Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes); HDLSerialPortCore.sendData(sendDatas); } /** * 发送组播命令 * 这个方法目前仅用在拿到Rcu ip地址 * * @param command 操作码 * @param subnetID 子网号 * @param deviceID 设备号 * @param addBytes 附加数据 */ public static void cusSendMulticastCommand(int command, int subnetID, int deviceID, byte[] addBytes) { Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes); HDLSerialPortCore.sendMulticastData(sendDatas); } // // /** // * 设置是否开启透传 // * 透传数据,不走bus协议,直接转发,不做数据格式处理 // * @param bOpen // */ // public static void setHDLPassThroughOpen(boolean bOpen){ // if(HDLSerialPortCore.bPassThrough != bOpen){ // HDLSerialPortCore.bPassThrough = bOpen; // } // } // // // //**************************MCU串口协议指令************************** // /** // * 发送数据 // */ // private static void HDLSendMCUData(final MCUCrc mcuDataList, boolean bPassThrough){ // if(HDLSerialPortCore.bPassThrough != bPassThrough){ // HDLSerialPortCore.bPassThrough = bPassThrough; // } // if(bPassThrough){ // HDLSerialPortCore.sendMCUData(mcuDataList); // }else { // HDLDeviceManager.isMCUCtrlSuccess = false; // if (mcuCtrlFailTimer != null) { // mcuCtrlFailTimer.cancel(); // mcuCtrlFailTimer = null; // } // HDLSerialPortCore.sendMCUData(mcuDataList); // // mcuCtrlFailTimer = new Timer(); // mcuCtrlFailTimer.schedule(new TimerTask() { // @Override // public void run() { // if (!HDLDeviceManager.isMCUCtrlSuccess) { //// MCUDataBean mMCUDataBean = new MCUDataBean(); //// mMCUDataBean.command = mcuDataList.mcuCommand; // EventBus.getDefault().post(new MCUFeedBackEvent(new MCUDataBean(), EventCode.FAILURE_TIMEOUT, "MCU请求超时,请稍后再试")); // } // } // }, mRequestTimeout); // } // // } // // /** // * 2019-8-9 // * 透传数据 // * 透传数据,不走bus协议,直接转发,不做数据格式处理 // */ // public static void mcuSendTransparentData(byte[] sendData) { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_COMMAND_SEND, sendData); // HDLSendMCUData(sendDatas, true); // } // // // /** // * 检测丢包状态 // */ // public static void mcuGetDetectPacketLossStatus() { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_DETECT_PACKET_LOSS_STATUS, new byte[0]); // HDLSendMCUData(sendDatas, false); // } // // /** // * 读配置信息 // */ // public static void mcuReadConfiguration() { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_READ_CONFIGURATION, new byte[0]); // HDLSendMCUData(sendDatas, false); // } // // /** // * 写配置信息 // */ // public static void mcuWriteConfiguration(byte[] sendData) { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_WRITE_CONFIGURATION, sendData); // HDLSendMCUData(sendDatas, false); // } // // /** // * 请求升级 // * sendData 文件大小[4byte] // */ // public static void mcuRequestUpgrade(byte[] sendData) { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_REQUEST_UPGRADE, sendData); // HDLSendMCUData(sendDatas, false); // } // // /** // * 请求升级 // * sendData 升级文件 // */ // public static void mcuRequestUpgradeWithFile(byte[] upgradeFileDatas) { // try { // HDLSerialPortCore.upgradeFileDatas = upgradeFileDatas; // mcuRequestUpgrade(HDLUtlis.intToByteArray(upgradeFileDatas.length)); // } catch (Exception e) { // e.printStackTrace(); // HDLSerialPortCore.upgradeFileDatas = null;//释放 // HDLLog.E("mcuRequestUpgradeWithFile 出错"); // } // } // // // /** // * 发送升级数据 // * sendData 文件地址[4byte] 数据长度[2byte] // * 固定:1024,否则不处理 // */ // public static void mcuSendUpgradeData(byte[] sendData) { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_SEND_UPGRADE_DATA, sendData); //// HDLSendMCUData(sendDatas, false); // HDLSerialPortCore.sendMCUData(sendDatas); // } // // /** // * 重启MCU // * 时间(1byte):范围1-10s // * 当为0xF8的时候,代表重启成功 // */ // public static void mcuSendRestart() { // MCUCrc sendDatas = new MCUCrc(MCUConstants.MCU_RESTART, new byte[0]); // HDLSendMCUData(sendDatas, false); // } }