@@ -270,17 +270,22 @@ def bluetooth_ctx(*, uuid: str, debug: bool):
270270 server_sock .listen (1 )
271271
272272 bluetooth .advertise_service (
273- server_sock , "SerialBridge" , service_id = uuid ,
274- service_classes = [uuid , bluetooth .SERIAL_PORT_CLASS ],
273+ sock = server_sock , name = uuid , service_id = uuid ,
274+ service_classes = [bluetooth .SERIAL_PORT_CLASS ],
275275 profiles = [bluetooth .SERIAL_PORT_PROFILE ],
276- description = "Serial-to-Bluetooth Bridge" )
276+ provider = "BTSerialBridge" , description = "Serial-to-Bluetooth Bridge" )
277277
278278 if debug :
279279 print (
280280 'Waiting for RFCOMM connection on port'
281281 f"{ server_sock .getsockname ()} ..." )
282282 bt_sock , client_info = server_sock .accept ()
283283 print (f"Accepted connection from { client_info } " )
284+ # Note that `BluetoothSocket` objects *wrap* a `socket` object:
285+ # https://github.com/pybluez/pybluez/blob/82cbba8a/bluetooth/bluez.py#L233
286+ # Also note Serial objects are custom objects, but on POSIX (only!) they
287+ # have a fileno:
288+ # https://github.com/pyserial/pyserial/blob/911a0b8c/serial/serialposix.py#L806
284289
285290 try :
286291 yield bt_sock
@@ -291,6 +296,8 @@ def bluetooth_ctx(*, uuid: str, debug: bool):
291296
292297
293298def bridge_ports (* , ser : serial .Serial , bt : socket .socket , debug : bool ):
299+ # TODO: consider switching to asyncio.
300+ # Hints: `asyncio.loop.add_reader`, `loop.sock_recv` etc.
294301 keep_running = True
295302 while keep_running :
296303 try :
@@ -311,7 +318,7 @@ def bridge_ports(*, ser: serial.Serial, bt: socket.socket, debug: bool):
311318 if debug :
312319 print (f"Serial -> BT: { data !r} " )
313320 if data :
314- bt .send (data )
321+ bt .sendall (data )
315322 elif not ser .is_open :
316323 print ('Stopping b/c of Serial disconnect' )
317324 keep_running = False
0 commit comments