mac
2023-12-19 74d51db562aea6e2d8cb8f861a5eeeeb750696fb
app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java
@@ -7,6 +7,7 @@
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;
@@ -14,9 +15,9 @@
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;
@@ -30,9 +31,10 @@
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;
@@ -91,7 +93,7 @@
    /**
     * 服务是否开启 true=开启
     */
    public boolean mServiceStart = false;
    public boolean mServiceStart= false;
    /**
     * true表示终止下载升级文件(用户行为)
@@ -380,10 +382,11 @@
    //endregion
    /**
     * 设置终止下载文件指令
     * 取消终止下载文件指令
     */
    public void setStopDriversDownload() {
    public void stopDownloadUpgradeFile() {
        this.stopDownload = true;
    }
@@ -427,6 +430,7 @@
     */
    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);//模块信息
@@ -434,8 +438,10 @@
//        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) {
@@ -451,6 +457,43 @@
                }
            }
        });
    }
    /**
     * 取消升级驱动,固件文件指令
     *
     * @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);
//                }
//            }
//        });
    }
@@ -641,6 +684,8 @@
     * @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();
@@ -667,6 +712,8 @@
        EventBus.getDefault().post(baseEventBus);
//            }
//        });
    }