From 7ae3378cab3a872f0f1bc8dfbc4dd9fad303d875 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期三, 08 十二月 2021 09:34:44 +0800
Subject: [PATCH] 修改下细节

---
 HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java |  101 +++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 75 insertions(+), 26 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 2a652c1..5f9fcfd 100644
--- a/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
+++ b/HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -9,7 +9,9 @@
 import androidx.recyclerview.widget.RecyclerView;
 
 import android.Manifest;
+import android.content.Intent;
 import android.os.Bundle;
+import android.text.TextUtils;
 import android.util.Log;
 import android.view.View;
 import android.widget.TextView;
@@ -17,14 +19,18 @@
 
 import com.chad.library.adapter.base.BaseQuickAdapter;
 import com.chad.library.adapter.base.listener.OnItemClickListener;
+import com.google.gson.reflect.TypeToken;
+import com.hdl.hdlsdk.device.DevicesListActivity;
 import com.hdl.sdk.common.event.EventListener;
 import com.hdl.sdk.common.exception.HDLLinkException;
 import com.hdl.sdk.common.utils.IdUtils;
 import com.hdl.sdk.common.utils.IpUtils;
+import com.hdl.sdk.common.utils.gson.GsonConvert;
 import com.hdl.sdk.connect.HDLLink;
 import com.hdl.sdk.connect.bean.LinkResponse;
 import com.hdl.sdk.connect.bean.request.AuthenticateRequest;
 import com.hdl.sdk.connect.bean.request.PropertyReadRequest;
+import com.hdl.sdk.connect.bean.response.BaseLocalResponse;
 import com.hdl.sdk.connect.bean.response.GatewaySearchBean;
 import com.hdl.sdk.connect.callback.HDLLinkCallBack;
 import com.hdl.sdk.connect.callback.HDLLinkResponseCallBack;
@@ -43,15 +49,18 @@
 import java.util.List;
 import java.util.Map;
 
+import static com.hdl.sdk.common.config.TopicConstant.GATEWAY_SEARCH_REPLY;
+
 public class MainActivity extends AppCompatActivity {
 
+    private static final String TAG = "MainActivity";
     private DemoAdapter demoAdapter;
     private RecyclerView rv;
     private TextView tv;
     private TextView responseTv;
     boolean isOn;
     private EventListener allTopicsListener;
-    private String testLightSid = "000101B847C71B02020100010101";
+    private String testLightSid = "0001010D48C71B02020100010101";
 
     @Override
     protected void onDestroy() {
@@ -69,6 +78,7 @@
         rv.setLayoutManager(new LinearLayoutManager(this));
 
         checkIfCertified();
+
         registerAllTopicsListener();
 
         ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@@ -89,17 +99,16 @@
         beans.add(new DemoBean("璇诲彇鐘舵��"));
         beans.add(new DemoBean("鑾峰彇鍦烘櫙鍒楄〃"));
         beans.add(new DemoBean("鍦烘櫙鎺у埗"));
+        beans.add(new DemoBean("璁惧鍔熻兘鍒楄〃"));
         demoAdapter = new DemoAdapter(beans);
         rv.setAdapter(demoAdapter);
 
 
-        final SocketOptions options = new SocketOptions();
-
-        MessagePipeLine pipeLine = new MessagePipeLine();
-        pipeLine.add(new LinkMessageDecoder());
-        pipeLine.add(new LinkMessageEncoder());
-        options.setHandleMessage(pipeLine);
-        options.setEnabledHeartbeat(false);
+//        final SocketOptions options = new SocketOptions();
+//
+//        MessagePipeLine pipeLine = new MessagePipeLine();
+//        options.setHandleMessage(pipeLine);
+//        options.setEnabledHeartbeat(false);
 
         demoAdapter.setOnItemClickListener(new OnItemClickListener() {
             @Override
@@ -137,6 +146,10 @@
                         //鑾峰彇鍦烘櫙鍒楄〃
                         controlScene();
                         break;
+                    case 8:
+                        //鍔熻兘鍒楄〃
+                        startDevicesListActivity();
+                        break;
                 }
             }
         });
@@ -163,10 +176,45 @@
             @Override
             public void onMessage(Object msg) {
                 LinkResponse response = (LinkResponse)msg;
-                Log.i("TAG", "AllTopicsListener onMessage: "+msg.toString());
             }
         };
         HDLLink.getInstance().registerAllTopicsListener(allTopicsListener);
