| 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 importResource |
|---|
| 24 | import importNode |
|---|
| 25 | import WaveformClass |
|---|
| 26 | from WaveformClass import Waveform |
|---|
| 27 | import PlatformClass |
|---|
| 28 | import ComponentClass |
|---|
| 29 | import threading |
|---|
| 30 | import cPickle |
|---|
| 31 | from edu.vt.ossie.jyinterface.interfaces import MainFrame |
|---|
| 32 | import traceback |
|---|
| 33 | import generate.templates.custom_ports.genStructure as genStruct |
|---|
| 34 | import generate.genNode as genNode |
|---|
| 35 | import XML_gen.application_gen as xml_gen |
|---|
| 36 | from errorMsg import errorMsg |
|---|
| 37 | import commands |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | class MainFrameTreeNode: |
|---|
| 41 | def __init__(self, name, contents = []): |
|---|
| 42 | self.name = name |
|---|
| 43 | self.contents = contents |
|---|
| 44 | self.allowChildrenToExpand = True |
|---|
| 45 | self.iconName = None |
|---|
| 46 | |
|---|
| 47 | |
|---|
| 48 | class RunInNewThread(threading.Thread): |
|---|
| 49 | def __init__(self, inCommand): |
|---|
| 50 | self.command = inCommand |
|---|
| 51 | threading.Thread.__init__(self) |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | def run(self): |
|---|
| 55 | os.system(self.command) |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | class MainFrameGlue(MainFrame): |
|---|
| 60 | def __init__(self): |
|---|
| 61 | self.active_waveform = Waveform() |
|---|
| 62 | self.active_platform = PlatformClass.Platform() |
|---|
| 63 | self.installPath = "/sdr/" |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | def loadResources(self): |
|---|
| 67 | self.Available_Components = [] |
|---|
| 68 | self.Available_Devices = [] |
|---|
| 69 | self.Available_Nodes = [] |
|---|
| 70 | resList = [] |
|---|
| 71 | |
|---|
| 72 | # List possible resource directories (components and device) |
|---|
| 73 | baseComponentPath = self.installPath + 'xml/' |
|---|
| 74 | if os.path.isdir(baseComponentPath): |
|---|
| 75 | for r in os.listdir(baseComponentPath): |
|---|
| 76 | if r != 'dtd' and r != '.DS_Store' : # ignore dtd directory, OSX sometimes creates a hidden file called .DS_Store that screws things up |
|---|
| 77 | resList.append( (baseComponentPath,r) ) |
|---|
| 78 | else: |
|---|
| 79 | errorMsg(self,"No component resources could be found in: " + self.installPath) |
|---|
| 80 | return |
|---|
| 81 | |
|---|
| 82 | # find the .scd.xml files for each resource |
|---|
| 83 | |
|---|
| 84 | for r in resList: |
|---|
| 85 | tmpResName = r[1] |
|---|
| 86 | tmpResPath = r[0] + r[1] |
|---|
| 87 | tmpComp = importResource.getResource(tmpResPath,tmpResName,self) |
|---|
| 88 | |
|---|
| 89 | if tmpComp == None: |
|---|
| 90 | continue |
|---|
| 91 | if tmpComp.type == 'resource': |
|---|
| 92 | self.Available_Components.append(tmpComp) |
|---|
| 93 | |
|---|
| 94 | elif tmpComp.type == 'executabledevice': |
|---|
| 95 | self.Available_Devices.append(tmpComp) |
|---|
| 96 | |
|---|
| 97 | elif tmpComp.type == 'loadabledevice': |
|---|
| 98 | self.Available_Devices.append(tmpComp) |
|---|
| 99 | |
|---|
| 100 | elif tmpComp.type == 'device': |
|---|
| 101 | self.Available_Devices.append(tmpComp) |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | nodeList = [] |
|---|
| 105 | if os.path.isdir(self.installPath + 'nodes'): |
|---|
| 106 | nodeList = os.listdir(self.installPath + 'nodes') |
|---|
| 107 | # print nodeList |
|---|
| 108 | else: |
|---|
| 109 | errorMsg(self, "No nodes could be found in: " + self.installPath) |
|---|
| 110 | |
|---|
| 111 | # find the scd files for each node |
|---|
| 112 | for node_name in nodeList: |
|---|
| 113 | |
|---|
| 114 | # check for existence of DomainManager XML files |
|---|
| 115 | nodes_root_path = self.installPath + os.path.sep + 'nodes' + os.path.sep + node_name + os.path.sep |
|---|
| 116 | if not os.path.exists(nodes_root_path + 'DeviceManager.dcd.xml'): |
|---|
| 117 | errorMsg(self, "Could not find DeviceManager.dcd.xml in: " + nodes_root_path) |
|---|
| 118 | continue |
|---|
| 119 | elif not os.path.exists(nodes_root_path + 'DeviceManager.prf.xml'): |
|---|
| 120 | errorMsg(self, "Could not find DeviceManager.prf.xml in: " + nodes_root_path) |
|---|
| 121 | continue |
|---|
| 122 | elif not os.path.exists(nodes_root_path + 'DeviceManager.scd.xml'): |
|---|
| 123 | errorMsg(self, "Could not find DeviceManager.scd.xml in: " + nodes_root_path) |
|---|
| 124 | continue |
|---|
| 125 | elif not os.path.exists(nodes_root_path + 'DeviceManager.spd.xml'): |
|---|
| 126 | errorMsg(self, "Could not find DeviceManager.spd.xml in: " + nodes_root_path) |
|---|
| 127 | continue |
|---|
| 128 | |
|---|
| 129 | nodeName = node_name |
|---|
| 130 | nodePath = self.installPath + 'nodes/' + nodeName + '/' |
|---|
| 131 | |
|---|
| 132 | # print "calling getNode(", nodePath, ",", nodeName, ")" |
|---|
| 133 | tmpNode = importNode.getNode(nodePath,nodeName,self) |
|---|
| 134 | |
|---|
| 135 | if tmpNode == None: |
|---|
| 136 | print "WARNING: possibly an error reading node " + nodePath + "/" + nodeName |
|---|
| 137 | continue |
|---|
| 138 | self.Available_Nodes.append(tmpNode) |
|---|
| 139 | return [MainFrameTreeNode("Components", self.Available_Components), |
|---|
| 140 | MainFrameTreeNode("Devices", self.Available_Devices), |
|---|
| 141 | MainFrameTreeNode("Nodes", self.Available_Nodes)] |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | def getActiveWaveform(self): |
|---|
| 145 | return self.active_waveform |
|---|
| 146 | |
|---|
| 147 | def getActivePlatform(self): |
|---|
| 148 | return self.active_platform |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | def getOssieInstallPath(self): |
|---|
| 152 | return self.installPath |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | def setOssieInstallPath(self, newInstallPath): |
|---|
| 156 | self.installPath = newInstallPath |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | def generateTestWaveform(self): |
|---|
| 160 | self.active_waveform = Waveform() |
|---|
| 161 | int1 = ComponentClass.Interface('complexShort') |
|---|
| 162 | op1 = ComponentClass.Operation('pushPacket','void') |
|---|
| 163 | param1 = ComponentClass.Param('I','PortTypes::ShortSequence','in') |
|---|
| 164 | param2 = ComponentClass.Param('Q','PortTypes::ShortSequence','in') |
|---|
| 165 | op1.params.extend([param1,param2]) |
|---|
| 166 | int1.operations.append(op1) |
|---|
| 167 | |
|---|
| 168 | t2 = ComponentClass.Component("Transmitter", AC=True, generate=False) |
|---|
| 169 | p1 = ComponentClass.Port('inPortTx1',copy.deepcopy(int1),'Provides') |
|---|
| 170 | p2 = ComponentClass.Port('outPortTx1',copy.deepcopy(int1),'Uses') |
|---|
| 171 | t2.ports.append(p1) |
|---|
| 172 | t2.ports.append(p2) |
|---|
| 173 | self.active_waveform.components.append(t2) |
|---|
| 174 | |
|---|
| 175 | t3 = ComponentClass.Component("Channel", generate=False) |
|---|
| 176 | p1 = ComponentClass.Port('inPortCh1',copy.deepcopy(int1),'Provides') |
|---|
| 177 | p2 = ComponentClass.Port('inPortCh2',copy.deepcopy(int1),'Provides') |
|---|
| 178 | p3 = ComponentClass.Port('inPortCh3',copy.deepcopy(int1),'Provides') |
|---|
| 179 | p4 = ComponentClass.Port('outPortCh1',copy.deepcopy(int1),'Uses') |
|---|
| 180 | p5 = ComponentClass.Port('outPortCh2',copy.deepcopy(int1),'Uses') |
|---|
| 181 | p6 = ComponentClass.Port('outPortCh3',copy.deepcopy(int1),'Uses') |
|---|
| 182 | t3.ports.extend([p1,p2,p3,p4,p5,p6]) |
|---|
| 183 | self.active_waveform.components.append(t3) |
|---|
| 184 | |
|---|
| 185 | t4 = ComponentClass.Component("Receiver", generate=False) |
|---|
| 186 | p1 = ComponentClass.Port('inPortRx1',copy.deepcopy(int1),'Provides') |
|---|
| 187 | p2 = ComponentClass.Port('outPortRx1',copy.deepcopy(int1),'Uses') |
|---|
| 188 | t4.ports.append(p1) |
|---|
| 189 | t4.ports.append(p2) |
|---|
| 190 | self.active_waveform.components.append(t4) |
|---|
| 191 | |
|---|
| 192 | #temp_dev = ComponentClass.Component("GPP", generate=False) |
|---|
| 193 | #self.active_waveform.devices.append(temp_dev) |
|---|
| 194 | return [MainFrameTreeNode("Sample Waveform", self.active_waveform)] |
|---|
| 195 | |
|---|
| 196 | |
|---|
| 197 | def displayDoxygen(self, referenceMaterials): |
|---|
| 198 | defaultHtml = 'index.html' |
|---|
| 199 | defaultPdf = 'refman.pdf' |
|---|
| 200 | docList = None |
|---|
| 201 | |
|---|
| 202 | docsPath = self.installPath + 'docs/' + referenceMaterials.name |
|---|
| 203 | print docsPath |
|---|
| 204 | if os.path.isdir(docsPath): |
|---|
| 205 | docList = os.listdir(docsPath) |
|---|
| 206 | if os.path.isfile(docsPath + '/' + defaultHtml): |
|---|
| 207 | webbrowser.open_new('file://' + docsPath + '/' + defaultHtml) |
|---|
| 208 | elif os.path.isfile(docsPath + '/' + defaultPdf): |
|---|
| 209 | #find more portable way to view pdf? |
|---|
| 210 | try: |
|---|
| 211 | RunInNewThread('evince ' + docsPath + '/' + defaultPdf + ' &') |
|---|
| 212 | finally: |
|---|
| 213 | errorMsg(self,'evince pdf viewer threw exception or not found') |
|---|
| 214 | #webbrowser.open('file://' + docsPath + '/' + defaultPdf, 1) |
|---|
| 215 | else: |
|---|
| 216 | errorMsg(self,'Neither index.html nor refman.pdf found in ' + docsPath + ': directory listing: ' + str(docList)) |
|---|
| 217 | else: |
|---|
| 218 | errorMsg(self,'No directory for ' + referenceMaterials.name + ' could be found in: ' + self.installPath + 'docs') |
|---|
| 219 | return |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | def errorMsg(self, message): |
|---|
| 223 | print >>sys.stderr, message |
|---|
| 224 | |
|---|
| 225 | |
|---|
| 226 | def saveProject(self, saveProjectPath): |
|---|
| 227 | f = open(saveProjectPath,'w') |
|---|
| 228 | cPickle.dump(('project',self.active_waveform,self.active_platform),f) |
|---|
| 229 | f.close() |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | def loadProject(self, projectPath): |
|---|
| 233 | f = open(projectPath,'r') |
|---|
| 234 | tmpObject = cPickle.load(f) |
|---|
| 235 | if tmpObject[0] == 'waveform': |
|---|
| 236 | self.active_waveform = tmpObject[1] |
|---|
| 237 | elif tmpObject[0] == 'platform': |
|---|
| 238 | self.active_platform = tmpObject[1] |
|---|
| 239 | elif tmpObject[0] == 'project': |
|---|
| 240 | self.active_waveform = tmpObject[1] |
|---|
| 241 | self.active_platform = tmpObject[2] |
|---|
| 242 | f.close() |
|---|
| 243 | |
|---|
| 244 | |
|---|
| 245 | def generateProject(self, path): |
|---|
| 246 | wavedevPath = self.installPath |
|---|
| 247 | if wavedevPath == None or len(wavedevPath) == 0: |
|---|
| 248 | errorMsg(self, "installPath not set") |
|---|
| 249 | wavedevPath = '/sdr/' |
|---|
| 250 | if wavedevPath[len(wavedevPath)-1] != '/': |
|---|
| 251 | wavedevPath = wavedevPath + '/' |
|---|
| 252 | wavedevPath = wavedevPath + 'tools/WaveDev/wavedev/' |
|---|
| 253 | gen = genStruct.genAll(path, wavedevPath, copy.deepcopy(self.active_waveform)) |
|---|
| 254 | gen.genDirs() |
|---|
| 255 | # Only include the device manager files if there is just one node |
|---|
| 256 | if len(self.active_platform.nodes) == 1: |
|---|
| 257 | gen.writeMakefiles(True) |
|---|
| 258 | else: |
|---|
| 259 | gen.writeMakefiles(False) |
|---|
| 260 | # TODO: use different configure.ac file for application -JDG |
|---|
| 261 | gen.genConfigureACFiles(self.installPath) |
|---|
| 262 | for c in self.active_waveform.components: |
|---|
| 263 | if c.generate: |
|---|
| 264 | gen.genCompFiles(c) |
|---|
| 265 | |
|---|
| 266 | xml_gen.genxml(copy.deepcopy(self.active_waveform.components), path, wavedevPath, self.active_waveform.name) |
|---|
| 267 | xml_gen.genDAS(copy.deepcopy(self.active_waveform.components), path, wavedevPath, self.active_waveform.name) |
|---|
| 268 | xml_gen.writeWaveSetuppy(path, wavedevPath, self.active_waveform.name) |
|---|
| 269 | |
|---|
| 270 | gen.cleanUp() |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | def dump(self, x): |
|---|
| 274 | from Utilities import dumpObj |
|---|
| 275 | dumpObj(x) |
|---|
| 276 | |
|---|
| 277 | def uuidgen(self): |
|---|
| 278 | result = commands.getoutput('uuidgen -t') |
|---|
| 279 | # On some linux-like OSes, uuidgen does not take any parameter to specify |
|---|
| 280 | # the kind of uuid to generate |
|---|
| 281 | if (result.find('usage:') >= 0): |
|---|
| 282 | result = commands.getoutput('uuidgen') |
|---|
| 283 | return result |
|---|