Created
December 30, 2013 08:28
-
-
Save russdill/8179362 to your computer and use it in GitHub Desktop.
PMDL decoder for zeroplus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import xml.etree.ElementTree as ET | |
import sys | |
try: | |
tree = ET.parse(sys.argv[1]) | |
except: | |
tree = ET.parse(sys.stdin) | |
root = tree.getroot() | |
regs = { | |
'00' : 'HARD_DATA_CHECK_SUM', | |
'01' : 'PASS_WORD', | |
'10' : 'DEV_ID0', | |
'11' : 'DEV_ID1', | |
'20' : 'START_STATUS', | |
'21' : 'DEV_STATUS', | |
'30' : 'FREQUENCY_REG0', | |
'31' : 'FREQUENCY_REG1', | |
'32' : 'FREQUENCY_REG2', | |
'33' : 'FREQUENCY_REG3', | |
'34' : 'FREQUENCY_REG4', | |
'35' : 'MEMORY_LENGTH', | |
'36' : 'CLOCK_SOURCE', | |
'40' : 'TRIGGER_STATUS0', | |
'41' : 'TRIGGER_STATUS1', | |
'42' : 'TRIGGER_STATUS2', | |
'43' : 'TRIGGER_STATUS3', | |
'44' : 'TRIGGER_STATUS4', | |
'45' : 'TRIGGER_STATUS5', | |
'46' : 'TRIGGER_STATUS6', | |
'47' : 'TRIGGER_STATUS7', | |
'48' : 'TRIGGER_STATUS8', | |
'50' : 'TRIGGER_COUNT0', | |
'51' : 'TRIGGER_COUNT1', | |
'55' : 'TRIGGER_LEVEL0', | |
'56' : 'TRIGGER_LEVEL1', | |
'57' : 'TRIGGER_LEVEL2', | |
'58' : 'TRIGGER_LEVEL3', | |
'60' : 'RAMSIZE_TRIGGERBAR_ADDRESS0', | |
'61' : 'RAMSIZE_TRIGGERBAR_ADDRESS1', | |
'62' : 'RAMSIZE_TRIGGERBAR_ADDRESS2', | |
'63' : 'TRIGGERBAR_ADDRESS0', | |
'64' : 'TRIGGERBAR_ADDRESS1', | |
'65' : 'TRIGGERBAR_ADDRESS2', | |
'66' : 'DONT_CARE_TRIGGERBAR', | |
'70' : 'FILTER_ENABLE', | |
'71' : 'FILTER_STATUS', | |
'7a' : 'ENABLE_DELAY_TIME0', | |
'7b' : 'ENABLE_DELAY_TIME1' | |
} | |
last_reg = "" | |
status_bits = [ | |
"STATUS_BUSY", | |
"STATUS_READY", | |
"STATUS_BUTTON_PRESSED", | |
"BIT(3)", | |
"BIT(4)", | |
"BIT(5)", | |
"BIT(6)", | |
"BIT(7)" | |
] | |
flag_bits = [ | |
"STATUS_FLAG_RESET", | |
"STATUS_FLAG_INIT", | |
"STATUS_FLAG_GO", | |
"STATUS_FLAG_PAUSE", | |
"STATUS_FLAG_READ", | |
"STATUS_FLAG_20", | |
"STATUS_FLAG_40", | |
"STATUS_FLAG_80", | |
] | |
def print_bits(val, bits, none): | |
if val == 0: | |
print none | |
else: | |
for bit in range(8): | |
if val & (1 << bit): | |
print bits[bit], | |
for packet in root.iter('packet'): | |
proto = packet.findall("./proto[@name='frame']")[0] | |
time = proto.findall("./field[@name='frame.time_relative']")[0].attrib['show'] | |
proto = packet.findall("./proto[@showname='USB URB']")[0] | |
urb_type = proto.findall("./field[@name='usb.urb_type']")[0].attrib['value'] | |
transfer_type = proto.findall("./field[@name='usb.transfer_type']")[0].attrib['value'] | |
endpoint_number = proto.findall("./field[@name='usb.endpoint_number']")[0].attrib['value'] | |
try: | |
proto = packet.findall("./proto[@showname='URB setup']")[0] | |
wvalue = proto.findall("./field[@name='usb.setup.wValue']")[0].attrib['value'][:2] | |
except: | |
wvalue = None | |
try: | |
proto = packet.findall("./proto[@name='fake-field-wrapper']") | |
try: | |
data = proto[0].findall("./field[@name='usb.capdata']")[0].attrib['value'] | |
except: | |
data = proto[0].findall("./field[@name='']")[0].attrib['value'] | |
except: | |
data = None | |
if urb_type == "53" and transfer_type == "02" and endpoint_number == "00": | |
if wvalue == "82": | |
print "Read bulk" | |
elif wvalue == "83": | |
if data in regs: | |
last_reg = regs[data] | |
else: | |
last_reg = data | |
print time, last_reg, | |
elif wvalue == "85": | |
print "write", | |
if last_reg == "START_STATUS": | |
val = int(data, 16) | |
print "unk", val >> 6, | |
print_bits(val & 0x3f, flag_bits, "STATUS_FLAG_NONE") | |
else: | |
print data | |
if urb_type == "53" and transfer_type == "02" and endpoint_number == "80": | |
if wvalue == "82": | |
print time, "Read bulk" | |
elif wvalue == "84": | |
print "read", | |
elif urb_type == "43" and transfer_type == "02" and endpoint_number == "80": | |
if last_reg == "DEV_STATUS": | |
print_bits(int(data, 16), status_bits, "STATUS_NONE") | |
else: | |
print data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment