Skip to content

Commit e88081c

Browse files
Andy LiaoAndy Liao
authored andcommitted
bug fix
1 parent fed7b49 commit e88081c

File tree

6 files changed

+13
-20
lines changed

6 files changed

+13
-20
lines changed

‎app/app.iml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="BLEDemo" external.system.module.version="unspecified"type="JAVA_MODULE"version="4">
2+
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="androidBLEDemo" external.system.module.version="unspecified"type="JAVA_MODULE"version="4">
33
<componentname="FacetManager">
44
<facettype="android-gradle"name="Android-Gradle">
55
<configuration>

‎blelibrary/blelibrary.iml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<module external.linked.project.id=":blelibrary" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="BLEDemo" external.system.module.version="unspecified"type="JAVA_MODULE"version="4">
2+
<module external.linked.project.id=":blelibrary" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="androidBLEDemo" external.system.module.version="unspecified"type="JAVA_MODULE"version="4">
33
<componentname="FacetManager">
44
<facettype="android-gradle"name="Android-Gradle">
55
<configuration>

‎blelibrary/src/main/java/me/czvn/blelibrary/bluetooth/BLEClient.java‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@
2626
* 对bluetoothGatt进行了封装
2727
*/
2828
publicfinalclassBLEClient{
29-
// TODO: 2016/1/22 为了实现多人聊天的情景,可以将消息全部改成Json传输
3029
privatestaticfinalStringTAG = BLEClient.class.getSimpleName();
3130
privateContextmContext;
32-
privateBluetoothManagerbluetoothManager;
33-
privateBluetoothAdapterbluetoothAdapter;
3431

3532
privateBluetoothGattCallbackgattCallback;
3633
privateBluetoothGattbluetoothGatt;
@@ -44,9 +41,7 @@ public final class BLEClient{
4441

4542
privatebooleanconnected;
4643

47-
privateMsgQueuemsgQueue;//使用消息队列达到异步处理数据发送的问题
48-
// 现在在中文字符数达到一定量的时候会乱码,说明这部分还是有问题,可能跟中文字符的getBytes方法有关系,需要尝试指定字符编码
49-
//指定字符编码无效,待Debug
44+
privateMsgQueue<byte[]> msgQueue;//使用消息队列达到异步处理数据发送的问题
5045

5146
privatebooleanonWrite;//是否正在发送数据
5247

@@ -68,7 +63,7 @@ public void receiveMessage(String msg){
6863
ibleCallback.onMessageReceived(msg);
6964
}
7065
});
71-
msgQueue = newMsgQueue();
66+
msgQueue = newMsgQueue<>();
7267
initGattCallback();
7368

7469
}
@@ -80,8 +75,8 @@ public void receiveMessage(String msg){
8075
* @return 是否连接成功
8176
*/
8277
publicbooleanstartConnect(Stringadderss){
83-
bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
84-
bluetoothAdapter = bluetoothManager.getAdapter();
78+
BluetoothManagerbluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
79+
BluetoothAdapterbluetoothAdapter = bluetoothManager.getAdapter();
8580
bluetoothGatt = bluetoothAdapter.getRemoteDevice(adderss).connectGatt(mContext, false, gattCallback);
8681
if (bluetoothGatt.connect()){
8782
connected = true;
@@ -146,7 +141,7 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status){
146141
if (service != null){
147142
BluetoothGattCharacteristiccharacteristic = service.getCharacteristic(UUID.fromString(BLEProfile.UUID_CHARACTERISTIC_NOTIFY));
148143
if (characteristic != null){
149-
//SetNotification
144+
//订阅通知,这段代码对iOS的peripheral也能订阅
150145
Log.i(TAG, "SetNotification");
151146
bluetoothGatt.setCharacteristicNotification(characteristic, true);
152147
for (BluetoothGattDescriptordescriptor : characteristic.getDescriptors()){

‎blelibrary/src/main/java/me/czvn/blelibrary/bluetooth/BLEScanner.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ public final class BLEScanner{
2727

2828
privateContextcontext;
2929
privateIScanResultListenerscanResultListener;
30-
privateBluetoothAdapterbluetoothAdapter;
3130
privateBluetoothLeScannerscanner;
3231
privateScanCallbackscanCallback;
3332
privateScanSettingsscanSettings;
@@ -55,7 +54,7 @@ public static BLEScanner getInstance(Context context, IScanResultListener listen
5554
* @return 如果设备不支持BLE扫描则返回false,支持返回true
5655
*/
5756
publicbooleanstartScan(){
58-
bluetoothAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
57+
BluetoothAdapterbluetoothAdapter = ((BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE)).getAdapter();
5958
if (bluetoothAdapter == null){
6059
Log.e(TAG, "bluetoothAdapter is null");
6160
returnfalse;

‎blelibrary/src/main/java/me/czvn/blelibrary/bluetooth/BLEServer.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ public void sendMsg(String msg){
105105
}
106106

107107

108-
109108
privatevoidsetCallback(IBLECallbackcallback){
110109
this.callback = callback;
111110
}

‎blelibrary/src/main/java/me/czvn/blelibrary/utils/MsgQueue.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Created by andy on 2016/1/19.
55
* 链表实现的队列
66
*/
7-
publicclassMsgQueue{
7+
publicfinalclassMsgQueue<T>{
88
privateNodefirst;
99
privateNodelast;
1010
privateintlength;
@@ -17,7 +17,7 @@ public int size(){
1717
returnlength;
1818
}
1919

20-
publicvoidenQueue(byte[]item){
20+
publicvoidenQueue(Titem){
2121
Nodeoldlast = last;
2222
last = newNode();
2323
last.item = item;
@@ -31,19 +31,19 @@ public void enQueue(byte[] item){
3131

3232
}
3333

34-
publicbyte[]deQueue(){
34+
publicTdeQueue(){
3535
if (isEmpty()){
3636
last = null;
3737
returnnull;
3838
}
39-
byte[]values = first.item;
39+
Tvalues = first.item;
4040
first = first.next;
4141
length--;
4242
returnvalues;
4343
}
4444

4545
privateclassNode{
46-
byte[]item;
46+
Titem;
4747
Nodenext;
4848
}
4949
}

0 commit comments

Comments
(0)