From 27a0768b0e0a042911b7f299fcc599d2da4e7fc0 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期一, 13 十二月 2021 10:36:52 +0800
Subject: [PATCH] 更改了udp测试后版本
---
HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java | 111 +++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 98 insertions(+), 13 deletions(-)
diff --git a/HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java b/HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
index 44815ae..d6c6e37 100644
--- a/HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
+++ b/HDLSDK_DEMO/app/src/main/java/com/hdl/hdlsdk/MainActivity.java
@@ -19,14 +19,17 @@
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;
@@ -100,13 +103,17 @@
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);
@@ -150,10 +157,29 @@
//鍔熻兘鍒楄〃
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();
}
@@ -176,13 +202,6 @@
@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);
@@ -238,9 +257,9 @@
tv.setText("寮�濮嬪叆缃戣璇�...");
//璁よ瘉鎻愪氦鍙傛暟鍑嗗
- String spkStr = "ir.module";//浜у搧spk
- String macStr = "AA000000000000BB";//璁惧鍞竴MAC鍦板潃
- String secret = "87ae414b7a853f65";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
+ String spkStr = "screen.mirror";//浜у搧spk
+ String macStr = "AA000000000000AC";//璁惧鍞竴MAC鍦板潃
+ String secret = "ee62124c151b737c";//閫氳繃spk鍜宮ac鎻愪氦浜戠璁よ瘉鍚庡垎閰嶇殑secret
String mac_key = stringToMD5(stringToMD5(macStr + secret));
String versionString = "HDL_V1.0.1";//
String time = String.valueOf(System.currentTimeMillis());
@@ -248,7 +267,7 @@
//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();
@@ -263,7 +282,7 @@
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");
@@ -476,4 +495,70 @@
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());
+ }
}
\ No newline at end of file
--
Gitblit v1.8.0