| 1 | import sys, os, copy |
|---|
| 2 | import wavedev.importResource |
|---|
| 3 | import wavedev.importNode |
|---|
| 4 | from wavedev.WaveformClass import Waveform |
|---|
| 5 | import wavedev.PlatformClass |
|---|
| 6 | import wavedev.ComponentClass |
|---|
| 7 | import threading |
|---|
| 8 | import cPickle |
|---|
| 9 | from edu.vt.ossie.jyinterface.interfaces import MainFrame |
|---|
| 10 | |
|---|
| 11 | class MainFrameTreeNode: |
|---|
| 12 | def __init__(self, name, contents): |
|---|
| 13 | self.name = name |
|---|
| 14 | self.contents = contents |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | class RunInNewThread(threading.Thread): |
|---|
| 18 | def __init__(self, inCommand): |
|---|
| 19 | self.command = inCommand |
|---|
| 20 | threading.Thread.__init__(self) |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | def run(self): |
|---|
| 24 | os.system(self.command) |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | class MainFrameGlue(MainFrame): |
|---|
| 29 | def __init__(self): |
|---|
| 30 | self.active_waveform = Waveform() |
|---|
| 31 | self.active_platform = wavedev.PlatformClass.Platform() |
|---|
| 32 | self.installPath = "/sdr/" |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | def loadResources(self): |
|---|
| 36 | self.Available_Components = [] |
|---|
| 37 | self.Available_Devices = [] |
|---|
| 38 | self.Available_Nodes = [] |
|---|
| 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 |
|---|
| 52 | |
|---|
| 53 | for r in resList: |
|---|
| 54 | tmpResName = r[1] |
|---|
| 55 | tmpResPath = r[0] + r[1] |
|---|
| 56 | tmpComp = wavedev.importResource.getResource(tmpResPath,tmpResName,self) |
|---|
| 57 | |
|---|
| 58 | if tmpComp == None: |
|---|
| 59 | continue |
|---|
| 60 | if tmpComp.type == 'resource': |
|---|
| 61 | self.Available_Components.append(tmpComp) |
|---|
| 62 | |
|---|
| 63 | elif tmpComp.type == 'executabledevice': |
|---|
| 64 | self.Available_Devices.append(tmpComp) |
|---|
| 65 | |
|---|
| 66 | elif tmpComp.type == 'loadabledevice': |
|---|
| 67 | self.Available_Devices.append(tmpComp) |
|---|
| 68 | |
|---|
| 69 | elif tmpComp.type == 'device': |
|---|
| 70 | self.Available_Devices.append(tmpComp) |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | nodeList = [] |
|---|
| 74 | if os.path.isdir(self.installPath + 'nodes'): |
|---|
| 75 | nodeList = os.listdir(self.installPath + 'nodes') |
|---|
| 76 | print nodeList |
|---|
| 77 | else: |
|---|
| 78 | errorMsg(self, "No nodes could be found in: " + self.installPath) |
|---|
| 79 | |
|---|
| 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 + '/' |
|---|
| 100 | |
|---|
| 101 | print "calling getNode(", nodePath, ",", nodeName, ")" |
|---|
| 102 | tmpNode = wavedev.importNode.getNode(nodePath,nodeName,self) |
|---|
| 103 | |
|---|
| 104 | if tmpNode == None: |
|---|
| 105 | print "WARNING: possibly an error reading node " + nodePath + "/" + nodeName |
|---|
| 106 | continue |
|---|
| 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 | |
|---|
| 112 | |
|---|
| 113 | def getActiveWaveform(self): |
|---|
| 114 | return self.active_waveform |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | def getActivePlatform(self): |
|---|
| 118 | return self.active_platform |
|---|
| 119 | |
|---|
| 120 | |
|---|
| 121 | def getOssieInstallPath(self): |
|---|
| 122 | return self.installPath |
|---|
| 123 | |
|---|
| 124 | |
|---|
| 125 | def setOssieInstallPath(self, newInstallPath): |
|---|
| 126 | self.installPath = newInstallPath |
|---|
| 127 | |
|---|
| 128 | |
|---|
| 129 | def generateTestWaveform(self): |
|---|
| 130 | self.active_waveform = 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_waveform.components.append(t2) |
|---|
| 143 | |
|---|
| 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]) |
|---|
| 152 | self.active_waveform.components.append(t3) |
|---|
| 153 | |
|---|
| 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) |
|---|
| 158 | self.active_waveform.components.append(t4) |
|---|
| 159 | |
|---|
| 160 | temp_dev = wavedev.ComponentClass.Component("GPP") |
|---|
| 161 | self.active_waveform.devices.append(temp_dev) |
|---|
| 162 | return [MainFrameTreeNode("Sample Waveform", self.active_waveform)] |
|---|
| 163 | |
|---|
| 164 | def displayDoxygen(self, referenceMaterials): |
|---|
| 165 | defaultHtml = 'index.html' |
|---|
| 166 | defaultPdf = 'refman.pdf' |
|---|
| 167 | docList = None |
|---|
| 168 | |
|---|
| 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: |
|---|
| 186 | errorMsg(self,'No directory for ' + referenceMaterials.name + ' could be found in: ' + self.installPath + 'docs') |
|---|
| 187 | return |
|---|
| 188 | |
|---|
| 189 | |
|---|
| 190 | def errorMsg(self, message): |
|---|
| 191 | sys.stderr.write(message) |
|---|
| 192 | |
|---|
| 193 | |
|---|
| 194 | def saveProject(self, saveProjectPath): |
|---|
| 195 | f = open(saveProjectPath,'w') |
|---|
| 196 | cPickle.dump(('project',self.active_waveform,self.active_platform),f) |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | def loadProject(self, projectPath): |
|---|
| 200 | f = open(projectPath,'r') |
|---|
| 201 | tmpObject = cPickle.load(f) |
|---|
| 202 | if tmpObject[0] == 'waveform': |
|---|
| 203 | self.active_waveform = tmpObject[1] |
|---|
| 204 | elif tmpObject[0] == 'platform': |
|---|
| 205 | self.active_platform = tmpObject[1] |
|---|
| 206 | elif tmpObject[0] == 'project': |
|---|
| 207 | self.active_waveform = tmpObject[1] |
|---|
| 208 | self.active_platform = tmpObject[2] |
|---|