From 936fb552a30c05fc7a60c20f47bf6fccbc2dc1c1 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期三, 27 十二月 2023 16:17:23 +0800
Subject: [PATCH] 备份一下代码
---
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 507 ++++++++++++++++++++++++++++++++++++++------------------
1 files changed, 343 insertions(+), 164 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 58ef4c6..034ccaa 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;
@@ -85,25 +82,25 @@
* 鍘熺敓鎺ユ敹鍒皍ni鍙戞潵鐨勬暟鎹�
*
* @param appId -uni灏忕▼搴忔寚瀹氱殑appId
- * @param event -uni灏忕▼搴忓彂鏉ユ暟鎹�
+ * @param topic -uni灏忕▼搴忓彂鏉ヤ富棰�(澶х被)
* @param data JSONObject com.alibaba.fastjson瑙f瀽澶勭悊
* @param callback callback.invoke(JSONObject) 鐢╟om.alibaba.fastjson
*/
@Override
- public void onOtherUniMPEventReceive(String appId, String event, Object data, DCUniMPJSCallback callback) {
+ public void onOtherUniMPEventReceive(String appId, String topic, Object data, DCUniMPJSCallback callback) {
try {
if (!HDLUniMP.UNI_APP_ID.equals(appId)) {
return;
}
- String type = getKeyValue("type", data);
- if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) {
+ String type = getKeyValue("type", data);//灏忕被
+ if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(topic)) {
//浣忓畢妯″潡
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);
@@ -123,12 +120,22 @@
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);
+ }
+ break;
}
if (callback != null) {
uniCallbackData(null, callback);
}
- } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) {
+ } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(topic)) {
//璁惧妯″潡
switch (type) {
//娣诲姞閫嗗彉鍣ㄥ埌浜戠
@@ -148,7 +155,7 @@
break;
//鑾峰彇閫嗗彉鍣ㄥ垪琛�
case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
- this.uniGetCurrentHomeLocalAndCloudGatewayList(callback);
+ this.uniGetCurrentHomeLocalAndCloudGatewayList(data, callback);
}
break;
//modBus鍗忚涓撶敤
@@ -185,8 +192,8 @@
}
- } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) {
- WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance());
+ } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(topic)) {
+ WifiUtils wifiUtils = WifiUtils.getInstance();
//wifi妯″潡
switch (type) {
//鑾峰彇wifi鍒楄〃
@@ -210,7 +217,7 @@
break;
}
- } else if (HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL.equals(event)) {
+ } else if (HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL.equals(topic)) {
//OTA鍗囩骇妯″潡
switch (type) {
//鍚戜簯绔幏鍙杘id鍒楄〃
@@ -268,9 +275,22 @@
this.uniUpgradeGatewayDriver(data, callback);
}
break;
- //璁惧鍙栨秷涓嬭浇鍗囩骇鏂囦欢
+ //璁惧鍙栨秷椹卞姩,鍥轰欢涓嬭浇鍗囩骇鏂囦欢
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;
//鎵撳紑鏈嶅姟
@@ -285,7 +305,7 @@
break;
}
- } else if (HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL.equals(event)) {
+ } else if (HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL.equals(topic)) {
//鍏跺畠妯″潡
switch (type) {
//鑾峰彇娓╁害鍗曚綅
@@ -300,9 +320,9 @@
break;
}
}
- HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===" + event + "\r\n" + data, false);
+ HdlLogLogic.print("uni鍙戞潵鐨勬暟鎹�--->澶х被-->" + topic + "\r\n" + data, true);
} catch (Exception e) {
- HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===" + e.getMessage(), false);
+ HdlLogLogic.print("uni鍙戞潵鐨勬暟鎹�--->" + e.getMessage(), true);
}
}
@@ -317,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);
}
/**
@@ -331,7 +351,7 @@
try {
HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, topic, getJSONObject(callBackBaseBean));
} catch (Exception e) {
- HdlLogLogic.print("uni===鍘熺敓涓诲姩鍚戝皬绋嬪簭鍙戦�侀�氱煡浜嬩欢===" + e.getMessage(), false);
+ HdlLogLogic.print("uni--->鍘熺敓涓诲姩鍚戝皬绋嬪簭鍙戦�侀�氱煡浜嬩欢--->" + e.getMessage(), false);
}
}
@@ -412,18 +432,23 @@
String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//纭欢鍨嬪彿
String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//绯荤粺闀滃儚id
String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//鍥轰欢鐗堟湰id
+// String oid = getKeyValue("oid", getKeyValue("data", data));//鍥轰欢oid
List<DeviceFirmwareBean> list = new ArrayList<>();
String driverFileList = HdlFileLogic.getInstance().getFirmwareRootPath();
File file = new File(driverFileList);
if (file.list() != null) {
for (int i = 0; i < Objects.requireNonNull(file.list()).length; i++) {
String path = Objects.requireNonNull(file.list())[i];
+ if (!path.contains(osImageId)) {
+ continue;
+ }
String[] ary = path.split("/");
String[] driverInfoAry = ary[ary.length - 1].split("_");
DeviceFirmwareBean deviceFirmwareBean = new DeviceFirmwareBean();
deviceFirmwareBean.setOid(driverInfoAry[0]);
- deviceFirmwareBean.setVersion(driverInfoAry[1].replace(".zip", ""));
- deviceFirmwareBean.setLocalUrl(HdlFileLogic.getInstance().getFirmwarePathFileName(deviceFirmwareBean.getOid(), deviceFirmwareBean.getVersion()));
+ deviceFirmwareBean.setImageId(driverInfoAry[1]);
+ deviceFirmwareBean.setVersion(driverInfoAry[2].replace(".zip", ""));
+ deviceFirmwareBean.setLocalUrl(HdlFileLogic.getInstance().getFirmwarePathFileName(deviceFirmwareBean.getOid(), osImageId, deviceFirmwareBean.getVersion()));
list.add(deviceFirmwareBean);
}
}
@@ -439,7 +464,7 @@
*/
private void uniDeviceFirmwareDownload(Object data, DCUniMPJSCallback callback) {
String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//浜戠涓婅澶噄d
- String oid = getKeyValue("oid", getKeyValue("data", data));//鍥轰欢鐨刼id
+ String oid = getKeyValue("oid", getKeyValue("data", data));//璇ュ浐浠剁殑oid
String imageId = getKeyValue("imageId", getKeyValue("data", data));//鍥轰欢闀滃儚id
String version = getKeyValue("version", getKeyValue("data", data));//鍥轰欢鐗堟湰
String localUrl = getKeyValue("localUrl", getKeyValue("data", data));//鍌ㄥ瓨鍦ㄦ湰鍦板浐浠舵枃浠惰矾寰�
@@ -448,19 +473,33 @@
HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() {
@Override
public void onSuccess(ResponseBody responseBody) {
- String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, version);
- boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(firmwarePathFileName, responseBody, md5, HdlOtaLogic.firmware_type);
- if (isBoolean) {
- HdlFileLogic.getInstance().deleteFile(localUrl);//涓嬭浇鎴愬姛,鍒犻櫎鏃у浐浠舵枃浠�;
- } else {
- HdlFileLogic.getInstance().deleteFile(firmwarePathFileName);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣鍥轰欢鏂囦欢;
- }
- HdlLogLogic.print("鍐欏叆鏂板浐浠舵枃浠跺埌鍐呭瓨鎴愬姛.", false);
+ 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);
+ }
+ }
+ });
+
}
@Override
public void onFailure(HDLException e) {
- HdlLogLogic.print("涓嬭浇鍥轰欢鏂囦欢鍒板唴瀛樺け璐�.", false);
+ HdlLogLogic.print("涓嬭浇鍥轰欢鏂囦欢鍒板唴瀛樺け璐�.", true);
uniCallbackData(null, e.getCode(), e.getMsg(), callback);
}
});
@@ -476,63 +515,80 @@
String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//鍥轰欢鐗堟湰id
String version = getKeyValue("version", getKeyValue("data", data));//鍥轰欢鐗堟湰
String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//浜戠涓婃枃浠禡D5
+ String imageId = getKeyValue("imageId", getKeyValue("data", data));//鍥轰欢闀滃儚id
+ String module = "FW#" + imageId;
//鍗囩骇鏈湴浼樺厛->浜戠鍗囩骇
- boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac);
- if (isLocalConnect) {
- //鏈湴
- //1,寤虹珛鏈湴鏈嶅姟锛�
- //2,鍛婅瘔缃戝叧鎵嬫満ip鍜岀鍙o紱
- //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
- HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- //鏈湴鍗囩骇鍥轰欢鏂囦欢璺緞
- String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, version);
- String data = HdlFileLogic.getInstance().readFile(firmwarePathFileName);
- String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧鍥轰欢闇�瑕�
- //鍗囩骇鍥轰欢鏂囦欢鍦板潃
- String upgradeFileLocalPathUrl = AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName;
- //閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�绛変俊鎭�
- HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, oid, hardwareModel, version, data.length() + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
+ HdlDeviceLogic.getInstance().isLocalConnect(deviceMac, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean b) {
+ if (b) {
+ HdlLogLogic.print("鏈湴鍗囩骇--->", true);
+ //鏈湴
+ //1,寤虹珛鏈湴鏈嶅姟锛�
+ //2,鍛婅瘔缃戝叧鎵嬫満ip鍜岀鍙o紱
+ //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
+ HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
@Override
- public void onSuccess(String obj) {
- HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�鎴愬姛.", false);
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ //鏈湴鍗囩骇鍥轰欢鏂囦欢璺緞
+ String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
+ byte[] data = HdlFileLogic.getInstance().readFileByte(firmwarePathFileName);
+ if (data == null || data.length == 0) {
+ uniCallbackData(null, -2, "鏈湴鎵句笉鍒板崌绾у浐浠舵枃浠�,璇蜂笅杞藉ソ鍥轰欢鏂囦欢,鍐嶉噸鏂板崌绾�.", callback);
+ return;
+ }
+ String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧鍥轰欢闇�瑕�
+ //鍗囩骇鍥轰欢鏂囦欢鍦板潃
+ 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
+ public void onSuccess(String obj) {
+ HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�鎴愬姛.", true);
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", true);
+ uniCallbackData(null, -2, "閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ }
+ });
}
@Override
- public void onError(HDLLinkException e) {
- HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", false);
- uniCallbackData(null, -2, "閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ public void onServiceDisconnected(ComponentName name) {
+ uniCallbackData(null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
}
});
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- uniCallbackData(null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
- }
- });
-
- } else {
- //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
- HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
- @Override
- public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
- //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
- if (cloudInverterDeviceBean == null) {
- uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
- return;
- }
- if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
- uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
- return;
- }
- //4:杩愯
- HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() {
+ } else {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
+ //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
- public void onSuccess(Boolean obj) {
- uniCallbackData(obj, callback);
+ public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
+ //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+ if (cloudInverterDeviceBean == null) {
+ uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
+ return;
+ }
+ if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
+ uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+ return;
+ }
+ //4:杩愯
+ HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(obj, callback);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+
}
@Override
@@ -540,16 +596,48 @@
uniCallbackData(null, e.getCode(), e.getMsg(), callback);
}
});
-
}
+ }
- @Override
- public void onFailure(HDLException e) {
- uniCallbackData(null, e.getCode(), e.getMsg(), callback);
- }
- });
+ @Override
+ public void onFailure(HDLException e) {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
+ //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
+ @Override
+ public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
+ //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+ if (cloudInverterDeviceBean == null) {
+ uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
+ return;
+ }
+ if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
+ uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+ return;
+ }
+ //4:杩愯
+ HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(obj, callback);
+ }
- }
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+ }
+ });
+
}
/**
@@ -629,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
@@ -640,19 +729,33 @@
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);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣椹卞姩鏂囦欢;
- }
- HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", false);
+ 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
public void onFailure(HDLException e) {
- HdlLogLogic.print("涓嬭浇椹卞姩鏂囦欢鍒板唴瀛樺け璐�.", false);
+ HdlLogLogic.print("涓嬭浇椹卞姩鏂囦欢鍒板唴瀛樺け璐�.", true);
uniCallbackData(null, e.getCode(), e.getMsg(), callback);
}
});
@@ -666,64 +769,81 @@
String deviceMac = getKeyValue("mac", getKeyValue("data", data));//閫嗗彉鍣ㄨ澶噈ac锛堟煡鎵緎ocket锛�
String deviceOid = getKeyValue("oid", getKeyValue("data", data));//閫嗗彉鍣ㄨ澶噊id
String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//椹卞姩鐗堟湰id
- String module = getKeyValue("module", getKeyValue("data", data));//妯″潡淇℃伅
String version = getKeyValue("version", getKeyValue("data", data));//椹卞姩鐗堟湰鍙�
String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//椹卞姩缂栫爜
+ String imageId = getKeyValue("imageId", getKeyValue("data", data));//鍥轰欢闀滃儚id
+ String module = driverCode + "#" + imageId;
//鍗囩骇鏈湴浼樺厛->浜戠鍗囩骇
- boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac);
- if (isLocalConnect) {
- //鏈湴
- //1,寤虹珛鏈湴鏈嶅姟锛�
- // 2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱
- //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
- HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
- @Override
- public void onServiceConnected(ComponentName name, IBinder service) {
- //鏈湴鍗囩骇椹卞姩鏂囦欢璺緞
- String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
- String data = HdlFileLogic.getInstance().readFile(drivePathFileName);
- String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕�
- //鍗囩骇椹卞姩鏂囦欢鍦板潃
- String upgradeFileLocalPathUrl = AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName;
- //閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�绛変俊鎭�
- HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, deviceOid, module, version, data.length() + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
+ HdlDeviceLogic.getInstance().isLocalConnect(deviceMac, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean b) {
+ if (b) {
+ HdlLogLogic.print("鏈湴鍗囩骇--->", true);
+ //鏈湴
+ //1,寤虹珛鏈湴鏈嶅姟锛�
+ // 2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱
+ //瀹炰緥鍖� 鑾峰彇ip 鍦板潃
+ HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
@Override
- public void onSuccess(String obj) {
- HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�鎴愬姛.", false);
+ public void onServiceConnected(ComponentName name, IBinder service) {
+ //鏈湴鍗囩骇椹卞姩鏂囦欢璺緞
+ String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
+ byte[] data = HdlFileLogic.getInstance().readFileByte(drivePathFileName);
+ if (data == null || data.length == 0) {
+ uniCallbackData(null, -2, "鏈湴鎵句笉鍒板崌绾ч┍鍔ㄦ枃浠�,璇蜂笅杞藉ソ椹卞姩鏂囦欢,鍐嶉噸鏂板崌绾�.", callback);
+ return;
+ }
+ String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕�
+ //鍗囩骇椹卞姩鏂囦欢鍦板潃
+ 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
+ public void onSuccess(String obj) {
+ HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�鎴愬姛.", true);
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+ HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", true);
+ uniCallbackData(null, -2, "閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ }
+ });
}
@Override
- public void onError(HDLLinkException e) {
- HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", false);
- uniCallbackData(null, -2, "閫氱煡缁欑綉鍏冲崌绾ч┍鍔ㄦ枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇,", callback);
+ public void onServiceDisconnected(ComponentName name) {
+ uniCallbackData(null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
}
});
- }
-
- @Override
- public void onServiceDisconnected(ComponentName name) {
- uniCallbackData(null, -2, "鏈湴鏈嶅姟鏈夊紓甯稿け璐�,鏃犳硶鍗囩骇,", callback);
- }
- });
- } else {
- //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
- HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
- @Override
- public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
- //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
- if (cloudInverterDeviceBean == null) {
- uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
- return;
- }
- if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
- uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
- return;
- }
- //4:杩愯
- HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
+ } else {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
+ //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
@Override
- public void onSuccess(Boolean obj) {
- uniCallbackData(obj, callback);
+ public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
+ //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+ if (cloudInverterDeviceBean == null) {
+ uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
+ return;
+ }
+ if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
+ uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+ return;
+ }
+ //4:杩愯
+ HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(obj, callback);
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+
}
@Override
@@ -731,23 +851,73 @@
uniCallbackData(null, e.getCode(), e.getMsg(), callback);
}
});
-
}
+ }
- @Override
- public void onFailure(HDLException e) {
- uniCallbackData(null, e.getCode(), e.getMsg(), callback);
- }
- });
+ @Override
+ public void onFailure(HDLException e) {
+ HdlLogLogic.print("鍦ㄧ嚎鍗囩骇--->", true);
+ //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯
+ HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
+ @Override
+ public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
+ //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�)
+ if (cloudInverterDeviceBean == null) {
+ uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback);
+ return;
+ }
+ if (cloudInverterDeviceBean.getDeviceStatus() != 3) {
+ uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback);
+ return;
+ }
+ //4:杩愯
+ HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+ uniCallbackData(obj, callback);
+ }
- }
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+
+ }
+
+ @Override
+ public void onFailure(HDLException e) {
+ uniCallbackData(null, e.getCode(), e.getMsg(), callback);
+ }
+ });
+ }
+ });
+
}
/**
- * 鍙栨秷涓嬭浇鍗囩骇鏂囦欢
+ * 鍙栨秷涓嬭浇銆愰┍鍔�,鍥轰欢銆戝崌绾ф枃浠�
*/
private void uniCancelDownloadingUpgradeFile(Object data, DCUniMPJSCallback callback) {
- HdlOtaLogic.getInstance().setStopDriversDownload();
+ HdlOtaLogic.getInstance().stopDownloadUpgradeFile();
+ uniCallbackData(null, 0, "鍙栨秷涓嬭浇鎴愬姛.", callback);
+ }
+
+ /**
+ * 鍙栨秷銆愰┍鍔�,鍥轰欢銆戝崌绾�
+ */
+ private void uniCancelUpgrade(Object data, DCUniMPJSCallback callback) {
+ HdlOtaLogic.getInstance().cancelUpgrade("", new LinkCallBack<Boolean>() {
+ @Override
+ public void onSuccess(Boolean obj) {
+
+ }
+
+ @Override
+ public void onError(HDLLinkException e) {
+
+ }
+ });
}
/**
@@ -824,7 +994,7 @@
*/
private void uniUploadDataToCloud(Object data, DCUniMPJSCallback callback) {
String mac = getKeyValue("mac", getKeyValue("data", data));
- HdlDeviceLogic.getInstance().uploadDataToCloud(mac, null);
+ HdlDeviceLogic.getInstance().uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), mac, null);
}
/**
@@ -970,7 +1140,7 @@
* @param callback uni鍥炶皟
*/
private void uniSearchGateway(DCUniMPJSCallback callback) {
- HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() {
+ HdlDeviceLogic.getInstance().searchCurrentHomeGateway(new GatewayCallBack() {
@Override
public void onSuccess(List<GatewayBean> gatewayBeanList) {
uniCallbackData(gatewayBeanList, callback);
@@ -990,18 +1160,27 @@
*
* @param callback uni鍥炶皟
*/
- private void uniGetCurrentHomeLocalAndCloudGatewayList(DCUniMPJSCallback callback) {
- HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(new CloudCallBeak<List<GatewayBean>>() {
+ private void uniGetCurrentHomeLocalAndCloudGatewayList(Object data, DCUniMPJSCallback callback) {
+ String homeId = getKeyValue("homeId", getKeyValue("data", data));
+ HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(homeId, new CloudCallBeak<List<GatewayBean>>() {
@Override
public void onSuccess(List<GatewayBean> list) {
+ GatewayBean gatewayBean = HdlDeviceLogic.getInstance().queryCurrentHomeMainGateway(list);
+ if (gatewayBean != null) {
+ //杩涙潵浣忓畢璇︽儏閮借涓婁紶涓�娆id鍒楄〃鍒颁簯绔�;
+ HdlDeviceLogic.getInstance().uploadDataToCloud(homeId, gatewayBean.getDevice_mac(), null);
+ }
+ //EventBus浜嬩欢鍒嗗彂,杩涘叆浣忓畢寮�濮嬭闃呬富棰�
+ BaseEventBus baseEventBus = new BaseEventBus();
+ baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST);
+ baseEventBus.setData(list);
+
+ EventBus.getDefault().post(baseEventBus);
if (callback != null) {
uniCallbackData(list, callback);
- //EventBus浜嬩欢鍒嗗彂
- BaseEventBus baseEventBus = new BaseEventBus();
- baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST);
- baseEventBus.setData(list);
- EventBus.getDefault().post(baseEventBus);
}
+
+
}
@Override
@@ -1129,7 +1308,7 @@
*
* @return JSONObject
*/
- private JSONObject getJSONObject(Object obj) {
+ public JSONObject getJSONObject(Object obj) {
try {
if (obj == null) {
return new JSONObject();
@@ -1158,7 +1337,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