versionCode 1
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
- versionName '2.1.0'
+ versionName '2.1.1'
buildConfigField("String", "SDK_VERSION", "\"${versionName}\"")
multiDexEnabled true
}
}
public void sendConnectState(boolean enable){
- byte[] data = new byte[1];
- data[0] = enable?(byte) (1 & 0xFF):(byte) (0 & 0xFF);
+ byte[] ret = new byte[4];
+ ret = enable?ByteTools.little_intToByte(0,4):ByteTools.little_intToByte(-1,4);
+ byte[] fd = new byte[4];
+ fd = enable?ByteTools.little_intToByte(1,4):ByteTools.little_intToByte(0,4);
MsgBody msgBody = new MsgBody();
msgBody.setService(1);
- msgBody.setData(data);
+ msgBody.setData(ByteTools.concatAll(ret,fd));
msgBody.setType(MsgBody.TYPE_RIDECODE_CONNECT);
BleMsgSendHandler.getInstance().sendMsg(msgBody,null);
SobLog.d(TAG,"sendConnectState--");
@Override
public void onMessageReceived(byte[] message) {
- SobLog.d(TAG,"onMessageReceived--"+ByteTools.byteArrToHex(message));
+ SobLog.d(TAG,"onMessageReceived--"+message.length);
sendSocketMsgToD(message);
}
package com.zhixun.blesdk.hssdk.alisocket;
+import android.os.SystemClock;
+
+import com.zhixun.blesdk.hssdk.bttools.ByteTools;
import com.zhixun.blesdk.hssdk.callback.OnSocketListener;
import com.zhixun.blesdk.hssdk.util.SobLog;
import java.io.BufferedReader;
+import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
private OnSocketListener onSocketListener;
private String serverIpAddress;
private int serverPort;
+ private OutputStream socketOut;
private String TAG = "SocketClient";
public void setSocketListener(OnSocketListener onSocketListener) {
this.onSocketListener = onSocketListener;
// 启动心跳线程
socket.setKeepAlive(true);
mInputStream = socket.getInputStream();
- reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
+ socketOut = socket.getOutputStream();
+ reader = new BufferedReader(new InputStreamReader(mInputStream));
+ writer = new PrintWriter(new OutputStreamWriter(socketOut), true);
startReadMsg();
if (onSocketListener != null) {
onSocketListener.onConnectStateChange(true);
try {
while (!socket.isClosed()) {
- //方法三:基于字符的读取或基于字节的读取,如果bytesRead一直不返回-1,可以尝试替换以下方法
if (mInputStream.available() > 0) {
SobLog.d(TAG,"receiver size--"+mInputStream.available());
byte[] arrayOfByte = new byte[mInputStream.available()];
mInputStream.read(arrayOfByte);
+
if (arrayOfByte.length > 0 && onSocketListener != null) {
// Process the entire content at once
+ SobLog.d(TAG,"receiver --"+ ByteTools.byteArrToHex(arrayOfByte));
onSocketListener.onMessageReceived(arrayOfByte);
}
}
+
+
}
} catch (IOException e) {
e.printStackTrace();
@Override
public void run() {
if (socket != null && socket.isConnected()) {
- writer.println(message);
+ SobLog.d(TAG,"sendMessage --"+ ByteTools.byteArrToHex(message));
+ String tempMsg = "16 03 03 00 a5 01 00 00 a1 03 03 68 05 f6 95 f9 02 8d 97 0a 46 54 54 f9 42 ce 16 57 9f 2b 3c c7 aa d5 17 df 85 16 d5 f4 a3 82 2c 00 00 24 00 9d c0 9d 00 3d 00 35 c0 a1 c0 7b 00 c0 00 84 00 9c c0 9c 00 3c 00 2f c0 a0 c0 7a 00 ba 00 41 00 0a 00 ff 01 00 00 54 00 00 00 16 00 14 00 00 11 69 6f 74 61 70 69 2e 61 6c 69 70 61 79 2e 63 6f 6d 00 0d 00 16 00 14 06 03 06 01 05 03 05 01 04 03 04 01 03 03 03 01 02 03 02 01 00 0a 00 0a 00 08 00 17 00 16 00 14 00 12 00 0b 00 02 01 00 00 16 00 00 00 17 00 00 00 23 00 00";
+// writer.println(ByteTools.hexToByteArr(tempMsg.replace(" ","")));
+ try {
+ socketOut.write(message);
+ if(socketOut!=null){
+ socketOut.flush();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
}
}
}).start();
--- /dev/null
+package com.zhixun.blesdk.hssdk.alisocket;
+
+import com.zhixun.blesdk.hssdk.bttools.ByteTools;
+import com.zhixun.blesdk.hssdk.callback.OnSocketListener;
+import com.zhixun.blesdk.hssdk.util.SobLog;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.security.KeyManagementException;
+import java.security.NoSuchAlgorithmException;
+
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.SSLSocketFactory;
+
+public class SocketClientSSL {
+ private Socket socket;
+ private InputStream mInputStream = null;
+ private BufferedReader reader = null;
+ private PrintWriter writer = null;
+ private OnSocketListener onSocketListener;
+ private String serverIpAddress;
+ private int serverPort;
+ private String TAG = "SocketClientSSL";
+ private OutputStream socketOut;
+ public void setSocketListener(OnSocketListener onSocketListener) {
+ this.onSocketListener = onSocketListener;
+ }
+
+ public void setServerIpAddress(String serverIpAddress) {
+ this.serverIpAddress = serverIpAddress;
+ }
+
+ public void setServerPort(int serverPort) {
+ this.serverPort = serverPort;
+ }
+
+ public void connect(String serverIpAddress,int serverPort) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ // 创建 SSL 上下文
+// SSLContext sslContext = SSLContext.getInstance("TLS");
+// sslContext.init(null, null, null);
+ SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
+
+ // 创建 SSL 套接字并连接到服务器
+ socket = sslSocketFactory.createSocket("www.baidu.com", serverPort);
+ socket.setKeepAlive(true);
+ mInputStream = socket.getInputStream();
+ socketOut = socket.getOutputStream();
+ reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
+ writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
+ startReadMsg();
+ if (onSocketListener != null) {
+ onSocketListener.onConnectStateChange(true);
+ }
+ SobLog.d(TAG,"连接成功");
+ } catch (IOException e) {
+ e.printStackTrace();
+ SobLog.d(TAG,"连接失败"+e.getMessage());
+ if (onSocketListener != null) {
+ onSocketListener.onConnectStateChange(false);
+ }
+ }
+ }
+ }).start();
+ }
+
+ public void startReadMsg() {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+
+
+ try {
+ while (!socket.isClosed()) {
+
+ if (mInputStream.available() > 0) {
+ SobLog.d(TAG,"receiver size--"+mInputStream.available());
+ byte[] arrayOfByte = new byte[mInputStream.available()];
+ mInputStream.read(arrayOfByte);
+
+ if (arrayOfByte.length > 0 && onSocketListener != null) {
+ // Process the entire content at once
+ SobLog.d(TAG,"receiver --"+ ByteTools.getString(arrayOfByte,"UTF8"));
+ onSocketListener.onMessageReceived(arrayOfByte);
+ }
+ }
+
+
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ // 处理连接中断的情况
+ SobLog.d(TAG,"连接中断"+e.getMessage());
+ if (onSocketListener != null) {
+ onSocketListener.onConnectionLost();
+ }
+ }
+ }
+ }).start();
+ }
+
+
+ public void sendMessage(byte[] message) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ if (socket != null && socket.isConnected()) {
+ SobLog.d(TAG,"sendMessage --"+ ByteTools.getString(message,"UTF8"));
+ String tempMsg = "47 45 54 20 2f 69 6e 64 65 78 2e 68 74 6d 6c 20 48 54 54 50 2f 31 2e 31 0a 48 6f 73 74 3a 20 77 77 77 2e 62 61 69 64 75 2e 63 6f 6d 3a 34 34 33 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74 2f 68 74 6d 6c 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 30 0a 0d 0a";
+ SobLog.d(TAG,"tempMsg --"+ ByteTools.getString(ByteTools.hexToByteArr(tempMsg.replace(" ","")),"UTF8"));
+ try {
+ socketOut.write(ByteTools.hexToByteArr(tempMsg.replace(" ","")));
+ if(socketOut!=null){
+ socketOut.flush();
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+
+// writer.println(ByteTools.hexToByteArr(tempMsg.replace(" ","")));
+ }
+ }
+ }).start();
+
+ }
+
+ public void disConnection() {
+ SobLog.d(TAG,"disConnection");
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ if (socket != null && !socket.isClosed()) {
+ socket.close();
+ }
+ if(reader!=null){
+ reader.close();
+ }
+ if(writer!=null){
+ writer.close();
+ }
+ if(socketOut!=null){
+ socketOut.flush();
+ }
+
+ socket = null;
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }).start();
+
+ }
+
+
+
+
+}
import com.zhixun.blesdk.hssdk.callback.OnTrainStateListener;
import com.zhixun.blesdk.hssdk.callback.OnUnBondDeviceCallBack;
import com.zhixun.blesdk.hssdk.data.bean.ReceiverData;
+import com.zhixun.blesdk.hssdk.entity.MsgBody;
import com.zhixun.blesdk.hssdk.util.BleDataUtil;
import com.zhixun.blesdk.hssdk.util.SobLog;
receiverData.setContent(composeData(cacheData));
handData(receiverData);
splitDataMap.remove(receiverData.getType());
-
+ if(data[1]==0x09){
+ //乘车码多包
+ byte[] answer = new byte[1];
+ answer[0] = (byte) (0 & 0xFF);
+ MsgBody msgBody = new MsgBody();
+ msgBody.setService(1);
+ msgBody.setData(answer);
+ msgBody.setType(MsgBody.TYPE_RIDECODE_SPLIT);
+ BleMsgSendHandler.getInstance().sendMsg(msgBody,null);
+ SobLog.d(TAG,"send split --");
+ }
}else {
if (receiverData.getType()==TYPE_GET_WEAR_AUDIO){
receiverLooperThread.startAudioTimeOut();
mSendMsgHandle.sendEmptyMessageDelayed(MSG_SEND,40);
return;
}
- SobLog.d(TAG, "data---" + ByteTools.byteArrToHex(data));
byte[] sendBytes = new byte[data.length-2];
System.arraycopy(data,2,sendBytes,0,sendBytes.length);
- SobLog.d(TAG, "sendBytes---" + ByteTools.byteArrToHex(sendBytes));
int channel = 0xFF & data[0];
int service = 0xFF & data[1];
SobLog.d(TAG, "MSG_SEND---" + ByteTools.byteArrToHex(sendBytes));
import com.zhixun.blesdk.hssdk.HsAgentSdk;
import com.zhixun.blesdk.hssdk.alisocket.RideCodeManager;
-import com.zhixun.blesdk.hssdk.alisocket.SocketClient;
+
import com.zhixun.blesdk.hssdk.bttools.BleHandle;
import com.zhixun.blesdk.hssdk.callback.BtVtransferCallback;
import com.zhixun.blesdk.hssdk.bttools.ByteTools;
case MsgBody.TYPE_RIDECODE_DISCONNECT:
SobLog.d(TAG, "TYPE_RIDECODE_DISCONNECT--");
RideCodeManager.getInstance().disconnect();
+ break;
+ case MsgBody.TYPE_RIDECODE_SPLIT:
+ SobLog.d(TAG, "TYPE_RIDECODE_SPLIT--"+ByteTools.byteArrToHex(content));
+
break;
}
if (callBackMap.containsKey(revData.getType()) && response.getBody() != null) {
message.what = MSG_RECEIVERDATA;
message.obj = data;
mReceiverMsgHandle.sendMessage(message);
+
}
private byte[] audioCache = new byte[0];
public static final int TYPE_RIDECODE_CONNECT = 777;
public static final int TYPE_RIDECODE_MSG = 1033;
public static final int TYPE_RIDECODE_DISCONNECT = 1289;
+ public static final int TYPE_RIDECODE_SPLIT = 65289;
//AI2.0
// public static final int TYPE_START_CHAT = 264;
// public static final int TYPE_CHAT_AUDIO = 520;