add L2CAP CoC to ASHA

This commit is contained in:
Yuyang Huang
2022-12-20 11:15:58 -08:00
parent ea6a8d4339
commit 6febd1ba35

View File

@@ -31,6 +31,7 @@ from ..gatt import (
Characteristic, Characteristic,
CharacteristicValue, CharacteristicValue,
) )
from ..device import Device
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Logging # Logging
@@ -50,9 +51,10 @@ class AshaService(TemplateService):
SUPPORTED_CODEC_ID = [0x02, 0x01] # Codec IDs [G.722 at 16 kHz] SUPPORTED_CODEC_ID = [0x02, 0x01] # Codec IDs [G.722 at 16 kHz]
RENDER_DELAY = [00, 00] 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.hisyncid = hisyncid
self.capability = capability # Device Capabilities [Left, Monaural] self.capability = capability # Device Capabilities [Left, Monaural]
self.device = device
# Handler for volume control # Handler for volume control
def on_volume_write(_connection, value): def on_volume_write(_connection, value):
@@ -116,9 +118,17 @@ class AshaService(TemplateService):
CharacteristicValue(write=on_volume_write), CharacteristicValue(write=on_volume_write),
) )
# TODO add real psm value # Register an L2CAP CoC server
self.psm = 0x0080 def on_coc(channel):
# self.psm = device.register_l2cap_channel_server(0, on_coc, 8) 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( self.le_psm_out_characteristic = Characteristic(
GATT_ASHA_LE_PSM_OUT_CHARACTERISTIC, GATT_ASHA_LE_PSM_OUT_CHARACTERISTIC,
Characteristic.READ, Characteristic.READ,