| | |
| | | import android.Manifest; |
| | | import android.app.Instrumentation; |
| | | import android.os.Bundle; |
| | | import android.util.Log; |
| | | import android.view.View; |
| | | import android.widget.TextView; |
| | | |
| | | import com.chad.library.adapter.base.BaseQuickAdapter; |
| | | import com.chad.library.adapter.base.listener.OnItemClickListener; |
| | | import com.google.gson.JsonObject; |
| | | import com.hdl.sdk.common.config.AuthenticateConfig; |
| | | import com.hdl.sdk.common.config.TopicConstant; |
| | | import com.hdl.sdk.common.utils.IdUtils; |
| | | import com.hdl.sdk.common.utils.IpUtils; |
| | | import com.hdl.sdk.connect.HDLAuthSocket; |
| | | import com.hdl.sdk.connect.HDLSocket; |
| | | import com.hdl.sdk.connect.bean.DeviceControlRequest; |
| | | import com.hdl.sdk.connect.bean.GatewaySearchBean; |
| | | import com.hdl.sdk.connect.bean.LinkRequest; |
| | | import com.hdl.sdk.connect.protocol.LinkMessageDecoder; |
| | | import com.hdl.sdk.connect.protocol.LinkMessageEncoder; |
| | |
| | | private RecyclerView rv; |
| | | private TextView tv; |
| | | private TextView responseTv; |
| | | |
| | | boolean isOn; |
| | | |
| | | |
| | | @Override |
| | |
| | | tv = findViewById(R.id.state_tv); |
| | | rv = findViewById(R.id.rv); |
| | | rv.setLayoutManager(new LinearLayoutManager(this)); |
| | | AuthenticateConfig.getInstance().setLocalEncrypt(true); |
| | | AuthenticateConfig.getInstance().setLocalSecret("5648d9b9cafd30dd"); |
| | | |
| | | ActivityResultLauncher<String[]> launcher = registerForActivityResult(new ActivityResultContracts.RequestMultiplePermissions(), new ActivityResultCallback<Map<String, Boolean>>() { |
| | | @Override |
| | |
| | | beans.add(new DemoBean("设备控制")); |
| | | beans.add(new DemoBean("状态上报")); |
| | | beans.add(new DemoBean("读取状态")); |
| | | beans.add(new DemoBean("入网认证")); |
| | | demoAdapter = new DemoAdapter(beans); |
| | | rv.setAdapter(demoAdapter); |
| | | |
| | |
| | | break; |
| | | case 3: |
| | | //设备控制 |
| | | // HDLSocket.getInstance().propertyDown(); |
| | | isOn = !isOn; |
| | | List<DeviceControlRequest> requestList = new ArrayList<>(); |
| | | DeviceControlRequest request = new DeviceControlRequest(); |
| | | request.setSid("000101B847C71B02020100010101"); |
| | | List<DeviceControlRequest.StatusBean> statusBeanList= new ArrayList<>(); |
| | | DeviceControlRequest.StatusBean bean = new DeviceControlRequest.StatusBean(); |
| | | bean.setKey("on_off"); |
| | | bean.setValue(isOn ? "on" : "off"); |
| | | statusBeanList.add(bean); |
| | | request.setStatus(statusBeanList); |
| | | requestList.add(request); |
| | | HDLAuthSocket.getInstance().propertyDown(requestList,null); |
| | | |
| | | |
| | | break; |
| | | case 4: |
| | | //状态上报 |
| | |
| | | //读取状态 |
| | | // HDLSocket.getInstance().propertyRead(); |
| | | break; |
| | | case 6: |
| | | //入网认证 |
| | | HDLAuthSocket.getInstance().sendAuthenticateRequest(new HDLAuthSocket.CallBack() { |
| | | @Override |
| | | public void onError(String error) { |
| | | Log.i("TAG", "onError: 认证失败"); |
| | | // tv.setText("认证失败"); |
| | | // responseTv.setText(error); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | tv.setText("认证成功"); |
| | | responseTv.setText(data); |
| | | } |
| | | }); |
| | | |
| | | // HDLAuthSocket.getInstance().searchGateway("1406844230123372545", new HDLAuthSocket.SearchGatewayCallBack() { |
| | | // @Override |
| | | // public void onEnd(String error) { |
| | | // |
| | | // } |
| | | // |
| | | // @Override |
| | | // public void onSuccess(GatewaySearchBean gatewaySearchBean) { |
| | | // Log.i("TAG", "onSuccess: 搜索成功:"+gatewaySearchBean.getGatewayId()); |
| | | // } |
| | | // }); |
| | | |
| | | |
| | | break; |
| | | } |
| | | } |
| | | }); |