| | |
| | | package com.hdl.sdk.ttl.HDLDeviceManger.Core; |
| | | |
| | | import android.util.Log; |
| | | |
| | | import com.hdl.sdk.ttl.Config.Configuration; |
| | | import com.hdl.sdk.ttl.HDLDeviceManger.Bean.DevicesData; |
| | | import com.hdl.sdk.ttl.HDLDeviceManger.Bean.RemarkTimes; |
| | | import com.hdl.sdk.ttl.HDLDeviceManger.Bean.SearchCountBean; |
| | | import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DevicesInfoEvent; |
| | | import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.ScenesInfoEvent; |
| | | import com.hdl.sdk.ttl.Utils.LogUtils.HDLLog; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Random; |
| | | import java.util.Set; |
| | | import java.util.Timer; |
| | | import java.util.TimerTask; |
| | | |
| | |
| | | */ |
| | | public class HandleSearch { |
| | | public static boolean isSearching = true; |
| | | public static boolean isSceneSearching = true; |
| | | public static int curSearchMode = 0; |
| | | // public static String rcuIp = "";//主动传入的rcu ip地址 |
| | | // private static Timer getRcuIpTimer = null;//获取Rcuip Timer |
| | | // private static Timer getRcuIpFailorSuccessTimer = null;//获取Rcuip Timer |
| | | public static boolean isGetRcuIp = false; |
| | | private static boolean isRefreshAllDevicesState = false; |
| | | private static boolean isRefreshAllScenesState = false; |
| | | |
| | | public static Timer searchTimer = null;//发送第一次搜索Timer |
| | | public static Timer searchTwiceTimer = null;//发送第二次搜索Timer |
| | | public static Timer searchByIndexTimer = null;//发送设备搜索Timer |
| | | public static Timer searchFailTimer = null;//发送搜索失败Timer |
| | | public static Timer remarkTimer = null;//搜索备注Timer |
| | | private static Timer refreshTimer = null; |
| | | public static Timer searchSceneTimer = null;//发送场景第一次搜索Timer |
| | | public static Timer searchSceneFailTimer = null;//发送搜索失败Timer |
| | | public static Timer remarkSceneTimer = null;//搜索场景备注Timer |
| | | |
| | | private static int curDevSize;//记录设备总数。作用:比较搜索出来的总设备数 |
| | | private static int curSceneSize;//记录场景总数。作用:比较搜索出来的总场景数 |
| | | public static byte random1 = 0;//随机数1 |
| | | public static byte random2 = 0;//随机数2 |
| | | |
| | | public static final int GET_RCU_DEVICES = 0;//获取Rcu模块设备 |
| | | public static final int GET_BUS_DEVICES = 1;//获取家居模块 设备 |
| | | public static final int GET_BUS_SCENES = 2;//获取家居模块 场景 |
| | | |
| | | private static final int SEARCH_POINT_TO_POINT = 100;//点对点 |
| | | private static final int SEARCH_BROACAST = 101;//广播 |
| | |
| | | |
| | | |
| | | /** |
| | | * 搜索网关 |
| | | */ |
| | | public static void seachGateway() { |
| | | HDLCommand.cusSendCommand(Configuration.SEARCH_GATEWAY_COMMAND, |
| | | 255, 255, new byte[]{random1, random2}); |
| | | } |
| | | |
| | | /** |
| | | * 全部重新搜索,清空原设备列表数据 |
| | | */ |
| | | public static void getHomeDevices() { |
| | | public static void getHomeDevices(int subnetID, int deviceID) { |
| | | bSearchAll = true; |
| | | curSearchMode = GET_BUS_DEVICES; |
| | | searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索 |
| | | searchDevices(GET_BUS_DEVICES, SEARCH_POINT_TO_POINT, subnetID, deviceID);//家居搜索 |
| | | } |
| | | |
| | | /** |
| | | * 发现新设备搜索,不会清空原设备列表数据 |
| | | * 只能搜索发现不存在realDevicesDataList里面的新设备 |
| | | */ |
| | | public static void getNewHomeDevices() { |
| | | public static void getNewHomeDevices(int subnetID, int deviceID) { |
| | | bSearchAll = false; |
| | | curSearchMode = GET_BUS_DEVICES; |
| | | searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索 |
| | | searchDevices(GET_BUS_DEVICES, SEARCH_POINT_TO_POINT, subnetID, deviceID);//家居搜索 |
| | | } |
| | | |
| | | /** |
| | | * 搜索场景 |
| | | */ |
| | | public static void seachHomeScenes(int subnetID, int deviceID) { |
| | | HDLDeviceManager.scenesDataList.clear(); |
| | | searchScenes(subnetID, deviceID); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param baseSearchType 基础搜索类型 |
| | | * @param |
| | | */ |
| | | private static void searchDevices(final int searchMode, final int baseSearchType, final int port) { |
| | | private static void searchDevices(final int searchMode, final int baseSearchType, final int subnetID, final int deviceID) { |
| | | isSearching = true; |
| | | isRefreshAllDevicesState = false; |
| | | |
| | |
| | | searchTimer.purge(); |
| | | searchTimer = null; |
| | | } |
| | | |
| | | if (searchFailTimer != null) { |
| | | searchFailTimer.cancel(); |
| | | searchFailTimer.purge(); |
| | | searchFailTimer = null; |
| | | } |
| | | if (searchByIndexTimer != null) { |
| | | searchByIndexTimer.cancel(); |
| | | searchByIndexTimer.purge(); |
| | | searchByIndexTimer = null; |
| | | } |
| | | if (remarkTimer != null) { |
| | | remarkTimer.cancel(); |
| | |
| | | |
| | | searchTimer = new Timer(); |
| | | searchFailTimer = new Timer(); |
| | | searchByIndexTimer = new Timer(); |
| | | |
| | | int max = 254; |
| | | int min = 1; |
| | | random1 = (byte) (new Random().nextInt(max + 1) % (max - min + 1) + min); |
| | | random2 = (byte) (new Random().nextInt(max + 1) % (max - min + 1) + min); |
| | | |
| | | baseSearch(baseSearchType, port); |
| | | baseSearch(baseSearchType, subnetID, deviceID); |
| | | |
| | | // 初始化搜索超时,5000毫秒后,无搜索设备数据返回则搜索超时 |
| | | searchFailTimer.schedule(new TimerTask() { |
| | |
| | | HDLLog.I("有新设备阻断发送搜索命令"); |
| | | } |
| | | if (HDLDeviceManager.realDevicesDataList.size() == 0) { |
| | | baseSearch(baseSearchType, port); |
| | | baseSearch(baseSearchType, subnetID, deviceID); |
| | | } else { |
| | | curDevSize = HDLDeviceManager.realDevicesDataList.size(); |
| | | HDLLog.I("有新设备,继续等待500毫秒"); |
| | | } |
| | | |
| | | } else { |
| | | if (searchTwiceTimer == null) { |
| | | searchTwiceTimer = new Timer(); |
| | | final SearchCountBean bean = new SearchCountBean(); |
| | | bean.setCount(0); |
| | | searchTwiceTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (bean.getCount() < 3) { |
| | | HDLLog.I("没有收到新设备,发送第 " + (bean.getCount() + 1) + " 次搜索命令"); |
| | | secondTimeSearch(random1, random2, (bean.getCount() + 1), HDLDeviceManager.realDevicesDataList); |
| | | } else { |
| | | if (searchTimer != null) { |
| | | searchTimer.cancel(); |
| | | searchTimer.purge(); |
| | | searchTimer = null; |
| | | HDLLog.I("网关设备总数:" + HDLDeviceManager.totalDeviceSize + " 接收到的设备总数:" + HDLDeviceManager.realDevicesDataList.size()); |
| | | if (HDLDeviceManager.totalDeviceSize != HDLDeviceManager.realDevicesDataList.size()) { |
| | | if (searchByIndexTimer != null) { |
| | | searchByIndexTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (HDLDeviceManager.totalDeviceSize != HDLDeviceManager.realDevicesDataList.size()) { |
| | | searchByIndex(HDLDeviceManager.realDevicesDataList, subnetID, deviceID); |
| | | } else { |
| | | if (searchByIndexTimer != null) { |
| | | searchByIndexTimer.cancel(); |
| | | searchByIndexTimer.purge(); |
| | | searchByIndexTimer = null; |
| | | } |
| | | } |
| | | if (searchTwiceTimer != null) { |
| | | searchTwiceTimer.cancel(); |
| | | searchTwiceTimer.purge(); |
| | | searchTwiceTimer = null; |
| | | } |
| | | |
| | | isSearching = false; |
| | | HDLLog.I("开始获取每个模块的回路状态与备注"); |
| | | getDevRemarks();//开始获取第一备注,逐一获取。 |
| | | } |
| | | bean.setCount(bean.getCount() + 1); |
| | | } |
| | | }, 1, 800); |
| | | } |
| | | }, 5000, 5000); |
| | | } |
| | | } else { |
| | | if (searchTwiceTimer == null) { |
| | | searchTwiceTimer = new Timer(); |
| | | final SearchCountBean bean = new SearchCountBean(); |
| | | bean.setCount(0); |
| | | searchTwiceTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (bean.getCount() < 3) { |
| | | HDLLog.I("没有收到新设备,发送第 " + (bean.getCount() + 1) + " 次搜索命令"); |
| | | secondTimeSearch(random1, random2, (bean.getCount() + 1), HDLDeviceManager.realDevicesDataList, subnetID, deviceID); |
| | | } else { |
| | | if (searchTimer != null) { |
| | | searchTimer.cancel(); |
| | | searchTimer.purge(); |
| | | searchTimer = null; |
| | | } |
| | | if (searchTwiceTimer != null) { |
| | | searchTwiceTimer.cancel(); |
| | | searchTwiceTimer.purge(); |
| | | searchTwiceTimer = null; |
| | | } |
| | | if (searchByIndexTimer != null) { |
| | | searchByIndexTimer.cancel(); |
| | | searchByIndexTimer.purge(); |
| | | searchByIndexTimer = null; |
| | | } |
| | | |
| | | isSearching = false; |
| | | HDLLog.I("开始获取每个模块的回路状态与备注"); |
| | | getDevRemarks();//开始获取第一备注,逐一获取。 |
| | | } |
| | | bean.setCount(bean.getCount() + 1); |
| | | } |
| | | }, 1, 800); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | }, 800, 800); |
| | | }, 5000, 5000); |
| | | } |
| | | |
| | | /** |
| | | * 发送第一次搜索 |
| | | * |
| | | * @param type 搜索类型 |
| | | * @param port 端口号 |
| | | * @param type 搜索类型 |
| | | * @param subnetID 网关子网号 |
| | | * @param deviceID 网关设备号 |
| | | */ |
| | | private static void baseSearch(int type, int port) { |
| | | private static void baseSearch(int type, int subnetID, int deviceID) { |
| | | // 设备列表、设备备注列表初始化清空 |
| | | if (remarkTimer != null) { |
| | | remarkTimer.cancel(); |
| | |
| | | HDLDeviceManager.realDevicesDataList.clear(); |
| | | HDLDeviceManager.listRemarks.clear(); |
| | | curDevSize = 0; |
| | | HDLDeviceManager.totalDeviceSize = 0; |
| | | } |
| | | |
| | | // 发送第一次搜索命令 |
| | | switch (type) { |
| | | case SEARCH_POINT_TO_POINT: |
| | | HDLLog.I("发送第一次RCU搜索"); |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_COMMAND, |
| | | 255, 255, new byte[]{random1, random2}); |
| | | HDLLog.I("发送第一次家居搜索"); |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND, |
| | | subnetID, deviceID, new byte[]{random1, random2, 0, 0}); |
| | | break; |
| | | case SEARCH_BROACAST: |
| | | HDLLog.I("发送第一次家居搜索"); |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_COMMAND, |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND, |
| | | 255, 255, new byte[]{random1, random2}); |
| | | break; |
| | | case SEARCH_MULTICAST: |
| | | HDLCommand.cusSendMulticastCommand(Configuration.DEVICES_SEARCH_COMMAND, |
| | | HDLCommand.cusSendMulticastCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND, |
| | | 255, 255 |
| | | , new byte[]{random1, random2}); |
| | | break; |
| | |
| | | * @param arg2 随机数2 |
| | | * @param devicesDataList 所有设备信息集 |
| | | */ |
| | | public static void secondTimeSearch(byte arg1, byte arg2, int countSend, List<DevicesData> devicesDataList) { |
| | | public static void secondTimeSearch(byte arg1, byte arg2, int countSend, List<DevicesData> devicesDataList, int subnetID, int deviceID) { |
| | | if (devicesDataList == null || devicesDataList.size() == 0) { |
| | | return; |
| | | } |
| | | int devicesCount = 32; |
| | | int count = devicesDataList.size() / devicesCount; |
| | | int remainder = devicesDataList.size() % devicesCount; |
| | | // HDLLog.I("kkkkcount:"+count+" remainder: "+remainder); |
| | | if (remainder != 0) { |
| | | count++; |
| | | } |
| | | outter: |
| | | for (int j = 0; j < count; j++) { |
| | | byte[] bytes; |
| | | int remainder2; |
| | | if (j != count - 1 |
| | | || (count == 1 && remainder == 0) |
| | | ) { |
| | | remainder2 = devicesCount; |
| | | } else { |
| | | remainder2 = remainder; |
| | | } |
| | | |
| | | bytes = new byte[2 + remainder2 * 2]; |
| | | byte[] bytes = new byte[4]; |
| | | bytes[0] = arg1; |
| | | bytes[1] = arg2; |
| | | for (int k = 0; k < remainder2; k++) { |
| | | if ((devicesCount * j + k >= devicesDataList.size()) || ((2 + 2 * k + 1) >= bytes.length)) { |
| | | break outter; |
| | | } |
| | | bytes[2 + 2 * k] = (byte) devicesDataList.get(devicesCount * j + k).getSourceSubnetID(); |
| | | bytes[2 + 2 * k + 1] = (byte) devicesDataList.get(devicesCount * j + k).getSourceDeviceID(); |
| | | } |
| | | bytes[2] = 0; |
| | | bytes[3] = 0; |
| | | |
| | | String sendData = ""; |
| | | for (int i = 0; i < bytes.length; i++) { |
| | |
| | | } |
| | | } |
| | | HDLLog.I("第" + countSend + "次发送的搜索数据:" + sendData); |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_COMMAND, 255, 255, bytes); |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND, subnetID, deviceID, bytes); |
| | | } |
| | | } |
| | | |
| | | // |
| | | // /** |
| | | // * 返回设备列表 |
| | | // */ |
| | | // public static void deviceListCallBack() { |
| | | // byte[] debugBytes = new byte[6 + HDLDeviceManager.devicesDataList.size() * 2]; |
| | | // debugBytes[0] = 1; |
| | | // debugBytes[1] = 1; |
| | | // debugBytes[2] = 1; |
| | | // debugBytes[3] = 1; |
| | | // debugBytes[4] = 1; |
| | | // debugBytes[5] = 1; |
| | | // |
| | | // for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) { |
| | | // debugBytes[6 + i + i] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID(); |
| | | // debugBytes[6 + i + i + 1] = (byte) HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID(); |
| | | // String device = "第 " + (i + 1) + " 个模块:模块备注名称:" + HDLDeviceManager.devicesDataList.get(i).getRemark() |
| | | // + ",子网号:" + HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() |
| | | // + ",设备号:" + HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() |
| | | // + ",回路数:" + HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size() + "\n"; |
| | | // HDLLog.I(device); |
| | | // } |
| | | //// HDLSerialPortCore.sendTestCMD(debugBytes, HDLTest.SEND_TEST_PORT); |
| | | // EventBus.getDefault().post(new DevicesInfoEvent(HDLDeviceManager.devicesDataList, true)); |
| | | // } |
| | | public static void searchByIndex(List<DevicesData> devicesDataList, int subnetID, int deviceID) { |
| | | |
| | | HDLLog.I("searchByIndex 网关设备总数:" + HDLDeviceManager.totalDeviceSize + " 接收到的设备总数:" + HDLDeviceManager.realDevicesDataList.size()); |
| | | |
| | | if (HDLDeviceManager.totalDeviceSize != devicesDataList.size()) { |
| | | List<Integer> indexList = new ArrayList<>(); |
| | | for (int i = 0; i < devicesDataList.size(); i++) { |
| | | DevicesData devicesData = devicesDataList.get(i); |
| | | indexList.add(devicesData.getDeviceIndex()); |
| | | } |
| | | |
| | | //创建包含所有索引的集合 |
| | | Set<Integer> allIndices = new HashSet<>(); |
| | | for (int i = 1; i <= HDLDeviceManager.totalDeviceSize; i++) { |
| | | allIndices.add(i); |
| | | } |
| | | //将indexList转换为集合 |
| | | Set<Integer> indexSet = new HashSet<>(indexList); |
| | | //计算未包含的索引 |
| | | allIndices.removeAll(indexSet); |
| | | //将结果转换为列表 |
| | | List<Integer> newIndexList = new ArrayList<>(allIndices); |
| | | HDLLog.I("未包含的设备总数:" + newIndexList.size() + " 设备索引:" + newIndexList.toString()); |
| | | |
| | | int max = 254; |
| | | int min = 1; |
| | | |
| | | for (int i = 0; i < newIndexList.size(); i++) { |
| | | random1 = (byte) (new Random().nextInt(max + 1) % (max - min + 1) + min); |
| | | random2 = (byte) (new Random().nextInt(max + 1) % (max - min + 1) + min); |
| | | HDLLog.I("发送搜索设备的索引:" + newIndexList.get(i)); |
| | | |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND, |
| | | subnetID, deviceID, new byte[]{random1, random2, (byte) (newIndexList.get(i) / 256), (byte) (newIndexList.get(i) % 256)}); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 初始化搜索场景 |
| | | * |
| | | * @param |
| | | */ |
| | | private static void searchScenes(int subnetID, int deviceID) { |
| | | isSceneSearching = true; |
| | | isRefreshAllScenesState = false; |
| | | |
| | | if (searchSceneTimer != null) { |
| | | searchSceneTimer.cancel(); |
| | | searchSceneTimer.purge(); |
| | | searchSceneTimer = null; |
| | | } |
| | | |
| | | if (searchSceneFailTimer != null) { |
| | | searchSceneFailTimer.cancel(); |
| | | searchSceneFailTimer.purge(); |
| | | searchSceneFailTimer = null; |
| | | } |
| | | |
| | | searchSceneTimer = new Timer(); |
| | | searchSceneFailTimer = new Timer(); |
| | | |
| | | HDLCommand.cusSendCommand(Configuration.SCENE_SEARCH_FROM_GATEWAY_COMMAND, |
| | | subnetID, deviceID, new byte[]{0, 0}); |
| | | |
| | | // 初始化搜索超时,5000毫秒后,无搜索设备数据返回则搜索超时 |
| | | searchSceneFailTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (HDLDeviceManager.scenesDataList.size() == 0) { |
| | | // 返回搜索超时 |
| | | if (searchSceneTimer != null) { |
| | | searchSceneTimer.cancel(); |
| | | searchSceneTimer.purge(); |
| | | searchSceneTimer = null; |
| | | } |
| | | EventBus.getDefault().post(new ScenesInfoEvent(false));//不进行场景搜索,直接停止 |
| | | } |
| | | } |
| | | }, 5000); |
| | | |
| | | if (searchSceneTimer == null) { |
| | | return; |
| | | } |
| | | searchSceneTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (HDLDeviceManager.scenesDataList.size() != 0) { |
| | | if (searchSceneTimer != null) { |
| | | searchSceneTimer.cancel(); |
| | | searchSceneTimer.purge(); |
| | | searchSceneTimer = null; |
| | | } |
| | | |
| | | isSceneSearching = false; |
| | | HDLLog.I("开始获取每个场景的详细信息"); |
| | | getSceneDetails();//开始获取第一场景,逐一获取。 |
| | | } |
| | | } |
| | | }, 1, 800); |
| | | } |
| | | |
| | | /** |
| | | * 返回设备列表 |
| | |
| | | EventBus.getDefault().post(new DevicesInfoEvent(HDLDeviceManager.devicesDataList, true)); |
| | | /**搜索设备成功,执行一次保存到本地*/ |
| | | HDLDeviceManager.saveDevicesDataList(); |
| | | } |
| | | |
| | | /** |
| | | * 返回场景列表 |
| | | * 2024-01-18 |
| | | */ |
| | | public static void OnSceneListGetSuccessCallBack() { |
| | | EventBus.getDefault().post(new ScenesInfoEvent(HDLDeviceManager.scenesDataList, true)); |
| | | } |
| | | |
| | | |
| | |
| | | public static void getDevRemarks() { |
| | | if (remarkTimer != null) { |
| | | remarkTimer.cancel(); |
| | | // remarkTimer.purge(); |
| | | remarkTimer = null; |
| | | } |
| | | if ((HDLDeviceManager.listRemarks != null && HDLDeviceManager.listRemarks.size() == 0) || isSearching) { |
| | |
| | | } |
| | | return; |
| | | } |
| | | |
| | | int pos = -1; |
| | | for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) { |
| | | if (!HDLDeviceManager.listRemarks.get(i).isCallBack()) { |
| | |
| | | remarkTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (remarkTimes.getCount() < 3) { |
| | | if (remarkTimes.getCount() < 1) { |
| | | remarkTimes.setCount(remarkTimes.getCount() + 1); |
| | | if (newPos < HDLDeviceManager.listRemarks.size()) { |
| | | // int port = 0; |
| | | // String ipAddress = ""; |
| | | switch (curSearchMode) { |
| | | case HandleSearch.GET_RCU_DEVICES: |
| | | // ipAddress = rcuIp; |
| | | // port = Configuration.RCU_SEND_PORT; |
| | | break; |
| | | case HandleSearch.GET_BUS_DEVICES: |
| | | // ipAddress = NetWorkUtil.getLocalBroadCast(); |
| | | // ipAddress = HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getIpAddress(); |
| | | // port = Configuration.PORT; |
| | | break; |
| | | } |
| | | HDLLog.I("----->发送获取备注命令。共" + HDLDeviceManager.listRemarks.size() + "个模块。第" |
| | | + newPos + "个模块。第 " + (HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getChannelNum()) |
| | | + " 回路,子网号:" + HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceSubnetID() |
| | | + ",设备号:" + HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceDeviceID() |
| | | + " 第 " + remarkTimes.getCount() + " 次"); |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_READ_COMMAND, |
| | | HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceSubnetID() |
| | | , HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceDeviceID(), |
| | | HDLCommand.cusSendCommand(Configuration.DEVICES_READ_FROM_GATEWAY_COMMAND, |
| | | HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getSourceSubnetID() |
| | | , HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getSourceDeviceID(), |
| | | new byte[]{ |
| | | (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceSubnetID(), |
| | | (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getDeviceDeviceID(), |
| | | (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getChannelNum(), |
| | | (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getBigType(), |
| | | (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getLittleType(), |
| | | (byte) HDLDeviceManager.listRemarks.get(newPos).getAppliancesInfo().getChannelNum()}); |
| | | }); |
| | | } |
| | | } else { |
| | | |
| | |
| | | }, 1, 1200); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取场景详情 |
| | | * |
| | | * @param |
| | | */ |
| | | public static void getSceneDetails() { |
| | | if (HDLDeviceManager.scenesDataList.size() == 0) { |
| | | return; |
| | | } |
| | | if (remarkSceneTimer != null) { |
| | | remarkSceneTimer.cancel(); |
| | | remarkSceneTimer = null; |
| | | } |
| | | |
| | | int pos = -1; |
| | | for (int i = 0; i < HDLDeviceManager.scenesDataList.size(); i++) { |
| | | if (!HDLDeviceManager.scenesDataList.get(i).isCallBack()) { |
| | | pos = i; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | //判断是否获取场景备注完全,若完全则返回所有场景列表。 |
| | | if (HDLDeviceManager.scenesDataList != null && HDLDeviceManager.scenesDataList.size() != 0 && pos == -1) { |
| | | HandleSearch.OnSceneListGetSuccessCallBack(); |
| | | return; |
| | | } |
| | | |
| | | remarkSceneTimer = new Timer(); |
| | | final int newPos = pos; |
| | | final RemarkTimes remarkTimes = new RemarkTimes(); |
| | | remarkTimes.setCount(0); |
| | | |
| | | if (remarkSceneTimer == null) { |
| | | return; |
| | | } |
| | | |
| | | remarkSceneTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (remarkTimes.getCount() < 1) { |
| | | remarkTimes.setCount(remarkTimes.getCount() + 1); |
| | | if (newPos < HDLDeviceManager.scenesDataList.size()) { |
| | | |
| | | HDLLog.I("----->发送获取备注命令。共" + HDLDeviceManager.scenesDataList.size() + "个场景。第" |
| | | + (HDLDeviceManager.scenesDataList.get(newPos).getIndex()) |
| | | + "个场景。"); |
| | | HDLCommand.cusSendCommand(Configuration.SCENE_READ_FROM_GATEWAY_COMMAND, |
| | | HDLDeviceManager.scenesDataList.get(newPos).getSourceSubnetID() |
| | | , HDLDeviceManager.scenesDataList.get(newPos).getSourceDeviceID(), |
| | | new byte[]{ |
| | | (byte) (HDLDeviceManager.scenesDataList.get(newPos).getIndex() / 256), |
| | | (byte) (HDLDeviceManager.scenesDataList.get(newPos).getIndex() % 256) |
| | | }); |
| | | } |
| | | } else { |
| | | if (HDLDeviceManager.scenesDataList != null |
| | | && HDLDeviceManager.scenesDataList.size() != 0 |
| | | && newPos < HDLDeviceManager.scenesDataList.size()) { |
| | | HDLDeviceManager.scenesDataList.get(newPos).setCallBack(true); |
| | | } |
| | | getSceneDetails(); |
| | | } |
| | | |
| | | } |
| | | }, 1, 2000); |
| | | } |
| | | } |