| | |
| | | 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.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.photovoltaic.ui.bean.StatusOverviewBean; |
| | | 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; |
| | | |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | |
| | | } |
| | | |
| | | |
| | | private List<DeviceBean> mListDevice = new ArrayList<>(); |
| | | private List<CloudInverterDeviceBean> mListDevice = new ArrayList<>(); |
| | | |
| | | |
| | | public void clearDeviceList() { |
| | |
| | | } |
| | | } |
| | | |
| | | public List<DeviceBean> getDeviceList() { |
| | | public List<CloudInverterDeviceBean> getDeviceList() { |
| | | if (mListDevice == null) { |
| | | return new ArrayList<>(); |
| | | } |
| | |
| | | * @param pageNo 页码 |
| | | * @param pageSize 页数 |
| | | */ |
| | | public void getPowerStationDeviceList(String searchTxt, long pageNo, long pageSize, CloudCallBeak<PageNumberObject<DeviceBean>> cloudCallBeak) { |
| | | 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)) { |
| | |
| | | } |
| | | } |
| | | Gson gson = new Gson(); |
| | | Type type = new TypeToken<PageNumberObject<DeviceBean>>() { |
| | | Type type = new TypeToken<PageNumberObject<CloudInverterDeviceBean>>() { |
| | | }.getType(); |
| | | PageNumberObject<DeviceBean> pageNumberObject = gson.fromJson(jsonStr, type); |
| | | PageNumberObject<CloudInverterDeviceBean> pageNumberObject = gson.fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(pageNumberObject); |
| | | } |
| | |
| | | * |
| | | * @param list -设备列表 |
| | | */ |
| | | public void setListDevice(List<DeviceBean> list) { |
| | | public void setListDevice(List<CloudInverterDeviceBean> list) { |
| | | try { |
| | | if (list == null || list.size() == 0) { |
| | | return; |
| | |
| | | * |
| | | * @param deviceBean -设备对象 |
| | | */ |
| | | public void setSingleDevice(DeviceBean deviceBean) { |
| | | public void setSingleDevice(CloudInverterDeviceBean deviceBean) { |
| | | try { |
| | | if (deviceBean == null) { |
| | | return; |
| | |
| | | @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); |
| | |
| | | |
| | | /** |
| | | * 刷新逆变器缓存信息(包括设置mqtt秘钥) |
| | | * 注: |
| | | * 注: //目的是为了获取拿到网关ID,mqtt通讯秘钥等信息,缓存本地逆变器列表里面,发送数据数据时自动去缓存列表里面去查找; |
| | | * 1:本地存在,更新信息即可; |
| | | * 2:本地不存在,则虚拟一个逆变器对象添加在本地; |
| | | * |