From 4a42989853dd83c0519d0684383430006b7e9625 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期二, 26 八月 2025 17:59:50 +0800 Subject: [PATCH] 获取设备列表序列化 --- HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java | 71 +++++++++++++++-------------------- 1 files changed, 31 insertions(+), 40 deletions(-) diff --git a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java index e76c21e..982ef41 100644 --- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java +++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java @@ -38,6 +38,7 @@ import com.hdl.sdk.common.utils.SPUtils; import com.hdl.sdk.common.utils.gson.GsonConvert; import com.hdl.sdk.connect.HDLLink; +import com.hdl.sdk.connect.bean.LinkFunctionInfo; import com.hdl.sdk.connect.bean.LinkResponse; import com.hdl.sdk.connect.bean.request.AttributesRequest; import com.hdl.sdk.connect.bean.request.AuthenticateRequest; @@ -50,6 +51,7 @@ import com.hdl.sdk.connect.bean.response.UpdateInfo; import com.hdl.sdk.connect.callback.HDLLinkCallBack; import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack; +import com.hdl.sdk.connect.callback.HDLLinkTCallBack; import com.hdl.sdk.connect.cloud.CallBackListener; import com.hdl.sdk.connect.cloud.CheckAppVersionListener; import com.hdl.sdk.connect.cloud.HDLException; @@ -81,8 +83,8 @@ private EventListener allTopicsListener; private String testLightSid = "020101A19B485D02020100010101"; private String secret = ""; - private List<FunctionBean> devicesList = new ArrayList<>(); - private List<FunctionBean> roomDevicesList = new ArrayList<>(); + private List<LinkFunctionInfo> devicesList = new ArrayList<>(); + private List<LinkFunctionInfo> roomDevicesList = new ArrayList<>(); private List<SceneBean> sceneList = new ArrayList<>(); private List<SceneDetailBean> sceneDetailList = new ArrayList<>(); private List<SceneDetailBean> roomSceneList = new ArrayList<>(); @@ -92,8 +94,8 @@ tv.setText("寮�濮嬬敵璇疯澶囧瘑閽�..."); responseTv.setText(""); - String supplier = "HIK KNX";//鍘傚晢 - String mac = "FQ4895630";//璁惧鍞竴MAC鍦板潃 + String supplier = "JINMAOYUN";//鍘傚晢 + String mac = "f2c5d8bad48f";//璁惧鍞竴MAC鍦板潃 // String mac = editText.getText().toString(); String spk = "screen.touch";//浜у搧spk @@ -228,7 +230,7 @@ selectnetwork(); checkIfCertified(); - //initDeviceInfo();//涓嶈蛋浠庢満鍏ョ綉鐨勬柟寮忎笉闇�瑕佸垵濮嬪寲 + initDeviceInfo();//涓嶈蛋浠庢満鍏ョ綉鐨勬柟寮忎笉闇�瑕佸垵濮嬪寲锛岃蛋浠庢満鍏ョ綉鍒欓渶瑕佸垵濮嬪寲 registerAllTopicsListener(); HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() { @Override @@ -411,11 +413,12 @@ LinkResponse response = (LinkResponse) msg; Log.i("onMessage", "response.getTopic():" + response.getTopic()); String topic = String.format(TopicConstant.GATEWAY_LOGIN, - HDLLinkConfig.getInstance().getGatewayId())+ "_reply";; + HDLLinkConfig.getInstance().getGatewayId()) + "_reply"; + ; if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())) { localSecret.setText("瀵嗛挜锛�" + HDLLinkConfig.getInstance().getLocalSecret()); - }else if (topic.equals(response.getTopic())){ + } else if (topic.equals(response.getTopic())) { //tcp杩炴帴鎴愬姛锛屽鐞嗕笟鍔¢�昏緫 } } @@ -473,8 +476,8 @@ infoBean.setDeviceName("榄旈暅");//璁惧鍚嶅瓧 infoBean.setDeviceModel("HDLSDK");//璁惧鍨嬪彿 infoBean.setAccessMode("WIFI"); - infoBean.setIPGateway("192.168.31.1"); - infoBean.setIPAddress("192.168.31.103"); + infoBean.setIPGateway("192.168.1.1"); + infoBean.setIPAddress("192.168.1.103"); infoBean.setGateway_type("screen.touch"); infoBean.setHw_version("HW2.0"); infoBean.setFw_version("Fw1.0"); @@ -507,7 +510,7 @@ //璁よ瘉鎻愪氦鍙傛暟鍑嗗 //姝e紡鏈嶅姟鍣� - String spkStr = "screen.mirror";//浜у搧spk + String spkStr = "screen.touch";//浜у搧spk String macStr = "f2c5d8bad48f";//璁惧鍞竴MAC鍦板潃 String mac_key = stringToMD5(stringToMD5(macStr + secret)); @@ -596,37 +599,23 @@ void getFunctionList() { tv.setText("鑾峰彇璁惧鍒楄〃涓�..."); responseTv.setText(""); - HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() { + HDLLink.getInstance().getFunctionInfoList(new HDLLinkTCallBack<List<LinkFunctionInfo>>() { + @Override + public void onSuccess(List<LinkFunctionInfo> data) { + if (data != null && data.size() != 0) { + devicesList.clear(); + devicesList.addAll(data); + + tv.setText("鑾峰彇璁惧鍒楄〃鎴愬姛"); + responseTv.setText(data.toString()); + } + } + @Override public void onError(HDLLinkException error) { tv.setText(error.getMsg()); } - - @Override - public void onSuccess(String data) { - tv.setText("鑾峰彇璁惧鍒楄〃鎴愬姛"); - responseTv.setText(data); - - handelFunctionList(data); - } }); - } - - void handelFunctionList(String data) { - try { - final LinkResponse linkResponse = GsonConvert.getGson().fromJson(data, new TypeToken<LinkResponse>() { - }.getType()); - - final BaseLocalResponse<List<FunctionBean>> bean = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<FunctionBean>>>() { - }.getType()); - devicesList.clear(); - devicesList.addAll(bean.getObjects()); - - Log.d(TAG, "handelFunList-----> " + devicesList.toString()); - } catch (Exception e) { - Log.e(TAG, "handelFunList: " + e.getMessage()); - } - } /** @@ -643,10 +632,12 @@ sids.add(testLightSid); } - HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() { + HDLLink.getInstance().getFunctionAttributeInfo(sids, new HDLLinkTCallBack<List<LinkFunctionInfo>>() { @Override - public void onSuccess(String msg) { - responseTv.setText(msg); + public void onSuccess(List<LinkFunctionInfo> data) { + if (data != null && data.size() != 0) { + responseTv.setText(data.toString()); + } } @Override @@ -707,7 +698,7 @@ request.setStatus(statusBeanList); requestList.add(request); - HDLLink.getInstance().propertyDown(requestList, new HDLLinkCallBack() { + HDLLink.getInstance().propertyDownDevice(requestList, new HDLLinkTCallBack<String>() { @Override public void onSuccess(String data) { responseTv.setText(data); -- Gitblit v1.8.0