From 78dbac2e8e7ad58d9e5d6a025de0d6fc58f69146 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 21 十二月 2023 21:17:15 +0800 Subject: [PATCH] 2023年12月21日21:17:08 --- app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 424 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 281 insertions(+), 143 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 3c1c9b4..0667e34 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; @@ -268,9 +264,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; //鎵撳紑鏈嶅姟 @@ -300,9 +309,9 @@ break; } } - HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===澶х被->" + topic + "\r\n" + data, false); + HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===澶х被->" + topic + "\r\n" + data, true); } catch (Exception e) { - HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===" + e.getMessage(), false); + HdlLogLogic.print("uni===鍘熺敓鎺ユ敹uni鍙戞潵鐨勬暟鎹�===" + e.getMessage(), true); } } @@ -453,14 +462,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);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣鍥轰欢鏂囦欢; - } - HdlLogLogic.print("鍐欏叆鏂板浐浠舵枃浠跺埌鍐呭瓨鎴愬姛.", true); + 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 @@ -482,67 +505,77 @@ 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, imageId, version); - String data = HdlFileLogic.getInstance().readFile(firmwarePathFileName); - if (TextUtils.isEmpty(data)) { - uniCallbackData(null, -2, "鏈湴鎵句笉鍒板崌绾у浐浠舵枃浠�,璇蜂笅杞藉ソ鍥轰欢鏂囦欢,鍐嶉噸鏂板崌绾�.", callback); - return; - } - 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) { + //鏈湴 + //1,寤虹珛鏈湴鏈嶅姟锛� + //2,鍛婅瘔缃戝叧鎵嬫満ip鍜岀鍙o紱 + //瀹炰緥鍖� 鑾峰彇ip 鍦板潃 + HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() { @Override - public void onSuccess(String obj) { - HdlLogLogic.print("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�鎴愬姛.", true); + 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://" + AppManagerUtils.getAppManager().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("閫氱煡缁欑綉鍏冲崌绾у浐浠舵枃浠跺湴鍧�澶辫触,鏃犳硶鍗囩骇.", true); - 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 { + //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯 + 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 @@ -550,16 +583,47 @@ 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) { + //杩滅▼鍗囩骇闇�瑕佹娴嬪湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯 + 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); + } + }); + } + }); + } /** @@ -650,14 +714,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);//涓嬭浇澶辫触锛屽垹闄や笉瀹屾暣椹卞姩鏂囦欢; - } - HdlLogLogic.print("鍐欏叆鏂伴┍鍔ㄦ枃浠跺埌鍐呭瓨鎴愬姛.", true); + 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 @@ -676,68 +754,79 @@ 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); - if (TextUtils.isEmpty(data)) { - uniCallbackData(null, -2, "鏈湴鎵句笉鍒板崌绾ч┍鍔ㄦ枃浠�,璇蜂笅杞藉ソ椹卞姩鏂囦欢,鍐嶉噸鏂板崌绾�.", callback); - return; - } - 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) { + //鏈湴 + //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://" + AppManagerUtils.getAppManager().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 { + //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯 + 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 @@ -745,23 +834,72 @@ 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) { + //杩滅▼鍗囩骇闇�瑕併�愭娴嬨�戝湪閫嗗彉鍣ㄦ湁娌℃湁杩炴帴涓婁簯 + 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) { + + } + }); } /** -- Gitblit v1.8.0