| | |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.bean.InverterBean; |
| | | import com.hdl.photovoltaic.bean.LocalResponse; |
| | | import com.hdl.photovoltaic.bean.PageNumberObject; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | |
| | | import java.lang.reflect.Type; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | |
| | |
| | | * @param mac 网关mac |
| | | * @param linkCallBack 回调 |
| | | */ |
| | | public void getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) { |
| | | public void getGatewayInfo(String mac, LinkCallBack<InverterBean> linkCallBack) { |
| | | String requestUrl = TopicApi.GET_GATEWAY_INFO; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("device_mac", mac); |
| | |
| | | } |
| | | |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<BaseLocalResponse<GatewayBean>>() { |
| | | Type typeOfT = new TypeToken<BaseLocalResponse<InverterBean>>() { |
| | | }.getType(); |
| | | BaseLocalResponse<GatewayBean> baseLocalResponse = gson.fromJson(json, typeOfT); |
| | | BaseLocalResponse<InverterBean> baseLocalResponse = gson.fromJson(json, typeOfT); |
| | | if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) { |
| | | linkCallBack.onSuccess(new GatewayBean()); |
| | | linkCallBack.onSuccess(new InverterBean()); |
| | | } else { |
| | | linkCallBack.onSuccess(baseLocalResponse.getObjects()); |
| | | } |
| | |
| | | List<String> removeSidList = new ArrayList<>(); |
| | | for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); |
| | | if (gatewayBean.getSpk().equals(INVERTER_DEVICE_SPK)) { |
| | | if (!isLoadCenterSpk(gatewayBean.getSpk())) { |
| | | //不是负载中心的spk不做处理; |
| | | continue; |
| | | } |
| | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | //外网只有1种情况(本地搜索逆变器列表失败了) |
| | | //向云端获取逆变器列表 |
| | | getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | //外网进来先【默认】清空本地逆变器列表 |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | setDeviceRemoteInfo(list, homeId, cloudCallBeak); |
| | | public void onSuccess(List<CloudInverterDeviceBean> cloudInverterList) { |
| | | //再向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | //外网进来先【默认】清空本地逆变器列表 |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | 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) { |
| | | //外网进来先【默认】清空本地逆变器列表 |
| | | //向云端获取负载中心列表失败,直接返回逆变器列表; |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | setDeviceRemoteInfo(cloudInverterList, homeId, cloudCallBeak); |
| | | } |
| | | }); |
| | | // //外网进来先【默认】清空本地逆变器列表 |
| | | // HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | // setDeviceRemoteInfo(list, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | //向云端获取逆变器列表失败 |
| | | //再向云端获取负载中心列表 |
| | | getLoadCentreDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> loadCentreDeviceList) { |
| | | //外网进来先【默认】清空本地逆变器列表 |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | //逆变器列表和负载中心列表 |
| | | setDeviceRemoteInfo(loadCentreDeviceList, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | // if (cloudCallBeak != null) { |
| | | // cloudCallBeak.onFailure(e); |
| | | // } |
| | | } |
| | | }); |
| | | } |
| | |
| | | if (gatewayBean != null) { |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 判断spk是否是负载中心 |
| | | * |
| | | * @param spk spk |
| | | * @return 真=true,否则返回false |
| | | */ |
| | | private boolean isLoadCenterSpk(String spk) { |
| | | return Objects.equals(spk, LC_SPK); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 逆变器密码登录 |
| | | * |
| | | * @param mac 逆变器mac |
| | | * @param password 逆变器密码 |
| | | */ |
| | | public void getPasswordVerification(String mac, String password, LinkCallBack<LocalResponse> callBeak) { |
| | | String requestUrl = TopicApi.DELETING_GATEWAY_password_verifiy; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("password", password); |
| | | json.addProperty("mac", mac); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, false, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | try { |
| | | |
| | | Gson gson = new Gson(); |
| | | LocalResponse localResponse = gson.fromJson(msg, LocalResponse.class); |
| | | if (localResponse == null) { |
| | | localResponse = new LocalResponse(); |
| | | } |
| | | if (callBeak != null) { |
| | | callBeak.onSuccess(localResponse); |
| | | } |
| | | } catch (Exception e) { |
| | | if (callBeak != null) { |
| | | callBeak.onSuccess(new LocalResponse()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | if (callBeak != null) { |
| | | callBeak.onError(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 刷新逆变器缓存信息(包括设置mqtt秘钥) |
| | | * 注: //目的是为了获取拿到网关ID,mqtt通讯秘钥等信息,缓存本地逆变器列表里面,发送数据数据时自动去缓存列表里面去查找; |
| | | * 1:本地存在,更新信息即可; |
| | |
| | | gatewayBean.setDevice_name(cloudInverterDeviceBean.getName());//设备名称 |
| | | gatewayBean.setGatewayType(cloudInverterDeviceBean.getSpk());//设置spk |
| | | gatewayBean.setLocalEncrypt(true); |
| | | //离网逆变器 |
| | | gatewayBean.setOgMaster(cloudInverterDeviceBean.isOgMaster()); |
| | | //逆变器 |
| | | gatewayBean.setMaster(GatewayMasterType.MasterTrue);//默认都是主逆变器(以后支持从逆变器要更改) |
| | | gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//设备状态 |
| | | gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//软件版本号 |
| | |
| | | List<String> spks = new ArrayList<>(); |
| | | spks.add(INVERTER_DEVICE_SPK); |
| | | spks.add(LC_SPK); |
| | | spks.add(OFF_INVERTER_OG_SPK); |
| | | return spks; |
| | | } |
| | | |
| | |
| | | * 负载中心spk |
| | | */ |
| | | public final String LC_SPK = "energy.hdl_lc"; |
| | | /** |
| | | * 离线逆变器spk |
| | | */ |
| | | public final String OFF_INVERTER_OG_SPK = "energy.inverter_og"; |
| | | } |