Last active
May 1, 2016 21:26
-
-
Save altendky/c5150ca098732513287fdd29dd3c9a1e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/canmatrix/canmatrix.py b/canmatrix/canmatrix.py | |
index 78cda25..8199023 100644 | |
--- a/canmatrix/canmatrix.py | |
+++ b/canmatrix/canmatrix.py | |
@@ -149,16 +149,6 @@ class Signal(object): | |
else: | |
self._offset = float(0) | |
- if 'min' in kwargs: | |
- self._min = float(kwargs["min"]) | |
- else: | |
- self._min = float(0) | |
- | |
- if 'max' in kwargs: | |
- self._max = float(kwargs["max"]) | |
- else: | |
- self._max = float(0) | |
- | |
if 'unit' in kwargs: | |
self._unit = kwargs["unit"] | |
else: | |
@@ -183,6 +173,26 @@ class Signal(object): | |
else: | |
self._multiplex = None | |
+ if 'min' in kwargs: | |
+ min = kwargs["min"] | |
+ else: | |
+ min = None | |
+ | |
+ if min is None: | |
+ self.setMin() | |
+ else: | |
+ self._min = float(min) | |
+ | |
+ if 'max' in kwargs: | |
+ max = kwargs["max"] | |
+ else: | |
+ max = None | |
+ | |
+ if max is None: | |
+ self.setMax() | |
+ else: | |
+ self._max = float(max) | |
+ | |
self._name = name | |
self._attributes = {} | |
self._values = {} | |
@@ -272,7 +282,29 @@ class Signal(object): | |
def getLsbStartbit(self): | |
return int(self._startbit) | |
- | |
+ | |
+ def calculateRawRange(self): | |
+ rawRange = 2 ** self._signalsize | |
+ | |
+ if self._is_signed: | |
+ rawRange /= 2 | |
+ | |
+ return (-rawRange if self._is_signed else 0, | |
+ rawRange - 1) | |
+ | |
+ def setMin(self, min=None): | |
+ self._min = min | |
+ | |
+ if self._min is None: | |
+ rawMin = self.calculateRawRange()[0] | |
+ self._min = self._offset + (rawMin * self._factor) | |
+ | |
+ def setMax(self, max=None): | |
+ self._max = max | |
+ | |
+ if self._max is None: | |
+ rawMax = self.calculateRawRange()[1] | |
+ self._max = self._offset + (rawMax * self._factor) | |
class SignalGroup(object): | |
diff --git a/canmatrix/importarxml.py b/canmatrix/importarxml.py | |
index f555ac9..091d670 100644 | |
--- a/canmatrix/importarxml.py | |
+++ b/canmatrix/importarxml.py | |
@@ -82,8 +82,8 @@ def getSignals(signalarray, Bo, arDict, ns, multiplexId): | |
length = arGetChild(syssignal, "LENGTH", arDict, ns) | |
name = arGetChild(syssignal, "SHORT-NAME", arDict, ns) | |
- Min = 0 | |
- Max = 1 | |
+ Min = None | |
+ Max = None | |
factor = 1.0 | |
offset = 0 | |
Unit = "" | |
diff --git a/canmatrix/importkcd.py b/canmatrix/importkcd.py | |
index 250600a..9b5167c 100644 | |
--- a/canmatrix/importkcd.py | |
+++ b/canmatrix/importkcd.py | |
@@ -52,8 +52,8 @@ def parseSignal(signal, mux, namespace, nodelist): | |
unit = "" | |
offset = 0 | |
factor = 1 | |
- min = 0 | |
- max = 1 | |
+ min = None | |
+ max = None | |
is_signed = False | |
values = signal.find('./' + namespace + 'Value') | |
@@ -163,8 +163,8 @@ def importKcd(filename): | |
is_little_endian = True | |
- min = 0 | |
- max = 1 | |
+ min = None | |
+ max = None | |
values = multiplex.find('./' + namespace + 'Value') | |
if values is not None: | |
if 'min' in values.attrib: | |
diff --git a/canmatrix/importsym.py b/canmatrix/importsym.py | |
index 1a85e3c..663c966 100644 | |
--- a/canmatrix/importsym.py | |
+++ b/canmatrix/importsym.py | |
@@ -139,8 +139,8 @@ def importSym(filename, **options): | |
intel = 1 | |
unit = "" | |
factor = 1 | |
- max = 1 | |
- min = 0 | |
+ max = None | |
+ min = None | |
longName = None | |
startValue = 0 | |
offset = 0 | |
diff --git a/canmatrix/importxls.py b/canmatrix/importxls.py | |
index 559aa94..ef40c6a 100644 | |
--- a/canmatrix/importxls.py | |
+++ b/canmatrix/importxls.py | |
@@ -260,8 +260,8 @@ def importXls(filename, **options): | |
newSig._max = float(maxi) | |
except: | |
newSig._offset = 0 | |
- newSig._min = 0 | |
- newSig._max = 1 | |
+ newSig._min = None | |
+ newSig._max = None | |
elif valueName.__len__() > 0: | |
@@ -272,8 +272,8 @@ def importXls(filename, **options): | |
newSig._max = float(maxi) | |
else: | |
newSig._offset = 0 | |
- newSig._min = 0 | |
- newSig._max = 1 | |
+ newSig._min = None | |
+ newSig._max = None | |
for frame in db._fl._list: | |
diff --git a/canmatrix/importxlsx.py b/canmatrix/importxlsx.py | |
index 09d5943..67ff854 100644 | |
--- a/canmatrix/importxlsx.py | |
+++ b/canmatrix/importxlsx.py | |
@@ -339,8 +339,8 @@ def importXlsx(filename, **options): | |
newSig._max = float(maxi) | |
except: | |
newSig._offset = 0 | |
- newSig._min = 0 | |
- newSig._max = 1 | |
+ newSig._min = None | |
+ newSig._max = None | |
elif valueName.__len__() > 0: | |
@@ -351,8 +351,8 @@ def importXlsx(filename, **options): | |
newSig._max = float(maxi) | |
else: | |
newSig._offset = 0 | |
- newSig._min = 0 | |
- newSig._max = 1 | |
+ newSig._min = None | |
+ newSig._max = None | |
# dlc-estimation / dlc is not in xls, thus calculate a minimum-dlc: | |
for frame in db._fl._list: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment