mac
2023-12-27 936fb552a30c05fc7a60c20f47bf6fccbc2dc1c1
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -2,8 +2,6 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.text.TextUtils;
@@ -15,7 +13,6 @@
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.linkpm.sdk.utils.HDLMD5Utils;
import com.hdl.photovoltaic.HDLApp;
@@ -23,7 +20,6 @@
import com.hdl.photovoltaic.bean.ModBusBean;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpService;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.listener.LinkCallBack;
import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean;
@@ -32,6 +28,7 @@
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.uni.HDLUniMPSDKManager;
import com.hdl.photovoltaic.utils.AppManagerUtils;
import com.hdl.photovoltaic.utils.NetworkUtils;
import com.hdl.photovoltaic.utils.WifiUtils;
import com.hdl.sdk.link.common.exception.HDLLinkCode;
import com.hdl.sdk.link.common.exception.HDLLinkException;
@@ -101,9 +98,9 @@
                switch (type) {
                    //创建电站
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: {
                        //EventBus事件分发
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL);
                        baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION);
                        baseEventBus.setData(getKeyValue("data", data));
                        EventBus.getDefault().post(baseEventBus);
@@ -119,6 +116,16 @@
                        //EventBus事件分发
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE);
                        baseEventBus.setData(getKeyValue("data", data));
                        EventBus.getDefault().post(baseEventBus);
                    }
                    break;
                    //住宅【电站】编辑
                    case HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT: {
                        //EventBus事件分发
                        BaseEventBus baseEventBus = new BaseEventBus();
                        baseEventBus.setTopic(HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL);
                        baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_EDIT);
                        baseEventBus.setData(getKeyValue("data", data));
                        EventBus.getDefault().post(baseEventBus);
                    }
@@ -148,7 +155,7 @@
                    break;
                    //获取逆变器列表
                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
                        this.uniGetCurrentHomeLocalAndCloudGatewayList(callback);
                        this.uniGetCurrentHomeLocalAndCloudGatewayList(data, callback);
                    }
                    break;
                    //modBus协议专用
@@ -186,7 +193,7 @@
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(topic)) {
                WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance());
                WifiUtils wifiUtils = WifiUtils.getInstance();
                //wifi模块
                switch (type) {
                    //获取wifi列表
@@ -271,10 +278,18 @@
                    //设备取消驱动,固件下载升级文件
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_CANCEL_DOWNLOAD: {
                        this.uniCancelDownloadingUpgradeFile(data, callback);
//                        HdlThreadLogic.runSubThread(new Runnable() {
//                            @Override
//                            public void run() {
//                                HdlLogLogic.print("当前线程名称取消下载====" + Thread.currentThread().getName());
//                                uniCancelDownloadingUpgradeFile(data, callback);
//                            }
//                        });
                    }
                    break;
                    //设备驱动,固件取消升级
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_CANCEL_UPGRADE: {
                        this.uniCancelUpgrade(data, callback);
                    }
                    break;
@@ -305,9 +320,9 @@
                    break;
                }
            }
            HdlLogLogic.print("uni===原生接收uni发来的数据===大类->" + topic + "\r\n" + data, true);
            HdlLogLogic.print("uni发来的数据--->大类-->" + topic + "\r\n" + data, true);
        } catch (Exception e) {
            HdlLogLogic.print("uni===原生接收uni发来的数据===" + e.getMessage(), true);
            HdlLogLogic.print("uni发来的数据--->" + e.getMessage(), true);
        }
    }
