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;
|
|
/**
|
* Modify by JLChen on 2019/6/27
|
*/
|
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;//广播
|
private static final int SEARCH_MULTICAST = 102;//组播
|
|
private static boolean bSearchAll = true; //是否全部重新搜索,或者发现新设备搜索
|
|
/**
|
* 酒店搜索
|
* <p>
|
* <p>
|
* 这方法暂时不提供,获取备注当中也没有处理此类型。
|
* <p>
|
* 获取Rcu ip地址
|
*/
|
// private static void getRcuIp() {
|
// isGetRcuIp = true;
|
// HDLSerialPortCore.closeMulticast6000();
|
// HDLSerialPortCore.initMulticastSocket6008();
|
// if (getRcuIpFailorSuccessTimer != null) {
|
// getRcuIpFailorSuccessTimer.cancel();
|
// getRcuIpFailorSuccessTimer = null;
|
// }
|
// if (getRcuIpTimer != null) {
|
// getRcuIpTimer.cancel();
|
// getRcuIpTimer = null;
|
// }
|
//
|
// getRcuIpTimer = new Timer();
|
// getRcuIpFailorSuccessTimer = new Timer();
|
// HDLDeviceManager.isGetRcuIpSuccess = false;
|
// HDLDeviceManager.rcuIpList.clear();
|
//
|
// getRcuIpTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
//// 每400毫秒发送一次
|
// if (!HDLDeviceManager.isGetRcuIpSuccess) {
|
// baseSearch(SEARCH_MULTICAST, Configuration.RCU_SEND_PORT);
|
// }
|
//
|
//
|
// }
|
// }, 1, 200);
|
//
|
//
|
// getRcuIpFailorSuccessTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// isGetRcuIp = false;
|
// if (getRcuIpTimer != null) {
|
// getRcuIpTimer.cancel();
|
// getRcuIpTimer = null;
|
// }
|
//// 若没有回复则失败,开始家居搜索。若有回复则保存Rcu ip地址,开始酒店协议搜索第二步
|
// if (HDLDeviceManager.isGetRcuIpSuccess) {
|
// HDLDeviceManager.isGetRcuIpSuccess = false;
|
// //返回ip地址列表,如果只有一个不返回,直接搜索。
|
// switch (HDLDeviceManager.rcuIpList.size()) {
|
// case 0:
|
// searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
|
// break;
|
// case 1:
|
// rcuIp = HDLDeviceManager.rcuIpList.get(0);
|
// HDLLog.I("搜索到的rcu ip地址:" + rcuIp);
|
// searchDevices(GET_RCU_DEVICES, SEARCH_POINT_TO_POINT, Configuration.RCU_SEND_PORT);//RCU模块搜索
|
// break;
|
// default:
|
// //返回用户选择哪个rcuIp
|
// EventBus.getDefault().post(new RcuIpListEvent(HDLDeviceManager.rcuIpList));
|
// break;
|
// }
|
//
|
// } else {
|
// HDLLog.I("开始家居协议搜索");
|
// searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
|
// }
|
// }
|
// }, 1000);
|
// }
|
|
// /**
|
// * 酒店搜索
|
// * 获取Rcu模块设备
|
// */
|
// public static void getRcuDevices(Context context, String newRcuIp) {
|
// curSearchMode = GET_RCU_DEVICES;
|
// rcuIp = newRcuIp;
|
// SPUtils.setParam(context, SPUtils.KEY_RCU_IP_, newRcuIp);
|
// searchDevices(GET_RCU_DEVICES, SEARCH_POINT_TO_POINT, Configuration.RCU_SEND_PORT);
|
// }
|
|
|
/**
|
* 搜索网关
|
*/
|
public static void seachGateway() {
|
HDLCommand.cusSendCommand(Configuration.SEARCH_GATEWAY_COMMAND,
|
255, 255, new byte[]{random1, random2});
|
}
|
|
/**
|
* 全部重新搜索,清空原设备列表数据
|
*/
|
public static void getHomeDevices(int subnetID, int deviceID) {
|
bSearchAll = true;
|
curSearchMode = GET_BUS_DEVICES;
|
searchDevices(GET_BUS_DEVICES, SEARCH_POINT_TO_POINT, subnetID, deviceID);//家居搜索
|
}
|
|
/**
|
* 发现新设备搜索,不会清空原设备列表数据
|
* 只能搜索发现不存在realDevicesDataList里面的新设备
|
*/
|
public static void getNewHomeDevices(int subnetID, int deviceID) {
|
bSearchAll = false;
|
curSearchMode = GET_BUS_DEVICES;
|
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 searchMode 搜索模式
|
* @param baseSearchType 基础搜索类型
|
* @param
|
*/
|
private static void searchDevices(final int searchMode, final int baseSearchType, final int subnetID, final int deviceID) {
|
isSearching = true;
|
isRefreshAllDevicesState = false;
|
|
if (searchTimer != null) {
|
searchTimer.cancel();
|
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();
|
remarkTimer.purge();
|
remarkTimer = null;
|
}
|
|
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, subnetID, deviceID);
|
|
// 初始化搜索超时,5000毫秒后,无搜索设备数据返回则搜索超时
|
searchFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (HDLDeviceManager.devicesDataList.size() == 0) {
|
// 返回搜索超时
|
if (searchTimer != null) {
|
searchTimer.cancel();
|
searchTimer.purge();
|
searchTimer = null;
|
}
|
|
switch (searchMode) {
|
case GET_RCU_DEVICES:
|
HDLLog.I("Rcu设备搜索超时");
|
// searchDevices(GET_BUS_DEVICES, SEARCH_BROACAST, Configuration.PORT);//家居搜索
|
EventBus.getDefault().post(new DevicesInfoEvent(false));//不进行家居搜索,直接停止
|
break;
|
case GET_BUS_DEVICES:
|
//家居协议搜索超时
|
HDLLog.I("家居设备搜索超时");
|
EventBus.getDefault().post(new DevicesInfoEvent(false));
|
break;
|
}
|
}
|
}
|
}, 5000);
|
|
if (searchTimer == null) {
|
return;
|
}
|
|
//TODO 可能会为空
|
searchTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
// 每隔500毫秒判断当前的设备数与搜索出来的设备数是否一致
|
if (curDevSize != HDLDeviceManager.realDevicesDataList.size() || HDLDeviceManager.realDevicesDataList.size() == 0) {
|
//有新设备,继续等待500毫秒
|
if (searchTwiceTimer != null) {
|
searchTwiceTimer.cancel();
|
searchTwiceTimer.purge();
|
searchTwiceTimer = null;
|
HDLLog.I("有新设备阻断发送搜索命令");
|
}
|
if (HDLDeviceManager.realDevicesDataList.size() == 0) {
|
baseSearch(baseSearchType, subnetID, deviceID);
|
} else {
|
curDevSize = HDLDeviceManager.realDevicesDataList.size();
|
HDLLog.I("有新设备,继续等待500毫秒");
|
}
|
|
} else {
|
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;
|
}
|
}
|
}
|
}, 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);
|
}
|
}
|
|
}
|
}
|
}, 5000, 5000);
|
}
|
|
/**
|
* 发送第一次搜索
|
*
|
* @param type 搜索类型
|
* @param subnetID 网关子网号
|
* @param deviceID 网关设备号
|
*/
|
private static void baseSearch(int type, int subnetID, int deviceID) {
|
// 设备列表、设备备注列表初始化清空
|
if (remarkTimer != null) {
|
remarkTimer.cancel();
|
remarkTimer.purge();
|
remarkTimer = null;
|
}
|
isRefreshAllDevicesState = false;
|
/*** 全部重新搜索才清空list数组*/
|
if (bSearchAll) {
|
HDLDeviceManager.devicesDataList.clear();
|
HDLDeviceManager.realDevicesDataList.clear();
|
HDLDeviceManager.listRemarks.clear();
|
curDevSize = 0;
|
HDLDeviceManager.totalDeviceSize = 0;
|
}
|
|
// 发送第一次搜索命令
|
switch (type) {
|
case SEARCH_POINT_TO_POINT:
|
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_FROM_GATEWAY_COMMAND,
|
255, 255, new byte[]{random1, random2});
|
break;
|
case SEARCH_MULTICAST:
|
HDLCommand.cusSendMulticastCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND,
|
255, 255
|
, new byte[]{random1, random2});
|
break;
|
default:
|
break;
|
}
|
}
|
|
/**
|
* 发送第二次搜索
|
*
|
* @param arg1 随机数1
|
* @param arg2 随机数2
|
* @param 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;
|
if (remainder != 0) {
|
count++;
|
}
|
outter:
|
for (int j = 0; j < count; j++) {
|
byte[] bytes = new byte[4];
|
bytes[0] = arg1;
|
bytes[1] = arg2;
|
bytes[2] = 0;
|
bytes[3] = 0;
|
|
String sendData = "";
|
for (int i = 0; i < bytes.length; i++) {
|
if (i % 2 != 0) {
|
if ((i / 2) == 0) {
|
sendData += (bytes[i] & 0xff) + "(随机数)";
|
} else {
|
sendData += (bytes[i] & 0xff) + "(第" + (i / 2) + "个模块),";
|
}
|
} else {
|
sendData += (bytes[i] & 0xff) + ",";
|
}
|
}
|
HDLLog.I("第" + countSend + "次发送的搜索数据:" + sendData);
|
HDLCommand.cusSendCommand(Configuration.DEVICES_SEARCH_FROM_GATEWAY_COMMAND, subnetID, deviceID, bytes);
|
}
|
}
|
|
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);
|
}
|
|
/**
|
* 返回设备列表
|
* 2019-07-01
|
*/
|
public static void OnDeviceListGetSuccessCallBack() {
|
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));
|
}
|
|
|
/**
|
* 马上刷新所有设备数据,刷新备注名和其它状态参数
|
*
|
* @param
|
*/
|
public static void refreshAllDevicesStateNow() {
|
if (isSearching) {
|
isRefreshAllDevicesState = false;
|
return;
|
}
|
isRefreshAllDevicesState = true;
|
for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) {
|
HDLDeviceManager.listRemarks.get(i).setCallBack(false);
|
}
|
getDevRemarks();
|
}
|
|
// /**
|
// * 延迟30S后,发送刷新数据命令
|
// *
|
// * @param
|
// */
|
// public static void refreshAllDevicesState() {
|
// if (refreshTimer != null) {
|
// refreshTimer.cancel();
|
// refreshTimer.purge();
|
// refreshTimer = null;
|
// }
|
// if (isSearching) {
|
// isRefreshAllDevicesState = false;
|
// return;
|
// }
|
//
|
// refreshTimer = new Timer();
|
// refreshTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// isRefreshAllDevicesState = true;
|
// for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) {
|
// HDLDeviceManager.listRemarks.get(i).setCallBack(false);
|
// }
|
// getDevRemarks();
|
// }
|
// }, 1000 * 30);
|
// }
|
|
|
/**
|
* 获取备注
|
*
|
* @param
|
*/
|
public static void getDevRemarks() {
|
if (remarkTimer != null) {
|
remarkTimer.cancel();
|
remarkTimer = null;
|
}
|
if ((HDLDeviceManager.listRemarks != null && HDLDeviceManager.listRemarks.size() == 0) || isSearching) {
|
isRefreshAllDevicesState = false;
|
if (HDLDeviceManager.devicesDataList != null && HDLDeviceManager.devicesDataList.size() > 0) {
|
HandleSearch.OnDeviceListGetSuccessCallBack();
|
}
|
return;
|
}
|
|
int pos = -1;
|
for (int i = 0; i < HDLDeviceManager.listRemarks.size(); i++) {
|
if (!HDLDeviceManager.listRemarks.get(i).isCallBack()) {
|
pos = i;
|
break;
|
}
|
}
|
|
//判断是否获取设备备注完全,若完全则返回所有设备列表。
|
if (HDLDeviceManager.listRemarks != null && HDLDeviceManager.listRemarks.size() != 0 && pos == -1) {
|
if (!isRefreshAllDevicesState) {
|
HandleSearch.OnDeviceListGetSuccessCallBack();
|
} else {
|
//刷新完毕
|
// TODO: 2018/12/29 刷新完毕可能要做某些事情
|
HDLLog.I("刷新设备状态完毕");
|
isRefreshAllDevicesState = false;
|
HandleSearch.OnDeviceListGetSuccessCallBack();
|
}
|
|
return;
|
}
|
remarkTimer = new Timer();
|
final int newPos = pos;
|
final RemarkTimes remarkTimes = new RemarkTimes();
|
remarkTimes.setCount(0);
|
|
if (remarkTimer == null) {
|
return;
|
}
|
remarkTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (remarkTimes.getCount() < 1) {
|
remarkTimes.setCount(remarkTimes.getCount() + 1);
|
if (newPos < HDLDeviceManager.listRemarks.size()) {
|
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_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(),
|
});
|
}
|
} else {
|
|
if (HDLDeviceManager.listRemarks != null
|
&& HDLDeviceManager.listRemarks.size() != 0
|
&& newPos < HDLDeviceManager.listRemarks.size()) {
|
HDLDeviceManager.listRemarks.get(newPos).setCallBack(true);
|
}
|
getDevRemarks();
|
}
|
}
|
}, 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);
|
}
|
}
|