From 70c1ba24af27ba64e1d9ad50eb722541212ed8b6 Mon Sep 17 00:00:00 2001 From: wjc <1243177876@qq.com> Date: 星期五, 30 六月 2023 17:26:54 +0800 Subject: [PATCH] 2023年06月30日17:26:51 --- app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java | 209 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 186 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java index c16a5ad..a5f0327 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlDeviceLogic.java @@ -1,22 +1,39 @@ package com.hdl.photovoltaic.other; +import android.text.TextUtils; + import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.reflect.TypeToken; +import com.hdl.hdlhttp.HxHttp; import com.hdl.photovoltaic.bean.HttpResponsePack; +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.ui.bean.CloudInverterChildDeviceBean; import com.hdl.photovoltaic.ui.bean.CloudInverterDeviceBean; import com.hdl.photovoltaic.ui.bean.InverterDeviceBean; 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.callback.GatewayCallBack; +import com.hdl.sdk.link.core.callback.HDLLinkCallBack; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import java.lang.reflect.Type; +import java.util.ArrayList; import java.util.List; + +import io.reactivex.rxjava3.disposables.Disposable; /** * 璁惧閫昏緫鐨勭晫闈� @@ -42,20 +59,25 @@ } /** - * 娣诲姞閫嗗彉鍣� + * 娣诲姞閫嗗彉鍣ㄥ埌浜戠涓� * - * @param inverterDeviceBean 閫嗗彉鍣ㄥ璞� - * @param cloudCallBeak 鍥炶皟 + * @param mac - + * @param spk - + * @param sid - + * @param oid - + * @param name - + * @param cloudCallBeak */ - public void addInverterDevice(InverterDeviceBean inverterDeviceBean, CloudCallBeak<Boolean> cloudCallBeak) { + public void addInverterDeviceToCloud(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("mac", inverterDeviceBean.getDevice_mac()); - json.addProperty("spk", inverterDeviceBean.getGateway_type()); - json.addProperty("sid", inverterDeviceBean.getSid()); - json.addProperty("oid", inverterDeviceBean.getOid()); - json.addProperty("name", inverterDeviceBean.getDevice_name()); + json.addProperty("mac", mac); + json.addProperty("spk", spk); + json.addProperty("sid", sid); + json.addProperty("oid", oid); + json.addProperty("name", name); // json.addProperty("zoneType", "password");//鍖哄煙 HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { @@ -76,34 +98,42 @@ } /** - * 鑾峰彇閫嗗彉鍣ㄥ垪琛� + * 鑾峰彇浜戠閫嗗彉鍣ㄥ垪琛� * - * @param inverterDeviceBean 閫嗗彉鍣ㄥ璞� - * @param cloudCallBeak 鍥炶皟 + * @param homeId 浣忓畢id + * @param cloudCallBeak 鍥炶皟 */ - public void getInverterDeviceList(InverterDeviceBean inverterDeviceBean, CloudCallBeak<CloudInverterDeviceBean> cloudCallBeak) { + public void getCloudInverterDeviceList(String homeId, CloudCallBeak<List<CloudInverterDeviceBean>> cloudCallBeak) { String requestUrl = HttpApi.POST_Device_List; JsonObject json = new JsonObject(); - json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); + json.addProperty("homeId", homeId); // json.addProperty("zoneType", "password");//鍖哄煙 HttpClient.getInstance().requestHttp(requestUrl, json.toString(), true, true, new BaseSuccessFailureCallBeak() { @Override public void onSuccess(HttpResponsePack httpResponsePack) { - if (httpResponsePack != null && httpResponsePack.getData() != null) { - Gson gson = new Gson(); - String json = gson.toJson(httpResponsePack.getData()); - CloudInverterDeviceBean loginUserRegionBean = new Gson().fromJson(json, CloudInverterDeviceBean.class); + try { + if (httpResponsePack != null && httpResponsePack.getData() != null) { + Gson gson = new Gson(); + String json = gson.toJson(httpResponsePack.getData()); + Type type = new TypeToken<List<CloudInverterDeviceBean>>() { + }.getType(); + List<CloudInverterDeviceBean> list = new Gson().fromJson(json, type); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } + } catch (Exception e) { if (cloudCallBeak != null) { - cloudCallBeak.onSuccess(loginUserRegionBean); + cloudCallBeak.onFailure(e); } } } @Override - public void onFailure(Exception exception) { + public void onFailure(Exception e) { if (cloudCallBeak != null) { - cloudCallBeak.onFailure(exception); + cloudCallBeak.onFailure(e); } } }); @@ -180,9 +210,9 @@ * 鍏ㄩ噺鏇存柊OID * * @param oidList oid鍒楄〃 - * @param cloudCallBeak 鍥炶皟 + * @param cloudCallBeak 鍥炶皟update */ - public void fullRenewalOid(List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { + public void fullUpdateOid(List<OidBean> oidList, CloudCallBeak<Boolean> cloudCallBeak) { String requestUrl = HttpApi.POST_Device_ChildDevices_List; JsonObject json = new JsonObject(); json.addProperty("operationSource", "PROGRAM_ENERGY");// @@ -222,6 +252,139 @@ } } }); + } + + /** + * 璁剧疆缃戝叧杩滅▼鍙傛暟 + * + * @param mac 璁惧mac + * @param cloudCallBeak 鍥炶皟update + */ + public void steGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) { + String requestUrl = TopicApi.SET_GATEWAY_REMOTE_EDIT; + JsonObject json = new JsonObject(); + json.addProperty("homeId", UserConfigManage.getInstance().getHomeId()); + json.addProperty("server_addr", AppConfigManage.getUserRegionUrl()); + json.addProperty("local_secret", UserConfigManage.getInstance().getLocalSecret()); + //瑙e瘑璐熻浇鏁版嵁(鍥犱负鍐欏瘑閽ョ粰缃戝叧涓�瀹氭槑鏂囷紝鍥犱负閭f椂缃戝叧杩樻病鏈夊瘑閽�) + TcpClient.getInstance().sendDataToLinkGateway(mac, false, 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 (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + + } + + @Override + public void onError(HDLLinkException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + } + + /** + * 缂栬緫缃戝叧鍙傛暟 + * + * @param mac 璁惧mac + * @param cloudCallBeak 鍥炶皟update + */ + public void editGatewayParam(String mac, CloudCallBeak<Boolean> cloudCallBeak) { + String requestUrl = TopicApi.SET_GATEWAY_EDIT; + JsonObject json = new JsonObject(); + json.addProperty("master", "true"); + TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, json, "", new HDLLinkCallBack() { + @Override + public void onSuccess(String msg) { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(true); + } + } + + @Override + public void onError(HDLLinkException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + + } + + /** + * 鑾峰彇缃戝叧oid鍒楄〃 + * + * @param mac 缃戝叧mac + * @param cloudCallBeak 鍥炶皟 + */ + public void getGatewayOidList(String mac, CloudCallBeak<List<OidBean>> cloudCallBeak) { + String requestUrl = TopicApi.GET_GATEWAY_OID_LIST; + TcpClient.getInstance().sendDataToLinkGateway(mac, requestUrl, null, "", new HDLLinkCallBack() { + @Override + public void onSuccess(String msg) { + try { + if (!TextUtils.isEmpty(msg)) { + Gson gson = new Gson(); + String json = gson.toJson(msg); + Type typeOfT = new TypeToken<List<OidBean>>() { + }.getType(); + List<OidBean> list = gson.fromJson(json, typeOfT); + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(list); + } + } else { + if (cloudCallBeak != null) { + cloudCallBeak.onSuccess(new ArrayList<>()); + } + } + + } catch (Exception e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + } + + @Override + public void onError(HDLLinkException e) { + if (cloudCallBeak != null) { + cloudCallBeak.onFailure(e); + } + } + }); + + } + + + /** + * 鎼滅储缃戝叧鍒楄〃 + * + * @param gatewayCallBack - + */ + public void searchGateway(GatewayCallBack gatewayCallBack) { + List<String> spks = this.getGatewaySpk(); + //缃戝叧鎼滅储 + HDLLinkLocalGateway.getInstance().refreshGatewayByHomeIdAndSpk(UserConfigManage.getInstance().getHomeId(), spks, true, gatewayCallBack); + } + + /** + * 鑾峰彇缃戝叧spk鍒楄〃 + * + * @return - + */ + private List<String> getGatewaySpk() { + List<String> spks = new ArrayList<>(); + spks.add("energy.hdl_inverter"); + return spks; + } } -- Gitblit v1.8.0