]> sigrok.org Git - libsigrokdecode.git/commitdiff
hdcp: Reduce nesting level.
authorUwe Hermann <redacted>
Sat, 7 Dec 2019 15:34:46 +0000 (16:34 +0100)
committerUwe Hermann <redacted>
Sat, 7 Dec 2019 15:42:07 +0000 (16:42 +0100)
decoders/hdcp/pd.py

index 38ea99a4f8aac1c935963a299391850ec89dc54a..6004b7b6e1b6af1c146067a01b0747d4e3044686 100644 (file)
@@ -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)