mac
2023-12-27 936fb552a30c05fc7a60c20f47bf6fccbc2dc1c1
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -6,22 +6,7 @@
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.hdl.hdlhttp.HxHttp;
import com.hdl.linkpm.sdk.core.api.HDLCloudHomeApi;
import com.hdl.linkpm.sdk.core.callback.IDefaultCallBack;
import com.hdl.linkpm.sdk.core.callback.IResponseCallBack;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.linkpm.sdk.core.response.HDLResponse;
import com.hdl.linkpm.sdk.device.bean.DeviceOidInfoBean;
import com.hdl.linkpm.sdk.device.bean.GatewayCloudBean;
import com.hdl.linkpm.sdk.ota.HDLLinkPMOta;
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.project.HDLLinkPMProject;
import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
@@ -45,15 +30,11 @@
import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
import com.hdl.sdk.link.gateway.type.GatewayMasterType;
import org.json.JSONException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import io.dcloud.feature.unimp.DCUniMPJSCallback;
import io.reactivex.rxjava3.disposables.Disposable;
/**
@@ -101,14 +82,14 @@
    }
    /**
     * 获取当前住宅的【主】逆变器列表
     * 获取当前住宅的【主】逆变器
     */
    public GatewayBean getCurrentHomeMainGateway() {
        return queryCurrentHomeMainGateway(this.getCurrentHomeGatewayList());
    }
    /**
     * 查询当前住宅的【主】逆变器列表
     * 查询当前住宅的【主】逆变器
     */
    public GatewayBean queryCurrentHomeMainGateway(List<GatewayBean> list) {
        if (list == null || list.size() == 0) {
@@ -130,31 +111,32 @@
    /**
     * 逆变器上传数据到云端(包括:sid,oid)
     *
     * @param mac 设备mac
     * @param homeId 住宅id
     * @param mac    设备mac
     */
    public void uploadDataToCloud(String mac, CloudCallBeak<Boolean> callBeak) {
    public void uploadDataToCloud(String homeId, String mac, CloudCallBeak<Boolean> callBeak) {
        getInverterOidList(mac, new LinkCallBack<List<OidBean>>() {
            @Override
            public void onSuccess(List<OidBean> obj) {
                if (obj == null) {
                    return;
                }
                fullUpdateOid(obj, new CloudCallBeak<Boolean>() {
                fullUpdateOid(homeId, obj, new CloudCallBeak<Boolean>() {
                    @Override
                    public void onSuccess(Boolean obj) {
                        HdlLogLogic.print("上传oid列表到云端成功-->" + homeId + "--->" + mac, true);
                    }
                    @Override
                    public void onFailure(HDLException e) {
                        HdlLogLogic.print("上传oid列表到云端失败-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
                    }
                });
            }
            @Override
            public void onError(HDLLinkException e) {
                HdlLogLogic.print("获取逆变器oid列表失败-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true);
            }
        });
@@ -188,7 +170,7 @@
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                    //临时的逻辑,上传oid列表到云端
                    uploadDataToCloud(mac, null);
                    uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), mac, null);
                }
            }
@@ -312,14 +294,15 @@
    /**
     * 全量更新OID
     *
     * @param homeId        住宅id
     * @param oidList       oid列表
     * @param cloudCallBeak 回调update
     */
    public void fullUpdateOid(List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
    public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
        String requestUrl = HttpApi.POST_Device_Oid;
        JsonObject json = new JsonObject();
        json.addProperty("operationSource", "PROGRAM_ENERGY");//
        json.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
        json.addProperty("homeId", homeId);
        JsonArray jsonArray = new JsonArray();
        for (int i = 0; i < oidList.size(); i++) {
            OidBean oidBean = oidList.get(i);
@@ -573,14 +556,15 @@
     * 获取逆变器列表(整合云端和本地列表)
     * 注意:有外网,以云端设备为准,本地存在,云端没有则删除;内网,以本地为主,搜索多少个设备就显示多少个;
     *
     * @param homeId        住宅id
     * @param cloudCallBeak 返回逆变器列表
     */
    public void getCurrentHomeLocalAndCloudGatewayList(CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
    public void getCurrentHomeLocalAndCloudGatewayList(String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) {
        HdlDeviceLogic.getInstance().searchCurrentHomeGateway(new GatewayCallBack() {
            @Override
            public void onSuccess(List<GatewayBean> gatewayBeanList) {
                //局域网有2种情况(1:有局域网,有外网;2:有局域网,没有外网);
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                    @Override
                    public void onSuccess(List<CloudInverterDeviceBean> list) {
                        ///情况1:有局域网,有外网;
@@ -596,7 +580,7 @@
                        for (int i = 0; i < list.size(); i++) {
                            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
                            //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥)
                            getDeviceRemoteInfo(UserConfigManage.getInstance().getHomeId(), cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() {
                            getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() {
                                @Override
                                public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) {
                                    atomicInteger.set(atomicInteger.get() + 1);
@@ -675,7 +659,7 @@
            @Override
            public void onError(HDLLinkException e) {
                //外网只有1种情况(本地搜索逆变器列表失败了)
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                    @Override
                    public void onSuccess(List<CloudInverterDeviceBean> list) {
                        //外网进来先【默认】清空本地逆变器列表
@@ -685,7 +669,7 @@
                                //云端也没有逆变器列表,返回空列表回去
                                cloudCallBeak.onSuccess(new ArrayList<>());
                            }
                            HdlLogLogic.print("在只有【外网】情况下获取云端逆变器列表返回空列表",true);
                            HdlLogLogic.print("在只有【外网】情况下获取云端逆变器列表返回空列表", true);
                            return;
                        }
                        //记录条数
@@ -695,7 +679,7 @@
                            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
                            //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥)
                            getDeviceRemoteInfo(UserConfigManage.getInstance().getHomeId(), cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() {
                            getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() {
                                @Override
                                public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) {
                                    atomicInteger.set(atomicInteger.get() + 1);
@@ -846,14 +830,62 @@
    }
    /**
     * 判断是本地连接
     * 检测本地连接状态
     *
     * @param deviceMac 设备mac
     * @return true=本地连接
     * @param deviceMac 设备mac,
     * @param callBeak  返回 true=本地连接;false=远程;
     */
    public boolean isLocalConnect(String deviceMac) {
        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceMac);
        return gatewayBean == null;
    public void isLocalConnect(String deviceMac, CloudCallBeak<Boolean> callBeak) {
        searchCurrentHomeGateway(new GatewayCallBack() {
            @Override
            public void onSuccess(List<GatewayBean> gatewayBeanList) {
                if (gatewayBeanList == null || gatewayBeanList.size() == 0) {
                    if (callBeak != null) {
                        callBeak.onSuccess(false);
                    }
                    return;
                }
                boolean is_find = false;
                for (int i = 0; i < gatewayBeanList.size(); i++) {
                    GatewayBean gatewayBean = gatewayBeanList.get(i);
                    if (gatewayBean.getDevice_mac().equals(deviceMac)) {
                        //升级的时候搜索网关列表,把之前mqtt秘钥覆盖掉,要重新获取才行;
                        if (!TextUtils.isEmpty(gatewayBean.getHomeId())) {
                            getDeviceRemoteInfo(gatewayBean.getHomeId(), gatewayBean.getSpk(), gatewayBean.getDevice_mac(), new CloudCallBeak<DeviceRemoteInfo>() {
                                @Override
                                public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) {
                                    if (deviceRemoteInfo != null) {
                                        gatewayBean.setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥
                                        gatewayBean.setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId
                                        //todo 设置到【库】里面,底层mqtt订阅,加解密会用到该参数;
                                        HDLLinkConfig.getInstance().setAesKey(deviceRemoteInfo.getSecret());//设置mqtt通讯秘钥库
                                        HDLLinkConfig.getInstance().setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId
                                    }
                                }
                                @Override
                                public void onFailure(HDLException e) {
                                }
                            });
                        }
                        is_find = true;
                        break;
                    }
                }
                if (callBeak != null) {
                    callBeak.onSuccess(is_find);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (callBeak != null) {
                    callBeak.onSuccess(false);
                }
            }
        });
    }
    /**
@@ -929,7 +961,7 @@
        gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//设备状态
        gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//软件版本号
        gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());//设备类型(产品二级分类名称
        gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//子网号/设备号
        gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//子网号/设备号,逆变器地址
        gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//发电功率
        gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//今日发电量
        gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//设备型号