root/ossiedev/branches/jsnyder/ComponentProject/PythonSrc/MainFrameGlue.py @ 7254

Revision 7254, 7.7 KB (checked in by stedwar2, 5 years ago)

Added waveform save support.

RevLine 
[7164]1import sys, os, copy
[7192]2import wavedev.importResource
3import wavedev.importNode
4import wavedev.WaveformClass
5import wavedev.PlatformClass
6import wavedev.ComponentClass
7import threading
[7254]8import cPickle
[7164]9from edu.vt.ossie.jyinterface.interfaces import MainFrame
10
[7192]11class MainFrameTreeNode:
12    def __init__(self, name, contents):
13        self.name = name
14        self.contents = contents
[7246]15
16
[7192]17class RunInNewThread(threading.Thread):
18    def __init__(self, inCommand):
19        self.command = inCommand
20        threading.Thread.__init__(self)
[7246]21
22
[7192]23    def run(self):
24        os.system(self.command)
[7164]25
[7246]26
27
[7164]28class MainFrameGlue(MainFrame):
[7192]29    def __init__(self):
30        self.active_waveform = wavedev.WaveformClass.Waveform()
31        self.active_platform = wavedev.PlatformClass.Platform()
32        self.installPath = "/sdr/"
[7246]33
34
[7164]35    def loadResources(self):
36        self.Available_Components = []
37        self.Available_Devices = []
[7254]38        self.Available_Nodes = []
[7164]39        resList = []
40
41        # List possible resource directories (components and device)
42        baseComponentPath = self.installPath + 'xml/'
43        if os.path.isdir(baseComponentPath):
44            for r in os.listdir(baseComponentPath):
45                if r != 'dtd':  # ignore dtd directory
46                    resList.append( (baseComponentPath,r) )
47        else:
48            errorMsg(self,"No component resources could be found in: " + self.installPath)
49            return
50
51        # find the .scd.xml files for each resource
[7254]52
[7164]53        for r in resList:
54            tmpResName = r[1]
55            tmpResPath = r[0] + r[1]
[7192]56            tmpComp = wavedev.importResource.getResource(tmpResPath,tmpResName,self)
[7254]57
[7164]58            if tmpComp == None:
59                continue
60            if tmpComp.type == 'resource':
61                self.Available_Components.append(tmpComp)
[7254]62
[7164]63            elif tmpComp.type == 'executabledevice':
64                self.Available_Devices.append(tmpComp)
[7254]65
[7164]66            elif tmpComp.type == 'loadabledevice':
67                self.Available_Devices.append(tmpComp)
[7254]68
[7164]69            elif tmpComp.type == 'device':
70                self.Available_Devices.append(tmpComp)
[7254]71
72
[7164]73        nodeList = []
74        if os.path.isdir(self.installPath + 'nodes'):
75            nodeList = os.listdir(self.installPath + 'nodes')
[7192]76            print nodeList
[7164]77        else:
78            errorMsg(self, "No nodes could be found in: " + self.installPath)
[7254]79
[7164]80        # find the scd files for each node
81        for node_name in nodeList:
82
83            # check for existence of DomainManager XML files
84            nodes_root_path = self.installPath + os.path.sep + 'nodes' + os.path.sep + node_name + os.path.sep
85            if not os.path.exists(nodes_root_path + 'DeviceManager.dcd.xml'):
86                errorMsg(self, "Could not find DeviceManager.dcd.xml in: " + nodes_root_path)
87                continue
88            elif not os.path.exists(nodes_root_path + 'DeviceManager.prf.xml'):
89                errorMsg(self, "Could not find DeviceManager.prf.xml in: " + nodes_root_path)
90                continue
91            elif not os.path.exists(nodes_root_path + 'DeviceManager.scd.xml'):
92                errorMsg(self, "Could not find DeviceManager.scd.xml in: " + nodes_root_path)
93                continue
94            elif not os.path.exists(nodes_root_path + 'DeviceManager.spd.xml'):
95                errorMsg(self, "Could not find DeviceManager.spd.xml in: " + nodes_root_path)
96                continue
97
98            nodeName = node_name
99            nodePath = self.installPath + 'nodes/' + nodeName + '/'
[7254]100
[7192]101            print "calling getNode(", nodePath, ",", nodeName, ")"
102            tmpNode = wavedev.importNode.getNode(nodePath,nodeName,self)
[7254]103
[7164]104            if tmpNode == None:
105                print "WARNING: possibly an error reading node " + nodePath + "/" + nodeName
106                continue
[7192]107            self.Available_Nodes.append(tmpNode)
108        return [MainFrameTreeNode("Components", self.Available_Components),
109                MainFrameTreeNode("Devices", self.Available_Devices),
110                MainFrameTreeNode("Nodes", self.Available_Nodes)]
111
[7246]112
[7192]113    def getActiveWaveform(self):
114        return self.active_waveform
[7246]115
116
[7192]117    def getActivePlatform(self):
118        return self.active_platform
[7246]119
120
121    def getOssieInstallPath(self):
122        return self.installPath
123
124
125    def setOssieInstallPath(self, newInstallPath):
126        self.installPath = newInstallPath
127
128
[7192]129    def generateTestWaveform(self):
130        self.active_wave = wavedev.WaveformClass.Waveform()
131        int1 = wavedev.ComponentClass.Interface('complexShort')
132        op1 = wavedev.ComponentClass.Operation('pushPacket','void')
133        param1 = wavedev.ComponentClass.Param('I','PortTypes::ShortSequence','in')
134        param2 = wavedev.ComponentClass.Param('Q','PortTypes::ShortSequence','in')
135        op1.params.extend([param1,param2])
136        int1.operations.append(op1)
137
138        t2 = wavedev.ComponentClass.Component("Transmitter",AC=True)
139        p1 = wavedev.ComponentClass.Port('inPortTx1',copy.deepcopy(int1),'Provides')
140        p2 = wavedev.ComponentClass.Port('outPortTx1',copy.deepcopy(int1),'Uses')
141        t2.ports.append(p1); t2.ports.append(p2)
142        self.active_wave.components.append(t2)
[7254]143
[7192]144        t3 = wavedev.ComponentClass.Component("Channel")
145        p1 = wavedev.ComponentClass.Port('inPortCh1',copy.deepcopy(int1),'Provides')
146        p2 = wavedev.ComponentClass.Port('inPortCh2',copy.deepcopy(int1),'Provides')
147        p3 = wavedev.ComponentClass.Port('inPortCh3',copy.deepcopy(int1),'Provides')
148        p4 = wavedev.ComponentClass.Port('outPortCh1',copy.deepcopy(int1),'Uses')
149        p5 = wavedev.ComponentClass.Port('outPortCh2',copy.deepcopy(int1),'Uses')
150        p6 = wavedev.ComponentClass.Port('outPortCh3',copy.deepcopy(int1),'Uses')
151        t3.ports.extend([p1,p2,p3,p4,p5,p6])
[7254]152        self.active_wave.components.append(t3)
153
[7192]154        t4 = wavedev.ComponentClass.Component("Receiver")
155        p1 = wavedev.ComponentClass.Port('inPortRx1',copy.deepcopy(int1),'Provides')
156        p2 = wavedev.ComponentClass.Port('outPortRx1',copy.deepcopy(int1),'Uses')
157        t4.ports.append(p1); t4.ports.append(p2)
[7254]158        self.active_wave.components.append(t4)
159
[7192]160        temp_dev = wavedev.ComponentClass.Component("GPP")
161        self.active_wave.devices.append(temp_dev)
162        return [MainFrameTreeNode("Sample Waveform", self.active_wave)]
[7254]163
[7192]164    def displayDoxygen(self, referenceMaterials):
165        defaultHtml = 'index.html'
166        defaultPdf = 'refman.pdf'
167        docList = None
[7254]168
[7192]169        docsPath = self.installPath + 'docs/' + referenceMaterials.name
170        print docsPath
171        RunInNewThread('evince ' + "/home/Ossie/Desktop/OSSIE_0.6.2_User_Guide.pdf").start()
172        if os.path.isdir(docsPath):
173            docList = os.listdir(docsPath)
174            if os.path.isfile(docsPath + '/' + defaultHtml):
175                webbrowser.open_new('file://' + docsPath + '/' + defaultHtml)
176            elif os.path.isfile(docsPath + '/' + defaultPdf):
177                #find more portable way to view pdf?
178                try:
179                    RunInNewThread('evince ' + docsPath + '/' + defaultPdf + ' &')
180                finally:
181                    errorMsg(self,'evince pdf viewer threw exception or not found')
182                #webbrowser.open('file://' + docsPath + '/' + defaultPdf, 1)
183            else:
184                errorMsg(self,'Neither index.html nor refman.pdf found in ' + docsPath + ': directory listing: ' + str(docList))
185        else:
[7254]186            errorMsg(self,'No directory for ' + referenceMaterials.name + ' could be found in: ' + self.installPath + 'docs')
[7192]187            return
[7246]188
189
[7192]190    def errorMsg(self, message):
191        sys.stderr.write(message)
[7254]192
193
194    def saveProject(self, saveProjectPath):
195        f = open(saveProjectPath,'w')
196        cPickle.dump(('project',self.active_waveform,self.active_platform),f)
Note: See TracBrowser for help on using the browser.