panlili2024
9 天以前 84bb9a10e795b8839d9770eeb37aab71bf22e107
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;
@@ -59,6 +61,7 @@
import com.hdl.sdk.connect.cloud.bean.AiLoginInfo;
import com.hdl.sdk.connect.config.HDLLinkConfig;
import com.hdl.sdk.connect.socket.HDLAuthSocket;
import com.hdl.sdk.connect.socket.HDLSocket;
import com.hdl.sdk.sourceos.utils.SPKey;
import java.io.UnsupportedEncodingException;
@@ -81,8 +84,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 +95,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 +231,7 @@
        selectnetwork();
        checkIfCertified();
        //initDeviceInfo();//不走从机入网的方式不需要初始化
        initDeviceInfo();//不走从机入网的方式不需要初始化,走从机入网则需要初始化
        registerAllTopicsListener();
        HDLLink.getInstance().setDeleteNetworkListener(new DeleteNetworkListener() {
            @Override
@@ -411,11 +414,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 +477,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 +511,7 @@
        //认证提交参数准备
        //正式服务器
        String spkStr = "screen.mirror";//产品spk
        String spkStr = "screen.touch";//产品spk
        String macStr = "f2c5d8bad48f";//设备唯一MAC地址
        String mac_key = stringToMD5(stringToMD5(macStr + secret));
@@ -596,37 +600,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 +633,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 +699,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);
@@ -1009,6 +1001,7 @@
        String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId());
        String bodyStr = getPropertyDownBodyStr();
        HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr);
    }
    /**