root/ossiedev/branches/june/trunk/platform/USRP_UHD/src/port_impl.cpp @ 11039

Revision 11039, 13.0 KB (checked in by june, 16 months ago)

done tx samplerate, frequency

Line 
1/****************************************************************************
2
3Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE USRP_UHD Device.
6
7OSSIE USRP_UHD Device is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12OSSIE USRP_UHD Device is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with OSSIE USRP_UHD Device; if not, write to the Free Software
19Foundation, 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
29USRP_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
34void 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
45void 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
54void 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
69void 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
82void 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
94void 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
112void 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    if (channel == 0) {
117        uhd::tune_result_t result = usrp_uhd->sdev->set_tx_freq(f);
118
119        DEBUG(3, USRP_UHD, "USRP_UHD TX tune_result:" <<std::endl<<
120              " \tTarget_RF_Freq=" << result.target_rf_freq <<std::endl<<
121              " \tActual_RF_Freq=" << result.actual_rf_freq <<std::endl<<
122              " \tTarget_DSP_freq="   << result.target_dsp_freq <<std::endl<<
123              " \tActual_DSP_freq="   << result.actual_dsp_freq);
124    } else {
125        DEBUG(3, USRP_UHD, "USRP_UHD TX set_frequency (invalid channel)");
126        return;
127    }
128
129}
130
131void USRP_UHD_TX_Control_i::get_frequency(CORBA::ULong channel, CORBA::Float &f)
132{
133        f = usrp_uhd->sdev->get_tx_freq();
134        DEBUG(3, USRP_UHD, "In TX Control get frequency channel: " << channel << ", frequency: " << f);
135
136}
137
138void USRP_UHD_TX_Control_i::start(CORBA::ULong channel)
139{
140    omni_mutex_lock l(usrp_uhd->tx_control_access);
141
142    if (!usrp_uhd->tx_active) {
143        usrp_uhd->tx_thread = new omni_thread(USRP_UHD_i::do_tx_data_process, ((void *)usrp_uhd));
144        usrp_uhd->tx_thread->start();
145    }
146}
147
148void USRP_UHD_TX_Control_i::stop(CORBA::ULong channel)
149{
150    omni_mutex_lock l(usrp_uhd->tx_control_access);
151
152    usrp_uhd->tx_active = false;
153
154}
155
156void USRP_UHD_TX_Control_i::set_values(const CF::Properties &values)
157{
158
159    DEBUG(3, USRP_UHD, "USRP_UHD TX setting " << values.length() << " values, value[0].id " << values[0].id)
160#if 0
161    for (unsigned int i =0; i < values.length(); ++i) {
162        if (strcmp(values[i].id, "SET_MUX") == 0 ) {
163            CORBA::ULong mux;
164            values[i].value >>= mux;
165            DEBUG(1, USRP_UHD, "Request to set transmit mux to  " << mux<<" Not Supported")
166            //omni_mutex_lock l(usrp_uhd->tx_control_access);
167            //usrp_uhd->usrp_uhd_ptr->set_mux(mux);
168        } else if (strcmp(values[i].id, "SET_AUTO_TR_1") == 0) {
169            CORBA::ULong atx;
170            values[i].value >>= atx;
171            DEBUG(3, USRP_UHD, "Set Auto TX/RX for side 1 to " << atx)
172            omni_mutex_lock l(usrp_uhd->tx_control_access);
173            if (usrp_uhd->tx_db0_control && usrp_uhd->rx_db0_control) {
174                if (atx) {
175                    usrp_uhd->tx_db0_control->set_auto_tr(true);
176                    usrp_uhd->rx_db0_control->set_auto_tr(true);
177                } else {
178                    usrp_uhd->tx_db0_control->set_auto_tr(false);
179                    usrp_uhd->rx_db0_control->set_auto_tr(false);
180                }
181            }
182        }
183    }
184#endif
185}
186
187void USRP_UHD_TX_Control_i::set_interpolation_rate(CORBA::ULong channel, CORBA::ULong I)
188{
189    omni_mutex_lock l(usrp_uhd->tx_control_access);
190    ///\TODO: rate matching in UHD works a little different. Review
191    double master_clock = usrp_uhd->sdev->get_master_clock_rate();
192    double request_da_rate = master_clock/(double)I;
193    usrp_uhd->sdev->set_tx_rate(request_da_rate,channel);
194    double real_da_rate = usrp_uhd->sdev->get_tx_rate(channel);
195    DEBUG(3, USRP_UHD, "Requested Tx sample rate ="<<request_da_rate<<", Real Tx sample rate ="<<real_da_rate)
196}
197
198void USRP_UHD_TX_Control_i::get_interpolation_range(CORBA::ULong channel, CORBA::ULong &imin, CORBA::ULong &imax, CORBA::ULong &istep)
199{
200        double master_clock = usrp_uhd->sdev->get_master_clock_rate();
201        uhd::meta_range_t tx_range = usrp_uhd->sdev->get_tx_rates(channel);
202    imax = master_clock/tx_range.start();
203    imin = master_clock/tx_range.stop();
204    istep = master_clock/tx_range.step();
205    DEBUG(3, USRP_UHD, "Interpolation min="<<imin<<", max="<<imax<<", step="<<istep)
206}
207
208USRP_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)
209{
210    DEBUG(3, USRP_UHD, "RX Control port constructor called")
211}
212
213void USRP_UHD_RX_Control_i::set_number_of_channels(CORBA::ULong nchan)
214{
215    DEBUG(1, USRP_UHD, "Request to set number of channels to " << nchan<<" not supported")
216
217//omni_mutex_lock l(usrp_uhd->rx_control_access);
218
219//usrp_uhd->usrp_uhd_ptr->set_nchannels(nchan);
220}
221
222void USRP_UHD_RX_Control_i::get_number_of_channels(CORBA::ULong &num)
223{
224    DEBUG(1, USRP_UHD, "Request to get number of channels not supported")
225//omni_mutex_lock l(usrp_uhd->rx_control_access);
226
227//num = usrp_uhd->usrp_uhd_ptr->nchannels();
228}
229
230void USRP_UHD_RX_Control_i::get_gain_range(CORBA::ULong channel, CORBA::Float &gmin, CORBA::Float &gmax, CORBA::Float &gstep)
231{
232    omni_mutex_lock l(usrp_uhd->rx_control_access);
233
234    if (channel == 0 && usrp_uhd->sdev) {
235        uhd::gain_range_t range = usrp_uhd->sdev->get_rx_gain_range();
236        // All values in range are in dB
237        gmin = range.start();
238        gmax = range.stop();
239        gstep = range.step();
240    }
241}
242
243void USRP_UHD_RX_Control_i::set_gain(CORBA::ULong channel, CORBA::Float gain)
244{
245    DEBUG(1, USRP_UHD, "set gain to "<<gain);
246
247    omni_mutex_lock l(usrp_uhd->rx_control_access);
248
249    if (channel == 0) {
250        if (usrp_uhd->sdev)
251            usrp_uhd->sdev->set_rx_gain(gain);
252    } else {
253        DEBUG(1, USRP_UHD, "Attempt to set gain on non-existent db.");
254        return; ///\todo throw bad channel exception
255    }
256}
257
258void USRP_UHD_RX_Control_i::get_gain(CORBA::ULong channel, CORBA::Float &gain)
259{
260    omni_mutex_lock l(usrp_uhd->rx_control_access);
261    if (channel == 0 && usrp_uhd->sdev)
262        gain = usrp_uhd->sdev->get_rx_gain();
263    else
264        return; ///\todo throw bad channel exception
265}
266
267void USRP_UHD_RX_Control_i::get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin, CORBA::Float &fmax, CORBA::Float &fstep)
268{
269    omni_mutex_lock l(usrp_uhd->rx_control_access);
270
271    if (channel == 0) {
272        if (usrp_uhd->sdev) {
273            uhd::freq_range_t range = usrp_uhd->sdev->get_rx_freq_range();
274            // All values in range are in dB
275            fmin = range.start();
276            fmax = range.stop();
277            fstep = 0.0; // There is no step value in uhd::freq_range
278        }
279    } else {
280        return; ///\todo throw bad channel exception
281    }
282}
283
284void USRP_UHD_RX_Control_i::set_frequency(CORBA::ULong channel, CORBA::Float f)
285{
286    DEBUG(3, USRP_UHD, "In RX Control set frequency channel: " << channel << ", frequency: " << f);
287
288    omni_mutex_lock l(usrp_uhd->rx_control_access);
289
290    if (channel == 0) {
291        uhd::tune_result_t result = usrp_uhd->sdev->set_rx_freq(f);
292/*
293        DEBUG(3, USRP_UHD, "USRP_UHD RX tune_result:" <<
294              " target_inter_freq=" << result.target_inter_freq <<
295              " actual_inter_freq=" << result.actual_inter_freq <<
296              " target_dsp_freq="   << result.target_dsp_freq <<
297              " actual_dsp_freq="   << result.actual_dsp_freq);
298              */
299    } else {
300        DEBUG(3, USRP_UHD, "USRP_UHD TX set_frequency (invalid channel)");
301        return;
302    }
303}
304
305void USRP_UHD_RX_Control_i::get_frequency(CORBA::ULong channel, CORBA::Float &f)
306{
307    DEBUG(1, USRP_UHD, "RX get_frequency not supported!!");
308
309    f = 0.0;
310}
311
312void USRP_UHD_RX_Control_i::start(CORBA::ULong channel)
313{
314    omni_mutex_lock l(usrp_uhd->rx_control_access);
315
316    usrp_uhd->rx_packet_count = usrp_uhd->set_rx_packet_count;
317    usrp_uhd->rx_active = true;
318
319// Set up RX thread
320    usrp_uhd->rx_thread = new omni_thread(USRP_UHD_i::do_rx_data_process, ((void *)usrp_uhd));
321    usrp_uhd->rx_thread->start();
322}
323
324void USRP_UHD_RX_Control_i::stop(CORBA::ULong channel)
325{
326    omni_mutex_lock l(usrp_uhd->rx_control_access);
327    DEBUG(0, USRP_UHD, "USRP_RX_Control stop Called")
328
329    usrp_uhd->rx_active = false;//false;
330}
331
332void USRP_UHD_RX_Control_i::set_values(const CF::Properties &values)
333{
334/*    DEBUG(3, USRP_UHD, "USRP_UHD RX setting " << values.length() << " values, value[0].id " << values[0].id)
335
336    for (unsigned int i =0; i < values.length(); ++i) {
337        if (strcmp(values[i].id, "SET_NUM_RX_PACKETS") == 0) {
338            CORBA::ULong num_packets;
339            values[i].value >>= num_packets;
340            DEBUG(3, USRP_UHD, "Number of packets to RX = " << num_packets)
341            usrp_uhd->set_rx_packet_count = num_packets;
342        } else if (strcmp(values[i].id, "SET_MUX") == 0 ) {
343            CORBA::ULong mux;
344            values[i].value >>= mux;
345            DEBUG(1, USRP_UHD, "Request to setting receive mux to  " << mux<<" not supported")
346            //omni_mutex_lock l(usrp_uhd->rx_control_access);
347            //usrp_uhd->usrp_uhd_ptr->set_mux(mux);
348        } else if (strcmp(values[i].id, "SET_RX_ANT_1") == 0 ) {
349            CORBA::ULong ant;
350            values[i].value >>= ant;
351            DEBUG(3, USRP_UHD, "Setting receive antenna to  " << ant)
352            omni_mutex_lock l(usrp_uhd->rx_control_access);
353            if (usrp_uhd->rx_db0_control)
354                usrp_uhd->rx_db0_control->select_rx_antenna(ant);
355        }
356    }*/
357}
358
359void USRP_UHD_RX_Control_i::set_decimation_rate(CORBA::ULong channel, CORBA::ULong D)
360{
361    omni_mutex_lock l(usrp_uhd->rx_control_access);
362    if(channel == 0 && usrp_uhd->sdev)
363        usrp_uhd->sdev->set_rx_rate(ADC_RATE/D);
364}
365
366void USRP_UHD_RX_Control_i::get_decimation_range(CORBA::ULong channel, CORBA::ULong &dmin, CORBA::ULong &dmax, CORBA::ULong &dstep)
367{
368    DEBUG(1, USRP_UHD, "get_decimation_rate not supported!!")
369    dmin = 0;
370    dmax = 0;
371    dstep = 0;
372}
373
374void USRP_UHD_RX_Control_i::set_data_packet_size(CORBA::ULong channel, CORBA::ULong N)
375{
376    omni_mutex_lock l(usrp_uhd->rx_control_access);
377
378    usrp_uhd->rx_packet_size = N;
379}
Note: See TracBrowser for help on using the browser.