Repository: ebroecker/canmatrix

Issue:
Mux value field is interpreted as a signed value when importing a .Sym file
When a can db is loaded from a .sym file the mux value fields are interpreted as signed integers. This means that when decoding, if the mux value is greater than half the max value (so the msb is 1) the number is interpreted incorrectly and is a negative number. 

I dont think the .sym file format allows mux values to be negative. If you try to set a -ve number in the PCAN Symbol editor the number is replaced with the 64 bit 2s complement equivalent in hex as soon as you click off the input box. (e.g -10 goes to FFFFFFFFFFFFFFF6h)

This test illustrates the problem:

```
@pytest.mark.parametrize(
    'var_name,data,raw_value',
    (
        ('VarMux1',   bytearray([1,  12,  0,  0,  0,  0,  0,  0]), 12),
        ('VarMux2',   bytearray([2,  0,  0,  0,  23,  0,  0,  0]), 23),
        ('VarMux200', bytearray([200,  0,  0,  0,  0,  0,  34,  0]), 34),
    )
)
def test_mux_decode(var_name,data,raw_value):
    f = io.BytesIO('''\
    FormatVersion=5.0 // Do not edit this line!
    Title="Types Test"

FormatVersion=5.0 // Do not edit this line!
Title="Test Symbols File"

{SENDRECEIVE}

[MuxTestFrame]
ID=002h
DLC=8
Mux=Mux1 0,8 1 
Var=VarMux1 unsigned 8,8

[MuxTestFrame]
DLC=8
Mux=Mux2 0,8 2 
Var=VarMux2 unsigned 32,8

[MuxTestFrame]
DLC=8
Mux=Mux200 0,8 C8h
Var=VarMux200 unsigned 48,8
    '''.encode('utf-8'),
                   )
    matrix = canmatrix.formats.sym.load(f)
    # Check no errors loading the matrix
    assert matrix.load_errors == []

    frame = matrix.frame_by_name("MuxTestFrame")
    r = frame.decode(data)
    assert var_name in r.keys(), "Signal {}, not decoded".format(var_name)
    assert r[var_name].raw_value == raw_value
```

Here the final case, with mux=200 doesnt work because the value of 200 (0xC8) is interpreted as -56

Discussion:

Patch:
diff --git a/.travis.yml b/.travis.yml
index c3ea345..2ff1def 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -36,8 +36,9 @@ script:
 
 deploy:
   provider: pypi
-  user: ebroecker
+  username: __token__
   skip_existing: true
+  skip_cleanup: true
   on:
     tags: true
     branch: master 
diff --git a/src/canmatrix/formats/sym.py b/src/canmatrix/formats/sym.py
index cc95e18..b7f71f7 100644
--- a/src/canmatrix/formats/sym.py
+++ b/src/canmatrix/formats/sym.py
@@ -442,7 +442,10 @@ def load(f, **options):  # type: (typing.IO, **typing.Any) -> canmatrix.CanMatri
                     is_float = False
                     is_ascii = False
                     enumeration = None
-                    if index_offset != 1:
+
+                    if tmp_mux == "Mux":
+                        is_signed = False
+                    elif index_offset != 1 :
                         is_signed = True
                     else:
                         is_signed = False


Test patch:
diff --git a/src/canmatrix/tests/test_sym.py b/src/canmatrix/tests/test_sym.py
index ab7354e..79048f6 100644
--- a/src/canmatrix/tests/test_sym.py
+++ b/src/canmatrix/tests/test_sym.py
@@ -3,6 +3,7 @@ import io
 import sys
 import textwrap
 from itertools import chain
+from pprint import pprint
 
 import pytest
 
@@ -353,4 +354,47 @@ Var=Float float 0,32	// Must be 4 Bytes according to PCAN Symbol Editor V5
                                                             "Double",
                                                             "Float", ])
 
+@pytest.mark.parametrize(
+    'var_name,data,raw_value',
+    (
+        ('VarMux1',   bytearray([1,  12,  0,  0,  0,  0,  0,  0]), 12),
+        ('VarMux2',   bytearray([2,  0,  0,  0,  23,  0,  0,  0]), 23),
+        ('VarMux200', bytearray([200,  0,  0,  0,  0,  0,  34,  0]), 34),
+    )
+)
+def test_mux_decode(var_name,data,raw_value):
+    f = io.BytesIO('''\
+    FormatVersion=5.0 // Do not edit this line!
+    Title="Types Test"
+
+FormatVersion=5.0 // Do not edit this line!
+Title="Test Symbols File"
+
+{SENDRECEIVE}
+
+[MuxTestFrame]
+ID=002h
+DLC=8
+Mux=Mux1 0,8 1 
+Var=VarMux1 unsigned 8,8
+
+[MuxTestFrame]
+DLC=8
+Mux=Mux2 0,8 2 
+Var=VarMux2 unsigned 32,8
+
+[MuxTestFrame]
+DLC=8
+Mux=Mux200 0,8 C8h
+Var=VarMux200 unsigned 48,8
+    '''.encode('utf-8'),
+                   )
+
+    matrix = canmatrix.formats.sym.load(f)
+    # Check no errors loading the matrix
+    assert matrix.load_errors == []
 
+    frame = matrix.frame_by_name("MuxTestFrame")
+    r = frame.decode(data)
+    assert var_name in r.keys(), "Signal {}, not decoded. Only : {}".format(var_name, ','.join(r for r in r.keys()))
+    assert r[var_name].raw_value == raw_value
\ No newline at end of file