From d491e976a3542e1de7b240df1276d8f380ffbde1 Mon Sep 17 00:00:00 2001 From: Sebastian Walz Date: Sun, 21 Oct 2018 01:11:51 +0200 Subject: [PATCH] =?UTF-8?q?Option=20=C2=BBbase=C2=AB=20added,=20=C2=BB:?= =?UTF-8?q?=C2=AB=20allowed=20in=20options?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ?base=16 for hexadecimal ?base=8 for octal (one byte) --- protocol | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/protocol b/protocol index 5bfeeda..39b798b 100755 --- a/protocol +++ b/protocol @@ -94,6 +94,7 @@ class Protocol(): self.hdr_char_fill_even="-" # Fill character for border even positions self.hdr_char_sep="|" # Field separator character self.bits_per_line=32 # Number of bits per line + self.base_of_top_tens=10 # Base of top numbers self.do_print_top_tens=True # True: print top numbers for bit tens self.do_print_top_units=True # True: print top numbers for bit units self.field_list=[] # Header fields to be printed out @@ -138,11 +139,15 @@ class Protocol(): opts=opts.split(",") for opt in opts: try: - var, value = opt.split("=") + var, value = opt.replace(':','=').split("=") if var.lower()=="bits": self.bits_per_line=int(value) if self.bits_per_line<=0: raise ProtocolException("FATAL: Invalid value for 'bits' option (%s)" % value) + elif var.lower()=="base": + self.base_of_top_tens=int(value) + if self.base_of_top_tens<=0 or self.base_of_top_tens>16: + raise ProtocolException("FATAL: Invalid value for 'base' option (%s)" % value) elif var.lower()=="numbers": if value.lower() in ["0", "n", "no", "none", "false"]: self.do_print_top_tens=False @@ -185,14 +190,14 @@ class Protocol(): lines=["", ""] if self.do_print_top_tens is True: for i in range(0, self.bits_per_line): - if str(i)[-1:]=="0": - lines[0]+=" %s" % str(i)[0] + if i%self.base_of_top_tens==0: + lines[0]+=" %s" % chars[int(i/self.base_of_top_tens)%self.base_of_top_tens] else: lines[0]+=" " lines[0]+="\n" if self.do_print_top_units is True: for i in range(0, self.bits_per_line): - lines[1]+=" %s" % str(i)[-1:] + lines[1]+=" %s" % chars[i%self.base_of_top_tens] #lines[1]+="\n" result = "".join(lines) return result if len(result)>0 else None