Exemplo n.º 1
0
    def __init__(self, index: int, uuid: str, is_primary: bool,
                 ble_device: str):
        self.ble_device = ble_device
        self.path = BleUtils.get_service_path_base(
            self.ble_device) + str(index)

        self.bus = BleUtils.get_system_dbus()
        self.uuid = uuid
        self.is_primary = is_primary
        self.characteristics = []
        self.next_index = 0
        dbus.service.Object.__init__(self, self.bus, self.path)
Exemplo n.º 2
0
    def __init__(self, index: int, advertising_type: str, ble_device: str):

        self.ble_device = ble_device
        self.path = BleUtils.get_advertisement_path_base(ble_device)
        self.bus = BleUtils.get_system_dbus()
        self.ad_type = advertising_type

        # Setting to None to represent "unset"
        self.local_name = None
        self.service_uuids = None
        self.solicit_uuids = None
        self.manufacturer_data = None
        self.service_data = None
        self.include_tx_power = None
        dbus.service.Object.__init__(self, self.bus, self.path)
Exemplo n.º 3
0
    def register(self):
        bus = BleUtils.get_system_dbus()
        adapter = BleUtils.get_ble_dbus_path(bus, self.ble_device)

        try:
            ad_mgr = dbus.Interface(
                bus.get_object(Constants.dbus_bluez_service_name, adapter),
                Constants.dbus_ble_interface_advertising_manager)
        except Exception:
            Utils.logger.error(
                'Failed to retrieve the the advertisement manager.')

        ad_mgr.RegisterAdvertisement(self.get_path(), {},
                                     reply_handler=self.register_ad_cb,
                                     error_handler=self.register_ad_error_cb)
Exemplo n.º 4
0
 def __init__(self, ble_device: str = 'hci0'):
     self.ble_device = ble_device
     dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
     self.mainloop = GObject.MainLoop()
     self.bus = BleUtils.get_system_dbus()
     self.path = '/'
     self.services = []
     self.next_index = 0
     dbus.service.Object.__init__(self, self.bus, self.path)
Exemplo n.º 5
0
    def WriteValue(self, value: str, options: list = None):
        input_value = BleUtils.parse_dbus_array(value)

        try:
            self.value = int(input_value)
            Utils.logger.info(f'Written value "{self.value}" to '
                              f'{self.__class__.__name__}')
        except ValueError:
            Utils.logger.error(f'Given value {input_value} is '
                               f'invalid type for an array')
Exemplo n.º 6
0
    def register(self):
        Utils.logger.info('Registering Application.')
        adapter = BleUtils.get_ble_dbus_path(self.bus, self.ble_device)

        service_manager = dbus.Interface(
            self.bus.get_object(Constants.dbus_bluez_service_name, adapter),
            Constants.dbus_ble_interface_gatt_manager)

        service_manager.RegisterApplication(self.get_path(), {},
                                            reply_handler=self.reg_app_cb,
                                            error_handler=self.reg_app_err_cb)
Exemplo n.º 7
0
    def WriteValue(self, value: str, options: list = None):
        try:
            str_value = BleUtils.parse_dbus_array(value)

            if str_value.lower() in ['1', 't', 'true']:
                Utils.logger.info('true')
                self.value = True
            else:
                self.value = False

            Utils.logger.info(f'Written value "{self.value}" to '
                              f'{self.__class__.__name__}')
        except AssertionError:
            Utils.logger.error(f'The value {value} was not valid')
Exemplo n.º 8
0
 def encode_value(self) -> dbus.Byte:
     return BleUtils.encode_as_dbus_byte_array(self.value)
Exemplo n.º 9
0
    def WriteValue(self, value: str, options: list = None):
        self.value = BleUtils.parse_dbus_array(value)

        Utils.logger.info(f'Written value "{self.value}" to '
                          f'{self.__class__.__name__}')
Exemplo n.º 10
0
 def WriteValue(self, value, options):
     print('Default WriteValue called, returning error')
     raise BleUtils.NotSupportedException()
Exemplo n.º 11
0
 def ReadValue(self, options):
     print('Default ReadValue called, returning error')
     raise BleUtils.NotSupportedException()
Exemplo n.º 12
0
    def GetAll(self, interface):
        if interface != Constants.dbus_ble_interface_gatt_descriptor:
            raise BleUtils.InvalidArgsException()

        return self.get_properties()[
            Constants.dbus_ble_interface_gatt_descriptor]
Exemplo n.º 13
0
 def StopNotify(self):
     print('Default StopNotify called, returning error')
     raise BleUtils.NotSupportedException()
Exemplo n.º 14
0
    def GetAll(self, interface: str) -> dict:
        if interface != Constants.dbus_ble_interface_gatt_characteristic:
            raise BleUtils.InvalidArgsException()

        return self.get_properties()[
            Constants.dbus_ble_interface_gatt_characteristic]
Exemplo n.º 15
0
 def GetAll(self, interface: str) -> dict:
     if interface != Constants.dbus_ble_interface_advertisement:
         raise BleUtils.InvalidArgsException()
     else:
         return self.get_properties()[
             Constants.dbus_ble_interface_advertisement]