From 3e904bfa8a1bb53dcf461e5c717f9b808e179245 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 08 一月 2025 16:27:48 +0800
Subject: [PATCH] 2025年01月08日16:27:46
---
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 326 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 283 insertions(+), 43 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 684048c..f5eb2c4 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -3,14 +3,13 @@
import android.os.SystemClock;
import android.text.TextUtils;
-import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
-
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.photovoltaic.bean.InverterBean;
+import com.hdl.photovoltaic.bean.LocalResponse;
import com.hdl.photovoltaic.bean.PageNumberObject;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
@@ -22,6 +21,7 @@
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.DeviceInfoBean;
import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo;
import com.hdl.photovoltaic.ui.bean.DeviceTimeBean;
import com.hdl.photovoltaic.ui.bean.NotRunBean;
@@ -34,7 +34,6 @@
import com.hdl.sdk.link.core.config.HDLLinkConfig;
import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
import com.hdl.sdk.link.gateway.type.GatewayMasterType;
-import com.huawei.hms.support.api.entity.core.JosBaseReq;
import java.lang.reflect.Type;
@@ -912,7 +911,7 @@
* @param mac 缃戝叧mac
* @param linkCallBack 鍥炶皟
*/
- public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) {
+ public void getGatewayInfo(String mac, LinkCallBack<InverterBean> linkCallBack) {
String requestUrl = TopicApi.GET_GATEWAY_INFO;
JsonObject json = new JsonObject();
json.addProperty("device_mac", mac);
@@ -928,11 +927,11 @@
}
Gson gson = new Gson();
- Type typeOfT = new TypeToken<BaseLocalResponse<GatewayBean>>() {
+ Type typeOfT = new TypeToken<BaseLocalResponse<InverterBean>>() {
}.getType();
- BaseLocalResponse<GatewayBean> baseLocalResponse = gson.fromJson(json, typeOfT);
+ BaseLocalResponse<InverterBean> baseLocalResponse = gson.fromJson(json, typeOfT);
if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) {
- linkCallBack.onSuccess(new GatewayBean());
+ linkCallBack.onSuccess(new InverterBean());
} else {
linkCallBack.onSuccess(baseLocalResponse.getObjects());
}
@@ -1061,36 +1060,107 @@
* @param cloudCallBeak 杩斿洖閫嗗彉鍣ㄥ垪琛�
*/
public void getCurrentHomeLocalAndCloudGatewayList(String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
- HdlDeviceLogic.getInstance().searchCurrentHomeGateway(homeId, new GatewayCallBack() {
+ searchCurrentHomeGateway(homeId, new GatewayCallBack() {
@Override
public void onSuccess(List<GatewayBean> gatewayBeanList) {
//灞�鍩熺綉鏈�2绉嶆儏鍐�(1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�2:鏈夊眬鍩熺綉锛屾病鏈夊缃�);
- HdlDeviceLogic.getInstance().getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
+ getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
@Override
- public void onSuccess(List<CloudInverterDeviceBean> list) {
- List<String> removeSidList = new ArrayList<>();
- 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());
+ public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) {
+ //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛�
+ getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ @Override
+ public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+ if (loadCentreDeviceList != null) {
+ //鍚堝苟璐熻浇涓績璁惧鍒楄〃锛岀劧鍚庡湪涓�璧峰仛澶勭悊
+ inverterDeviceList.addAll(loadCentreDeviceList);
+ }
+ List<String> removeSidList = new ArrayList<>();
+ for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+ if (querySidInverter(inverterDeviceList, gatewayBean.getSid())) {
+ //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+ removeSidList.add(gatewayBean.getSid());
+ }
+ }
+ for (int i = 0; i < removeSidList.size(); i++) {
+ //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
+ removeLocalInverter(removeSidList.get(i));
+ }
+ //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
+ setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
}
- }
- for (int i = 0; i < removeSidList.size(); i++) {
- //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
- removeLocalInverter(removeSidList.get(i));
- }
- //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
- setDeviceRemoteInfo(list, homeId, cloudCallBeak);
+
+ @Override
+ public void onFailure(HDLException e) {
+ //鍚戜簯绔幏鍙栬礋杞戒腑蹇冭澶囧垪琛ㄥけ璐ュ悗锛屼粛鐒跺鐞嗛�嗗彉鍣ㄨ澶囧垪琛�
+ List<String> removeSidList = new ArrayList<>();
+ for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+ if (querySidInverter(inverterDeviceList, gatewayBean.getSid())) {
+ //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+ removeSidList.add(gatewayBean.getSid());
+ }
+ }
+ for (int i = 0; i < removeSidList.size(); i++) {
+ //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
+ removeLocalInverter(removeSidList.get(i));
+ }
+ //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
+ setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak);
+ }
+ });
+
+
}
@Override
public void onFailure(HDLException e) {
///鎯呭喌2:鏈夊眬鍩熺綉锛屾病鏈夊缃�;
//鏈湴鏈夐�嗗彉鍣ㄥ垪琛�,鑾峰彇浜戠缁戝畾閫嗗彉鍣ㄥけ璐�,榛樿杩斿洖鏈湴閫嗗彉鍣ㄥ垪琛�;
- if (cloudCallBeak != null) {
- cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
- }
+ //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛�
+ getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ @Override
+ public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+ if (loadCentreDeviceList == null) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
+ }
+ return;
+ }
+ List<String> removeSidList = new ArrayList<>();
+ for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) {
+ GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j);
+ if (gatewayBean.getSpk().equals(INVERTER_DEVICE_SPK)) {
+ //涓嶆槸璐熻浇涓績鐨剆pk涓嶅仛澶勭悊锛�
+ continue;
+ }
+ if (querySidInverter(loadCentreDeviceList, gatewayBean.getSid())) {
+ //鏈湴鏈夛紝浜戠娌℃湁,鍒犻櫎鏈湴锛�
+ removeSidList.add(gatewayBean.getSid());
+ }
+ }
+ for (int i = 0; i < removeSidList.size(); i++) {
+ //鍒犻櫎鏈湴鐨勯�嗗彉鍣�
+ removeLocalInverter(removeSidList.get(i));
+ }
+ //鎯呭喌1:鏈夊眬鍩熺綉锛屾湁澶栫綉锛�
+ setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ //鍚戜簯绔幏鍙栬礋杞戒腑蹇冭澶囧垪琛ㄥけ璐ュ悗锛岄粯璁よ繑鍥炴湰鍦伴�嗗彉鍣ㄥ垪琛�;
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
+ }
+ }
+ });
+
+// if (cloudCallBeak != null) {
+// cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId));
+// }
}
});
}
@@ -1098,19 +1168,63 @@
@Override
public void onError(HDLLinkException e) {
//澶栫綉鍙湁1绉嶆儏鍐�(鏈湴鎼滅储閫嗗彉鍣ㄥ垪琛ㄥけ璐ヤ簡)
- HdlDeviceLogic.getInstance().getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛�
+ getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
@Override
- public void onSuccess(List<CloudInverterDeviceBean> list) {
- //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
- HDLLinkLocalGateway.getInstance().getGatewayList().clear();
- setDeviceRemoteInfo(list, homeId, cloudCallBeak);
+ public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) {
+ //鍐嶅悜浜戠鑾峰彇璐熻浇涓績鍒楄〃
+ getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ @Override
+ public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+ //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
+ HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+ List<CloudInverterDeviceBean> newList = new ArrayList<>();
+ if (cloudInverterList != null) {
+ newList.addAll(cloudInverterList);
+ }
+ if (loadCentreDeviceList != null) {
+ newList.addAll(loadCentreDeviceList);
+ }
+ //閫嗗彉鍣ㄥ垪琛ㄥ拰璐熻浇涓績鍒楄〃鐩稿姞
+ setDeviceRemoteInfo(newList, homeId, cloudCallBeak);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
+ //鍚戜簯绔幏鍙栬礋杞戒腑蹇冨垪琛ㄥけ璐�,鐩存帴杩斿洖閫嗗彉鍣ㄥ垪琛紱
+ HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+ setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak);
+ }
+ });
+// //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
+// HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+// setDeviceRemoteInfo(list, homeId, cloudCallBeak);
}
@Override
public void onFailure(HDLException e) {
- if (cloudCallBeak != null) {
- cloudCallBeak.onFailure(e);
- }
+ //鍚戜簯绔幏鍙栭�嗗彉鍣ㄥ垪琛ㄥけ璐�
+ //鍐嶅悜浜戠鑾峰彇璐熻浇涓績鍒楄〃
+ getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
+ @Override
+ public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) {
+ //澶栫綉杩涙潵鍏堛�愰粯璁ゃ�戞竻绌烘湰鍦伴�嗗彉鍣ㄥ垪琛�
+ HDLLinkLocalGateway.getInstance().getGatewayList().clear();
+ //閫嗗彉鍣ㄥ垪琛ㄥ拰璐熻浇涓績鍒楄〃
+ setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+// if (cloudCallBeak != null) {
+// cloudCallBeak.onFailure(e);
+// }
}
});
}
@@ -1168,19 +1282,21 @@
}
/**
- * 閫氳繃sid鏌ヨ閫嗗彉鍣�
+ * 閫氳繃sid鏌ヨ閫嗗彉鍣ㄦ槸鍚﹀瓨缁戝畾鍦ㄤ簯绔�
*
* @param list 浜戠涓婇�嗗彉鍣ㄥ垪琛�
- * @return 瀛樺湪涓簍rue, 鍚﹀垯涓篺alse
+ * @return true涓嶅瓨鍦紝鍚﹀垯瀛樺湪
*/
private boolean querySidInverter(List<CloudInverterDeviceBean> list, String sid) {
+ int exists_value = -1;
for (int i = 0; i < list.size(); i++) {
CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
if (sid.equals(cloudInverterDeviceBean.getSid())) {
- return true;
+ exists_value = 1;
+ break;
}
}
- return false;
+ return exists_value == -1;
}
/**
@@ -1428,11 +1544,11 @@
* @param homeId 鐢电珯id
* @param arrayList 璁惧id鏁扮粍
*/
- public void setDeviceStartup(String homeId, String arrayList, CloudCallBeak<Boolean> cloudCallBeak) {
+ public void setDeviceStartup(String homeId, JsonArray arrayList, CloudCallBeak<Boolean> cloudCallBeak) {
String requestUrl = HttpApi.POST_Device_startup;
JsonObject json = new JsonObject();
json.addProperty("homeId", homeId);
- json.addProperty("deviceIds", arrayList);
+ json.add("deviceIds", arrayList);
// json.addProperty("zoneType", "password");//鍖哄煙
HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
@@ -1448,6 +1564,122 @@
public void onFailure(HDLException e) {
if (cloudCallBeak != null) {
cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+
+ /**
+ * 鑾峰彇璁惧璇︽儏
+ *
+ * @param homeId 鐢电珯id
+ * @param arrayList 璁惧id鏁扮粍
+ */
+ public void getDeviceInfo(String homeId, JsonArray arrayList, CloudCallBeak<List<DeviceInfoBean>> cloudCallBeak) {
+ String requestUrl = HttpApi.POST_Device_info;
+ JsonObject json = new JsonObject();
+ json.addProperty("homeId", homeId);
+ json.add("deviceIds", arrayList);
+ // json.addProperty("zoneType", "password");//鍖哄煙
+
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String jsonStr) {
+ if (TextUtils.isEmpty(jsonStr)) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(new ArrayList<>());
+ }
+ return;
+ }
+ Gson gson = new Gson();
+ List<DeviceInfoBean> list = gson.fromJson(jsonStr, new TypeToken<List<DeviceInfoBean>>() {
+ }.getType());
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(list);
+ }
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+
+
+ /**
+ * 鑾峰彇鐢电珯涓嬭礋杞芥帶鍒朵腑蹇冨垪琛�
+ *
+ * @param homeId 鐢电珯id
+ */
+ public void getLoadCentreDeviceList(String homeId, CloudCallBeak<List<CloudInverterDeviceBean>> cloudCallBeak) {
+ String requestUrl = HttpApi.POST_Device_loadCentreDevices;
+ JsonObject json = new JsonObject();
+ json.addProperty("homeId", homeId);
+ // json.addProperty("zoneType", "password");//鍖哄煙
+
+ HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
+ @Override
+ public void onSuccess(String jsonStr) {
+ if (TextUtils.isEmpty(jsonStr)) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onSuccess(new ArrayList<>());
+ }
+ }
+ 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(HDLException e) {
+ if (cloudCallBeak != null) {
+ cloudCallBeak.onFailure(e);
+ }
+ }
+ });
+ }
+
+ /**
+ * 閫嗗彉鍣ㄥ瘑鐮佺櫥褰�
+ *
+ * @param mac 閫嗗彉鍣╩ac
+ * @param password 閫嗗彉鍣ㄥ瘑鐮�
+ */
+ public void getPasswordVerification(String mac, String password, LinkCallBack<LocalResponse> callBeak) {
+ String requestUrl = TopicApi.DELETING_GATEWAY_password_verifiy;
+ JsonObject json = new JsonObject();
+ json.addProperty("password", password);
+ json.addProperty("mac", mac);
+ TcpClient.getInstance().sendDataToLinkGateway(mac, false, requestUrl, json, "", new HDLLinkCallBack() {
+ @Override
+ public void onSuccess(String msg) {
+ try {
+
+ Gson gson = new Gson();
+ LocalResponse localResponse = gson.fromJson(msg, LocalResponse.class);
+ if (localResponse == null) {
+ localResponse = new LocalResponse();
+ }
+ if (callBeak != null) {
+ callBeak.onSuccess(localResponse);
+ }
+ } catch (Exception e) {
+ if (callBeak != null) {
+ callBeak.onSuccess(new LocalResponse());
+ }
+ }
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ if (callBeak != null) {
+ callBeak.onError(e);
}
}
});
@@ -1515,7 +1747,8 @@
*/
public List<String> getGatewaySpk() {
List<String> spks = new ArrayList<>();
- spks.add(DEVICE_SPK);
+ spks.add(INVERTER_DEVICE_SPK);
+ spks.add(LC_SPK);
return spks;
}
@@ -1531,5 +1764,12 @@
return false;
}
- public final String DEVICE_SPK = "energy.hdl_inverter";
+ /**
+ * 閫嗗彉鍣╯pk
+ */
+ public final String INVERTER_DEVICE_SPK = "energy.hdl_inverter";
+ /**
+ * 璐熻浇涓績spk
+ */
+ public final String LC_SPK = "energy.hdl_lc";
}
--
Gitblit v1.8.0