#!/usr/bin/env python2.1 import sys import Tkinter import Pmw import string from tkFileDialog import askopenfilename # for TestVector lib import TestVectorTMCM import vme, ComDaq title = 'TestVector Player' class Demo: def __init__(self, parent): self.miniMCM=0 # 0 for TMCM, 1 for miniMCM self.tvector = TestVectorTMCM.TestVectorTMCM() # Create the Balloon. self.balloon = Pmw.Balloon() # Create and pack the MenuBar. menuBar = Pmw.MenuBar(parent, #hull_relief = 'raised', #hull_borderwidth = 1, balloon = self.balloon) menuBar.pack(fill = 'x') self.menuBar = menuBar self.srcFilename = '' self.srcBinFilename = '' self.iVecBinFilename = '' self.iVecTxtFilename = '' self.iVecSumFilename = '' self.oVecBinFilename = '' self.oVecTxtFilename = '' self.oVecSumFilename = '' # Add some buttons to the MenuBar. menuBar.addmenu('File', 'Close this window or exit') menuBar.addmenuitem('File', 'command', 'Close this window', command = self.openVecSrcFile, label = 'Open') menuBar.addmenuitem('File', 'separator') menuBar.addmenuitem('File', 'command', 'Close this window', command = PrintOne('Action: close'), label = 'Close') menuBar.addmenuitem('File', 'separator') menuBar.addmenuitem('File', 'command', 'Exit the application', command = parent.destroy, label = 'Exit') ##### Load Source File ##### group1 = Pmw.Group(parent, tag_pyclass = None ) group1.pack(fill = 'both', expand = 1, padx = 10, pady = 5) self.loadSrcButton = Pmw.ButtonBox(group1.interior(), labelpos = 'w', label_text = None, frame_borderwidth = 0, frame_relief = 'groove') self.loadSrcButton.pack(side='left', fill = 'x', expand = 1, padx = 5, pady = 5) self.loadSrcButton.add('Open TestVector source', command = self.openVecSrcFile) self.srcFileMsg = Pmw.MessageBar(group1.interior(), entry_width = 50, entry_relief='groove', labelpos = 'w', label_width=14, label_text = 'source file:') self.srcFileMsg.pack(side='right', fill = 'x', expand = 1, padx = 5, pady = 5) ##### Make Test Vector ##### group2 = Pmw.Group(parent, tag_pyclass = None) group2.pack(fill = 'both', expand = 1, padx = 10, pady = 5) self.buttonMakeVec = Pmw.ButtonBox(group2.interior(), labelpos = 'w', label_text = None, frame_borderwidth = 0, frame_relief = 'groove') self.buttonMakeVec.pack(fill = 'both', expand = 1, padx = 10, pady = 10) #self.buttonMakeVec.pack(side='left', padx = 10, pady = 10) self.buttonMakeVec.add('Make TestVector only', command = self.makeTestVec) self.buttonMakeVec.add('Do everything', command = self.doEverything) self.dutTypeButtons = Pmw.RadioSelect(group2.interior(), orient = 'horizontal', labelpos = 'w', label_text = 'DUT Type: ', hull_borderwidth = 0, hull_relief = 'ridge', command = None ) #self.dutTypeMenu.pack(side='left', padx = 10, pady = 10) self.dutTypeButtons.pack(expand = 1, padx = 10, pady = 10) for text in ('mini MCM','full TMCM') : self.dutTypeButtons.add(text) self.dutTypeButtons.invoke('mini MCM') self.iVecOptButtons = Pmw.RadioSelect(group2.interior(), buttontype = 'checkbutton', orient = 'vertical', labelpos = 'w', command = self.checkOptState, #self.checkbuttoncallback, label_text = 'Output\nfile\noption', hull_borderwidth = 0, hull_relief = 'ridge', ) self.iVecOptButtons.pack(side = 'left', expand = 1, padx = 10, pady = 10) for text in ('binary', 'VHDL', 'summary'): self.iVecOptButtons.add(text) self.iVecBinFileMsg = Pmw.MessageBar(group2.interior(), entry_width = 70, entry_relief='groove', labelpos = 'w', label_width=12, label_text = 'binary file:') self.iVecBinFileMsg.pack(fill = 'x', expand = 1, padx = 10, pady = 5) self.iVecTxtFileMsg = Pmw.MessageBar(group2.interior(), entry_width = 70, entry_relief='groove', labelpos = 'w', label_width = 12, label_text = 'VHDL file:') self.iVecTxtFileMsg.pack(fill = 'x', expand = 1, padx = 10, pady = 5) self.iVecSumFileMsg = Pmw.MessageBar(group2.interior(), entry_width = 70, entry_relief='groove', labelpos = 'w', label_width = 12, label_text = 'summary file:') self.iVecSumFileMsg.pack(fill = 'x', expand = 1, padx = 10, pady = 5) #################### load ##################### group3 = Pmw.Group(parent, tag_pyclass = None) group3.pack(fill = 'both', expand = 1, padx = 10, pady = 5) # Create and pack the ButtonBox. self.loadVecButton = Pmw.ButtonBox(group3.interior(), labelpos = 'w', label_text = None, frame_borderwidth = 0, frame_relief = 'groove') self.loadVecButton.add('Load TestVector to COM board', command = self.loadVecToCom) self.loadVecButton.pack(side = 'left', padx = 5, pady = 5) #self.loadVecButton.grid(col=0, row=0, sticky='e') self.iVecLenMsg = Pmw.MessageBar(group3.interior(), entry_width = 10, entry_relief='groove', labelpos = 'w', label_width = 20, label_text = 'TestVector length = ') self.iVecLenMsg.pack(expand = 1, padx = 5, pady = 5) #################### play ############################ group4 = Pmw.Group(parent, tag_pyclass = None) group4.pack(fill = 'both', expand = 1, padx = 10, pady = 5) # Create and pack the ButtonBox. self.playVecButton = Pmw.ButtonBox(group4.interior(), labelpos = 'w', label_text = None, frame_borderwidth = 0, frame_relief = 'groove') self.playVecButton.pack(fill = 'both', expand = 1, padx = 10, pady = 10) self.playVecButton.add('Play TestVector', command = self.playVec) self.playVecButton.add('Replay', command = self.replayVec) self.oVecOptButtons = Pmw.RadioSelect(group4.interior(), buttontype = 'checkbutton', orient = 'vertical', labelpos = 'w', command = self.checkOptState, #self.playVec, #self.checkbuttoncallback, label_text = 'Output\nfile\noption', hull_borderwidth = 0, hull_relief = 'ridge', ) #self.result_option.pack() self.oVecOptButtons.pack(side = 'left', expand = 1, padx = 10, pady = 10) # Add some buttons to the checkbutton RadioSelect. for text in ('binary', 'VHDL', 'summary'): self.oVecOptButtons.add(text) #self.oVecOptButtons.invoke(text) self.oVecBinFileMsg = Pmw.MessageBar(group4.interior(), entry_width = 70, entry_relief='groove', labelpos = 'w', label_width = 12, label_text = 'binary file:') self.oVecBinFileMsg.pack(fill = 'x', expand = 1, padx = 10, pady = 5) self.oVecTxtFileMsg = Pmw.MessageBar(group4.interior(), entry_width = 70, entry_relief='groove', labelpos = 'w', label_width = 12, label_text = 'VHDL file:') self.oVecTxtFileMsg.pack(fill = 'x', expand = 1, padx = 10, pady = 5) self.oVecSumFileMsg = Pmw.MessageBar(group4.interior(), entry_width = 70, entry_relief='groove', labelpos = 'w', label_width = 12, label_text = 'summary file:') self.oVecSumFileMsg.pack(fill = 'x', expand = 1, padx = 10, pady = 5) ##### function to open source file for test vector ##### def openVecSrcFile(self) : self.srcFilename = askopenfilename(filetypes=[("Python script file","*.py"), ("Binary vector file", "*_in-bin.dat")]) self.srcBinFilename = string.replace(self.srcFilename, '.py', '_in-bin.dat') self.srcFileMsg.message('state', self.srcFilename) self.updateFilename() def updateFilename(self) : if 'binary' in self.iVecOptButtons.getcurselection() : self.iVecBinFilename = self.srcBinFilename else : self.iVecBinFilename = '' if 'VHDL' in self.iVecOptButtons.getcurselection() : self.iVecTxtFilename = string.replace(self.srcBinFilename, '_in-bin.dat', '_in-vhdl.txt') else : self.iVecTxtFilename = '' if 'summary' in self.iVecOptButtons.getcurselection() : self.iVecSumFilename = string.replace(self.srcBinFilename, '_in-bin.dat', '_in-summary.txt') else : self.iVecSumFilename = '' if 'binary' in self.oVecOptButtons.getcurselection() : self.oVecBinFilename = string.replace(self.srcBinFilename, '_in-bin.dat', '_out-bin.dat') else : self.oVecBinFilename = '' if 'VHDL' in self.oVecOptButtons.getcurselection() : self.oVecTxtFilename = string.replace(self.srcBinFilename, '_in-bin.dat', '_out-vhdl.txt') else : self.oVecTxtFilename = '' if 'summary' in self.oVecOptButtons.getcurselection() : self.oVecSumFilename = string.replace(self.srcBinFilename, '_in-bin.dat', '_out-summary.txt') else : self.oVecSumFilename = '' self.iVecBinFileMsg.message('state', self.iVecBinFilename) self.iVecTxtFileMsg.message('state', self.iVecTxtFilename) self.iVecSumFileMsg.message('state', self.iVecSumFilename) self.oVecBinFileMsg.message('state', self.oVecBinFilename) self.oVecTxtFileMsg.message('state', self.oVecTxtFilename) self.oVecSumFileMsg.message('state', self.oVecSumFilename) def checkOptState(self, tag, state) : self.updateFilename() def doEverything(self) : self.makeTestVec() self.loadVecToCom() self.playVec() # make TestVector def makeTestVec(self) : print 'Test Vector for', self.dutTypeButtons.getcurselection() if self.dutTypeButtons.getcurselection() == 'mini MCM' : self.miniMCM = 1 else : self.miniMCM = 0 self.tvector.__init__(self.miniMCM) # create TestVector if string.find(self.srcFilename[-4:], '.py') > 0 : print 'encoding command script...' execfile(self.srcFilename) else : self.tvector.fromfile(open(self.srcFilename, 'r')) print '%d steps in total' % self.tvector.length() # output TestVector to file if self.iVecBinFilename is not '': print 'dumping binary file...' self.tvector.tofile(open(self.iVecBinFilename, 'w')) if self.iVecTxtFilename is not '': print 'dumping VHDL file...' self.tvector.toVHDL(open(self.iVecTxtFilename, 'w')) if self.iVecSumFilename is not '': print 'decoding test vector into summary file...' self.tvector.summarize(output_file=open(self.iVecSumFilename, 'w')) print 'Process to make TestVector finished.' self.iVecLenMsg.message('state', "%d" % self.tvector.length() ) def loadVecToCom(self) : # COM module baseAdrs = 0x40000000 self.com = ComDaq.ComDaq() self.com.setBaseAdrs(baseAdrs) vme.VMEinit () # reset COM module self.com.reset() self.com.clockOn() self.tvector.toCOM(self.com) print 'Loading test vector finished.' def playVec(self) : self.playVecBase() def replayVec(self) : self.playVecBase(replay=1) def playVecBase(self, replay=0) : self.toutput = TestVectorTMCM.TestOutputTMCM(self.tvector) self.toutput.setLoopbackDelay(2) if replay : self.com.replay() else : self.com.play() print 'Playing test vector finishied' self.toutput.fromCOM(self.com, len(self.tvector)) if self.oVecBinFilename is not '': self.toutput.tofile(open(self.oVecBinFilename, 'w')) if self.oVecTxtFilename is not '': self.toutput.toVHDL(open(self.oVecTxtFilename, 'w')) if self.oVecSumFilename is not '': print 'Decoding test output...' self.toutput.applyMonitorMask() self.toutput.summarize(output_file=open(self.oVecSumFilename, 'w')) print 'Process to play TestVector finished.' class PrintOne: def __init__(self, text): self.text = text def __call__(self): print self.text ############################################################ if __name__ == '__main__' : root = Tkinter.Tk() #Pmw.initialise(root, fontScheme = 'pmwl') Pmw.initialise(root) root.title(title) widget = Demo(root) root.mainloop()