[chirp_devel] [PATCH] Allow specification of the hexdump address format

Dan Smith
Fri Jul 18 07:58:15 PDT 2014


# HG changeset patch
# User Dan Smith <dsmith at danplanet.com>
# Date 1405695480 25200
#      Fri Jul 18 07:58:00 2014 -0700
# Node ID 6c8e270a40b1df08aae813258355cfb929c32958
# Parent  3bab2acc2cf68e735e48138bf4871c2cd3fed85a
Allow specification of the hexdump address format

This allows developers to override the address format used during
whole-diff (and potentially other) hexdump operations.

Idea and much of the implementation borrowed from Dan Drogichen

Related to #1767

diff -r 3bab2acc2cf6 -r 6c8e270a40b1 README.developers
--- a/README.developers	Mon Jul 14 20:10:30 2014 -0400
+++ b/README.developers	Fri Jul 18 07:58:00 2014 -0700
@@ -19,6 +19,7 @@
 [developer]
 diff_fontsize = 16
 browser_fontsize = 13
+hexdump_addrfmt = %(addr)03i
 
 ===================================
 
@@ -40,3 +41,14 @@
 The default size is 10. Values less than 4, greater than 144, or not
 recognized as an integer will result in a log message and the default 
 size will be used.
+
+========
+hexdump_addrfmt = %(addr)03i
+This specifies the format of the address used during some hexdump
+operations. You can specify an alternate format, such as the following
+for hex:
+
+ hexdump_addrfmt = 0x%(addr)04x
+
+Any of the variables in local scope of chirp/util.py::hexdump.py are
+valid for substitution, including block and block_size.
diff -r 3bab2acc2cf6 -r 6c8e270a40b1 chirp/util.py
--- a/chirp/util.py	Mon Jul 14 20:10:30 2014 -0400
+++ b/chirp/util.py	Fri Jul 18 07:58:00 2014 -0700
@@ -15,34 +15,39 @@
 
 import struct
 
-def hexprint(data):
+def hexprint(data, addrfmt=None):
     """Return a hexdump-like encoding of @data"""
-    line_sz = 8
+    if addrfmt is None:
+        addrfmt = '%(block)03i'
 
-    lines = len(data) / line_sz
+    block_size = 8
+
+    lines = len(data) / block_size
     
-    if (len(data) % line_sz) != 0:
+    if (len(data) % block_size) != 0:
         lines += 1
-        data += "\x00" * ((lines * line_sz) - len(data))
+        data += "\x00" * ((lines * block_size) - len(data))
 
     out = ""
         
-    for i in range(0, (len(data)/line_sz)):
-        out += "%03i: " % (i * line_sz)
+    for block in range(0, (len(data)/block_size)):
+        addr = block * block_size
+        out += addrfmt % locals()
+        out += ': '
 
-        left = len(data) - (i * line_sz)
-        if left < line_sz:
+        left = len(data) - (block * block_size)
+        if left < block_size:
             limit = left
         else:
-            limit = line_sz
+            limit = block_size
             
         for j in range(0, limit):
-            out += "%02x " % ord(data[(i * line_sz) + j])
+            out += "%02x " % ord(data[(block * block_size) + j])
 
         out += "  "
 
         for j in range(0, limit):
-            char = data[(i * line_sz) + j]
+            char = data[(block * block_size) + j]
 
             if ord(char) > 0x20 and ord(char) < 0x7E:
                 out += "%s" % char
diff -r 3bab2acc2cf6 -r 6c8e270a40b1 chirpui/config.py
--- a/chirpui/config.py	Mon Jul 14 20:10:30 2014 -0400
+++ b/chirpui/config.py	Fri Jul 18 07:58:00 2014 -0700
@@ -36,14 +36,15 @@
         self.__config.write(cfg_file)
         cfg_file.close()
 
-    def get(self, key, section):
+    def get(self, key, section, raw=False):
         if not self.__config.has_section(section):
             return None
 
         if not self.__config.has_option(section, key):
             return None
 
-        return self.__config.get(section, key)
+        print "Calling get %s with raw=%s" %(key, raw)
+        return self.__config.get(section, key, raw=raw)
 
     def set(self, key, value, section):
         if not self.__config.has_section(section):
@@ -65,8 +66,9 @@
         self._config = config
         self._section = section
 
-    def get(self, key, section=None):
-        return self._config.get(key, section or self._section)
+    def get(self, key, section=None, raw=False):
+        return self._config.get(key, section or self._section,
+                                raw=raw)
 
     def set(self, key, value, section=None):
         return self._config.set(key, value, section or self._section)
diff -r 3bab2acc2cf6 -r 6c8e270a40b1 chirpui/mainapp.py
--- a/chirpui/mainapp.py	Mon Jul 14 20:10:30 2014 -0400
+++ b/chirpui/mainapp.py	Fri Jul 18 07:58:00 2014 -0700
@@ -224,8 +224,15 @@
         elif isinstance(eset_a.rthread.radio, chirp_common.CloneModeRadio) and\
                 isinstance(eset_b.rthread.radio, chirp_common.CloneModeRadio):
             # Diff whole (can do this without a job, since both are clone-mode)
-            a = util.hexprint(eset_a.rthread.radio._mmap.get_packed())
-            b = util.hexprint(eset_b.rthread.radio._mmap.get_packed())
+            try:
+                addrfmt = CONF.get('hexdump_addrfmt', section='developer',
+                                   raw=True)
+            except:
+                pass
+            a = util.hexprint(eset_a.rthread.radio._mmap.get_packed(),
+                              addrfmt=addrfmt)
+            b = util.hexprint(eset_b.rthread.radio._mmap.get_packed(),
+                              addrfmt=addrfmt)
             if sel_chan_a == -2:
                 diffsonly = True
             else:



More information about the chirp_devel mailing list