Пример #1
0
def convert(infile, outfileName, **options):
    dbs = {}
    print("Importing " + infile + " ... ")
    if infile[-3:] == 'dbc':
        dbs[""] = im.importDbc(infile, **options)
    elif infile[-3:] == 'dbf':
        dbs[""] = im.importDbf(infile, **options)
    elif infile[-3:] == 'sym':
        dbs[""] = im.importSym(infile, **options)
    elif infile[-3:] == 'kcd':
        dbs[""] = im.importKcd(infile)
    elif infile[-3:] == 'xls':
        dbs[""] = im.importXls(infile, **options)
    elif infile[-4:] == 'xlsx' :
        dbs[""] = im.importXlsx(infile, **options)
    elif infile[-5:] == 'arxml':
        dbs = im.importArxml(infile, **options)
    elif infile[-4:] == 'yaml':
        dbs[""] = im.importYaml(infile)
    else:
        sys.stderr.write('\nFile not recognized: ' + infile + "\n")
    print("done\n")


    print("Exporting " + outfileName + " ... ")

    for name in dbs:
        db = dbs[name]
        print(name)
        print("%d Frames found" % (db._fl._list.__len__()))

        if len(name) > 0:
            path = os.path.split(outfileName)
            outfile = os.path.join(path[0], name + "_" + path[1])
        else:
            outfile = outfileName
        if outfile[-3:] == 'dbc':
            ex.exportDbc(db, outfile, **options)
        elif outfile[-3:] == 'dbf':
            ex.exportDbf(db, outfile, **options)
        elif outfile[-3:] == 'sym':
            ex.exportSym(db, outfile, **options)
        elif outfile[-3:] == 'kcd':
            ex.exportKcd(db, outfile)
        elif outfile[-4:] == 'xlsx':
            ex.exportXlsx(db, outfile, **options)
        elif outfile[-3:] == 'xls':
            ex.exportXls(db, outfile, **options)
        elif outfile[-4:] == 'json':
            ex.exportJson(db, outfile)
        elif outfile[-5:] == 'arxml':
            ex.exportArxml(db, outfile)
        elif outfile[-4:] == 'yaml':
            ex.exportYaml(db, outfile)
        elif outfile[-3:] == 'csv':
            ex.exportCsv(db, outfile)
        else:
            sys.stderr.write('File not recognized: ' + outfileName + "\n")
    print("done")
Пример #2
0
def convert(infile, outfileName, **options):
    import canmatrix.exportall as ex
    import canmatrix.importall as im
    dbs = {}
    logger.info("Importing " + infile + " ... ")
    if infile[-3:] == 'dbc':
        dbs[""] = im.importDbc(infile, **options)
    elif infile[-3:] == 'dbf':
        dbs[""] = im.importDbf(infile, **options)
    elif infile[-3:] == 'sym':
        dbs[""] = im.importSym(infile, **options)
    elif infile[-3:] == 'kcd':
        dbs[""] = im.importKcd(infile)
    elif infile[-3:] == 'xls':
        dbs[""] = im.importXls(infile, **options)
    elif infile[-4:] == 'xlsx' :
        dbs[""] = im.importXlsx(infile, **options)
    elif infile[-5:] == 'arxml':
        dbs = im.importArxml(infile, **options)
    elif infile[-4:] == 'yaml':
        dbs[""] = im.importYaml(infile)
    else:
        logger.error('\nFile not recognized: ' + infile + "\n")
    logger.info("done\n")


    logger.info("Exporting " + outfileName + " ... ")

    for name in dbs:
        db = dbs[name]

        if 'deleteZeroSignals' in options and options['deleteZeroSignals']:
            db.deleteZeroSignals()
        
        if 'recalcDLC' in options and options['recalcDLC']:
            db.recalcDLC(options['recalcDLC'])

        logger.info(name)
        logger.info("%d Frames found" % (db._fl._list.__len__()))

        if len(name) > 0:
            path = os.path.split(outfileName)
            outfile = os.path.join(path[0], name + "_" + path[1])
        else:
            outfile = outfileName
           
        # Get output file extension   
        fileext = '' 
        if 'force_output' in options and options['force_output']:
            # Provided by the command line
            fileext = options['force_output']
        else:
            # Get extension from output filename
            fileext = os.path.splitext(outfile)[1]
       
        # Strip leading '.' from extension, of exists
        fileext = fileext[1:] if fileext.startswith('.') else fileext
         
                        
        if fileext == 'dbc':
            ex.exportDbc(db, outfile, **options)
        elif fileext == 'dbf':
            ex.exportDbf(db, outfile, **options)
        elif fileext == 'sym':
            ex.exportSym(db, outfile, **options)
        elif fileext == 'kcd':
            ex.exportKcd(db, outfile)
        elif fileext == 'xlsx':
            ex.exportXlsx(db, outfile, **options)
        elif fileext == 'xls':
            ex.exportXls(db, outfile, **options)
        elif fileext == 'json':
            ex.exportJson(db, outfile)
        elif fileext == 'arxml':
            ex.exportArxml(db, outfile)
        elif fileext == 'yaml':
            ex.exportYaml(db, outfile)
        elif fileext == 'csv':
            ex.exportCsv(db, outfile)
        else:
            logger.error('File not recognized: ' + outfileName + "\n")
    logger.info("done")
