| | |
| | | import com.hdl.sdk.link.core.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | import com.hdl.sdk.link.gateway.type.GatewayMasterType; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | |
| | | */ |
| | | public class HdlDeviceLogic { |
| | | private static volatile HdlDeviceLogic sHdlDeviceLogic; |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表 |
| | | */ |
| | | public List<GatewayBean> getGatewayList() { |
| | | List<GatewayBean> newList = new ArrayList<>(); |
| | | List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList(); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | if (gatewayBean.getMaster().equals("true") |
| | | && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | newList.add(gatewayBean); |
| | | } |
| | | } |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前对象 |
| | |
| | | } |
| | | return sHdlDeviceLogic; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表 |
| | | */ |
| | | public List<GatewayBean> getCurrentHomeGatewayList() { |
| | | List<GatewayBean> newList = new ArrayList<>(); |
| | | List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList(); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) |
| | | && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | newList.add(gatewayBean); |
| | | } |
| | | } |
| | | } |
| | | return newList; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加逆变器到云端上 |
| | |
| | | public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_EDIT; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("master", "true"); |
| | | json.addProperty("master", GatewayMasterType.MasterTrue); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取本地逆变器列表 |
| | | * 获取逆变器列表 |
| | | * 注意:有外网以云端设备为准,本地存在,云端没有则删除;内网以本地为主,搜索多少个设备就显示多少个; |
| | | * |
| | | * @param cloudCallBeak - |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | */ |
| | | public void getLocalGatewayList(CloudCallBeak<Boolean> cloudCallBeak) { |
| | | public void getCurrentHomeLocalAndCloudGatewayList(CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //局域网情况 |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | |
| | | // //云端没有绑定逆变器,以本地为主; |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | return; |
| | | } |
| | |
| | | removeInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | } |
| | |
| | | removeInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | //外网情况 |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | //清楚本地网关列表 |
| | | //云端没有,清空本地逆变器列表 |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | |
| | | if (list == null || list.size() == 0) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | return; |
| | | } |
| | |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | } |
| | |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | * @return - |
| | | */ |
| | | public void getDeviceRemoteInfo(String homeId, String spk, String mac, CloudCallBeak<DeviceRemoteInfo> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_remoteInfo; |
| | | String requestUrl = HttpApi.POST_Device_RemoteInfo; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("spk", spk); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 搜索网关列表 |
| | | * 搜索逆变器列表 |
| | | * |
| | | * @param gatewayCallBack - |
| | | */ |
| | |
| | | if (deviceRemoteInfo != null) { |
| | | gatewayBean.setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥 |
| | | gatewayBean.setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId |
| | | //用之前的库,底层mqtt订阅,加解密会用到该参数; |
| | | HDLLinkConfig.getInstance().setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥库 |
| | | HDLLinkConfig.getInstance().setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId |
| | | |
| | | } |
| | | gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());//住宅id |
| | | gatewayBean.setDeviceStatus(cloudInverterDeviceBean.getDeviceStatus());//设置网关状态 |
| | |
| | | gatewayBean.setDevice_name(cloudInverterDeviceBean.getName());//设备名称 |
| | | gatewayBean.setGatewayType(cloudInverterDeviceBean.getSpk());//设置spk |
| | | gatewayBean.setLocalEncrypt(true); |
| | | gatewayBean.setMaster("true"); |
| | | gatewayBean.setMaster(GatewayMasterType.MasterTrue); |
| | | gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//设备状态 |
| | | gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//软件版本号 |
| | | gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());//设备类型(产品二级分类名称 |