From 8aeedf9ee376f1b48fe9c42924ebf34f9c8c2ddd Mon Sep 17 00:00:00 2001 From: Jens Steinhauser Date: Sun, 3 Aug 2014 23:30:42 +0200 Subject: [PATCH] nrf24l01: prettify annotation output --- decoders/nrf24l01/pd.py | 31 +++++++++++-------- .../test/nrf24l01_activate_cmd.output | 4 +-- .../nrf24l01/test/nrf24l01_misc_cmd.output | 10 +++--- .../test/nrf24l01_misc_register.output | 10 +++--- .../test/nrf24l01_no_command_register.output | 8 ++--- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/decoders/nrf24l01/pd.py b/decoders/nrf24l01/pd.py index 3208a20..410a847 100644 --- a/decoders/nrf24l01/pd.py +++ b/decoders/nrf24l01/pd.py @@ -144,9 +144,9 @@ class Decoder(srd.Decoder): '''Returns the label for the current command.''' if self.cmd == 'R_REGISTER': reg = regs[self.dat][0] if self.dat in regs else 'unknown register' - return 'Cmd. R_REGISTER "{}"'.format(reg) + return 'Cmd R_REGISTER "{}"'.format(reg) else: - return 'Cmd. {}'.format(self.cmd) + return 'Cmd {}'.format(self.cmd) def parse_command(self, b): '''Parses the command byte. @@ -211,20 +211,25 @@ class Decoder(srd.Decoder): # The 'W_REGISTER' command is merged with the following byte(s). label = '{}: {}'.format(self.format_command(), name) else: - label = 'Reg. {}'.format(name) + label = 'Reg {}'.format(name) - self.decode_mb_data(pos, ann, data, label) + self.decode_mb_data(pos, ann, data, label, True) - def decode_mb_data(self, pos, ann, data, label, escape_all=True): + def decode_mb_data(self, pos, ann, data, label, always_hex): '''Decodes the data bytes 'data' of a multibyte command at position - 'pos'. The decoded data is prefixed with 'label'. If 'excape_all' is - True, all data bytes are escaped as hex codes.''' - - def escape(b): - c = chr(b) - if escape_all or not str.isprintable(c): - return '\\x{:02X}'.format(b) - return c + 'pos'. The decoded data is prefixed with 'label'. If 'always_hex' is + True, all bytes are decoded as hex codes, otherwise only non + printable characters are escaped.''' + + if always_hex: + def escape(b): + return '{:02X}'.format(b) + else: + def escape(b): + c = chr(b) + if not str.isprintable(c): + return '\\x{:02X}'.format(b) + return c data = ''.join([escape(b) for b in data]) text = '{} = "{}"'.format(label, data) diff --git a/decoders/nrf24l01/test/nrf24l01_activate_cmd.output b/decoders/nrf24l01/test/nrf24l01_activate_cmd.output index 4d5c33b..0a4ea21 100644 --- a/decoders/nrf24l01/test/nrf24l01_activate_cmd.output +++ b/decoders/nrf24l01/test/nrf24l01_activate_cmd.output @@ -1,2 +1,2 @@ -3-36 nrf24l01: cmd: "Cmd. ACTIVATE" -41-74 nrf24l01: cmd: "Cmd. ACTIVATE" +3-36 nrf24l01: cmd: "Cmd ACTIVATE" +41-74 nrf24l01: cmd: "Cmd ACTIVATE" diff --git a/decoders/nrf24l01/test/nrf24l01_misc_cmd.output b/decoders/nrf24l01/test/nrf24l01_misc_cmd.output index 015031e..041c365 100644 --- a/decoders/nrf24l01/test/nrf24l01_misc_cmd.output +++ b/decoders/nrf24l01/test/nrf24l01_misc_cmd.output @@ -1,5 +1,5 @@ -3-19 nrf24l01: cmd: "Cmd. REUSE_TX_PL" -24-40 nrf24l01: cmd: "Cmd. R_RX_PL_WID" -62-78 nrf24l01: cmd: "Cmd. R_RX_PL_WID" -83-99 nrf24l01: cmd: "Cmd. R_RX_PL_WID" -138-154 nrf24l01: cmd: "Cmd. W_ACK_PAYLOAD" +3-19 nrf24l01: cmd: "Cmd REUSE_TX_PL" +24-40 nrf24l01: cmd: "Cmd R_RX_PL_WID" +62-78 nrf24l01: cmd: "Cmd R_RX_PL_WID" +83-99 nrf24l01: cmd: "Cmd R_RX_PL_WID" +138-154 nrf24l01: cmd: "Cmd W_ACK_PAYLOAD" diff --git a/decoders/nrf24l01/test/nrf24l01_misc_register.output b/decoders/nrf24l01/test/nrf24l01_misc_register.output index 394846d..a3d38de 100644 --- a/decoders/nrf24l01/test/nrf24l01_misc_register.output +++ b/decoders/nrf24l01/test/nrf24l01_misc_register.output @@ -1,7 +1,7 @@ -3-19 nrf24l01: register: "Reg. STATUS = "\x00"" -24-40 nrf24l01: register: "Reg. STATUS = "\x00"" +3-19 nrf24l01: register: "Reg STATUS = "00"" +24-40 nrf24l01: register: "Reg STATUS = "00"" 41-57 nrf24l01: register: "Payload width = 9" -62-78 nrf24l01: register: "Reg. STATUS = "\x00"" -83-99 nrf24l01: register: "Reg. STATUS = "\x00"" +62-78 nrf24l01: register: "Reg STATUS = "00"" +83-99 nrf24l01: register: "Reg STATUS = "00"" 100-116 nrf24l01: register: "Payload width = 9" -138-154 nrf24l01: register: "Reg. STATUS = "\x00"" +138-154 nrf24l01: register: "Reg STATUS = "00"" diff --git a/decoders/nrf24l01/test/nrf24l01_no_command_register.output b/decoders/nrf24l01/test/nrf24l01_no_command_register.output index 2269878..5e97b3e 100644 --- a/decoders/nrf24l01/test/nrf24l01_no_command_register.output +++ b/decoders/nrf24l01/test/nrf24l01_no_command_register.output @@ -1,4 +1,4 @@ -11-27 nrf24l01: register: "Reg. STATUS = "\x00"" -28-44 nrf24l01: register: "Reg. CONFIG = "\x00"" -53-69 nrf24l01: register: "Reg. STATUS = "\x00"" -70-86 nrf24l01: register: "Reg. CONFIG = "\x00"" +11-27 nrf24l01: register: "Reg STATUS = "00"" +28-44 nrf24l01: register: "Reg CONFIG = "00"" +53-69 nrf24l01: register: "Reg STATUS = "00"" +70-86 nrf24l01: register: "Reg CONFIG = "00"" -- 2.30.2