From 2b624347a56d7f50ce0be4aa085454a9f6a0dac6 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期一, 25 十二月 2023 10:12:00 +0800
Subject: [PATCH] 2023年12月25日10:11:49
---
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 121 ++++++++++++++++++++++++++--------------
1 files changed, 79 insertions(+), 42 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
index 1a0c645..20bb470 100644
--- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
+++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -2,8 +2,6 @@
import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.text.TextUtils;
@@ -15,7 +13,6 @@
import com.hdl.linkpm.sdk.ota.bean.CloudDeviceFirmwaresBean;
import com.hdl.linkpm.sdk.ota.bean.CloudGatewayDriversBean;
import com.hdl.linkpm.sdk.ota.bean.DeviceFirmwareBean;
-import com.hdl.linkpm.sdk.ota.bean.DownloadUrlBean;
import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean;
import com.hdl.linkpm.sdk.utils.HDLMD5Utils;
import com.hdl.photovoltaic.HDLApp;
@@ -23,7 +20,6 @@
import com.hdl.photovoltaic.bean.ModBusBean;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
-import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.listener.LinkCallBack;
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
@@ -32,6 +28,7 @@
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.AppManagerUtils;
+import com.hdl.photovoltaic.utils.NetworkUtils;
import com.hdl.photovoltaic.utils.WifiUtils;
import com.hdl.sdk.link.common.exception.HDLLinkCode;
import com.hdl.sdk.link.common.exception.HDLLinkException;
@@ -101,9 +98,9 @@
switch (type) {
//鍒涘缓鐢电珯
case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: {
-
//EventBus浜嬩欢鍒嗗彂
BaseEventBus baseEventBus = new BaseEventBus();
+ baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL);
baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION);
baseEventBus.setData(getKeyValue("data", data));
EventBus.getDefault().post(baseEventBus);
@@ -119,6 +116,16 @@
//EventBus浜嬩欢鍒嗗彂
BaseEventBus baseEventBus = new BaseEventBus();
baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE);
+ baseEventBus.setData(getKeyValue("data", data));
+ EventBus.getDefault().post(baseEventBus);
+ }
+ break;
+ //浣忓畢銆愮數绔欍�戠紪杈�
+ case HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT: {
+ //EventBus浜嬩欢鍒嗗彂
+ BaseEventBus baseEventBus = new BaseEventBus();
+ baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL);
+ baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT);
baseEventBus.setData(getKeyValue("data", data));
EventBus.getDefault().post(baseEventBus);
}
@@ -186,7 +193,7 @@
}
} else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(topic)) {
- WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance());
+ WifiUtils wifiUtils = WifiUtils.getInstance();
//wifi妯″潡
switch (type) {
//鑾峰彇wifi鍒楄〃
@@ -271,10 +278,18 @@
//璁惧鍙栨秷椹卞姩,鍥轰欢涓嬭浇鍗囩骇鏂囦欢
case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: {
this.uniCancelDownloadingUpgradeFile(data, callback);
+// HdlThreadLogic.runSubThread(new Runnable() {
+// @Override
+// public void run() {
+// HdlLogLogic.print("褰撳墠绾跨▼鍚嶇О鍙栨秷涓嬭浇====" + Thread.currentThread().getName());
+// uniCancelDownloadingUpgradeFile(data, callback);
+// }
+// });
}
break;
//璁惧椹卞姩,鍥轰欢鍙栨秷鍗囩骇
case HDLUniMP.UNI_EVENT_REPLY_OTA_CANCEL_UPGRADE: {
+
this.uniCancelUpgrade(data, callback);
}
break;
@@ -305,9 +320,9 @@
break;
}
}
- HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===澶х被->" + topic + "\r\n" + data, true);
+ HdlLogLogic.print("uni鍙戞潵鐨勬暟鎹�--->澶х被-->" + topic + "\r\n" + data, true);
} catch (Exception e) {
- HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===" + e.getMessage(), true);
+ HdlLogLogic.print("uni鍙戞潵鐨勬暟鎹�--->" + e.getMessage(), true);
}
}
@@ -322,7 +337,7 @@
public void openUniMP(String path, JSONObject jsonObject) {
JSONObject json = this.createdJSONObject(jsonObject, true);
HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this);
- HdlLogLogic.print("uni===缁勮uni鍙戦�佹暟鎹牸寮�===" + json, false);
+ HdlLogLogic.print("uni--->缁勮uni鍙戦�佹暟鎹牸寮�--->" + json, false);
}
/**
@@ -458,21 +473,28 @@
HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() {
@Override
public void onSuccess(ResponseBody responseBody) {
- String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
- boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(firmwarePathFileName, responseBody, md5, HdlOtaLogic.firmware_type);
- if (isBoolean) {
- HdlFileLogic.getInstance().deleteFile(localUrl);//涓嬭浇鎴愬姛,鍒犻櫎鏃у浐浠舵枃浠�;
- } else {
- HdlFileLogic.getInstance().deleteFile(firmwarePathFileName);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣鍥轰欢鏂囦欢;
- }
+ HdlThreadLogic.runSubThread(new Runnable() {
+ @Override
+ public void run() {
+ String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
+ //涓嶅湪瀛愮嚎绋嬭娴佷細鍗℃涓荤嚎绋�
+ boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(firmwarePathFileName, responseBody, md5, HdlOtaLogic.firmware_type);
+ if (isBoolean) {
+ HdlFileLogic.getInstance().deleteFile(localUrl);//涓嬭浇鎴愬姛,鍒犻櫎鏃у浐浠舵枃浠�;
+ } else {
+ HdlFileLogic.getInstance().deleteFile(firmwarePathFileName);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣鍥轰欢鏂囦欢;
+ }
- if (isBoolean) {
- HdlLogLogic.print("鍐欏叆鏂板浐浠舵枃浠跺埌鍐呭瓨鎴愬姛.", true);
- uniCallbackData(null, 0, "鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛", callback);
- } else {
- HdlLogLogic.print("鐢ㄦ埛鍙栨秷涓嬭浇鍥轰欢鍗囩骇鏂囦欢.", true);
- uniCallbackData(null, -2, "鐢ㄦ埛鍙栨秷涓嬭浇椹卞姩鍗囩骇鏂囦欢", callback);
- }
+ if (isBoolean) {
+ HdlLogLogic.print("鍐欏叆鏂板浐浠舵枃浠跺埌鍐呭瓨鎴愬姛.", true);
+ uniCallbackData(null, 0, "鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛", callback);
+ } else {
+ HdlLogLogic.print("涓嬭浇鍥轰欢鍗囩骇鏂囦欢澶辫触.", true);
+ uniCallbackData(null, -2, "涓嬭浇鍥轰欢鍗囩骇鏂囦欢澶辫触", callback);
+ }
+ }
+ });
+
}
@Override
@@ -501,6 +523,7 @@
@Override
public void onSuccess(Boolean b) {
if (b) {
+ HdlLogLogic.print("鏈湴鍗囩骇--->", true);
//鏈湴
//1,寤虹珛鏈湴鏈嶅姟锛�
//2,鍛婅瘔缃戝叧鎵嬫満ip鍜岀鍙o紱
@@ -517,7 +540,7 @@
}
String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧鍥轰欢闇�瑕�
//鍗囩骇鍥轰欢鏂囦欢鍦板潃
- String upgradeFileLocalPathUrl = "http://" + AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName;
+ String upgradeFileLocalPathUrl = "http://" + NetworkUtils.getInstance().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName;
//閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�绛変俊鎭�
HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, oid, module, version, data.length + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
@Override
@@ -539,6 +562,7 @@
}
});
} else {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
//杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
@@ -577,6 +601,7 @@
@Override
public void onFailure(HDLException e) {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
//杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
@@ -692,6 +717,7 @@
* 鍚戜簯绔彂璧枫�愯澶囬┍鍔ㄤ笅杞姐�戞寚浠�
*/
private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) {
+
String deviceOid = getKeyValue("oid", getKeyValue("data", data));//閫嗗彉鍣ㄨ澶噊id
String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//椹卞姩缂栫爜
String imageId = getKeyValue("imageId", getKeyValue("data", data));//椹卞姩闀滃儚id
@@ -703,20 +729,28 @@
HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() {
@Override
public void onSuccess(ResponseBody responseBody) {
- String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
- boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5, HdlOtaLogic.driver_type);
- if (isBoolean) {
- HdlFileLogic.getInstance().deleteFile(localUrl);//涓嬭浇鎴愬姛,鍒犻櫎鏃ч┍鍔ㄦ枃浠�;
- } else {
- HdlFileLogic.getInstance().deleteFile(drivePathFileName);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣椹卞姩鏂囦欢;
- }
- if (isBoolean) {
- HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", true);
- uniCallbackData(null, 0, "鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛", callback);
- } else {
- HdlLogLogic.print("鐢ㄦ埛鍙栨秷涓嬭浇椹卞姩鍗囩骇鏂囦欢.", true);
- uniCallbackData(null, -2, "鐢ㄦ埛鍙栨秷涓嬭浇椹卞姩鍗囩骇鏂囦欢", callback);
- }
+ HdlThreadLogic.runSubThread(new Runnable() {
+ @Override
+ public void run() {
+
+ String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
+ //涓嶅湪瀛愮嚎绋嬭娴佷細鍗℃涓荤嚎绋�
+ boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5, HdlOtaLogic.driver_type);
+ if (isBoolean) {
+ HdlFileLogic.getInstance().deleteFile(localUrl);//涓嬭浇鎴愬姛,鍒犻櫎鏃ч┍鍔ㄦ枃浠�;
+ } else {
+ HdlFileLogic.getInstance().deleteFile(drivePathFileName);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣椹卞姩鏂囦欢;
+ }
+ if (isBoolean) {
+ HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", true);
+ uniCallbackData(null, 0, "鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛", callback);
+ } else {
+ HdlLogLogic.print("涓嬭浇椹卞姩鍗囩骇鏂囦欢澶辫触.", true);
+ uniCallbackData(null, -2, "涓嬭浇椹卞姩鍗囩骇鏂囦欢澶辫触", callback);
+ }
+ }
+ });
+
}
@Override
@@ -744,6 +778,7 @@
@Override
public void onSuccess(Boolean b) {
if (b) {
+ HdlLogLogic.print("鏈湴鍗囩骇--->", true);
//鏈湴
//1,寤虹珛鏈湴鏈嶅姟锛�
// 2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱
@@ -760,7 +795,7 @@
}
String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕�
//鍗囩骇椹卞姩鏂囦欢鍦板潃
- String upgradeFileLocalPathUrl = "http://" + AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName;
+ String upgradeFileLocalPathUrl = "http://" + NetworkUtils.getInstance().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName;
//閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�绛変俊鎭�
HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, deviceOid, module, version, data.length + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
@Override
@@ -782,6 +817,7 @@
}
});
} else {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
//杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
@@ -820,6 +856,7 @@
@Override
public void onFailure(HDLException e) {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
//杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
@@ -1124,7 +1161,7 @@
* @param callback uni鍥炶皟
*/
private void uniGetCurrentHomeLocalAndCloudGatewayList(DCUniMPJSCallback callback) {
- HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(new CloudCallBeak<List<GatewayBean>>() {
+ HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<GatewayBean>>() {
@Override
public void onSuccess(List<GatewayBean> list) {
if (callback != null) {
@@ -1269,7 +1306,7 @@
*
* @return JSONObject
*/
- private JSONObject getJSONObject(Object obj) {
+ public JSONObject getJSONObject(Object obj) {
try {
if (obj == null) {
return new JSONObject();
@@ -1298,7 +1335,7 @@
* @param obj -
* @return value
*/
- private String getKeyValue(String key, Object obj) {
+ public String getKeyValue(String key, Object obj) {
try {
JSONObject jsonObject = this.getJSONObject(obj);
if (jsonObject.has(key)) {
--
Gitblit v1.8.0