versionCode 1
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
- versionName '2.0.0'
+ versionName '2.1.0'
buildConfigField("String", "SDK_VERSION", "\"${versionName}\"")
multiDexEnabled true
}
buildTypes {
release {
- minifyEnabled true
+ minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+
+ <application >
+ <receiver android:name=".alisocket.NetworkStateReceiver"
+ android:exported="true">
+ <intent-filter>
+ <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
+ </intent-filter>
+ </receiver>
+ </application>
</manifest>
\ No newline at end of file
--- /dev/null
+package com.zhixun.blesdk.hssdk.alisocket;
+
+import static android.graphics.Color.BLACK;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
+
+import com.zhixun.blesdk.hssdk.util.SobLog;
+
+public class NetworkStateReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+
+
+ if (ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) {
+ NetworkInfo info =
+ intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
+ if (info == null) {
+ return;
+ }
+ if (info.getState() == NetworkInfo.State.CONNECTED && info.isAvailable()) {
+ if (info.getType() == ConnectivityManager.TYPE_WIFI
+ || info.getType() == ConnectivityManager.TYPE_MOBILE) {
+ SobLog.d("NetworkStateReceiver","有网");
+ RideCodeManager.getInstance().sendNetWorkState(true);
+ return;
+ }
+ }
+ SobLog.d("NetworkStateReceiver","无网");
+ RideCodeManager.getInstance().sendNetWorkState(false);
+ }
+
+ }
+}
--- /dev/null
+package com.zhixun.blesdk.hssdk.alisocket;
+
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+
+import androidx.annotation.NonNull;
+
+import com.zhixun.blesdk.hssdk.bttools.BleHandle;
+import com.zhixun.blesdk.hssdk.bttools.ByteTools;
+import com.zhixun.blesdk.hssdk.callback.OnSocketListener;
+import com.zhixun.blesdk.hssdk.data.BleMsgReceiverHandler;
+import com.zhixun.blesdk.hssdk.data.BleMsgSendHandler;
+import com.zhixun.blesdk.hssdk.data.ReceiverLooperThread;
+import com.zhixun.blesdk.hssdk.entity.MsgBody;
+import com.zhixun.blesdk.hssdk.util.SobLog;
+
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Iterator;
+
+public class RideCodeManager implements OnSocketListener {
+ private static RideCodeManager sInstance;
+ private String TAG = "RideCodeManager";
+
+ private RideCodeMsgLooperThread rideCodeMsgLooperThread;
+ private SocketClient client;
+ public static RideCodeManager getInstance() {
+ if (sInstance == null) {
+ synchronized (RideCodeManager.class) {
+ if (null == sInstance)
+ sInstance = new RideCodeManager();
+ }
+ }
+
+ return sInstance;
+ }
+
+ public void init(){
+ if (rideCodeMsgLooperThread == null) {
+ rideCodeMsgLooperThread = new RideCodeMsgLooperThread();
+ rideCodeMsgLooperThread.start();
+ }
+ }
+
+ public void receiverMsg(byte[] msg){
+
+ }
+
+ public void iPInetAddress(String domain)
+ {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ String ipv4Address = "";
+ try {
+ InetAddress[] inetAddresses = InetAddress.getAllByName(domain);
+ for (InetAddress inetAddress : inetAddresses) {
+ if (inetAddress instanceof Inet4Address) {
+ ipv4Address = inetAddress.getHostAddress();
+ break;
+ }
+ }
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ if(ipv4Address == null || ipv4Address.isEmpty()){
+ SobLog.d(TAG,"ipv4Address is null");
+ return;
+ }
+ sendIpRespons(getDnsResponseFrame(ipv4Address));
+ }
+ }).start();
+
+ }
+
+ /**
+ * 手机响应dns解析帧value结构
+ *
+ * @param ipv4Address ipv4信息
+ * @return byte[]
+ */
+ private byte[] getDnsResponseFrame(String ipv4Address) {
+ SobLog.d(TAG,"sendIpRespons--"+ipv4Address);
+
+ byte[] ipByteList = new byte[4];
+ String[] ipSplitList = ipv4Address.split("\\.");
+ for (int i = 0; i < ipSplitList.length; i++) {
+ ipByteList[i] = (byte) Integer.parseInt(ipSplitList[i], 10);
+ }
+ return ipByteList;
+ }
+
+ public void connectClient(String address,int port){
+ SobLog.d(TAG,"connectClient--"+address+":"+port);
+ client = new SocketClient();
+ client.connect(address,port);
+ client.setSocketListener(this);
+ }
+
+ public void sendMsgToService(byte[] msg){
+ SobLog.d(TAG,"sendMsgToService--");
+ if(client!=null){
+ client.sendMessage(msg);
+ }
+ }
+
+ public void disconnect(){
+ if(client!=null){
+ client.disConnection();
+ }
+ }
+
+ private void sendIpRespons(byte[] ipv4Address){
+
+ byte[] data = ipv4Address;
+ MsgBody msgBody = new MsgBody();
+ msgBody.setService(1);
+ msgBody.setData(data);
+ msgBody.setType(MsgBody.TYPE_RIDECODE_DNS);
+ BleMsgSendHandler.getInstance().sendMsg(msgBody,null);
+ }
+
+ public void sendNetWorkState(boolean enable){
+
+ byte[] data = new byte[1];
+ data[0] = enable?(byte) (1 & 0xFF):(byte) (0 & 0xFF);
+ MsgBody msgBody = new MsgBody();
+ msgBody.setService(1);
+ msgBody.setData(data);
+ msgBody.setType(MsgBody.TYPE_RIDECODE_NETSTATE);
+ BleMsgSendHandler.getInstance().sendMsg(msgBody,null);
+ SobLog.d(TAG,"sendNetWorkState--");
+ }
+
+ public void sendConnectState(boolean enable){
+ byte[] data = new byte[1];
+ data[0] = enable?(byte) (1 & 0xFF):(byte) (0 & 0xFF);
+ MsgBody msgBody = new MsgBody();
+ msgBody.setService(1);
+ msgBody.setData(data);
+ msgBody.setType(MsgBody.TYPE_RIDECODE_CONNECT);
+ BleMsgSendHandler.getInstance().sendMsg(msgBody,null);
+ SobLog.d(TAG,"sendConnectState--");
+ }
+ private void sendSocketMsgToD(byte[] msg){
+ SobLog.d(TAG,"sendSocketMsgToD--");
+ MsgBody msgBody = new MsgBody();
+ msgBody.setService(1);
+ msgBody.setData(msg);
+ msgBody.setType(MsgBody.TYPE_RIDECODE_MSG);
+ BleMsgSendHandler.getInstance().sendMsg(msgBody,null);
+
+ }
+
+ @Override
+ public void onMessageReceived(byte[] message) {
+ SobLog.d(TAG,"onMessageReceived--"+ByteTools.byteArrToHex(message));
+ sendSocketMsgToD(message);
+ }
+
+ @Override
+ public void onConnectStateChange(boolean state) {
+ SobLog.d(TAG,"onConnectStateChange--");
+ sendConnectState(state);
+ }
+
+ @Override
+ public void onConnectionLost() {
+ SobLog.d(TAG,"onConnectionLost--");
+ }
+
+ private final int MSG_SEND = 101;//发送数据
+ private Handler msgHandler;
+ // private final int MSG_CHECKSENDMSG = 102;//检测普通数据
+ private class RideCodeMsgLooperThread extends Thread {
+
+ public void run() {
+ Looper.prepare();
+ msgHandler = new Handler(Looper.myLooper()) {
+ @Override
+ public void handleMessage(@NonNull Message msg) {
+ super.handleMessage(msg);
+ switch (msg.what) {
+
+
+ }
+ }
+ };
+ Looper.loop();
+
+
+ }
+ }
+}
package com.zhixun.blesdk.hssdk.alisocket;
+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;
private InputStream mInputStream = null;
private BufferedReader reader = null;
private PrintWriter writer = null;
- private OnMessageReceivedListener messageListener;
+ private OnSocketListener onSocketListener;
private String serverIpAddress;
private int serverPort;
+ private String TAG = "SocketClient";
+ public void setSocketListener(OnSocketListener onSocketListener) {
+ this.onSocketListener = onSocketListener;
+ }
public void setServerIpAddress(String serverIpAddress) {
this.serverIpAddress = serverIpAddress;
this.serverPort = serverPort;
}
- public void connect() {
- try {
- socket = new Socket();
- SocketAddress socAddress = new InetSocketAddress(serverIpAddress, serverPort);
- socket.connect(socAddress, 2000);
- // 启动心跳线程
- socket.setKeepAlive(true);
- mInputStream = socket.getInputStream();
- reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- writer = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()), true);
- startReadMsg();
- } catch (IOException e) {
- e.printStackTrace();
- }
+ public void connect(String serverIpAddress,int serverPort) {
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ socket = new Socket();
+ SocketAddress socAddress = new InetSocketAddress(serverIpAddress, serverPort);
+ socket.connect(socAddress, 2000);
+ // 启动心跳线程
+ socket.setKeepAlive(true);
+ mInputStream = socket.getInputStream();
+ 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() {
@Override
public void run() {
- byte[] arrayOfByte = new byte[1024];
+
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 && messageListener != null) {
+ if (arrayOfByte.length > 0 && onSocketListener != null) {
// Process the entire content at once
- messageListener.onMessageReceived(arrayOfByte);
+ onSocketListener.onMessageReceived(arrayOfByte);
}
}
}
} catch (IOException e) {
e.printStackTrace();
// 处理连接中断的情况
- if (messageListener != null) {
- messageListener.onConnectionLost();
+ SobLog.d(TAG,"连接中断"+e.getMessage());
+ if (onSocketListener != null) {
+ onSocketListener.onConnectionLost();
}
}
}
public void sendMessage(byte[] message) {
- if (socket != null && socket.isConnected()) {
- writer.println(message);
- }
+ new Thread(new Runnable() {
+ @Override
+ public void run() {
+ if (socket != null && socket.isConnected()) {
+ writer.println(message);
+ }
+ }
+ }).start();
+
}
public void disConnection() {
+ SobLog.d(TAG,"disConnection");
try {
if (socket != null && !socket.isClosed()) {
socket.close();
}
- reader.close();
- writer.close();
+ if(reader!=null){
+ reader.close();
+ }
+ if(writer!=null){
+ writer.close();
+ }
+
+ socket = null;
} catch (IOException e) {
e.printStackTrace();
}
}
- public interface OnMessageReceivedListener {
- void onMessageReceived(byte[] message);
- void onConnectionLost();
- }
}
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import com.google.gson.Gson;
import com.zhixun.blesdk.hssdk.HsAgentSdk;
+import com.zhixun.blesdk.hssdk.alisocket.RideCodeManager;
import com.zhixun.blesdk.hssdk.callback.BtVtransferCallback;
import com.zhixun.blesdk.hssdk.callback.IBtScanCallback;
import com.zhixun.blesdk.hssdk.callback.OnBleControlCallback;
SobLog.d(TAG, "BLE Discover Service Success!!!");
deviceNotifyEnable();
readInitMsg();
+ }else if (BleUuidUtil.getInstance().getRCServiceUUID().toString().equals(se.getUuid().toString())) {
+ SobLog.d(TAG, "BLE Discover RC Service Success!!!");
+ deviceRcNotifyEnable();
+
}
}
//3D 00 01 00 00 01 61 22 33 44 09 11 00 00 05 05 00 01 00 01
//64 00 01 00 00 01 28 11 06 AF B0 F7 00 00 05 05 00 01 00 01
updataDevice(data);
-
-
SobLog.d(TAG, "mBleConnectDevice--" + new Gson().toJson(mBleConnectDevice));
sendPhoneInfo();
//读取成功后 需要下发同步基础信息 才能进行接下来的通信
SobLog.d(TAG, "onCharacteristicChanged--" + characteristic.getUuid().toString() + ":" +
(value.length > 500 ? value.length : ByteTools.byteArrToHex(value)));
if (BleUuidUtil.getInstance().getNotifyUUID().toString().equals(characteristic.getUuid().toString())
- ||BleUuidUtil.getInstance().getmAudioNotifyUUID().toString().equals(characteristic.getUuid().toString())) {
+ ||BleUuidUtil.getInstance().getmAudioNotifyUUID().toString().equals(characteristic.getUuid().toString())
+ ||BleUuidUtil.getInstance().getRCNotifyUUID().toString().equals(characteristic.getUuid().toString())) {
BleMsgReceiverHandler.getInstance().receiverData(value);
} else if (BleUuidUtil.getInstance().getFileNotifyUUID().toString().equals(characteristic.getUuid().toString())) {
mBluetoothGatt.disconnect();
}
-
+ public boolean isNetworkAvailable() {
+ ConnectivityManager connectivityManager =
+ (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+ if (connectivityManager != null) {
+ NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
+ return networkInfo != null && networkInfo.isConnected();
+ }
+ return false;
+ }
private boolean isBinded = false;
public void connectStateChange(int state) {
SobLog.d(TAG, "connectStateChange--" + state);
}
isConnected = true;
SpUtils.getInstance().saveValue(SpUtils.KEY_LAST_DEVICE,new Gson().toJson(mBleConnectDevice));
+
+ RideCodeManager.getInstance().sendNetWorkState(isNetworkAvailable());
}else {
if(state==BtVtransferCallback.STATE_BLE_ISBINDED){
isBinded = true;
}
isConnected = false;
clear();
-
-
}
}
+
+
public void setDeviceStor(long storage){
mBleConnectDevice.setStorage(storage);
}
return false;
}
+ private void deviceRcNotifyEnable() {
+ if (!mBluetoothDeviceConnected) {
+ return;
+ }
+ if (!checkBluePermission())
+ return;
+ BluetoothGattService service = mBluetoothGatt.getService(BleUuidUtil.getInstance().getRCServiceUUID());//对应server端的setService方法
+
+ BluetoothGattCharacteristic characteristic = service.getCharacteristic(BleUuidUtil.getInstance().getRCNotifyUUID());//对应server端的setCharacteristic方法
+ if(characteristic!=null){
+ mBluetoothGatt.setCharacteristicNotification(characteristic, true);
+ }
+
+ BluetoothGattCharacteristic characteristic2 = service.getCharacteristic(BleUuidUtil.getInstance().getRCWriteUUID());//对应server端的setCharacteristic方法
+ if(characteristic2!=null){
+ mBluetoothGatt.setCharacteristicNotification(characteristic2, true);
+ }
+ }
+
private void deviceNotifyEnable() {
if (!mBluetoothDeviceConnected) {
return;
return;
}
BluetoothGattCharacteristic characteristic = service.getCharacteristic(BleUuidUtil.getInstance().getNotifyUUID());//对应server端的setCharacteristic方法
- mBluetoothGatt.setCharacteristicNotification(characteristic, true);
+ if(characteristic!=null){
+ mBluetoothGatt.setCharacteristicNotification(characteristic, true);
+ }
BluetoothGattCharacteristic characteristic2 = service.getCharacteristic(BleUuidUtil.getInstance().getReadUUID());//对应server端的setCharacteristic方法
- mBluetoothGatt.setCharacteristicNotification(characteristic2, true);
+ if(characteristic2!=null){
+ mBluetoothGatt.setCharacteristicNotification(characteristic2, true);
+ }
BluetoothGattCharacteristic characteristic3 = service.getCharacteristic(BleUuidUtil.getInstance().getFileNotifyUUID());//对应server端的setCharacteristic方法
- mBluetoothGatt.setCharacteristicNotification(characteristic3, true);
+ if(characteristic3!=null){
+ mBluetoothGatt.setCharacteristicNotification(characteristic3, true);
+ }
BluetoothGattCharacteristic characteristic4 = service.getCharacteristic(BleUuidUtil.getInstance().getmAudioNotifyUUID());//对应server端的setCharacteristic方法
- mBluetoothGatt.setCharacteristicNotification(characteristic4, true);
+ if(characteristic4!=null){
+ mBluetoothGatt.setCharacteristicNotification(characteristic4, true);
+ }
+
}
- public void deviceWrite(byte[] msg, int type) {
+ public void deviceWrite(byte[] msg, int type,int service) {
if(!mBluetoothDeviceConnected||mContext==null){
return;
}
- UUID writeUUID = BleUuidUtil.getInstance().getWriteUUID(type);
- SobLog.d(TAG, "---btsend-uuid--" + writeUUID.toString());
+
new Thread(new Runnable() {
@Override
public void run() {
if (!mBluetoothDeviceConnected || !checkBluePermission()) return;
+ UUID writeUUID = BleUuidUtil.getInstance().getWriteUUID(type);
+ if(service==1){
+ writeUUID = BleUuidUtil.getInstance().getRCWriteUUID();
+ }
+ SobLog.d(TAG, "---btsend-uuid--" + writeUUID.toString());
gattService = mBluetoothGatt.getService(BleUuidUtil.getInstance().getServiceUUID());//对应server端的setService方法
+ if(service==1){
+ gattService = mBluetoothGatt.getService(BleUuidUtil.getInstance().getRCServiceUUID());
+ }
if(gattService==null){
SobLog.d(TAG,"deviceWrite gattService null");
disconnectDevice();
}
public void sendE6Msg(byte[] data){
- deviceWrite(data,6);
+ deviceWrite(data,6,0);
}
return num & 0x1;
}
+ public static int CRC16_XMODEM(byte[] buffer) {
+ int wCRCin = 0x0000;
+ int wCPoly = 0x1021;
+ for (byte b : buffer) {
+ for (int i = 0; i < 8; i++) {
+ boolean bit = ((b >> (7 - i) & 1) == 1);
+ boolean c15 = ((wCRCin >> 15 & 1) == 1);
+ wCRCin <<= 1;
+ if (c15 ^ bit)
+ wCRCin ^= wCPoly;
+ }
+ }
+ wCRCin &= 0xffff;
+ return wCRCin ^= 0x0000;
+ }
+
}
--- /dev/null
+package com.zhixun.blesdk.hssdk.callback;
+
+public interface OnSocketListener {
+ void onMessageReceived(byte[] message);
+
+ void onConnectStateChange(boolean state);
+
+ void onConnectionLost();
+}
SobLog.d(TAG,"未匹配到数据类型");
return;
}
- SobLog.d(TAG,"sendMsg--"+msgBody.toString());
+
byte[] data = msgBody.getData();
byte[] pageNum = new byte[4];
byte[] pageTotalLen = new byte[4];
}else {
SobLog.d(TAG,"分包发送");
//分包计算
- int otherPageSize = data.length-mtu-18;
- int otherPage = otherPageSize/mtu;
- if(otherPageSize%mtu!=0){
- otherPage++;
- }
- int allpage = otherPage+1;//得加上第一帧
- pageNum = ByteTools.little_intToByte(allpage,pageNum.length);
+ if(msgBody.getService()==0){
+ int otherPageSize = data.length-mtu-18;
+ int otherPage = otherPageSize/mtu;
+ if(otherPageSize%mtu!=0){
+ otherPage++;
+ }
+ int allpage = otherPage+1;//得加上第一帧
+ pageNum = ByteTools.little_intToByte(allpage,pageNum.length);
+
+ //添加第一帧
+ byte[] crc = new byte[1];
+ byte[] firstContent = new byte[mtu-18];
+ System.arraycopy(data,0,firstContent,0,firstContent.length);
+
+ pageLen = ByteTools.little_intToByte(mtu-18,pageLen.length);
+ crc[0] = ByteTools.getLRC(firstContent);
+ byte[] firstData = ByteTools.concatAll(ByteTools.hexToByteArr(head),pageNum,pageTotalLen,
+ pageIndex,pageLen,firstContent,crc);
+ SobLog.d(TAG,"firstData--"+ByteTools.byteArrToHex(firstData));
+ queueMsg.add(firstData);
+
+ //添加剩余帧
+ byte[] otherContent = new byte[otherPageSize];
+ System.arraycopy(data,firstContent.length,otherContent,0,otherContent.length);
+ for (int i=0;i<otherPage;i++){
+ byte[] otherData = new byte[mtu];
+ if(otherPageSize%mtu!=0&&i==otherPage-1){
+ otherData = new byte[otherPageSize%mtu];
+ }
+ System.arraycopy(otherContent,i*mtu,otherData,0,otherData.length);
+ byte channel = (byte) (msgBody.getChannel() & 0xFF);
+ byte service = (byte) (msgBody.getService() & 0xFF);
+ byte[] otherHead = new byte[2];
+ otherHead[0] = channel;
+ otherHead[1] = service;
+ queueMsg.add(ByteTools.concatAll(otherHead,otherData));
+ }
+ }else {
+ int pageSize = (mtu-18);
+ int page = data.length/pageSize;
+ if(page%mtu!=0){
+ page++;
+ }
+
+ pageNum = ByteTools.little_intToByte(page,pageNum.length);
+
+ for (int i=0;i<page;i++){
+ byte[] childContent = new byte[pageSize];
+ if(data.length%pageSize!=0&&i==page-1){
+ childContent = new byte[data.length%pageSize];
+ }
+ System.arraycopy(data,i*pageSize,childContent,0,childContent.length);
+
+ byte[] crc = new byte[1];
+ pageIndex = ByteTools.little_intToByte(i+1,pageIndex.length);
+
+ pageLen = ByteTools.little_intToByte(childContent.length,pageLen.length);
+ crc[0] = ByteTools.getLRC(childContent);
+
+ byte[] childData = ByteTools.concatAll(ByteTools.hexToByteArr(head),pageNum,pageTotalLen,
+ pageIndex,pageLen,childContent,crc);
+ SobLog.d(TAG,"childData--"+ByteTools.byteArrToHex(childData));
+ queueMsg.add(childData);
- //添加第一帧
- byte[] crc = new byte[1];
- byte[] firstContent = new byte[mtu-18];
- System.arraycopy(data,0,firstContent,0,firstContent.length);
- pageLen = ByteTools.little_intToByte(mtu-18,firstContent.length);
- crc[0] = ByteTools.getLRC(firstContent);
- byte[] firstData = ByteTools.concatAll(ByteTools.hexToByteArr(head),pageNum,pageTotalLen,
- pageIndex,pageLen,firstContent,crc);
- queueMsg.add(firstData);
-
- //添加剩余帧
- byte[] otherContent = new byte[otherPageSize];
- System.arraycopy(data,firstContent.length,otherContent,0,otherContent.length);
- for (int i=0;i<otherPage;i++){
- byte[] otherData = new byte[mtu];
- if(otherPageSize%mtu!=0&&i==otherPage-1){
- otherData = new byte[otherPageSize%mtu];
}
- System.arraycopy(otherContent,i*mtu,otherData,0,otherData.length);
- queueMsg.add(otherData);
}
+
+
}
if(!isStart){
mSendMsgHandle.sendEmptyMessage(MSG_SEND);
private String getDataHead(MsgBody msgBody){
byte channel = (byte) (msgBody.getChannel() & 0xFF);
- StringBuffer head = new StringBuffer(ByteTools.byteToHex(channel)+"73");
+ byte service = (byte) (msgBody.getService() & 0xFF);
+ StringBuffer head = new StringBuffer(ByteTools.byteToHex(channel)+ByteTools.byteToHex(service)+"73");
byte[] typeB = ByteTools.little_intToByte(msgBody.getType(),2);
head.append(ByteTools.byteArrToHex(typeB));
return head.toString();
byte[] element = iterator.next();
byte[] head = new byte[3];
System.arraycopy(element,0,head,0,3);
- if (ByteTools.byteArrToHex(head).equals("73021F")) { // 如果是偶数
+ if (ByteTools.byteArrToHex(head).equals("73021F")) { // 如果是AI数据
iterator.remove(); // 移除该元素
}
}
mSendMsgHandle.sendEmptyMessageDelayed(MSG_SEND,40);
return;
}
-
- byte[] sendBytes = new byte[data.length-1];
- System.arraycopy(data,1,sendBytes,0,sendBytes.length);
+ 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));
- BleHandle.getInstance().deviceWrite(sendBytes,channel);
+ BleHandle.getInstance().deviceWrite(sendBytes,channel,service);
mSendMsgHandle.sendEmptyMessageDelayed(MSG_SEND,40);
break;
/*case MSG_CHECKSENDMSG:
msgSendState = false;
sendSize++;
SobLog.d(TAG,"sendSize--"+sendSize);
- BleHandle.getInstance().deviceWrite(sendArr.get(sendSize),MsgBody.CHANNEL_E0);
+ BleHandle.getInstance().deviceWrite(sendArr.get(sendSize),MsgBody.CHANNEL_E0,0);
BleHandle.getInstance().setOnSendStateChangeListener(new BleHandle.OnSendStateChangeListener() {
@Override
public void onSendStateRespose(boolean state) {
msgSendState = true;
msgSendRespose = true;
}*/
- BleHandle.getInstance().deviceWrite(sendArr.get(sendSize),MsgBody.CHANNEL_E6);
+ BleHandle.getInstance().deviceWrite(sendArr.get(sendSize),MsgBody.CHANNEL_E6,0);
BleHandle.getInstance().setOnSendStateChangeListener(new BleHandle.OnSendStateChangeListener() {
@Override
import com.google.gson.Gson;
+import com.zhixun.blesdk.hssdk.alisocket.RideCodeManager;
import com.zhixun.blesdk.hssdk.bttools.BleHandle;
import com.zhixun.blesdk.hssdk.callback.BtVtransferCallback;
import com.zhixun.blesdk.hssdk.bttools.ByteTools;
SpUtils.getInstance().init(mContext);
BleHandle.getInstance().init(context);
BleMsgSendHandler.getInstance().init();
+ RideCodeManager.getInstance().init();
BleMsgReceiverHandler.getInstance().init();
FileHandler.getInstance().init();
// FileHandlerE6.getInstance().init();
import com.google.gson.Gson;
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;
import org.json.JSONException;
import org.json.JSONObject;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
+import java.util.Locale;
import java.util.TimeZone;
public class ReceiverLooperThread extends Thread {
public static final int TYPE_START_SEND = 264;
public static final int TYPE_STOP_SEND = 520;
+
+ public static final int TYPE_RIDE_CODE = 0000;
private boolean startSendAudio = false;
private Handler mReceiverMsgHandle;
+
private HashMap<Integer, OnMsgSendCallBack> callBackMap = new HashMap<>();
public void run() {
PolymerizeAgent.getInstance().getAuthenAPI().setAIChannelKey("xunfei", "", callback);
}*/
+ break;
+ case MsgBody.TYPE_RIDECODE_DNS:
+
+ String address = ByteTools.getString(content,"UTF8");
+ SobLog.d(TAG, "TYPE_RIDECODE_DNS--"+address);
+ RideCodeManager.getInstance().iPInetAddress(address);
+ break;
+ case MsgBody.TYPE_RIDECODE_CONNECT:
+ SobLog.d(TAG, "TYPE_RIDECODE_CONNECT--"+content.length);
+ if(content.length<6){
+ return;
+ }
+ byte[] ip = new byte[4];
+ byte[] port = new byte[2];
+ System.arraycopy(content,0,ip,0,4);
+ System.arraycopy(content,4,port,0,2);
+ String ipStr = "";
+ for (byte b:ip){
+ ipStr = ipStr+"."+ByteTools.byte2Int(b);
+ }
+ int portI = ByteTools.little_bytesToInt(port);
+ RideCodeManager.getInstance().connectClient(ipStr.substring(1,ipStr.length()),portI);
+ break;
+ case MsgBody.TYPE_RIDECODE_MSG:
+ SobLog.d(TAG, "TYPE_RIDECODE_MSG--"+content.length);
+ RideCodeManager.getInstance().sendMsgToService(content);
+ break;
+ case MsgBody.TYPE_RIDECODE_DISCONNECT:
+ SobLog.d(TAG, "TYPE_RIDECODE_DISCONNECT--");
+ RideCodeManager.getInstance().disconnect();
break;
}
if (callBackMap.containsKey(revData.getType()) && response.getBody() != null) {
public ReceiverLooperThread() {
}
+
+
+
private void sendTime() {
AppTime appTime = new AppTime();
appTime.setTime((System.currentTimeMillis() / 1000));
public static final int TYPE_GET_SOS = 13825;
public static final int TYPE_SET_SOS = 9474;
+ public static final int TYPE_RIDECODE_NETSTATE = 265;
+ public static final int TYPE_RIDECODE_DNS = 521;
+ public static final int TYPE_RIDECODE_CONNECT = 777;
+ public static final int TYPE_RIDECODE_MSG = 1033;
+ public static final int TYPE_RIDECODE_DISCONNECT = 1289;
//AI2.0
// public static final int TYPE_START_CHAT = 264;
// public static final int TYPE_CHAT_AUDIO = 520;
public static final int CHANNEL_E6 = 6;
public static final int CHANNEL_E8 = 8;
private int channel;
+ private int service;
private int port;
private int type;
private byte[] data;
private String filePath;
+ public int getService() {
+ return service;
+ }
+
+ public void setService(int service) {
+ this.service = service;
+ }
+
public int getChannel() {
return channel;
}
private UUID mFileNotifyUUID = UUID.fromString("00002ae7-0000-1000-8000-00805f9b34fb");//客户端文件接收
private UUID mServiceUUID = UUID.fromString("000018e0-0000-1000-8000-00805f9b34fb");//客户端接收;
+
+ //乘车码
+ private UUID mRCServiceUUID = UUID.fromString("00001000-0000-1000-8000-00805f9b34fb");
+ private UUID mRCNotifyUUID = UUID.fromString("00001001-0000-1000-8000-00805f9b34fb");
+ private UUID mRCWriteUUID = UUID.fromString("00001002-0000-1000-8000-00805f9b34fb");
public static BleUuidUtil getInstance() {
if(sInstance == null) {
synchronized(BleUuidUtil.class) {
return r2AE2UUID;
}
+ public UUID getRCServiceUUID() {
+ return mRCServiceUUID;
+ }
+ public UUID getRCNotifyUUID() {
+ return mRCNotifyUUID;
+ }
+
+ public UUID getRCWriteUUID() {
+ return mRCWriteUUID;
+ }
public UUID getWriteUUID(int channal) {
if (channal == MsgBody.CHANNEL_E1) {