+    }
+
+    /**
+     * 澶勭悊鏀跺埌鐨勪富棰�
+     * @param response
+     */
+    private void handleLinkResponse(LinkResponse response){
+        //缃戝叧鎼滅储鍥炲
+        if(response.getTopic().contains("/user/all/custom/gateway/search_reply")){
+            String data = response.getData();
+            if (!TextUtils.isEmpty(data)) {
+                Log.i("handleLinkResponse", "data:"+data);
+                final BaseLocalResponse<GatewaySearchBean> bean = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewaySearchBean>>() {
+                }.getType());
+                GatewaySearchBean searchBean = bean.getObjects();
+                Log.i("handleLinkResponse", "GatewaySearchBean: "+searchBean.getGatewayId());
+            }
+        }else{
+            //鍏跺畠涓婚
+
+        }
+    }
+
+    private GatewaySearchBean getGatewaySearchBean(Object msg) {
+        GatewaySearchBean searchBean = null;
+        if (msg instanceof LinkResponse) {
+            LinkResponse linkResponse = (LinkResponse) msg;
+            String data = linkResponse.getData();
+            if (!TextUtils.isEmpty(data)) {
+                final BaseLocalResponse<GatewaySearchBean> response = GsonConvert.getGson().fromJson(data, new TypeToken<BaseLocalResponse<GatewaySearchBean>>() {
+                }.getType());
+                searchBean = response.getObjects();
+            }
+
+        }
+        return searchBean;
     }
 
     /**
@@ -181,12 +229,13 @@
      */
     void sendAuthenticateRequest(){
         tv.setText("寮�濮嬪叆缃戣璇�...");
+        //璁よ瘉鎻愪氦鍙傛暟鍑嗗
 
-        String macStr = "AA000000000000BB";
-        String secret = "87ae414b7a853f65";
+        String spkStr = "ir.module";//浜у搧spk
+        String macStr = "AA000000000000BB";//璁惧鍞竴MAC鍦板潃
+        String secret = "87ae414b7a853f65";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
         String mac_key = stringToMD5(stringToMD5(macStr + secret));
-
-        String versionString = "HDL_V1.0.1";
+        String versionString = "HDL_V1.0.1";//
         String time = String.valueOf(System.currentTimeMillis());
 
         //1.璁剧疆璁よ瘉淇℃伅
@@ -196,7 +245,7 @@
         requestBean.setFirmwareVersion(versionString);
         requestBean.setHardwareModel("1956F");
         AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean();
-        authbean.setSpk("ir.module");
+        authbean.setSpk(spkStr);
         authbean.setMACKey(mac_key);
         authbean.setRequest(requestBean);
 
@@ -204,11 +253,11 @@
         AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
         infoBean.setDeviceMAC(macStr);
         infoBean.setIPMAC(macStr);
-        infoBean.setDeviceName("HDL闈㈡澘");
-        infoBean.setDeviceModel("HDL");
+        infoBean.setDeviceName("绾㈠瀹�");//璁惧鍚嶅瓧
+        infoBean.setDeviceModel("HDL");//
         infoBean.setAccessMode("WIFI");
+        infoBean.setIPGateway("192.168.12.1");
         infoBean.setIPAddress(IpUtils.getIP(this));
-
 
         infoBean.setOID("010105000000FE08");
         infoBean.setSid("010105000000FE08110100000000");
@@ -216,16 +265,12 @@
         AuthenticateRequest.VersionBean[] versionBeans = new AuthenticateRequest.VersionBean[]{new AuthenticateRequest.VersionBean("FW", versionString), new AuthenticateRequest.VersionBean("HW", "1956F")};
         infoBean.setVersions(versionBeans);
         AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, infoBean, authbean);
-
-        String ip = IpUtils.getBroadcastAddress();
-//        ip = "192.168.10.102";
-
         HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() {
             @Override
             public void onError(HDLLinkException e) {
                 tv.setText("璁よ瘉澶辫触");
                 responseTv.setText(e.getMsg());
-//                Log.i("TAG", "onError: 璁よ瘉澶辫触");
+                Log.i("TAG", "onError: 璁よ瘉澶辫触");
             }
 
             @Override
@@ -268,6 +313,7 @@
             @Override
             public void onError(HDLLinkException e) {
                 tv.setText("缃戝叧涓嶅湪绾�");
+                responseTv.setText(e.getMsg());
             }
             @Override
             public void onSuccess(GatewaySearchBean gatewaySearchBean) {
@@ -284,8 +330,7 @@
     void getFunctionList(){
         tv.setText("鑾峰彇鍔熻兘鍒楄〃涓�...");
         responseTv.setText("");
-        HDLSocket.getInstance().getFunctionList(new HDLLinkCallBack() {
-
+        HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() {
             @Override
             public void onError(HDLLinkException error) {
                 tv.setText(error.getMsg());
@@ -307,7 +352,7 @@
         tv.setText("鍔熻兘灞炴�ц鍙�");
         List<String> sids = new ArrayList<>();
         sids.add(testLightSid);
-        HDLSocket.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() {
+        HDLLink.getInstance().getFunctionAttribute(sids, new HDLLinkCallBack() {
             @Override
             public void onSuccess(String msg) {
                 responseTv.setText(msg);
@@ -328,7 +373,7 @@
         tv.setText("璇诲彇鐘舵�佷腑...");
         List<String> list = new ArrayList<>();
         list.add(testLightSid);//瑕佽鍙栬澶囩殑sid
-        HDLSocket.getInstance().propertyRead(list, new HDLLinkCallBack() {
+        HDLLink.getInstance().propertyRead(list, new HDLLinkCallBack() {
             @Override
             public void onSuccess(String data) {
                 tv.setText("璇诲彇鎴愬姛");
@@ -420,4 +465,8 @@
     }
 
 
+    void startDevicesListActivity(){
+        Intent intent = new Intent(this, DevicesListActivity.class);
+        startActivity(intent);
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0