| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE USRP_UHD Device. |
|---|
| 6 | |
|---|
| 7 | OSSIE USRP_UHD Device is free software; you can redistribute it and/or modify |
|---|
| 8 | it under the terms of the GNU General Public License as published by |
|---|
| 9 | the Free Software Foundation; either version 2 of the License, or |
|---|
| 10 | (at your option) any later version. |
|---|
| 11 | |
|---|
| 12 | OSSIE USRP_UHD Device is distributed in the hope that it will be useful, |
|---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 15 | GNU General Public License for more details. |
|---|
| 16 | |
|---|
| 17 | You should have received a copy of the GNU General Public License |
|---|
| 18 | along with OSSIE USRP_UHD Device; if not, write to the Free Software |
|---|
| 19 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | ****************************************************************************/ |
|---|
| 23 | |
|---|
| 24 | #include <iostream> |
|---|
| 25 | #include <omniORB4/CORBA.h> |
|---|
| 26 | #include "ossie/debug.h" |
|---|
| 27 | #include "USRP_UHD.h" |
|---|
| 28 | |
|---|
| 29 | USRP_UHD_TX_Control_i::USRP_UHD_TX_Control_i(USRP_UHD_i *_usrp_uhd, const char* _name, const char* _domain) : standardInterfaces_i::TX_Control_p(_name, _domain), usrp_uhd(_usrp_uhd) |
|---|
| 30 | { |
|---|
| 31 | DEBUG(3, USRP_UHD, "TX Control port constructor called") |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | void USRP_UHD_TX_Control_i::set_number_of_channels(CORBA::ULong nchan) |
|---|
| 35 | { |
|---|
| 36 | DEBUG(3, USRP_UHD, "Setting number of TX channels to " << nchan<< " is not supported"); |
|---|
| 37 | |
|---|
| 38 | ///\TODO: Define if we need this interface. Number of channels is defined at transmit or receive |
|---|
| 39 | |
|---|
| 40 | //omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 41 | |
|---|
| 42 | //usrp_uhd->usrp_uhd_ptr->set_nchannels(nchan); |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | void USRP_UHD_TX_Control_i::get_number_of_channels(CORBA::ULong &num) |
|---|
| 46 | { |
|---|
| 47 | ///\TODO: Define if we need this interface. Number of channels is defined at transmit or receive |
|---|
| 48 | DEBUG(3, USRP_UHD, "Getting number of TX channels is not supported"); |
|---|
| 49 | //omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 50 | |
|---|
| 51 | //num = usrp_uhd->usrp_uhd_ptr->nchannels(); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | void USRP_UHD_TX_Control_i::get_gain_range(CORBA::ULong channel, CORBA::Float &gmin, CORBA::Float &gmax, CORBA::Float &gstep) |
|---|
| 55 | { |
|---|
| 56 | if (channel == 0) { |
|---|
| 57 | if (usrp_uhd->sdev) { |
|---|
| 58 | uhd::gain_range_t range = usrp_uhd->sdev->get_tx_gain_range(); |
|---|
| 59 | // All values in range are in dB |
|---|
| 60 | gmin = range.start(); |
|---|
| 61 | gmax = range.stop(); |
|---|
| 62 | gstep = range.step(); |
|---|
| 63 | } |
|---|
| 64 | } else { |
|---|
| 65 | return; ///\todo throw bad channel exception |
|---|
| 66 | } |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | void USRP_UHD_TX_Control_i::set_gain(CORBA::ULong channel, CORBA::Float gain) |
|---|
| 70 | { |
|---|
| 71 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 72 | |
|---|
| 73 | if (channel == 0) { |
|---|
| 74 | if (usrp_uhd->sdev) { |
|---|
| 75 | usrp_uhd->sdev->set_tx_gain(gain); |
|---|
| 76 | } |
|---|
| 77 | } else { |
|---|
| 78 | return; ///\todo throw bad channel exception |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | void USRP_UHD_TX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain) |
|---|
| 83 | { |
|---|
| 84 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 85 | if (channel == 0) { |
|---|
| 86 | if (usrp_uhd->sdev) { |
|---|
| 87 | gain = usrp_uhd->sdev->get_tx_gain(); |
|---|
| 88 | } |
|---|
| 89 | } else { |
|---|
| 90 | return; ///\todo throw bad channel exception |
|---|
| 91 | } |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | void USRP_UHD_TX_Control_i::get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, CORBA::Float &fmax, CORBA::Float &fstep) |
|---|
| 95 | { |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | if (channel == 0) { |
|---|
| 99 | if (usrp_uhd->sdev) { |
|---|
| 100 | uhd::freq_range_t range = usrp_uhd->sdev->get_tx_freq_range(); |
|---|
| 101 | // All values in range are in dB |
|---|
| 102 | fmin = range.start(); |
|---|
| 103 | fmax = range.stop(); |
|---|
| 104 | fstep = 0.0; // There is no step value in uhd::freq_range |
|---|
| 105 | } |
|---|
| 106 | } else { |
|---|
| 107 | return; ///\todo throw bad channel exception |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | void USRP_UHD_TX_Control_i::set_frequency(CORBA::ULong channel, CORBA::Float f) |
|---|
| 113 | { |
|---|
| 114 | DEBUG(3, USRP_UHD, "In TX Control set frequency channel: " << channel << ", frequency: " << f); |
|---|
| 115 | |
|---|
| 116 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 117 | |
|---|
| 118 | if (channel == 0) { |
|---|
| 119 | uhd::tune_result_t result = usrp_uhd->sdev->set_tx_freq(f); |
|---|
| 120 | |
|---|
| 121 | DEBUG(3, USRP_UHD, "USRP_UHD TX tune_result:" << |
|---|
| 122 | " target_inter_freq=" << result.target_inter_freq << |
|---|
| 123 | " actual_inter_freq=" << result.actual_inter_freq << |
|---|
| 124 | " target_dsp_freq=" << result.target_dsp_freq << |
|---|
| 125 | " actual_dsp_freq=" << result.actual_dsp_freq); |
|---|
| 126 | } else { |
|---|
| 127 | DEBUG(3, USRP_UHD, "USRP_UHD TX set_frequency (invalid channel)"); |
|---|
| 128 | return; |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | void USRP_UHD_TX_Control_i::get_frequency(CORBA::ULong channel, CORBA::Float &f) |
|---|
| 134 | { |
|---|
| 135 | // omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 136 | DEBUG(1, USRP_UHD, "get_frequency() not supported!!") |
|---|
| 137 | f = 0.0; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | void USRP_UHD_TX_Control_i::start(CORBA::ULong channel) |
|---|
| 141 | { |
|---|
| 142 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 143 | |
|---|
| 144 | if (!usrp_uhd->tx_active) { |
|---|
| 145 | usrp_uhd->tx_thread = new omni_thread(USRP_UHD_i::do_tx_data_process, ((void *)usrp_uhd)); |
|---|
| 146 | usrp_uhd->tx_thread->start(); |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | void USRP_UHD_TX_Control_i::stop(CORBA::ULong channel) |
|---|
| 151 | { |
|---|
| 152 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 153 | |
|---|
| 154 | usrp_uhd->tx_active = false; |
|---|
| 155 | |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | void USRP_UHD_TX_Control_i::set_values(const CF::Properties &values) |
|---|
| 159 | { |
|---|
| 160 | /* |
|---|
| 161 | DEBUG(3, USRP_UHD, "USRP_UHD TX setting " << values.length() << " values, value[0].id " << values[0].id) |
|---|
| 162 | |
|---|
| 163 | for (unsigned int i =0; i < values.length(); ++i) { |
|---|
| 164 | if (strcmp(values[i].id, "SET_MUX") == 0 ) { |
|---|
| 165 | CORBA::ULong mux; |
|---|
| 166 | values[i].value >>= mux; |
|---|
| 167 | DEBUG(1, USRP_UHD, "Request to set transmit mux to " << mux<<" Not Supported") |
|---|
| 168 | //omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 169 | //usrp_uhd->usrp_uhd_ptr->set_mux(mux); |
|---|
| 170 | } else if (strcmp(values[i].id, "SET_AUTO_TR_1") == 0) { |
|---|
| 171 | CORBA::ULong atx; |
|---|
| 172 | values[i].value >>= atx; |
|---|
| 173 | DEBUG(3, USRP_UHD, "Set Auto TX/RX for side 1 to " << atx) |
|---|
| 174 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 175 | if (usrp_uhd->tx_db0_control && usrp_uhd->rx_db0_control) { |
|---|
| 176 | if (atx) { |
|---|
| 177 | usrp_uhd->tx_db0_control->set_auto_tr(true); |
|---|
| 178 | usrp_uhd->rx_db0_control->set_auto_tr(true); |
|---|
| 179 | } else { |
|---|
| 180 | usrp_uhd->tx_db0_control->set_auto_tr(false); |
|---|
| 181 | usrp_uhd->rx_db0_control->set_auto_tr(false); |
|---|
| 182 | } |
|---|
| 183 | } |
|---|
| 184 | } |
|---|
| 185 | }*/ |
|---|
| 186 | } |
|---|
| 187 | |
|---|
| 188 | void USRP_UHD_TX_Control_i::set_interpolation_rate(CORBA::ULong channel, CORBA::ULong I) |
|---|
| 189 | { |
|---|
| 190 | omni_mutex_lock l(usrp_uhd->tx_control_access); |
|---|
| 191 | ///\TODO: rate matching in UHD works a little different. Review |
|---|
| 192 | usrp_uhd->sdev->set_tx_rate(DAC_RATE/I); |
|---|
| 193 | } |
|---|
| 194 | |
|---|
| 195 | void USRP_UHD_TX_Control_i::get_interpolation_range(CORBA::ULong channel, CORBA::ULong &imin, CORBA::ULong &imax, CORBA::ULong &istep) |
|---|
| 196 | { |
|---|
| 197 | DEBUG(1, USRP_UHD, "Get interpolation rate not supported") |
|---|
| 198 | imin = 0; |
|---|
| 199 | imax = 0; |
|---|
| 200 | istep = 0; |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | USRP_UHD_RX_Control_i::USRP_UHD_RX_Control_i(USRP_UHD_i *_usrp_uhd, const char* _name, const char* _domain) : standardInterfaces_i::RX_Control_p(_name, _domain), usrp_uhd(_usrp_uhd) |
|---|
| 204 | { |
|---|
| 205 | DEBUG(3, USRP_UHD, "RX Control port constructor called") |
|---|
| 206 | } |
|---|
| 207 | |
|---|
| 208 | void USRP_UHD_RX_Control_i::set_number_of_channels(CORBA::ULong nchan) |
|---|
| 209 | { |
|---|
| 210 | DEBUG(1, USRP_UHD, "Request to set number of channels to " << nchan<<" not supported") |
|---|
| 211 | |
|---|
| 212 | //omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 213 | |
|---|
| 214 | //usrp_uhd->usrp_uhd_ptr->set_nchannels(nchan); |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | void USRP_UHD_RX_Control_i::get_number_of_channels(CORBA::ULong &num) |
|---|
| 218 | { |
|---|
| 219 | DEBUG(1, USRP_UHD, "Request to get number of channels not supported") |
|---|
| 220 | //omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 221 | |
|---|
| 222 | //num = usrp_uhd->usrp_uhd_ptr->nchannels(); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | void USRP_UHD_RX_Control_i::get_gain_range(CORBA::ULong channel, CORBA::Float &gmin, CORBA::Float &gmax, CORBA::Float &gstep) |
|---|
| 226 | { |
|---|
| 227 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 228 | |
|---|
| 229 | if (channel == 0 && usrp_uhd->sdev) { |
|---|
| 230 | uhd::gain_range_t range = usrp_uhd->sdev->get_rx_gain_range(); |
|---|
| 231 | // All values in range are in dB |
|---|
| 232 | gmin = range.start(); |
|---|
| 233 | gmax = range.stop(); |
|---|
| 234 | gstep = range.step(); |
|---|
| 235 | } |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | void USRP_UHD_RX_Control_i::set_gain(CORBA::ULong channel, CORBA::Float gain) |
|---|
| 239 | { |
|---|
| 240 | DEBUG(1, USRP_UHD, "set gain to "<<gain); |
|---|
| 241 | |
|---|
| 242 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 243 | |
|---|
| 244 | if (channel == 0) { |
|---|
| 245 | if (usrp_uhd->sdev) |
|---|
| 246 | usrp_uhd->sdev->set_rx_gain(gain); |
|---|
| 247 | } else { |
|---|
| 248 | DEBUG(1, USRP_UHD, "Attempt to set gain on non-existent db."); |
|---|
| 249 | return; ///\todo throw bad channel exception |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | void USRP_UHD_RX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain) |
|---|
| 254 | { |
|---|
| 255 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 256 | if (channel == 0 && usrp_uhd->sdev) |
|---|
| 257 | gain = usrp_uhd->sdev->get_rx_gain(); |
|---|
| 258 | else |
|---|
| 259 | return; ///\todo throw bad channel exception |
|---|
| 260 | } |
|---|
| 261 | |
|---|
| 262 | void USRP_UHD_RX_Control_i::get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, CORBA::Float &fmax, CORBA::Float &fstep) |
|---|
| 263 | { |
|---|
| 264 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 265 | |
|---|
| 266 | if (channel == 0) { |
|---|
| 267 | if (usrp_uhd->sdev) { |
|---|
| 268 | uhd::freq_range_t range = usrp_uhd->sdev->get_rx_freq_range(); |
|---|
| 269 | // All values in range are in dB |
|---|
| 270 | fmin = range.start(); |
|---|
| 271 | fmax = range.stop(); |
|---|
| 272 | fstep = 0.0; // There is no step value in uhd::freq_range |
|---|
| 273 | } |
|---|
| 274 | } else { |
|---|
| 275 | return; ///\todo throw bad channel exception |
|---|
| 276 | } |
|---|
| 277 | } |
|---|
| 278 | |
|---|
| 279 | void USRP_UHD_RX_Control_i::set_frequency(CORBA::ULong channel, CORBA::Float f) |
|---|
| 280 | { |
|---|
| 281 | DEBUG(3, USRP_UHD, "In RX Control set frequency channel: " << channel << ", frequency: " << f); |
|---|
| 282 | |
|---|
| 283 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 284 | |
|---|
| 285 | if (channel == 0) { |
|---|
| 286 | uhd::tune_result_t result = usrp_uhd->sdev->set_rx_freq(f); |
|---|
| 287 | |
|---|
| 288 | DEBUG(3, USRP_UHD, "USRP_UHD RX tune_result:" << |
|---|
| 289 | " target_inter_freq=" << result.target_inter_freq << |
|---|
| 290 | " actual_inter_freq=" << result.actual_inter_freq << |
|---|
| 291 | " target_dsp_freq=" << result.target_dsp_freq << |
|---|
| 292 | " actual_dsp_freq=" << result.actual_dsp_freq); |
|---|
| 293 | } else { |
|---|
| 294 | DEBUG(3, USRP_UHD, "USRP_UHD TX set_frequency (invalid channel)"); |
|---|
| 295 | return; |
|---|
| 296 | } |
|---|
| 297 | } |
|---|
| 298 | |
|---|
| 299 | void USRP_UHD_RX_Control_i::get_frequency(CORBA::ULong channel, CORBA::Float &f) |
|---|
| 300 | { |
|---|
| 301 | DEBUG(1, USRP_UHD, "RX get_frequency not supported!!"); |
|---|
| 302 | |
|---|
| 303 | f = 0.0; |
|---|
| 304 | } |
|---|
| 305 | |
|---|
| 306 | void USRP_UHD_RX_Control_i::start(CORBA::ULong channel) |
|---|
| 307 | { |
|---|
| 308 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 309 | |
|---|
| 310 | usrp_uhd->rx_packet_count = usrp_uhd->set_rx_packet_count; |
|---|
| 311 | usrp_uhd->rx_active = true; |
|---|
| 312 | |
|---|
| 313 | // Set up RX thread |
|---|
| 314 | usrp_uhd->rx_thread = new omni_thread(USRP_UHD_i::do_rx_data_process, ((void *)usrp_uhd)); |
|---|
| 315 | usrp_uhd->rx_thread->start(); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | void USRP_UHD_RX_Control_i::stop(CORBA::ULong channel) |
|---|
| 319 | { |
|---|
| 320 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 321 | DEBUG(0, USRP_UHD, "USRP_RX_Control stop Called") |
|---|
| 322 | |
|---|
| 323 | usrp_uhd->rx_active = false;//false; |
|---|
| 324 | } |
|---|
| 325 | |
|---|
| 326 | void USRP_UHD_RX_Control_i::set_values(const CF::Properties &values) |
|---|
| 327 | { |
|---|
| 328 | /* DEBUG(3, USRP_UHD, "USRP_UHD RX setting " << values.length() << " values, value[0].id " << values[0].id) |
|---|
| 329 | |
|---|
| 330 | for (unsigned int i =0; i < values.length(); ++i) { |
|---|
| 331 | if (strcmp(values[i].id, "SET_NUM_RX_PACKETS") == 0) { |
|---|
| 332 | CORBA::ULong num_packets; |
|---|
| 333 | values[i].value >>= num_packets; |
|---|
| 334 | DEBUG(3, USRP_UHD, "Number of packets to RX = " << num_packets) |
|---|
| 335 | usrp_uhd->set_rx_packet_count = num_packets; |
|---|
| 336 | } else if (strcmp(values[i].id, "SET_MUX") == 0 ) { |
|---|
| 337 | CORBA::ULong mux; |
|---|
| 338 | values[i].value >>= mux; |
|---|
| 339 | DEBUG(1, USRP_UHD, "Request to setting receive mux to " << mux<<" not supported") |
|---|
| 340 | //omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 341 | //usrp_uhd->usrp_uhd_ptr->set_mux(mux); |
|---|
| 342 | } else if (strcmp(values[i].id, "SET_RX_ANT_1") == 0 ) { |
|---|
| 343 | CORBA::ULong ant; |
|---|
| 344 | values[i].value >>= ant; |
|---|
| 345 | DEBUG(3, USRP_UHD, "Setting receive antenna to " << ant) |
|---|
| 346 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 347 | if (usrp_uhd->rx_db0_control) |
|---|
| 348 | usrp_uhd->rx_db0_control->select_rx_antenna(ant); |
|---|
| 349 | } |
|---|
| 350 | }*/ |
|---|
| 351 | } |
|---|
| 352 | |
|---|
| 353 | void USRP_UHD_RX_Control_i::set_decimation_rate(CORBA::ULong channel, CORBA::ULong D) |
|---|
| 354 | { |
|---|
| 355 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 356 | if(channel == 0 && usrp_uhd->sdev) |
|---|
| 357 | usrp_uhd->sdev->set_rx_rate(ADC_RATE/D); |
|---|
| 358 | } |
|---|
| 359 | |
|---|
| 360 | void USRP_UHD_RX_Control_i::get_decimation_range(CORBA::ULong channel, CORBA::ULong &dmin, CORBA::ULong &dmax, CORBA::ULong &dstep) |
|---|
| 361 | { |
|---|
| 362 | DEBUG(1, USRP_UHD, "get_decimation_rate not supported!!") |
|---|
| 363 | dmin = 0; |
|---|
| 364 | dmax = 0; |
|---|
| 365 | dstep = 0; |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | void USRP_UHD_RX_Control_i::set_data_packet_size(CORBA::ULong channel, CORBA::ULong N) |
|---|
| 369 | { |
|---|
| 370 | omni_mutex_lock l(usrp_uhd->rx_control_access); |
|---|
| 371 | |
|---|
| 372 | usrp_uhd->rx_packet_size = N; |
|---|
| 373 | } |
|---|