panlili2024
2025-02-24 9a437cca9b3d21f5081d544024ee2b3e216176f8
HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -1,8 +1,10 @@
package com.hdl.hdlsdk;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
@@ -15,7 +17,6 @@
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -23,6 +24,10 @@
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.bean.FunctionBean;
import com.hdl.hdlsdk.bean.RoomFunctionBean;
import com.hdl.hdlsdk.bean.SceneBean;
import com.hdl.hdlsdk.bean.SceneDetailBean;
import com.hdl.hdlsdk.device.DevicesListActivity;
import com.hdl.sdk.common.config.TopicConstant;
import com.hdl.sdk.common.event.DeleteNetworkListener;
@@ -33,14 +38,18 @@
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.AttributesRequest;
import com.hdl.sdk.connect.bean.request.AuthenticateRequest;
import com.hdl.sdk.connect.bean.request.DeviceControlRequest;
import com.hdl.sdk.connect.bean.request.ListSidRequest;
import com.hdl.sdk.connect.bean.request.ListUploadRequest;
import com.hdl.sdk.connect.bean.response.BaseLocalResponse;
import com.hdl.sdk.connect.bean.response.GatewaySearchBean;
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.cloud.CallBackListener;
import com.hdl.sdk.connect.cloud.CheckAppVersionListener;
import com.hdl.sdk.connect.cloud.HDLException;
import com.hdl.sdk.connect.config.HDLLinkConfig;
import com.hdl.sdk.connect.socket.HDLAuthSocket;
@@ -51,8 +60,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import retrofit2.http.HEAD;
public class MainActivity extends AppCompatActivity {
@@ -65,46 +72,25 @@
    private EditText editText;
    boolean isOn;
    private EventListener allTopicsListener;
    private String testLightSid = "02010131D9C03D01020300010107";
    private String testLightSid = "020101A19B485D02020100010101";
    private String secret = "";
    @Override
    protected void onDestroy() {
        super.onDestroy();
        removeAllTopicsListener();
    }
    void initDeviceInfo() {
        AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
        infoBean.setDeviceMAC("f2c5d8bad48f");
        infoBean.setIPMAC("f2c5d8bad48f");
        infoBean.setDeviceName("音乐播放器");//设备名字
        infoBean.setDeviceModel("MCLog.431");//设备型号
        infoBean.setAccessMode("WIFI");
        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");
        infoBean.setOID("010105000000FE11");//每个设备oid都要不一样
        infoBean.setSid("110105000000FE08110100000011");//每个设备的sid都要不一样
        infoBean.setSupplier("JINMAOYUN");
        HDLLinkConfig.getInstance().setDeviceInfoBean(infoBean);
    }
    private List<FunctionBean> devicesList = new ArrayList<>();
    private List<FunctionBean> roomDevicesList = new ArrayList<>();
    private List<SceneBean> sceneList = new ArrayList<>();
    private List<SceneDetailBean> sceneDetailList = new ArrayList<>();
    private List<SceneDetailBean> roomSceneList = new ArrayList<>();
    void applyDeviceSecret() {
        tv.setText("开始申请设备密钥...");
        responseTv.setText("");
//        //正式服务器
        String appKey = "i8hR07jzrIS";//appkey
        String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret
//        String appKey = "i8hR07jzrIS";//appkey
//        String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret
        //测试服务器
//        String appKey ="FcRyUJlLJFF";
//        String appSecret = "wz8wn75ABidx8vXcFGUotqhwFkTaYvvJ";
        String appKey = "FcRyUJlLJFF";
        String appSecret = "wz8wn75ABidx8vXcFGUotqhwFkTaYvvJ";
//        String appKey = "L2OZliZRxHc";
//        String appSecret = "aCIWSvJDOukXfx3kivsKW11x9xdR3IbV";
@@ -136,63 +122,30 @@
    }
    /**
     * 入网认证
     */
    void sendAuthenticateRequest() {
        tv.setText("开始入网认证...");
    void checkAppVersion() {
        tv.setText("开始检测更新...");
        responseTv.setText("");
        //认证提交参数准备
//
//        //测试服务器
//        String spkStr = "music.standard";//产品spk
//        String macStr = "AA000000000000AF";//设备唯一MAC地址
//        String secret = "44b360eb74b7ba64";//通过spk和mac提交云端认证后分配的secret
//        正式服务器
        String spkStr = "screen.touch";//产品spk
//        String macStr = "AA00000000000100";//设备唯一MAC地址
        String macStr = editText.getText().toString();//设备唯一MAC地址
//        String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的
//        //正式服务器
        String appKey = "i8hR07jzrIS";//appkey
        String appSecret = "BmnJ8RWTtaVEBk24zPPF4UMwfYu0lAWU";//appsecret
        String mac_key = stringToMD5(stringToMD5(macStr + secret));
        String versionString = "HDL_V1.0.1";//
        String time = String.valueOf(System.currentTimeMillis());
        HDLLinkConfig.getInstance().getDeviceInfoBean().setDeviceMAC(macStr);
//        HDLLinkConfig.getInstance().setCurrentGateway(infoBean);
        String appCode = "1697150870315999233";//appCode
        //1.设置认证信息
        AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean();
        requestBean.setMAC(macStr);
        requestBean.setSupplier("JINMAOYUN");
        requestBean.setFirmwareVersion(versionString);
        requestBean.setHardwareModel("1956F");
//        HDLLinkConfig.getInstance().setRequestBean(requestBean);
        AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean();
        authbean.setSpk(spkStr);
        authbean.setMACKey(mac_key);
        authbean.setRequest(requestBean);
        HDLLinkConfig.getInstance().setAuthBean(authbean);
        //HDLLinkConfig.getInstance().getDeviceInfoBean()这个初始化的时候要先设置好
        AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean);
        HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() {
        HDLLink.getInstance().checkAppVersion(this, appKey, appSecret, getAppVersionName(this), appCode, new CheckAppVersionListener() {
            @Override
            public void onError(HDLLinkException e) {
                tv.setText("认证失败" + e.getCode());
                responseTv.setText(e.getMsg());
                Log.e(TAG, "onError: 认证失败 " + e.getCode());
            public void onSuccess(UpdateInfo info) {
                tv.setText("有新更新");
                responseTv.setText(info.toString());
            }
            @RequiresApi(api = Build.VERSION_CODES.O)
            @Override
            public void onSuccess(String msg) {
                tv.setText("认证成功");
                responseTv.setText(msg.toString());
                localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret());
            public void onError(HDLException e) {
                tv.setText("检测更新失败");
                responseTv.setText(e.getMsg());
            }
        });
    }
    public void UploadDeviceAuth(String mac, String result, String message, String auth_code) {
@@ -241,6 +194,8 @@
            }
        });
        UploadSidList();
        ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
            @Override
            public void onActivityResult(Map<String, Boolean> result) {
@@ -255,27 +210,24 @@
        beans.add(new DemoBean("入网认证"));
        beans.add(new DemoBean("搜索指定网关是否在线"));
        beans.add(new DemoBean("上报oid列表"));
        beans.add(new DemoBean("获取功能列表"));
        beans.add(new DemoBean("功能属性读取"));
        beans.add(new DemoBean("获取设备列表"));
        beans.add(new DemoBean("设备功能属性读取"));
        beans.add(new DemoBean("设备控制"));
        beans.add(new DemoBean("读取状态"));
        beans.add(new DemoBean("获取场景列表"));
        beans.add(new DemoBean("场景详情"));
        beans.add(new DemoBean("场景控制"));
        beans.add(new DemoBean("设备功能列表"));
        beans.add(new DemoBean("UDP发送"));
        beans.add(new DemoBean("TCP发送"));
        beans.add(new DemoBean("UDP发送,监听主题回复,带重发带回调"));
        beans.add(new DemoBean("TCP发送,监听主题回复,带重发带回调"));
        beans.add(new DemoBean("退网"));
        beans.add(new DemoBean("Source功能支持"));
        beans.add(new DemoBean("获取房间列表"));
        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();
//        options.setHandleMessage(pipeLine);
//        options.setEnabledHeartbeat(false);
        demoAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
@@ -298,11 +250,12 @@
                        UploadOidList();
                        break;
                    case 4:
                        //获取功能列表
                        //获取设备列表
                        getFunctionList();
                        //startDevicesListActivity();
                        break;
                    case 5:
                        //功能属性读取
                        //设备功能属性读取
                        getFunctionAttribute();
                        break;
                    case 6:
@@ -318,32 +271,48 @@
                        getSceneList();
                        break;
                    case 9:
                        //场景详情
                        getSceneDetail();
                        break;
                    case 10:
                        //场景控制
                        controlScene();
                        break;
                    case 10:
                        //功能列表
                        startDevicesListActivity();
                        break;
                    case 11:
                        //UDP发送
                        udpSend();
                        break;
                    case 12:
                        //TCP发送
                        tcpSend();
                        break;
                    case 13:
                        //UDP发送,监听主题回复,带重发带回调
                        udpSendWithCallback();
                        break;
                    case 14:
                    case 12:
                        //TCP发送,监听主题回复,带重发带回调
                        tcpSendWithCallback();
                        break;
                    case 15:
                    case 13:
                        //退网
                        deleteNetwork();
                        break;
                    case 14:
                        //Source功能支持
                        startSourceTestActivity();
                        break;
                    case 15:
                        //获取房间列表
                        getRoomList();
                        break;
                    case 16:
                        //获取房间设备列表
                        getRoomDeviceList();
                        break;
                    case 17:
                        //获取房间场景列表
                        getRoomSceneList();
                        break;
                    case 18:
                        //获取自动化列表
                        getLogicList();
                        break;
                    case 19:
                        //⾃动化启⽤禁⽤
                        editEnableLogic();
                        break;
                }
            }
