Commit graph

22 commits

Author SHA1 Message Date
Christopher Willis-Ford
224e694874 feat(windows): BLE session first draft 2023-01-31 08:48:49 -08:00
Christopher Willis-Ford
32f8981487 fix: resolve crash on session close while connecting 2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
8fdc3d166e fix: disable BLE restore to fix 'Bluetooth unavailable' issue
Restore wasn't fully implemented anyway, and having it enabled would
occasionally cause macOS to report "Bluetooth unavailable" after
reconnecting BLE sessions several times.

After turning that off, macOS treats implementing
`WillRestoreStateEvent` as an error, so I removed that.
2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
5423e7800b fix: dispose of cbManager on session shutdown 2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
f59d16112d chore: convert remaining Debug logging to Trace 2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
d2df409958 fix(macBLE): handle UpdatedState even if it fires during CBCentralManager ctor 2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
b46f4359f6 fix(macBLE): fix 'API MISUSE' log message 2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
907ea9158e chore: add logging to help debug macOS 10/11 issues 2023-01-13 08:21:38 -08:00
Christopher Willis-Ford
124b6a0cef fix(Mac): make sure GetSettledBluetoothState() doesn't miss an event 2023-01-13 08:21:37 -08:00
Christopher Willis-Ford
b3c48ef166 fix(MacBT): dispose of inquiry & channel properly
The absence of this was causing native code to sometimes issue a
callback to a managed object that the GC had already collected, leading
to a crash.
2023-01-13 08:21:37 -08:00
Christopher Willis-Ford
d2c1cf9784 fix(MacBLE): allow more time for the Bluetooth state to settle 2023-01-13 08:21:37 -08:00
Christopher Willis-Ford
eed937fd18 fix: fix DisposedException by removing cancellation token
We really use the socket state to control the session, so there's no
need to also pass a CancellationToken around. The exception was being
caused when an unlucky callback happened after a session was disposed
and the callback tried to get a new token to check cancellation. If the
token source is already disposed, it can't provide a new token.

Also, remove some excessive logging and add more exception logging.
2023-01-13 08:21:37 -08:00
Christopher Willis-Ford
953144379d Mac: misc reliability improvements
An `EventAwaiter` timeout now throws a `TimeoutException` instead of a
`TaskCanceledException`.

Disconnecting a micro:bit while subscribed for change notifications was
causing an exception because a notification was being triggered after
the socket closed. Fixing that led to an attempt to close the socket
after it was closed and set to `null`. That one was solved with a null
check.

For BT, connection is still not reliable but it's a step in the right
direction... I think. The socket lock is now held while opening the
RFCOMM channel, which is an awful long time to hold a lock, but really
no other thread should be messing with the socket during that time so I
guess it's the right thing to do. I also added debug printouts on the
RFCOMM event delegate.
2023-01-13 08:21:37 -08:00
Christopher Willis-Ford
eba7b98883 Mac BLE: reduce log SPAM 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
bddf0dc50f clean up JsonRpc2Exception a bit 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
7ec18de421 share BTSession's address privacy implementation with BLESession 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
0b0b8802a8 add an extension to lock a SemaphoreSlim with 'using' 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
ac5e4a4431 close BLE session if the device disconnects 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
930beaaea5 add event debug messages to cbManager 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
172fc2c534 switch to Fleck for WebSockets 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
2c9e4c600a fixed usings and namespaces 2023-01-13 08:21:36 -08:00
Christopher Willis-Ford
2897e2d16f begin splitting scratch-link into scratch-link-{common,mac}
Note that this currently doesn't build since the files have not yet been
adapted to the new framework.
2023-01-13 08:21:36 -08:00