@@ -322,7 +337,7 @@
    public void openUniMP(String path, JSONObject jsonObject) {
        JSONObject json = this.createdJSONObject(jsonObject, true);
        HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this);
        HdlLogLogic.print("uni===组装uni发送数据格式===" + json, false);
        HdlLogLogic.print("uni--->组装uni发送数据格式--->" + json, false);
    }
    /**
@@ -336,7 +351,7 @@
        try {
            HDLUniMPSDKManager.getInstance().sendUniMPEvent(HDLUniMP.UNI_APP_ID, topic, getJSONObject(callBackBaseBean));
        } catch (Exception e) {
            HdlLogLogic.print("uni===原生主动向小程序发送通知事件===" + e.getMessage(), false);
            HdlLogLogic.print("uni--->原生主动向小程序发送通知事件--->" + e.getMessage(), false);
        }
    }
@@ -458,21 +473,28 @@
        HdlOtaLogic.getInstance().getDeviceUpgradeDownloadFile(url, new CloudCallBeak<ResponseBody>() {
            @Override
            public void onSuccess(ResponseBody responseBody) {
                String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
                boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(firmwarePathFileName, responseBody, md5, HdlOtaLogic.firmware_type);
                if (isBoolean) {
                    HdlFileLogic.getInstance().deleteFile(localUrl);//下载成功,删除旧固件文件;
                } else {
                    HdlFileLogic.getInstance().deleteFile(firmwarePathFileName);//下载失败,删除不完整固件文件;
                }
                HdlThreadLogic.runSubThread(new Runnable() {
                    @Override
                    public void run() {
                        String firmwarePathFileName = HdlFileLogic.getInstance().getFirmwarePathFileName(oid, imageId, version);
                        //不在子线程读流会卡死主线程
                        boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(firmwarePathFileName, responseBody, md5, HdlOtaLogic.firmware_type);
                        if (isBoolean) {
                            HdlFileLogic.getInstance().deleteFile(localUrl);//下载成功,删除旧固件文件;
                        } else {
                            HdlFileLogic.getInstance().deleteFile(firmwarePathFileName);//下载失败,删除不完整固件文件;
                        }
                if (isBoolean) {
                    HdlLogLogic.print("写入新固件文件到内存成功.", true);
                    uniCallbackData(null, 0, "写入新驱动文件到内存成功", callback);
                } else {
                    HdlLogLogic.print("用户取消下载固件升级文件.", true);
                    uniCallbackData(null, -2, "用户取消下载驱动升级文件", callback);
                }
                        if (isBoolean) {
                            HdlLogLogic.print("写入新固件文件到内存成功.", true);
                            uniCallbackData(null, 0, "写入新驱动文件到内存成功", callback);
                        } else {
                            HdlLogLogic.print("下载固件升级文件失败.", true);
                            uniCallbackData(null, -2, "下载固件升级文件失败", callback);
                        }
                    }
                });
            }
            @Override
@@ -501,6 +523,7 @@
            @Override
            public void onSuccess(Boolean b) {
                if (b) {
                    HdlLogLogic.print("本地升级--->", true);
                    //本地
                    //1,建立本地服务;
                    //2,告诉网关手机ip和端口;
@@ -517,7 +540,7 @@
                            }
                            String md5 = HDLMD5Utils.encodeMD5(data);//网关固件需要
                            //升级固件文件地址
                            String upgradeFileLocalPathUrl = "http://" + AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName;
                            String upgradeFileLocalPathUrl = "http://" + NetworkUtils.getInstance().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + firmwarePathFileName;
                            //通知给网关升级固件文件地址等信息
                            HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, oid, module, version, data.length + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
                                @Override
@@ -539,6 +562,7 @@
                        }
                    });
                } else {
                    HdlLogLogic.print("在线升级--->", true);
                    //远程升级需要检测在逆变器有没有连接上云
                    HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                        @Override
@@ -577,6 +601,7 @@
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("在线升级--->", true);
                //远程升级需要检测在逆变器有没有连接上云
                HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                    @Override
@@ -692,6 +717,7 @@
     * 向云端发起【设备驱动下载】指令
     */
    private void uniGatewayDriverDownload(Object data, DCUniMPJSCallback callback) {
        String deviceOid = getKeyValue("oid", getKeyValue("data", data));//逆变器设备oid
        String driverCode = getKeyValue("driverCode", getKeyValue("data", data));//驱动编码
        String imageId = getKeyValue("imageId", getKeyValue("data", data));//驱动镜像id
@@ -703,20 +729,28 @@
        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);//下载成功,删除旧驱动文件;
                } else {
                    HdlFileLogic.getInstance().deleteFile(drivePathFileName);//下载失败,删除不完整驱动文件;
                }
                if (isBoolean) {
                    HdlLogLogic.print("写入新驱动文件到内存成功.", true);
                    uniCallbackData(null, 0, "写入新驱动文件到内存成功", callback);
                } else {
                    HdlLogLogic.print("用户取消下载驱动升级文件.", true);
                    uniCallbackData(null, -2, "用户取消下载驱动升级文件", callback);
                }
                HdlThreadLogic.runSubThread(new Runnable() {
                    @Override
                    public void run() {
                        String drivePathFileName = HdlFileLogic.getInstance().getDrivePathFileName(driverCode, version);
                        //不在子线程读流会卡死主线程
                        boolean isBoolean = HdlOtaLogic.getInstance().disposeDownLoadFile(drivePathFileName, responseBody, md5, HdlOtaLogic.driver_type);
                        if (isBoolean) {
                            HdlFileLogic.getInstance().deleteFile(localUrl);//下载成功,删除旧驱动文件;
                        } else {
                            HdlFileLogic.getInstance().deleteFile(drivePathFileName);//下载失败,删除不完整驱动文件;
                        }
                        if (isBoolean) {
                            HdlLogLogic.print("写入新驱动文件到内存成功.", true);
                            uniCallbackData(null, 0, "写入新驱动文件到内存成功", callback);
                        } else {
                            HdlLogLogic.print("下载驱动升级文件失败.", true);
                            uniCallbackData(null, -2, "下载驱动升级文件失败", callback);
                        }
                    }
                });
            }
            @Override
