Exemple #1
0
    def StopNotify(self):
        if not self.notifying:
            log.info_print('Not notifying, nothing to do')
            return

        self.notifying = False
        self.update_notify_data()
Exemple #2
0
def get_connect_status():
    global ad_manager_interface
    global ble_advertisement
    global advertisement_status
    global ble_register
    global bus
    p = os.popen('hcitool con')
    data = p.read()
    len = data.find('> LE')
    if len > 0:
        if ad_manager_interface and ble_advertisement and advertisement_status == True:
            log.info_print("StartNotify UnregisterAdvertisement")
            ad_manager_interface.UnregisterAdvertisement(
                ble_advertisement.get_path())
            ble_advertisement.Release()
            advertisement_status = False
            ble_register = False
        return True
    else:
        if ad_manager_interface and ble_advertisement and advertisement_status == False and ble_register == False:
            log.info_print("StartNotify RegisterAdvertisement")
            ble_register = True
            ad_manager_interface.RegisterAdvertisement(
                ble_advertisement.get_path(), {},
                reply_handler=register_ad_cb,
                error_handler=register_ad_error_cb)
        return False
Exemple #3
0
def register_ad_error_cb(error):
    global ad_manager_interface
    global ble_advertisement
    #log.error_print('Failed to register advertisement: ' + str(error))
    print('Failed to register advertisement: ' + str(error))
    if str(error).find('AlreadyExists'):
        log.info_print('Unregister Advertisement')
        ad_manager_interface.UnregisterAdvertisement(
            ble_advertisement.get_path())
    advertisement_status = False
    mainloop.quit()
Exemple #4
0
def setup():
    global mainloop
    global ad_manager_interface
    global ble_advertisement
    global ble_server_start
    global ble_register
    global monitor_thread
    ad_manager_interface = None
    ble_advertisement = None
    ble_register = False
    set_ble_adv_inetval()
    monitor_thread = threading.Thread(target=monitor, args=())
    monitor_thread.setDaemon(True)
    monitor_thread.start()
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    bus = dbus.SystemBus()

    server_manager = get_server_manager(bus)
    if not server_manager:
        log.error_print('server manager interface not found')
        return

    add_manager = get_ad_manager(bus)
    if not add_manager:
        log.error_print('add manager interface not found')
        return

    service_manager_interface = dbus.Interface(
        bus.get_object(BLUEZ_SERVICE_NAME, server_manager), GATT_MANAGER_IFACE)

    ad_manager_interface = dbus.Interface(
        bus.get_object(BLUEZ_SERVICE_NAME, add_manager),
        LE_ADVERTISING_MANAGER_IFACE)

    ble_app = BLEApplication(bus)
    mainloop = GObject.MainLoop()

    log.info_print('Registering GATT application...')

    service_manager_interface.RegisterApplication(
        ble_app.get_path(), {},
        reply_handler=register_app_cb,
        error_handler=register_app_error_cb)
    log.info_print("Start BLEAdvertisement")
    ble_advertisement = BLEAdvertisement(bus, 0)

    mainloop_thread = threading.Thread(target=loop, args=())
    mainloop_thread.setDaemon(True)
    mainloop_thread.start()
    ble_server_start = True
Exemple #5
0
    def GetManagedObjects(self):
        response = {}
        log.info_print('GetManagedObjects')

        for service in self.services:
            response[service.get_path()] = service.get_properties()
            chrcs = service.get_characteristics()
            for chrc in chrcs:
                response[chrc.get_path()] = chrc.get_properties()
                descs = chrc.get_descriptors()
                for desc in descs:
                    response[desc.get_path()] = desc.get_properties()

        return response
Exemple #6
0
def register_ad_cb():
    global advertisement_status
    log.info_print('registered Advertisement')
    advertisement_status = True
Exemple #7
0
def register_app_cb():
    log.info_print('GATT application registered')
Exemple #8
0
 def StartNotify(self):
     if self.notifying:
         log.info_print('Already notifying, nothing to do')
         return
     self.notifying = True
     self.update_notify_data()
Exemple #9
0
 def Release(self):
     log.info_print('%s: Released!' % self.path)
Exemple #10
0
 def GetAll(self, interface):
     log.info_print('GetAll')
     if interface != LE_ADVERTISEMENT_IFACE:
         raise InvalidArgsException()
     log.info_print('returning props')
     return self.get_properties()[LE_ADVERTISEMENT_IFACE]