Пример #3
0
# create target Matrix
#

db3 = CanMatrix()

#
# Here a new Can-Matrix can be  'programmed':
# -----------------------------------------------------
#

#Copy Can-ID 1234 from second CAN-Matrix to target-Matrix
copyFrame(1234, db2, db3)

#Copy frame "Engine_123" from first CAN-Matrix to target-Matrix
copyFrame("Engine_123", db1, db3)

#Copy ECU (with all Frames) "Gateway" from first CAN-Matrix to target-Matrix
copyBUwithFrames("Gateway", db1, db3)

#
# -----------------------------------------------------
#


#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db3, "target.dbc")
Пример #4
0
def convert(infile, outfileName, **options):
    import canmatrix.exportall as ex
    import canmatrix.importany as im
    import canmatrix.canmatrix as cm
    import canmatrix.copy as cmcp
    dbs = {}

    logger.info("Importing " + infile + " ... ")
    dbs = im.importany(infile, **options)
    logger.info("done\n")

    logger.info("Exporting " + outfileName + " ... ")

    for name in dbs:
        db = None        

        if 'ecus' in options and options['ecus'] != None:
            ecuList = options['ecus'].split(',')
            db = cm.CanMatrix()
            for ecu in ecuList:
                logger.info("Copying ECU " + ecu)
                cmcp.copyBUwithFrames(ecu, dbs[name], db) 
        if 'frames' in options and options['frames'] != None:
            frameList = options['frames'].split(',')
            db = cm.CanMatrix()
            for frame in frameList:
                logger.info("Copying Frame " + frame)
                cmcp.copyFrame(frame, dbs[name], db) 
        if db == None:
            db = dbs[name]

        if 'merge' in options and options['merge'] != None:
            mergeFiles = options['merge'].split(',')
            for database in mergeFiles:
                mergeString = database.split(':')
                dbTempList = im.importany(mergeString[0])
                for dbTemp in dbTempList:
                    if mergeString.__len__() == 1:
                        print ("merge complete: " + mergeString[0])                    
                        for frame in dbTempList[dbTemp]._fl._list:
                            cmcp.copyFrame (frame._Id, dbTempList[dbTemp], db)
                    for mergeOpt in mergeString[1:]:
                        if mergeOpt.split('=')[0] == "ecu":
                            cmcp.copyBUwithFrames(mergeOpt.split('=')[1], dbTempList[dbTemp], db) 
                        if mergeOpt.split('=')[0] == "frame":
                            cmcp.copyFrame(mergeOpt.split('=')[1], dbTempList[dbTemp], db) 


        if 'deleteZeroSignals' in options and options['deleteZeroSignals']:
            db.deleteZeroSignals()
        
        if 'recalcDLC' in options and options['recalcDLC']:
            db.recalcDLC(options['recalcDLC'])

        logger.info(name)
        logger.info("%d Frames found" % (db._fl._list.__len__()))

        if len(name) > 0:
            path = os.path.split(outfileName)
            outfile = os.path.join(path[0], name + "_" + path[1])
        else:
            outfile = outfileName
           
        # Get output file extension   
        fileext = '' 
        if 'force_output' in options and options['force_output']:
            # Provided by the command line
            fileext = options['force_output']
        else:
            # Get extension from output filename
            fileext = os.path.splitext(outfile)[1]
       
        # Strip leading '.' from extension, of exists
        fileext = fileext[1:] if fileext.startswith('.') else fileext
         
                        
        if fileext == 'dbc':
            ex.exportDbc(db, outfile, **options)
        elif fileext == 'dbf':
            ex.exportDbf(db, outfile, **options)
        elif fileext == 'sym':
            ex.exportSym(db, outfile, **options)
        elif fileext == 'kcd':
            ex.exportKcd(db, outfile)
        elif fileext == 'xlsx':
            ex.exportXlsx(db, outfile, **options)
        elif fileext == 'xls':
            ex.exportXls(db, outfile, **options)
        elif fileext == 'json':
            ex.exportJson(db, outfile, **options)
        elif fileext == 'arxml':
            ex.exportArxml(db, outfile)
        elif fileext == 'yaml':
            ex.exportYaml(db, outfile)
        elif fileext == 'csv':
            ex.exportCsv(db, outfile)
        else:
            logger.error('File not recognized: ' + outfileName + "\n")
    logger.info("done")
