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