| 1 | #! /usr/bin/env python |
|---|
| 2 | |
|---|
| 3 | ''' |
|---|
| 4 | /**************************************************************************** |
|---|
| 5 | |
|---|
| 6 | Copyright 2007 Virginia Polytechnic Institute and State University |
|---|
| 7 | |
|---|
| 8 | This file is part of the OSSIE USRP_Commander_GUI. |
|---|
| 9 | |
|---|
| 10 | OSSIE USRP_Commander_GUI is free software; you can redistribute it and/or modify |
|---|
| 11 | it under the terms of the GNU General Public License as published by |
|---|
| 12 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 13 | (at your option) any later version. |
|---|
| 14 | |
|---|
| 15 | OSSIE USRP_Commander_GUI is distributed in the hope that it will be useful, |
|---|
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 18 | GNU General Public License for more details. |
|---|
| 19 | |
|---|
| 20 | You should have received a copy of the GNU General Public License |
|---|
| 21 | along with OSSIE USRP_Commander_GUI; if not, write to the Free Software |
|---|
| 22 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 23 | |
|---|
| 24 | ****************************************************************************/ |
|---|
| 25 | |
|---|
| 26 | ''' |
|---|
| 27 | |
|---|
| 28 | from omniORB import CORBA |
|---|
| 29 | from omniORB import URI |
|---|
| 30 | import CosNaming |
|---|
| 31 | import CF, CF__POA |
|---|
| 32 | import standardInterfaces__POA |
|---|
| 33 | import customInterfaces__POA |
|---|
| 34 | import sys |
|---|
| 35 | |
|---|
| 36 | # port stuff: |
|---|
| 37 | import Radio_Control_u |
|---|
| 38 | import resource_u |
|---|
| 39 | |
|---|
| 40 | import WorkModule # module found in the component directory. |
|---|
| 41 | # this module is where the main processing |
|---|
| 42 | # thread resides. |
|---|
| 43 | import threading |
|---|
| 44 | import time # primarily availble for time.sleep() statements |
|---|
| 45 | |
|---|
| 46 | #------------------------------------------------------------- |
|---|
| 47 | # USRP_Commander_GUI_i class definition (main component class) |
|---|
| 48 | #------------------------------------------------------------- |
|---|
| 49 | class USRP_Commander_GUI_i(CF__POA.Resource): |
|---|
| 50 | def __init__(self, uuid, label, poa): |
|---|
| 51 | CF._objref_Resource.__init__(self._this()) |
|---|
| 52 | print "USRP_Commander_GUI_i __init__: " + label |
|---|
| 53 | self.naming_service_name = label |
|---|
| 54 | self.poa = poa |
|---|
| 55 | |
|---|
| 56 | # debug statement |
|---|
| 57 | print "creating the resource port" |
|---|
| 58 | self.outPort0_servant = resource_u.resource_u_i(self, "Data_Control") |
|---|
| 59 | self.outPort0_var = self.outPort0_servant._this() |
|---|
| 60 | self.outPort0_active = False |
|---|
| 61 | |
|---|
| 62 | # debug statement |
|---|
| 63 | print "creating the rx control port" |
|---|
| 64 | self.rxCtrlPort_servant = Radio_Control_u.Radio_Control_u_i(self, |
|---|
| 65 | "RX_Control") |
|---|
| 66 | self.rxCtrlPort_var = self.rxCtrlPort_servant._this() |
|---|
| 67 | self.rxCtrlPort_active = False |
|---|
| 68 | |
|---|
| 69 | # debug statement |
|---|
| 70 | print "creating the tx control port" |
|---|
| 71 | self.txCtrlPort_servant = Radio_Control_u.Radio_Control_u_i(self, |
|---|
| 72 | "TX_Control") |
|---|
| 73 | self.txCtrlPort_var = self.txCtrlPort_servant._this() |
|---|
| 74 | self.txCtrlPort_active = False |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | self.WorkModule_created = False |
|---|
| 78 | |
|---|
| 79 | self.propertySet = [] |
|---|
| 80 | |
|---|
| 81 | # properties initializations: |
|---|
| 82 | self.rx_freq = 0 |
|---|
| 83 | self.rx_dec_fact = 0 |
|---|
| 84 | self.rx_pack_size = 0 |
|---|
| 85 | self.rx_gain = 0 |
|---|
| 86 | self.rx_gain_max = 0 |
|---|
| 87 | self.rx_start_flag = 0 |
|---|
| 88 | |
|---|
| 89 | self.tx_freq = 0 |
|---|
| 90 | self.tx_start_flag = 0 |
|---|
| 91 | self.tx_gain = 1 |
|---|
| 92 | self.tx_interp_rate = 0 |
|---|
| 93 | |
|---|
| 94 | self.work_mod = None |
|---|
| 95 | |
|---|
| 96 | print "done with the usrp commander __init__" |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | def start(self): |
|---|
| 100 | print "USRP_Commander_GUI start called" |
|---|
| 101 | |
|---|
| 102 | # TODO: call start on remote resources |
|---|
| 103 | |
|---|
| 104 | #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
|---|
| 105 | # Set Transmitter Properties: |
|---|
| 106 | |
|---|
| 107 | # initialize the USRP to the values read in from properties |
|---|
| 108 | self.txCtrlPort_servant.setNumberOfChannels(1) |
|---|
| 109 | self.txCtrlPort_servant.setGain(DEFAULT_USRP_TX_CHANNEL, self.tx_gain) |
|---|
| 110 | self.txCtrlPort_servant.setFrequency(DEFAULT_USRP_TX_CHANNEL, |
|---|
| 111 | self.tx_freq) |
|---|
| 112 | self.txCtrlPort_servant.setInterpolationRate(DEFAULT_USRP_TX_CHANNEL, |
|---|
| 113 | self.tx_interp_rate) |
|---|
| 114 | |
|---|
| 115 | # TODO: handle the next couple of lines |
|---|
| 116 | # Set transmit configurable properties not included in Radio_Control idl |
|---|
| 117 | ##CF::Properties tx_config; |
|---|
| 118 | ##tx_config.length(1); |
|---|
| 119 | |
|---|
| 120 | # Set automatic transmit/receive mode on |
|---|
| 121 | ##tx_config[0].id = CORBA::string_dup("SET_AUTO_TR_1"); |
|---|
| 122 | ##tx_config[0].value <<= (CORBA::ULong) 1; |
|---|
| 123 | |
|---|
| 124 | ##TXControl->set_values(tx_config); |
|---|
| 125 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|---|
| 126 | |
|---|
| 127 | |
|---|
| 128 | #vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
|---|
| 129 | # Set Receiver Properties: |
|---|
| 130 | |
|---|
| 131 | # Initialize the USRP to the values read in from properties |
|---|
| 132 | self.rxCtrlPort_servant.setNumberOfChannels(1) |
|---|
| 133 | self.rxCtrlPort_servant.setGain(DEFAULT_USRP_RX_CHANNEL, self.rx_gain) |
|---|
| 134 | self.rxCtrlPort_servant.setFrequency(DEFAULT_USRP_RX_CHANNEL, |
|---|
| 135 | self.rx_freq) |
|---|
| 136 | self.rxCtrlPort_servant.setDecimationRate(DEFAULT_USRP_RX_CHANNEL, |
|---|
| 137 | self.rx_dec_fact) |
|---|
| 138 | self.rxCtrlPort_servant.setDataPacketSize(DEFAULT_USRP_RX_CHANNEL, |
|---|
| 139 | self.pack_size) |
|---|
| 140 | |
|---|
| 141 | # Set transmit configurable properties not included in Radio_Control idl |
|---|
| 142 | ##CF::Properties rx_config; |
|---|
| 143 | ##rx_config.length(1); |
|---|
| 144 | |
|---|
| 145 | # Set rx antenna |
|---|
| 146 | ##rx_config[0].id = CORBA::string_dup("SET_RX_ANT_1"); |
|---|
| 147 | ##rx_config[0].value <<= (CORBA::ULong) 0; |
|---|
| 148 | |
|---|
| 149 | ##RXControl->set_values(rx_config); |
|---|
| 150 | |
|---|
| 151 | if self.tx_start_flag: |
|---|
| 152 | print "starting the USRP transmitter" |
|---|
| 153 | self.txCtrlPort_servant.start(DEFAULT_USRP_TX_CHANNEL) |
|---|
| 154 | |
|---|
| 155 | if self.rx_start_flag: |
|---|
| 156 | print "starting the USRP receiver" |
|---|
| 157 | self.rxCtrlPort_servant.start(DEFAULT_USRP_RX_CHANNEL) |
|---|
| 158 | #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
|---|
| 159 | |
|---|
| 160 | |
|---|
| 161 | def stop(self): |
|---|
| 162 | print "USRP_Commander_GUI stop called" |
|---|
| 163 | |
|---|
| 164 | def getPort(self, id): |
|---|
| 165 | if str(id) == "Data_Control": |
|---|
| 166 | return self.outPort0_var |
|---|
| 167 | if str(id) == "RX_Control": |
|---|
| 168 | return self.rxCtrlPort_var |
|---|
| 169 | if str(id) == "TX_Control": |
|---|
| 170 | return self.txCtrlPort_var |
|---|
| 171 | |
|---|
| 172 | return None #port not found in available ports list |
|---|
| 173 | |
|---|
| 174 | def initialize(self): |
|---|
| 175 | print "USRP_Commander_GUI initialize called" |
|---|
| 176 | |
|---|
| 177 | def configure(self, props): |
|---|
| 178 | ''' The configure method is called twice by the framework: |
|---|
| 179 | once to read the default properties in the component.prf |
|---|
| 180 | file, and once to read the component instance properties |
|---|
| 181 | storred in the waveform.sad file. This method should be |
|---|
| 182 | called before the start method. This method is where |
|---|
| 183 | the properties are read in by the component. |
|---|
| 184 | ''' |
|---|
| 185 | |
|---|
| 186 | print "USRP_Commander_GUI configure called" |
|---|
| 187 | |
|---|
| 188 | buffer_size = 0 |
|---|
| 189 | |
|---|
| 190 | # TODO: set number of channels in RXControl? |
|---|
| 191 | |
|---|
| 192 | for property in props: |
|---|
| 193 | if property not in self.propertySet: |
|---|
| 194 | self.propertySet.append(property) |
|---|
| 195 | |
|---|
| 196 | if property.id == "DCE:6a2d6952-ca11-4787-afce-87a89b882b7b": |
|---|
| 197 | # receiver frequency |
|---|
| 198 | rx_freq = int(property.value.value()) |
|---|
| 199 | |
|---|
| 200 | elif property.id == "DCE:9ca12c0e-ba65-40cf-9ef3-6e7ac671ab5d": |
|---|
| 201 | # transmitter frequency |
|---|
| 202 | tx_freq = int(property.value.value()) |
|---|
| 203 | |
|---|
| 204 | elif property.id == "DCE:92ec2b80-8040-47c7-a1d8-4c9caa4a4ed2": |
|---|
| 205 | # transmitter interpolation rate |
|---|
| 206 | tx_interp_rate = int(property.value.value()) |
|---|
| 207 | |
|---|
| 208 | elif property.id == "DCE:3efc3930-2739-40b4-8c02-ecfb1b0da9ee": |
|---|
| 209 | # receiver decimation factor |
|---|
| 210 | rx_dec_fact = int(property.value.value()) |
|---|
| 211 | |
|---|
| 212 | elif property.id == "DCE:93324adf-14f6-4406-ba92-a3650089857f": |
|---|
| 213 | # receiver data packet size |
|---|
| 214 | rx_pack_size = int(property.value.value()) |
|---|
| 215 | |
|---|
| 216 | elif property.id == "DCE:99d586b6-7764-4dc7-83fa-72270d0f1e1b": |
|---|
| 217 | # receiver gain |
|---|
| 218 | rx_gain = int(property.value.value()) |
|---|
| 219 | |
|---|
| 220 | elif property.id == "DCE:2d9c5ee4-a6f3-4ab9-834b-2b5c95818e53": |
|---|
| 221 | # receiver gain max |
|---|
| 222 | rx_gain_max = int(property.value.value()) |
|---|
| 223 | |
|---|
| 224 | elif property.id == "DCE:fd42344f-4d87-465b-9e6f-e1d7ae48afd6": |
|---|
| 225 | # receiver start flag |
|---|
| 226 | rx_start_flag = int(property.value.value()) |
|---|
| 227 | |
|---|
| 228 | elif property.id == "DCE:0a9b8c8c-f130-4a8f-9ef8-bba023128a4b": |
|---|
| 229 | # transmitter start flag |
|---|
| 230 | tx_start_flag = int(property.value.value()) |
|---|
| 231 | |
|---|
| 232 | else: |
|---|
| 233 | print "WARNING: the property with id :" + property.id + " is not supported in the configure method of USRP_Commander_GUI.py" |
|---|
| 234 | |
|---|
| 235 | |
|---|
| 236 | # make sure that only one WorkModule thread is started, |
|---|
| 237 | # even if configure method is called more than once |
|---|
| 238 | if not self.WorkModule_created: |
|---|
| 239 | self.work_mod = WorkModule.WorkClass(self, buffer_size) |
|---|
| 240 | self.WorkModule_created = True |
|---|
| 241 | |
|---|
| 242 | def query(self, props): |
|---|
| 243 | return self.propertySet |
|---|
| 244 | |
|---|
| 245 | def releaseObject(self): |
|---|
| 246 | # release the main work module |
|---|
| 247 | self.work_mod.Release() |
|---|
| 248 | |
|---|
| 249 | # release the main process threads for the ports |
|---|
| 250 | self.outPort0_servant.releasePort() |
|---|
| 251 | self.rxCtrlPort_servant.releasePort() |
|---|
| 252 | self.txCtrlPort_servant.releasePort() |
|---|
| 253 | |
|---|
| 254 | # deactivate the ports |
|---|
| 255 | oid0 = self.poa.reference_to_id(self.outPort0_var) |
|---|
| 256 | oid0 = self.poa.reference_to_id(self.rxCtrlPort_var) |
|---|
| 257 | oid0 = self.poa.reference_to_id(self.txCtrlPort_var) |
|---|
| 258 | |
|---|
| 259 | self.poa.deactivate_object(oid0) |
|---|
| 260 | self.poa.deactivate_object(oid1) |
|---|
| 261 | self.poa.deactivate_object(oid2) |
|---|
| 262 | |
|---|
| 263 | |
|---|
| 264 | |
|---|
| 265 | #------------------------------------------------------------------- |
|---|
| 266 | # ORB_Init class definition |
|---|
| 267 | #------------------------------------------------------------------- |
|---|
| 268 | class ORB_Init: |
|---|
| 269 | """Takes care of initializing the ORB and bind the object""" |
|---|
| 270 | |
|---|
| 271 | def __init__(self, uuid, label): |
|---|
| 272 | # initialize the orb |
|---|
| 273 | self.orb = CORBA.ORB_init() |
|---|
| 274 | |
|---|
| 275 | # get the POA |
|---|
| 276 | obj_poa = self.orb.resolve_initial_references("RootPOA") |
|---|
| 277 | poaManager = obj_poa._get_the_POAManager() |
|---|
| 278 | poaManager.activate() |
|---|
| 279 | |
|---|
| 280 | ns_obj = self.orb.resolve_initial_references("NameService") |
|---|
| 281 | rootContext = ns_obj._narrow(CosNaming.NamingContext) |
|---|
| 282 | |
|---|
| 283 | # create the main component object |
|---|
| 284 | self.USRP_Commander_GUI_Obj = USRP_Commander_GUI_i(uuid, |
|---|
| 285 | label, |
|---|
| 286 | obj_poa) |
|---|
| 287 | USRP_Commander_GUI_var = self.USRP_Commander_GUI_Obj._this() |
|---|
| 288 | |
|---|
| 289 | name = URI.stringToName(label) |
|---|
| 290 | rootContext.rebind(name, USRP_Commander_GUI_var) |
|---|
| 291 | |
|---|
| 292 | self.orb.run() |
|---|
| 293 | |
|---|
| 294 | #------------------------------------------------------------------- |
|---|
| 295 | # Code run when this file is executed |
|---|
| 296 | #------------------------------------------------------------------- |
|---|
| 297 | if __name__ == "__main__": |
|---|
| 298 | # debug statement: |
|---|
| 299 | print "main loop of USRP commander GUI" |
|---|
| 300 | if len(sys.argv) != 3: |
|---|
| 301 | print sys.argv[0] + " <id> <usage name> " |
|---|
| 302 | |
|---|
| 303 | uuid = str(sys.argv[1]) |
|---|
| 304 | label = str(sys.argv[2]) |
|---|
| 305 | |
|---|
| 306 | print "Identifier - " + uuid + " Label - " + label |
|---|
| 307 | |
|---|
| 308 | DEFAULT_USRP_TX_CONTROL = 0 |
|---|
| 309 | DEFAULT_USRP_RX_CONTROL = 0 |
|---|
| 310 | |
|---|
| 311 | orb = ORB_Init(uuid, label) |
|---|
| 312 | |
|---|
| 313 | |
|---|