def join_frame_for_manufacturer(db, files): #targetDb = next(iter(im.importany(files.pop(0)).values())) pgn_x, id_x = list_pgn(db=db) for f in files: sourceDb = next(iter(canmatrix.formats.loadp(f).values())) pgn_y, id_y = list_pgn(db=sourceDb) same_pgn = ids_sharing_same_pgn(id_x, pgn_x, id_y, pgn_y) for idx, idy in same_pgn: # print("{0:#x} {1:#x}".format(idx, idy)) targetFr = db.frameById(idx) sourceFr = sourceDb.frameById(idy) _, pgn, sa = CanId(targetFr.id).tuples() if(sa < 128): print('less', targetFr.name) to_add = [] for sig_s in sourceFr.signals: new_name = "{name}_{pgn:#04x}_{sa:03}".format( name=sig_s.name, pgn=pgn, sa=sa) sig_s.name = new_name to_add.append(sig_s) for s in to_add: targetFr.addSignal(s)
def renameFrameWithID(sourceDb): for frameSc in sourceDb.frames: _, pgn, sa = CanId(frameSc.id).tuples() exten = "__{pgn:#04X}_{sa:#02X}_{sa:03d}d".format(pgn=pgn, sa=sa) new_name = frameSc.name + exten # print(new_name) frameSc.name = new_name
def list_pgn(db): """ :param db: :return: pgn and id """ id = [x.id for x in db.frames] r = [CanId(t).tuples() for t in id] return [t[1] for t in r], id