mac
2024-01-02 d1ebb94e1a17b7c25d4fcf73d85345d92cc86b5c
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -18,6 +18,7 @@
import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.bean.ModBusBean;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpServer.MyNanoHttpServer;
import com.hdl.photovoltaic.listener.CloudCallBeak;
@@ -28,6 +29,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;
@@ -97,9 +99,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);
@@ -115,6 +117,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);
                    }
@@ -144,7 +156,7 @@
                    break;
                    //获取逆变器列表
                    case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: {
                        this.uniGetCurrentHomeLocalAndCloudGatewayList(callback);
                        this.uniGetCurrentHomeLocalAndCloudGatewayList(data, callback);
                    }
                    break;
                    //modBus协议专用
@@ -182,7 +194,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列表
@@ -309,9 +321,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);
        }
    }
@@ -326,7 +338,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);
    }
    /**
@@ -340,7 +352,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);
        }
    }
@@ -498,6 +510,7 @@
     * 向云端发起【设备固件】升级OTA指令
     */
    private void uniUpgradeDeviceFirmware(Object data, DCUniMPJSCallback callback) {
        String homeId = UserConfigManage.getInstance().getHomeId();
        String deviceMac = getKeyValue("mac", getKeyValue("data", data));//逆变器设备mac(查找socket)
        String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//云端上设备id
        String oid = getKeyValue("oid", getKeyValue("data", data));//升级固件的oid
@@ -512,6 +525,7 @@
            @Override
            public void onSuccess(Boolean b) {
                if (b) {
                    HdlLogLogic.print("本地升级--->", true);
                    //本地
                    //1,建立本地服务;
                    //2,告诉网关手机ip和端口;
@@ -528,7 +542,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
@@ -550,8 +564,9 @@
                        }
                    });
                } else {
                    HdlLogLogic.print("在线升级--->", true);
                    //远程升级需要检测在逆变器有没有连接上云
                    HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                    HdlDeviceLogic.getInstance().checkInverterConnectedCloud(homeId, deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                        @Override
                        public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
                            //1:连接中,2:故障,3:运行,4:离线,6:逆变器连不上云(自定义)
@@ -588,8 +603,9 @@
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("在线升级--->", true);
                //远程升级需要检测在逆变器有没有连接上云
                HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                HdlDeviceLogic.getInstance().checkInverterConnectedCloud(homeId, deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                    @Override
                    public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
                        //1:连接中,2:故障,3:运行,4:离线,6:逆变器连不上云(自定义)
@@ -703,6 +719,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
@@ -751,6 +768,7 @@
     */
    private void uniUpgradeGatewayDriver(Object data, DCUniMPJSCallback callback) {
        String homeId = UserConfigManage.getInstance().getHomeId();
        String deviceMac = getKeyValue("mac", getKeyValue("data", data));//逆变器设备mac(查找socket)
        String deviceOid = getKeyValue("oid", getKeyValue("data", data));//逆变器设备oid
        String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id
@@ -763,6 +781,7 @@
            @Override
            public void onSuccess(Boolean b) {
                if (b) {
                    HdlLogLogic.print("本地升级--->", true);
                    //本地
                    //1,建立本地服务;
                    // 2,告诉网关手机ip和端口;
@@ -779,7 +798,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
@@ -801,8 +820,9 @@
                        }
                    });
                } else {
                    HdlLogLogic.print("在线升级--->", true);
                    //远程升级需要【检测】在逆变器有没有连接上云
                    HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                    HdlDeviceLogic.getInstance().checkInverterConnectedCloud(homeId, deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                        @Override
                        public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
                            //1:连接中,2:故障,3:运行,4:离线,6:逆变器连不上云(自定义)
@@ -839,8 +859,9 @@
            @Override
            public void onFailure(HDLException e) {
                HdlLogLogic.print("在线升级--->", true);
                //远程升级需要【检测】在逆变器有没有连接上云
                HdlDeviceLogic.getInstance().checkInverterConnectedCloud(deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                HdlDeviceLogic.getInstance().checkInverterConnectedCloud(homeId, deviceMac, new CloudCallBeak<CloudInverterDeviceBean>() {
                    @Override
                    public void onSuccess(CloudInverterDeviceBean cloudInverterDeviceBean) {
                        //1:连接中,2:故障,3:运行,4:离线,6:逆变器连不上云(自定义)
@@ -976,7 +997,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);
    }
    /**
@@ -1046,6 +1067,7 @@
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
@@ -1056,7 +1078,8 @@
     */
    private void uniAddInverterDeviceToCloud(Object data, DCUniMPJSCallback callback) {
        String mac = getKeyValue("mac", getKeyValue("data", data));
        HdlDeviceLogic.getInstance().setGatewayRemoteParam(mac, new LinkCallBack<Boolean>() {
        String homeId = UserConfigManage.getInstance().getHomeId();
        HdlDeviceLogic.getInstance().setGatewayRemoteParam(homeId, mac, new LinkCallBack<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                HdlDeviceLogic.getInstance().editGatewayParam(mac, new LinkCallBack<Boolean>() {
@@ -1065,9 +1088,10 @@
                        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac);
                        if (gatewayBean == null) {
                            uniCallbackData(null, -100, "本地找不到网关", callback);
                            return;
                        }
                        HdlDeviceLogic.getInstance().addInverterDeviceToCloud(mac, gatewayBean.getGatewayType(), gatewayBean.getSid(), gatewayBean.getOid(), gatewayBean.getDevice_name(), new CloudCallBeak<Boolean>() {
                        HdlDeviceLogic.getInstance().addInverterDeviceToCloud(homeId, mac, gatewayBean.getGatewayType(), gatewayBean.getSid(), gatewayBean.getOid(), gatewayBean.getDevice_name(), new CloudCallBeak<Boolean>() {
                            @Override
                            public void onSuccess(Boolean obj) {
                                uniCallbackData(null, callback);
@@ -1102,7 +1126,8 @@
     */
    private void uniDelInverterDevice(Object data, DCUniMPJSCallback callback) {
        String deviceId = getKeyValue("deviceId", getKeyValue("data", data));
        HdlDeviceLogic.getInstance().delInverterDevice(deviceId, new CloudCallBeak<Boolean>() {
        String homeId = UserConfigManage.getInstance().getHomeId();
        HdlDeviceLogic.getInstance().delInverterDevice(homeId, deviceId, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                uniCallbackData(null, callback);
@@ -1142,25 +1167,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, homeId);
                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
@@ -1240,13 +1267,17 @@
                data = new JSONObject();
            }
            if (isTokenAndRefreshToken) {
                //小程序那里有自己的请求方法,需要这些数据
                data.put("token", UserConfigManage.getInstance().getToken());
                data.put("refreshToken", UserConfigManage.getInstance().getRefreshToken());
                data.put("serverAddress", AppConfigManage.getUserRegionUrl());
                data.put("appKey", AppConfigManage.getAppKey());
                data.put("appSecret", AppConfigManage.getAppSecret());
            }
            uniCallBackBaseBean.setData(data);
            return getJSONObject(uniCallBackBaseBean);
        } catch (Exception e) {
            HdlLogLogic.print("uni===组装uni发送数据格式===" + e.getMessage(), false);
            HdlLogLogic.print("uni--->组装uni发送数据格式有异常--->" + e.getMessage(), false);
        }
        return new JSONObject();
    }
@@ -1270,6 +1301,7 @@
            if (callback != null) {
                callback.invoke(getJSONObject(uniCallBackBaseBean));
//                callback.invoke(uniCallBackBaseBean);
                HdlLogLogic.print("uni--->组装uni发送数据格式--->" + new Gson().toJson(uniCallBackBaseBean), false);
            }
        } catch (Exception e) {
@@ -1288,7 +1320,7 @@
     *
     * @return JSONObject
     */
    private JSONObject getJSONObject(Object obj) {
    public JSONObject getJSONObject(Object obj) {
        try {
            if (obj == null) {
                return new JSONObject();
@@ -1317,7 +1349,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)) {