Пример #5
0
mySignal2.addValues(3, "three")

mySignal.addComment(
    "Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8"))
myFrame.addComment("Multi \n Line \n Frame comment")

myFrame.addSignal(mySignal)
myFrame.addSignal(mySignal2)

myFrame2 = Frame(0x12, "extendedFrame", 8, "testBU")
myFrame2._extended = 1

db._fl.addFrame(myFrame)
db._fl.addFrame(myFrame2)

db.boardUnitByName("testBU").addComment("sender ECU")
db.boardUnitByName("testBU").addAttribute("NetworkNode", 0x111)
db.boardUnitByName("recBU").addComment("receiver ECU")

db.frameByName("testFrame1").addAttribute("GenMsgCycleTime", 100)

db.addFrameDefines("GenMsgCycleTime", 'INT 0 65535')
db.addBUDefines("NetworkNode", 'INT 0 65535')

#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db, "test.dbc", 'iso-8859-1', 'iso-8859-1')
Пример #6
0
mySignal2 = Signal("Signal", 20, 3, 1, "+", 1.0, 0.0, 0, 6, "someUnit", ["recBU"])
mySignal2.addValues(1, "one")
mySignal2.addValues(2, "two")
mySignal2.addValues(3, "three")

mySignal.addComment("Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8"))
myFrame.addComment("Multi \n Line \n Frame comment")

myFrame.addSignal(mySignal)
myFrame.addSignal(mySignal2)


db._fl.addFrame(myFrame)

db.boardUnitByName("testBU").addComment("sender ECU")
db.boardUnitByName("testBU").addAttribute("NetworkNode", 0x111)
db.boardUnitByName("recBU").addComment("reciever ECU")

db.frameByName("testFrame1").addAttribute("GenMsgCycleTime", 100)

db.addFrameDefines("GenMsgCycleTime",  'INT 0 65535')


#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db, "test.dbc", 'iso-8859-1', 'iso-8859-1')

Пример #7
0
mySignal2.addValues(3, "three")

mySignal.addComment("Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8"))
myFrame.addComment("Multi \n Line \n Frame comment")

myFrame.addSignal(mySignal)
myFrame.addSignal(mySignal2)

