#!/usr/bin/python import sys def get_line(): l = sys.stdin.readline() return (l[0], int(l[1:], 16)) def get_ack(): (dir,data) = get_line() if dir!='R' and data!=0xfa: print('! Unknown reply: %02x'%data) while True: notes = '' (dir,data) = get_line() if dir == 'S': get_ack() if data == 0xff: notes = 'reset' elif data == 0xfe: notes = 'resend' elif data == 0xf6: notes = 'set defaults' elif data == 0xf5: notes = 'disable reporting' elif data == 0xf4: notes = 'enable reporting' elif data == 0xf3: dir,data = get_line() notes = 'set_sample_rate: %02x' % data get_ack() elif data == 0xf2: _,d = get_line() notes = 'get device id: %02x' % d elif data == 0xf0: notes = 'set remote mode' elif data == 0xee: notes = 'set wrap mode' elif data == 0xec: notes = 'reset wrap mode' elif data == 0xeb: notes = 'read data' elif data == 0xea: notes = 'set stream mode' elif data == 0xe9: _,d1 = get_line() _,d2 = get_line() _,d3 = get_line() notes = 'status request: %02x resolution=%02x rate=%02x' % (d1, d2, d3) elif data == 0xe8: _,d = get_line() notes = 'set resolution: %02x' % d get_ack() elif data == 0xe7: notes = 'set scaling 2:1' elif data == 0xe6: notes = 'set scaling 1:1' else: notes = 'unknown command' print('%s %02x %s' % (dir, data, notes))