| | |
| | | package com.hdl.photovoltaic.other; |
| | | |
| | | 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.listener.LinkCallBack; |
| | | import com.hdl.photovoltaic.ui.bean.CloudInverterChildDeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceTimeBean; |
| | | import com.hdl.photovoltaic.ui.bean.HouseInfoBean; |
| | | import com.hdl.photovoltaic.ui.bean.MessageBean; |
| | | 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; |
| | | } |
| | | |
| | | public static final String kWp = "kWp"; |
| | | public static final String kWh = "kW.h"; |
| | | |
| | | public static final String kW = "kW"; |
| | | private List<DeviceBean> mListDevice = new ArrayList<>(); |
| | | |
| | | public void clearDeviceList() { |
| | | if (mListDevice == null) { |
| | | return; |
| | | } |
| | | if (mListDevice.size() > 0) { |
| | | mListDevice.clear(); |
| | | } |
| | | } |
| | | |
| | | public List<DeviceBean> getDeviceList() { |
| | | if (mListDevice == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | | return mListDevice; |
| | | } |
| | | |
| | | /** |
| | | * 获取当前住宅的逆变器列表(包括从的逆变器) |
| | | */ |
| | | public List<GatewayBean> getCurrentHomeGatewayList() { |
| | | public List<GatewayBean> getCurrentHomeGatewayList(String homeId) { |
| | | List<GatewayBean> newList = new ArrayList<>(); |
| | | List<GatewayBean> list = HDLLinkLocalGateway.getInstance().getGatewayList(); |
| | | if (list.size() > 0) { |
| | |
| | | continue; |
| | | } |
| | | //用homeId筛选当前住宅的逆变器列表 |
| | | if (gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | if (gatewayBean.getHomeId().equals(homeId)) { |
| | | newList.add(gatewayBean); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取当前住宅的【主】逆变器 |
| | | * 添加逆变器到缓存列表里面去 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param newGatewayBean 逆变器对象 |
| | | */ |
| | | public GatewayBean getCurrentHomeMainGateway() { |
| | | return queryCurrentHomeMainGateway(this.getCurrentHomeGatewayList()); |
| | | } |
| | | |
| | | /** |
| | | * 查询当前住宅的【主】逆变器 |
| | | */ |
| | | public GatewayBean queryCurrentHomeMainGateway(List<GatewayBean> list) { |
| | | if (list == null || list.size() == 0) { |
| | | return null; |
| | | public void addGatewayToLocalCacheMemory(String homeId, GatewayBean newGatewayBean) { |
| | | if (newGatewayBean == null || TextUtils.isEmpty(homeId)) { |
| | | return; |
| | | } |
| | | GatewayBean findGatewayBean = null; |
| | | 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.getMaster().equals(GatewayMasterType.MasterTrue) && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | //找到返回 |
| | | findGatewayBean = gatewayBean; |
| | | if (gatewayBean.getDevice_mac().equals(newGatewayBean.getDevice_mac())) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | return findGatewayBean; |
| | | if (index > 0) { |
| | | list.remove(index); |
| | | list.add(index, newGatewayBean); |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 移除缓存列表里面逆变器 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param mac 逆变器mac |
| | | */ |
| | | public void removeLocalCacheMemoryGateway(String homeId, String mac) { |
| | | if (TextUtils.isEmpty(mac)) { |
| | | 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.getDevice_mac().equals(mac)) { |
| | | index = i; |
| | | break; |
| | | } |
| | | } |
| | | if (index > 0) { |
| | | list.remove(index); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取设备列表(安装商) |
| | | * |
| | | * @param searchTxt 搜索内容 |
| | | * @param pageNo 页码 |
| | | * @param pageSize 页数 |
| | | */ |
| | | public void getPowerStationDeviceList(String searchTxt, long pageNo, long pageSize, CloudCallBeak<PageNumberObject<DeviceBean>> 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<DeviceBean>>() { |
| | | }.getType(); |
| | | PageNumberObject<DeviceBean> pageNumberObject = gson.fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(pageNumberObject); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 添加【设备列表】到本地缓存 |
| | | * |
| | | * @param list -设备列表 |
| | | */ |
| | | public void setListDevice(List<DeviceBean> 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 deviceBean -设备对象 |
| | | */ |
| | | public void setSingleDevice(DeviceBean 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) |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param mac 设备mac |
| | | * @param homeId 住宅id |
| | | * @param list 逆变器列表 |
| | | * @param whetherToAdd true表示用增量,false表示用全量 |
| | | */ |
| | | public void uploadDataToCloud(String homeId, String mac, CloudCallBeak<Boolean> callBeak) { |
| | | getInverterOidList(mac, new LinkCallBack<List<OidBean>>() { |
| | | @Override |
| | | public void onSuccess(List<OidBean> obj) { |
| | | if (obj == null) { |
| | | return; |
| | | public void uploadOidDataToCloud(String homeId, List<GatewayBean> list, boolean whetherToAdd, CloudCallBeak<Boolean> callBeak) { |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | | } |
| | | if (whetherToAdd) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | fullUpdateOid(homeId, obj, new CloudCallBeak<Boolean>() { |
| | | getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("上传oid列表到云端成功-->" + homeId + "--->" + mac, true); |
| | | public void onSuccess(List<OidBean> oidBeanList) { |
| | | if (oidBeanList == null) { |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | public void onError(HDLLinkException e) { |
| | | } |
| | | }); |
| | | SystemClock.sleep(200); |
| | | } |
| | | } else { |
| | | //只有进入详情界面 |
| | | List<OidBean> newOidList = new ArrayList<>(); |
| | | AtomicInteger atomicInteger = new AtomicInteger(0); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | if (gatewayBean == null || TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | getInverterOidList(gatewayBean.getDevice_mac(), new LinkCallBack<List<OidBean>>() { |
| | | @Override |
| | | public void onSuccess(List<OidBean> oidBeanList) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | if (oidBeanList == null) { |
| | | return; |
| | | } |
| | | newOidList.addAll(oidBeanList); |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (newOidList.size() == 0) { |
| | | return; |
| | | } |
| | | // //增量添加oid |
| | | // updateOidAdd(homeId, oidList, new CloudCallBeak<Boolean>() { |
| | | // @Override |
| | | // public void onSuccess(Boolean obj) { |
| | | // 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); |
| | | // } |
| | | // }); |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | HdlLogLogic.print("获取逆变器oid列表失败-->" + homeId + "--->" + 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); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败(全量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | 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); |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败(增量)--->住宅id:" + homeId + "--->mac:" + gatewayBean.getDevice_mac() + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | }); |
| | | SystemClock.sleep(200); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param name - |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void addInverterDeviceToCloud(String mac, String spk, String sid, String oid, String name, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | public void addInverterDeviceToCloud(String homeId, String mac, String spk, String sid, String oid, String name, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | |
| | | String requestUrl = HttpApi.POST_Device_Add; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("mac", mac); |
| | | json.addProperty("spk", spk); |
| | | json.addProperty("sid", sid); |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | //临时的逻辑,上传oid列表到云端 |
| | | uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), mac, null); |
| | | List<GatewayBean> list = HdlDeviceLogic.getInstance().getCurrentHomeGatewayList(homeId); |
| | | uploadOidDataToCloud(UserConfigManage.getInstance().getHomeId(), list, true, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 添加多个逆变器到云端上 |
| | | * |
| | | * @param list 逆变器列表 |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void addAllInverterDeviceToCloud(String homeId, List<GatewayBean> list, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | |
| | | String requestUrl = HttpApi.POST_Device_Add_All; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | JsonArray ary = new JsonArray(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | GatewayBean gatewayBean = list.get(i); |
| | | JsonObject inverterInfo = new JsonObject(); |
| | | inverterInfo.addProperty("mac", gatewayBean.getDevice_mac()); |
| | | inverterInfo.addProperty("spk", gatewayBean.getGatewayType()); |
| | | inverterInfo.addProperty("sid", gatewayBean.getSid()); |
| | | inverterInfo.addProperty("oid", gatewayBean.getOid()); |
| | | inverterInfo.addProperty("name", gatewayBean.getDevice_name()); |
| | | ary.add(inverterInfo); |
| | | } |
| | | json.add("devices", ary); |
| | | // 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); |
| | | //临时的逻辑,上传oid列表到云端 |
| | | uploadOidDataToCloud(homeId, list, true, null); |
| | | } |
| | | } |
| | | |
| | |
| | | * @param deviceId 设备id |
| | | * @param cloudCallBeak 回调 |
| | | */ |
| | | public void delInverterDevice(String deviceId, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | public void delInverterDevice(String homeId, String deviceId, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_Remove; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("deviceId", deviceId); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | |
| | |
| | | * @param parentOid 上级设备的Oid |
| | | * @param cloudCallBeak 回调 |
| | | */ |
| | | public void getInverterDeviceChildDeviceList(String parentOid, CloudCallBeak<List<CloudInverterChildDeviceBean>> cloudCallBeak) { |
| | | public void getInverterDeviceChildDeviceList(String homeId, String parentOid, CloudCallBeak<List<CloudInverterChildDeviceBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_ChildDevices_List; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("parentOid", parentOid); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | |
| | |
| | | * @param cloudCallBeak 回调update |
| | | */ |
| | | public void fullUpdateOid(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | if (oidList == null || oidList.size() == 0) { |
| | | HdlLogLogic.print("oid列表为空,无法全量更新oid到云端--->", true); |
| | | return; |
| | | } |
| | | String requestUrl = HttpApi.POST_Device_Oid; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("operationSource", "PROGRAM_ENERGY");// |
| | | json.addProperty("homeId", homeId); |
| | | JsonArray jsonArray = new JsonArray(); |
| | | for (int i = 0; i < oidList.size(); i++) { |
| | | OidBean oidBean = oidList.get(i); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("protocolType", oidBean.getProtocolType()); |
| | | jsonObject.addProperty("deviceType", oidBean.getDeviceType()); |
| | | jsonObject.addProperty("mac", oidBean.getDevice_mac()); |
| | | jsonObject.addProperty("oid", oidBean.getOid()); |
| | | jsonObject.addProperty("device_name", oidBean.getDevice_name()); |
| | | jsonObject.addProperty("device_model", oidBean.getDevice_model()); |
| | | jsonObject.addProperty("addresses", oidBean.getAddresses()); |
| | | jsonObject.addProperty("parentOid", oidBean.getParentOid()); |
| | | jsonArray.add(jsonObject); |
| | | |
| | | } |
| | | json.add("devices", jsonArray); |
| | | // 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); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * (oid)增量添加 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param oidList oid列表 |
| | | * @param cloudCallBeak 回调update |
| | | */ |
| | | public void updateOidAdd(String homeId, List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | if (oidList == null || oidList.size() == 0) { |
| | | HdlLogLogic.print("oid列表为空,无法增量添加oid到云端--->", true); |
| | | return; |
| | | } |
| | | String requestUrl = HttpApi.POST_Device_IncrAdd; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | JsonArray jsonArray = new JsonArray(); |
| | | for (int i = 0; i < oidList.size(); i++) { |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | |
| | | HdlLogLogic.print("增量添加oid到云端成功--->"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | HdlLogLogic.print("增量添加oid到云端失败--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | * @param mac 设备mac |
| | | * @param linkCallBack 回调update |
| | | */ |
| | | public void setGatewayRemoteParam(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | public void setGatewayRemoteParam(String homeId, String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); |
| | | json.addProperty("homeId", homeId); |
| | | json.addProperty("server_addr", AppConfigManage.getUserRegionUrl()); |
| | | json.addProperty("local_secret", UserConfigManage.getInstance().getLocalSecret()); |
| | | //解密负载数据(写密钥给网关一定是明文,因为那时网关还没有密钥) |
| | |
| | | * 网关时间读取 |
| | | * |
| | | * @param mac 设备mac |
| | | * @param linkCallBack 回调update |
| | | * @param linkCallBack 回调updatetime |
| | | */ |
| | | public void getGatewayTime(String mac, LinkCallBack<DeviceTimeBean> linkCallBack) { |
| | | String requestUrl = TopicApi.GET_GATEWAY_TIME; |
| | |
| | | * @param mac 设备mac |
| | | * @param date 日期 |
| | | * @param time 时间 |
| | | * @param timezone 时区 |
| | | * @param linkCallBack 回调update |
| | | */ |
| | | public void editGatewayTime(String mac, String date, String time, LinkCallBack<Boolean> linkCallBack) { |
| | | public void editGatewayTime(String mac, String date, String time, String timezone, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_TIME_EDIT; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("date", date);// "2020-08-15" |
| | | json.addProperty("time", time);//"17:25:20" |
| | | if (!TextUtils.isEmpty(date)) { |
| | | json.addProperty("date", date);// "2020-08-15" |
| | | } |
| | | if (!TextUtils.isEmpty(time)) { |
| | | json.addProperty("time", time);//"17:25:20" |
| | | } |
| | | if (!TextUtils.isEmpty(timezone)) { |
| | | json.addProperty("timezone", timezone);//时区(语雀https://hdl-gz.yuque.com/wnkbmh/cdrglh/yckkyp#qWOPS) |
| | | } |
| | | |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 初始化逆变器 |
| | | * |
| | | * @param mac 网关mac |
| | | */ |
| | | public void initializeGateway(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.GATEWAY_INITIALIZE_REMOTE; |
| | | JsonObject jObject = new JsonObject(); |
| | | jObject.addProperty("device_mac", mac); |
| | | jObject.addProperty("reset_factory", "true");//为false或无此字段,则为"清除数据" |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jObject, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onSuccess(true); |
| | | } |
| | | HdlLogLogic.print("初始化逆变器成功-->mac:" + mac, true); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onError(e); |
| | | } |
| | | HdlLogLogic.print("初始化逆变器失败-->mac:" + mac + "--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 删除oid |
| | | * |
| | | * @param mac 网关mac |
| | | * @param oid 设备oid |
| | | */ |
| | | public void deleteOid(String mac, String oid, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.DELETING_GATEWAY_SLAVE; |
| | | JsonArray jsonArray = new JsonArray(); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("oid", oid);//设备oid |
| | | jsonArray.add(jsonObject); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonArray, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onSuccess(true); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onError(e); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取逆变器oid列表 |
| | | * |
| | | * @param mac 网关mac |
| | |
| | | if (list == null || list.size() == 0) { |
| | | //云端没有绑定逆变器,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | return; |
| | | } |
| | |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(true, cloudInverterDeviceBean, deviceRemoteInfo); |
| | | refreshGatewayCacheData(true, cloudInverterDeviceBean, deviceRemoteInfo, homeId); |
| | | //最后一条才做删除逆变器逻辑处理 |
| | | if (atomicInteger.get() == list.size()) { |
| | | //收集删除逆变器sid |
| | | List<String> removeSidList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); |
| | | if (!cloudInverterDeviceBean.getSid().equals(gatewayBean.getSid())) { |
| | | //本地有,云端没有,删除本地; |
| | | removeSidList.add(gatewayBean.getSid()); |
| | | } |
| | | |
| | | 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()); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | } |
| | |
| | | if (atomicInteger.get() == list.size()) { |
| | | //收集删除逆变器sid |
| | | List<String> removeSidList = new ArrayList<>(); |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | for (int j = 0; j < HDLLinkLocalGateway.getInstance().getGatewayList().size(); j++) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getGatewayList().get(j); |
| | | if (!cloudInverterDeviceBean.getSid().equals(gatewayBean.getSid())) { |
| | | //本地有,云端没有,删除本地; |
| | | removeSidList.add(gatewayBean.getSid()); |
| | | } |
| | | |
| | | 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()); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | |
| | | ///情况2:有局域网,没有外网; |
| | | //本地有逆变器列表,获取云端绑定逆变器失败,默认返回本地逆变器列表; |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | }); |
| | |
| | | public void onSuccess(DeviceRemoteInfo deviceRemoteInfo) { |
| | | atomicInteger.set(atomicInteger.get() + 1); |
| | | //更新逆变器本地缓存信息 |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo); |
| | | refreshGatewayCacheData(false, cloudInverterDeviceBean, deviceRemoteInfo, homeId); |
| | | //到最后一条,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | } |
| | |
| | | //当最后一条请求失败了,才有回调 |
| | | if (atomicInteger.get() == list.size()) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | HdlLogLogic.print("获取设备远程通讯信息失败--->msg--->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |
| | |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 通过sid查询逆变器 |
| | | * |
| | | * @param list 云端上逆变器列表 |
| | | * @return 存在为true, 否则为false |
| | | */ |
| | | private boolean querySidInverter(List<CloudInverterDeviceBean> list, String sid) { |
| | | for (int i = 0; i < list.size(); i++) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = list.get(i); |
| | | if (sid.equals(cloudInverterDeviceBean.getSid())) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", ""); |
| | | json.addProperty("server_addr", ""); |
| | | json.addProperty("local_secret", ""); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, true, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | |
| | | * |
| | | * @param gatewayCallBack - |
| | | */ |
| | | public void searchAllGateway(GatewayCallBack gatewayCallBack) { |
| | | public void searchAllNetworkGateway(GatewayCallBack gatewayCallBack) { |
| | | List<String> spks = this.getGatewaySpk(); |
| | | //网关搜索 |
| | | HDLLinkLocalSdk.getInstance().refreshGateway(gatewayCallBack, this.getGatewaySpk()); |
| | | HDLLinkLocalGateway.getInstance().refreshGatewayBySpk(spks, true, gatewayCallBack); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param deviceMac 设备mac |
| | | */ |
| | | public void checkInverterConnectedCloud(String deviceMac, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { |
| | | this.getCloudInverterDeviceList(UserConfigManage.getInstance().getHomeId(), new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | public void checkInverterConnectedCloud(String homeId, String deviceMac, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { |
| | | this.getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | CloudInverterDeviceBean cloudInverterDeviceBean = null; |
| | |
| | | * @param deviceRemoteInfo 设备远程通讯信息 |
| | | * @param cloudInverterDeviceBean 逆变器 |
| | | */ |
| | | private void refreshGatewayCacheData(boolean isLocal, CloudInverterDeviceBean cloudInverterDeviceBean, DeviceRemoteInfo deviceRemoteInfo) { |
| | | private void refreshGatewayCacheData(boolean isLocal, CloudInverterDeviceBean cloudInverterDeviceBean, DeviceRemoteInfo deviceRemoteInfo, String homeId) { |
| | | //本地查找逆变器 |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(cloudInverterDeviceBean.getOsn()); |
| | | if (gatewayBean == null) { |
| | |
| | | HDLLinkConfig.getInstance().setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId |
| | | |
| | | } |
| | | gatewayBean.setHomeId(UserConfigManage.getInstance().getHomeId());//住宅id |
| | | gatewayBean.setHomeId(homeId);//住宅id |
| | | gatewayBean.setDeviceStatus(cloudInverterDeviceBean.getDeviceStatus());//设置网关状态 |
| | | gatewayBean.setDeviceId(cloudInverterDeviceBean.getDeviceId());//设置link设备id |
| | | gatewayBean.setDevice_mac(cloudInverterDeviceBean.getOsn());//设置mac |
| | |
| | | gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//子网号/设备号,逆变器地址 |
| | | gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//发电功率 |
| | | gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//今日发电量 |
| | | gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//设备型号 |
| | | if (!TextUtils.isEmpty(cloudInverterDeviceBean.getOmodel())) { |
| | | //可能设备没有上报给云端,建议绑定逆变器时候追加一个参数; |
| | | gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//设备型号 |
| | | } |
| | | gatewayBean.setSpk(cloudInverterDeviceBean.getSpk());//设备spk |
| | | |
| | | |