From 5e080d063f213f2b2c2ed34e1d54b9fd7df1c6b0 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 23 十一月 2023 19:28:47 +0800 Subject: [PATCH] 2023年11月23日19:28:37 --- app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java | 3 app/src/main/res/values-zh/strings.xml | 1 app/src/main/res/values/strings.xml | 1 app/src/main/res/values-en/strings.xml | 1 app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java | 71 +++++++++++++++++ app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 24 ++++- app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java | 118 ++++++++++++++--------------- 7 files changed, 149 insertions(+), 70 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java index e28e092..972a3c6 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java @@ -89,6 +89,11 @@ private ServiceConnection mServiceConnection = null; + /** + * true琛ㄧず缁堟涓嬭浇鍗囩骇鏂囦欢(鐢ㄦ埛琛屼负) + */ + private boolean stopDownload = false; + //region -----鍥轰欢鍗囩骇--------- /** @@ -390,6 +395,13 @@ } /** + * 璁剧疆缁堟涓嬭浇鏂囦欢鎸囦护 + */ + public void setStopDriversDownload() { + this.stopDownload = true; + } + + /** * 浜戠鍙戣捣銆愯澶囬┍鍔ㄣ�戝崌绾TA鎸囦护 * * @param oid 缃戝叧璁惧oid @@ -407,43 +419,6 @@ public void onSuccess(String json) { if (callBack != null) { callBack.onSuccess(true); - } - } - - @Override - public void onFailure(HDLException e) { - if (callBack != null) { - callBack.onFailure(e); - } - } - }); - } - - /** - * 鍚戜簯绔幏鍙栥�愯澶囬┍鍔ㄣ�戝崌绾у寘涓嬭浇鍦板潃 - * - * @param driverVersionId 椹卞姩鐗堟湰Id - */ - public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<DownloadUrlBean> callBack) { - - String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceDriverDownloadUrl; - JsonObject json = new JsonObject(); - json.addProperty("driverVersionId", driverVersionId); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { - @Override - public void onSuccess(String s) { - if (TextUtils.isEmpty(s)) { - if (callBack != null) { - callBack.onSuccess(new DownloadUrlBean()); - } - return; - } - Gson gson = new Gson(); - Type typeOfT = new TypeToken<DownloadUrlBean>() { - }.getType(); - DownloadUrlBean downloadUrlBean = gson.fromJson(s, typeOfT); - if (callBack != null) { - callBack.onSuccess(downloadUrlBean); } } @@ -563,11 +538,11 @@ String driver = driver_type; //-100:娌℃湁鏁版嵁;-101:娌℃湁md5绉橀挜;-102:md5绉橀挜涓嶅;-103:鏈夊紓甯�; if (zipData == null) { - this.eventBusPost(driver, -100, "娌℃湁鏁版嵁"); + this.eventBusPost(fullPath,driver, -100, "娌℃湁鏁版嵁"); return false; } if (TextUtils.isEmpty(md5)) { - this.eventBusPost(driver, -101, "娌℃湁md5绉橀挜"); + this.eventBusPost(fullPath,driver, -101, "娌℃湁md5绉橀挜"); return false; } InputStream is = null; @@ -580,7 +555,7 @@ is = zipData.byteStream(); long total = zipData.contentLength(); if (total == 0) { - this.eventBusPost(driver, -100, "娌℃湁鏁版嵁"); + this.eventBusPost(fullPath,driver, -100, "娌℃湁鏁版嵁"); return false; } fos = new FileOutputStream(file); @@ -592,7 +567,7 @@ int progress = (int) (100 * sum * 1.0f / total); if (sum != total) { //涓嶇瓑浜�100閮借鎶�,绛変簬100澶勭悊鏁村潡閫昏緫瀹屼箣鍚庡啀鎶�100; - this.eventBusPost(driver, progress, "姝e父涓婃姤"); + this.eventBusPost(fullPath,driver, progress, "姝e父涓婃姤"); } } fos.flush(); @@ -601,19 +576,19 @@ byte[] bytes = FileUtils.readFileToByteArray(file); String fileMD5 = Md5Utils.encodeMD5(bytes); if (TextUtils.isEmpty(fileMD5)) { - this.eventBusPost(driver, -106, "鏂囦欢鐢熸垚md5澶辫触."); + this.eventBusPost(fullPath,driver, -106, "鏂囦欢鐢熸垚md5澶辫触."); return false; } if (!md5.equals(fileMD5)) { - this.eventBusPost(driver, -107, "md5姣斿澶辫触."); + this.eventBusPost(fullPath,driver, -107, "md5姣斿澶辫触."); return false; } - this.eventBusPost(driver, 100, "涓嬭浇瀹屾垚."); + this.eventBusPost(fullPath,driver, 100, "涓嬭浇瀹屾垚."); return true; } catch (Exception e) { - this.eventBusPost(driver, -103, e.getMessage()); + this.eventBusPost(fullPath,driver, -103, e.getMessage()); e.printStackTrace(); } return false; @@ -622,20 +597,21 @@ /** * 澶勭悊涓嬭浇鏂囦欢鏁版嵁 * - * @param fullPath 鏂囦欢鍏ㄨ矾寰� - * @param zipData 鏂囦欢鏁版嵁娴佸璞� - * @param md5 妫�楠屾枃浠禡D5鍊� - * @param driver 椹卞姩鎴栬�呭浐浠� + * @param fileFullPath 鏂囦欢鍏ㄨ矾寰� + * @param zipData 鏂囦欢鏁版嵁娴佸璞� + * @param md5 妫�楠屾枃浠禡D5鍊� + * @param driver 椹卞姩鎴栬�呭浐浠� * @return 鎴愬姛true */ - public boolean disposeDownLoadFile(String fullPath, ResponseBody zipData, String md5, String driver) { + public boolean disposeDownLoadFile(String fileFullPath, ResponseBody zipData, String md5, String driver) { + this.stopDownload = false; //-100:娌℃湁鏁版嵁;-101:娌℃湁md5绉橀挜;-102:md5绉橀挜涓嶅;-103:鏈夊紓甯�; if (zipData == null) { - this.eventBusPost(driver, -100, "娌℃湁鏁版嵁"); + this.eventBusPost(fileFullPath, driver, -100, "娌℃湁鏁版嵁"); return false; } if (TextUtils.isEmpty(md5)) { - this.eventBusPost(driver, -101, "娌℃湁md5绉橀挜"); + this.eventBusPost(fileFullPath, driver, -101, "娌℃湁md5绉橀挜"); return false; } InputStream is = null; @@ -644,23 +620,31 @@ FileOutputStream fos = null; File file = null; try { - file = new File(fullPath); + file = new File(fileFullPath); is = zipData.byteStream(); long total = zipData.contentLength(); if (total == 0) { - this.eventBusPost(driver, -100, "娌℃湁鏁版嵁"); + this.eventBusPost(fileFullPath, driver, -100, "娌℃湁鏁版嵁"); return false; } fos = new FileOutputStream(file); long sum = 0; while ((len = is.read(buf)) != -1) { + if (this.stopDownload) { + this.eventBusPost(fileFullPath, driver, -108, "鐢ㄦ埛鍙栨秷涓嬭浇."); + fos.flush(); + fos.close(); + is.close(); + //todo 鐢ㄦ埛缁堟瀹剁户缁鍙栨暟鎹�; + return false; + } fos.write(buf, 0, len); sum += len; //todo 涓嬭浇涓紝鍙互鑷繁璁$畻鐨勮繘搴︽潯(鍙互骞挎挱鍑哄幓) int progress = (int) (100 * sum * 1.0f / total); if (sum != total) { //涓嶇瓑浜�100閮借鎶�,绛変簬100澶勭悊鏁村潡閫昏緫瀹屼箣鍚庡啀鎶�100; - this.eventBusPost(driver, progress, "姝e父涓婃姤"); + this.eventBusPost(fileFullPath, driver, progress, "姝e父涓婃姤"); } } fos.flush(); @@ -670,24 +654,24 @@ //涓嬭浇鏂囦欢闇�瑕佽В瀵嗕箣鍚庡啀杩涜md5鍘诲仛姣斿 byte[] decrypt = AesUtils.decrypt(bytes); if (decrypt == null) { - this.eventBusPost(driver, -105, "aes瑙e瘑澶辫触."); + this.eventBusPost(fileFullPath, driver, -105, "aes瑙e瘑澶辫触."); return false; } String fileMD5 = Md5Utils.encodeMD5(decrypt); if (TextUtils.isEmpty(fileMD5)) { - this.eventBusPost(driver, -106, "鏂囦欢鐢熸垚md5澶辫触."); + this.eventBusPost(fileFullPath, driver, -106, "鏂囦欢鐢熸垚md5澶辫触."); return false; } if (!md5.equals(fileMD5)) { - this.eventBusPost(driver, -107, "md5姣斿澶辫触."); + this.eventBusPost(fileFullPath, driver, -107, "md5姣斿澶辫触."); return false; } //todo 娉ㄦ剰:瑙e瘑涔嬪悗锛岃閲嶆柊鍐欐暟鎹�; FileUtils.writeByteArrayToFile(file, decrypt, false); - this.eventBusPost(driver, 100, "涓嬭浇瀹屾垚."); + this.eventBusPost(fileFullPath, driver, 100, "涓嬭浇瀹屾垚."); return true; } catch (Exception e) { - this.eventBusPost(driver, -103, e.getMessage()); + this.eventBusPost(fileFullPath, driver, -103, e.getMessage()); e.printStackTrace(); } return false; @@ -701,7 +685,19 @@ * @param progressValue 杩涘害鍊� * @param describe 鎻忚堪鏂囨湰 */ - public void eventBusPost(String type, int progressValue, String describe) { + public void eventBusPost(String fileFullPath, String type, int progressValue, String describe) { + if (this.stopDownload) { + HdlFileLogic.getInstance().deleteFile(fileFullPath);//鍒犻櫎涓嬭浇涓嶅畬鎴愭暟鎹�; + BaseEventBus baseEventBus = new BaseEventBus(); + baseEventBus.setTopic(localDownloadProgress); + Progress progress = new Progress(); + progress.step = progressValue; + progress.describe = describe; + baseEventBus.setType(type); + baseEventBus.setData(progress); + EventBus.getDefault().post(baseEventBus); + return; + } // HdlThreadLogic.runMainThread(new Runnable() { // @Override // public void run() { 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 8136a4a..36f0772 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java @@ -267,6 +267,11 @@ this.uniUpgradeGatewayDriver(data, callback); } break; + //璁惧鍙栨秷涓嬭浇鍗囩骇鏂囦欢 + case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: { + this.uniCancelDownloadingUpgradeFile(data, callback); + } + break; } } @@ -553,7 +558,7 @@ } /** - * 鍚戜簯绔彂璧枫�愯澶囬┍鍔ㄣ�戜笅杞芥寚浠� + * 鍚戜簯绔彂璧枫�愯澶囬┍鍔ㄤ笅杞姐�戞寚浠� */ private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) { String deviceOid = getKeyValue("oid", getKeyValue("data", data));//缃戝叧璁惧oid @@ -633,17 +638,17 @@ } }); } else { - //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯 + //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯 HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() { @Override public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) { - //1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�) + //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�) if (cloudInverterDeviceBean == null) { - uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback); + uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_binding_cloud_upgrade_fails), callback); return; } - if (cloudInverterDeviceBean.getDeviceStatus() != 4) { - uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), getDeviceStatusString(cloudInverterDeviceBean.getDeviceStatus()), callback); + if (cloudInverterDeviceBean.getDeviceStatus() != 3) { + uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback); return; } //4:杩愯 @@ -670,6 +675,13 @@ } } + /** + * 鍙栨秷涓嬭浇鍗囩骇鏂囦欢 + */ + private void uniCancelDownloadingUpgradeFile(Object data, DCUniMPJSCallback callback) { + HdlOtaLogic.getInstance().setStopDriversDownload(); + } + /** * @param deviceStatus 閫嗗彉鍣ㄨ繛鎺ヤ簯绔姸鎬佸�硷紙 1:寰呮満,2:杩炴帴涓�,3:鏁呴殰,4:杩愯,5:绂荤嚎锛� diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java index 1706fa8..771e5b0 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java @@ -83,7 +83,7 @@ //鍒濆鍖杕qtt瀹㈡埛绔� initMqttClient(); - +// dddd(); } @@ -354,7 +354,76 @@ } + private void dddd() { +// String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName("036F6C1B", "V01.01.02"); +// String data = HdlFileLogic.getInstance().readFile(drivePathFileName); +// String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕� +// Log.e("", md5); +// HdlOtaLogic.getInstance().getDeviceDriverDownloadFile("http://192.168.16.135:49152/storage/emulated/0/Android/data/com.hdl.photovoltaic/files/Documents/upgrade/drive/036F6C1B_V01.01.02.zip", new CloudCallBeak<ResponseBody>() { +// @Override +// public void onSuccess(ResponseBody responseBody) { +// +// HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5); +// +//// //鏈湴鍗囩骇椹卞姩鏂囦欢璺緞 +//// +//// String data = HdlFileLogic.getInstance().readFile(drivePathFileName); +//// String md5 = HDLMD5Utils.encodeMD5(data);//缃戝叧椹卞姩闇�瑕� +// } +// +// @Override +// public void onFailure(HDLException e) { +// +// } +// }); +// HdlOtaLogic.getInstance().getNewGatewayDrivers("036F6C1B", "A000", new CloudCallBeak<CloudGatewayDriversBean>() { +// @Override +// public void onSuccess(CloudGatewayDriversBean obj) { +// +// } +// +// @Override +// public void onFailure(HDLException e) { +// +// } +// }); + + +// dowlao(); + HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + + } + + @Override + public void onServiceDisconnected(ComponentName name) { + + } + }); + + } + + void dowlao() { + + HdlOtaLogic.getInstance().getDeviceDriverDownloadFile("http://hdl-hz-test.oss-cn-hangzhou.aliyuncs.com/20/2023/11/1834a1d0-d2a7-4b6f-9877-6f2722e9b7bc.hdlipk_sec", new CloudCallBeak<ResponseBody>() { + @Override + public void onSuccess(ResponseBody responseBody) { + String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName("036F6C1B", "V01.01.02"); + HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, "84cd8e62d4311c90508313f0e5965dbb", HdlOtaLogic.driver_type); + +// HdlFileLogic.getInstance().writeFile(drivePathFileName, bytes);//鍐欏叆鏂版枃浠� + HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", false); + } + + @Override + public void onFailure(HDLException e) { + HdlLogLogic.print("涓嬭浇椹卞姩鏂囦欢鍒板唴瀛樺け璐�.", false); + } + }); + } + } \ No newline at end of file diff --git a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java index 3e5b1ce..f19a682 100644 --- a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java +++ b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java @@ -45,16 +45,15 @@ public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_NEW_LIST = "firmwares_new_list";//璁惧鏂板浐浠跺垪琛� public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_LOCAL = "firmwares_local_list";//璁惧鏈湴鍥轰欢鍒楄〃 public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_DOWNLOAD = "firmwares_download";//璁惧鍥轰欢涓嬭浇 - public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_CANCEL_DOWNLOAD = "firmwares_cancel_download";//璁惧鍥轰欢鍙栨秷涓嬭浇 public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE = "firmwares_upgrade";//璁惧鍥轰欢鍗囩骇 public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_CANCEL_UPGRADE = "firmwares_cancel_upgrade";//璁惧鍥轰欢鍙栨秷鍗囩骇 public final static String UNI_EVENT_REPLY_OTA_DRIVER_LIST = "driver_current_list";//褰撳墠璁惧椹卞姩鍒楄〃 public final static String UNI_EVENT_REPLY_OTA_DRIVER_NEW = "driver_new_list";//璁惧鏂伴┍鍔ㄥ垪琛� public final static String UNI_EVENT_REPLY_OTA_DRIVER_LOCAL = "driver_local_list";//璁惧鏈湴椹卞姩鍒楄〃 public final static String UNI_EVENT_REPLY_OTA_DRIVER_DOWNLOAD = "driver_download";//璁惧椹卞姩涓嬭浇 - public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD = "driver_cancel_download";//璁惧椹卞姩鍙栨秷涓嬭浇 public final static String UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE = "driver_upgrade";//璁惧椹卞姩鍗囩骇 public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_UPGRADE = "driver_cancel_upgrade";//璁惧椹卞姩鍙栨秷鍗囩骇 + public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD = "cancel_download";//璁惧鍙栨秷涓嬭浇鍗囩骇鏂囦欢 /*********Wifi妯″潡*********/ //鍗敠瀹氫箟 diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 7c8521b..be75fd7 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -107,6 +107,7 @@ <string name="set_nickname_modification">鏄电О淇敼</string> <!--ota--> + <string name="ota_binding_cloud_upgrade_fails">閫嗗彉鍣ㄦ病缁戝畾涓婁簯,鍗囩骇澶辫触.</string> <string name="ota_not_cloud_upgrade_fails">閫嗗彉鍣ㄦ病涓婁簯,鍗囩骇澶辫触.</string> <!--uin--> <string name="uni_open_error">椤甸潰鍒濆鍖栦腑 璇风瓑寰�5绉掑啀鐐瑰嚮</string> diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 6e117ef..7039151 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -107,6 +107,7 @@ <string name="set_nickname_modification">鏄电О淇敼</string> <!--ota--> + <string name="ota_binding_cloud_upgrade_fails">閫嗗彉鍣ㄦ病缁戝畾涓婁簯,鍗囩骇澶辫触.</string> <string name="ota_not_cloud_upgrade_fails">閫嗗彉鍣ㄦ病涓婁簯,鍗囩骇澶辫触.</string> <!--uin--> <string name="uni_open_error">椤甸潰鍒濆鍖栦腑 璇风瓑寰�5绉掑啀鐐瑰嚮</string> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e1b913b..b1c099d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -107,6 +107,7 @@ <string name="set_nickname_modification">鏄电О淇敼</string> <!--ota--> + <string name="ota_binding_cloud_upgrade_fails">閫嗗彉鍣ㄦ病缁戝畾涓婁簯,鍗囩骇澶辫触.</string> <string name="ota_not_cloud_upgrade_fails">閫嗗彉鍣ㄦ病杩炰笂浜�,鍗囩骇澶辫触.</string> -- Gitblit v1.8.0