Esempio n. 1
0
    def convert_exec(self, out_put_file, option):
        print("convert")
        print(out_put_file)
        options = self.option

        dbs = self.dbs
        outdbs = {}
        for name in dbs:
            db = None

            if 'ecus' in options and options['ecus'] is not None:
                ecuList = options['ecus'].split(',')
                db = cm.CanMatrix()
                for ecu in ecuList:
                    cmcp.copyBUwithFrames(ecu, dbs[name], db)
            if 'frames' in options and options['frames'] is not None:
                frameList = options['frames'].split(',')
                db = cm.CanMatrix()
                for frame in frameList:
                    cmcp.copyFrame(frame, dbs[name], db)
            if db is None:
                db = dbs[name]

            outdbs[name] = db

        out = canmatrix.formats.dumpp(outdbs, out_put_file)

        if out == -1:
            self.textEdit.append("Convert Failed!")
            self.open_convert_done_file_btn.setEnabled(False)
        else:
            self.textEdit.append("Convert Success!")
            self.textEdit.append("Out put file: " + out_put_file)
            self.convert_done_file_name = out_put_file
            self.open_convert_done_file_btn.setEnabled(True)
Esempio n. 2
0
def convert(infile, outfileName, **options):
    dbs = {}

    logger.info("Importing " + infile + " ... ")
    dbs = canmatrix.formats.loadp(infile, **options)
    logger.info("done\n")

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

    outdbs = {}
    for name in dbs:
        db = None

        if 'ecus' in options and options['ecus'] is not 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'] is not 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 is None:
            db = dbs[name]

        if 'merge' in options and options['merge'] is not None:
            mergeFiles = options['merge'].split(',')
            for database in mergeFiles:
                mergeString = database.split(':')
                dbTempList = canmatrix.formats.loadp(mergeString[0])
                for dbTemp in dbTempList:
                    if mergeString.__len__() == 1:
                        print("merge complete: " + mergeString[0])
                        for frame in dbTempList[dbTemp].frames:
                            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 'renameEcu' in options and options['renameEcu'] is not None:
            renameTuples = options['renameEcu'].split(',')
            for renameTuple in renameTuples:
                old, new = renameTuple.split(':')
                db.renameEcu(old, new)
        if 'deleteEcu' in options and options['deleteEcu'] is not None:
            deleteEcuList = options['deleteEcu'].split(',')
            for ecu in deleteEcuList:
                db.delEcu(ecu)
        if 'renameFrame' in options and options['renameFrame'] is not None:
            renameTuples = options['renameFrame'].split(',')
            for renameTuple in renameTuples:
                old, new = renameTuple.split(':')
                db.renameFrame(old, new)
        if 'deleteFrame' in options and options['deleteFrame'] is not None:
            deleteFrameList = options['deleteFrame'].split(',')
            for frame in deleteFrameList:
                db.delFrame(frame)
        if 'renameSignal' in options and options['renameSignal'] is not None:
            renameTuples = options['renameSignal'].split(',')
            for renameTuple in renameTuples:
                old, new = renameTuple.split(':')
                db.renameSignal(old, new)
        if 'deleteSignal' in options and options['deleteSignal'] is not None:
            deleteSignalList = options['deleteSignal'].split(',')
            for signal in deleteSignalList:
                db.delSignal(signal)

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

        if 'deleteSignalAttributes' in options and options[
                'deleteSignalAttributes']:
            unwantedAttributes = options['deleteSignalAttributes'].split(',')
            db.delSignalAttributes(unwantedAttributes)

        if 'deleteFrameAttributes' in options and options[
                'deleteFrameAttributes']:
            unwantedAttributes = options['deleteFrameAttributes'].split(',')
            db.delFrameAttributes(unwantedAttributes)

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

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

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

        outdbs[name] = db

    if 'force_output' in options and options['force_output'] is not None:
        canmatrix.formats.dumpp(outdbs,
                                outfileName,
                                exportType=options['force_output'],
                                **options)
    else:
        canmatrix.formats.dumpp(outdbs, outfileName, **options)
    logger.info("done")
Esempio n. 3
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")
Esempio n. 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")
Esempio n. 5
0
def convert(infile, outfileName, **options):
    import canmatrix.exportany 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 'deleteSignalAttributes' in options and options[
                'deleteSignalAttributes']:
            unwantedAttributes = options['deleteSignalAttributes'].split(',')
            db.delSignalAttributes(unwantedAttributes)

        if 'deleteFrameAttributes' in options and options[
                'deleteFrameAttributes']:
            unwantedAttributes = options['deleteFrameAttributes'].split(',')
            db.delFrameAttributes(unwantedAttributes)

        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

        ex.exportany(db, outfile, **options)
    logger.info("done")