myFrame2 = Frame(0x12, "extendedFrame", 8, "testBU")
myFrame2._extended = 1

db._fl.addFrame(myFrame)
db._fl.addFrame(myFrame2)

db.boardUnitByName("testBU").addComment("sender ECU")
db.boardUnitByName("testBU").addAttribute("NetworkNode", 0x111)
db.boardUnitByName("recBU").addComment("receiver ECU")

db.frameByName("testFrame1").addAttribute("GenMsgCycleTime", 100)

db.addFrameDefines("GenMsgCycleTime", "INT 0 65535")
db.addBUDefines("NetworkNode", "INT 0 65535")


#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db, "test.dbc", "iso-8859-1", "iso-8859-1")
Пример #8
0
def convert(infile, outfileName, **options):
    import canmatrix.exportall as ex
    import canmatrix.importany as im
    import canmatrix.canmatrix as cm
    import canmatrix.copy as cmcp
    dbs = {}

    logger.info("Importing " + infile + " ... ")
    dbs = im.importany(infile, **options)
    logger.info("done\n")

    logger.info("Exporting " + outfileName + " ... ")

    for name in dbs:
        db = None

        if 'ecus' in options and options['ecus'] != None:
            ecuList = options['ecus'].split(',')
            db = cm.CanMatrix()
            for ecu in ecuList:
                logger.info("Copying ECU " + ecu)
                cmcp.copyBUwithFrames(ecu, dbs[name], db)
        if 'frames' in options and options['frames'] != None:
            frameList = options['frames'].split(',')
            db = cm.CanMatrix()
            for frame in frameList:
                logger.info("Copying Frame " + frame)
                cmcp.copyFrame(frame, dbs[name], db)
        if db == None:
            db = dbs[name]

        if 'merge' in options and options['merge'] != None:
            mergeFiles = options['merge'].split(',')
            for database in mergeFiles:
                mergeString = database.split(':')
                dbTempList = im.importany(mergeString[0])
                for dbTemp in dbTempList:
                    if mergeString.__len__() == 1:
                        print("merge complete: " + mergeString[0])
                        for frame in dbTempList[dbTemp]._fl._list:
                            cmcp.copyFrame(frame._Id, dbTempList[dbTemp], db)
                    for mergeOpt in mergeString[1:]:
                        if mergeOpt.split('=')[0] == "ecu":
                            cmcp.copyBUwithFrames(
                                mergeOpt.split('=')[1], dbTempList[dbTemp], db)
                        if mergeOpt.split('=')[0] == "frame":
                            cmcp.copyFrame(
                                mergeOpt.split('=')[1], dbTempList[dbTemp], db)

        if 'deleteZeroSignals' in options and options['deleteZeroSignals']:
            db.deleteZeroSignals()

        if 'recalcDLC' in options and options['recalcDLC']:
            db.recalcDLC(options['recalcDLC'])

        logger.info(name)
        logger.info("%d Frames found" % (db._fl._list.__len__()))

        if len(name) > 0:
            path = os.path.split(outfileName)
            outfile = os.path.join(path[0], name + "_" + path[1])
        else:
            outfile = outfileName

        # Get output file extension
        fileext = ''
        if 'force_output' in options and options['force_output']:
            # Provided by the command line
            fileext = options['force_output']
        else:
            # Get extension from output filename
            fileext = os.path.splitext(outfile)[1]

        # Strip leading '.' from extension, of exists
        fileext = fileext[1:] if fileext.startswith('.') else fileext

        if fileext == 'dbc':
            ex.exportDbc(db, outfile, **options)
        elif fileext == 'dbf':
            ex.exportDbf(db, outfile, **options)
        elif fileext == 'sym':
            ex.exportSym(db, outfile, **options)
        elif fileext == 'kcd':
            ex.exportKcd(db, outfile)
        elif fileext == 'xlsx':
            ex.exportXlsx(db, outfile, **options)
        elif fileext == 'xls':
            ex.exportXls(db, outfile, **options)
        elif fileext == 'json':
            ex.exportJson(db, outfile, **options)
        elif fileext == 'arxml':
            ex.exportArxml(db, outfile)
        elif fileext == 'yaml':
            ex.exportYaml(db, outfile)
        elif fileext == 'csv':
            ex.exportCsv(db, outfile)
        else:
            logger.error('File not recognized: ' + outfileName + "\n")
    logger.info("done")
