| | |
| | | import android.os.SystemClock; |
| | | import android.text.TextUtils; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.annotation.Nullable; |
| | | |
| | | 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.DeviceInfoBean; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceRemoteInfo; |
| | | import com.hdl.photovoltaic.ui.bean.DeviceTimeBean; |
| | | import com.hdl.photovoltaic.ui.bean.NotRunBean; |
| | | import com.hdl.photovoltaic.ui.bean.OidBean; |
| | | import com.hdl.sdk.link.common.exception.HDLLinkException; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | | import com.hdl.sdk.link.gateway.type.GatewayMasterType; |
| | | import com.huawei.hms.support.api.entity.core.JosBaseReq; |
| | | |
| | | |
| | | import java.lang.reflect.Type; |
| | |
| | | |
| | | @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 getGatewayInfo(String mac, LinkCallBack<GatewayBean> linkCallBack) { |
| | | String requestUrl = TopicApi.GET_GATEWAY_INFO; |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("device_mac", mac); |
| | | TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String json) { |
| | | if (TextUtils.isEmpty(json)) { |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onSuccess(null); |
| | | } |
| | | if (linkCallBack == null) { |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | GatewayBean gatewayBean = gson.fromJson(json, GatewayBean.class); |
| | | if (linkCallBack != null) { |
| | | linkCallBack.onSuccess(gatewayBean); |
| | | if (TextUtils.isEmpty(json)) { |
| | | linkCallBack.onSuccess(null); |
| | | return; |
| | | } |
| | | |
| | | Gson gson = new Gson(); |
| | | Type typeOfT = new TypeToken<BaseLocalResponse<GatewayBean>>() { |
| | | }.getType(); |
| | | BaseLocalResponse<GatewayBean> baseLocalResponse = gson.fromJson(json, typeOfT); |
| | | if (baseLocalResponse == null || baseLocalResponse.getObjects() == null) { |
| | | linkCallBack.onSuccess(new GatewayBean()); |
| | | } else { |
| | | linkCallBack.onSuccess(baseLocalResponse.getObjects()); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | /** |
| | | * 获取逆变器列表(整合云端和本地列表) |
| | | * 注意:有外网,以云端设备为准,本地存在,云端没有则删除;内网,以本地为主,搜索多少个设备就显示多少个; |
| | | * 注意:有外网,以云端设备为准,本地存在,云端没有则删除;否则,没有外网只有局域网,以本地为主,搜索多少个设备就显示多少个 |
| | | * |
| | | * @param homeId 住宅id |
| | | * @param cloudCallBeak 返回逆变器列表 |
| | |
| | | HdlDeviceLogic.getInstance().getCloudInverterDeviceList(homeId, new CloudCallBeak<List<CloudInverterDeviceBean>>() { |
| | | @Override |
| | | public void onSuccess(List<CloudInverterDeviceBean> list) { |
| | | ///情况1:有局域网,有外网; |
| | | 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)); |
| | | } |
| | | //情况1:有局域网,有外网; |
| | | setDeviceRemoteInfo(list, homeId, cloudCallBeak); |
| | | } |
| | | |
| | |
| | | |
| | | |
| | | /** |
| | | * 获取未运行逆变器列表 |
| | | * |
| | | * @param homeId 电站id |
| | | */ |
| | | public void getListNotRun(String homeId, CloudCallBeak<List<NotRunBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_listNotRun; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | |
| | | 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 ArrayList<>()); |
| | | } |
| | | } |
| | | Type type = new TypeToken<List<NotRunBean>>() { |
| | | }.getType(); |
| | | List<NotRunBean> list = new Gson().fromJson(jsonStr, type); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 逆变器开机 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param arrayList 设备id数组 |
| | | */ |
| | | public void setDeviceStartup(String homeId, JsonArray arrayList, CloudCallBeak<Boolean> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_startup; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.add("deviceIds", arrayList); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | |
| | | HttpClient.getInstance().requestHttp(requestUrl, json.toString(), new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String jsonStr) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 获取设备详情 |
| | | * |
| | | * @param homeId 电站id |
| | | * @param arrayList 设备id数组 |
| | | */ |
| | | public void getDeviceInfo(String homeId, JsonArray arrayList, CloudCallBeak<List<DeviceInfoBean>> cloudCallBeak) { |
| | | String requestUrl = HttpApi.POST_Device_info; |
| | | JsonObject json = new JsonObject(); |
| | | json.addProperty("homeId", homeId); |
| | | json.add("deviceIds", arrayList); |
| | | // json.addProperty("zoneType", "password");//区域 |
| | | |
| | | 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 ArrayList<>()); |
| | | } |
| | | return; |
| | | } |
| | | Gson gson = new Gson(); |
| | | List<DeviceInfoBean> list = gson.fromJson(jsonStr, new TypeToken<List<DeviceInfoBean>>() { |
| | | }.getType()); |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onSuccess(list); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 刷新逆变器缓存信息(包括设置mqtt秘钥) |
| | | * 注: //目的是为了获取拿到网关ID,mqtt通讯秘钥等信息,缓存本地逆变器列表里面,发送数据数据时自动去缓存列表里面去查找; |
| | | * 1:本地存在,更新信息即可; |
| | |
| | | HDLLinkConfig.getInstance().setGatewayId(deviceRemoteInfo.getGatewayId());//设置gatewayId |
| | | |
| | | } |
| | | |
| | | gatewayBean.setHomeId(homeId);//住宅id |
| | | gatewayBean.setDeviceStatus(cloudInverterDeviceBean.getDeviceStatus());//设置网关状态 |
| | | gatewayBean.setDeviceStatus(cloudInverterDeviceBean.getDeviceStatus());//设置网关状态(1 : 连接中,2 : 故障, 3 : 运行,4 : 离线) |
| | | gatewayBean.setDeviceId(cloudInverterDeviceBean.getDeviceId());//设置link设备id |
| | | gatewayBean.setDevice_mac(cloudInverterDeviceBean.getOsn());//设置mac |
| | | gatewayBean.setOid(cloudInverterDeviceBean.getOid());//设备oid |
| | |
| | | gatewayBean.setDeviceType(cloudInverterDeviceBean.getDeviceType());//设备类型(INV:逆变器;BMS:BMS控制盒;BATTERY:电池单元) |
| | | gatewayBean.setAddresses(cloudInverterDeviceBean.getAddresses());//子网号/设备号,逆变器地址 |
| | | gatewayBean.setPowerPvNow(cloudInverterDeviceBean.getPowerPvNow());//发电功率 |
| | | gatewayBean.setOutputActivePower(cloudInverterDeviceBean.getOutputActivePower());//逆变器输出有功功率 |
| | | gatewayBean.setTotalElectricityPvToday(cloudInverterDeviceBean.getTotalElectricityPvToday());//今日发电量 |
| | | if (!TextUtils.isEmpty(cloudInverterDeviceBean.getOmodel())) { |
| | | //可能设备没有上报给云端,建议绑定逆变器时候追加一个参数; |