New file |
| | |
| | | package com.hdl.linkpm.sdk.ota.controller; |
| | | |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.hdlhttp.HxHttp; |
| | | import com.hdl.linkpm.sdk.core.api.HDLCloudHomeApi; |
| | | import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack; |
| | | import com.hdl.linkpm.sdk.core.callback.IResponseCallBack; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.core.response.HDLResponse; |
| | | 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.FirmwareBean; |
| | | import com.hdl.linkpm.sdk.ota.bean.GatewayDriverBean; |
| | | import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils; |
| | | |
| | | import java.util.List; |
| | | |
| | | import io.reactivex.rxjava3.disposables.Disposable; |
| | | import io.reactivex.rxjava3.schedulers.Schedulers; |
| | | import io.reactivex.rxjava3.subscribers.DisposableSubscriber; |
| | | import okhttp3.ResponseBody; |
| | | |
| | | /** |
| | | * Created by jlchen on 12/17/21. |
| | | * OTA 网关、设备固件查询和下载相关管理 |
| | | */ |
| | | public class HDLPMOtaController { |
| | | /** |
| | | * instance |
| | | */ |
| | | private volatile static HDLPMOtaController instance; |
| | | |
| | | /** |
| | | * getInstance |
| | | * |
| | | * @return HDLPMOtaController |
| | | */ |
| | | public static synchronized HDLPMOtaController getInstance() { |
| | | if (instance == null) { |
| | | synchronized (HDLPMOtaController.class) { |
| | | if (instance == null) { |
| | | instance = new HDLPMOtaController(); |
| | | } |
| | | } |
| | | } |
| | | return instance; |
| | | } |
| | | |
| | | /** |
| | | * 原生设备获取固件升级包下载地址 |
| | | * |
| | | * @param firmwareVersionId 固件版本Id |
| | | * @return downloadUrl |
| | | */ |
| | | public Disposable getNativeDeviceFirmwareDownloadUrl(String firmwareVersionId, IResponseCallBack<DownloadUrlBean> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("firmwareVersionId", firmwareVersionId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_NativeDeviceFirmwareDownloadUrl); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<DownloadUrlBean>() { |
| | | @Override |
| | | public void onResponse(DownloadUrlBean response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * Link网关驱动列表获取 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param oid 网关设备oid |
| | | * @param callBack |
| | | * @return |
| | | */ |
| | | public Disposable getGatewayDrivers(String homeId, String oid, IResponseCallBack<List<GatewayDriverBean>> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("oid", oid); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_GatewayDrivers); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<List<GatewayDriverBean>>() { |
| | | @Override |
| | | public void onResponse(List<GatewayDriverBean> response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * Link网关驱动->获取存储在云端的驱动分页列表 |
| | | * |
| | | * @param driveCode 驱动编号或驱动名称 |
| | | * @param osImageId 驱动类型id |
| | | * @param callBack |
| | | * @return |
| | | */ |
| | | public Disposable getCloudGatewayDrivers(String driveCode, String osImageId, IResponseCallBack<CloudGatewayDriversBean> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("driveCode", driveCode); |
| | | json.addProperty("osImageId", osImageId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_CloudGatewayDrivers); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<CloudGatewayDriversBean>() { |
| | | @Override |
| | | public void onResponse(CloudGatewayDriversBean response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * Link网关驱动升级OTA命令下发 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param oid 网关设备oid |
| | | * @param driverVersionId 驱动版本id |
| | | * @param callBack |
| | | * @return |
| | | */ |
| | | public Disposable upgradeGatewayDriver(String homeId, String oid, String driverVersionId, IDefaultCallBack callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("oid", oid); |
| | | json.addProperty("driverVersionId", driverVersionId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GatewayDriverUpgrade); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<String>() { |
| | | @Override |
| | | public void onResponse(String response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取IARCC三方固件分页 |
| | | * |
| | | * @param json 请求数据 |
| | | * @param callBack 回调 |
| | | * @return |
| | | */ |
| | | public Disposable getACIARCCFirmware(String json, IResponseCallBack<List<FirmwareBean>> callBack) { |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_FIRMWARE_PAGE); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<List<FirmwareBean>>() { |
| | | @Override |
| | | public void onResponse(List<FirmwareBean> list) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取IARCC三方固件分类 |
| | | * |
| | | * @param json 请求数据 |
| | | * @param callBack 回调 |
| | | * @return |
| | | */ |
| | | public Disposable getACIARCCFirmwareList(String json, IResponseCallBack<List<FirmwareBean>> callBack) { |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_FIRMWARE_LIST); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<List<FirmwareBean>>() { |
| | | @Override |
| | | public void onResponse(List<FirmwareBean> list) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 下载IARCC固件 |
| | | * |
| | | * @param requestUrl 请求地址 |
| | | * @param callBack 回调 |
| | | * @return |
| | | */ |
| | | public Disposable downloadCloudACIARCCFirmware(String requestUrl, IResponseCallBack<ResponseBody> callBack) { |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .build() |
| | | .download() |
| | | .observeOn(Schedulers.io()) |
| | | .subscribeWith(new DisposableSubscriber<ResponseBody>() { |
| | | @Override |
| | | public void onNext(ResponseBody responseBody) { |
| | | try { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(responseBody); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(Throwable t) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, null, t); |
| | | } |
| | | |
| | | @Override |
| | | public void onComplete() { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * LINK网关获取驱动升级包下载地址 |
| | | * |
| | | * @param driverVersionId 驱动版本Id |
| | | * @return |
| | | */ |
| | | public Disposable getLinkDeviceDriverDownloadUrl(String driverVersionId, IResponseCallBack<DownloadUrlBean> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("driverVersionId", driverVersionId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_LinkDeviceDriverDownloadUrl); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<DownloadUrlBean>() { |
| | | @Override |
| | | public void onResponse(DownloadUrlBean response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取设备固件列表获取 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param deviceOidId oid云端id |
| | | * @param callBack |
| | | * @return |
| | | */ |
| | | public Disposable getDeviceFirmwares(String homeId, String deviceOidId, IResponseCallBack<List<DeviceFirmwareBean>> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("deviceOidId", deviceOidId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_DeviceFirmwares); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<List<DeviceFirmwareBean>>() { |
| | | @Override |
| | | public void onResponse(List<DeviceFirmwareBean> response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取设备固件列表获取->获取存储在云端的固件分页列表 |
| | | * |
| | | * @param hardwareModel 硬件型号 |
| | | * @param osImageId 系统镜像id |
| | | * @param callBack |
| | | * @return |
| | | */ |
| | | public Disposable getCloudDeviceFirmwares(String hardwareModel, String osImageId, IResponseCallBack<List<CloudDeviceFirmwaresBean>> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("hardwareModel", hardwareModel); |
| | | json.addProperty("osImageId", osImageId); |
| | | json.addProperty("protocolType", "ZIGBEE");//协议类型,可用值:BUSPRO,KNX,ZIGBEE,OTHER |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_CloudDeviceFirmwares); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<List<CloudDeviceFirmwaresBean>>() { |
| | | @Override |
| | | public void onResponse(List<CloudDeviceFirmwaresBean> response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * Link设备固件升级OTA命令下发 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param deviceOidId 设备id |
| | | * @param firmwareVersionId 固件版本id |
| | | * @param callBack |
| | | * @return |
| | | */ |
| | | public Disposable upgradeDeviceFirmware(String homeId, String deviceOidId, String firmwareVersionId, IDefaultCallBack callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("deviceOidId", deviceOidId); |
| | | json.addProperty("firmwareVersionId", firmwareVersionId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_DeviceFirmwareUpgrade); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<String>() { |
| | | @Override |
| | | public void onResponse(String response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * LINK设备获取固件升级包下载地址 |
| | | * |
| | | * @param firmwareVersionId 固件版本Id |
| | | * @return |
| | | */ |
| | | public Disposable getLinkDeviceFirmwareDownloadUrl(String firmwareVersionId, IResponseCallBack<DownloadUrlBean> callBack) { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("firmwareVersionId", firmwareVersionId); |
| | | String requestUrl = HDLCloudHomeApi.getRequestUrl(HDLCloudHomeApi.POST_OTA_GET_LinkDeviceFirmwareDownloadUrl); |
| | | return HxHttp.builder() |
| | | .url(requestUrl) |
| | | .raw(json.toString()) |
| | | .build() |
| | | .post() |
| | | .subscribeWith(new HDLResponse<DownloadUrlBean>() { |
| | | @Override |
| | | public void onResponse(DownloadUrlBean response) { |
| | | if (callBack != null) { |
| | | callBack.onSuccess(response); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HDLExceptionSubmitUtils.submit(requestUrl, json, e); |
| | | if (callBack != null) { |
| | | callBack.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |