mac
2023-11-23 5e080d063f213f2b2c2ed34e1d54b9fd7df1c6b0
2023年11月23日19:28:37

备份一下代码
7个文件已修改
213 ■■■■■ 已修改文件
app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java 112 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java 71 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values-en/strings.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values-zh/strings.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/res/values/strings.xml 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
app/src/main/java/com/hdl/photovoltaic/other/HdlOtaLogic.java
@@ -89,6 +89,11 @@
    private ServiceConnection mServiceConnection = null;
    /**
     * true表示终止下载升级文件(用户行为)
     */
    private boolean stopDownload = false;
    //region -----固件升级---------
    /**
@@ -390,6 +395,13 @@
    }
    /**
     * 设置终止下载文件指令
     */
    public void setStopDriversDownload() {
        this.stopDownload = true;
    }
    /**
     * 云端发起【设备驱动】升级OTA指令
     *
     * @param oid             网关设备oid
@@ -407,43 +419,6 @@
            public void onSuccess(String json) {
                if (callBack != null) {
                    callBack.onSuccess(true);
                }
            }
            @Override
            public void onFailure(HDLException e) {
                if (callBack != null) {
                    callBack.onFailure(e);
                }
            }
        });
    }
    /**
     * 向云端获取【设备驱动】升级包下载地址
     *
     * @param driverVersionId 驱动版本Id
     */
    public void getDeviceDriverDownloadUrl(String driverVersionId, CloudCallBeak<DownloadUrlBean> callBack) {
        String requestUrl = HttpApi.POST_OTA_GET_LinkDeviceDriverDownloadUrl;
        JsonObject json = new JsonObject();
        json.addProperty("driverVersionId", driverVersionId);
        HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String s) {
                if (TextUtils.isEmpty(s)) {
                    if (callBack != null) {
                        callBack.onSuccess(new DownloadUrlBean());
                    }
                    return;
                }
                Gson gson = new Gson();
                Type typeOfT = new TypeToken<DownloadUrlBean>() {
                }.getType();
                DownloadUrlBean downloadUrlBean = gson.fromJson(s, typeOfT);
                if (callBack != null) {
                    callBack.onSuccess(downloadUrlBean);
                }
            }
@@ -563,11 +538,11 @@
        String driver = driver_type;
        //-100:没有数据;-101:没有md5秘钥;-102:md5秘钥不对;-103:有异常;
        if (zipData == null) {
            this.eventBusPost(driver, -100, "没有数据");
            this.eventBusPost(fullPath,driver, -100, "没有数据");
            return false;
        }
        if (TextUtils.isEmpty(md5)) {
            this.eventBusPost(driver, -101, "没有md5秘钥");
            this.eventBusPost(fullPath,driver, -101, "没有md5秘钥");
            return false;
        }
        InputStream is = null;
@@ -580,7 +555,7 @@
            is = zipData.byteStream();
            long total = zipData.contentLength();
            if (total == 0) {
                this.eventBusPost(driver, -100, "没有数据");
                this.eventBusPost(fullPath,driver, -100, "没有数据");
                return false;
            }
            fos = new FileOutputStream(file);
@@ -592,7 +567,7 @@
                int progress = (int) (100 * sum * 1.0f / total);
                if (sum != total) {
                    //不等于100都要报,等于100处理整块逻辑完之后再报100;
                    this.eventBusPost(driver, progress, "正常上报");
                    this.eventBusPost(fullPath,driver, progress, "正常上报");
                }
            }
            fos.flush();
@@ -601,19 +576,19 @@
            byte[] bytes = FileUtils.readFileToByteArray(file);
            String fileMD5 = Md5Utils.encodeMD5(bytes);
            if (TextUtils.isEmpty(fileMD5)) {
                this.eventBusPost(driver, -106, "文件生成md5失败.");
                this.eventBusPost(fullPath,driver, -106, "文件生成md5失败.");
                return false;
            }
            if (!md5.equals(fileMD5)) {
                this.eventBusPost(driver, -107, "md5比对失败.");
                this.eventBusPost(fullPath,driver, -107, "md5比对失败.");
                return false;
            }
            this.eventBusPost(driver, 100, "下载完成.");
            this.eventBusPost(fullPath,driver, 100, "下载完成.");
            return true;
        } catch (Exception e) {
            this.eventBusPost(driver, -103, e.getMessage());
            this.eventBusPost(fullPath,driver, -103, e.getMessage());
            e.printStackTrace();
        }
        return false;
@@ -622,20 +597,21 @@
    /**
     * 处理下载文件数据
     *
     * @param fullPath 文件全路径
     * @param fileFullPath 文件全路径
     * @param zipData  文件数据流对象
     * @param md5      检验文件MD5值
     * @param driver   驱动或者固件
     * @return 成功true
     */
    public boolean disposeDownLoadFile(String fullPath, ResponseBody zipData, String md5, String driver) {
    public boolean disposeDownLoadFile(String fileFullPath, ResponseBody zipData, String md5, String driver) {
        this.stopDownload = false;
        //-100:没有数据;-101:没有md5秘钥;-102:md5秘钥不对;-103:有异常;
        if (zipData == null) {
            this.eventBusPost(driver, -100, "没有数据");
            this.eventBusPost(fileFullPath, driver, -100, "没有数据");
            return false;
        }
        if (TextUtils.isEmpty(md5)) {
            this.eventBusPost(driver, -101, "没有md5秘钥");
            this.eventBusPost(fileFullPath, driver, -101, "没有md5秘钥");
            return false;
        }
        InputStream is = null;
@@ -644,23 +620,31 @@
        FileOutputStream fos = null;
        File file = null;
        try {
            file = new File(fullPath);
            file = new File(fileFullPath);
            is = zipData.byteStream();
            long total = zipData.contentLength();
            if (total == 0) {
                this.eventBusPost(driver, -100, "没有数据");
                this.eventBusPost(fileFullPath, driver, -100, "没有数据");
                return false;
            }
            fos = new FileOutputStream(file);
            long sum = 0;
            while ((len = is.read(buf)) != -1) {
                if (this.stopDownload) {
                    this.eventBusPost(fileFullPath, driver, -108, "用户取消下载.");
                    fos.flush();
                    fos.close();
                    is.close();
                    //todo 用户终止家继续读取数据;
                    return false;
                }
                fos.write(buf, 0, len);
                sum += len;
                //todo 下载中,可以自己计算的进度条(可以广播出去)
                int progress = (int) (100 * sum * 1.0f / total);
                if (sum != total) {
                    //不等于100都要报,等于100处理整块逻辑完之后再报100;
                    this.eventBusPost(driver, progress, "正常上报");
                    this.eventBusPost(fileFullPath, driver, progress, "正常上报");
                }
            }
            fos.flush();
@@ -670,24 +654,24 @@
            //下载文件需要解密之后再进行md5去做比对
            byte[] decrypt = AesUtils.decrypt(bytes);
            if (decrypt == null) {
                this.eventBusPost(driver, -105, "aes解密失败.");
                this.eventBusPost(fileFullPath, driver, -105, "aes解密失败.");
                return false;
            }
            String fileMD5 = Md5Utils.encodeMD5(decrypt);
            if (TextUtils.isEmpty(fileMD5)) {
                this.eventBusPost(driver, -106, "文件生成md5失败.");
                this.eventBusPost(fileFullPath, driver, -106, "文件生成md5失败.");
                return false;
            }
            if (!md5.equals(fileMD5)) {
                this.eventBusPost(driver, -107, "md5比对失败.");
                this.eventBusPost(fileFullPath, driver, -107, "md5比对失败.");
                return false;
            }
            //todo 注意:解密之后,要重新写数据;
            FileUtils.writeByteArrayToFile(file, decrypt, false);
            this.eventBusPost(driver, 100, "下载完成.");
            this.eventBusPost(fileFullPath, driver, 100, "下载完成.");
            return true;
        } catch (Exception e) {
            this.eventBusPost(driver, -103, e.getMessage());
            this.eventBusPost(fileFullPath, driver, -103, e.getMessage());
            e.printStackTrace();
        }
        return false;
@@ -701,7 +685,19 @@
     * @param progressValue 进度值
     * @param describe      描述文本
     */
    public void eventBusPost(String type, int progressValue, String describe) {
    public void eventBusPost(String fileFullPath, String type, int progressValue, String describe) {
        if (this.stopDownload) {
            HdlFileLogic.getInstance().deleteFile(fileFullPath);//删除下载不完成数据;
            BaseEventBus baseEventBus = new BaseEventBus();
            baseEventBus.setTopic(localDownloadProgress);
            Progress progress = new Progress();
            progress.step = progressValue;
            progress.describe = describe;
            baseEventBus.setType(type);
            baseEventBus.setData(progress);
            EventBus.getDefault().post(baseEventBus);
            return;
        }
//        HdlThreadLogic.runMainThread(new Runnable() {
//            @Override
//            public void run() {
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -267,6 +267,11 @@
                        this.uniUpgradeGatewayDriver(data, callback);
                    }
                    break;
                    //设备取消下载升级文件
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: {
                        this.uniCancelDownloadingUpgradeFile(data, callback);
                    }
                    break;
                }
            }
@@ -553,7 +558,7 @@
    }
    /**
     * 向云端发起【设备驱动】下载指令
     * 向云端发起【设备驱动下载】指令
     */
    private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) {
        String deviceOid = getKeyValue("oid", getKeyValue("data", data));//网关设备oid
@@ -633,17 +638,17 @@
                }
            });
        } 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:运行
@@ -670,6 +675,13 @@
        }
    }
    /**
     * 取消下载升级文件
     */
    private void uniCancelDownloadingUpgradeFile(Object data, DCUniMPJSCallback callback) {
        HdlOtaLogic.getInstance().setStopDriversDownload();
    }
    /**
     * @param deviceStatus 逆变器连接云端状态值( 1:待机,2:连接中,3:故障,4:运行,5:离线)
app/src/main/java/com/hdl/photovoltaic/ui/MyPowerStationActivity.java
@@ -83,7 +83,7 @@
        //初始化mqtt客户端
        initMqttClient();
//        dddd();
    }
@@ -354,7 +354,76 @@
    }
    private void dddd() {
//        String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName("036F6C1B", "V01.01.02");
//        String data = HdlFileLogic.getInstance().readFile(drivePathFileName);
//        String md5 = HDLMD5Utils.encodeMD5(data);//网关驱动需要
//        Log.e("", md5);
//        HdlOtaLogic.getInstance().getDeviceDriverDownloadFile("http://192.168.16.135:49152/storage/emulated/0/Android/data/com.hdl.photovoltaic/files/Documents/upgrade/drive/036F6C1B_V01.01.02.zip", new CloudCallBeak<ResponseBody>() {
//            @Override
//            public void onSuccess(ResponseBody responseBody) {
//
//                HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5);
//
////                //本地升级驱动文件路径
////
////                String data = HdlFileLogic.getInstance().readFile(drivePathFileName);
////                String md5 = HDLMD5Utils.encodeMD5(data);//网关驱动需要
//            }
//
//            @Override
//            public void onFailure(HDLException e) {
//
//            }
//        });
//        HdlOtaLogic.getInstance().getNewGatewayDrivers("036F6C1B", "A000", new CloudCallBeak<CloudGatewayDriversBean>() {
//            @Override
//            public void onSuccess(CloudGatewayDriversBean obj) {
//
//            }
//
//            @Override
//            public void onFailure(HDLException e) {
//
//            }
//        });
//        dowlao();
        HdlOtaLogic.getInstance().startLocalService(new ServiceConnection() {
            @Override
            public void onServiceConnected(ComponentName name, IBinder service) {
            }
            @Override
            public void onServiceDisconnected(ComponentName name) {
            }
        });
    }
    void dowlao() {
        HdlOtaLogic.getInstance().getDeviceDriverDownloadFile("http://hdl-hz-test.oss-cn-hangzhou.aliyuncs.com/20/2023/11/1834a1d0-d2a7-4b6f-9877-6f2722e9b7bc.hdlipk_sec", new CloudCallBeak<ResponseBody>() {
            @Override
            public void onSuccess(ResponseBody responseBody) {
                String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName("036F6C1B", "V01.01.02");
                HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, "84cd8e62d4311c90508313f0e5965dbb", HdlOtaLogic.driver_type);
//                HdlFileLogic.getInstance().writeFile(drivePathFileName, bytes);//写入新文件
                HdlLogLogic.print("写入新驱动文件到内存成功.", false);
            }
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("下载驱动文件到内存失败.", false);
            }
        });
    }
}
app/src/main/java/com/hdl/photovoltaic/uni/HDLUniMP.java
@@ -45,16 +45,15 @@
    public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_NEW_LIST = "firmwares_new_list";//设备新固件列表
    public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_LOCAL = "firmwares_local_list";//设备本地固件列表
    public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_DOWNLOAD = "firmwares_download";//设备固件下载
    public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_CANCEL_DOWNLOAD = "firmwares_cancel_download";//设备固件取消下载
    public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE = "firmwares_upgrade";//设备固件升级
    public final static String UNI_EVENT_REPLY_OTA_FIRMWARES_CANCEL_UPGRADE = "firmwares_cancel_upgrade";//设备固件取消升级
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_LIST = "driver_current_list";//当前设备驱动列表
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_NEW = "driver_new_list";//设备新驱动列表
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_LOCAL = "driver_local_list";//设备本地驱动列表
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_DOWNLOAD = "driver_download";//设备驱动下载
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD = "driver_cancel_download";//设备驱动取消下载
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE = "driver_upgrade";//设备驱动升级
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_UPGRADE = "driver_cancel_upgrade";//设备驱动取消升级
    public final static String UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD = "cancel_download";//设备取消下载升级文件
    /*********Wifi模块*********/ //卫锦定义
app/src/main/res/values-en/strings.xml
@@ -107,6 +107,7 @@
    <string name="set_nickname_modification">昵称修改</string>
    <!--ota-->
    <string name="ota_binding_cloud_upgrade_fails">逆变器没绑定上云,升级失败.</string>
    <string name="ota_not_cloud_upgrade_fails">逆变器没上云,升级失败.</string>
    <!--uin-->
    <string name="uni_open_error">页面初始化中 请等待5秒再点击</string>
app/src/main/res/values-zh/strings.xml
@@ -107,6 +107,7 @@
    <string name="set_nickname_modification">昵称修改</string>
    <!--ota-->
    <string name="ota_binding_cloud_upgrade_fails">逆变器没绑定上云,升级失败.</string>
    <string name="ota_not_cloud_upgrade_fails">逆变器没上云,升级失败.</string>
    <!--uin-->
    <string name="uni_open_error">页面初始化中 请等待5秒再点击</string>
app/src/main/res/values/strings.xml
@@ -107,6 +107,7 @@
    <string name="set_nickname_modification">昵称修改</string>
    <!--ota-->
    <string name="ota_binding_cloud_upgrade_fails">逆变器没绑定上云,升级失败.</string>
    <string name="ota_not_cloud_upgrade_fails">逆变器没连上云,升级失败.</string>