return sInstance;
}
-
+ private boolean isInit = false;
public void init(Context context) {
- Log.e(TAG, "Bluetooth Handle Start");
+ Log.e(TAG, "Bluetooth Handle Start---"+isInit);
+ if(isInit)return;
+ isInit = true;
mContext = context;
if (bleLooperThread == null) {
bleLooperThread = new BleLooperThread();
mBluetoothGatt.close();
mBluetoothGatt = null;
}
+ isRead = false;
}
if (newState != BluetoothProfile.STATE_CONNECTED) {
//SobLog.d(TAG, "---btsend---over");
}
-
-
+ private boolean isRead = false;
private void readInitMsg() {
if (!mBluetoothDeviceConnected || !checkBluePermission()) return;
gattService = mBluetoothGatt.getService(BleUuidUtil.getInstance().getServiceUUID());//对应server端的setService方法
connectStateChange(BtVtransferCallback.STATE_DISCONNECTED);
return;
}
+ SobLog.d(TAG,"readInitMsg-isRead-"+isRead);
+ if(isRead){
+ return;
+ }
+ isRead = true;
BluetoothGattCharacteristic characteristic = gattService.getCharacteristic(BleUuidUtil.getInstance().getReadUUID());
if (characteristic != null) {
// 读取特性的值
byte[] content = revData.getContent();
MsgResponse response = new MsgResponse();
switch (revData.getType()) {
+ case -1:
+ SobLog.d(TAG, "TYPE_SET_PHONEINFO--Timeout");
+ BleHandle.getInstance().disconnectDevice();
+ break;
case BleMsgSendHandler.TYPE_SET_PHONEINFO:
SobLog.d(TAG, "TYPE_SET_PHONEINFO--" + ByteTools.byteArrToHex(content));
int connectState = ByteTools.bytes2Int(content, 1);
BleHandle.getInstance().connectStateChange(BtVtransferCallback.STATE_BLE_ISBINDED);
}
response.setBody(connectState);
+ mReceiverMsgHandle.sendEmptyMessageDelayed(-1,8000);
break;
case TYPE_SURE_PAIR:
//收到确认配对消息
+ mReceiverMsgHandle.removeMessages(-1);
SobLog.d(TAG, "TYPE_SURE_PAIR--" + ByteTools.byteArrToHex(content));
int pairState = ByteTools.bytes2Int(content, 1);
if (pairState == 2) {
}
break;
case MsgBody.TYPE_SET_TIME:
+ mReceiverMsgHandle.removeMessages(-1);
//时间同步
int timeAnsyState = ByteTools.bytes2Int(content, 1);
if (timeAnsyState == 1) {