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

Revision 7192, 7.6 KB (checked in by Snyder.Jason, 5 years ago)

added displayDoxygen() and generateTestWaveform

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