| | |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlhttp.HxHttp; |
| | | import com.hdl.linkpm.sdk.core.api.HDLCloudHomeApi; |
| | | import com.hdl.linkpm.sdk.core.callback.IResponseCallBack; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.core.response.HDLResponse; |
| | | import com.hdl.linkpm.sdk.device.bean.FunctionInfoBean; |
| | | import com.hdl.linkpm.sdk.utils.HDLExceptionSubmitUtils; |
| | | import com.hdl.photovoltaic.bean.HttpResponsePack; |
| | | import com.hdl.photovoltaic.bean.LocalResponse; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | | import com.hdl.photovoltaic.internet.TcpClient; |
| | | import com.hdl.photovoltaic.internet.api.HttpApi; |
| | | import com.hdl.photovoltaic.internet.api.TopicApi; |
| | | import com.hdl.photovoltaic.listener.BaseSuccessFailureCallBeak; |
| | | import com.hdl.photovoltaic.listener.CloudCallBeak; |
| | | 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.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.ui.bean.InverterDeviceBean; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceTimeBean; |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkCode; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.bean.request.BaseLocalRequest; |
| | | 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 java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import io.reactivex.rxjava3.disposables.Disposable; |
| | | |
| | | |
| | | /** |
| | |
| | | if (TextUtils.isEmpty(gatewayBean.getDevice_mac())) { |
| | | continue; |
| | | } |
| | | if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) |
| | | && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | if (gatewayBean.getMaster().equals(GatewayMasterType.MasterTrue) && gatewayBean.getHomeId().equals(UserConfigManage.getInstance().getHomeId())) { |
| | | newList.add(gatewayBean); |
| | | } |
| | | } |
| | |
| | | return newList; |
| | | } |
| | | |
| | | /** |
| | | * 逆变器上传数据到云端(包括:sid,oid) |
| | | * |
| | | * @param mac 设备mac |
| | | */ |
| | | public void uploadDataToCloud(String mac, CloudCallBeak<Boolean> callBeak) { |
| | | getInverterOidList(mac, new LinkCallBack<List<OidBean>>() { |
| | | @Override |
| | | public void onSuccess(List<OidBean> obj) { |
| | | if (obj == null) { |
| | | return; |
| | | } |
| | | fullUpdateOid(obj, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 添加逆变器到云端上 |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | //临时的逻辑,上传oid列表到云端 |
| | | getGatewayOidList(mac, new LinkCallBack<List<OidBean>>() { |
| | | @Override |
| | | public void onSuccess(List<OidBean> obj) { |
| | | if (obj == null) { |
| | | return; |
| | | } |
| | | fullUpdateOid(obj, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | |
| | | } |
| | | }); |
| | | uploadDataToCloud(mac, null); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * 删除逆变器 |
| | | * 删除云端上逆变器 |
| | | * |
| | | * @param deviceId 设备id |
| | | * @param cloudCallBeak 回调 |
| | |
| | | * @param mac 设备mac |
| | | * @param linkCallBack 回调update |
| | | */ |
| | | public void getGatewayTime(String mac, LinkCallBack<Boolean> linkCallBack) { |
| | | public void getGatewayTime(String mac, LinkCallBack<DeviceTimeBean> linkCallBack) { |
| | | String requestUrl = TopicApi.GET_GATEWAY_TIME; |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | public void onSuccess(String json) { |
| | | |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onSuccess(new DeviceTimeBean()); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<BaseLocalResponse<DeviceTimeBean>>() { |
| | | }.getType(); |
| | | BaseLocalResponse<DeviceTimeBean> baseLocalResponse = gson.fromJson(json, typeOfT); |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onSuccess(true); |
| | | linkCallBack.onSuccess(baseLocalResponse.getObjects()); |
| | | } |
| | | } |
| | | |
| | |
| | | * 网关时间修改 |
| | | * |
| | | * @param mac 设备mac |
| | | * @param date 日期 |
| | | * @param time 时间 |
| | | * @param linkCallBack 回调update |
| | | */ |
| | | public void editGatewayTime(String mac, JsonObject jsonObject, LinkCallBack<Boolean> linkCallBack) { |
| | | public void editGatewayTime(String mac, String date, String time, LinkCallBack<Boolean> linkCallBack) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_TIME_EDIT; |
| | | // JsonObject json = new JsonObject(); |
| | | // json.addProperty("master", "true"); |
| | | // "objects": { |
| | | // "date": "2020-08-15", |
| | | // "time": "17:25:20" |
| | | // } |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, jsonObject, "", new HDLLinkCallBack() { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("date", date);// "2020-08-15" |
| | | json.addProperty("time", time);//"17:25:20" |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | if (linkCallBack != null) { |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取网关oid列表 |
| | | * 获取逆变器oid列表 |
| | | * |
| | | * @param mac 网关mac |
| | | * @param linkCallBack 回调 |
| | | */ |
| | | public void getGatewayOidList(String mac, LinkCallBack<List<OidBean>> linkCallBack) { |
| | | public void getInverterOidList(String mac, LinkCallBack<List<OidBean>> linkCallBack) { |
| | | String requestUrl = TopicApi.GET_GATEWAY_OID_LIST; |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { |
| | | @Override |
| | |
| | | } |
| | | for (int i = 0; i < removeSidList.size(); i++) { |
| | | //删除本地的逆变器 |
| | | removeInverter(removeSidList.get(i)); |
| | | removeLocalInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | |
| | | } |
| | | for (int i = 0; i < removeSidList.size(); i++) { |
| | | //删除本地的逆变器 |
| | | removeInverter(removeSidList.get(i)); |
| | | removeLocalInverter(removeSidList.get(i)); |
| | | } |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList()); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 删除本地逆变器 |
| | | * 删除本地缓存逆变器 |
| | | * |
| | | * @param sid 设备sid |
| | | */ |
| | | private void removeInverter(String sid) { |
| | | private void removeLocalInverter(String sid) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(sid); |
| | | if (gatewayBean != null) { |
| | | HDLLinkLocalGateway.getInstance().getGatewayList().remove(gatewayBean); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 清空逆变器住宅id |
| | | * |
| | | * @param mac mac |
| | | */ |
| | | public void clearInverterHomeId(String mac, LinkCallBack<Boolean> callBeak) { |
| | | String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", ""); |
| | | json.addProperty("server_addr", ""); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, true, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); |
| | | if (gatewayBean != null) { |
| | | if (!TextUtils.isEmpty(UserConfigManage.getInstance().getLocalSecret())) { |
| | | gatewayBean.setLocalEncrypt(true); |
| | | } |
| | | } |
| | | if (callBeak != null) { |
| | | callBeak.onSuccess(true); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | if (callBeak != null) { |
| | | callBeak.onError(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | //网关搜索 |
| | | HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新逆变器缓存信息(包括设置mqtt秘钥) |
| | |
| | | gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//子网号/设备号 |
| | | gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//发电功率 |
| | | gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//今日发电量 |
| | | gatewayBean.setDevice_model(cloudInverterDeviceBean.getOmodel());//设备型号 |
| | | gatewayBean.setSpk(cloudInverterDeviceBean.getSpk());//设备spk |
| | | |
| | | |
| | | } |
| | | |