def _dispatch_notifications(self): while True: handle, data = self._notify_queue.get() if self.notification_sink: try: self.notification_sink(handle, data) except BaseException: log.warning("Data was: %s", str2hex(data)) log.warning("Failed to dispatch notification: %s", traceback.format_exc()) else: log.warning("Dropped notification %s: %s", handle, str2hex(data))
def _notify(self, conn, handle, data): payload = { "type": "notification", "handle": handle, "data": str2hex(data) } log.debug("Send notification: %s", payload) try: conn.send(json.dumps(payload) + "\n") except KeyboardInterrupt: raise except BaseException: log.error("Problem sending notification: %s", traceback.format_exc()) self._check_shutdown(data)
def on_indication(self, handle, data): log.debug("Indication on handle %s: %s", handle, str2hex(data))
def write(self, handle, data): payload = {"type": "write", "handle": handle, "data": str2hex(data)} self._send(payload)
def write(self, handle, data): log.debug("Writing to %s: %s", handle, str2hex(data)) return self.requester.write_by_handle(handle, data)