From 32b5f366ceaad4aa9a33eccf0b109eef24175495 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 10 十月 2023 14:55:01 +0800 Subject: [PATCH] 2023年10月10日14:54:56 --- app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java | 181 +++++++++++++++++++++++++++++++++++++++----- 1 files changed, 159 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java index 18cc579..491e3f0 100644 --- a/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java +++ b/app/src/main/java/com/hdl/photovoltaic/other/HdlUniLogic.java @@ -1,34 +1,37 @@ package com.hdl.photovoltaic.other; -import android.content.Intent; import android.text.TextUtils; +import android.util.Log; -import com.alibaba.fastjson.JSON; import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.hdl.linkpm.sdk.core.exception.HDLException; import com.hdl.photovoltaic.HDLApp; import com.hdl.photovoltaic.bean.BaseEventBus; import com.hdl.photovoltaic.bean.ModBusBean; import com.hdl.photovoltaic.config.ConstantManage; import com.hdl.photovoltaic.config.UserConfigManage; import com.hdl.photovoltaic.listener.CloudCallBeak; -import com.hdl.photovoltaic.ui.bean.HouseIdBean; +import com.hdl.photovoltaic.listener.LinkCallBack; +import com.hdl.photovoltaic.ui.bean.OidBean; import com.hdl.photovoltaic.uni.HDLUniMP; import com.hdl.photovoltaic.uni.HDLUniMPSDKManager; -import com.hdl.photovoltaic.uni.UniToAndroidBean; import com.hdl.photovoltaic.utils.WifiUtils; import com.hdl.sdk.link.common.exception.HDLLinkCode; import com.hdl.sdk.link.common.exception.HDLLinkException; -import com.hdl.sdk.link.common.utils.LogUtils; import com.hdl.sdk.link.core.bean.gateway.GatewayBean; import com.hdl.sdk.link.core.callback.GatewayCallBack; import com.hdl.sdk.link.core.callback.ModbusCallBack; import com.hdl.sdk.link.core.connect.HDLModBusConnect; +import com.hdl.sdk.link.core.utils.mqtt.MqttRecvClient; +import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; import org.greenrobot.eventbus.EventBus; import org.json.JSONObject; +import java.util.Arrays; import java.util.List; import io.dcloud.feature.unimp.DCUniMPJSCallback; @@ -56,7 +59,7 @@ return sHdlUniLogic; } - //region ******銆愬師鐢熴�戝拰銆愬皬绋嬪簭銆戦�氳鐨勬柟娉� onOtherUniMPEventReceive();openUniMP();sendUni();****** + //region ******銆愬師鐢熴�戝拰銆愬皬绋嬪簭銆戦�氳鐨�3涓柟娉曞悕 onOtherUniMPEventReceive();openUniMP();sendUni();****** /** * 鍘熺敓鎺ユ敹鍒皍ni鍙戞潵鐨勬暟鎹� @@ -76,16 +79,28 @@ if (HDLUniMP.UNI_EVENT_REPLY_HOME_MODEL.equals(event)) { //浣忓畢妯″潡 switch (type) { + //鍒涘缓鐢电珯 case HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION: { - //鍒涘缓 + //EventBus浜嬩欢鍒嗗彂 BaseEventBus baseEventBus = new BaseEventBus(); - baseEventBus.setType(ConstantManage.EVENTBUS_POST_HOME_CREATED); + baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CREATION); + baseEventBus.setData(getKeyValue("data", data)); EventBus.getDefault().post(baseEventBus); } break; + //璇诲彇璇︽儏 case HDLUniMP.UNI_EVENT_REPLY_HOME_DETAILS: { - //璇︽儏 + + } + break; + //鍏抽棴璇︽儏椤� + case HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE: { + //EventBus浜嬩欢鍒嗗彂 + BaseEventBus baseEventBus = new BaseEventBus(); + baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_HOME_CLOSE_HOME_DETAILS_PAGE); + baseEventBus.setData(getKeyValue("data", data)); + EventBus.getDefault().post(baseEventBus); } break; @@ -96,13 +111,56 @@ } else if (HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODEL.equals(event)) { //璁惧妯″潡 switch (type) { + //娣诲姞閫嗗彉鍣ㄥ埌浜戠 case HDLUniMP.UNI_EVENT_REPLY_DEVICE_ADD: { - //娣诲姞 + String mac = getKeyValue("mac", getKeyValue("data", data)); + HdlDeviceLogic.getInstance().setGatewayRemoteParam(mac, new LinkCallBack<Boolean>() { + @Override + public void onSuccess(Boolean obj) { + HdlDeviceLogic.getInstance().editGatewayParam(mac, new LinkCallBack<Boolean>() { + @Override + public void onSuccess(Boolean obj) { + GatewayBean gatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(mac); + if (gatewayBean == null) { + uniCallbackData(null, -100, "鏈湴鎵句笉鍒扮綉鍏�", callback); + return; + } + HdlDeviceLogic.getInstance().addInverterDeviceToCloud(mac, + gatewayBean.getGatewayType(), + gatewayBean.getSid(), + gatewayBean.getOid(), + gatewayBean.getDevice_name(), + new CloudCallBeak<Boolean>() { + @Override + public void onSuccess(Boolean obj) { + uniCallbackData(null, callback); + } + + @Override + public void onFailure(HDLException e) { + uniCallbackData(null, -100, e.getMessage(), callback); + } + }); + } + + @Override + public void onError(HDLLinkException e) { + uniCallbackData(null, -100, e.getMessage(), callback); + } + }); + } + + @Override + public void onError(HDLLinkException e) { + uniCallbackData(null, -100, e.getMessage(), callback); + } + }); + } break; - case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: { - //缃戝叧鎼滅储 + //灞�鍩熺綉鎼滅储閫嗗彉鍣ㄥ垪琛� + case HDLUniMP.UNI_EVENT_REPLY_DEVICE_NET_LIST: { HdlDeviceLogic.getInstance().searchGateway(new GatewayCallBack() { @Override public void onSuccess(List<GatewayBean> gatewayBeanList) { @@ -117,31 +175,100 @@ }); } break; + //鑾峰彇閫嗗彉鍣ㄥ垪琛� + case HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST: { + HdlDeviceLogic.getInstance().getCurrentHomeLocalAndCloudGatewayList(new CloudCallBeak<List<GatewayBean>>() { + @Override + public void onSuccess(List<GatewayBean> list) { + if (callback != null) { + uniCallbackData(list, callback); + //EventBus浜嬩欢鍒嗗彂 + BaseEventBus baseEventBus = new BaseEventBus(); + baseEventBus.setType(HDLUniMP.UNI_EVENT_REPLY_DEVICE_LIST); + baseEventBus.setData(list); + EventBus.getDefault().post(baseEventBus); + } + } + + @Override + public void onFailure(HDLException e) { + if (callback != null) { + uniCallbackData(null, -2, e.getMessage(), callback); + } + } + }); + } + break; case HDLUniMP.UNI_EVENT_REPLY_DEVICE_MODBUS_SEND: { sendModBus(data, callback); + } + break; + //鑾峰彇oid鍒楄〃 + case HDLUniMP.UNI_EVENT_REPLY_DEVICE_OID: { + + String mac = getKeyValue("mac", getKeyValue("data", data)); + HdlDeviceLogic.getInstance().getGatewayOidList(mac, new LinkCallBack<List<OidBean>>() { + @Override + public void onSuccess(List<OidBean> list) { + if (callback != null) { + uniCallbackData(list, callback); + } + } + + @Override + public void onError(HDLLinkException e) { + uniCallbackData(null, -2, e.getMsg(), callback); + } + }); + } + break; + //閫嗗彉鍣ㄦ椂闂磋鍙� + case HDLUniMP.UNI_EVENT_REPLY_DEVICE_TIME: { + String mac = getKeyValue("mac", getKeyValue("data", data)); + HdlDeviceLogic.getInstance().getGatewayTime(mac, new LinkCallBack<Boolean>() { + @Override + public void onSuccess(Boolean obj) { + + } + + @Override + public void onError(HDLLinkException e) { + + } + }); + } + break; + //閫嗗彉鍣ㄦ椂闂寸紪杈� + case HDLUniMP.UNI_EVENT_REPLY_DEVICE_TIME_EDIT: { + String mac = getKeyValue("mac", getKeyValue("data", data)); + HdlDeviceLogic.getInstance().editGatewayTime(mac, new JsonObject(), null); + } + break; + } } else if (HDLUniMP.UNI_EVENT_REPLY_WIFI_MODEL.equals(event)) { WifiUtils wifiUtils = new WifiUtils(HDLApp.getInstance()); //wifi妯″潡 switch (type) { + //鑾峰彇wifi鍒楄〃 case HDLUniMP.UNI_EVENT_REPLY_WIFI_LIST: { - //鑾峰彇wifi鍒楄〃 if (callback != null) { uniCallbackData(wifiUtils.getScanResult(), callback); } } break; + //褰撳墠wifi璇︽儏 case HDLUniMP.UNI_EVENT_REPLY_WIFI_INFO: { - //褰撳墠wifi璇︽儏 if (callback != null) { uniCallbackData(wifiUtils.getCurrentConnectWifiInfo(), callback); } } break; + //wifi杩炴帴 case HDLUniMP.UNI_EVENT_REPLY_WIFI_CONNECT: { - //wifi杩炴帴 + } break; @@ -162,23 +289,28 @@ */ void sendModBus(Object data, DCUniMPJSCallback callback) { String tempData = getKeyValue("data", data); - if (tempData == null) { - LogUtils.i("data鍐呭涓虹┖"); + if (TextUtils.isEmpty(tempData)) { + HdlLogLogic.print("data鍐呭涓虹┖"); return; } - ModBusBean modBusBean = com.alibaba.fastjson.JSONObject.parseObject(JSON.toJSONString(tempData), ModBusBean.class); + ModBusBean modBusBean = new Gson().fromJson(tempData, ModBusBean.class); // ModBusBean modBusBean = new ModBusBean(); // modBusBean.setOid("0101050219D44A00"); // modBusBean.setData(new byte[]{00,01,00,00,00,0x09,00,00,00,01,03,00,00,00,01}); - if (modBusBean.getOid() == null || modBusBean.getData() == null) { - LogUtils.i("鍐呭涓虹┖,oid=" + modBusBean.getOid() + " data=" + modBusBean.getData()); +// if (TextUtils.isEmpty(modBusBean.getOid())) { +// modBusBean.setOid("0101050217BBC400"); +// } + if (modBusBean.getMac() == null || modBusBean.getData() == null) { + HdlLogLogic.print("鍐呭涓虹┖,oid=" + modBusBean.getMac() + " data=" + modBusBean.getData()); return; } + //鍙戦�乵odbus鍗忚 - HDLModBusConnect.getInstance().Send(modBusBean.getOid(), modBusBean.getData(), new ModbusCallBack() { + HDLModBusConnect.getInstance().Send(modBusBean.getMac(), modBusBean.getData(), new ModbusCallBack() { @Override - public void onSuccess(byte[] data) { + public void onSuccess(int[] data) { + Log.d("data", Arrays.toString(data)); uniCallbackData(data, callback); } @@ -271,6 +403,8 @@ uniCallBackBaseBean.setData(obj); if (callback != null) { callback.invoke(getJSONObject(uniCallBackBaseBean)); +// callback.invoke(uniCallBackBaseBean); + } } catch (Exception e) { HdlLogLogic.print("uni===缁勮uni鍙戦�佹暟鎹牸寮�", e.getMessage()); @@ -296,6 +430,9 @@ if (TextUtils.isEmpty(obj.toString())) { return new JSONObject(); } + if (obj.toString().startsWith("{") && obj.toString().endsWith("}")) { + return new JSONObject(obj.toString()); + } if (obj instanceof JSONObject) { return (JSONObject) obj; } -- Gitblit v1.8.0