mac
2023-10-09 a59bbb7890e107a681f677765f2600e278c06a0d
app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java
@@ -9,6 +9,7 @@
import com.hdl.hdlhttp.HxHttp;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.bean.HttpResponsePack;
import com.hdl.photovoltaic.bean.LocalResponse;
import com.hdl.photovoltaic.config.AppConfigManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.internet.HttpClient;
@@ -27,6 +28,8 @@
import com.hdl.sdk.link.common.exception.HDLLinkCode;
import com.hdl.sdk.link.common.exception.HDLLinkException;
import com.hdl.sdk.link.core.bean.gateway.GatewayBean;
import com.hdl.sdk.link.core.bean.request.BaseLocalRequest;
import com.hdl.sdk.link.core.bean.response.BaseLocalResponse;
import com.hdl.sdk.link.core.callback.GatewayCallBack;
import com.hdl.sdk.link.core.callback.HDLLinkCallBack;
import com.hdl.sdk.link.gateway.HDLLinkLocalGateway;
@@ -35,10 +38,9 @@
import java.util.ArrayList;
import java.util.List;
import io.reactivex.rxjava3.disposables.Disposable;
/**
 * 设备逻辑的界面
 * 设备逻辑
 */
public class HdlDeviceLogic {
    private static volatile HdlDeviceLogic sHdlDeviceLogic;
@@ -52,15 +54,18 @@
        if (list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                GatewayBean gatewayBean = list.get(i);
                if (!TextUtils.isEmpty(gatewayBean.getHomeId())
                if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) {
                    continue;
                }
                if (gatewayBean.getMaster().equals("true")
                        && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) {
//                    if ("0101050217BBC400".equals(gatewayBean.getOid()))//测试时过滤掉无效的,这行后面代码要删除
//                        continue;
                    newList.add(gatewayBean);
                }
            }
        }
        return newList;
    }
    /**
@@ -107,6 +112,31 @@
            public void onSuccess(String str) {
                if (cloudCallBeak != null) {
                    cloudCallBeak.onSuccess(true);
                    //临时的逻辑,上传oid列表到云端
                    getGatewayOidList(mac, new LinkCallBack<List<OidBean>>() {
                        @Override
                        public void onSuccess(List<OidBean> obj) {
                            if (obj == null) {
                                return;
                            }
                            fullUpdateOid(obj, new CloudCallBeak<Boolean>() {
                                @Override
                                public void onSuccess(Boolean obj) {
                                }
                                @Override
                                public void onFailure(HDLException e) {
                                }
                            });
                        }
                        @Override
                        public void onError(HDLLinkException e) {
                        }
                    });
                }
            }
@@ -234,7 +264,7 @@
     * @param cloudCallBeak 回调update
     */
    public void fullUpdateOid(List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) {
        String requestUrl = HttpApi.POST_Device_ChildDevices_List;
        String requestUrl = HttpApi.POST_Device_Oid;
        JsonObject json = new JsonObject();
        json.addProperty("operationSource", "PROGRAM_ENERGY");//
        json.addProperty("homeId", UserConfigManage.getInstance().getHomeId());
@@ -244,7 +274,7 @@
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("protocolType", oidBean.getProtocolType());
            jsonObject.addProperty("deviceType", oidBean.getDeviceType());
            jsonObject.addProperty("mac", oidBean.getMac());
            jsonObject.addProperty("mac", oidBean.getDevice_mac());
            jsonObject.addProperty("oid", oidBean.getOid());
            jsonObject.addProperty("device_name", oidBean.getDevice_name());
            jsonObject.addProperty("device_model", oidBean.getDevice_model());
@@ -315,6 +345,64 @@
    }
    /**
     * 网关时间读取
     *
     * @param mac          设备mac
     * @param linkCallBack 回调update
     */
    public void getGatewayTime(String mac, LinkCallBack<Boolean> linkCallBack) {
        String requestUrl = TopicApi.GET_GATEWAY_TIME;
        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(true);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (linkCallBack != null) {
                    linkCallBack.onError(e);
                }
            }
        });
    }
    /**
     * 网关时间修改
     *
     * @param mac          设备mac
     * @param linkCallBack 回调update
     */
    public void editGatewayTime(String mac, JsonObject jsonObject, LinkCallBack<Boolean> linkCallBack) {
        String requestUrl = TopicApi.SET_GATEWAY_TIME_EDIT;
//        JsonObject json = new JsonObject();
//        json.addProperty("master", "true");
//        "objects": {
//            "date": "2020-08-15",
//                    "time": "17:25:20"
//        }
        TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonObject, "", new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(true);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                if (linkCallBack != null) {
                    linkCallBack.onError(e);
                }
            }
        });
    }
    /**
     * 编辑网关参数
     *
     * @param mac          设备mac
@@ -341,7 +429,6 @@
        });
    }
    /**
     * 获取网关详情信息
@@ -395,11 +482,17 @@
                    return;
                }
                Gson gson = new Gson();
                Type typeOfT = new TypeToken<List<OidBean>>() {
                Type typeOfT = new TypeToken<BaseLocalResponse<List<OidBean>>>() {
                }.getType();
                List<OidBean> list = gson.fromJson(json, typeOfT);
                if (linkCallBack != null) {
                    linkCallBack.onSuccess(list);
                BaseLocalResponse<List<OidBean>> baseLocalResponse = gson.fromJson(json, typeOfT);
                if (linkCallBack == null) {
                    return;
                }
                if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) {
                    linkCallBack.onSuccess(new ArrayList<>());
                } else {
                    linkCallBack.onSuccess(baseLocalResponse.getObjects());
                }
            }
@@ -448,8 +541,14 @@
                            }
                        }
                        for (int i = 0; i < removeSidList.size(); i++) {
                            //获取本地的逆变器
                            //删除本地的逆变器
                            removeInverter(removeSidList.get(i));
                        }
                        for (int i = 0; i < list.size(); i++) {
                            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
                            GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(cloudInverterDeviceBean.getSid());
                            objectAssignment(cloudInverterDeviceBean, gatewayBean);
                        }
                        if (cloudCallBeak != null) {
@@ -471,25 +570,20 @@
                HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() {
                    @Override
                    public void onSuccess(List<CloudInverterDeviceBean> list) {
                        //清楚本地网关列表
                        HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                        if (list == null || list.size() == 0) {
                            if (cloudCallBeak != null) {
                                cloudCallBeak.onSuccess(true);
                            }
                            return;
                        }
                        //清楚本地网关列表
                        HDLLinkLocalGateway.getInstance().getGatewayList().clear();
                        for (int i = 0; i < list.size(); i++) {
                            CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i);
                            //云端对象数据交换到本地对象
                            GatewayBean gatewayBean = new GatewayBean();
                            gatewayBean.setOid(cloudInverterDeviceBean.getOid());
                            gatewayBean.setSid(cloudInverterDeviceBean.getSid());
                            gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId());
                            gatewayBean.setOnline(cloudInverterDeviceBean.isOnline());
                            gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName());
                            gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());
                            gatewayBean.setLocalEncrypt(true);
                            gatewayBean.setMaster("true");
                            objectAssignment(cloudInverterDeviceBean, gatewayBean);
                            //添加网关
                            HDLLinkLocalGateway.getInstance().getGatewayList().add(gatewayBean);
                        }
@@ -516,7 +610,6 @@
     * @param sid 设备sid
     */
    private void removeInverter(String sid) {
        //获取本地的毫米波
        GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid);
        if (gatewayBean != null) {
            HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean);
@@ -534,6 +627,27 @@
        HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack);
    }
    private void objectAssignment(CloudInverterDeviceBean cloudInverterDeviceBean, GatewayBean gatewayBean) {
        if (cloudInverterDeviceBean == null || gatewayBean == null) {
            return;
        }
        gatewayBean.setOid(cloudInverterDeviceBean.getOid());
        gatewayBean.setSid(cloudInverterDeviceBean.getSid());
        gatewayBean.setGatewayId(cloudInverterDeviceBean.getGatewayId());
        gatewayBean.setOnline(cloudInverterDeviceBean.isOnline());
        gatewayBean.setDevice_mac(cloudInverterDeviceBean.getOsn());//设备mac
        gatewayBean.setDevice_name(cloudInverterDeviceBean.getGatewayName());
        gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());
        gatewayBean.setLocalEncrypt(true);
        gatewayBean.setMaster("true");
        gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());
        gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());
        gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());
        gatewayBean.setDeviceId(cloudInverterDeviceBean.getDeviceId());
    }
    /**
     * 获取网关spk列表
     *