From 22494af577e21a930abef309f2f60c03c9615bd1 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期五, 07 七月 2023 18:16:55 +0800 Subject: [PATCH] 2023年07月07日18:16:52 --- app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 157 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 157 insertions(+), 0 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java index a5f0327..08d8f54 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java @@ -139,6 +139,7 @@ }); } + /** * 鍒犻櫎閫嗗彉鍣� * @@ -321,6 +322,49 @@ } + + /** + * 鑾峰彇缃戝叧璇︽儏淇℃伅 + * + * @param mac 缃戝叧mac + * @param cloudCallBeak 鍥炶皟 + */ + public void getGatewayInfo(String mac, CloudCallBeak<GatewayBean> cloudCallBeak) { + String requestUrl = TopicApi.GET_GATEWAY_INFO; + TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { + @Override + public void onSuccess(String msg) { + try { + if (!TextUtils.isEmpty(msg)) { + Gson gson = new Gson(); + String json = gson.toJson(msg); + GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(gatewayBean); + } + } else { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(new GatewayBean()); + } + } + + } catch (Exception e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + } + + @Override + public void onError(HDLLinkException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + + } + /** * 鑾峰彇缃戝叧oid鍒楄〃 * @@ -365,6 +409,119 @@ } + /** + * 鑾峰彇鏈湴璁惧鍒楄〃 + * 娉ㄦ剰:鏈夊缃戜互浜戠璁惧涓哄噯,鏈湴瀛樺湪锛屼簯绔病鏈夊垯鍒犻櫎锛涘唴缃戜互鏈湴涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓紱 + * + * @param cloudCallBeak - + */ + public void getLocalGatewayList(CloudCallBeak<Boolean> 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) { + if (list == null) { + //浜戠娌℃湁缁戝畾閫嗗彉鍣�,娓呯┖鏈湴鍒楄〃; + HDLLinkLocalGateway.getInstance().getGatewayList().clear(); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + return; + } + //鏀堕泦鍒犻櫎閫嗗彉鍣╯id + List<String> removeSidList = new ArrayList<>(); + for (int i = 0; i < list.size(); i++) { + CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); + for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); + if (!cloudInverterDeviceBean.getSid().equals(gatewayBean.getSid())) { + //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛� + removeSidList.add(gatewayBean.getSid()); + } + + } + } + for (int i = 0; i < removeSidList.size(); i++) { + //鑾峰彇鏈湴鐨勬绫虫尝 + removeInverter(removeSidList.get(i)); + } + + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + } + + @Override + public void onFailure(Exception exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); + } + + @Override + public void onError(HDLLinkException e) { + HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { + @Override + public void onSuccess(List<CloudInverterDeviceBean> list) { + if (list == null) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + return; + } + if (list.size() <= 0) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + return; + } + HDLLinkLocalGateway.getInstance().getGatewayList().clear(); + for (int i = 0; i < list.size(); i++) { + CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); + GatewayBean gatewayBean = new GatewayBean(); + gatewayBean.setOid(cloudInverterDeviceBean.getOid()); + gatewayBean.setSid(cloudInverterDeviceBean.getSid()); + gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId()); + gatewayBean.setOnline(cloudInverterDeviceBean.isOnline()); + gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName()); + gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId()); + gatewayBean.setLocalEncrypt(true); + gatewayBean.setMaster("true"); + HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean); + } + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + + } + + @Override + public void onFailure(Exception exception) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(exception); + } + } + }); + } + }); + } + + /** + * 鍒犻櫎鏈湴閫嗗彉鍣� + * + * @param sid 璁惧sid + */ + private void removeInverter(String sid) { + //鑾峰彇鏈湴鐨勬绫虫尝 + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid); + if (gatewayBean != null) { + HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); + } + } /** * 鎼滅储缃戝叧鍒楄〃 -- Gitblit v1.8.0