send BTstackEventDaemonDisconnect event in case connection to daemon gets broken

This commit is contained in:
matthias.ringwald@gmail.com 2014-06-20 08:41:40 +00:00
parent f64240626f
commit bb40d93c3e
3 changed files with 35 additions and 2 deletions

View File

@ -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");

View File

@ -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();

View File

@ -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);
}
}