| | |
| | | import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceTimeBean; |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.sdk.link.HDLLinkLocalSdk; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; |
| | |
| | | * 获取当前住宅的【主】逆变器列表 |
| | | */ |
| | | public GatewayBean getCurrentHomeMainGateway() { |
| | | List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList(); |
| | | if (list.size() > 0) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | //找到返回 |
| | | return gatewayBean; |
| | | } |
| | | return queryCurrentHomeMainGateway(this.getCurrentHomeGatewayList()); |
| | | } |
| | | |
| | | /** |
| | | * 查询当前住宅的【主】逆变器列表 |
| | | */ |
| | | public GatewayBean queryCurrentHomeMainGateway(List<GatewayBean> list) { |
| | | if (list == null || list.size() == 0) { |
| | | return null; |
| | | } |
| | | GatewayBean findGatewayBean = null; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | //找到返回 |
| | | findGatewayBean = gatewayBean; |
| | | break; |
| | | } |
| | | } |
| | | return null; |
| | | return findGatewayBean; |
| | | } |
| | | |
| | | |
| | |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("server_addr", AppConfigManage.getUserRegionUrl()); |
| | | json.addProperty("local_secret", UserConfigManage.getInstance().getLocalSecret()); |
| | | //解密负载数据(因为写密钥给网关一定明文,因为那时网关还没有密钥) |
| | | //解密负载数据(写密钥给网关一定是明文,因为那时网关还没有密钥) |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, false, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取逆变器列表 |
| | | * 注意:有外网以云端设备为准,本地存在,云端没有则删除;内网以本地为主,搜索多少个设备就显示多少个; |
| | | * 获取逆变器列表(整合云端和本地列表) |
| | | * 注意:有外网,以云端设备为准,本地存在,云端没有则删除;内网,以本地为主,搜索多少个设备就显示多少个; |
| | | * |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | */ |
| | | public void getCurrentHomeLocalAndCloudGatewayList(CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { |
| | | HdlDeviceLogic.getInstance().searchCurrentHomeGateway(new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //局域网有2种情况(1:有局域网,有外网;2:有局域网,没有外网); |
| | |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | //外网只有1情况(本地搜索逆变器列表失败了) |
| | | //外网只有1种情况(本地搜索逆变器列表失败了) |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | |
| | | |
| | | /** |
| | | * 搜索逆变器列表 |
| | | * 注意:只搜索当前住宅逆变器和没有被绑定的逆变器 |
| | | * |
| | | * @param gatewayCallBack - |
| | | */ |
| | | public void searchGateway(GatewayCallBack gatewayCallBack) { |
| | | public void searchCurrentHomeGateway(GatewayCallBack gatewayCallBack) { |
| | | List<String> spks = this.getGatewaySpk(); |
| | | //网关搜索 |
| | | HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack); |
| | | } |
| | | |
| | | /** |
| | | * 搜索局域网所有逆变器列表 |
| | | * 注意:包括已经被绑定到住宅的逆变器 |
| | | * |
| | | * @param gatewayCallBack - |
| | | */ |
| | | public void searchAllGateway(GatewayCallBack gatewayCallBack) { |
| | | //网关搜索 |
| | | HDLLinkLocalSdk.getInstance().refreshGateway(gatewayCallBack, this.getGatewaySpk()); |
| | | } |
| | | |
| | | /** |
| | | * 判断是本地连接 |
| | | * |
| | | * @param deviceMac 设备mac |
| | | * @return true=本地连接 |
| | | */ |
| | | public boolean isLocalConnect(String deviceMac) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceMac); |
| | | return gatewayBean == null; |
| | | } |
| | | |
| | | /** |
| | | * 检测逆变器有没有连接上云 |
| | | * |
| | | * @param deviceMac 设备mac |
| | | */ |
| | | public void checkInverterConnectedCloud(String deviceMac, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { |
| | | this.getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), 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); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @return - |
| | | */ |
| | | private List<String> getGatewaySpk() { |
| | | public List<String> getGatewaySpk() { |
| | | List<String> spks = new ArrayList<>(); |
| | | spks.add(DEVICE_SPK); |
| | | return spks; |
| | | } |
| | | |
| | | public boolean isGatewaySpk(String spk) { |
| | | if (TextUtils.isEmpty(spk)) { |
| | | return false; |
| | | } |
| | | for (int i = 0; i < this.getGatewaySpk().size(); i++) { |
| | | if (this.getGatewaySpk().get(i).equals(spk)) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public final String DEVICE_SPK = "energy.hdl_inverter"; |
| | | } |