mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-09 21:45:54 +00:00
send BTstackEventDaemonDisconnect event in case connection to daemon gets broken
This commit is contained in:
parent
f64240626f
commit
bb40d93c3e
@ -14,6 +14,7 @@ import com.bluekitchen.btstack.GATTService;
|
||||
import com.bluekitchen.btstack.Packet;
|
||||
import com.bluekitchen.btstack.PacketHandler;
|
||||
import com.bluekitchen.btstack.Util;
|
||||
import com.bluekitchen.btstack.event.BTstackEventDaemonDisconnect;
|
||||
import com.bluekitchen.btstack.event.BTstackEventState;
|
||||
import com.bluekitchen.btstack.event.GAPLEAdvertisingReport;
|
||||
import com.bluekitchen.btstack.event.GATTCharacteristicQueryResult;
|
||||
@ -310,6 +311,21 @@ public class MainActivity extends Activity implements PacketHandler {
|
||||
}
|
||||
|
||||
public void testConnectDisconnect(Packet packet){
|
||||
|
||||
if (packet instanceof BTstackEventDaemonDisconnect){
|
||||
addMessage("Daemon disconnected, restarting connection");
|
||||
|
||||
// wait a bit for BTstack to restart
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
// start all over
|
||||
test();
|
||||
return;
|
||||
}
|
||||
|
||||
if (packet instanceof HCIEventDisconnectionComplete){
|
||||
if (state != STATE.w4_disconnect) {
|
||||
state = STATE.w4_scan_result;
|
||||
@ -419,6 +435,7 @@ public class MainActivity extends Activity implements PacketHandler {
|
||||
testConnectDisconnect(packet);
|
||||
}
|
||||
|
||||
|
||||
void test(){
|
||||
|
||||
addMessage("LE Test Application");
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.bluekitchen.btstack;
|
||||
|
||||
import com.bluekitchen.btstack.event.BTstackEventDaemonDisconnect;
|
||||
|
||||
public class BTstackClient {
|
||||
|
||||
/**
|
||||
@ -69,14 +71,19 @@ public class BTstackClient {
|
||||
public void run() {
|
||||
while (socketConnection != null && !Thread.currentThread().isInterrupted()){
|
||||
Packet packet = socketConnection.receivePacket();
|
||||
if (packet == null) break;
|
||||
if (packet == null) {
|
||||
// server disconnected
|
||||
System.out.println("Rx Thread: Daemon Disconnected");
|
||||
packetHandler.handlePacket(new BTstackEventDaemonDisconnect());
|
||||
return;
|
||||
}
|
||||
if (packet.getPacketType() == Packet.HCI_EVENT_PACKET){
|
||||
packetHandler.handlePacket(EventFactory.eventForPacket(packet));
|
||||
continue;
|
||||
}
|
||||
packetHandler.handlePacket(packet);
|
||||
}
|
||||
System.out.println("Rx Thread: Disconnected");
|
||||
System.out.println("Rx Thread: Interrupted");
|
||||
}
|
||||
});
|
||||
rxThread.start();
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.bluekitchen.btstack.event;
|
||||
|
||||
import com.bluekitchen.btstack.Event;
|
||||
|
||||
public class BTstackEventDaemonDisconnect extends Event {
|
||||
public BTstackEventDaemonDisconnect() {
|
||||
super(new byte[]{0x00, 0x00}, 0);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user