Пример #9
0
mySignal2 = Signal("Signal", 20, 3, 1, "+", 1.0, 0.0, 0, 6, "someUnit", ["recBU"])
mySignal2.addValues(1, "one")
mySignal2.addValues(2, "two")
mySignal2.addValues(3, "three")

mySignal.addComment("Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8"))
myFrame.addComment("Multi \n Line \n Frame comment")

myFrame.addSignal(mySignal)
myFrame.addSignal(mySignal2)


db._fl.addFrame(myFrame)

db.boardUnitByName("testBU").addComment("sender ECU")
db.boardUnitByName("testBU").addAttribute("NetworkNode", 0x111)
db.boardUnitByName("recBU").addComment("reciever ECU")

db.frameByName("testFrame1").addAttribute("GenMsgCycleTime", 100)

db.addFrameDefines("GenMsgCycleTime",  'INT 0 65535')


#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db, "test.dbc", 'utf-8', 'utf-8')

Пример #10
0
#!/usr/bin/env python3

import canmatrix.exportall as ex
from canmatrix.join import join_frame_by_signal_startbit

files = ["../test/db_B.dbc", "../test/db_A.dbc"]

target = join_frame_by_signal_startbit(files)

#
# export the new (target)-Matrix for example as .dbc:
#
ex.exportDbc(target, "target.dbc")
ex.exportXlsx(target, "target.xlsx")
Пример #11
0
mySignal.addComment("Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8"))
myFrame.addComment("Multi \n Line \n Frame comment")

myFrame.addSignal(mySignal)
myFrame.addSignal(mySignal2)

myFrame2 = Frame("extendedFrame", Id = 0x12,  dlc = 8, transmitter = "testBU" )
myFrame2._extended = 1

db._fl.addFrame(myFrame)
db._fl.addFrame(myFrame2)

db.boardUnitByName("testBU").addComment("sender ECU")
db.boardUnitByName("testBU").addAttribute("NetworkNode", 0x111)
db.boardUnitByName("recBU").addComment("receiver ECU")

db.frameByName("testFrame1").addAttribute("GenMsgCycleTime", 100)

db.addFrameDefines("GenMsgCycleTime",  'INT 0 65535')
db.addBUDefines("NetworkNode", 'INT 0 65535')


#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db, "test.dbc", dbcExportEncoding='iso-8859-1', dbcExportCommentEncoding='iso-8859-1')

Пример #12
0
    "Multi \n Line \n Signal comment with a-umlaut: ä".decode("utf-8"))
myFrame.addComment("Multi \n Line \n Frame comment")

myFrame.addSignal(mySignal)
myFrame.addSignal(mySignal2)

myFrame2 = Frame("extendedFrame", Id=0x12, dlc=8, transmitter="testBU")
myFrame2._extended = 1

db._fl.addFrame(myFrame)
db._fl.addFrame(myFrame2)

db.boardUnitByName("testBU").addComment("sender ECU")
db.boardUnitByName("testBU").addAttribute("NetworkNode", 0x111)
db.boardUnitByName("recBU").addComment("receiver ECU")

db.frameByName("testFrame1").addAttribute("GenMsgCycleTime", 100)

db.addFrameDefines("GenMsgCycleTime", 'INT 0 65535')
db.addBUDefines("NetworkNode", 'INT 0 65535')

#
#
# export the new (target)-Matrix for example as .dbc:
#

ex.exportDbc(db,
             "test.dbc",
             dbcExportEncoding='iso-8859-1',
             dbcExportCommentEncoding='iso-8859-1')