| | |
| | | |
| | | import com.chad.library.adapter.base.BaseQuickAdapter; |
| | | import com.chad.library.adapter.base.listener.OnItemClickListener; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.reflect.TypeToken; |
| | | import com.hdl.hdlsdk.device.DevicesListActivity; |
| | | import com.hdl.sdk.common.config.TopicConstant; |
| | | 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.LinkRequest; |
| | | import com.hdl.sdk.connect.bean.LinkResponse; |
| | | import com.hdl.sdk.connect.bean.request.AuthenticateRequest; |
| | | import com.hdl.sdk.connect.bean.request.PropertyReadRequest; |
| | |
| | | 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发送,不回调不重发")); |
| | | demoAdapter = new DemoAdapter(beans); |
| | | rv.setAdapter(demoAdapter); |
| | | |
| | | |
| | | // final SocketOptions options = new SocketOptions(); |
| | | // |
| | | MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // MessagePipeLine pipeLine = new MessagePipeLine(); |
| | | // options.setHandleMessage(pipeLine); |
| | | // options.setEnabledHeartbeat(false); |
| | | |
| | |
| | | //功能列表 |
| | | startDevicesListActivity(); |
| | | break; |
| | | case 9: |
| | | //UDP发送 |
| | | udpSendWithCallback(); |
| | | break; |
| | | case 10: |
| | | //TCP发送 |
| | | tcpSendWithCallback(); |
| | | case 11: |
| | | //UDP发送 |
| | | udpSend(); |
| | | break; |
| | | case 12: |
| | | //TCP发送 |
| | | tcpSend(); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public void showToast(String text) { |
| | | Toast.makeText(this, text, Toast.LENGTH_SHORT).show(); |
| | | } |
| | |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | LinkResponse response = (LinkResponse)msg; |
| | | if(response != null){ |
| | | Log.i(TAG, "AllTopicsListener" |
| | | + "\nTopic: " + response.getTopic() |
| | | +"\n Data: " + response.getData()); |
| | | handleLinkResponse(response); |
| | | } |
| | | |
| | | } |
| | | }; |
| | | HDLLink.getInstance().registerAllTopicsListener(allTopicsListener); |
| | |
| | | tv.setText("开始入网认证..."); |
| | | //认证提交参数准备 |
| | | |
| | | String spkStr = "ir.module";//产品spk |
| | | String macStr = "AA000000000000BB";//设备唯一MAC地址 |
| | | String secret = "87ae414b7a853f65";//通过spk和mac提交云端认证后分配的secret |
| | | String spkStr = "screen.mirror";//产品spk |
| | | String macStr = "AA000000000000AC";//设备唯一MAC地址 |
| | | String secret = "ee62124c151b737c";//通过spk和mac提交云端认证后分配的secret |
| | | String mac_key = stringToMD5(stringToMD5(macStr + secret)); |
| | | String versionString = "HDL_V1.0.1";// |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | |
| | | //1.设置认证信息 |
| | | AuthenticateRequest.RequestBean requestBean = new AuthenticateRequest.RequestBean(); |
| | | requestBean.setMAC(macStr); |
| | | requestBean.setSupplier("HDL"); |
| | | requestBean.setSupplier("raysgem"); |
| | | requestBean.setFirmwareVersion(versionString); |
| | | requestBean.setHardwareModel("1956F"); |
| | | AuthenticateRequest.AuthBean authbean = new AuthenticateRequest.AuthBean(); |
| | |
| | | infoBean.setDeviceName("红外宝");//设备名字 |
| | | infoBean.setDeviceModel("HDL");// |
| | | infoBean.setAccessMode("WIFI"); |
| | | infoBean.setIPGateway("192.168.12.1"); |
| | | infoBean.setIPGateway("192.168.88.1"); |
| | | infoBean.setIPAddress(IpUtils.getIP(this)); |
| | | |
| | | infoBean.setOID("010105000000FE08"); |
| | |
| | | Intent intent = new Intent(this, DevicesListActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | |
| | | /** |
| | | * TCP发送,监听主题回复,带重发带回调 |
| | | */ |
| | | private void tcpSendWithCallback() { |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("id", IdUtils.getUUId()); |
| | | jsonObject.addProperty("time_stamp", time); |
| | | HDLLink.getInstance().tcpSendMsg(TopicConstant.GATEWAY_SEARCH, jsonObject.toString(), new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | responseTv.setText(data); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * UDP发送,监听主题回复,带重发带回调 |
| | | */ |
| | | private void udpSendWithCallback() { |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("id", IdUtils.getUUId()); |
| | | jsonObject.addProperty("time_stamp", time); |
| | | HDLLink.getInstance().udpSendMsg(TopicConstant.GATEWAY_SEARCH, jsonObject.toString(), new HDLLinkResponseCallBack() { |
| | | @Override |
| | | public void onSuccess(LinkResponse linkResponse) { |
| | | if(linkResponse != null){ |
| | | responseTv.setText(linkResponse.getData()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * TCP发送 只发一次,不监听回复,不重发 |
| | | */ |
| | | private void tcpSend() { |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("id", IdUtils.getUUId()); |
| | | jsonObject.addProperty("time_stamp", time); |
| | | HDLLink.getInstance().tcpSendMsg(TopicConstant.GATEWAY_SEARCH, jsonObject.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 只发一次,不监听回复,不重发 |
| | | */ |
| | | private void udpSend() { |
| | | String time = String.valueOf(System.currentTimeMillis()); |
| | | JsonObject jsonObject = new JsonObject(); |
| | | jsonObject.addProperty("id", IdUtils.getUUId()); |
| | | jsonObject.addProperty("time_stamp", time); |
| | | HDLLink.getInstance().udpSendMsg(TopicConstant.GATEWAY_SEARCH, jsonObject.toString()); |
| | | } |
| | | } |