From c6427ab4a6d9da271dc9f16bd9a7dce23af39120 Mon Sep 17 00:00:00 2001 From: Daniel Pavel Date: Sat, 6 Oct 2012 14:48:42 +0300 Subject: [PATCH] better logging in cli tools --- lib/cli/hidconsole.py | 8 +++++--- lib/cli/ur_scanner.py | 15 +++++++++------ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/cli/hidconsole.py b/lib/cli/hidconsole.py index ed9f8fe6..2bf165a9 100644 --- a/lib/cli/hidconsole.py +++ b/lib/cli/hidconsole.py @@ -11,7 +11,8 @@ def read_next(handle, timeout=1000, ignore_nodata=False): print "!! Read failed, aborting" raise Exception() if reply: - print ">> %s %s" % (hexlify(reply), repr(reply)) + hexs = hexlify(reply) + print ">> [%s %s %s %s] %s" % (hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(reply)) return True if not ignore_nodata: @@ -25,7 +26,7 @@ def console_cycle(handle): continue line = raw_input('!! Enter packet to send (hex bytes) or ^C to abort: ') - line = line.strip() + line = line.strip().replace(' ', '').replace('-', '') if not line: continue if len(line) % 2 == 1: @@ -36,7 +37,8 @@ def console_cycle(handle): except: print "!! Invalid input." continue - print "<< %s %s" % (hexlify(data), repr(data)) + hexs = hexlify(data) + print "<< [%s %s %s %s] %s" % (hexs[0:2], hexs[2:4], hexs[4:8], hexs[8:], repr(data)) hidapi.write(handle, data) read_next(handle) diff --git a/lib/cli/ur_scanner.py b/lib/cli/ur_scanner.py index 805f4cd7..b77f6d78 100644 --- a/lib/cli/ur_scanner.py +++ b/lib/cli/ur_scanner.py @@ -18,6 +18,8 @@ def scan_devices(receiver): for devinfo in devices: print "Device [%d] %s (%s)" % (devinfo.number, devinfo.name, devinfo.type) + print " Protocol %s" % devinfo.protocol + for fw in devinfo.firmware: print " %s firmware: %s version %s build %d" % (fw.type, fw.name, fw.version, fw.build) @@ -51,11 +53,12 @@ if __name__ == '__main__': log_level = logging.root.level - 10 * args.verbose logging.root.setLevel(log_level if log_level > 0 else 1) - receiver = api.open() - if receiver: - print "!! Logitech Unifying Receiver found." - scan_devices(receiver) + for rawdevice in api._base.list_receiver_devices(): + receiver = api._base.try_open(rawdevice.path) + if receiver: + print "!! Logitech Unifying Receiver found (%s)." % rawdevice.path + scan_devices(receiver) + api.close(receiver) + break else: print "!! Logitech Unifying Receiver not found." - - api.close(receiver)