| 1 | ## Copyright 2008 Virginia Polytechnic Institute and State University |
|---|
| 2 | ## |
|---|
| 3 | ## This file is part of the OSSIE Waveform Developer. |
|---|
| 4 | ## |
|---|
| 5 | ## OSSIE Waveform Developer is free software; you can redistribute it and/or |
|---|
| 6 | ## modify it under the terms of the GNU General Public License as published by |
|---|
| 7 | ## the Free Software Foundation; either version 2 of the License, or |
|---|
| 8 | ## (at your option) any later version. |
|---|
| 9 | ## |
|---|
| 10 | ## OSSIE Waveform Developer is distributed in the hope that it will be useful, |
|---|
| 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 13 | ## GNU General Public License for more details. |
|---|
| 14 | ## |
|---|
| 15 | ## You should have received a copy of the GNU General Public License |
|---|
| 16 | ## along with OSSIE Waveform Developer; if not, write to the Free Software |
|---|
| 17 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 18 | |
|---|
| 19 | ## $Author$ |
|---|
| 20 | ## $Id$ |
|---|
| 21 | |
|---|
| 22 | import sys, os, copy |
|---|
| 23 | import wavedev.importResource |
|---|
| 24 | import wavedev.importNode |
|---|
| 25 | import wavedev.WaveformClass |
|---|
| 26 | from wavedev.WaveformClass import Waveform |
|---|
| 27 | import wavedev.PlatformClass |
|---|
| 28 | import wavedev.ComponentClass |
|---|
| 29 | import threading |
|---|
| 30 | import cPickle |
|---|
| 31 | from edu.vt.ossie.jyinterface.interfaces import MainFrame |
|---|
| 32 | import traceback |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | #def newUuidgen(): |
|---|
| 36 | # result = commands.getoutput('uuidgen -t') |
|---|
| 37 | # # On some linux-like OSes, uuidgen does not take any parameter to specify |
|---|
| 38 | # # the kind of uuid to generate |
|---|
| 39 | # if (result.find('usage:') >= 0): |
|---|
| 40 | # result = commands.getoutput('uuidgen') |
|---|
| 41 | # return result |
|---|
| 42 | |
|---|
| 43 | # try: |
|---|
| 44 | # setattr(wavedev.ComponentClass, 'uuidgen', newUuidgen) |
|---|
| 45 | # except: |
|---|
| 46 | # traceback.print_exc() |
|---|
| 47 | |
|---|
| 48 | class MainFrameTreeNode: |
|---|
| 49 | def __init__(self, name, contents): |
|---|
| 50 | self.name = name |
|---|
| 51 | self.contents = contents |
|---|
| 52 | self.allowChildrenToExpand = True |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | class RunInNewThread(threading.Thread): |
|---|
| 56 | def __init__(self, inCommand): |
|---|
| 57 | self.command = inCommand |
|---|
| 58 | threading.Thread.__init__(self) |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | def run(self): |
|---|
| 62 | os.system(self.command) |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | class MainFrameGlue(MainFrame): |
|---|
| 67 | def __init__(self): |
|---|
| 68 | self.active_waveform = Waveform() |
|---|
| 69 | self.active_platform = wavedev.PlatformClass.Platform() |
|---|
| 70 | self.installPath = "/sdr/" |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | def loadResources(self): |
|---|
| 74 | self.Available_Components = [] |
|---|
| 75 | self.Available_Devices = [] |
|---|
| 76 | self.Available_Nodes = [] |
|---|
| 77 | resList = [] |
|---|
| 78 | |
|---|
| 79 | # List possible resource directories (components and device) |
|---|
| 80 | baseComponentPath = self.installPath + 'xml/' |
|---|
| 81 | if os.path.isdir(baseComponentPath): |
|---|
| 82 | for r in os.listdir(baseComponentPath): |
|---|
| 83 | if r != 'dtd': # ignore dtd directory |
|---|
| 84 | resList.append( (baseComponentPath,r) ) |
|---|
| 85 | else: |
|---|
| 86 | errorMsg(self,"No component resources could be found in: " + self.installPath) |
|---|
| 87 | return |
|---|
| 88 | |
|---|
| 89 | # find the .scd.xml files for each resource |
|---|
| 90 | |
|---|
| 91 | for r in resList: |
|---|
| 92 | tmpResName = r[1] |
|---|
| 93 | tmpResPath = r[0] + r[1] |
|---|
| 94 | tmpComp = wavedev.importResource.getResource(tmpResPath,tmpResName,self) |
|---|
| 95 | |
|---|
| 96 | if tmpComp == None: |
|---|
| 97 | continue |
|---|
| 98 | if tmpComp.type == 'resource': |
|---|
| 99 | self.Available_Components.append(tmpComp) |
|---|
| 100 | |
|---|
| 101 | elif tmpComp.type == 'executabledevice': |
|---|
| 102 | self.Available_Devices.append(tmpComp) |
|---|
| 103 | |
|---|
| 104 | elif tmpComp.type == 'loadabledevice': |
|---|
| 105 | self.Available_Devices.append(tmpComp) |
|---|
| 106 | |
|---|
| 107 | elif tmpComp.type == 'device': |
|---|
| 108 | self.Available_Devices.append(tmpComp) |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | nodeList = [] |
|---|
| 112 | if os.path.isdir(self.installPath + 'nodes'): |
|---|
| 113 | nodeList = os.listdir(self.installPath + 'nodes') |
|---|
| 114 | # print nodeList |
|---|
| 115 | else: |
|---|
| 116 | errorMsg(self, "No nodes could be found in: " + self.installPath) |
|---|
| 117 | |
|---|
| 118 | # find the scd files for each node |
|---|
| 119 | for node_name in nodeList: |
|---|
| 120 | |
|---|
| 121 | # check for existence of DomainManager XML files |
|---|
| 122 | nodes_root_path = self.installPath + os.path.sep + 'nodes' + os.path.sep + node_name + os.path.sep |
|---|
| 123 | if not os.path.exists(nodes_root_path + 'DeviceManager.dcd.xml'): |
|---|
| 124 | errorMsg(self, "Could not find DeviceManager.dcd.xml in: " + nodes_root_path) |
|---|
| 125 | continue |
|---|
| 126 | elif not os.path.exists(nodes_root_path + 'DeviceManager.prf.xml'): |
|---|
| 127 | errorMsg(self, "Could not find DeviceManager.prf.xml in: " + nodes_root_path) |
|---|
| 128 | continue |
|---|
| 129 | elif not os.path.exists(nodes_root_path + 'DeviceManager.scd.xml'): |
|---|
| 130 | errorMsg(self, "Could not find DeviceManager.scd.xml in: " + nodes_root_path) |
|---|
| 131 | continue |
|---|
| 132 | elif not os.path.exists(nodes_root_path + 'DeviceManager.spd.xml'): |
|---|
| 133 | errorMsg(self, "Could not find DeviceManager.spd.xml in: " + nodes_root_path) |
|---|
| 134 | continue |
|---|
| 135 | |
|---|
| 136 | nodeName = node_name |
|---|
| 137 | nodePath = self.installPath + 'nodes/' + nodeName + '/' |
|---|
| 138 | |
|---|
| 139 | # print "calling getNode(", nodePath, ",", nodeName, ")" |
|---|
| 140 | tmpNode = wavedev.importNode.getNode(nodePath,nodeName,self) |
|---|
| 141 | |
|---|
| 142 | if tmpNode == None: |
|---|
| 143 | print "WARNING: possibly an error reading node " + nodePath + "/" + nodeName |
|---|
| 144 | continue |
|---|
| 145 | self.Available_Nodes.append(tmpNode) |
|---|
| 146 | return [MainFrameTreeNode("Components", self.Available_Components), |
|---|
| 147 | MainFrameTreeNode("Devices", self.Available_Devices), |
|---|
| 148 | MainFrameTreeNode("Nodes", self.Available_Nodes)] |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | def getActiveWaveform(self): |
|---|
| 152 | return self.active_waveform |
|---|
| 153 | |
|---|
| 154 | def getActivePlatform(self): |
|---|
| 155 | return self.active_platform |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | def getOssieInstallPath(self): |
|---|
| 159 | return self.installPath |
|---|
| 160 | |
|---|
| 161 | |
|---|
| 162 | def setOssieInstallPath(self, newInstallPath): |
|---|
| 163 | self.installPath = newInstallPath |
|---|
| 164 | |
|---|
| 165 | |
|---|
| 166 | def generateTestWaveform(self): |
|---|
| 167 | self.active_waveform = Waveform() |
|---|
| 168 | int1 = wavedev.ComponentClass.Interface('complexShort') |
|---|
| 169 | op1 = wavedev.ComponentClass.Operation('pushPacket','void') |
|---|
| 170 | param1 = wavedev.ComponentClass.Param('I','PortTypes::ShortSequence','in') |
|---|
| 171 | param2 = wavedev.ComponentClass.Param('Q','PortTypes::ShortSequence','in') |
|---|
| 172 | op1.params.extend([param1,param2]) |
|---|
| 173 | int1.operations.append(op1) |
|---|
| 174 | |
|---|
| 175 | t2 = wavedev.ComponentClass.Component("Transmitter",AC=True) |
|---|
| 176 | p1 = wavedev.ComponentClass.Port('inPortTx1',copy.deepcopy(int1),'Provides') |
|---|
| 177 | p2 = wavedev.ComponentClass.Port('outPortTx1',copy.deepcopy(int1),'Uses') |
|---|
| 178 | t2.ports.append(p1); t2.ports.append(p2) |
|---|
| 179 | self.active_waveform.components.append(t2) |
|---|
| 180 | |
|---|
| 181 | t3 = wavedev.ComponentClass.Component("Channel") |
|---|
| 182 | p1 = wavedev.ComponentClass.Port('inPortCh1',copy.deepcopy(int1),'Provides') |
|---|
| 183 | p2 = wavedev.ComponentClass.Port('inPortCh2',copy.deepcopy(int1),'Provides') |
|---|
| 184 | p3 = wavedev.ComponentClass.Port('inPortCh3',copy.deepcopy(int1),'Provides') |
|---|
| 185 | p4 = wavedev.ComponentClass.Port('outPortCh1',copy.deepcopy(int1),'Uses') |
|---|
| 186 | p5 = wavedev.ComponentClass.Port('outPortCh2',copy.deepcopy(int1),'Uses') |
|---|
| 187 | p6 = wavedev.ComponentClass.Port('outPortCh3',copy.deepcopy(int1),'Uses') |
|---|
| 188 | t3.ports.extend([p1,p2,p3,p4,p5,p6]) |
|---|
| 189 | self.active_waveform.components.append(t3) |
|---|
| 190 | |
|---|
| 191 | t4 = wavedev.ComponentClass.Component("Receiver") |
|---|
| 192 | p1 = wavedev.ComponentClass.Port('inPortRx1',copy.deepcopy(int1),'Provides') |
|---|
| 193 | p2 = wavedev.ComponentClass.Port('outPortRx1',copy.deepcopy(int1),'Uses') |
|---|
| 194 | t4.ports.append(p1); t4.ports.append(p2) |
|---|
| 195 | self.active_waveform.components.append(t4) |
|---|
| 196 | |
|---|
| 197 | temp_dev = wavedev.ComponentClass.Component("GPP") |
|---|
| 198 | self.active_waveform.devices.append(temp_dev) |
|---|
| 199 | return [MainFrameTreeNode("Sample Waveform", self.active_waveform)] |
|---|
| 200 | |
|---|
| 201 | def displayDoxygen(self, referenceMaterials): |
|---|
| 202 | defaultHtml = 'index.html' |
|---|
| 203 | defaultPdf = 'refman.pdf' |
|---|
| 204 | docList = None |
|---|
| 205 | |
|---|
| 206 | docsPath = self.installPath + 'docs/' + referenceMaterials.name |
|---|
| 207 | print docsPath |
|---|
| 208 | RunInNewThread('evince ' + "/home/Ossie/Desktop/OSSIE_0.6.2_User_Guide.pdf").start() |
|---|
| 209 | if os.path.isdir(docsPath): |
|---|
| 210 | docList = os.listdir(docsPath) |
|---|
| 211 | if os.path.isfile(docsPath + '/' + defaultHtml): |
|---|
| 212 | webbrowser.open_new('file://' + docsPath + '/' + defaultHtml) |
|---|
| 213 | elif os.path.isfile(docsPath + '/' + defaultPdf): |
|---|
| 214 | #find more portable way to view pdf? |
|---|
| 215 | try: |
|---|
| 216 | RunInNewThread('evince ' + docsPath + '/' + defaultPdf + ' &') |
|---|
| 217 | finally: |
|---|
| 218 | errorMsg(self,'evince pdf viewer threw exception or not found') |
|---|
| 219 | #webbrowser.open('file://' + docsPath + '/' + defaultPdf, 1) |
|---|
| 220 | else: |
|---|
| 221 | errorMsg(self,'Neither index.html nor refman.pdf found in ' + docsPath + ': directory listing: ' + str(docList)) |
|---|
| 222 | else: |
|---|
| 223 | errorMsg(self,'No directory for ' + referenceMaterials.name + ' could be found in: ' + self.installPath + 'docs') |
|---|
| 224 | return |
|---|
| 225 | |
|---|
| 226 | |
|---|
| 227 | def errorMsg(self, message): |
|---|
| 228 | print >>sys.stderr, message |
|---|
| 229 | |
|---|
| 230 | |
|---|
| 231 | def saveProject(self, saveProjectPath): |
|---|
| 232 | f = open(saveProjectPath,'w') |
|---|
| 233 | cPickle.dump(('project',self.active_waveform,self.active_platform),f) |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | def loadProject(self, projectPath): |
|---|
| 237 | f = open(projectPath,'r') |
|---|
| 238 | tmpObject = cPickle.load(f) |
|---|
| 239 | if tmpObject[0] == 'waveform': |
|---|
| 240 | self.active_waveform = tmpObject[1] |
|---|
| 241 | elif tmpObject[0] == 'platform': |
|---|
| 242 | self.active_platform = tmpObject[1] |
|---|
| 243 | elif tmpObject[0] == 'project': |
|---|
| 244 | self.active_waveform = tmpObject[1] |
|---|
| 245 | self.active_platform = tmpObject[2] |
|---|
| 246 | |
|---|
| 247 | |
|---|
| 248 | def dump(self, x): |
|---|
| 249 | from Utilities import dumpObj |
|---|
| 250 | dumpObj(x) |
|---|