JLChen
2021-12-02 a03799e08e7cc9b984b89cd125fd01e31f78486d
2021-12-02 1.增加网关认证错误
5个文件已修改
29 ■■■■ 已修改文件
HDLSDK/app/src/main/java/com/hdl/hdlsdk/App.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkCode.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/config/HDLLinkConfig.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
HDLSDK/app/src/main/java/com/hdl/hdlsdk/App.java
@@ -21,7 +21,7 @@
        //初始化SDK
        HDLSdk.getInstance().init(this);
        //控制SDK日志打印
        HDLSdk.getInstance().setLogEnabled(false);
        HDLSdk.getInstance().setLogEnabled(true);
    }
HDLSDK/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -69,6 +69,7 @@
        rv.setLayoutManager(new LinearLayoutManager(this));
        checkIfCertified();
        registerAllTopicsListener();
        ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() {
@@ -281,7 +282,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());
@@ -303,7 +304,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);
@@ -324,7 +325,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("读取成功");
HDLSDK/hdl-common/src/main/java/com/hdl/sdk/common/exception/HDLLinkCode.java
@@ -13,6 +13,7 @@
    HDL_SEND_ERROR(-2003,"发送失败"),
    HDL_TIMEOUT_ERROR(-2004,"超时"),
    HDL_UNAUTHORIZED_ERROR(-2005,"未认证,请先认证"),
    HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED(-2006,"认证失败,网关未注册到云端"),
    HDL_GET_DEVICE_LIST_ERROR(-2100,"获取设备列表失败"),
    HDL_GET_FUNCTION_LIST_ERROR(-2101,"获取功能列表失败"),
    HDL_GET_FUNCTION_PROPERTIES_ERROR(-2102,"获取功能属性失败"),
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/config/HDLLinkConfig.java
@@ -28,6 +28,7 @@
     * instance
     */
    private volatile static HDLLinkConfig instance;
    /**
     * getInstance
     *
@@ -71,6 +72,7 @@
    /**
     * 保存配置
     *
     * @param localSecret
     * @param gatewayId
     * @param ipAddress
@@ -86,6 +88,7 @@
    /**
     * 检测是否已经认证过
     *
     * @return
     */
    public boolean checkIfCertified(){
@@ -127,10 +130,18 @@
    public void setCurrentGateway(GatewaySearchBean currentGateway) {
        this.currentGateway = currentGateway;
        if (this.currentGateway != null && !TextUtils.isEmpty(this.currentGateway.getIp_address())) {
            if (!this.ipAddress.equals(this.currentGateway.getIp_address())) {
                //如果IP地址有变化则更新
                this.ipAddress = this.currentGateway.getIp_address();
                SPUtils.put(AUTHENTICATE_IPADDRESS_KEY, ipAddress);
            }
        }
    }
    /**
     * 判断当前主题数据是否需要加密
     *
     * @param topicStr 当前主题
     * @return
     */
@@ -145,6 +156,7 @@
    /**
     * 拼接网关ID获取完整的主题
     *
     * @param topicStr
     * @return
     */
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/socket/HDLAuthSocket.java
@@ -164,12 +164,17 @@
                    String localSecret = bean.getAuth().getLocalSecret();
                    String gatewayId = bean.getObjects().getGatewayID();
                    String ipAddress = bean.getObjects().getIPAddress();
                    //判断网关是否已经注册到云端
                    if(TextUtils.isEmpty(localSecret) ||TextUtils.isEmpty(gatewayId)){
                        //认证失败,网关未注册到云端
                        callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_AUTH_ERROR_GATEWAY_NOT_REGISTERED));
                    }else{
                    HDLLinkConfig.getInstance().saveConfig(localSecret,gatewayId,ipAddress);
                    callBack.onSuccess("认证成功");
                    }
                }else{
                    callBack.onError(HDLLinkException.getErrorWithCode(HDLLinkCode.HDL_DATA_ERROR));
                }
            }
            @Override