| | |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.linkpm.sdk.core.exception.HDLException; |
| | | import com.hdl.linkpm.sdk.home.type.GatewayType; |
| | | import com.hdl.photovoltaic.config.AppConfigManage; |
| | | import com.hdl.photovoltaic.config.UserConfigManage; |
| | | import com.hdl.photovoltaic.internet.HttpClient; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | | import io.dcloud.common.adapter.util.DeviceInfo; |
| | | |
| | | |
| | | /** |
| | |
| | | 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) { |
| | | public void onSuccess(List<OidBean> oidBeanList) { |
| | | if (oidBeanList == null) { |
| | | return; |
| | | } |
| | | fullUpdateOid(homeId, obj, new CloudCallBeak<Boolean>() { |
| | | fullUpdateOid(homeId, oidBeanList, new CloudCallBeak<Boolean>() { |
| | | @Override |
| | | public void onSuccess(Boolean obj) { |
| | | HdlLogLogic.print("上传oid列表到云端成功-->" + homeId + "--->" + mac, true); |
| | | HdlLogLogic.print("上传oid列表到云端成功--->住宅id:" + homeId + "--->mac:" + mac, true); |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | HdlLogLogic.print("上传oid列表到云端失败-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("上传oid列表到云端失败--->住宅id:" + homeId + "--->mac:" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | HdlLogLogic.print("获取逆变器oid列表失败-->" + homeId + "--->" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | HdlLogLogic.print("获取逆变器oid列表失败--->住宅id:" + homeId + "--->mac:" + mac + "-->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | json.addProperty("sid", sid); |
| | | json.addProperty("oid", oid); |
| | | json.addProperty("name", name); |
| | | // 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列表到云端 |
| | | uploadDataToCloud(UserConfigManage.getInstance().getHomeId(), mac, null); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 添加多个逆变器到云端上 |
| | | * |
| | | * @param mac - |
| | | * @param cloudCallBeak - |
| | | */ |
| | | public void addAllInverterDeviceToCloud(String homeId, String mac, 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>() { |
| | |
| | | cloudCallBeak.onSuccess(true); |
| | | } |
| | | |
| | | HdlLogLogic.print("全量更新oid到云端成功--->", true); |
| | | |
| | | } |
| | | |
| | |
| | | if (cloudCallBeak != null) { |
| | | cloudCallBeak.onFailure(e); |
| | | } |
| | | HdlLogLogic.print("全量更新oid到云端失败--->" + e.getMsg() + "(" + e.getCode() + ")", true); |
| | | } |
| | | }); |
| | | |
| | |
| | | * 网关时间读取 |
| | | * |
| | | * @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) { |
| | |
| | | cloudCallBeak.onSuccess(getCurrentHomeGatewayList(homeId)); |
| | | } |
| | | } |
| | | HdlLogLogic.print("获取设备远程通讯信息失败->msg->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | HdlLogLogic.print("获取设备远程通讯信息失败--->msg--->" + e.getMsg() + "(" + e.getCode() + ")"); |
| | | } |
| | | }); |
| | | } |
| | |
| | | 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) { |
| | | //网关搜索 |
| | | HDLLinkLocalSdk.getInstance().refreshGateway(gatewayCallBack, this.getGatewaySpk()); |
| | | } |