| | |
| | | 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); |
| | | |
| | |
| | | //TCP发送 |
| | | tcpSend(); |
| | | break; |
| | | case 11: |
| | | //UDP发送,监听主题回复,带重发带回调 |
| | | udpSendWithCallback(); |
| | | break; |
| | | case 12: |
| | | //TCP发送,监听主题回复,带重发带回调 |
| | | tcpSendWithCallback(); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | |
| | | public void showToast(String text) { |
| | |
| | | |
| | | /** |
| | | * 处理收到的主题 |
| | | * |
| | | * @param response |
| | | */ |
| | | private void handleLinkResponse(LinkResponse response){ |
| | |
| | | tv.setText("网关不在线"); |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | |
| | | @Override |
| | | public void onSuccess(GatewaySearchBean gatewaySearchBean) { |
| | | tv.setText("网关在线"); |
| | |
| | | tv.setText("读取成功"); |
| | | responseTv.setText(data); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | tv.setText("读取失败"); |
| | |
| | | |
| | | //场景列表 |
| | | // {"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"}]} |
| | | |
| | | /** |
| | | * 控制场景 |
| | | * 执行成功的话 响应code为200 |
| | |
| | | * TCP发送 只发一次,不监听回复,不重发 |
| | | */ |
| | | private void tcpSend() { |
| | | tv.setText("TCP发送 只发一次,不监听回复,不重发"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr); |
| | | } |
| | | |
| | | /** |
| | | * 只发一次,不监听回复,不重发 |
| | | * UDP只发一次,不监听回复,不重发 |
| | | */ |
| | | private void udpSend() { |
| | | tv.setText("UDP发送 只发一次,不监听回复,不重发"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr); |
| | |
| | | |
| | | return GsonConvert.getGson().toJson(data); |
| | | } |
| | | |
| | | /** |
| | | * UDP发送,监听主题回复,带重发带回调 |
| | | */ |
| | | private void udpSendWithCallback() { |
| | | tv.setText("UDP发送,监听主题回复,带重发带回调"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().udpSendMsg(propertyDownTopic, bodyStr, new HDLLinkResponseCallBack() { |
| | | @Override |
| | | public void onSuccess(LinkResponse msg) { |
| | | Log.i("udpSendWithCallback", "udpSendWithCallback"); |
| | | responseTv.setText(GsonConvert.getGson().toJson(msg)); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * TCP发送,监听主题回复,带重发带回调 |
| | | */ |
| | | private void tcpSendWithCallback() { |
| | | tv.setText("TCP发送,监听主题回复,带重发带回调"); |
| | | String propertyDownTopic = String.format(TopicConstant.PROPERTY_DOWN, HDLLinkConfig.getInstance().getGatewayId()); |
| | | String bodyStr = getPropertyDownBodyStr(); |
| | | HDLLink.getInstance().tcpSendMsg(propertyDownTopic, bodyStr, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String msg) { |
| | | Log.i("tcpSendWithCallback", "tcpSendWithCallback"); |
| | | responseTv.setText(msg); |
| | | } |
| | | |
| | | @Override |
| | | public void onError(HDLLinkException e) { |
| | | responseTv.setText(e.getMsg()); |
| | | } |
| | | }); |
| | | } |
| | | } |