From 6febd1ba359147a288fd246d01c375035b81a21c Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Tue, 20 Dec 2022 11:15:58 -0800 Subject: [PATCH 1/4] add L2CAP CoC to ASHA --- bumble/profiles/asha_service.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/bumble/profiles/asha_service.py b/bumble/profiles/asha_service.py index e9aa19c9..1cb8380c 100644 --- a/bumble/profiles/asha_service.py +++ b/bumble/profiles/asha_service.py @@ -31,6 +31,7 @@ from ..gatt import ( Characteristic, CharacteristicValue, ) +from ..device import Device # ----------------------------------------------------------------------------- # Logging @@ -50,9 +51,10 @@ class AshaService(TemplateService): SUPPORTED_CODEC_ID = [0x02, 0x01] # Codec IDs [G.722 at 16 kHz] RENDER_DELAY = [00, 00] - def __init__(self, capability: int, hisyncid: List[int]): + def __init__(self, capability: int, hisyncid: List[int], device: Device): self.hisyncid = hisyncid self.capability = capability # Device Capabilities [Left, Monaural] + self.device = device # Handler for volume control def on_volume_write(_connection, value): @@ -116,9 +118,17 @@ class AshaService(TemplateService): CharacteristicValue(write=on_volume_write), ) - # TODO add real psm value - self.psm = 0x0080 - # self.psm = device.register_l2cap_channel_server(0, on_coc, 8) + # Register an L2CAP CoC server + def on_coc(channel): + def on_data(data): + logging.debug('<<< Voice data received:', data.hex()) + # TODO think about where should voice data go + # audio_out.write(data) + + channel.sink = on_data + + # let the server find a free PSM + self.psm = self.device.register_l2cap_channel_server(0, on_coc, 8) self.le_psm_out_characteristic = Characteristic( GATT_ASHA_LE_PSM_OUT_CHARACTERISTIC, Characteristic.READ, From 1068a6858da0049d291a11c06c1869f3661e7e32 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Tue, 20 Dec 2022 13:33:18 -0800 Subject: [PATCH 2/4] improve logging --- bumble/profiles/asha_service.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bumble/profiles/asha_service.py b/bumble/profiles/asha_service.py index 1cb8380c..03b9ba3e 100644 --- a/bumble/profiles/asha_service.py +++ b/bumble/profiles/asha_service.py @@ -121,8 +121,8 @@ class AshaService(TemplateService): # Register an L2CAP CoC server def on_coc(channel): def on_data(data): - logging.debug('<<< Voice data received:', data.hex()) - # TODO think about where should voice data go + logging.debug(f'<<< Voice data received:{data.hex()}') + # TODO think about where data should be dumped # audio_out.write(data) channel.sink = on_data From 06018211fe065ee6161765b6aa5ebcf2edc792f3 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Tue, 20 Dec 2022 13:33:18 -0800 Subject: [PATCH 3/4] emit event for ASHA l2cap packet --- bumble/profiles/asha_service.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bumble/profiles/asha_service.py b/bumble/profiles/asha_service.py index 03b9ba3e..eb7723fc 100644 --- a/bumble/profiles/asha_service.py +++ b/bumble/profiles/asha_service.py @@ -55,6 +55,8 @@ class AshaService(TemplateService): self.hisyncid = hisyncid self.capability = capability # Device Capabilities [Left, Monaural] self.device = device + self.emitted_data_name = 'ASHA_data_' + str(self.capability) + self.audio_out_data = b'' # Handler for volume control def on_volume_write(_connection, value): @@ -121,9 +123,10 @@ class AshaService(TemplateService): # Register an L2CAP CoC server def on_coc(channel): def on_data(data): - logging.debug(f'<<< Voice data received:{data.hex()}') - # TODO think about where data should be dumped - # audio_out.write(data) + logging.debug(f'<<< data received:{data}') + + self.emit(self.emitted_data_name, data) + self.audio_out_data += data channel.sink = on_data From 64b75be29bd4ed3df0a59add14cdebef069abd58 Mon Sep 17 00:00:00 2001 From: Yuyang Huang Date: Tue, 3 Jan 2023 16:39:45 -0800 Subject: [PATCH 4/4] add psm parameter for testing support --- bumble/profiles/asha_service.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bumble/profiles/asha_service.py b/bumble/profiles/asha_service.py index eb7723fc..fabaa281 100644 --- a/bumble/profiles/asha_service.py +++ b/bumble/profiles/asha_service.py @@ -51,12 +51,13 @@ class AshaService(TemplateService): SUPPORTED_CODEC_ID = [0x02, 0x01] # Codec IDs [G.722 at 16 kHz] RENDER_DELAY = [00, 00] - def __init__(self, capability: int, hisyncid: List[int], device: Device): + def __init__(self, capability: int, hisyncid: List[int], device: Device, psm=0): self.hisyncid = hisyncid self.capability = capability # Device Capabilities [Left, Monaural] self.device = device self.emitted_data_name = 'ASHA_data_' + str(self.capability) self.audio_out_data = b'' + self.psm = psm # a non-zero psm is mainly for testing purpose # Handler for volume control def on_volume_write(_connection, value): @@ -131,7 +132,7 @@ class AshaService(TemplateService): channel.sink = on_data # let the server find a free PSM - self.psm = self.device.register_l2cap_channel_server(0, on_coc, 8) + self.psm = self.device.register_l2cap_channel_server(self.psm, on_coc, 8) self.le_psm_out_characteristic = Characteristic( GATT_ASHA_LE_PSM_OUT_CHARACTERISTIC, Characteristic.READ,