| | |
| | | this.uniGetCurrentHomeLocalAndCloudGatewayList(callback); |
| | | } |
| | | break; |
| | | //modBus协议专用 |
| | | case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: { |
| | | sendModBus(data, callback); |
| | | } |
| | |
| | | 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) |
| | |
| | | * 前提条件:设备自动上报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) { |
| | |
| | | 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 firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id |
| | | List<DeviceFirmwareBean> list = new ArrayList<>(); |
| | | String driverFileList = HdlFileLogic.getInstance().getFirmwareRootPath(); |
| | | File file = new File(driverFileList); |
| | |
| | | String[] ary = path.split("/"); |
| | | String[] driverInfoAry = ary[ary.length - 1].split("_"); |
| | | DeviceFirmwareBean deviceFirmwareBean = new DeviceFirmwareBean(); |
| | | deviceFirmwareBean.setVersion(driverInfoAry[0]); |
| | | deviceFirmwareBean.setImageId(driverInfoAry[1].replace(".zip", "")); |
| | | deviceFirmwareBean.setOid(driverInfoAry[0]); |
| | | deviceFirmwareBean.setVersion(driverInfoAry[1].replace(".zip", "")); |
| | | deviceFirmwareBean.setLocalUrl(HdlFileLogic.getInstance().getFirmwarePathFileName(deviceFirmwareBean.getOid(), deviceFirmwareBean.getVersion())); |
| | | list.add(deviceFirmwareBean); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 向云端发起【设备固件】下载指令 |
| | | * 向云端发起【设备固件下载】指令 |
| | | */ |
| | | 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 { |
| | | //远程升级需要检测在逆变器有没有连接上云 |
| | | 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:运行 |
| | |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * 向云端发起【设备驱动下载】指令 |
| | | */ |
| | | 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 localUrl = getKeyValue("localUrl", getKeyValue("data", data));//储存在本地驱动文件路径 |
| | | String url = getKeyValue("url", getKeyValue("data", data));//云端上文件地址 |
| | | String md5 = getKeyValue("md5", getKeyValue("data", data));//云端上文件MD5 |
| | | 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); |
| | | boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5, HdlOtaLogic.driver_type); |
| | | if (isBoolean) { |
| | | HdlFileLogic.getInstance().deleteFile(localUrl);//下载成功,删除旧文件; |
| | | HdlFileLogic.getInstance().deleteFile(localUrl);//下载成功,删除旧驱动文件; |
| | | } else { |
| | | HdlFileLogic.getInstance().deleteFile(drivePathFileName);//下载失败删除不完成数据; |
| | | HdlFileLogic.getInstance().deleteFile(drivePathFileName);//下载失败,删除不完整驱动文件; |
| | | } |
| | | HdlLogLogic.print("写入新驱动文件到内存成功.", false); |
| | | } |
| | |
| | | */ |
| | | 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));//驱动版本号 |
| | |
| | | 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; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * @param deviceStatus 逆变器连接云端状态值( 1:待机,2:连接中,3:故障,4:运行,5:离线) |
| | | * 关闭服务 |
| | | */ |
| | | 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_await); |
| | | } |
| | | case 2: { |
| | | return HDLApp.getInstance().getString(R.string.my_power_station_connecting); |
| | | } |
| | | case 3: { |
| | | case 2: { |
| | | return HDLApp.getInstance().getString(R.string.my_power_station_malfunction); |
| | | } |
| | | case 5: { |
| | | case 4: { |
| | | return HDLApp.getInstance().getString(R.string.my_power_station_off_line); |
| | | } |
| | | default: |