| | |
| | | <component name="GradleSettings">
|
| | | <option name="linkedExternalProjectsSettings">
|
| | | <GradleProjectSettings>
|
| | | <option name="testRunner" value="GRADLE" />
|
| | | <option name="distributionType" value="DEFAULT_WRAPPED" />
|
| | | <option name="externalProjectPath" value="$PROJECT_DIR$" />
|
| | | <option name="gradleJvm" value="Embedded JDK" />
|
| | | <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
|
| | | <option name="modules">
|
| | | <set>
|
| | | <option value="$PROJECT_DIR$" />
|
| | | <option value="$PROJECT_DIR$/app" />
|
| | | <option value="$PROJECT_DIR$/com.hdl.sdk" />
|
| | | <option value="$PROJECT_DIR$/hdl-connect" />
|
| | | </set>
|
| | | </option>
|
| | | <option name="resolveModulePerSourceSet" value="false" />
|
| | | <option name="resolveExternalAnnotations" value="false" />
|
| | | </GradleProjectSettings>
|
| | | </option>
|
| | | </component>
|
| | |
| | | @Override |
| | | public void onMessage(Object msg) { |
| | | LinkResponse response = (LinkResponse) msg; |
| | | Log.i("onMessage", "response.getTopic():" + response.getTopic()); |
| | | if ("/user/all/custom/gateway/broadcast_reply".equals(response.getTopic())) { |
| | | localSecret.setText("密钥:" + HDLLinkConfig.getInstance().getLocalSecret()); |
| | | |
| | | } |
| | | } |
| | | }; |
| | |
| | | HDLLink.getInstance().removeAllTopicsListener(allTopicsListener); |
| | | } |
| | | |
| | | void initDeviceInfo() |
| | | { |
| | | void initDeviceInfo() { |
| | | AuthenticateRequest.AuthenticateDeviceInfoBean infoBean = new AuthenticateRequest.AuthenticateDeviceInfoBean(); |
| | | infoBean.setDeviceMAC("f2c5d8bad48f"); |
| | | infoBean.setIPMAC("f2c5d8bad48f"); |
| | |
| | | infoBean.setDeviceModel("HDLSDK");//设备型号 |
| | | infoBean.setAccessMode("WIFI"); |
| | | infoBean.setIPGateway("192.168.1.1"); |
| | | infoBean.setIPAddress("192.168.1.116"); |
| | | infoBean.setIPAddress("192.168.1.103"); |
| | | infoBean.setGateway_type("screen.touch"); |
| | | infoBean.setHw_version("HW2.0"); |
| | | infoBean.setFw_version("Fw1.0"); |
| | |
| | | statusBeanList.add(bean); |
| | | request.setStatus(statusBeanList); |
| | | requestList.add(request); |
| | | |
| | | HDLLink.getInstance().propertyDown(requestList, new HDLLinkCallBack() { |
| | | @Override |
| | | public void onSuccess(String data) { |
| | |
| | | AttributesRequest attributes = new AttributesRequest(); |
| | | attributes.setKey("on_off"); |
| | | attributes.setData_type("string"); |
| | | List<Object> valueList=new ArrayList<>(); |
| | | List<Object> valueList = new ArrayList<>(); |
| | | valueList.add("on"); |
| | | valueList.add("off"); |
| | | attributes.setValue(valueList); |
| | |
| | | defaultConfig { |
| | | minSdkVersion rootProject.minSdkVersion |
| | | targetSdkVersion rootProject.targetSdkVersion |
| | | versionCode 117 |
| | | versionName "1.1.7" |
| | | versionCode 118 |
| | | versionName "1.1.8" |
| | | } |
| | | buildTypes { |
| | | debug { |
| | |
| | | defaultConfig { |
| | | minSdkVersion rootProject.minSdkVersion |
| | | targetSdkVersion rootProject.targetSdkVersion |
| | | versionCode 5 |
| | | versionName "1.1.3" |
| | | versionCode 6 |
| | | versionName "1.1.8" |
| | | |
| | | consumerProguardFiles "consumer-rules.pro" |
| | | } |
| | |
| | | */ |
| | | public void UploadDeviceAuth(String mac, String result, String message, String auth_code, HDLLinkCallBack callBack) { |
| | | HDLSocket.getInstance().UploadDeviceAuth(mac, result, message, auth_code, callBack); |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | |
|
| | | if (encrypt(body)) {
|
| | | //需要解密
|
| | | byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret());
|
| | | if (bodyBytes != null) {
|
| | | response.setData(new String(bodyBytes, StandardCharsets.UTF_8));
|
| | | } else {
|
| | | LogUtils.e("解密失败\r\n" + topic);
|
| | | response.setData(new String(body, "utf-8"));
|
| | | continue;
|
| | | if (!TextUtils.isEmpty(HDLLinkConfig.getInstance().getLocalSecret())) {
|
| | | byte[] bodyBytes = AesUtil.aesDecrypt(body, HDLLinkConfig.getInstance().getLocalSecret());
|
| | | if (bodyBytes != null) {
|
| | | response.setData(new String(bodyBytes, StandardCharsets.UTF_8));
|
| | | } else {
|
| | | LogUtils.e("解密失败\r\n" + topic);
|
| | | response.setData(new String(body, "utf-8"));
|
| | | continue;
|
| | | }
|
| | | }
|
| | | } else {
|
| | | response.setData(new String(body, "utf-8"));
|
| | |
| | | |
| | | import com.hdl.sdk.common.utils.IpUtils; |
| | | import com.hdl.sdk.common.utils.LogUtils; |
| | | import com.hdl.sdk.socket.SocketBoot; |
| | | import com.hdl.sdk.socket.SocketOptions; |
| | | import com.hdl.sdk.socket.SocketPool; |
| | | import com.hdl.sdk.socket.codec.IHandleMessage; |
| | | import com.hdl.sdk.socket.udp.UdpSocketBoot; |
| | | import com.hdl.sdk.socket.udp.UdpSocketOptions; |
| | | import com.hdl.sdk.socket.codec.IHandleMessage; |
| | | |
| | | import java.io.IOException; |
| | | import java.net.DatagramPacket; |
| | | import java.net.DatagramSocket; |
| | | import java.net.InetAddress; |
| | | import java.net.InetSocketAddress; |
| | | import java.net.SocketAddress; |
| | | import java.util.concurrent.atomic.AtomicBoolean; |
| | | |
| | | |
| | | /** |
| | |
| | | /** |
| | | * 当前socket |
| | | */ |
| | | private DatagramSocket mSocket; |
| | | private DatagramSocket mSocket; |
| | | |
| | | /** |
| | | * 接收数据包 |
| | |
| | | |
| | | /** |
| | | * 初始化参数 |
| | | * @param ipAddress 本地监听端口 |
| | | * @param port 本地监听端口 |
| | | * |
| | | * @param ipAddress 本地监听端口 |
| | | * @param port 本地监听端口 |
| | | * @param socketOptions |
| | | */ |
| | | private UdpClient(String ipAddress,int port, UdpSocketOptions socketOptions) { |
| | | private UdpClient(String ipAddress, int port, UdpSocketOptions socketOptions) { |
| | | this.ipAddress = ipAddress; |
| | | this.port = port; |
| | | this.socketOptions = socketOptions; |
| | |
| | | |
| | | /** |
| | | * 初始化参数 |
| | | * |
| | | * @param ipAddress 本地监听IP地址 |
| | | * @param port 本地监听端口 |
| | | * @param port 本地监听端口 |
| | | * @param options |
| | | * @return |
| | | */ |
| | |
| | | |
| | | /** |
| | | * 初始化参数 |
| | | * @param port 本地监听端口 |
| | | * |
| | | * @param port 本地监听端口 |
| | | * @param options |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | if (TextUtils.isEmpty(ipAddress)) { |
| | | mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(port)); |
| | | }else { |
| | | mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(ipAddress,port)); |
| | | } else { |
| | | mSocket = SocketPool.getInstance().getUdpSocket(new InetSocketAddress(ipAddress, port)); |
| | | } |
| | | mSocket.setBroadcast(true); |
| | | // mSocket.setReuseAddress(true); |
| | |
| | | if (handleMessage != null) { |
| | | byte[] data = new byte[receivePacket.getLength()]; |
| | | System.arraycopy(receivePacket.getData(), 0, data, 0, data.length); |
| | | handleMessage.read(data,receivePacket.getAddress().getHostAddress()); |
| | | handleMessage.read(data, receivePacket.getAddress().getHostAddress()); |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | |
| | | |
| | | |
| | | @Override |
| | | public void sendMsg(String ipAddress,int port, byte[] msg) throws Exception { |
| | | public void sendMsg(String ipAddress, int port, byte[] msg) throws Exception { |
| | | if (msg == null) { |
| | | return; |
| | | } |
| | | final DatagramPacket sendPacket = new DatagramPacket(msg, msg.length, InetAddress.getByName(ipAddress), port); |
| | | mSocket.send(sendPacket); |
| | | if (mSocket != null && sendPacket != null) { |
| | | mSocket.send(sendPacket); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 绑定 socket |
| | | * |
| | | * @throws Exception 可能端口冲突 |
| | | */ |
| | | public void bind() throws Exception { |
| | |
| | | * 初始化接收线程 |
| | | */ |
| | | private void initReceiveThread() { |
| | | if(null!=receiveThread){ |
| | | if (null != receiveThread) { |
| | | return; |
| | | } |
| | | receiveThread = ThreadToolUtils.getInstance().newFixedThreadPool(1); |
| | |
| | | try { |
| | | client.onHandleResponse(); |
| | | } catch (Exception e) { |
| | | LogUtils.i("接收线程异常:"+e.getMessage()); |
| | | LogUtils.i("接收线程异常:" + e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | /** |
| | | * 发送数据 |
| | | * |
| | | * @param ipAddress 目的的IP地址 |
| | | * @param port 端口 |
| | | * @param msg 发送数据 |
| | | * @param listener 发送回调 |
| | | * @param port 端口 |
| | | * @param msg 发送数据 |
| | | * @param listener 发送回调 |
| | | */ |
| | | public void sendMsg(String ipAddress,int port,byte[] msg, SendListener listener) { |
| | | sendMsg(ipAddress,port, msg, true, listener); |
| | | public void sendMsg(String ipAddress, int port, byte[] msg, SendListener listener) { |
| | | sendMsg(ipAddress, port, msg, true, listener); |
| | | } |
| | | |
| | | /** |
| | | * 发送数据 |
| | | * |
| | | * @param ipAddress 目的的IP地址 |
| | | * @param port 端口 |
| | | * @param msg 发送数据 |
| | | * @param port 端口 |
| | | * @param msg 发送数据 |
| | | */ |
| | | public void sendMsg(String ipAddress,int port,byte[] msg) { |
| | | sendMsg(ipAddress,port, msg, true, null); |
| | | public void sendMsg(String ipAddress, int port, byte[] msg) { |
| | | sendMsg(ipAddress, port, msg, true, null); |
| | | } |
| | | |
| | | /** |
| | | * 发送数据 |
| | | * @param ipAddress 目的IP地址 |
| | | * @param port 端口 |
| | | * @param msg 发送的数据 |
| | | * |
| | | * @param ipAddress 目的IP地址 |
| | | * @param port 端口 |
| | | * @param msg 发送的数据 |
| | | * @param isRefreshRetry 是否要重发 |
| | | * @param listener 发送回调 |
| | | * @param listener 发送回调 |
| | | */ |
| | | public void sendMsg(String ipAddress,int port, byte[] msg, boolean isRefreshRetry, SendListener listener) { |
| | | public void sendMsg(String ipAddress, int port, byte[] msg, boolean isRefreshRetry, SendListener listener) { |
| | | if (isRefreshRetry) { |
| | | //重置连接次数 |
| | | resendCount.set(0); |
| | |
| | | isOpenRetry.set(false); |
| | | sendMap.clear(); |
| | | receiveThread.shutdown(); |
| | | receiveThread=null; |
| | | receiveThread = null; |
| | | client.close(); |
| | | } |
| | | } |
| | |
| | | |
| | | //include ':app' |
| | | include ':app' |
| | | //include ':hdl-socket' |
| | | include ':hdl-connect' |
| | | //include ':hdl-common' |