diff options
author | Sven Gothel <[email protected]> | 2022-02-05 19:52:48 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2022-02-05 19:52:48 +0100 |
commit | 0d71d635f998270b1417f9d6bde2f20ccef5816c (patch) | |
tree | 1f6de783b7f690054f45123aa83e7eb37fb2dfe4 /examples | |
parent | 8846416805efbc3650addf070785737ff1ae73ea (diff) |
FwdGattServerHandler::close(): Shall not disconnect fwdServer (esp in same thread), let client app (dbt_repeater00) manage forwarding disconnect client -> server
dbt_repeater00: On client disconnect reset the server connection:
- disconnect connection to server
- power-cycle the adapter to server
- start-discovery
Diffstat (limited to 'examples')
-rw-r--r-- | examples/dbt_repeater00.cpp | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/examples/dbt_repeater00.cpp b/examples/dbt_repeater00.cpp index 791e7a6d..66569e2b 100644 --- a/examples/dbt_repeater00.cpp +++ b/examples/dbt_repeater00.cpp @@ -513,6 +513,20 @@ static void removeDeviceToServer(BTDeviceRef device) { device->remove(); } +static void resetConnectionToServer(BTDeviceRef device) { + fprintf_td(stderr, "****** To Server: Disconnected: %s\n", device->toString().c_str()); + device->disconnect(HCIStatusCode::DISCONNECTED); + + BTAdapter& a = device->getAdapter(); + fprintf_td(stderr, "****** To Server: Power off: %s\n", a.toString().c_str()); + if( a.setPowered(false) ) { + fprintf_td(stderr, "****** To Server: Power on: %s\n", a.toString().c_str()); + if( a.setPowered(true) ) { + startDiscoveryToServer(&a, "resetConnectionToServer"); + } + } +} + static bool startDiscoveryToServer(BTAdapter *a, std::string msg) { if( adapterToServerAddr != EUI48::ALL_DEVICE && adapterToServerAddr != a->getAddressAndType().address ) { fprintf_td(stderr, "****** To Server: Start discovery (%s): Adapter not selected: %s\n", msg.c_str(), a->toString().c_str()); @@ -700,7 +714,17 @@ static void processDisconnectedDeviceToClient(BTDeviceRef device) { BTDeviceRegistry::removeFromProcessingDevices(device->getAddressAndType()); std::this_thread::sleep_for(std::chrono::milliseconds(100)); // wait a little (FIXME: Fast restart of advertising error) - startAdvertisingToClient(adapterToClient, "processDisconnectedDeviceToClient"); + BTDeviceRef devToServer; + { + jau::sc_atomic_critical sync(sync_data); + devToServer = connectedDeviceToServer; + } + if( nullptr != devToServer ) { + std::thread sd(::resetConnectionToServer, devToServer); // @suppress("Invalid arguments") + sd.detach(); + } else { + startAdvertisingToClient(adapterToClient, "processDisconnectedDeviceToClient"); + } fprintf_td(stderr, "****** To Client: Disonnected Device: End %s\n", device->toString().c_str()); } |