Repository: ebroecker/canmatrix

Issue:
Cannot parse "Enum" signal types in .Sym files
The PCAN Symbol editor allows several types to be set for signals. These are:

- Bit
- Char
- String
- Signed
- Unsigned
- Float
- Enum
- Double
- Raw

Currently Canmatrix will accept some of these but not all.
The ones which do not work yet are:

- Char
- String
- Enum
- Raw

To make the enum types work we would need to add some more functionality to the Signal class. I think it would be enough to just add a property with the name of the enum (which must appear in the Value_Table for the marix) for the signal.
@ebroecker  I can't see any existing stuff like this, but do any of the other can db formats support anything like this already? (Before i try and make any changes which might be rewriting existing functionality)

Discussion:

Patch:
diff --git a/src/canmatrix/formats/sym.py b/src/canmatrix/formats/sym.py
index b9557d5..cac6bab 100644
--- a/src/canmatrix/formats/sym.py
+++ b/src/canmatrix/formats/sym.py
@@ -440,6 +440,7 @@ def load(f, **options):  # type: (typing.IO, **typing.Any) -> canmatrix.CanMatri
 
                     is_float = False
                     is_ascii = False
+                    enumeration = None
                     if index_offset != 1:
                         is_signed = True
                     else:
@@ -459,7 +460,8 @@ def load(f, **options):  # type: (typing.IO, **typing.Any) -> canmatrix.CanMatri
                             is_float = True
                         elif type_label in ['char', 'string']:
                             is_ascii = True
-                            pass
+                        elif type_label in db.value_tables.keys():
+                            enumeration = type_label
                         else:
                             raise ValueError('Unknown type \'{}\' found'.format(type_label))
 
@@ -582,6 +584,7 @@ def load(f, **options):  # type: (typing.IO, **typing.Any) -> canmatrix.CanMatri
                             multiplex=multiplexor,
                             comment=comment,
                             type_label=type_label,
+                            enumeration=enumeration,
                             **extras)
                         if min_value is not None:
                             signal.min = float_factory(min_value)


Test patch:
diff --git a/src/canmatrix/tests/test_sym.py b/src/canmatrix/tests/test_sym.py
index ff89974..ab7354e 100644
--- a/src/canmatrix/tests/test_sym.py
+++ b/src/canmatrix/tests/test_sym.py
@@ -288,8 +288,8 @@ Var=Char char 1,8
 Var=String string 16,16
 Var=Signed signed 32,4
 Var=Unsigned unsigned 36,4
-'''  # Var=Enum EnumAnimals 40,4
-                   '''
+Var=Enum EnumAnimals 40,4
+
 Var=Raw raw 48,16
 
 [SymbolDouble]
@@ -348,6 +348,7 @@ Var=Float float 0,32	// Must be 4 Bytes according to PCAN Symbol Editor V5
                                                             "String",
                                                             "Signed",
                                                             "Unsigned",
+                                                            "Enum",
                                                             "Raw",
                                                             "Double",
                                                             "Float", ])