@@ -377,8 +346,10 @@
            @Override
            public void onMessage(Object msg) {
                LinkResponse response = (LinkResponse) msg;
                if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())){
                Log.i("onMessage", "response.getTopic():" + response.getTopic());
                if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())) {
                    localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret());
                }
            }
        };
@@ -428,6 +399,74 @@
        HDLLink.getInstance().removeAllTopicsListener(allTopicsListener);
    }
    void initDeviceInfo() {
        AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean();
        infoBean.setDeviceMAC("f2c5d8bad48f");
        infoBean.setIPMAC("f2c5d8bad48f");
        infoBean.setDeviceName("魔镜");//设备名字
        infoBean.setDeviceModel("HDLSDK");//设备型号
        infoBean.setAccessMode("WIFI");
        infoBean.setIPGateway("192.168.31.1");
        infoBean.setIPAddress("192.168.31.103");
        infoBean.setGateway_type("screen.touch");
        infoBean.setHw_version("HW2.0");
        infoBean.setFw_version("Fw1.0");
        infoBean.setOID("010105000000FE11");//每个设备oid都要不一样
        infoBean.setSid("110105000000FE08110100000011");//每个设备的sid都要不一样
        infoBean.setSupplier("JINMAOYUN");
        HDLLinkConfig.getInstance().setDeviceInfoBean(infoBean);
    }
    /**
     * 入网认证
     */
    void sendAuthenticateRequest() {
        tv.setText("开始入网认证...");
        //认证提交参数准备
//        测试服务
//        String spkStr = "ir.module";//产品spk
//        String macStr = "AA000000000000AF";//设备唯一MAC地址
//        String secret = "44b360eb74b7ba64";//通过spk和mac提交云端认证后分配的secret
//        正式服务器
        String spkStr = "screen.mirror";//产品spk
        String macStr = "f2c5d8bad48f";//设备唯一MAC地址
//        String secret = "e186beeb7974998e";//通过spk和mac提交云端认证后分配的secret
        String mac_key = stringToMD5(stringToMD5(macStr + secret));
        String versionString = "HDL_V1.0.1";//
        String time = String.valueOf(System.currentTimeMillis());
        HDLLinkConfig.getInstance().getDeviceInfoBean().setDeviceMAC(macStr);
        //1.设置认证信息
        AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean();
        requestBean.setMAC(macStr);
        requestBean.setSupplier("JINMAOYUN");
        requestBean.setFirmwareVersion(versionString);
        requestBean.setHardwareModel("1956F");
        AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean();
        authbean.setSpk(spkStr);
        authbean.setMACKey(mac_key);
        authbean.setRequest(requestBean);
        //HDLLinkConfig.getInstance().getDeviceInfoBean()这个初始化的时候要先设置好
        AuthenticateRequest request = new AuthenticateRequest(IdUtils.getUUId(), time, HDLLinkConfig.getInstance().getDeviceInfoBean(), authbean);
        HDLLink.getInstance().startAuthenticateRequest(request, new HDLLinkCallBack() {
            @Override
            public void onError(HDLLinkException e) {
                tv.setText("认证失败");
                responseTv.setText(e.getMsg());
                Log.i("TAG", "onError: 认证失败");
            }
            @Override
            public void onSuccess(String msg) {
                tv.setText("认证成功");
                responseTv.setText(msg.toString());
            }
        });
    }
    String stringToMD5(String text) {
        byte[] hash;
@@ -443,8 +482,7 @@
        StringBuilder hex = new StringBuilder(hash.length * 2);
        for (byte b : hash) {
            if ((b & 0xFF) < 0x10)
                hex.append("0");
            if ((b & 0xFF) < 0x10) hex.append("0");
            hex.append(Integer.toHexString(b & 0xFF));
        }
@@ -458,6 +496,7 @@
    void searchGatewayBroadcast() {
        tv.setText("搜索网关中...");
        responseTv.setText("");
        HDLLinkConfig.getInstance().getGatewayId();
        HDLLink.getInstance().searchGatewayBroadcast(new HDLAuthSocket.SearchGatewayCallBack() {
            @Override
            public void onError(HDLLinkException e) {
@@ -475,10 +514,10 @@
    }
    /**
     * 获取功能列表
     * 获取设备列表
     */
    void getFunctionList() {
        tv.setText("获取功能列表中...");
        tv.setText("获取设备列表中...");
        responseTv.setText("");
        HDLLink.getInstance().getFunctionList(new HDLLinkCallBack() {
            @Override
@@ -488,18 +527,37 @@
            @Override
            public void onSuccess(String data) {
                tv.setText("获取功能列表成功");
                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());
        }
    }
    /**
     * 功能属性读取
     * 设备功能属性读取
     * 支持批量读取
     */
    void getFunctionAttribute() {
        tv.setText("功能属性读取");
        tv.setText("设备功能属性读取");
        responseTv.setText("");
        List<String> sids = new ArrayList<>();
        sids.add(testLightSid);
@@ -558,6 +616,7 @@
        statusBeanList.add(bean);
        request.setStatus(statusBeanList);
        requestList.add(request);
        HDLLink.getInstance().propertyDown(requestList, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String data) {
@@ -581,6 +640,8 @@
            @Override
            public void onSuccess(String msg) {
                responseTv.setText(msg);
                handelSceneList(msg);
            }
            @Override
@@ -590,8 +651,73 @@
        });
    }
    void handelSceneList(String data) {
        try {
            final LinkResponse linkResponse = GsonConvert.getGson().fromJson(data, new TypeToken<LinkResponse>() {
            }.getType());
            final BaseLocalResponse<List<SceneBean>> bean = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<SceneBean>>>() {
            }.getType());
            sceneList.clear();
            sceneList.addAll(bean.getObjects());
            Log.d(TAG, "handelSceneList-----> " + sceneList.toString());
        } catch (Exception e) {
            Log.e(TAG, "handelSceneList: " + e.getMessage());
        }
    }
    //场景列表
    // {"id":"8a5eaa143ce943b987b577df5a66759b","time_stamp":"1637040217235","objects":[{"sid":"04010560D2C7170A0A0100000000","name":"回家模式","status":"off","group":"255","delay":"0","modify_time":"1634871490"},{"sid":"04010560D2C76E0A0A0100010000","name":"离家模式","status":"off","group":"255","delay":"0","modify_time":"1634785823"}]}
//    {"id":"98a683eca5384f2db2ca1ed688953439","time_stamp":"1740024067320","code":"0","msg":"Success","objects":[{"sid":"0201039965BF5D0A0A0100011100","name":"场景-1","status":"off","group":"255","delay":"0","modify_time":"1735293636","local":"false"},{"sid":"030105016B84AA0A0A0100020000","name":"大厅灯开","status":"off","group":"255","delay":"0","modify_time":"1740023916","local":"false"},{"sid":"030105016D14240A0A0100030000","name":"大厅灯关","status":"off","group":"255","delay":"0","modify_time":"1740023969","local":"false"},{"sid":"020103D465BF5D0A0A0100041100","name":"场景-4","status":"off","group":"255","delay":"0","modify_time":"1735200096","local":"false"}]}
    /**
     * 获取场景详情
     * 执行成功的话 响应code为200
     */
    void getSceneDetail() {
        tv.setText("场景读取");
        responseTv.setText("");
        //场景sid列表,支持批量读取
        if (sceneList != null && sceneList.size() != 0) {
            List<String> sids = new ArrayList<>();
            for (SceneBean s : sceneList) {
                sids.add(s.getSid());//遍历所有场景拿到详情信息
            }
            HDLLink.getInstance().getScene(sids, new HDLLinkCallBack() {
                @Override
                public void onSuccess(String msg) {
                    responseTv.setText(msg);
                    handelSceneDetailList(msg);
                }
                @Override
                public void onError(HDLLinkException e) {
                    responseTv.setText(e.getMsg());
                }
            });
        } else {
            Toast.makeText(MainActivity.this, "请先获取场景列表", Toast.LENGTH_SHORT).show();
        }
    }
    void handelSceneDetailList(String data) {
        try {
            final LinkResponse linkResponse = GsonConvert.getGson().fromJson(data, new TypeToken<LinkResponse>() {
            }.getType());
            final BaseLocalResponse<List<SceneDetailBean>> bean = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<SceneDetailBean>>>() {
            }.getType());
            sceneDetailList.clear();
            sceneDetailList.addAll(bean.getObjects());
            Log.d(TAG, "handelSceneDetailList-----> " + sceneDetailList.toString());
        } catch (Exception e) {
            Log.e(TAG, "handelSceneDetailList: " + e.getMessage());
        }
    }
    /**
     * 控制场景
@@ -604,9 +730,9 @@
        List<String> sids = new ArrayList<>();
        isOn = !isOn;
        if (isOn) {
            sids.add("04010560D2C7170A0A0100000000");
            sids.add("030105016D14240A0A0100030000");
        } else {
            sids.add("04010560D2C76E0A0A0100010000");
            sids.add("030105016B84AA0A0A0100020000");
        }
        HDLLink.getInstance().controlScene(sids, new HDLLinkCallBack() {
            @Override
@@ -621,9 +747,161 @@
        });
    }
    /**
     * 获取房间列表
     */
    void getRoomList() {
        tv.setText("读取房间列表");
        responseTv.setText("");
        HDLLink.getInstance().getRoomList(new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                responseTv.setText(msg);
            }
            @Override
            public void onError(HDLLinkException e) {
                responseTv.setText(e.getMsg());
            }
        });
    }
    /**
     * 获取房间设备列表
     * 先获取房间绑定关系列表,通过sid和设备列表匹配筛选
     */
    void getRoomDeviceList() {
        tv.setText("获取房间设备列表");
        responseTv.setText("");
        //房间uid列表,支持批量读取
        List<String> uid = new ArrayList<>();
        uid.add("64a4fc6f-4eae-4d1d-82e4-40140c802c48");
        HDLLink.getInstance().getRoomBindList(uid, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                if (!TextUtils.isEmpty(msg)) {
                    handelRoomFunctionList(msg);
                }
            }
            @Override
            public void onError(HDLLinkException e) {
                responseTv.setText(e.getMsg());
            }
        });
    }
    void handelRoomFunctionList(String data) {
        try {
            final LinkResponse linkResponse = GsonConvert.getGson().fromJson(data, new TypeToken<LinkResponse>() {
            }.getType());
            final BaseLocalResponse<List<RoomFunctionBean>> bean = GsonConvert.getGson().fromJson(linkResponse.getData(), new TypeToken<BaseLocalResponse<List<RoomFunctionBean>>>() {
            }.getType());
            List<RoomFunctionBean> roomFunctionBeans = bean.getObjects();
            List<RoomFunctionBean.Functions> functions = roomFunctionBeans.get(0).getFunctions();
            roomDevicesList.clear();
            if (devicesList != null && devicesList.size() != 0) {
                for (int i = 0; i < functions.size(); i++) {
                    for (int j = 0; j < devicesList.size(); j++) {
                        //与设备列表的数据匹配,sid对应
                        if (functions.get(i).getSid().equals(devicesList.get(j).getSid())) {
                            roomDevicesList.add(devicesList.get(j));
                        }
                    }
                }
                responseTv.setText(roomDevicesList.toString());
                Log.d(TAG, "handelRoomFunctionList-----> " + roomDevicesList.toString());
            } else {
                Toast.makeText(MainActivity.this, "请先获取设备列表", Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {
            Log.e(TAG, "handelRoomFunctionList: " + e.getMessage());
        }
    }
    /**
     * 获取自动化列表
     */
    void getLogicList() {
        tv.setText("读取自动化列表");
        responseTv.setText("");
        HDLLink.getInstance().getLogicList(new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                responseTv.setText(msg);
            }
            @Override
            public void onError(HDLLinkException e) {
                responseTv.setText(e.getMsg());
            }
        });
    }
    /**
     * ⾃动化启⽤禁⽤
     */
    void editEnableLogic() {
        tv.setText("⾃动化启⽤禁⽤");
        responseTv.setText("");
        String sid = "0301050041800C161501000A0000";//自动化sid
        boolean enable = true;//true=启⽤ false=禁⽤
        HDLLink.getInstance().editEnableLogic(sid, enable, new HDLLinkCallBack() {
            @Override
            public void onSuccess(String msg) {
                responseTv.setText(msg);
            }
            @Override
            public void onError(HDLLinkException e) {
                responseTv.setText(e.getMsg());
            }
        });
    }
    /**
     * 获取房间场景列表(需要先拿到场景详情)
     */
    void getRoomSceneList() {
        tv.setText("获取房间场景列表");
        responseTv.setText("");
        String uid = "64a4fc6f-4eae-4d1d-82e4-40140c802c48";
        roomSceneList.clear();
        if (sceneDetailList != null && sceneDetailList.size() != 0) {
            for (SceneDetailBean s : sceneDetailList) {
                List<String> roomUids = s.getUids();
                if (roomUids != null && roomUids.size() != 0) {
                    for (int i = 0; i < roomUids.size(); i++) {
                        if (uid.equals(roomUids.get(i))) {
                            roomSceneList.add(s);
                        }
                    }
                }
            }
            responseTv.setText(roomSceneList.toString());
            Log.d(TAG, "getRoomSceneList-----> " + roomSceneList.toString());
        } else {
            Toast.makeText(MainActivity.this, "请先获取场景列表详情", Toast.LENGTH_SHORT).show();
        }
    }
    void startDevicesListActivity() {
        Intent intent = new Intent(this, DevicesListActivity.class);
        startActivity(intent);
    }
    void startSourceTestActivity() {
        Intent intent = new Intent(this, SourceTestActivity.class);
        startActivity(intent);
    }
@@ -764,4 +1042,73 @@
            }
        });
    }
    private void UploadSidList() {
        tv.setText("上报Sid列表...");
        responseTv.setText("");
        //1.设置设备信息
        AuthenticateRequest.AuthenticateDeviceInfoBean authenticateDeviceInfoBean = HDLLinkConfig.getInstance().getDeviceInfoBean();
        ListSidRequest request = new ListSidRequest();
        request.setOid(authenticateDeviceInfoBean.getOID());
        request.setName("sid名称");
        request.setOmodel(authenticateDeviceInfoBean.getDeviceModel());
        request.setSid("12345678");//当前sid的
        request.setSpk("light.switch");//当前spk名称,根据实际设备来定义
        request.setFrom(authenticateDeviceInfoBean.getOID());//来自哪个网关,如果时Link网络设备,则填自身oid;如果是驱动则不需要此字段
        AttributesRequest attributes = new AttributesRequest();
        attributes.setKey("on_off");
        attributes.setData_type("string");
        List<Object> valueList = new ArrayList<>();
        valueList.add("on");
        valueList.add("off");
        attributes.setValue(valueList);
        //添加支持的属性列表
        List<AttributesRequest> attributesList = new ArrayList<>();
        request.setAttributes(attributesList);
        List<ListSidRequest> sidRequestList = new ArrayList<>();
        sidRequestList.add(request);
        HDLLink.getInstance().UploadSidList(sidRequestList, new HDLLinkCallBack() {
            @Override
            public void onError(HDLLinkException error) {
                tv.setText(error.getMsg());
            }
            @Override
            public void onSuccess(String data) {
                tv.setText("上报sid列表成功");
                responseTv.setText(data);
            }
        });
    }
    /**
     * 获取APP版本
     *
     * @param context
     * @return
     */
    public static String getAppVersionName(Context context) {
        String versionName = "0";
        try {
            PackageManager packageManager = context.getPackageManager();
            PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
            versionName = packageInfo.versionName;
            if (TextUtils.isEmpty(versionName)) {
                versionName = "0";
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return versionName;
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();
        removeAllTopicsListener();
    }
}