diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2019-12-07 16:34:46 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2019-12-07 16:42:07 +0100 |
commit | 9bbfff99dc56be9e69522ffe744b3197f54007db (patch) | |
tree | d697384aed16c49a3e415a0bfa60284ac0cfa965 /decoders/hdcp | |
parent | 4abd552b354cedc416c19722c7264292f29a9ca9 (diff) | |
download | libsigrokdecode-9bbfff99dc56be9e69522ffe744b3197f54007db.tar.gz libsigrokdecode-9bbfff99dc56be9e69522ffe744b3197f54007db.zip |
hdcp: Reduce nesting level.
Diffstat (limited to 'decoders/hdcp')
-rw-r--r-- | decoders/hdcp/pd.py | 71 |
1 files changed, 38 insertions, 33 deletions
diff --git a/decoders/hdcp/pd.py b/decoders/hdcp/pd.py index 38ea99a..6004b7b 100644 --- a/decoders/hdcp/pd.py +++ b/decoders/hdcp/pd.py @@ -144,40 +144,45 @@ class Decoder(srd.Decoder): if cmd in ('STOP', 'NACK'): self.es_block = es self.state = 'IDLE' - if self.type != '': - if self.stack: - if self.type == 'RxStatus': - rxstatus = (self.stack.pop() << 8) | self.stack.pop() - reauth_req = (rxstatus & 0x800) != 0 - ready = (rxstatus & 0x400) != 0 - length = rxstatus & 0x3ff - text = '%s, reauth %s, ready %s, length %s' % (self.type, reauth_req, ready, length) - self.putb([18, [text]]) - elif self.type == '1.4 Bstatus': - bstatus = (self.stack.pop() << 8) | self.stack.pop() - device_count = bstatus & 0x7f - max_devs_exceeded = (bstatus & 0x80) != 0 - depth = ((bstatus & 0x700) >> 8) - max_cascase_exceeded = bstatus & 0x800 - hdmi_mode = (bstatus & 0x1000) != 0 - text = '%s, %s devices, depth %s, hdmi mode %s' % (self.type, device_count, depth, hdmi_mode) - self.putb([18, [text]]) - elif self.type == 'Read_Message': - msg = self.stack.pop(0) - self.putb([msg, ['%s, %s' % (self.type, msg_ids.get(msg, 'Invalid'))]]) - elif self.type == 'Write_Message': - msg = self.stack.pop(0) - self.putb([msg, ['%s, %s' % (self.type, msg_ids.get(msg, 'Invalid'))]]) - elif self.type == 'HDCP2Version': - version = self.stack.pop(0) - if (version & 0x4): - self.putb([18, ['HDCP2']]) - else: - self.putb([18, ['NOT HDCP2']]) - else: - self.putb([18, ['%s' % (self.type)]]) + if self.type == '': + return + if not self.stack: + self.putb([18, ['%s' % (self.type)]]) + return + if self.type == 'RxStatus': + rxstatus = (self.stack.pop() << 8) | self.stack.pop() + reauth_req = (rxstatus & 0x800) != 0 + ready = (rxstatus & 0x400) != 0 + length = rxstatus & 0x3ff + text = '%s, reauth %s, ready %s, length %s' % \ + (self.type, reauth_req, ready, length) + self.putb([18, [text]]) + elif self.type == '1.4 Bstatus': + bstatus = (self.stack.pop() << 8) | self.stack.pop() + device_count = bstatus & 0x7f + max_devs_exceeded = (bstatus & 0x80) != 0 + depth = ((bstatus & 0x700) >> 8) + max_cascase_exceeded = bstatus & 0x800 + hdmi_mode = (bstatus & 0x1000) != 0 + text = '%s, %s devices, depth %s, hdmi mode %s' % \ + (self.type, device_count, depth, hdmi_mode) + self.putb([18, [text]]) + elif self.type == 'Read_Message': + msg = self.stack.pop(0) + self.putb([msg, ['%s, %s' % (self.type, + msg_ids.get(msg, 'Invalid'))]]) + elif self.type == 'Write_Message': + msg = self.stack.pop(0) + self.putb([msg, ['%s, %s' % (self.type, + msg_ids.get(msg, 'Invalid'))]]) + elif self.type == 'HDCP2Version': + version = self.stack.pop(0) + if (version & 0x4): + self.putb([18, ['HDCP2']]) else: - self.putb([18, ['%s' % (self.type)]]) + self.putb([18, ['NOT HDCP2']]) + else: + self.putb([18, ['%s' % (self.type)]]) elif cmd == 'DATA READ': # Stack up our data bytes. self.stack.append(databyte) |