| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | |
| | | import android.content.ComponentName; |
| | | import android.content.Context; |
| | | import android.content.Intent; |
| | | import android.content.ServiceConnection; |
| | | import android.os.IBinder; |
| | | import android.text.TextUtils; |
| | | import android.util.Log; |
| | | |
| | |
| | | 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; |
| | | import com.hdl.photovoltaic.R; |
| | | 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; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceTimeBean; |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.WifiUtils; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkCode; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | |
| | | import org.json.JSONObject; |
| | | |
| | | |
| | | import java.io.File; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | import io.dcloud.feature.unimp.DCUniMPJSCallback; |
| | | import okhttp3.ResponseBody; |
| | | |
| | | /** |
| | | * uni小程序的逻辑 |
| | |
| | | } |
| | | return sHdlUniLogic; |
| | | } |
| | | |
| | | |
| | | //region ******【原生】和【小程序】通讯的3个方法名 onOtherUniMPEventReceive();openUniMP();sendUni();****** |
| | | |
| | |
| | | this.uniGetCurrentHomeLocalAndCloudGatewayList(callback); |
| | | } |
| | | break; |
| | | //modBus协议专用 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: { |
| | | sendModBus(data, callback); |
| | | } |
| | |
| | | this.uniUpgradeGatewayDriver(data, callback); |
| | | } |
| | | break; |
| | | //设备取消下载升级文件 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: { |
| | | 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; |
| | | |
| | | } |
| | | } else if (HDLUniMP.UNI_EVENT_REPLY_OTHER_MODEL.equals(event)) { |
| | | //其它模块 |
| | | switch (type) { |
| | | //获取温度单位 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTHER_UNIT: { |
| | | uniCallbackData(UserConfigManage.getInstance().getTemperature_unit(), callback); |
| | | } |
| | | break; |
| | | //获取当前app语言 |
| | | case HDLUniMP.UNI_EVENT_REPLY_OTHER_APP_LANGUAGE: { |
| | | uniCallbackData(UserConfigManage.getInstance().getCurrentAppLanguage(), callback); |
| | | } |
| | | break; |
| | | } |
| | | } |
| | | HdlLogLogic.print("uni===原生接收uni发来的数据===" + event + "\r\n" + data, false); |
| | |
| | | |
| | | |
| | | /** |
| | | * 原生打开uni指定页面 |
| | | * 原生【打开】uni指定页面 |
| | | * |
| | | * @param path 打开路径 |
| | | * @param jsonObject 附件数据(没有数据填null) |
| | |
| | | * 注意:需要提前小程序在运行才可成功 |
| | | * |
| | | * @param topic 主题大类(如:UNI_EVENT_REPLY_HOME_MODEL) |
| | | * @param callBackBaseBean —— |
| | | * @param callBackBaseBean 自定义实体类 |
| | | */ |
| | | public void sendUni(String topic, HDLUniMP.UniCallBackBaseBean callBackBaseBean) { |
| | | try { |
| | |
| | | * 前提条件:设备自动上报oid信息给云端 |
| | | */ |
| | | private void uniGetCurrentDeviceFirmwares(Object data, DCUniMPJSCallback callback) { |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data)); |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//云端上设备id |
| | | HdlOtaLogic.getInstance().getCurrentDeviceFirmwares(deviceOidId, new CloudCallBeak<List<DeviceFirmwareBean>>() { |
| | | @Override |
| | | public void onSuccess(List<DeviceFirmwareBean> obj) { |
| | |
| | | * 获取【设备本地固件】列表 |
| | | */ |
| | | private void uniGetLocalFirmwares(Object data, DCUniMPJSCallback callback) { |
| | | String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//硬件型号 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//系统镜像id |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//系统镜像id |
| | | try { |
| | | 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(oid)) { |
| | | // 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())); |
| | | list.add(deviceFirmwareBean); |
| | | } |
| | | } |
| | | if (callback != null) { |
| | | this.uniCallbackData(list, callback); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备固件】下载指令 |
| | | * 向云端发起【设备固件下载】指令 |
| | | */ |
| | | 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));//云端上设备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));//储存在本地固件文件路径 |
| | | String url = getKeyValue("url", getKeyValue("data", data));//云端上文件地址 |
| | | String md5 = getKeyValue("md5", getKeyValue("data", data));//云端上文件MD5 |
| | | 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); |
| | | } |
| | | }); |
| | |
| | | * 向云端发起【设备固件】升级OTA指令 |
| | | */ |
| | | private void uniUpgradeDeviceFirmware(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | String deviceMac = getKeyValue("mac", getKeyValue("data", data));//网关设备mac(查找socket) |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//设备id |
| | | String deviceMac = getKeyValue("mac", getKeyValue("data", data));//逆变器设备mac(查找socket) |
| | | String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//云端上设备id |
| | | String oid = getKeyValue("oid", getKeyValue("data", data));//升级固件的oid |
| | | String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | String version = getKeyValue("version", getKeyValue("data", data));//固件版本 |
| | | String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//云端上文件MD5 |
| | | |
| | | //升级本地优先->云端升级 |
| | | boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac); |
| | | if (isLocalConnect) { |
| | | //本地 |
| | | //1,建立本地服务; |
| | | // 2,告诉网关手机ip和端口; |
| | | //2,告诉网关手机ip和端口; |
| | | //实例化 获取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 { |
| | | //云端 |
| | | HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() { |
| | | //远程升级需要检测在逆变器有没有连接上云 |
| | | 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 |
| | |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | |
| | | * 获取【设备本地驱动】列表 |
| | | */ |
| | | private void uniGetLocalDrivers(Object data, DCUniMPJSCallback callback) { |
| | | String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//驱动编号或驱动名称 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动类型id |
| | | try { |
| | | String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//驱动编号或驱动名称 |
| | | String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动类型id |
| | | List<GatewayDriverBean> list = new ArrayList<>(); |
| | | String driverFileList = HdlFileLogic.getInstance().getDriveRootPath(); |
| | | File file = new File(driverFileList); |
| | | if (file.list() != null) { |
| | | for (int i = 0; i < Objects.requireNonNull(file.list()).length; i++) { |
| | | String fileName = Objects.requireNonNull(file.list())[i]; |
| | | if (!fileName.contains(driveCode)) { |
| | | continue; |
| | | } |
| | | String[] driverInfoAry = fileName.split("_"); |
| | | GatewayDriverBean gatewayDriverBean = new GatewayDriverBean(); |
| | | gatewayDriverBean.setDriverCode(driverInfoAry[0]); |
| | | gatewayDriverBean.setVersion(driverInfoAry[1].replace(".zip", "")); |
| | | gatewayDriverBean.setLocalUrl(HdlFileLogic.getInstance().getDrivePathFileName(gatewayDriverBean.getDriverCode(), gatewayDriverBean.getVersion())); |
| | | list.add(gatewayDriverBean); |
| | | } |
| | | } |
| | | if (callback != null) { |
| | | this.uniCallbackData(list, callback); |
| | | } |
| | | } catch (Exception exception) { |
| | | this.uniCallbackData(new ArrayList<>(), callback); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备驱动】下载指令 |
| | | * 向云端发起【设备驱动下载】指令 |
| | | */ |
| | | private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//网关设备oid |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//逆变器设备oid |
| | | String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//驱动编码 |
| | | String imageId = getKeyValue("imageId", getKeyValue("data", data));//驱动镜像id |
| | | String version = getKeyValue("version", getKeyValue("data", data));//驱动版本 |
| | | String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id |
| | | HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() { |
| | | String localUrl = getKeyValue("localUrl", getKeyValue("data", data));//储存在本地驱动文件路径 |
| | | String url = getKeyValue("url", getKeyValue("data", data));//云端上文件地址 |
| | | String md5 = getKeyValue("md5", getKeyValue("data", data));//云端上文件MD5 |
| | | HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(obj, callback); |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("下载驱动文件到内存失败.", false); |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | |
| | | */ |
| | | private void uniUpgradeGatewayDriver(Object data, DCUniMPJSCallback callback) { |
| | | |
| | | String deviceMac = getKeyValue("mac", getKeyValue("data", data));//网关设备mac(查找socket) |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//网关设备oid |
| | | String deviceMac = getKeyValue("mac", getKeyValue("data", data));//逆变器设备mac(查找socket) |
| | | String deviceOid = getKeyValue("oid", getKeyValue("data", data));//逆变器设备oid |
| | | 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));//驱动编码 |
| | | //升级本地优先->云端升级 |
| | | boolean isLocalConnect = HdlDeviceLogic.getInstance().isLocalConnect(deviceMac); |
| | | if (isLocalConnect) { |
| | | //本地 |
| | | //1,建立本地服务; |
| | | // 2,告诉网关手机ip和端口; |
| | | |
| | | } else { |
| | | HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() { |
| | | //实例化 获取ip 地址 |
| | | HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | uniCallbackData(obj, callback); |
| | | 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>() { |
| | | @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:离线,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 |
| | |
| | | uniCallbackData(null, e.getCode(), e.getMsg(), callback); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 取消下载升级文件 |
| | | */ |
| | | private void uniCancelDownloadingUpgradeFile(Object data, DCUniMPJSCallback callback) { |
| | | 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:离线) |
| | | * @return 返回文本 |
| | | */ |
| | | public String getDeviceStatusString(int deviceStatus) { |
| | | switch (deviceStatus) { |
| | | case 1: { |
| | | return HDLApp.getInstance().getString(R.string.my_power_station_connecting); |
| | | } |
| | | case 2: { |
| | | return HDLApp.getInstance().getString(R.string.my_power_station_malfunction); |
| | | } |
| | | case 4: { |
| | | return HDLApp.getInstance().getString(R.string.my_power_station_off_line); |
| | | } |
| | | default: |
| | | return ""; |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | public void onSuccess(List<GatewayBean> list) { |
| | | if (callback != null) { |
| | | uniCallbackData(list, callback); |
| | | //EventBus事件分发 |
| | | //EventBus事件分发,进入住宅开始订阅主题 |
| | | BaseEventBus baseEventBus = new BaseEventBus(); |
| | | baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST); |
| | | baseEventBus.setData(list); |
| | | EventBus.getDefault().post(baseEventBus); |
| | | GatewayBean gatewayBean = HdlDeviceLogic.getInstance().queryCurrentHomeMainGateway(list); |
| | | if (gatewayBean != null) { |
| | | //进来住宅详情都要上传一次oid列表到云端; |
| | | HdlDeviceLogic.getInstance().uploadDataToCloud(gatewayBean.getDevice_mac(), null); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |
| | | |