Skip to content

Instantly share code, notes, and snippets.

@TylerOderkirk
Last active August 17, 2016 10:52
Show Gist options
  • Save TylerOderkirk/81c2085ed8ca5869982c to your computer and use it in GitHub Desktop.
Save TylerOderkirk/81c2085ed8ca5869982c to your computer and use it in GitHub Desktop.
bluelog_stdout_parser.py
#!/usr/bin/env python
import subprocess, time, os, sys
#TODO: kill any already-running bluelog instances
cmd = ['./bluelog', '-m', '-t', '-f', '-a0', '-n', '-v']
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
mru_macs = []
for line in iter(p.stdout.readline, b''):
# w/ friendly-class option (-v) output is:
# printf("%s,%s,%s,%s,(%s)\n",\
# dev_cache[ri].time, dev_cache[ri].addr,\
# dev_cache[ri].name, device_class(dev_cache[ri].major_class,\
# dev_cache[ri].minor_class), device_capability(dev_cache[ri].flags));
# strip the trailing LF
line = line.strip()
# does the line begin with a timestamp?
if line[0] in '0123456789':
timestamp = line.split(',')[0]
mac = line.split(',')[1]
name = line.split(',')[2]
clazz = line.split(',')[3]
cap = line.split(',')[4]
if mac not in mru_macs:
mru_macs.append(mac)
print(timestamp, mac, name, clazz, cap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment