X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=decoders%2Fsrd_usb.py;h=a223dbbade809f642355e4f60eed264769d8ed7e;hb=f6555179b242357f9c75b1f6178537de2001cd98;hp=07fc732a04531cb6ce3a9bbfd7a0adc1165a12f4;hpb=67e847fd2185aa5677954dceacf3c279d7a68af1;p=libsigrokdecode.git diff --git a/decoders/srd_usb.py b/decoders/srd_usb.py index 07fc732..a223dbb 100644 --- a/decoders/srd_usb.py +++ b/decoders/srd_usb.py @@ -46,7 +46,7 @@ class Sample(): def __init__(self, data): self.data = data def probe(self, probe): - s = ord(self.data[probe / 8]) & (1 << (probe % 8)) + s = ord(self.data[int(probe / 8)]) & (1 << (probe % 8)) return True if s else False def sampleiter(data, unitsize): @@ -110,7 +110,7 @@ def packet_decode(packet): return pid + ' ' + data -class Decoder(): +class Decoder(sigrok.Decoder): id = 'usb' name = 'USB' desc = 'Universal Serial Bus' @@ -127,10 +127,14 @@ class Decoder(): def __init__(self): self.probes = Decoder.probes.copy() + self.output_protocol = None + self.output_annotation = None def start(self, metadata): self.unitsize = metadata['unitsize'] self.rate = metadata['samplerate'] + # self.output_protocol = self.output_new(2) + self.output_annotation = self.output_new(1) if self.rate < 48000000: raise Exception("Sample rate not sufficient for USB decoding") # Initialise decoder state. @@ -138,8 +142,10 @@ class Decoder(): self.scount = 0 self.packet = '' - def decode(self, data): - for sample in sampleiter(data['data'], self.unitsize): + def decode(self, timeoffset, duration, data): + out = [] + + for sample in sampleiter(data, self.unitsize): self.scount += 1 @@ -157,18 +163,18 @@ class Decoder(): # How many bits since the last transition? if self.packet or self.sym != J: - bitcount = (self.scount - 1) * 12000000 / self.rate + bitcount = int((self.scount - 1) * 12000000 / self.rate) else: bitcount = 0 if self.sym == SE0: if bitcount == 1: # End-Of-Packet (EOP) - sigrok.put({"type":"usb", "data":self.packet, - "display":packet_decode(self.packet)}) + out += [{"type":"usb", "data":self.packet, + "display":packet_decode(self.packet)}] else: # Longer than EOP, assume reset. - sigrok.put({"type":"usb", "display":"RESET"}) + out += [{"type":"usb", "display":"RESET"}] self.scount = 0 self.sym = sym self.packet = '' @@ -180,10 +186,12 @@ class Decoder(): if bitcount < 6 and sym != SE0: self.packet += '0' elif bitcount > 6: - sigrok.put({"type":"usb", "display":"BIT STUFF ERROR"}) + out += [{"type":"usb", "display":"BIT STUFF ERROR"}] self.scount = 0 self.sym = sym -sigrok.register(Decoder) + if out != []: + # self.put(self.output_protocol, 0, 0, out_proto) + self.put(self.output_annotation, 0, 0, out)