| | |
| | | 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 List<GatewayBean> getCurrentHomeGatewayList() { |
| | | List<GatewayBean> newList = new ArrayList<>(); |
| | |
| | | * 获取当前住宅的【主】逆变器列表 |
| | | */ |
| | | 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:有局域网,没有外网); |
| | |
| | | //云端也没有逆变器列表,返回空列表回去 |
| | | cloudCallBeak.onSuccess(new ArrayList<>()); |
| | | } |
| | | HdlLogLogic.print("在只有【外网】情况下获取云端逆变器列表返回空列表",true); |
| | | return; |
| | | } |
| | | //记录条数 |
| | |
| | | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | |
| | | //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥) |
| | | getDeviceRemoteInfo(UserConfigManage.getInstance().getHomeId(), cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 搜索逆变器列表 |
| | | * 注意:只搜索当前住宅逆变器和没有被绑定的逆变器 |
| | | * |
| | | * @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()); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 获取网关支持spk列表 |
| | | * |
| | | * @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"; |
| | | } |