improve get service advertising data

This commit is contained in:
Yuyang Huang
2022-12-05 11:21:20 -08:00
parent 697d5df3f8
commit 29f9a79502
4 changed files with 14 additions and 10 deletions

View File

@@ -940,11 +940,6 @@ class Device(CompositeEventEmitter):
if self.advertising:
await self.stop_advertising()
# add each Service's advertising data
for attribute in self.gatt_server.attributes:
if isinstance(attribute, Service):
self.advertising_data += attribute.get_service_advertising_data()
# Set/update the advertising data if the advertising type allows it
if advertising_type.has_data:
await self.send_command(HCI_LE_Set_Advertising_Data_Command(

View File

@@ -210,12 +210,13 @@ class Service(Attribute):
self.characteristics = characteristics[:]
self.primary = primary
def get_service_advertising_data(self):
def get_advertising_data(self):
"""
Get Service specific advertising data
Defined by each Service, default value is empty
:return Service data for advertising
"""
return b''
return None
def __str__(self):
return f'Service(handle=0x{self.handle:04X}, end=0x{self.end_group_handle:04X}, uuid={self.uuid}){"" if self.primary else "*"}'

View File

@@ -66,6 +66,15 @@ class Server(EventEmitter):
def next_handle(self):
return 1 + len(self.attributes)
def get_advertising_service_data(self):
service_advertising_data_map = dict[Service, bytes]()
for attribute in self.attributes:
if isinstance(attribute, Service):
if not attribute.get_advertising_data():
continue
service_advertising_data_map[attribute] = attribute.get_advertising_data()
return service_advertising_data_map
def get_attribute(self, handle):
attribute = self.attributes_by_handle.get(handle)
if attribute:

View File

@@ -49,7 +49,7 @@ class AshaService(TemplateService):
FEATURE_MAP = [0x01] # [LE CoC audio output streaming supported]
SUPPORTED_CODEDC_ID = [0x02, 0x01] # Codec IDs [G.722 at 16 kHz]
def __init__(self, capability: int, hisyncid: []):
def __init__(self, capability: int, hisyncid: [int]):
self.hisyncid = hisyncid
self.capability = capability # Device Capabilities [Left, Monaural]
self.render_delay = [00, 00]
@@ -131,8 +131,7 @@ class AshaService(TemplateService):
super().__init__(characteristics)
def get_service_advertising_data(self):
def get_advertising_data(self):
return bytes(
AdvertisingData([
(AdvertisingData.INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS, bytes(GATT_ASHA_SERVICE)),