mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-04-17 20:42:47 +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.Packet;
|
||||||
import com.bluekitchen.btstack.PacketHandler;
|
import com.bluekitchen.btstack.PacketHandler;
|
||||||
import com.bluekitchen.btstack.Util;
|
import com.bluekitchen.btstack.Util;
|
||||||
|
import com.bluekitchen.btstack.event.BTstackEventDaemonDisconnect;
|
||||||
import com.bluekitchen.btstack.event.BTstackEventState;
|
import com.bluekitchen.btstack.event.BTstackEventState;
|
||||||
import com.bluekitchen.btstack.event.GAPLEAdvertisingReport;
|
import com.bluekitchen.btstack.event.GAPLEAdvertisingReport;
|
||||||
import com.bluekitchen.btstack.event.GATTCharacteristicQueryResult;
|
import com.bluekitchen.btstack.event.GATTCharacteristicQueryResult;
|
||||||
@ -310,6 +311,21 @@ public class MainActivity extends Activity implements PacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testConnectDisconnect(Packet packet){
|
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 (packet instanceof HCIEventDisconnectionComplete){
|
||||||
if (state != STATE.w4_disconnect) {
|
if (state != STATE.w4_disconnect) {
|
||||||
state = STATE.w4_scan_result;
|
state = STATE.w4_scan_result;
|
||||||
@ -419,6 +435,7 @@ public class MainActivity extends Activity implements PacketHandler {
|
|||||||
testConnectDisconnect(packet);
|
testConnectDisconnect(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void test(){
|
void test(){
|
||||||
|
|
||||||
addMessage("LE Test Application");
|
addMessage("LE Test Application");
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.bluekitchen.btstack;
|
package com.bluekitchen.btstack;
|
||||||
|
|
||||||
|
import com.bluekitchen.btstack.event.BTstackEventDaemonDisconnect;
|
||||||
|
|
||||||
public class BTstackClient {
|
public class BTstackClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,14 +71,19 @@ public class BTstackClient {
|
|||||||
public void run() {
|
public void run() {
|
||||||
while (socketConnection != null && !Thread.currentThread().isInterrupted()){
|
while (socketConnection != null && !Thread.currentThread().isInterrupted()){
|
||||||
Packet packet = socketConnection.receivePacket();
|
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){
|
if (packet.getPacketType() == Packet.HCI_EVENT_PACKET){
|
||||||
packetHandler.handlePacket(EventFactory.eventForPacket(packet));
|
packetHandler.handlePacket(EventFactory.eventForPacket(packet));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
packetHandler.handlePacket(packet);
|
packetHandler.handlePacket(packet);
|
||||||
}
|
}
|
||||||
System.out.println("Rx Thread: Disconnected");
|
System.out.println("Rx Thread: Interrupted");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rxThread.start();
|
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