| | |
| | | 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; |
| | |
| | | */ |
| | | public void getCloudInverterDeviceList(String homeId, CloudCallBeak<List<CloudInverterDeviceBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_List; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | if (TextUtils.isEmpty(jsonStr)) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(null); |
| | | } |
| | | } |
| | | Type type = new TypeToken<List<CloudInverterDeviceBean>>() { |
| | | }.getType(); |
| | | List<CloudInverterDeviceBean> list = new Gson().fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取云端BMS设备列表 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 回调 |
| | | */ |
| | | public void getCloudBmsDeviceList(String homeId, CloudCallBeak<List<CloudInverterDeviceBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_bmsDevices; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | |
| | | * 获取逆变器列表,整合云端逆变器列表和本地逆变器列表(设备类型有:并网逆变器,离线逆变器,负载中心设备); |
| | | * 注意:有外网,以云端设备列表为准;云端没有,本地存在,则删除本地;否则,没有外网只有局域网,以本地为主,搜索多少个设备就显示多少个 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | * @param powerStationType 电站类型(逆变器,BMS电站) |
| | | */ |
| | | public void getCurrentHomeLocalAndCloudGatewayList(String homeId, 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); |
| | | public void getCurrentHomeLocalAndCloudGatewayList(String homeId, String powerStationType, CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear();//先清空之前逆变器列表 |
| | | 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()) { |
| | | //未激活设备 |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //注意:这个逆变器只能本地控制(因为拿不到mqtt通讯秘钥以及GatewayID,无法远程控制) |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, null, homeId); |
| | | //到最后一条,才处理回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false)); |
| | | if (cloudInverterDeviceBean == null) { |
| | | if (cloudInverterDeviceBean.getDeviceType().equals(DeviceType.bms)) { |
| | | //未激活设备 |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //注意:这个逆变器只能本地控制(因为拿不到mqtt通讯秘钥以及GatewayID,无法远程控制) |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, null, homeId); |
| | | //到最后一条,才处理回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("设备未激活(mac:" + cloudInverterDeviceBean.getOsn() + "))", true); |
| | | continue; |
| | | } else { |
| | | if (!cloudInverterDeviceBean.isActivate()) { |
| | | //未激活设备 |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //注意:这个逆变器只能本地控制(因为拿不到mqtt通讯秘钥以及GatewayID,无法远程控制) |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, null, homeId); |
| | | //到最后一条,才处理回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(IntegrateCloudAndLocalData(homeId, list, false)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("设备未激活(mac:" + cloudInverterDeviceBean.getOsn() + "))", true); |
| | | continue; |
| | | } |
| | | } |
| | | HdlLogLogic.print("设备未激活(mac:" + cloudInverterDeviceBean.getOsn() + "))", true); |
| | | continue; |
| | | } |
| | | //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥) |
| | | getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | |
| | | gatewayBean.setPopUpgrade(cloudInverterDeviceBean.isPopUpgrade());//改设备是否有弹窗升级 |
| | | gatewayBean.setSubPopUpgrade(cloudInverterDeviceBean.isSubPopUpgrade());//下挂设备是否有弹窗升级 |
| | | |
| | | |
| | | if (cloudInverterDeviceBean.getDeviceType().equals(DeviceType.bms)) { |
| | | gatewayBean.setDeviceOidId(cloudInverterDeviceBean.getDeviceOidId()); |
| | | gatewayBean.setFwVersion(cloudInverterDeviceBean.getFwVersion()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | 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"; |
| | | } |