Home:ALL Converter>Python, cantools - How to resolve overlapping signals issue

Python, cantools - How to resolve overlapping signals issue

Ask Time:2022-03-18T21:30:11         Author:Karkar

Json Formatter

I work with quite large sym database with some (multiplexed) messages containing overlapped signals.

I am using this database to decode a CAN communication log files in asc format. It works well unless the message has overlapped signals.

This causes lack of data in the message loaded from file (assuming "missing" data are these for overlapped signals) and decoding stops with error.

  File "C:\Users\xxx\AppData\Local\Programs\Python\Python39\lib\site-packages\bitstruct\__init__.py", line 308, in unpack_from_any
    raise Error(

Error: unpack requires at least 72 bits to unpack (got 64)

Is there any cantools utility / function or some free tool available for a sym database / message modification to remove these overlapped signals?

Or can this to be somehow done within cantools loaded database?

I am looking for such solution because it looks like the cantools library has internally lost the byte order information. Only all signal types and names information are carried to the message decoding point by _parse_format function.

import cantools
import can

dbfile = 'DBFile.sym'
ascfile = 'CANLog.asc'

db = cantools.database.load_file(dbfile,strict=False) #path of .dbc file
#strict=False allows database load with overlaping signals.

# Use ASCReader from python-can (installed as dependency for cantools)
with can.ASCReader(ascfile) as asclog:
    for mesg in asclog:
        dced_msg = db.decode_message(mesg.arbitration_id, mesg.data)

Here is a sample of the mesages:

   0.094000 1   1BBBBBB0x      Rx  d 8 09 D0 FF FF FF FF FF FF
   0.124000 1   1BBBBBB0x      Rx  d 8 0A 3E F0 FF FF FF FF 00

First message multiplex 09 is parsed OK, whilst the other one fails.

Here are the database records related to the messages above:

[A0AT]
Len=8
CycleTime=1000
Mux=_9 0,8 9
Var=Signal00 unsigned 40,8 /u:% /max:100 /e:Signal00
Var=Signal01 unsigned 48,8 /u:% /max:100 /e:Signal01
Var=Signal02 unsigned 10,2 /e:Signal02
Var=Signal03 unsigned 12,2 /e:Signal03
Var=Signal04 unsigned 8,2 /max:1 /e:Signal04
Var=Signal05 unsigned 14,2 /max:1 /e:Signal05
Var=Signal06 unsigned 16,8 /u:°C /o:-40 /min:0 /max:40 /e:Signal06
Var=Signal07 unsigned 24,8 /u:°C /o:-40 /min:0 /max:40 /e:Signal07
Var=Signal08 unsigned 36,4 /e:Signal08
Var=Signal09 unsigned 34,2 /e:Signal09
Var=Signal10 unsigned 32,2 /max:1 /e:Signal10
Var=Signal11 unsigned 56,4 /max:1 /e:Signal11
Var=Signal12 unsigned 60,4 /max:1 /e:Signal12

[A0AT]
Len=8
CycleTime=1000
Mux=_10 0,8 0Ah
Var=Signal00 unsigned 8,7 /u:°C /o:-40 /max:80 /e:Signal00
Var=Signal01 bit 15,1 /e:Signal01
Var=Signal02 unsigned 16,2
Var=Signal03 unsigned 18,2
Var=Signal04 unsigned 28,4 /e:Signal04
Var=Signal05 unsigned 24,2 /e:Signal05
Var=Signal06 unsigned 32,7 /u:°C /o:-40 /e:Signal06
Var=Signal07 unsigned 56,8 /u:°C /e:Signal07
Var=Signal08 unsigned 40,8 /u:°C /o:-40 /e:Signal08
Var=Signal09 unsigned 48,8 /u:°C /o:-40 /e:Signal09
Var=Signal10 unsigned 26,2 /e:Signal10
Var=Signal11 bit 39,1
Var=Signal12 unsigned 8,7 /u:°F /o:32
Var=Signal13 unsigned 32,7 /u:°F /o:32 /e:Signal13
Var=Signal14 unsigned 20,4 /e:Signal14

Please do not mind the signal names, the are modified to allow public presentation.

Author:Karkar,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71527786/python-cantools-how-to-resolve-overlapping-signals-issue
yy