| | |
| | | |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | |
| | | 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.photovoltaic.HDLApp; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | | import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer; |
| | |
| | | import com.hdl.photovoltaic.utils.AppManagerUtils; |
| | | import com.hdl.photovoltaic.utils.Md5Utils; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.common.utils.ByteUtils; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.greenrobot.eventbus.EventBus; |
| | |
| | | /** |
| | | * 服务是否开启 true=开启 |
| | | */ |
| | | public boolean mServiceStart = false; |
| | | public boolean mServiceStart= false; |
| | | |
| | | /** |
| | | * true表示终止下载升级文件(用户行为) |
| | |
| | | |
| | | //endregion |
| | | |
| | | |
| | | /** |
| | | * 设置终止下载文件指令 |
| | | * 取消终止下载文件指令 |
| | | */ |
| | | public void setStopDriversDownload() { |
| | | public void stopDownloadUpgradeFile() { |
| | | this.stopDownload = true; |
| | | } |
| | | |
| | |
| | | */ |
| | | public void pushUpgradePacketInfo(String mac, String oid, String module, String version, String size, String url, String sign_method, LinkCallBack<String> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_UPGRADE_INFO; |
| | | JsonArray jsonArray = new JsonArray(); |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("oid", oid);// 物理设备oid |
| | | json.addProperty("module", module);//模块信息 |
| | |
| | | // json.addProperty("is_diff", is_diff);//true=增量包,false=全量包 |
| | | json.addProperty("size", size);//升级包大小 |
| | | json.addProperty("url", url);//升级包下载地址 |
| | | json.addProperty("sign_method", sign_method);//升级包签名类型:md5 |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { |
| | | json.addProperty("sign", sign_method);//升级包签名类型:md5 |
| | | json.addProperty("sign_method", "md5");//升级包签名类型:md5 |
| | | jsonArray.add(json); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonArray, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | if (linkCallBack != null) { |
| | |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 取消升级驱动,固件文件指令 |
| | | * |
| | | * @param mac 设备mac |
| | | * @param linkCallBack 回调update |
| | | */ |
| | | public void cancelUpgrade(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT; |
| | | // JsonObject json = new JsonObject(); |
| | | // json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | // json.addProperty("server_addr", AppConfigManage.getUserRegionUrl()); |
| | | // json.addProperty("local_secret", UserConfigManage.getInstance().getLocalSecret()); |
| | | // //解密负载数据(写密钥给网关一定是明文,因为那时网关还没有密钥) |
| | | // TcpClient.getInstance().sendDataToLinkGateway(mac, false, requestUrl, json, "", new HDLLinkCallBack() { |
| | | // @Override |
| | | // public void onSuccess(String msg) { |
| | | // GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); |
| | | // if (gatewayBean != null) { |
| | | // if (!TextUtils.isEmpty(UserConfigManage.getInstance().getLocalSecret())) { |
| | | // gatewayBean.setLocalEncrypt(true); |
| | | // } |
| | | // } |
| | | // if (linkCallBack != null) { |
| | | // linkCallBack.onSuccess(true); |
| | | // } |
| | | // |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onError(HDLLinkException e) { |
| | | // if (linkCallBack != null) { |
| | | // linkCallBack.onError(e); |
| | | // } |
| | | // } |
| | | // }); |
| | | } |
| | | |
| | | |
| | |
| | | * @param describe 描述文本 |
| | | */ |
| | | public void eventBusPost(String fileFullPath, String type, int progressValue, String describe) { |
| | | HdlLogLogic.print("进度值====" + progressValue + ""); |
| | | |
| | | if (this.stopDownload) { |
| | | HdlFileLogic.getInstance().deleteFile(fileFullPath);//删除下载不完整数据; |
| | | BaseEventBus baseEventBus = new BaseEventBus(); |
| | |
| | | EventBus.getDefault().post(baseEventBus); |
| | | // } |
| | | // }); |
| | | |
| | | |
| | | } |
| | | |
| | | |