Skip to content

Commit

Permalink
Bugfix loading decodings and centralized place for decodings (#563)
Browse files Browse the repository at this point in the history
* Bugfix loading decodings and centralized place for decodings

* fix bug when combining de whitening with external programs
* remove decodings.txt for projects, save it in project file

* update changelog

* fix display bug for aligned messages

* increase timeout for ci

* use default osx image

* use other osx image

* improve stability for noise detection

* try xcode 10
  • Loading branch information
jopohl committed Oct 31, 2018
1 parent 06aabdb commit f78d7cd
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ matrix:
dist: xenial
sudo: true
- os: osx
osx_image: xcode9.2
language: generic
osx_image: xcode10

allow_failures:
- python: 3.4_with_system_site_packages
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

### Bugfixes
- fix problem with set reference message shortcut [#559](https://github.com/jopohl/urh/pull/559)
- fix loading decodings and centralized place for decodings [#563](https://github.com/jopohl/urh/pull/563)

## v2.4.1 (23/10/2018)
### New features
Expand Down
6 changes: 5 additions & 1 deletion src/urh/ainterpretation/AutoInterpretation.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def detect_noise_level(magnitudes):
# Get all indices for values which are in range of 10% of minimum mean value
indices = np.nonzero(mean_values <= 1.1 * np.min(mean_values))[0]

result = np.max([np.max(chunks[i]) for i in indices])
try:
result = np.max([np.max(chunks[i]) for i in indices if len(chunks[i]) > 0])
except ValueError:
return 0

# Round up to fourth digit
return math.ceil(result * 10000) / 10000
Expand Down Expand Up @@ -191,6 +194,7 @@ def detect_modulation_for_messages(signal: np.ndarray, message_indices: list) ->

def detect_center(rectangular_signal: np.ndarray):
rect = rectangular_signal[rectangular_signal > -4] # do not consider noise

hist_min, hist_max = util.minmax(rect)
hist_step = 0.05

Expand Down
2 changes: 1 addition & 1 deletion src/urh/controller/CompareFrameController.py
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ def on_table_selection_timer_timeout(self):
f = 4 if cur_view == 1 else 8 if cur_view == 2 else 1
start, end = start * f, end * f

bits = message.decoded_bits_str[start:end]
bits = message.decoded_bits_str[start-message.alignment_offset:end-message.alignment_offset]
hexs = "".join(("{0:x}".format(int(bits[i:i + 4], 2)) for i in range(0, len(bits), 4)))
decimals = str(int(bits, 2)) if len(bits) > 0 else ""

Expand Down
23 changes: 8 additions & 15 deletions src/urh/controller/dialogs/DecoderDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,16 @@ def choose_encoder(self):

def save_to_file(self):
if self.project_manager.project_file:
prefix = os.path.realpath(os.path.dirname(
self.project_manager.project_file))
self.project_manager.decodings = self.decodings
else:
prefix = os.path.realpath(os.path.join(constants.SETTINGS.fileName(), ".."))

f = open(os.path.join(prefix, constants.DECODINGS_FILE), "w")
if not f:
return

for i in range(0, self.ui.combobox_decodings.count()):
str = ""
for j in self.decodings[i].get_chain():
str += repr(j) + ", "
str += "\n"
f.write(str)

f.close()
with open(os.path.join(prefix, constants.DECODINGS_FILE), "w") as f:
for i in range(0, self.ui.combobox_decodings.count()):
str = ""
for j in self.decodings[i].get_chain():
str += repr(j) + ", "
str += "\n"
f.write(str)

def saveas(self):
# Ask for a name
Expand Down
2 changes: 1 addition & 1 deletion src/urh/signalprocessing/Encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,6 @@ def read_decoders_from_xml_tag(xml_tag: ET.Element):

decoders = []
for decoding_tag in xml_tag.findall("decoding"):
conf = [d.strip().replace("'", "") for d in decoding_tag.text.split(",") if d.strip().replace("'", "")]
conf = [d.strip().replace("'", "") for d in decoding_tag.text.split(",")]
decoders.append(Encoding(conf))
return decoders
21 changes: 6 additions & 15 deletions src/urh/util/ProjectManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def on_simulator_sniff_parameters_changed(self, kwargs: dict):

def load_decodings(self):
if self.project_file:
prefix = os.path.realpath(os.path.dirname(self.project_file))
return
else:
prefix = os.path.realpath(os.path.join(constants.SETTINGS.fileName(), ".."))

Expand All @@ -143,25 +143,16 @@ def load_decodings(self):
self.decodings = fallback
return

if not f:
self.decodings = fallback
return

decodings = []
for line in f:
for line in map(str.strip, f):
tmp_conf = []
for j in line.split(","):
tmp = j.strip()
tmp = tmp.replace("'", "")
if not "\n" in tmp and tmp != "":
tmp_conf.append(tmp)
for j in map(str.strip, line.split(",")):
tmp_conf.append(j.replace("'", ""))
decodings.append(Encoding(tmp_conf))
f.close()

if decodings:
self.decodings = decodings
else:
self.decodings = fallback
self.decodings = decodings if decodings else fallback


@staticmethod
def read_device_conf_dict(tag: ET.Element, target_dict):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_protocol_sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def test_protocol_sniffer(self):
# send data
send_data = np.concatenate(packages)
self.network_sdr_plugin_sender.send_raw_data(send_data, 1)
time.sleep(0.5)
time.sleep(1)

# Send enough pauses to end sniffing
self.network_sdr_plugin_sender.send_raw_data(np.zeros(10 * bit_len, dtype=np.complex64), 1)
time.sleep(0.5)
time.sleep(1)

sniffer.stop()
self.assertEqual(sniffer.plain_bits_str, data)

0 comments on commit f78d7cd

Please sign in to comment.