From 5ca2b601848c62607d88fee5afdae6af80f6eea7 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期三, 20 三月 2024 16:12:26 +0800 Subject: [PATCH] 2024年03月20日16:12:17 --- app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 234 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 174 insertions(+), 60 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 6175ea4..d5bf0a7 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java @@ -2,6 +2,7 @@ import android.text.TextUtils; +import com.facebook.imagepipeline.image.OriginalEncodedImageInfo; import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; @@ -21,12 +22,17 @@ import com.hdl.photovoltaic.ui.bean.DeviceTimeBean; import com.hdl.photovoltaic.ui.bean.OidBean; import com.hdl.sdk.link.HDLLinkLocalSdk; +import com.hdl.sdk.link.common.config.TopicConstant; +import com.hdl.sdk.link.common.exception.HDLLinkCode; import com.hdl.sdk.link.common.exception.HDLLinkException; +import com.hdl.sdk.link.common.utils.IdUtils; +import com.hdl.sdk.link.core.bean.LinkRequest; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; import com.hdl.sdk.link.core.callback.GatewayCallBack; import com.hdl.sdk.link.core.callback.HDLLinkCallBack; import com.hdl.sdk.link.core.config.HDLLinkConfig; +import com.hdl.sdk.link.core.connect.HDLConnectHelper; import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import com.hdl.sdk.link.gateway.type.GatewayMasterType; @@ -60,6 +66,7 @@ return sHdlDeviceLogic; } + /** * 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�) */ @@ -81,64 +88,55 @@ return newList; } - /** - * 鑾峰彇褰撳墠浣忓畢鐨勩�愪富銆戦�嗗彉鍣� - */ - public GatewayBean getCurrentHomeMainGateway(String homeId) { - return queryCurrentHomeMainGateway(this.getCurrentHomeGatewayList(homeId), homeId); - } - - /** - * 鏌ヨ褰撳墠浣忓畢鐨勩�愪富銆戦�嗗彉鍣� - */ - public GatewayBean queryCurrentHomeMainGateway(List<GatewayBean> list, String homeId) { - if (list == null || list.size() == 0) { - return null; - } - GatewayBean findGatewayBean = null; - for (int i = 0; i < list.size(); i++) { - GatewayBean gatewayBean = list.get(i); - if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) && gatewayBean.getHomeId().equals(homeId)) { - //鎵惧埌杩斿洖 - findGatewayBean = gatewayBean; - break; - } - } - return findGatewayBean; - } - /** * 閫嗗彉鍣ㄤ笂浼犳暟鎹埌浜戠(鍖呮嫭:sid锛宱id) * * @param homeId 浣忓畢id - * @param mac 璁惧mac + * @param list 閫嗗彉鍣ㄥ垪琛� */ - public void uploadDataToCloud(String homeId, String mac, CloudCallBeak<Boolean> callBeak) { - getInverterOidList(mac, new LinkCallBack<List<OidBean>>() { - @Override - public void onSuccess(List<OidBean> obj) { - if (obj == null) { - return; + public void uploadDataToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> callBeak) { + if (list == null || list.size() == 0) { + return; + } + List<OidBean> oidList = new ArrayList<>(); + AtomicInteger atomicInteger = new AtomicInteger(0); + for (int i = 0; i < list.size(); i++) { + atomicInteger.set(atomicInteger.get() + 1); + GatewayBean gatewayBean = list.get(i); + if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) { + continue; + } + getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() { + @Override + public void onSuccess(List<OidBean> oidBeanList) { + if (oidBeanList == null) { + return; + } + oidList.addAll(oidBeanList); + if (atomicInteger.get() == list.size()) { + //鍏ㄩ儴鑾峰彇鍚庡啀涓婁紶 + fullUpdateOid(homeId, oidList, new CloudCallBeak<Boolean>() { + @Override + public void onSuccess(Boolean obj) { + HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac(), true); + } + + @Override + public void onFailure(HDLException e) { + HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); + } + }); + } } - fullUpdateOid(homeId, obj, new CloudCallBeak<Boolean>() { - @Override - public void onSuccess(Boolean obj) { - HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�-->" + homeId + "--->" + mac, true); - } - @Override - public void onFailure(HDLException e) { - HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); - } - }); - } + @Override + public void onError(HDLLinkException e) { + HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); + } + }); + } - @Override - public void onError(HDLLinkException e) { - HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); - } - }); } @@ -170,7 +168,52 @@ if (cloudCallBeak != null) { cloudCallBeak.onSuccess(true); //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔� - uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), mac, null); + List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId); + uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null); + } + } + + @Override + public void onFailure(HDLException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + } + + /** + * 娣诲姞澶氫釜閫嗗彉鍣ㄥ埌浜戠涓� + * + * @param list 閫嗗彉鍣ㄥ垪琛� + * @param cloudCallBeak - + */ + public void addAllInverterDeviceToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> cloudCallBeak) { + + String requestUrl = HttpApi.POST_Device_Add_All; + JsonObject json = new JsonObject(); + json.addProperty("homeId", homeId); + JsonArray ary = new JsonArray(); + for (int i = 0; i < list.size(); i++) { + GatewayBean gatewayBean = list.get(i); + JsonObject inverterInfo = new JsonObject(); + inverterInfo.addProperty("mac", gatewayBean.getDevice_mac()); + inverterInfo.addProperty("spk", gatewayBean.getGatewayType()); + inverterInfo.addProperty("sid", gatewayBean.getSid()); + inverterInfo.addProperty("oid", gatewayBean.getOid()); + inverterInfo.addProperty("name", gatewayBean.getDevice_name()); + ary.add(inverterInfo); + } + json.add("devices", ary); + // json.addProperty("zoneType", "password");//鍖哄煙 + + HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { + @Override + public void onSuccess(String str) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + //涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔� + uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null); } } @@ -332,7 +375,6 @@ cloudCallBeak.onSuccess(true); } - HdlLogLogic.print("鍏ㄩ噺鏇存柊oid鍒颁簯绔垚鍔�--->", true); } @@ -341,7 +383,6 @@ if (cloudCallBeak != null) { cloudCallBeak.onFailure(e); } - HdlLogLogic.print("鍏ㄩ噺鏇存柊oid鍒颁簯绔け璐�--->" + e.getMsg() + "(" + e.getCode() + ")", true); } }); @@ -444,7 +485,7 @@ * 缃戝叧鏃堕棿璇诲彇 * * @param mac 璁惧mac - * @param linkCallBack 鍥炶皟update + * @param linkCallBack 鍥炶皟updatetime */ public void getGatewayTime(String mac, LinkCallBack<DeviceTimeBean> linkCallBack) { String requestUrl = TopicApi.GET_GATEWAY_TIME; @@ -484,13 +525,22 @@ * @param mac 璁惧mac * @param date 鏃ユ湡 * @param time 鏃堕棿 + * @param timezone 鏃跺尯 * @param linkCallBack 鍥炶皟update */ - public void editGatewayTime(String mac, String date, String time, LinkCallBack<Boolean> linkCallBack) { + public void editGatewayTime(String mac, String date, String time, String timezone, LinkCallBack<Boolean> linkCallBack) { String requestUrl = TopicApi.SET_GATEWAY_TIME_EDIT; JsonObject json = new JsonObject(); - json.addProperty("date", date);// "2020-08-15" - json.addProperty("time", time);//"17:25:20" + if (!TextUtils.isEmpty(date)) { + json.addProperty("date", date);// "2020-08-15" + } + if (!TextUtils.isEmpty(time)) { + json.addProperty("time", time);//"17:25:20" + } + if (!TextUtils.isEmpty(timezone)) { + json.addProperty("timezone", timezone);//鏃跺尯(璇泙https://hdl-gz.yuque.com/wnkbmh/cdrglh/yckkyp#qWOPS) + } + TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { @Override public void onSuccess(String msg) { @@ -518,7 +568,7 @@ public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) { String requestUrl = TopicApi.SET_GATEWAY_EDIT; JsonObject json = new JsonObject(); - json.addProperty("master", GatewayMasterType.MasterTrue); + json.addProperty("master", GatewayMasterType.MasterFalse); TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { @Override public void onSuccess(String msg) { @@ -570,6 +620,68 @@ }); } + + /** + * 鍒濆鍖栭�嗗彉鍣� + * + * @param mac 缃戝叧mac + */ + public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) { + String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE; + JsonObject sendJsonObj = new JsonObject(); + JsonObject jObject = new JsonObject(); + jObject.addProperty("device_mac", mac); + jObject.addProperty("reset_factory", "true");//涓篺alse鎴栨棤姝ゅ瓧娈碉紝鍒欎负"娓呴櫎鏁版嵁" + sendJsonObj.add("objects", jObject); + TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, sendJsonObj, "", new HDLLinkCallBack() { + @Override + public void onSuccess(String json) { + if (linkCallBack != null) { + linkCallBack.onSuccess(true); + } + } + + @Override + public void onError(HDLLinkException e) { + if (linkCallBack != null) { + linkCallBack.onError(e); + } + } + }); + + } + + + /** + * 鍒犻櫎oid + * + * @param mac 缃戝叧mac + * @param oid 璁惧oid + */ + public void deleteOid(String mac, String oid, LinkCallBack<Boolean> linkCallBack) { + String requestUrl = TopicApi.DELETING_GATEWAY_SLAVE; + JsonArray jsonArray = new JsonArray(); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("oid", oid);//璁惧oid + jsonArray.add(jsonObject); + TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonArray, "", new HDLLinkCallBack() { + @Override + public void onSuccess(String json) { + if (linkCallBack != null) { + linkCallBack.onSuccess(true); + } + } + + @Override + public void onError(HDLLinkException e) { + if (linkCallBack != null) { + linkCallBack.onError(e); + } + } + }); + + } + /** * 鑾峰彇閫嗗彉鍣╫id鍒楄〃 @@ -763,7 +875,7 @@ cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); } } - HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触->msg->" + e.getMsg() + "(" + e.getCode() + ")"); + HdlLogLogic.print("鑾峰彇璁惧杩滅▼閫氳淇℃伅澶辫触--->msg--->" + e.getMsg() + "(" + e.getCode() + ")"); } }); } @@ -843,6 +955,7 @@ JsonObject json = new JsonObject(); json.addProperty("homeId", ""); json.addProperty("server_addr", ""); + json.addProperty("local_secret", ""); TcpClient.getInstance().sendDataToLinkGateway(mac, true, requestUrl, json, "", new HDLLinkCallBack() { @Override public void onSuccess(String msg) { @@ -885,9 +998,10 @@ * * @param gatewayCallBack - */ - public void searchAllGateway(GatewayCallBack gatewayCallBack) { + public void searchAllNetworkGateway(GatewayCallBack gatewayCallBack) { + List<String> spks = this.getGatewaySpk(); //缃戝叧鎼滅储 - HDLLinkLocalSdk.getInstance().refreshGateway(gatewayCallBack, this.getGatewaySpk()); + HDLLinkLocalGateway.getInstance().refreshGatewayBySpk(spks, true, gatewayCallBack); } /** -- Gitblit v1.8.0