-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg.py
33 lines (29 loc) · 1.02 KB
/
msg.py
1
from event import event_analyzefrom cmd import cmd_analyze def acl_analyze(msg): handle = (msg[2] & 0x0f) * 256 + msg[1] pb = (msg[2] >> 4) & 0b11 bc = (msg[2] >> 6) & 0b11 len = msg[4] * 256 + msg[3] print 'ACL Data: Handle: 0x%03X PB_Flag: %d BC_Flag: %d ' % (handle, pb, bc), print 'Data Len: 0x%04X' % len, pass def sync_analyze(msg): handle = (msg[2] & 0x0f) * 256 + msg[1] ps = (msg[2] >> 4) & 0b11 len = msg[3] print 'Sync Data: Handle: 0x%03X Packet_Status_Flag: %d ' % (handle, ps), print 'Data Len: 0x%02X' % len, passmsg_tpye = [ { 'code' : 0x01, 'descript' : 'Command', 'analyze_fun' : cmd_analyze }, { 'code' : 0x02, 'descript' : 'ACL Data', 'analyze_fun' : acl_analyze }, { 'code' : 0x03, 'descript' : 'Sync Data', 'analyze_fun' : sync_analyze }, { 'code' : 0x04, 'descript' : 'Event', 'analyze_fun' : event_analyze } ]def msg_analyze(msg): for t in msg_tpye: if t['code'] == msg[0]: print ' ', t['analyze_fun'](msg) print print break