Skip to content

Commit

Permalink
fix #721
Browse files Browse the repository at this point in the history
  • Loading branch information
jopohl committed Jan 25, 2020
1 parent 5460cf5 commit 9664f1d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/urh/signalprocessing/Modulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def bits_per_symbol(self):

@bits_per_symbol.setter
def bits_per_symbol(self, value):
value = int(value)
if value != self.bits_per_symbol:
self.__bits_per_symbol = value
self.parameters = array.array("f", [0] * self.modulation_order)
Expand Down Expand Up @@ -265,13 +266,14 @@ def to_xml(self, index: int) -> ET.Element:

for attr, val in vars(self).items():
if attr not in ("data", "_Modulator__sample_rate", "_Modulator__modulation_type",
"default_sample_rate", "parameters"):
"_Modulator__bits_per_symbol", "default_sample_rate", "parameters"):
root.set(attr, str(val))

root.set("sample_rate", str(self.__sample_rate))
root.set("modulation_type", self.__modulation_type)
root.set("index", str(index))
root.set("parameters", ",".join(map(str, self.parameters)))
root.set("bits_per_symbol", str(self.bits_per_symbol))

return root

Expand All @@ -290,7 +292,7 @@ def estimate_carrier_frequency(self, signal, protocol) -> int or None:
@staticmethod
def from_xml(tag: ET.Element):
result = Modulator("")
for attrib, value in tag.attrib.items():
for attrib, value in sorted(tag.attrib.items()):
if attrib == "index":
continue
elif attrib == "name" or attrib == "modulation_type":
Expand All @@ -304,12 +306,14 @@ def from_xml(tag: ET.Element):
result.parameters[0] = Formatter.str2val(value, float, 0) # legacy
elif attrib == "param_for_one":
result.parameters[1] = Formatter.str2val(value, float, 100) # legacy
elif attrib == "bits_per_symbol":
result.bits_per_symbol = Formatter.str2val(value, int, 1)
elif attrib == "parameters":
try:
result.parameters = array.array("f", map(float, value.split(",")))
except ValueError:
continue
else:
elif not attrib.startswith("_Modulator__"):
setattr(result, attrib, Formatter.str2val(value, float, 1))
return result

Expand Down
2 changes: 1 addition & 1 deletion src/urh/signalprocessing/Signal.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def bits_per_symbol(self):
@bits_per_symbol.setter
def bits_per_symbol(self, value: int):
if self.__bits_per_symbol != value:
self.__bits_per_symbol = value
self.__bits_per_symbol = int(value)
self._qad = None

self.bits_per_symbol_changed.emit(self.__bits_per_symbol)
Expand Down

0 comments on commit 9664f1d

Please sign in to comment.