| | |
| | | import com.hdl.photovoltaic.bean.PageNumberObject; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.enums.DeviceType; |
| | | import com.hdl.photovoltaic.enums.PowerStationType; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | | import com.hdl.photovoltaic.internet.TcpClient; |
| | | import com.hdl.photovoltaic.internet.api.HttpApi; |
| | |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | |
| | | * 获取逆变器列表,整合云端逆变器列表和本地逆变器列表(设备类型有:并网逆变器,离线逆变器,负载中心设备); |
| | | * 注意:有外网,以云端设备列表为准;云端没有,本地存在,则删除本地;否则,没有外网只有局域网,以本地为主,搜索多少个设备就显示多少个 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | * @param powerStationType 电站类型(逆变器,BMS电站) |
| | | */ |
| | | public void getCurrentHomeLocalAndCloudGatewayList(String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | public void getCurrentHomeLocalAndCloudGatewayList(String homeId, String powerStationType, CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear();//先清空之前逆变器列表 |
| | | searchCurrentHomeGateway(homeId, new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //向云端获取逆变器列表 |
| | | getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) { |
| | | //向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | if (loadCentreDeviceList != null) { |
| | | //合并负载中心设备列表,然后在一起做处理 |
| | | inverterDeviceList.addAll(loadCentreDeviceList); |
| | | } |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak); |
| | | if (powerStationType.equals(PowerStationType.BMS)) { |
| | | searchCurrentHomeGateway(homeId, new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //向云端获取逆变器列表 |
| | | getCloudBmsDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) { |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //本地有逆变器列表,获取云端绑定逆变器失败,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false)); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取负载中心设备列表失败后,仍然处理逆变器设备列表 |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //本地有逆变器列表,获取云端绑定逆变器失败,默认返回本地逆变器列表; |
| | | //向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | if (loadCentreDeviceList == null) { |
| | | if (cloudCallBeak != null) { |
| | | //没有数据,默认返回本地逆变器列表; |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false)); |
| | | } |
| | | return; |
| | | } |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取负载中心设备列表失败后,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false)); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | // //外网进来先【默认】清空本地逆变器列表 |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | //向云端获取逆变器列表 |
| | | getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) { |
| | | //再向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | //向云端获取逆变器列表 |
| | | getCloudBmsDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) { |
| | | //整合设备列表后,再一起设置设备的远程信息 |
| | | setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | List<CloudInverterDeviceBean> newList = new ArrayList<>(); |
| | | if (cloudInverterList != null) { |
| | | //添加逆变器设备列表 |
| | | newList.addAll(cloudInverterList); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取逆变器列表失败 |
| | | //都是获取失败的话,直接返回空列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(new ArrayList<>()); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } else { |
| | | searchCurrentHomeGateway(homeId, new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //向云端获取逆变器列表 |
| | | getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> inverterDeviceList) { |
| | | //向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | if (loadCentreDeviceList != null) { |
| | | //合并负载中心设备列表,然后在一起做处理 |
| | | inverterDeviceList.addAll(loadCentreDeviceList); |
| | | } |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | if (loadCentreDeviceList != null) { |
| | | //添加负载中心设备列表 |
| | | newList.addAll(loadCentreDeviceList); |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取负载中心设备列表失败后,仍然处理逆变器设备列表 |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(inverterDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | //整合设备列表后,再一起设置设备的远程信息 |
| | | setDeviceRemoteInfo(newList, homeId, cloudCallBeak); |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取逆变器列表失败 |
| | | //再向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //都是获取失败的话,直接返回空列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(new ArrayList<>()); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //本地有逆变器列表,获取云端绑定逆变器失败,默认返回本地逆变器列表; |
| | | //向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | if (loadCentreDeviceList == null) { |
| | | if (cloudCallBeak != null) { |
| | | //没有数据,默认返回本地逆变器列表; |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false)); |
| | | } |
| | | return; |
| | | } |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取负载中心设备列表失败后,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, null, false)); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | // //外网进来先【默认】清空本地逆变器列表 |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | //向云端获取逆变器列表 |
| | | getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) { |
| | | //再向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | |
| | | List<CloudInverterDeviceBean> newList = new ArrayList<>(); |
| | | if (cloudInverterList != null) { |
| | | //添加逆变器设备列表 |
| | | newList.addAll(cloudInverterList); |
| | | } |
| | | if (loadCentreDeviceList != null) { |
| | | //添加负载中心设备列表 |
| | | newList.addAll(loadCentreDeviceList); |
| | | } |
| | | //整合设备列表后,再一起设置设备的远程信息 |
| | | setDeviceRemoteInfo(newList, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //向云端获取逆变器列表失败 |
| | | //再向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | //设置设备的远程信息 |
| | | setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //都是获取失败的话,直接返回空列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(new ArrayList<>()); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | if (cloudInverterDeviceBean == null || !cloudInverterDeviceBean.isActivate()) { |
| | | if (cloudInverterDeviceBean == null) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | continue; |
| | | } |
| | | if (!cloudInverterDeviceBean.getSpk().equals(HDL_BMS_SPK) && !cloudInverterDeviceBean.isActivate()) { |
| | | //未激活设备 |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //注意:这个逆变器只能本地控制(因为拿不到mqtt通讯秘钥以及GatewayID,无法远程控制) |
| | |
| | | * |
| | | * @param deviceMac 设备mac |
| | | */ |
| | | public void checkInverterConnectedCloud(String homeId, String deviceMac, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { |
| | | this.getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = null; |
| | | if (list != null && list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getOsn().equals(deviceMac)) { |
| | | cloudInverterDeviceBean = list.get(i); |
| | | break; |
| | | } |
| | | public void checkInverterConnectedCloud(String homeId, String deviceMac, String plantType, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { |
| | | if (plantType.equals(PowerStationType.BMS)) { |
| | | this.getCloudBmsDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = null; |
| | | if (list != null && list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getOsn().equals(deviceMac)) { |
| | | cloudInverterDeviceBean = list.get(i); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(cloudInverterDeviceBean); |
| | | } |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(cloudInverterDeviceBean); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | } else { |
| | | this.getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = null; |
| | | if (list != null && list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | if (list.get(i).getOsn().equals(deviceMac)) { |
| | | cloudInverterDeviceBean = list.get(i); |
| | | break; |
| | | } |
| | | |
| | | } |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(cloudInverterDeviceBean); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | gatewayBean.setPopUpgrade(cloudInverterDeviceBean.isPopUpgrade());//改设备是否有弹窗升级 |
| | | gatewayBean.setSubPopUpgrade(cloudInverterDeviceBean.isSubPopUpgrade());//下挂设备是否有弹窗升级 |
| | | |
| | | if (cloudInverterDeviceBean.getDeviceType().equals(DeviceType.bms)) { |
| | | gatewayBean.setDeviceOidId(cloudInverterDeviceBean.getDeviceOidId()); |
| | | gatewayBean.setFwVersion(cloudInverterDeviceBean.getFwVersion()); |
| | | } |
| | | gatewayBean.setBmsSource(cloudInverterDeviceBean.getBmsSource()); |
| | | //是否只支持远程发送命令 |
| | | gatewayBean.setSupportLocalSendCommands(!this.isBmsDevice(gatewayBean.getDevice_model())); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 是否是BMS设备(为什么使用设备类型查找,是因为有些BMS设备有可能支持TCP和远程,有些BMS设备只支持远程,因为有可能使用和逆变器一样的系统,而不是现在用单片机) |
| | | * |
| | | * @param model 设备类型 |
| | | * @return true表示是BMS设备,否则不是 |
| | | */ |
| | | private boolean isBmsDevice(String model) { |
| | | List<String> bmsModels = new ArrayList<>(); |
| | | bmsModels.add("ME-GLE-BW5K"); |
| | | if (bmsModels.contains("ME-GLE-BW5K")) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 获取网关支持spk列表 |
| | |
| | | spks.add(INVERTER_DEVICE_SPK); |
| | | spks.add(LC_SPK); |
| | | spks.add(OFF_INVERTER_OG_SPK); |
| | | spks.add(HDL_BMS_SPK); |
| | | return spks; |
| | | } |
| | | |
| | |
| | | * 离线逆变器spk |
| | | */ |
| | | public final String OFF_INVERTER_OG_SPK = "energy.inverter_og"; |
| | | /** |
| | | * BMS设备spk |
| | | */ |
| | | public final String HDL_BMS_SPK = "energy.hdl_bms"; |
| | | } |