From 788c70114287306db20e9a4539018d6e32fb5cb7 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 19 四月 2024 10:10:10 +0800
Subject: [PATCH] Merge branch 'wjc_new' into develop_new
---
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 316 +++++++++++++++++++++++++++++++++++++++++++---------
1 files changed, 262 insertions(+), 54 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 d656e12..d364f58 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -1,7 +1,9 @@
package com.hdl.photovoltaic.other;
+import android.os.SystemClock;
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 +23,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;
@@ -35,7 +42,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-
/**
@@ -61,6 +67,7 @@
return sHdlDeviceLogic;
}
+
/**
* 鑾峰彇褰撳墠浣忓畢鐨勯�嗗彉鍣ㄥ垪琛�(鍖呮嫭浠庣殑閫嗗彉鍣�)
*/
@@ -82,56 +89,183 @@
return newList;
}
+ /**
+ * 娣诲姞閫嗗彉鍣ㄥ埌缂撳瓨鍒楄〃閲岄潰鍘�
+ *
+ * @param homeId 鐢电珯id
+ * @param newGatewayBean 閫嗗彉鍣ㄥ璞�
+ */
+ public void addGatewayToLocalCacheMemory(String homeId, GatewayBean newGatewayBean) {
+ if (newGatewayBean == null || TextUtils.isEmpty(homeId)) {
+ return;
+ }
+ List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
+ if (list == null || list.size() == 0) {
+ return;
+ }
+ int index = -1;
+ for (int i = 0; i < list.size(); i++) {
+ GatewayBean gatewayBean = list.get(i);
+ if (gatewayBean.getDevice_mac().equals(newGatewayBean.getDevice_mac())) {
+ index = i;
+ break;
+ }
+ }
+ if (index > 0) {
+ list.remove(index);
+ list.add(index, newGatewayBean);
+
+ }
+ }
+
+ /**
+ * 绉婚櫎缂撳瓨鍒楄〃閲岄潰閫嗗彉鍣�
+ *
+ * @param homeId 鐢电珯id
+ * @param mac 閫嗗彉鍣╩ac
+ */
+ public void removeLocalCacheMemoryGateway(String homeId, String mac) {
+ if (TextUtils.isEmpty(mac)) {
+ return;
+ }
+ List<GatewayBean> list = getCurrentHomeGatewayList(homeId);
+ if (list == null || list.size() == 0) {
+ return;
+ }
+ int index = -1;
+ for (int i = 0; i < list.size(); i++) {
+ GatewayBean gatewayBean = list.get(i);
+ if (gatewayBean.getDevice_mac().equals(mac)) {
+ index = i;
+ break;
+ }
+ }
+ if (index > 0) {
+ list.remove(index);
+ }
+ }
+
/**
* 閫嗗彉鍣ㄤ笂浼犳暟鎹埌浜戠(鍖呮嫭:sid锛宱id)
*
- * @param homeId 浣忓畢id
- * @param list 閫嗗彉鍣ㄥ垪琛�
+ * @param homeId 浣忓畢id
+ * @param list 閫嗗彉鍣ㄥ垪琛�
+ * @param whetherToAdd true琛ㄧず鐢ㄥ閲�,false琛ㄧず鐢ㄥ叏閲�
*/
- public void uploadDataToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> callBeak) {
+ public void uploadOidDataToCloud(String homeId, List<GatewayBean> list, boolean whetherToAdd, 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() == oidList.size()) {
- //鍏ㄩ儴鑾峰彇鍚庡啀涓婁紶
- fullUpdateOid(homeId, oidList, new CloudCallBeak<Boolean>() {
+ if (whetherToAdd) {
+ for (int i = 0; i < list.size(); i++) {
+ 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) {
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->鏁版嵁鏄痭ull", true);
+ return;
+ }
+ //澧為噺娣诲姞oid
+ updateOidAdd(homeId, oidBeanList, new CloudCallBeak<Boolean>() {
@Override
public void onSuccess(Boolean obj) {
- HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac(), true);
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n鏁版嵁--->" + new Gson().toJson(oidBeanList), true);
}
@Override
public void onFailure(HDLException e) {
- HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_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) {
+ }
+ });
+ SystemClock.sleep(200);
+ }
+ } else {
+ //鍙湁杩涘叆璇︽儏鐣岄潰
+ List<OidBean> newOidList = new ArrayList<>();
+ AtomicInteger atomicInteger = new AtomicInteger(0);
+ for (int i = 0; i < list.size(); i++) {
+ 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) {
+ atomicInteger.set(atomicInteger.get() + 1);
+ if (oidBeanList == null) {
+ return;
+ }
+ newOidList.addAll(oidBeanList);
+ if (atomicInteger.get() == list.size()) {
+ if (newOidList.size() == 0) {
+ return;
+ }
+// //澧為噺娣诲姞oid
+// updateOidAdd(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, newOidList, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(鍏ㄩ噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n鏁版嵁--->" + new Gson().toJson(newOidList), true);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(鍏ㄩ噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+ }
+ });
+ }
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ atomicInteger.set(atomicInteger.get() + 1);
+ if (atomicInteger.get() == list.size()) {
+ if (newOidList.size() == 0) {
+ HdlLogLogic.print("鑾峰彇閫嗗彉鍣╫id鍒楄〃澶辫触--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+ return;
+ }
+ //澧為噺娣诲姞oid
+ updateOidAdd(homeId, newOidList, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔垚鍔�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n鏁版嵁--->" + new Gson().toJson(newOidList), true);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ HdlLogLogic.print("涓婁紶oid鍒楄〃鍒颁簯绔け璐�(澧為噺)--->浣忓畢id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
+ }
+ });
+ }
+ }
+ });
+ SystemClock.sleep(200);
+ }
}
-
-
}
/**
@@ -163,7 +297,7 @@
cloudCallBeak.onSuccess(true);
//涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId);
- uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null);
+ uploadOidDataToCloud(UserConfigManage.getInstance().getHomeId(), list, true, null);
}
}
@@ -179,7 +313,7 @@
/**
* 娣诲姞澶氫釜閫嗗彉鍣ㄥ埌浜戠涓�
*
- * @param list 閫嗗彉鍣ㄥ垪琛�
+ * @param list 閫嗗彉鍣ㄥ垪琛�
* @param cloudCallBeak -
*/
public void addAllInverterDeviceToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> cloudCallBeak) {
@@ -207,7 +341,7 @@
if (cloudCallBeak != null) {
cloudCallBeak.onSuccess(true);
//涓存椂鐨勯�昏緫锛屼笂浼爋id鍒楄〃鍒颁簯绔�
- uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), list, null);
+ uploadOidDataToCloud(homeId, list, true, null);
}
}
@@ -616,6 +750,68 @@
}
/**
+ * 鍒濆鍖栭�嗗彉鍣�
+ *
+ * @param mac 缃戝叧mac
+ */
+ public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) {
+ String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE;
+ JsonObject jObject = new JsonObject();
+ jObject.addProperty("device_mac", mac);
+ jObject.addProperty("reset_factory", "true");//涓篺alse鎴栨棤姝ゅ瓧娈碉紝鍒欎负"娓呴櫎鏁版嵁"
+ TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jObject, "", new HDLLinkCallBack() {
+ @Override
+ public void onSuccess(String json) {
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(true);
+ }
+ HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄦ垚鍔�-->mac:" + mac, true);
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ if (linkCallBack != null) {
+ linkCallBack.onError(e);
+ }
+ HdlLogLogic.print("鍒濆鍖栭�嗗彉鍣ㄥけ璐�-->mac:" + mac + "--->" + e.getMsg() + "(" + e.getCode() + ")", true);
+ }
+ });
+
+ }
+
+
+ /**
+ * 鍒犻櫎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鍒楄〃
*
* @param mac 缃戝叧mac
@@ -695,15 +891,11 @@
if (atomicInteger.get() == list.size()) {
//鏀堕泦鍒犻櫎閫嗗彉鍣╯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 j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+ if (!querySidInverter(list, gatewayBean.getSid())) {
+ //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+ removeSidList.add(gatewayBean.getSid());
}
}
for (int i = 0; i < removeSidList.size(); i++) {
@@ -723,15 +915,11 @@
if (atomicInteger.get() == list.size()) {
//鏀堕泦鍒犻櫎閫嗗彉鍣╯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 j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+ if (!querySidInverter(list, gatewayBean.getSid())) {
+ //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+ removeSidList.add(gatewayBean.getSid());
}
}
for (int i = 0; i < removeSidList.size(); i++) {
@@ -824,6 +1012,22 @@
});
}
});
+ }
+
+ /**
+ * 閫氳繃sid鏌ヨ閫嗗彉鍣�
+ *
+ * @param list 浜戠涓婇�嗗彉鍣ㄥ垪琛�
+ * @return 瀛樺湪涓簍rue, 鍚﹀垯涓篺alse
+ */
+ private boolean querySidInverter(List<CloudInverterDeviceBean> list, String sid) {
+ for (int i = 0; i < list.size(); i++) {
+ CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
+ if (sid.equals(cloudInverterDeviceBean.getSid())) {
+ return true;
+ }
+ }
+ return false;
}
/**
@@ -931,8 +1135,9 @@
* @param gatewayCallBack -
*/
public void searchAllNetworkGateway(GatewayCallBack gatewayCallBack) {
+ List<String> spks = this.getGatewaySpk();
//缃戝叧鎼滅储
- HDLLinkLocalSdk.getInstance().refreshGateway(gatewayCallBack, this.getGatewaySpk());
+ HDLLinkLocalGateway.getInstance().refreshGatewayBySpk(spks, true, gatewayCallBack);
}
/**
@@ -1070,7 +1275,10 @@
gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//瀛愮綉鍙�/璁惧鍙�,閫嗗彉鍣ㄥ湴鍧�
gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//鍙戠數鍔熺巼
gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//浠婃棩鍙戠數閲�
- gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//璁惧鍨嬪彿
+ if (!TextUtils.isEmpty(cloudInverterDeviceBean.getOmodel())) {
+ //鍙兘璁惧娌℃湁涓婃姤缁欎簯绔�,寤鸿缁戝畾閫嗗彉鍣ㄦ椂鍊欒拷鍔犱竴涓弬鏁�;
+ gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//璁惧鍨嬪彿
+ }
gatewayBean.setSpk(cloudInverterDeviceBean.getSpk());//璁惧spk
--
Gitblit v1.8.0