From 913498ef05a5b9c28a246d8db64e31f7c12a35e8 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 7 May 2025 21:19:43 +1000 Subject: [PATCH] aioble-l2cap: Raise correct error if l2cap disconnects during send. If BLE disconnects in the middle of a send process, this change makes the code raise `L2CAPDisconnectedError` rather than `TypeError` due to `_cid` being `None`. Signed-off-by: Andrew Leech --- micropython/bluetooth/aioble-l2cap/manifest.py | 2 +- micropython/bluetooth/aioble/aioble/l2cap.py | 2 +- micropython/bluetooth/aioble/manifest.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/bluetooth/aioble-l2cap/manifest.py b/micropython/bluetooth/aioble-l2cap/manifest.py index 9150ad547..34a96344e 100644 --- a/micropython/bluetooth/aioble-l2cap/manifest.py +++ b/micropython/bluetooth/aioble-l2cap/manifest.py @@ -1,4 +1,4 @@ -metadata(version="0.2.0") +metadata(version="0.2.1") require("aioble-core") diff --git a/micropython/bluetooth/aioble/aioble/l2cap.py b/micropython/bluetooth/aioble/aioble/l2cap.py index e2d3bd9d4..397b7ceb6 100644 --- a/micropython/bluetooth/aioble/aioble/l2cap.py +++ b/micropython/bluetooth/aioble/aioble/l2cap.py @@ -133,7 +133,6 @@ def available(self): # Waits until the channel is free and then sends buf. # If the buffer is larger than the MTU it will be sent in chunks. async def send(self, buf, timeout_ms=None, chunk_size=None): - self._assert_connected() offset = 0 chunk_size = min(self.our_mtu * 2, self.peer_mtu, chunk_size or self.peer_mtu) mv = memoryview(buf) @@ -141,6 +140,7 @@ async def send(self, buf, timeout_ms=None, chunk_size=None): if self._stalled: await self.flush(timeout_ms) # l2cap_send returns True if you can send immediately. + self._assert_connected() self._stalled = not ble.l2cap_send( self._connection._conn_handle, self._cid, diff --git a/micropython/bluetooth/aioble/manifest.py b/micropython/bluetooth/aioble/manifest.py index 832200570..1cf06c4d8 100644 --- a/micropython/bluetooth/aioble/manifest.py +++ b/micropython/bluetooth/aioble/manifest.py @@ -3,7 +3,7 @@ # code. This allows (for development purposes) all the files to live in the # one directory. -metadata(version="0.6.0") +metadata(version="0.6.1") # Default installation gives you everything. Install the individual # components (or a combination of them) if you want a more minimal install.