| | |
| | | import android.os.SystemClock; |
| | | import android.text.TextUtils; |
| | | |
| | | import com.facebook.imagepipeline.image.OriginalEncodedImageInfo; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.photovoltaic.bean.PageNumberObject; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | |
| | | 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.config.TopicConstant; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkCode; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.common.utils.IdUtils; |
| | | import com.hdl.sdk.link.core.bean.LinkRequest; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.bean.response.BaseLocalResponse; |
| | | import com.hdl.sdk.link.core.callback.GatewayCallBack; |
| | | import com.hdl.sdk.link.core.callback.HDLLinkCallBack; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.core.connect.HDLConnectHelper; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | import com.hdl.sdk.link.gateway.type.GatewayMasterType; |
| | | |
| | |
| | | return sHdlDeviceLogic; |
| | | } |
| | | |
| | | |
| | | private List<CloudInverterDeviceBean> mListDevice = new ArrayList<>(); |
| | | |
| | | |
| | | public void clearDeviceList() { |
| | | if (mListDevice == null) { |
| | | return; |
| | | } |
| | | if (mListDevice.size() > 0) { |
| | | mListDevice.clear(); |
| | | } |
| | | } |
| | | |
| | | public List<CloudInverterDeviceBean> getDeviceList() { |
| | | if (mListDevice == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return mListDevice; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表(包括从的逆变器) |
| | |
| | | * @param homeId 电站id |
| | | * @param mac 逆变器mac |
| | | */ |
| | | public void removeLocalCacheMemoryGateway(String homeId, String mac) { |
| | | public void removeLocalCacheMemoryGatewayToMac(String homeId, String mac) { |
| | | if (TextUtils.isEmpty(mac)) { |
| | | return; |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 移除缓存列表里面逆变器 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param deviceId 逆变器deviceId |
| | | */ |
| | | public void removeLocalCacheMemoryGatewayToDeviceId(String homeId, String deviceId) { |
| | | if (TextUtils.isEmpty(deviceId)) { |
| | | return; |
| | | } |
| | | List<GatewayBean> list = getCurrentHomeGatewayList(homeId); |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | int index = -1; |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (gatewayBean.getDeviceId().equals(deviceId)) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | if (index > 0) { |
| | | list.remove(index); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 添加【设备列表】到本地缓存 |
| | | * |
| | | * @param list -设备列表 |
| | | */ |
| | | public void setListDevice(List<CloudInverterDeviceBean> list) { |
| | | try { |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | if (this.mListDevice.size() == 0) { |
| | | this.mListDevice.addAll(list); |
| | | return; |
| | | } |
| | | for (int i = 0; i < list.size(); i++) { |
| | | this.setSingleDevice(list.get(i)); |
| | | } |
| | | } catch (Exception ignored) { |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取设备列表(安装商) |
| | | * |
| | | * @param searchTxt 搜索内容 |
| | | * @param pageNo 页码 |
| | | * @param pageSize 页数 |
| | | */ |
| | | public void getPowerStationDeviceList(String searchTxt, long pageNo, long pageSize, CloudCallBeak<PageNumberObject<CloudInverterDeviceBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_deviceList; |
| | | JsonObject json = new JsonObject(); |
| | | if (!TextUtils.isEmpty(searchTxt)) { |
| | | json.addProperty("searchTxt", searchTxt); |
| | | } |
| | | json.addProperty("pageNo", pageNo);//页码 |
| | | json.addProperty("pageSize", pageSize);//页数 |
| | | // json.addProperty("zoneType", zoneType);//区域 |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | if (TextUtils.isEmpty(jsonStr)) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(new PageNumberObject<>()); |
| | | } |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type type = new TypeToken<PageNumberObject<CloudInverterDeviceBean>>() { |
| | | }.getType(); |
| | | PageNumberObject<CloudInverterDeviceBean> pageNumberObject = gson.fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(pageNumberObject); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 添加设备到列表里面 |
| | | * |
| | | * @param deviceBean -设备对象 |
| | | */ |
| | | public void setSingleDevice(CloudInverterDeviceBean deviceBean) { |
| | | try { |
| | | if (deviceBean == null) { |
| | | return; |
| | | } |
| | | boolean if_boolean = false; |
| | | for (int i = 0; i < mListDevice.size(); i++) { |
| | | if (mListDevice.get(i).getOsn().equals(deviceBean.getOsn())) { |
| | | //存在替换 |
| | | mListDevice.remove(i); |
| | | mListDevice.add(i, deviceBean); |
| | | if_boolean = true; |
| | | break; |
| | | } |
| | | } |
| | | if (!if_boolean) { |
| | | //没有添加 |
| | | this.mListDevice.add(deviceBean); |
| | | } |
| | | } catch (Exception e) { |
| | | String mes = e.getMessage(); |
| | | HdlLogLogic.print("---" + mes); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 逆变器上传数据到云端(包括:sid,oid) |
| | |
| | | @Override |
| | | public void onSuccess(List<OidBean> oidBeanList) { |
| | | if (oidBeanList == null) { |
| | | HdlLogLogic.print("上传oid列表到云端成功--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->数据是null", true); |
| | | HdlLogLogic.print("上传oid列表到云端成功---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---数据是null", true); |
| | | return; |
| | | } |
| | | //增量添加oid |
| | | updateOidAdd(homeId, oidBeanList, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("上传oid列表到云端成功(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n数据--->" + new Gson().toJson(oidBeanList), true); |
| | | HdlLogLogic.print("上传oid列表到云端成功(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n数据---" + new Gson().toJson(oidBeanList), true); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | // updateOidAdd(homeId, oidList, new CloudCallBeak<Boolean>() { |
| | | // @Override |
| | | // public void onSuccess(Boolean obj) { |
| | | // HdlLogLogic.print("上传oid列表到云端成功--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac(), true); |
| | | // HdlLogLogic.print("上传oid列表到云端成功---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac(), true); |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onFailure(HDLException e) { |
| | | // HdlLogLogic.print("上传oid列表到云端失败--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | // HdlLogLogic.print("上传oid列表到云端失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | // } |
| | | // }); |
| | | |
| | |
| | | fullUpdateOid(homeId, newOidList, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("上传oid列表到云端成功(全量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n数据--->" + new Gson().toJson(newOidList), true); |
| | | HdlLogLogic.print("上传oid列表到云端成功(全量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n数据---" + new Gson().toJson(newOidList), true); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败(全量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("上传oid列表到云端失败(全量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (newOidList.size() == 0) { |
| | | HdlLogLogic.print("获取逆变器oid列表失败--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("获取逆变器oid列表失败---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | return; |
| | | } |
| | | //增量添加oid |
| | | updateOidAdd(homeId, newOidList, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("上传oid列表到云端成功(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "--->\r\n数据--->" + new Gson().toJson(newOidList), true); |
| | | HdlLogLogic.print("上传oid列表到云端成功(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "---\r\n数据---" + new Gson().toJson(newOidList), true); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)---住宅id:" + homeId + "---mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | |
| | | cloudCallBeak.onSuccess(true); |
| | | //临时的逻辑,上传oid列表到云端 |
| | | List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId); |
| | | uploadOidDataToCloud(UserConfigManage.getInstance().getHomeId(), list, true, null); |
| | | uploadOidDataToCloud(homeId, list, true, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //添加逆变器失败后初始化逆变器 |
| | | HdlLogLogic.print("添加逆变器失败后开始初始化逆变器-->", true); |
| | | HdlDeviceLogic.getInstance().initializeInverter(mac, new LinkCallBack<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("初始化逆变器成功-->mac:" + mac, true); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + mac, true); |
| | | } |
| | | }); |
| | | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | //添加逆变器失败后初始化逆变器 |
| | | HdlLogLogic.print("添加逆变器失败后开始初始化逆变器-->", true); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | HdlDeviceLogic.getInstance().initializeInverter(gatewayBean.getDevice_mac(), new LinkCallBack<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("初始化逆变器成功-->mac:" + gatewayBean.getDevice_mac(), true); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + gatewayBean.getDevice_mac(), true); |
| | | } |
| | | }); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | |
| | | |
| | | } |
| | | }); |
| | | } |
| | |
| | | */ |
| | | public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | if (oidList == null || oidList.size() == 0) { |
| | | HdlLogLogic.print("oid列表为空,无法全量更新oid到云端--->", true); |
| | | HdlLogLogic.print("oid列表为空,无法全量更新oid到云端---", true); |
| | | return; |
| | | } |
| | | String requestUrl = HttpApi.POST_Device_Oid; |
| | |
| | | */ |
| | | public void updateOidAdd(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | if (oidList == null || oidList.size() == 0) { |
| | | HdlLogLogic.print("oid列表为空,无法增量添加oid到云端--->", true); |
| | | HdlLogLogic.print("oid列表为空,无法增量添加oid到云端---", true); |
| | | return; |
| | | } |
| | | String requestUrl = HttpApi.POST_Device_IncrAdd; |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | HdlLogLogic.print("增量添加oid到云端成功--->"); |
| | | HdlLogLogic.print("增量添加oid到云端成功---"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | HdlLogLogic.print("增量添加oid到云端失败--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("增量添加oid到云端失败---" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 修改设备名称逆变器BMS电池包 |
| | | * 描述: 修改设备名称,支持逆变器,BMS,电池包设备名称修改 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param deviceType 设备类型(INV:逆变器,BMS:BMS控制盒,BATTERY:电池单元) |
| | | * @param deviceId 设备id(deviceType = INV 是逆变器deviceId;deviceType = BMS 是BMS的deviceOidId;deviceType = BATTERY 是电池包的deviceOidId) |
| | | * @param cloudCallBeak 回调update |
| | | */ |
| | | public void setRename(String homeId, String deviceType, String deviceId, String name, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_Rename; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("name", name); |
| | | json.addProperty("deviceType", deviceType);//设备类型(INV:逆变器,BMS:BMS控制盒,BATTERY:电池单元) |
| | | json.addProperty("deviceId", deviceId);//设备id(deviceType = INV 是逆变器deviceId;deviceType = BMS 是BMS的deviceOidId;deviceType = BATTERY 是电池包的deviceOidId) |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String str) { |
| | | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | |
| | | /** |
| | | * 初始化逆变器 |
| | | * |
| | | * @param mac 网关mac |
| | | * @param mac 逆变器mac |
| | | */ |
| | | public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | public void initializeInverter(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE; |
| | | JsonObject jObject = new JsonObject(); |
| | | jObject.addProperty("device_mac", mac); |
| | |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onError(e); |
| | | } |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + mac + "--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + mac + "---" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | | */ |
| | | public void getCurrentHomeLocalAndCloudGatewayList(String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | HdlDeviceLogic.getInstance().searchCurrentHomeGateway(new GatewayCallBack() { |
| | | HdlDeviceLogic.getInstance().searchCurrentHomeGateway(homeId, new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | //局域网有2种情况(1:有局域网,有外网;2:有局域网,没有外网); |
| | |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | ///情况1:有局域网,有外网; |
| | | if (list == null || list.size() == 0) { |
| | | //云端没有绑定逆变器,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | return; |
| | | } |
| | | //记录条数 |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥) |
| | | getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | | @Override |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(true, cloudInverterDeviceBean, deviceRemoteInfo, homeId); |
| | | //最后一条才做删除逆变器逻辑处理 |
| | | if (atomicInteger.get() == list.size()) { |
| | | //收集删除逆变器sid |
| | | List<String> removeSidList = new ArrayList<>(); |
| | | for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); |
| | | if (!querySidInverter(list, gatewayBean.getSid())) { |
| | | //本地有,云端没有,删除本地; |
| | | removeSidList.add(gatewayBean.getSid()); |
| | | } |
| | | } |
| | | for (int i = 0; i < removeSidList.size(); i++) { |
| | | //删除本地的逆变器 |
| | | removeLocalInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //当最后一条请求失败了,才在这里做删除逆变器逻辑处理 |
| | | if (atomicInteger.get() == list.size()) { |
| | | //收集删除逆变器sid |
| | | List<String> removeSidList = new ArrayList<>(); |
| | | for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); |
| | | if (!querySidInverter(list, gatewayBean.getSid())) { |
| | | //本地有,云端没有,删除本地; |
| | | removeSidList.add(gatewayBean.getSid()); |
| | | } |
| | | } |
| | | for (int i = 0; i < removeSidList.size(); i++) { |
| | | //删除本地的逆变器 |
| | | removeLocalInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | setDeviceRemoteInfo(list, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | //外网进来先【默认】清空本地逆变器列表 |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().clear(); |
| | | if (list == null || list.size() == 0) { |
| | | if (cloudCallBeak != null) { |
| | | //云端也没有逆变器列表,返回空列表回去 |
| | | cloudCallBeak.onSuccess(new ArrayList<>()); |
| | | } |
| | | HdlLogLogic.print("在只有【外网】情况下获取云端逆变器列表返回空列表", true); |
| | | return; |
| | | } |
| | | //记录条数 |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | |
| | | //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥) |
| | | getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | | @Override |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo, homeId); |
| | | //到最后一条,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //当最后一条请求失败了,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败--->msg--->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | setDeviceRemoteInfo(list, homeId, cloudCallBeak); |
| | | } |
| | | |
| | | @Override |
| | |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 设置设备的远程信息(拿到网关ID,mqtt通讯秘钥等信息) |
| | | * |
| | | * @param list 云端上的逆变器列表 |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 回调 |
| | | */ |
| | | public void setDeviceRemoteInfo(List<CloudInverterDeviceBean> list, String homeId, CloudCallBeak<List<GatewayBean>> cloudCallBeak) { |
| | | if (list == null || list.size() == 0) { |
| | | //云端没有绑定逆变器,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | |
| | | return; |
| | | } |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | //获取远程设备通讯信息(拿到网关ID,mqtt通讯秘钥) |
| | | getDeviceRemoteInfo(homeId, cloudInverterDeviceBean.getSpk(), cloudInverterDeviceBean.getOsn(), new CloudCallBeak<DeviceRemoteInfo>() { |
| | | @Override |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo, homeId); |
| | | //到最后一条,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //当最后一条请求失败了,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败---msg---" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param gatewayCallBack - |
| | | */ |
| | | public void searchCurrentHomeGateway(GatewayCallBack gatewayCallBack) { |
| | | public void searchCurrentHomeGateway(String homeId, GatewayCallBack gatewayCallBack) { |
| | | List<String> spks = this.getGatewaySpk(); |
| | | //网关搜索 |
| | | HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack); |
| | | HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(homeId, spks, true, gatewayCallBack); |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param deviceMac 设备mac, |
| | | * @param callBeak 返回 true=本地连接;false=远程; |
| | | */ |
| | | public void isLocalConnect(String deviceMac, CloudCallBeak<Boolean> callBeak) { |
| | | searchCurrentHomeGateway(new GatewayCallBack() { |
| | | public void isLocalConnect(String homeId, String deviceMac, CloudCallBeak<Boolean> callBeak) { |
| | | searchCurrentHomeGateway(homeId, new GatewayCallBack() { |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> gatewayBeanList) { |
| | | if (gatewayBeanList == null || gatewayBeanList.size() == 0) { |
| | |
| | | |
| | | /** |
| | | * 刷新逆变器缓存信息(包括设置mqtt秘钥) |
| | | * 注: |
| | | * 注: //目的是为了获取拿到网关ID,mqtt通讯秘钥等信息,缓存本地逆变器列表里面,发送数据数据时自动去缓存列表里面去查找; |
| | | * 1:本地存在,更新信息即可; |
| | | * 2:本地不存在,则虚拟一个逆变器对象添加在本地; |
| | | * |
| | |
| | | gatewayBean.setSystemStatusDesc(cloudInverterDeviceBean.getSystemStatusDesc());//设备状态 |
| | | gatewayBean.setHwVersion(cloudInverterDeviceBean.getHwVersion());//软件版本号 |
| | | gatewayBean.setCategorySecondName(cloudInverterDeviceBean.getCategorySecondName());//设备类型(产品二级分类名称 |
| | | gatewayBean.setDeviceType(cloudInverterDeviceBean.getDeviceType());//设备类型(INV:逆变器;BMS:BMS控制盒;BATTERY:电池单元) |
| | | gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//子网号/设备号,逆变器地址 |
| | | gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//发电功率 |
| | | gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//今日发电量 |