Skip to content

Commit

Permalink
Allow specification of the hexdump address format
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kk7ds committed Jul 18, 2014
1 parent ad1d196 commit ed2368a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
12 changes: 12 additions & 0 deletions README.developers
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ followed by an explanation of each directive:
[developer]
diff_fontsize = 16
browser_fontsize = 13
hexdump_addrfmt = %(addr)03i

===================================

Expand All @@ -40,3 +41,14 @@ tools are enabled.
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.
29 changes: 17 additions & 12 deletions chirp/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions chirpui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def save(self):
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)
return self.__config.get(section, key, raw=raw)

def set(self, key, value, section):
if not self.__config.has_section(section):
Expand All @@ -65,8 +65,9 @@ def __init__(self, config, section="global"):
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)
Expand Down
11 changes: 9 additions & 2 deletions chirpui/mainapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,15 @@ def _get_mem_b(mem_a):
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:
Expand Down

0 comments on commit ed2368a

Please sign in to comment.