ebroecker / canmatrix

Converting Can (Controller Area Network) Database Formats .arxml .dbc .dbf .kcd ...
BSD 2-Clause "Simplified" License
908 stars 401 forks source link

No Compmethod found on all signals #105

Closed nostar closed 6 years ago

nostar commented 6 years ago

None of the signals in a dbc file converted from arxml have factors/offsets due to 'No Compmethod found!! - try alternate scheme.' on all signals. The compmethods exist, but the layout seems different from other arxml files that work correctly with canmatrix. Here is a snip from an example signal:

<SYSTEM-SIGNAL UUID="xxx">
              <SHORT-NAME>Sig01</SHORT-NAME>
              <PHYSICAL-PROPS>
                <SW-DATA-DEF-PROPS-VARIANTS>
                  <SW-DATA-DEF-PROPS-CONDITIONAL>
                    <COMPU-METHOD-REF DEST="COMPU-METHOD">/1/2/Sig01_CompuMethod</COMPU-METHOD-REF>
                  </SW-DATA-DEF-PROPS-CONDITIONAL>
                </SW-DATA-DEF-PROPS-VARIANTS>
              </PHYSICAL-PROPS>
            </SYSTEM-SIGNAL>

    <COMPU-METHOD UUID="xxx">
              <SHORT-NAME>Sig01_CompuMethod</SHORT-NAME>
              <CATEGORY>LINEAR</CATEGORY>
              <UNIT-REF DEST="UNIT">/1/2/Sig01_Units</UNIT-REF>
              <COMPU-INTERNAL-TO-PHYS>
                <COMPU-SCALES>
                  <COMPU-SCALE>
                    <SHORT-LABEL>Sig01</SHORT-LABEL>
                    <LOWER-LIMIT>0</LOWER-LIMIT>
                    <UPPER-LIMIT>65535</UPPER-LIMIT>
                    <COMPU-RATIONAL-COEFFS>
                      <COMPU-NUMERATOR>
                        <V>0.0</V>
                        <V>0.25</V>
                      </COMPU-NUMERATOR>
                      <COMPU-DENOMINATOR>
                        <V>1</V>
                      </COMPU-DENOMINATOR>
                    </COMPU-RATIONAL-COEFFS>
                  </COMPU-SCALE>
                </COMPU-SCALES>
              </COMPU-INTERNAL-TO-PHYS>
            </COMPU-METHOD>
ebroecker commented 6 years ago

hi nostar, thanks for this arxml-snippet. I'll have a look on it.

nostar commented 6 years ago

Still no scaling in the converted DBC file. I get these lines now for all signals:

DEBUG - arxml - No Compmethod found!! - try alternate scheme 1. DEBUG - arxml - No Compmethod found!! - try alternate scheme 2.

nostar commented 6 years ago

I fixed it, i was gonna make a diff to show the difference but I think you took out your change so it didnt make sense... here is the code that works. Basically it was separate calls of arGetChild to each child instead of one call: (starting at line 1008 of arxml.py)

#####################################################################################################
        #
        #####################################################################################################
        if compmethod == None:
            logger.debug('No Compmethod found!! - try alternate scheme 2.')
            physprop = arGetChild(syssignal, "PHYSICAL-PROPS", arDict, ns)
            datdefpropsvar2 = arGetChild(physprop, "SW-DATA-DEF-PROPS-VARIANTS", arDict, ns)            
            datdefpropscond2 = arGetChild(datdefpropsvar2, "SW-DATA-DEF-PROPS-CONDITIONAL", arDict ,ns)
            if datdefpropscond2 != None:
                try:
                    compmethod = arGetChild(datdefpropscond2, "COMPU-METHOD", arDict, ns)            
                except:
                    logger.debug('No valid compu method found for this - check ARXML file!!')
                    compmethod = None

        unit = arGetChild(compmethod, "UNIT", arDict, ns)
        if unit is not None:
            longname = arGetChild(unit, "LONG-NAME", arDict, ns)

EDIT: I see now, the diff is fine its just against the original code:

--- /usr/lib/python2.7/site-packages/canmatrix/arxml.py.orig    2017-10-26 14:27:09.640931953 -0400
+++ /usr/lib/python2.7/site-packages/canmatrix/arxml.py 2017-10-26 14:26:21.804614418 -0400
@@ -1006,11 +1006,20 @@
                     logger.debug('No valid compu method found for this - check ARXML file!!')
                     compmethod = None
         #####################################################################################################
-        # no found compu-method fuzzy search in systemsignal:
+        #
         #####################################################################################################
         if compmethod == None:
-            logger.debug('No Compmethod found!! - fuzzy search in syssignal.')
-            compmethod = arGetChild(syssignal, "COMPU-METHOD", arDict, ns)
+            logger.debug('No Compmethod found!! - try alternate scheme 2.')
+            physprop = arGetChild(syssignal, "PHYSICAL-PROPS", arDict, ns)
+            datdefpropsvar2 = arGetChild(physprop, "SW-DATA-DEF-PROPS-VARIANTS", arDict, ns)            
+            datdefpropscond2 = arGetChild(datdefpropsvar2, "SW-DATA-DEF-PROPS-CONDITIONAL", arDict ,ns)
+            if datdefpropscond2 != None:
+                try:
+                    compmethod = arGetChild(datdefpropscond2, "COMPU-METHOD", arDict, ns)            
+                except:
+                    logger.debug('No valid compu method found for this - check ARXML file!!')
+                    compmethod = None
+
         unit = arGetChild(compmethod, "UNIT", arDict, ns)
         if unit is not None:
             longname = arGetChild(unit, "LONG-NAME", arDict, ns)
@@ -1023,7 +1032,7 @@
               logger.debug('No Unit Display name found!! - using long name')
             if displayname is not None:
               Unit = displayname.text
-            else:
+            else:  
         #####################################################################################################
         #####################################################################################################              
               l4 = arGetChild(longname, "L-4", arDict, ns)
ebroecker commented 6 years ago

so my simple 'fuzzy'-search works for you also? can I close this Issue?

nostar commented 6 years ago

The only thing that works for me is the patch shown above. The software as it stands in git does not work, nor did the patch https://github.com/ebroecker/canmatrix/commit/141b561d338843919466e901a522e208370f4e83

ebroecker commented 6 years ago

in deed my question is: does the development-branch work for you as is, or does only your patched version work for you?

nostar commented 6 years ago

the development branch does not work as-is. Only my patched version works.

ebroecker commented 6 years ago

I know that https://github.com/ebroecker/canmatrix/commit/141b561d338843919466e901a522e208370f4e83 did not work. But this simpler solution (https://github.com/ebroecker/canmatrix/commit/1eb7224afbd4cabef65059d46bc6d3bcb193d6a6) works for my hacked arxml: test.arxml.txt

Your patch does also work with this hacked arxml. My one is simpler and should be more fault tolerant. Are you shure, https://github.com/ebroecker/canmatrix/commit/1eb7224afbd4cabef65059d46bc6d3bcb193d6a6 does not work for you?

nostar commented 6 years ago

Sorry, I got confused about the different patches. https://github.com/ebroecker/canmatrix/commit/1eb7224afbd4cabef65059d46bc6d3bcb193d6a6 works for me.

ebroecker commented 6 years ago

ok, thanks for checking once more. Thus I can close this issue...