mac
2023-11-14 54a8c79222bba0644b02fe1dbc5d75e26ea50b5d
app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java
@@ -6,6 +6,11 @@
import com.google.gson.Gson;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.device.bean.DeviceOidInfoBean;
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.GatewayDriverBean;
import com.hdl.photovoltaic.HDLApp;
import com.hdl.photovoltaic.bean.ModBusBean;
import com.hdl.photovoltaic.config.UserConfigManage;
@@ -187,6 +192,46 @@
                    break;
                }
            } else if (HDLUniMP.UNI_EVENT_REPLY_OTA_MODEL.equals(event)) {
                //OTA升级模块
                switch (type) {
                    //向云端获取oid列表
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_CLOUD_OID_LIST: {
                        this.uniGetCloudOidList(data, callback);
                    }
                    break;
                    //当前设备固件列表
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_LIST: {
                        this.uniGetCurrentDeviceFirmwares(data, callback);
                    }
                    break;
                    //设备新固件列表
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_NEW_LIST: {
                        this.uniGetNewDeviceFirmwares(data, callback);
                    }
                    break;
                    //设备固件升级
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_FIRMWARES_UPGRADE: {
                        this.uniUpgradeDeviceFirmware(data, callback);
                    }
                    break;
                    //当前设备驱动列表
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_LIST: {
                        this.uniGetCurrentGatewayDrivers(data, callback);
                    }
                    break;
                    //设备新驱动列表
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_NEW: {
                        this.uniGetNewGatewayDrivers(data, callback);
                    }
                    break;
                    //设备驱动升级
                    case HDLUniMP.UNI_EVENT_REPLY_OTA_DRIVER_UPGRADE: {
                        this.uniUpgradeGatewayDriver(data, callback);
                    }
                    break;
                }
            }
            HdlLogLogic.print("uni===原生接收uni发来的数据===" + event + "\r\n" + data, false);
        } catch (Exception e) {
@@ -203,10 +248,9 @@
     * @param jsonObject 附件数据(没有数据填null)
     */
    public void openUniMP(String path, JSONObject jsonObject) {
        JSONObject json = this.createdJsonDate(jsonObject, true);
        HdlLogLogic.print("uni===组装uni发送数据格式===" + json, false);
        JSONObject json = this.createdJSONObject(jsonObject, true);
        HDLUniMPSDKManager.getInstance().openUniMP(HDLUniMP.UNI_APP_ID, path, json, HdlUniLogic.this);
        HdlLogLogic.print("uni===组装uni发送数据格式===" + json, false);
    }
    /**
@@ -232,7 +276,143 @@
    }
    //endregion
    //region ******uni逻辑方法******
    //region ******uni接口方法******
    /**
     * 向云端获取逆变器oid列表
     * 前提条件:要上传逆变器oid列表给云端
     *
     * @param callback -
     */
    private void uniGetCloudOidList(Object data, DCUniMPJSCallback callback) {
        HdlOtaLogic.getInstance().getCloudOidList(new CloudCallBeak<List<DeviceOidInfoBean>>() {
            @Override
            public void onSuccess(List<DeviceOidInfoBean> obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 向云端获取【当前设备固件】列表
     * 前提条件:设备自动上报oid信息给云端
     */
    private void uniGetCurrentDeviceFirmwares(Object data, DCUniMPJSCallback callback) {
        String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));
        HdlOtaLogic.getInstance().getCurrentDeviceFirmwares(deviceOidId, new CloudCallBeak<List<DeviceFirmwareBean>>() {
            @Override
            public void onSuccess(List<DeviceFirmwareBean> obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 向云端获取【设备新固件】列表
     * 前提条件:要通过平台软件上传新固件
     */
    private void uniGetNewDeviceFirmwares(Object data, DCUniMPJSCallback callback) {
        String hardwareModel = getKeyValue("hardwareModel", getKeyValue("data", data));//硬件型号
        String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//系统镜像id
        HdlOtaLogic.getInstance().getNewDeviceFirmwares(hardwareModel, osImageId, new CloudCallBeak<List<CloudDeviceFirmwaresBean>>() {
            @Override
            public void onSuccess(List<CloudDeviceFirmwaresBean> obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 向云端发起【设备固件】升级OTA指令
     */
    private void uniUpgradeDeviceFirmware(Object data, DCUniMPJSCallback callback) {
        String deviceOidId = getKeyValue("deviceOidId", getKeyValue("data", data));//设备id
        String firmwareVersionId = getKeyValue("firmwareVersionId", getKeyValue("data", data));//固件版本id
        HdlOtaLogic.getInstance().upgradeDeviceFirmware(deviceOidId, firmwareVersionId, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 向云端获取【当前设备驱动】列表
     * 前提条件:设备自动上报oid信息给云端
     */
    private void uniGetCurrentGatewayDrivers(Object data, DCUniMPJSCallback callback) {
        String deviceOid = getKeyValue("oid", getKeyValue("data", data));
        HdlOtaLogic.getInstance().getCurrentGatewayDrivers(deviceOid, new CloudCallBeak<List<GatewayDriverBean>>() {
            @Override
            public void onSuccess(List<GatewayDriverBean> obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 向云端获取【设备新驱动】列表
     * 前提条件:要通过平台软件上传新驱动
     */
    private void uniGetNewGatewayDrivers(Object data, DCUniMPJSCallback callback) {
        String driveCode = getKeyValue("driveCode", getKeyValue("data", data));//驱动编号或驱动名称
        String osImageId = getKeyValue("osImageId", getKeyValue("data", data));//驱动类型id
        HdlOtaLogic.getInstance().getNewGatewayDrivers(driveCode, osImageId, new CloudCallBeak<CloudGatewayDriversBean>() {
            @Override
            public void onSuccess(CloudGatewayDriversBean obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 向云端发起【设备驱动】升级OTA指令
     */
    private void uniUpgradeGatewayDriver(Object data, DCUniMPJSCallback callback) {
        String deviceOid = getKeyValue("oid", getKeyValue("data", data));//网关设备oid
        String driverVersionId = getKeyValue("driverVersionId", getKeyValue("data", data));//驱动版本id
        HdlOtaLogic.getInstance().upgradeGatewayDriver(deviceOid, driverVersionId, new CloudCallBeak<Boolean>() {
            @Override
            public void onSuccess(Boolean obj) {
                uniCallbackData(obj, callback);
            }
            @Override
            public void onFailure(HDLException e) {
                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
            }
        });
    }
    /**
     * 逆变器清空住宅id
@@ -354,22 +534,17 @@
                            uniCallbackData(null, -100, "本地找不到网关", callback);
                            return;
                        }
                        HdlDeviceLogic.getInstance().addInverterDeviceToCloud(mac,
                                gatewayBean.getGatewayType(),
                                gatewayBean.getSid(),
                                gatewayBean.getOid(),
                                gatewayBean.getDevice_name(),
                                new CloudCallBeak<Boolean>() {
                                    @Override
                                    public void onSuccess(Boolean obj) {
                                        uniCallbackData(null, callback);
                                    }
                        HdlDeviceLogic.getInstance().addInverterDeviceToCloud(mac, gatewayBean.getGatewayType(), gatewayBean.getSid(), gatewayBean.getOid(), gatewayBean.getDevice_name(), new CloudCallBeak<Boolean>() {
                            @Override
                            public void onSuccess(Boolean obj) {
                                uniCallbackData(null, callback);
                            }
                                    @Override
                                    public void onFailure(HDLException e) {
                                        uniCallbackData(null, e.getCode(), e.getMsg(), callback);
                                    }
                                });
                            @Override
                            public void onFailure(HDLException e) {
                                uniCallbackData(null, e.getCode(), e.getMsg(), callback);
                            }
                        });
                    }
                    @Override
@@ -461,11 +636,19 @@
    /**
     * 发送modbus协议数据
     * 透传协议
     * 下发主题:/user/${gw_id}/custom/native/${driver}/down;
     * 逆变器回复主题:/user/${gw_id}/custom/native/${driver}/down_reply;
     * Modbus ECU协议:事件ID(2个byte)->协议[固定:0,0](2个byte)->长度(2byte)->标识符[oid的addresses值](4个byte)->功能码(1个byte)->负载数据(N个byte);
     * 长度(2个byte)=标识符(4个byte)+功能码(1个byte)+负载数据(N个byte);
     * 负载数据=寄存器地址(2个byte)+寄存器长度(2个byte)+内容长度(1个byte)+内容数据(N个byte)【注意:单个写入寄存器-->去掉<寄存器长度>和<内容长度>】;
     * 寄存器长度=(内容数据/2);
     * 例子:new byte[]{00,01,00,00,00,0x09,00,00,00,01,03,00,00,00,01};
     *
     * @param data     modbus数据
     * @param callback 回调
     */
    void sendModBus(Object data, DCUniMPJSCallback callback) {
    private void sendModBus(Object data, DCUniMPJSCallback callback) {
        String tempData = getKeyValue("data", data);
        if (TextUtils.isEmpty(tempData)) {
            HdlLogLogic.print("data内容为空", false);
@@ -506,11 +689,11 @@
    /**
     * 组装uni发送数据格式
     *
     * @param data                   -附件数据(没有数据填null)
     * @param data                   附加数据(没有数据填null)
     * @param isTokenAndRefreshToken (true=底层默认添加token和refreshToken;false=不加)
     * @return JSONObject
     * @return JSONObject            uni方法名里面参数需要的JSONObject对象
     */
    private JSONObject createdJsonDate(JSONObject data, boolean isTokenAndRefreshToken) {
    private JSONObject createdJSONObject(JSONObject data, boolean isTokenAndRefreshToken) {
        HDLUniMP.UniCallBackBaseBean uniCallBackBaseBean = new HDLUniMP.UniCallBackBaseBean();
        try {
            if (data == null) {
@@ -604,6 +787,7 @@
        } catch (Exception e) {
            return "";
        }
    }
    //endregion