From 0a18a8180bc6040c941b07df1be1f7b726b4c155 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期一, 21 八月 2023 14:19:26 +0800
Subject: [PATCH] Merge branch 'master' into wjc
---
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 328 ++++++++++++++++++++++++++++++++++++++++++++++--------
1 files changed, 278 insertions(+), 50 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 6ecf796..1cc6471 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -1,11 +1,15 @@
package com.hdl.photovoltaic.other;
+import android.text.TextUtils;
+
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.hdlhttp.HxHttp;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.bean.HttpResponsePack;
+import com.hdl.photovoltaic.bean.LocalResponse;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
@@ -14,6 +18,7 @@
import com.hdl.photovoltaic.internet.api.TopicApi;
import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak;
import com.hdl.photovoltaic.listener.CloudCallBeak;
+import com.hdl.photovoltaic.listener.LinkCallBack;
import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean;
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
import com.hdl.photovoltaic.ui.bean.InverterDeviceBean;
@@ -40,6 +45,26 @@
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.getHomeId())
+ && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
+ newList.add(gatewayBean);
+ }
+
+ }
+ }
+ return newList;
+
+ }
+
+ /**
* 鑾峰彇褰撳墠瀵硅薄
*
* @return HdlDeviceLogic
@@ -57,16 +82,16 @@
}
/**
- * 娣诲姞閫嗗彉鍣�
+ * 娣诲姞閫嗗彉鍣ㄥ埌浜戠涓�
*
* @param mac -
* @param spk -
* @param sid -
* @param oid -
* @param name -
- * @param cloudCallBeak
+ * @param cloudCallBeak -
*/
- public void addInverterDevice(String mac, String spk, String sid, String oid, String name, CloudCallBeak<Boolean> cloudCallBeak) {
+ public void addInverterDeviceToCloud(String mac, String spk, String sid, String oid, String name, CloudCallBeak<Boolean> cloudCallBeak) {
String requestUrl = HttpApi.POST_Device_Add;
JsonObject json = new JsonObject();
@@ -78,56 +103,60 @@
json.addProperty("name", name);
// json.addProperty("zoneType", "password");//鍖哄煙
- HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@Override
- public void onSuccess(HttpResponsePack httpResponsePack) {
+ public void onSuccess(String str) {
if (cloudCallBeak != null) {
cloudCallBeak.onSuccess(true);
}
}
@Override
- public void onFailure(Exception exception) {
+ public void onFailure(HDLException e) {
if (cloudCallBeak != null) {
- cloudCallBeak.onFailure(exception);
+ cloudCallBeak.onFailure(e);
}
}
});
}
/**
- * 鑾峰彇閫嗗彉鍣ㄥ垪琛�
+ * 鑾峰彇浜戠閫嗗彉鍣ㄥ垪琛�
*
* @param homeId 浣忓畢id
* @param cloudCallBeak 鍥炶皟
*/
- public void getInverterDeviceList(String homeId, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) {
+ public void getCloudInverterDeviceList(String homeId, CloudCallBeak<List<CloudInverterDeviceBean>> cloudCallBeak) {
String requestUrl = HttpApi.POST_Device_List;
JsonObject json = new JsonObject();
json.addProperty("homeId", homeId);
// json.addProperty("zoneType", "password");//鍖哄煙
- HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@Override
- public void onSuccess(HttpResponsePack httpResponsePack) {
- if (httpResponsePack != null && httpResponsePack.getData() != null) {
- Gson gson = new Gson();
- String json = gson.toJson(httpResponsePack.getData());
- CloudInverterDeviceBean loginUserRegionBean = new Gson().fromJson(json, CloudInverterDeviceBean.class);
+ public void onSuccess(String jsonStr) {
+ if (TextUtils.isEmpty(jsonStr)) {
if (cloudCallBeak != null) {
- cloudCallBeak.onSuccess(loginUserRegionBean);
+ cloudCallBeak.onSuccess(null);
}
+ }
+ Type type = new TypeToken<List<CloudInverterDeviceBean>>() {
+ }.getType();
+ List<CloudInverterDeviceBean> list = new Gson().fromJson(jsonStr, type);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
}
}
@Override
- public void onFailure(Exception exception) {
+ public void onFailure(HDLException e) {
if (cloudCallBeak != null) {
- cloudCallBeak.onFailure(exception);
+ cloudCallBeak.onFailure(e);
}
}
});
}
+
/**
* 鍒犻櫎閫嗗彉鍣�
@@ -142,18 +171,18 @@
json.addProperty("deviceId", deviceId);
// json.addProperty("zoneType", "password");//鍖哄煙
- HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@Override
- public void onSuccess(HttpResponsePack httpResponsePack) {
+ public void onSuccess(String str) {
if (cloudCallBeak != null) {
cloudCallBeak.onSuccess(true);
}
}
@Override
- public void onFailure(Exception exception) {
+ public void onFailure(HDLException e) {
if (cloudCallBeak != null) {
- cloudCallBeak.onFailure(exception);
+ cloudCallBeak.onFailure(e);
}
}
});
@@ -172,25 +201,28 @@
json.addProperty("parentOid", parentOid);
// json.addProperty("zoneType", "password");//鍖哄煙
- HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@Override
- public void onSuccess(HttpResponsePack httpResponsePack) {
- if (httpResponsePack != null && httpResponsePack.getData() != null) {
- Gson gson = new Gson();
- String json = gson.toJson(httpResponsePack.getData());
- Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() {
- }.getType();
- List<CloudInverterChildDeviceBean> list = gson.fromJson(json, typeOfT);
+ public void onSuccess(String jsonStr) {
+ if (TextUtils.isEmpty(jsonStr)) {
if (cloudCallBeak != null) {
- cloudCallBeak.onSuccess(list);
+ cloudCallBeak.onSuccess(null);
}
+ return;
+ }
+ Gson gson = new Gson();
+ Type typeOfT = new TypeToken<List<CloudInverterChildDeviceBean>>() {
+ }.getType();
+ List<CloudInverterChildDeviceBean> list = gson.fromJson(jsonStr, typeOfT);
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
}
}
@Override
- public void onFailure(Exception exception) {
+ public void onFailure(HDLException e) {
if (cloudCallBeak != null) {
- cloudCallBeak.onFailure(exception);
+ cloudCallBeak.onFailure(e);
}
}
});
@@ -225,9 +257,9 @@
json.add("devices", jsonArray);
// json.addProperty("zoneType", "password");//鍖哄煙
- HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() {
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@Override
- public void onSuccess(HttpResponsePack httpResponsePack) {
+ public void onSuccess(String str) {
if (cloudCallBeak != null) {
cloudCallBeak.onSuccess(true);
@@ -236,9 +268,9 @@
}
@Override
- public void onFailure(Exception exception) {
+ public void onFailure(HDLException e) {
if (cloudCallBeak != null) {
- cloudCallBeak.onFailure(exception);
+ cloudCallBeak.onFailure(e);
}
}
});
@@ -249,24 +281,36 @@
/**
* 璁剧疆缃戝叧杩滅▼鍙傛暟
*
- * @param mac 璁惧mac
- * @param cloudCallBeak 鍥炶皟update
+ * @param mac 璁惧mac
+ * @param linkCallBack 鍥炶皟update
*/
- public void steGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) {
- String requestUrl = TopicApi.GATEWAY_SEND_REMOTE_EDIT;
+ public void setGatewayRemoteParam(String mac, LinkCallBack<Boolean> linkCallBack) {
+ String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT;
JsonObject json = new JsonObject();
json.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
json.addProperty("server_addr", AppConfigManage.getUserRegionUrl());
json.addProperty("local_secret", UserConfigManage.getInstance().getLocalSecret());
- TcpClient.getInstance().sendDataToLinkGateway(mac, true, requestUrl, json, "", new HDLLinkCallBack() {
+ //瑙e瘑璐熻浇鏁版嵁(鍥犱负鍐欏瘑閽ョ粰缃戝叧涓�瀹氭槑鏂囷紝鍥犱负閭f椂缃戝叧杩樻病鏈夊瘑閽�)
+ TcpClient.getInstance().sendDataToLinkGateway(mac, false, requestUrl, json, "", new HDLLinkCallBack() {
@Override
public void onSuccess(String msg) {
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac);
+ if (gatewayBean != null) {
+ if (!TextUtils.isEmpty(UserConfigManage.getInstance().getLocalSecret())) {
+ gatewayBean.setLocalEncrypt(true);
+ }
+ }
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(true);
+ }
}
@Override
public void onError(HDLLinkException e) {
-
+ if (linkCallBack != null) {
+ linkCallBack.onError(e);
+ }
}
});
}
@@ -274,22 +318,26 @@
/**
* 缂栬緫缃戝叧鍙傛暟
*
- * @param mac 璁惧mac
- * @param cloudCallBeak 鍥炶皟update
+ * @param mac 璁惧mac
+ * @param linkCallBack 鍥炶皟update
*/
- public void editGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) {
- String requestUrl = TopicApi.GATEWAY_SEND_EDIT;
+ public void editGatewayParam(String mac, LinkCallBack<Boolean> linkCallBack) {
+ String requestUrl = TopicApi.SET_GATEWAY_EDIT;
JsonObject json = new JsonObject();
json.addProperty("master", "true");
- TcpClient.getInstance().sendDataToLinkGateway(mac, true, requestUrl, json, "", new HDLLinkCallBack() {
+ TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() {
@Override
public void onSuccess(String msg) {
-
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(true);
+ }
}
@Override
public void onError(HDLLinkException e) {
-
+ if (linkCallBack != null) {
+ linkCallBack.onError(e);
+ }
}
});
@@ -297,6 +345,186 @@
/**
+ * 鑾峰彇缃戝叧璇︽儏淇℃伅
+ *
+ * @param mac 缃戝叧mac
+ * @param linkCallBack 鍥炶皟
+ */
+ public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) {
+ String requestUrl = TopicApi.GET_GATEWAY_INFO;
+ TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
+ @Override
+ public void onSuccess(String json) {
+ if (TextUtils.isEmpty(json)) {
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(null);
+ }
+ return;
+ }
+ Gson gson = new Gson();
+ GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class);
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(gatewayBean);
+ }
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ if (linkCallBack != null) {
+ linkCallBack.onError(e);
+ }
+ }
+ });
+
+ }
+
+ /**
+ * 鑾峰彇缃戝叧oid鍒楄〃
+ *
+ * @param mac 缃戝叧mac
+ * @param linkCallBack 鍥炶皟
+ */
+ public void getGatewayOidList(String mac, LinkCallBack<List<OidBean>> linkCallBack) {
+ String requestUrl = TopicApi.GET_GATEWAY_OID_LIST;
+ TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
+ @Override
+ public void onSuccess(String json) {
+ if (TextUtils.isEmpty(json)) {
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(null);
+ }
+ return;
+ }
+ Gson gson = new Gson();
+ Type typeOfT = new TypeToken<List<OidBean>>() {
+ }.getType();
+ List<OidBean> list = gson.fromJson(json, typeOfT);
+ if (linkCallBack != null) {
+ linkCallBack.onSuccess(list);
+ }
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ if (linkCallBack != null) {
+ linkCallBack.onError(e);
+ }
+ }
+ });
+
+ }
+
+ /**
+ * 鑾峰彇鏈湴璁惧鍒楄〃
+ * 娉ㄦ剰:鏈夊缃戜互浜戠璁惧涓哄噯,鏈湴瀛樺湪锛屼簯绔病鏈夊垯鍒犻櫎锛涘唴缃戜互鏈湴涓轰富,鎼滅储澶氬皯涓澶囧氨鏄剧ず澶氬皯涓紱
+ *
+ * @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 || list.size() == 0) {
+// //浜戠娌℃湁缁戝畾閫嗗彉鍣�,浠ユ湰鍦颁负涓�;
+// 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(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+
+ @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 || 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(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+ });
+ }
+
+ /**
+ * 鍒犻櫎鏈湴閫嗗彉鍣�
+ *
+ * @param sid 璁惧sid
+ */
+ private void removeInverter(String sid) {
+ //鑾峰彇鏈湴鐨勬绫虫尝
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid);
+ if (gatewayBean != null) {
+ HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean);
+ }
+ }
+
+ /**
* 鎼滅储缃戝叧鍒楄〃
*
* @param gatewayCallBack -
--
Gitblit v1.8.0