From 3d9a11739a3972deea2aa45f2b4dd219740ffa70 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 23 十一月 2023 21:29:10 +0800 Subject: [PATCH] 2023年11月23日21:28:21 --- app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java | 16 +++ app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java | 2 app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java | 2 app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 107 ++++++++++++++++++++++---- app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java | 105 +++++++------------------ 5 files changed, 138 insertions(+), 94 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java index f7f11d0..e9c08c8 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlFileLogic.java @@ -119,8 +119,20 @@ * @return 鍏ㄨ矾寰� */ public String getDrivePathFileName(String driverCode, String version) { - String driverFileName = driverCode + "_" + version + ".zip"; - return HdlFileLogic.getInstance().getDriveRootPath() + "/" + driverFileName; + String fileName = driverCode + "_" + version + ".zip"; + return HdlFileLogic.getInstance().getDriveRootPath() + "/" + fileName; + } + + /** + * 鑾峰彇鍥轰欢鍗囩骇鏂囦欢鍏ㄨ矾寰� + * + * @param oid - + * @param version 椹卞姩鐗堟湰 + * @return 鍏ㄨ矾寰� + */ + public String getFirmwarePathFileName(String oid, String version) { + String fileName = oid + "_" + version + ".zip"; + return HdlFileLogic.getInstance().getFirmwareRootPath() + "/" + fileName; } //endregion 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 972a3c6..0d490d5 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java @@ -88,11 +88,16 @@ private Intent intentServer = null; private ServiceConnection mServiceConnection = null; + /** + * 鏈嶅姟鏄惁寮�鍚� true=寮�鍚� + */ + public boolean mServiceStart = false; /** * true琛ㄧず缁堟涓嬭浇鍗囩骇鏂囦欢(鐢ㄦ埛琛屼负) */ private boolean stopDownload = false; + //region -----鍥轰欢鍗囩骇--------- @@ -250,59 +255,6 @@ } - /** - * 鍚戜簯绔幏鍙栥�愯澶囧浐浠躲�戝崌绾у寘涓嬭浇鍦板潃 - * - * @param firmwareVersionId 鍥轰欢鐗堟湰Id - */ - public void getDeviceFirmwareDownloadUrl(String firmwareVersionId, CloudCallBeak<DownloadUrlBean> callBack) { -// "protocolType":"bus", -// "deviceModel":"029B9988", -// "firmwareNameEn":"鏍稿績灞�", -// "firmwareNameCn":"鏍稿績灞�", -// "imageId":"12345678", -// "version":"V01.02.20" - String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; - JsonObject json = new JsonObject(); - json.addProperty("firmwareVersionId", firmwareVersionId); - HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { - @Override - public void onSuccess(String json) { - - if (TextUtils.isEmpty(json)) { - if (callBack != null) { - callBack.onSuccess(new DownloadUrlBean()); - } - return; - } - Gson gson = new Gson(); - Type typeOfT = new TypeToken<DownloadUrlBean>() { - }.getType(); - DownloadUrlBean downloadUrlBean = gson.fromJson(json, typeOfT); - if (callBack != null) { - callBack.onSuccess(downloadUrlBean); - } - } - - @Override - public void onFailure(HDLException e) { - if (callBack != null) { - callBack.onFailure(e); - } - } - }); - } - - /** - * 鍚戜簯绔幏鍙栥�愯澶囧浐浠躲�戜笅杞藉崌绾ф枃浠� - * - * @param downloadUrl 浜戠鍥轰欢鍦板潃 - */ - public void getDeviceFirmwareDownloadFile(String downloadUrl, CloudCallBeak<DownloadUrlBean> callBack) { - String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl; - JsonObject json = new JsonObject(); - - } //endregion @@ -394,15 +346,9 @@ } - /** - * 璁剧疆缁堟涓嬭浇鏂囦欢鎸囦护 - */ - public void setStopDriversDownload() { - this.stopDownload = true; - } /** - * 浜戠鍙戣捣銆愯澶囬┍鍔ㄣ�戝崌绾TA鎸囦护 + * 浜戠鍙戣捣銆愯澶囬┍鍔ㄥ崌绾с�慜TA鎸囦护 * * @param oid 缃戝叧璁惧oid * @param driverVersionId 椹卞姩鐗堟湰id @@ -431,12 +377,22 @@ }); } + + //endregion + /** - * 鍚戜簯绔幏鍙栥�愯澶囬┍鍔ㄣ�戜笅杞藉崌绾ф枃浠� + * 璁剧疆缁堟涓嬭浇鏂囦欢鎸囦护 + */ + public void setStopDriversDownload() { + this.stopDownload = true; + } + + /** + * 鍚戜簯绔幏鍙栥�愯澶囧崌绾ф枃浠�(椹卞姩,鍥轰欢)涓嬭浇銆戝崌绾ф枃浠� * * @param downloadUrl 浜戠椹卞姩鍦板潃 */ - public void getDeviceDriverDownloadFile(String downloadUrl, CloudCallBeak<ResponseBody> callBack) { + public void getDeviceUpgradeDownloadFile(String downloadUrl, CloudCallBeak<ResponseBody> callBack) { HttpClient.getInstance().downLoadFile(downloadUrl, new CloudCallBeak<ResponseBody>() { @Override public void onSuccess(ResponseBody s) { @@ -456,9 +412,6 @@ } - - - //endregion /** * 鏈湴鍗囩骇鍖呮帹閫�(鍛婅瘔缃戝叧涓嬭浇鍗囩骇鍖呭湴鍧�绛変俊鎭�) @@ -514,6 +467,7 @@ intentServer = new Intent(); intentServer.setClass(HDLApp.getInstance(), MyNanoHttpService.class); this.mServiceConnection = serviceConnection; + this.mServiceStart = true; //鍚姩鏈嶅姟鐩戝惉 HDLApp.getInstance().bindService(intentServer, serviceConnection, Context.BIND_AUTO_CREATE); } @@ -524,6 +478,7 @@ public void unLocalService() { if (intentServer != null && this.mServiceConnection != null) { HDLApp.getInstance().unbindService(this.mServiceConnection); + this.mServiceStart = false; } } @@ -538,11 +493,11 @@ String driver = driver_type; //-100:娌℃湁鏁版嵁;-101:娌℃湁md5绉橀挜;-102:md5绉橀挜涓嶅;-103:鏈夊紓甯�; if (zipData == null) { - this.eventBusPost(fullPath,driver, -100, "娌℃湁鏁版嵁"); + this.eventBusPost(fullPath, driver, -100, "娌℃湁鏁版嵁"); return false; } if (TextUtils.isEmpty(md5)) { - this.eventBusPost(fullPath,driver, -101, "娌℃湁md5绉橀挜"); + this.eventBusPost(fullPath, driver, -101, "娌℃湁md5绉橀挜"); return false; } InputStream is = null; @@ -555,7 +510,7 @@ is = zipData.byteStream(); long total = zipData.contentLength(); if (total == 0) { - this.eventBusPost(fullPath,driver, -100, "娌℃湁鏁版嵁"); + this.eventBusPost(fullPath, driver, -100, "娌℃湁鏁版嵁"); return false; } fos = new FileOutputStream(file); @@ -567,7 +522,7 @@ int progress = (int) (100 * sum * 1.0f / total); if (sum != total) { //涓嶇瓑浜�100閮借鎶�,绛変簬100澶勭悊鏁村潡閫昏緫瀹屼箣鍚庡啀鎶�100; - this.eventBusPost(fullPath,driver, progress, "姝e父涓婃姤"); + this.eventBusPost(fullPath, driver, progress, "姝e父涓婃姤"); } } fos.flush(); @@ -576,19 +531,19 @@ byte[] bytes = FileUtils.readFileToByteArray(file); String fileMD5 = Md5Utils.encodeMD5(bytes); if (TextUtils.isEmpty(fileMD5)) { - this.eventBusPost(fullPath,driver, -106, "鏂囦欢鐢熸垚md5澶辫触."); + this.eventBusPost(fullPath, driver, -106, "鏂囦欢鐢熸垚md5澶辫触."); return false; } if (!md5.equals(fileMD5)) { - this.eventBusPost(fullPath,driver, -107, "md5姣斿澶辫触."); + this.eventBusPost(fullPath, driver, -107, "md5姣斿澶辫触."); return false; } - this.eventBusPost(fullPath,driver, 100, "涓嬭浇瀹屾垚."); + this.eventBusPost(fullPath, driver, 100, "涓嬭浇瀹屾垚."); return true; } catch (Exception e) { - this.eventBusPost(fullPath,driver, -103, e.getMessage()); + this.eventBusPost(fullPath, driver, -103, e.getMessage()); e.printStackTrace(); } return false; @@ -691,8 +646,8 @@ BaseEventBus baseEventBus = new BaseEventBus(); baseEventBus.setTopic(localDownloadProgress); Progress progress = new Progress(); - progress.step = progressValue; - progress.describe = describe; + progress.step = -108; + progress.describe = "鐢ㄦ埛鍙栨秷涓嬭浇."; baseEventBus.setType(type); baseEventBus.setData(progress); EventBus.getDefault().post(baseEventBus); 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 36f0772..f18ca66 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java @@ -272,6 +272,16 @@ this.uniCancelDownloadingUpgradeFile(data, callback); } break; + //鎵撳紑鏈嶅姟 + case HDLUniMP.UNI_EVENT_REPLY_OTA_OPEN_SERVICE: { + this.uniOpenService(data, callback); + } + break; + //鍏抽棴鏈嶅姟 + case HDLUniMP.UNI_EVENT_REPLY_OTA_CLOSE_SERVICE: { + this.uniCloseService(data, callback); + } + break; } } @@ -345,7 +355,7 @@ * 鍓嶆彁鏉′欢:璁惧鑷姩涓婃姤oid淇℃伅缁欎簯绔� */ private void uniGetCurrentDeviceFirmwares(Object data, DCUniMPJSCallback callback) { - String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data)); + String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//浜戠涓婅澶噄d HdlOtaLogic.getInstance().getCurrentDeviceFirmwares(deviceOidId, new CloudCallBeak<List<DeviceFirmwareBean>>() { @Override public void onSuccess(List<DeviceFirmwareBean> obj) { @@ -409,19 +419,32 @@ } /** - * 鍚戜簯绔彂璧枫�愯澶囧浐浠躲�戜笅杞芥寚浠� + * 鍚戜簯绔彂璧枫�愯澶囧浐浠朵笅杞姐�戞寚浠� */ private void uniDeviceFirmwareDownload(Object data, DCUniMPJSCallback callback) { - String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//璁惧id - String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//鍥轰欢鐗堟湰id - HdlOtaLogic.getInstance().getDeviceFirmwareDownloadUrl(firmwareVersionId, new CloudCallBeak<DownloadUrlBean>() { + String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//浜戠涓婅澶噄d + 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));//鍌ㄥ瓨鍦ㄦ湰鍦伴┍鍔ㄦ枃浠惰矾寰� + String url = getKeyValue("url", getKeyValue("data", data));//浜戠涓婃枃浠跺湴鍧� + String md5 = getKeyValue("md5", getKeyValue("data", data));//浜戠涓婃枃浠禡D5 + HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() { @Override - public void onSuccess(DownloadUrlBean obj) { - uniCallbackData(obj, callback); + 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); } @Override public void onFailure(HDLException e) { + HdlLogLogic.print("涓嬭浇鍥轰欢鏂囦欢鍒板唴瀛樺け璐�.", false); uniCallbackData(null, e.getCode(), e.getMsg(), callback); } }); @@ -431,30 +454,61 @@ * 鍚戜簯绔彂璧枫�愯澶囧浐浠躲�戝崌绾TA鎸囦护 */ private void uniUpgradeDeviceFirmware(Object data, DCUniMPJSCallback callback) { - String deviceMac = getKeyValue("mac", getKeyValue("data", data));//缃戝叧璁惧mac锛堟煡鎵緎ocket锛� - String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//璁惧id + String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//浜戠涓婅澶噄d + String oid = getKeyValue("oid", getKeyValue("data", data));//璁惧id String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//鍥轰欢鐗堟湰id - + String version = getKeyValue("version", getKeyValue("data", data));//椹卞姩鐗堟湰 + String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//浜戠涓婃枃浠禡D5 //鍗囩骇鏈湴浼樺厛->浜戠鍗囩骇 boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac); if (isLocalConnect) { //鏈湴 //1,寤虹珛鏈湴鏈嶅姟锛� - // 2锛屽憡璇夌綉鍏虫墜鏈篿p鍜岀鍙o紱 + //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>() { + @Override + public void onSuccess(String obj) { + HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�鎴愬姛.", false); + } + + @Override + public void onError(HDLLinkException e) { + HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", false); + 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:杩愯,5:绂荤嚎,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�) + //1锛氳繛鎺ヤ腑,2锛氭晠闅�,3锛氳繍琛�,4锛氱绾�,6:閫嗗彉鍣ㄨ繛涓嶄笂浜�(鑷畾涔�) if (cloudInverterDeviceBean == null) { uniCallbackData(null, 6, HDLApp.getInstance().getString(R.string.ota_not_cloud_upgrade_fails), callback); return; } - if (cloudInverterDeviceBean.getDeviceStatus() != 4) { + if (cloudInverterDeviceBean.getDeviceStatus() != 3) { uniCallbackData(null, cloudInverterDeviceBean.getDeviceStatus(), getDeviceStatusString(cloudInverterDeviceBean.getDeviceStatus()), callback); return; } @@ -480,8 +534,6 @@ }); } - - } /** @@ -569,7 +621,7 @@ String localUrl = getKeyValue("localUrl", getKeyValue("data", data));//鍌ㄥ瓨鍦ㄦ湰鍦伴┍鍔ㄦ枃浠惰矾寰� String url = getKeyValue("url", getKeyValue("data", data));//浜戠涓婃枃浠跺湴鍧� String md5 = getKeyValue("md5", getKeyValue("data", data));//浜戠涓婃枃浠禡D5 - HdlOtaLogic.getInstance().getDeviceDriverDownloadFile(url, new CloudCallBeak<ResponseBody>() { + HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() { @Override public void onSuccess(ResponseBody responseBody) { String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version); @@ -682,6 +734,29 @@ HdlOtaLogic.getInstance().setStopDriversDownload(); } + /** + * 寮�鍚湇鍔� + */ + private void uniOpenService(Object data, DCUniMPJSCallback callback) { + HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() { + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + } + + @Override + public void onServiceDisconnected(ComponentName name) { + HdlOtaLogic.getInstance().mServiceStart = false; + } + }); + } + + /** + * 鍏抽棴鏈嶅姟 + */ + private void uniCloseService(Object data, DCUniMPJSCallback callback) { + HdlOtaLogic.getInstance().unLocalService(); + } + /** * @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 771e5b0..5dc0a4d 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java @@ -408,7 +408,7 @@ 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>() { + HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile("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"); 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 f19a682..39c5e11 100644 --- a/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java +++ b/app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java @@ -54,6 +54,8 @@ 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";//璁惧鍙栨秷涓嬭浇鍗囩骇鏂囦欢 + public final static String UNI_EVENT_REPLY_OTA_OPEN_SERVICE = "open_service";//鎵撳紑鏈嶅姟 + public final static String UNI_EVENT_REPLY_OTA_CLOSE_SERVICE = "close_service";//鍏抽棴鏈嶅姟 /*********Wifi妯″潡*********/ //鍗敠瀹氫箟 -- Gitblit v1.8.0