@@ -744,6 +778,7 @@
            @Override
            public void onSuccess(Boolean b) {
                if (b) {
                    HdlLogLogic.print("本地升级--->", true);
                    //本地
                    //1,建立本地服务;
                    // 2,告诉网关手机ip和端口;
@@ -760,7 +795,7 @@
                            }
                            String md5 = HDLMD5Utils.encodeMD5(data);//网关驱动需要
                            //升级驱动文件地址
                            String upgradeFileLocalPathUrl = "http://" + AppManagerUtils.getAppManager().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName;
                            String upgradeFileLocalPathUrl = "http://" + NetworkUtils.getInstance().getIPAddress(HDLApp.getInstance()) + ":" + MyNanoHttpServer.HTTP_PORT + drivePathFileName;
                            //通知给网关升级驱动文件地址等信息
                            HdlOtaLogic.getInstance().pushUpgradePacketInfo(deviceMac, deviceOid, module, version, data.length + "", upgradeFileLocalPathUrl, md5, new LinkCallBack<String>() {
                                @Override
@@ -782,6 +817,7 @@
                        }
                    });
                } else {
                    HdlLogLogic.print("在线升级--->", true);
                    //远程升级需要【检测】在逆变器有没有连接上云
                    HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                        @Override
@@ -820,6 +856,7 @@
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("在线升级--->", true);
                //远程升级需要【检测】在逆变器有没有连接上云
                HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                    @Override
@@ -957,7 +994,7 @@
     */
    private void uniUploadDataToCloud(Object data, DCUniMPJSCallback callback) {
        String mac = getKeyValue("mac", getKeyValue("data", data));
        HdlDeviceLogic.getInstance().uploadDataToCloud(mac, null);
        HdlDeviceLogic.getInstance().uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), mac, null);
    }
    /**
@@ -1123,25 +1160,27 @@
     *
     * @param callback uni回调
     */
    private void uniGetCurrentHomeLocalAndCloudGatewayList(DCUniMPJSCallback callback) {
        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(new CloudCallBeak<List<GatewayBean>>() {
    private void uniGetCurrentHomeLocalAndCloudGatewayList(Object data, DCUniMPJSCallback callback) {
        String homeId = getKeyValue("homeId", getKeyValue("data", data));
        HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(homeId, new CloudCallBeak<List<GatewayBean>>() {
            @Override
            public void onSuccess(List<GatewayBean> list) {
                GatewayBean gatewayBean = HdlDeviceLogic.getInstance().queryCurrentHomeMainGateway(list);
                if (gatewayBean != null) {
                    //进来住宅详情都要上传一次oid列表到云端;
                    HdlDeviceLogic.getInstance().uploadDataToCloud(homeId, gatewayBean.getDevice_mac(), null);
                }
                //EventBus事件分发,进入住宅开始订阅主题
                BaseEventBus baseEventBus = new BaseEventBus();
                baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST);
                baseEventBus.setData(list);
                EventBus.getDefault().post(baseEventBus);
                if (callback != null) {
                    uniCallbackData(list, callback);
                    //EventBus事件分发,进入住宅开始订阅主题
                    BaseEventBus baseEventBus = new BaseEventBus();
                    baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST);
                    baseEventBus.setData(list);
                    EventBus.getDefault().post(baseEventBus);
                    GatewayBean gatewayBean = HdlDeviceLogic.getInstance().queryCurrentHomeMainGateway(list);
                    if (gatewayBean != null) {
                        //进来住宅详情都要上传一次oid列表到云端;
                        HdlDeviceLogic.getInstance().uploadDataToCloud(gatewayBean.getDevice_mac(), null);
                    }
                }
            }
            @Override
@@ -1269,7 +1308,7 @@
     *
     * @return JSONObject
     */
    private JSONObject getJSONObject(Object obj) {
    public JSONObject getJSONObject(Object obj) {
        try {
            if (obj == null) {
                return new JSONObject();
@@ -1298,7 +1337,7 @@
     * @param obj -
     * @return value
     */
    private String getKeyValue(String key, Object obj) {
    public String getKeyValue(String key, Object obj) {
        try {
            JSONObject jsonObject = this.getJSONObject(obj);
            if (jsonObject.has(key)) {