summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Bruhin <me@the-compiler.org>2012-06-22 08:49:03 +0200
committerFlorian Bruhin <me@the-compiler.org>2012-06-22 08:49:03 +0200
commitf07d4ac9d53ccea1848221f612f6460420cba543 (patch)
treef57f3f61e22c969a6c47bbcda19953aae7d58e49
parent0ce13f191379acfdc461dd0d696d91c38e77bea9 (diff)
downloadxdd2esi-f07d4ac9d53ccea1848221f612f6460420cba543.tar.gz
xdd2esi-f07d4ac9d53ccea1848221f612f6460420cba543.zip
Make _get_py_datatype() in xddlib a function, not a method
-rw-r--r--xddlib.py80
1 files changed, 40 insertions, 40 deletions
diff --git a/xddlib.py b/xddlib.py
index ea7b25c..85a452a 100644
--- a/xddlib.py
+++ b/xddlib.py
@@ -118,45 +118,6 @@ class XDDFile:
_setattributes(subobject, child)
self.objlist.append(canobject)
- def _get_py_datatype(self, obj):
- """ Returns the Datatype of a CAN datatype """
- # signed: If the type is signed (True) or unsigned
- # (False). For strings, None is used.
- # type: Type (int / str)
- # size: Size in bytes - String: (len("x") + 1) * 8
- # name: Name like shown in screenshot
- datatypes = {
- 0x01: (None, 'boolean', 1, 'BOOLEAN'),
- 0x02: (True, 'integer', 8, 'INTEGER8'),
- 0x03: (True, 'integer', 16, 'INTEGER16'),
- 0x04: (True, 'integer', 32, 'INTEGER32'),
- 0x05: (False, 'integer', 8, 'UNSIGNED8'),
- 0x06: (False, 'integer', 16, 'UNSIGNED16'),
- 0x07: (False, 'integer', 32, 'UNSIGNED32'),
- 0x08: (None, 'float', 32, 'REAL32'),
- 0x09: (None, 'string', 0, 'VISIBLE_STRING'),
- 0x0A: (None, 'octet', 0, 'OCTET_STRING'),
- 0x0B: (None, 'unicode', 0, 'UNICODE_STRING'),
- #0x0F: (None, 'domain', 0, 'DOMAIN'),
- 0x10: (True, 'integer', 24, 'INTEGER24'),
- 0x11: (None, 'float', 64, 'REAL64'),
- 0x16: (False, 'integer', 24, 'UNSIGNED24'),
- 0x18: (False, 'integer', 40, 'UNSIGNED40'),
- 0x19: (False, 'integer', 48, 'UNSIGNED48'),
- 0x1A: (False, 'integer', 56, 'UNSIGNED56'),
- 0x1B: (False, 'integer', 64, 'UNSIGNED64'),
- }
- xdd_datatype = int(obj.datatype, 16)
- try:
- list_datatype = datatypes[xdd_datatype]
- except KeyError:
- warnings.warn("Datatype {} is not fully implemented yet!".format(
- xdd_datatype), UnknownDatatypeWarning)
- list_datatype = [None, None, None,
- 'UNKNOWN ({})'.format(xdd_datatype)]
- py_datatype = canlib.Datatype(*list_datatype)
- return py_datatype
-
def _convert_objecttypes(self, obj):
""" Converts the numeric objecttype to a more meaningful string """
objecttypes = {
@@ -171,7 +132,7 @@ class XDDFile:
""" Converts numeric XDD datatypes to datatype-objects """
# toplevel-objects of subobjects don't have a dataType
if obj.datatype is not None:
- py_datatype = self._get_py_datatype(obj)
+ py_datatype = _get_py_datatype(obj)
obj.datatype = py_datatype
special_handlers = {
'string': _set_string_length,
@@ -343,3 +304,42 @@ def _set_octet_length(obj):
size = 8 * length
obj.datatype.length = length
obj.datatype.size = size
+
+def _get_py_datatype(obj):
+ """ Returns the Datatype of a CAN datatype """
+ # signed: If the type is signed (True) or unsigned (False). For strings,
+ # None is used.
+ # type: Type (int / str)
+ # size: Size in bytes - String: (len("x") + 1) * 8
+ # name: Name like shown in screenshot
+ datatypes = {
+ 0x01: (None, 'boolean', 1, 'BOOLEAN'),
+ 0x02: (True, 'integer', 8, 'INTEGER8'),
+ 0x03: (True, 'integer', 16, 'INTEGER16'),
+ 0x04: (True, 'integer', 32, 'INTEGER32'),
+ 0x05: (False, 'integer', 8, 'UNSIGNED8'),
+ 0x06: (False, 'integer', 16, 'UNSIGNED16'),
+ 0x07: (False, 'integer', 32, 'UNSIGNED32'),
+ 0x08: (None, 'float', 32, 'REAL32'),
+ 0x09: (None, 'string', 0, 'VISIBLE_STRING'),
+ 0x0A: (None, 'octet', 0, 'OCTET_STRING'),
+ 0x0B: (None, 'unicode', 0, 'UNICODE_STRING'),
+ #0x0F: (None, 'domain', 0, 'DOMAIN'),
+ 0x10: (True, 'integer', 24, 'INTEGER24'),
+ 0x11: (None, 'float', 64, 'REAL64'),
+ 0x16: (False, 'integer', 24, 'UNSIGNED24'),
+ 0x18: (False, 'integer', 40, 'UNSIGNED40'),
+ 0x19: (False, 'integer', 48, 'UNSIGNED48'),
+ 0x1A: (False, 'integer', 56, 'UNSIGNED56'),
+ 0x1B: (False, 'integer', 64, 'UNSIGNED64'),
+ }
+ xdd_datatype = int(obj.datatype, 16)
+ try:
+ list_datatype = datatypes[xdd_datatype]
+ except KeyError:
+ warnings.warn("Datatype {} is not fully implemented yet!".format(
+ xdd_datatype), UnknownDatatypeWarning)
+ list_datatype = [None, None, None, 'UNKNOWN ({})'.format(
+ xdd_datatype)]
+ py_datatype = canlib.Datatype(*list_datatype)
+ return py_datatype