meta-digi/meta-digi-dey/recipes-connectivity/bluez/bluez5-5.41/0008-example-gatt-server-up...

125 lines
4.6 KiB
Diff

From: Isaac Hermida <isaac.hermida@digi.com>
Date: Wed, 27 Sep 2017 10:00:15 +0200
Subject: [PATCH] example-gatt-server: update example to master version
Current test example was not registering correctly the services, so the BLEGATT
server was not working properly.
Update this example to current version in master (commit ed63d7e5a9f6).
Note: In order to run it, the bluetoothd daemon needs to be started with the
experimental (-E) flag and needs to enable and advertise the BLE
functionallity (btmgmt le on/connectable on/advertisement on).
https://jira.digi.com/browse/DEL-5023
Signed-off-by: Isaac Hermida <isaac.hermida@digi.com>
---
test/example-gatt-server | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/test/example-gatt-server b/test/example-gatt-server
index 84905f3d0856..24aaff973b11 100755
--- a/test/example-gatt-server
+++ b/test/example-gatt-server
@@ -42,6 +42,9 @@ class FailedException(dbus.exceptions.DBusException):
class Application(dbus.service.Object):
+ """
+ org.bluez.GattApplication1 interface implementation
+ """
def __init__(self, bus):
self.path = '/'
self.services = []
@@ -74,6 +77,9 @@ class Application(dbus.service.Object):
class Service(dbus.service.Object):
+ """
+ org.bluez.GattService1 interface implementation
+ """
PATH_BASE = '/org/bluez/example/service'
def __init__(self, bus, index, uuid, primary):
@@ -121,6 +127,9 @@ class Service(dbus.service.Object):
class Characteristic(dbus.service.Object):
+ """
+ org.bluez.GattCharacteristic1 interface implementation
+ """
def __init__(self, bus, index, uuid, flags, service):
self.path = service.path + '/char' + str(index)
self.bus = bus
@@ -195,6 +204,9 @@ class Characteristic(dbus.service.Object):
class Descriptor(dbus.service.Object):
+ """
+ org.bluez.GattDescriptor1 interface implementation
+ """
def __init__(self, bus, index, uuid, flags, characteristic):
self.path = characteristic.path + '/desc' + str(index)
self.bus = bus
@@ -222,7 +234,7 @@ class Descriptor(dbus.service.Object):
if interface != GATT_DESC_IFACE:
raise InvalidArgsException()
- return self.get_properties()[GATT_CHRC_IFACE]
+ return self.get_properties()[GATT_DESC_IFACE]
@dbus.service.method(GATT_DESC_IFACE,
in_signature='a{sv}',
@@ -426,7 +438,7 @@ class TestService(Service):
TEST_SVC_UUID = '12345678-1234-5678-1234-56789abcdef0'
def __init__(self, bus, index):
- Service.__init__(self, bus, index, self.TEST_SVC_UUID, False)
+ Service.__init__(self, bus, index, self.TEST_SVC_UUID, True)
self.add_characteristic(TestCharacteristic(bus, 0, self))
self.add_characteristic(TestEncryptCharacteristic(bus, 1, self))
self.add_characteristic(TestSecureCharacteristic(bus, 2, self))
@@ -523,11 +535,11 @@ class TestEncryptCharacteristic(Characteristic):
CharacteristicUserDescriptionDescriptor(bus, 3, self))
def ReadValue(self, options):
- print('TestCharacteristic Read: ' + repr(self.value))
+ print('TestEncryptCharacteristic Read: ' + repr(self.value))
return self.value
def WriteValue(self, value, options):
- print('TestCharacteristic Write: ' + repr(value))
+ print('TestEncryptCharacteristic Write: ' + repr(value))
self.value = value
class TestEncryptDescriptor(Descriptor):
@@ -564,16 +576,16 @@ class TestSecureCharacteristic(Characteristic):
['secure-read', 'secure-write'],
service)
self.value = []
- self.add_descriptor(TestEncryptDescriptor(bus, 2, self))
+ self.add_descriptor(TestSecureDescriptor(bus, 2, self))
self.add_descriptor(
CharacteristicUserDescriptionDescriptor(bus, 3, self))
def ReadValue(self, options):
- print('TestCharacteristic Read: ' + repr(self.value))
+ print('TestSecureCharacteristic Read: ' + repr(self.value))
return self.value
def WriteValue(self, value, options):
- print('TestCharacteristic Write: ' + repr(value))
+ print('TestSecureCharacteristic Write: ' + repr(value))
self.value = value
@@ -636,6 +648,8 @@ def main():
mainloop = GObject.MainLoop()
+ print('Registering GATT application...')
+
service_manager.RegisterApplication(app.get_path(), {},
reply_handler=register_app_cb,
error_handler=register_app_error_cb)