Skip to content

Commit

Permalink
BLESession: Enrich logs for notification handling
Browse files Browse the repository at this point in the history
To debug the GitHub issue #26, add more debug and error logs to
functions to handle notifications.

Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
  • Loading branch information
kawasaki committed Nov 14, 2021
1 parent e6d63a5 commit f8ce9e3
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pyscrlink/scratch_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,8 @@ def run(self):
logger.debug("after waitForNotification")
logger.debug("released lock for waitForNotification")
except Exception as e:
logger.error(e)
logger.error(f"Exception in waitForNotifications: "
f"{type(e).__name__}: {e}")
self.session.close()
break
else:
Expand All @@ -413,14 +414,18 @@ def __init__(self, session):
self.restart_notification_event.set()

def add_handle(self, serviceId, charId, handle):
logger.debug(f"add handle for notification: {handle}")
logger.debug(f"add handle for notification: "
f"{serviceId} {charId} {handle}")
params = { 'serviceId': UUID(serviceId).getCommonName(),
'characteristicId': charId,
'encoding': 'base64' }
self.handles[handle] = params

def handleNotification(self, handle, data):
logger.debug(f"BLE notification: {handle} {data}")
if handle not in self.handles:
logger.error(f"Notification with unknown {handle}")
return
params = self.handles[handle].copy()
params['message'] = base64.standard_b64encode(data).decode('ascii')
self.session.notify('characteristicDidChange', params)
Expand Down

0 comments on commit f8ce9e3

Please sign in to comment.