root/components/USRP_TX_Control/branches/USRP_Commander/src/USRP_Commander.cpp @ 4536

Revision 4536, 9.8 KB (checked in by jgaeddert, 6 years ago)

in USRPCommander: moving remote port function calls to start() method which should be invoked after port connections are actually made

  • Property svn:eol-style set to native
Line 
1/****************************************************************************
2
3Copyright 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE USRP_Commander.
6
7OSSIE USRP_Commander 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_Commander 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_Commander; 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 <string>
25#include <iostream>
26
27#include "ossie/cf.h"
28#include "ossie/PortTypes.h"
29#include "ossie/debug.h"
30
31#include "USRP_Commander.h"
32
33#include "ossie/Resource_impl.h"
34
35USRP_Commander_i::USRP_Commander_i(const char *uuid, omni_condition *condition) :
36    Resource_impl(uuid),
37    component_running(condition),
38    tx_interp(0),
39    tx_freq(0),
40    tx_gain(0),
41    tx_start(false),
42    rx_decim(0),
43    rx_gain_max(0),
44    rx_freq(0),
45    rx_gain(0),
46    rx_size(0),
47    rx_start(false)
48{
49    // Create port instances
50    TXControl = new standardInterfaces_i::TX_Control_u("TX_Control");
51    RXControl = new standardInterfaces_i::RX_Control_u("RX_Control");
52    data_control = new standardInterfaces_i::Resource_u("Data_Control");
53}
54
55CORBA::Object_ptr USRP_Commander_i::getPort( const char* portName )
56    throw (CORBA::SystemException, CF::PortSupplier::UnknownPort)
57{
58    DEBUG(3, USRP_Commander, "getPort called with : " << portName)
59   
60    CORBA::Object_var p;
61
62    // Check TXControl
63    p = TXControl->getPort(portName);
64    if (!CORBA::is_nil(p))
65        return p._retn();
66
67    // Check RXControl
68    p = RXControl->getPort(portName);
69    if (!CORBA::is_nil(p))
70        return p._retn();
71
72    // Check data_control
73    p = data_control->getPort(portName);
74    if (!CORBA::is_nil(p))
75        return p._retn();
76
77    std::cerr << "USRP Commander::getPort() unknown port: " << portName << std::endl;
78    throw CF::PortSupplier::UnknownPort();
79
80    // This will never happen, but gcc complains if nothing is returned at this point
81    return p;
82}
83
84void USRP_Commander_i::start() throw (CORBA::SystemException, CF::Resource::StartError)
85{
86    DEBUG(3, USRP_Commander, "start called on USRP_Commander")
87
88    // Call start on remote resources
89    CF::Resource_var r = data_control->getRef();
90    r->start();
91
92    //-----------------------------------------------------------------------------
93    //
94    // Set TX properties
95    //
96    //-----------------------------------------------------------------------------
97
98    // Initialize to default TX values
99    TXControl->set_number_of_channels(1);
100    TXControl->set_gain(DEFAULT_USRP_TX_CHANNEL, tx_gain);
101    TXControl->set_frequency(DEFAULT_USRP_TX_CHANNEL, tx_freq);
102    TXControl->set_interpolation_rate(DEFAULT_USRP_TX_CHANNEL, tx_interp);
103
104    // Set transmit configurable properties not included in Radio_Control idl
105    CF::Properties tx_config;
106    tx_config.length(1);
107
108    // Set automatic transmit/receive mode on
109    tx_config[0].id = CORBA::string_dup("SET_AUTO_TR_1");
110    tx_config[0].value <<= (CORBA::ULong) 1;
111
112    TXControl->set_values(tx_config);
113
114    //-----------------------------------------------------------------------------
115    //
116    // Set RX properties
117    //
118    //-----------------------------------------------------------------------------
119
120    // Initialize to default RX values
121    RXControl->set_number_of_channels(1);
122    RXControl->set_gain(DEFAULT_USRP_RX_CHANNEL, rx_gain);
123    RXControl->set_frequency(DEFAULT_USRP_RX_CHANNEL, rx_freq);
124    RXControl->set_decimation_rate(DEFAULT_USRP_RX_CHANNEL, rx_decim);
125    RXControl->set_data_packet_size(DEFAULT_USRP_RX_CHANNEL, rx_size);
126
127    // Set transmit configurable properties not included in Radio_Control idl
128    CF::Properties rx_config;
129    rx_config.length(1);
130
131    // Set rx antenna
132    rx_config[0].id = CORBA::string_dup("SET_RX_ANT_1");
133    rx_config[0].value <<= (CORBA::ULong) 0;
134
135    RXControl->set_values(rx_config);
136
137    if (tx_start) {
138        DEBUG(3, USRP_Commander, "starting USRP transmit process...");
139        TXControl->start(DEFAULT_USRP_TX_CHANNEL);
140    }
141
142    if (rx_start) {
143        RXControl->start(DEFAULT_USRP_RX_CHANNEL);
144        DEBUG(3, USRP_Commander, "starting USRP receive process...");
145    }
146
147}
148
149void USRP_Commander_i::stop() throw (CORBA::SystemException, CF::Resource::StopError)
150
151    DEBUG(3, USRP_Commander, "stop called on USRP_Commander")
152
153    // Call stop on remote resources
154    CF::Resource_var r = data_control->getRef();
155    r->stop();
156
157    RXControl->stop(DEFAULT_USRP_RX_CHANNEL);
158    TXControl->stop(DEFAULT_USRP_TX_CHANNEL);
159}
160
161void USRP_Commander_i::releaseObject() throw (CORBA::SystemException, CF::LifeCycle::ReleaseError)
162{
163    DEBUG(3, USRP_Commander, "releaseObject called on USRP_Commander")
164   
165    component_running->signal();
166}
167
168void USRP_Commander_i::initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException)
169{
170    DEBUG(3, USRP_Commander, "initialize called on USRP_Commander")
171   
172    // Initialize USRP TX properties
173    tx_interp = 256;        // TX interpolation factor
174    tx_freq = 475000000;    // TX frequency
175    tx_gain = 1;            // TX gain
176    tx_start = false;       // Start transmitter flag
177
178    // Initialize USRP RX properties
179    rx_decim = 256;         // RX decimation factor
180    rx_freq = 485000000;    // RX frequency
181    rx_gain = 1;            // RX gain
182    rx_size = 1024;         // RX packet size
183    rx_start = false;       // Start receiver flag
184
185}
186
187
188
189void USRP_Commander_i::configure(const CF::Properties& props)
190    throw (CORBA::SystemException,
191           CF::PropertySet::InvalidConfiguration,
192           CF::PropertySet::PartialConfiguration)
193{
194    DEBUG(3, USRP_Commander, "configure called on USRP_Commander")
195   
196    DEBUG(3, USRP_Commander, "props length : " << props.length())
197
198    RXControl->set_number_of_channels(1);
199
200    for (unsigned int i = 0; i < props.length(); i++) {
201        DEBUG(3, USRP_Commander, "Property id : " << props[i].id)
202
203        if (strcmp(props[i].id, "DCE:3efc3930-2739-40b4-8c02-ecfb1b0da9ee") == 0) {
204            // RX Frequency
205            CORBA::Float F;
206            props[i].value >>= F;
207            DEBUG(3, USRP_Commander, "RX Frequency property= " << F)
208            rx_freq = F;
209            RXControl->set_frequency(DEFAULT_USRP_RX_CHANNEL, rx_freq);
210        } else if (strcmp(props[i].id, "DCE:6a2d6952-ca11-4787-afce-87a89b882b7b") == 0) {
211            // TX Frequency
212            CORBA::Float F;
213            props[i].value >>= F;
214            DEBUG(3, USRP_Commander, "TX Frequency property= " << F)
215            tx_freq = F;
216            TXControl->set_frequency(DEFAULT_USRP_TX_CHANNEL, tx_freq);
217        } else if (strcmp(props[i].id, "DCE:9ca12c0e-ba65-40cf-9ef3-6e7ac671ab5d") == 0) {
218            // Transmitter Interpolation Factor
219            CORBA::Short M;
220            props[i].value >>= M;
221            DEBUG(3, USRP_Commander, "TX Interpolation Factor property= " << M)
222            tx_interp = M;
223            TXControl->set_interpolation_rate(DEFAULT_USRP_TX_CHANNEL, tx_interp);
224        } else if (strcmp(props[i].id, "DCE:92ec2b80-8040-47c7-a1d8-4c9caa4a4ed2") == 0) {
225            // RX Decimation factor
226            CORBA::Short D;
227            props[i].value >>= D;
228            DEBUG(3, USRP_Commander, "RX Decimation Factor property= " << D)
229            rx_decim = D;
230            RXControl->set_decimation_rate(DEFAULT_USRP_RX_CHANNEL, rx_decim);
231        } else if (strcmp(props[i].id, "DCE:93324adf-14f6-4406-ba92-a3650089857f") == 0) {
232            // RX Data Packet size
233            CORBA::ULong L;
234            props[i].value >>= L;
235            DEBUG(3, USRP_Commander, "RX Data Packet size property= " << L)
236            rx_size = L;
237            RXControl->set_data_packet_size(DEFAULT_USRP_RX_CHANNEL, rx_size);
238        } else if (strcmp(props[i].id, "DCE:99d586b6-7764-4dc7-83fa-72270d0f1e1b") == 0) {
239            //Rx Gain
240            CORBA::Float G;
241            props[i].value >>= G;
242            DEBUG(3, USRP_Commander, "RX Gain property= " << G)
243            rx_gain = G;
244            RXControl->set_gain(DEFAULT_USRP_RX_CHANNEL, rx_gain);
245        } else if (strcmp(props[i].id, "DCE:2d9c5ee4-a6f3-4ab9-834b-2b5c95818e53") == 0) {
246            //Rx Gain Max
247            ///\todo check gain values, perhaps get rid of this property
248            CORBA::Short v;
249            props[i].value >>= v;
250            DEBUG(3, USRP_Commander, "RX Gain Max property= " << v)
251            DEBUG(3, USRP_Commander, "  ::::  WARNING: RX Gain Max property ignored!  ::::")
252            rx_gain_max = v;
253        } else if (strcmp(props[i].id, "DCE:fd42344f-4d87-465b-9e6f-e1d7ae48afd6") == 0) {
254            // rx_start
255            CORBA::Short v;
256            props[i].value >>= v;
257            rx_start = (v==0) ? false : true;
258            DEBUG(3, USRP_Commander, "RX start set  to " << rx_start)
259            //if (rx_start)
260            //    RXControl->start(DEFAULT_USRP_RX_CHANNEL);
261        } else if (strcmp(props[i].id, "DCE:0a9b8c8c-f130-4a8f-9ef8-bba023128a4b") == 0) {
262            // tx_start
263            CORBA::Short v;
264            props[i].value >>= v;
265            tx_start = (v==0) ? false : true;
266            DEBUG(3, USRP_Commander, "TX Start set to " << tx_start)
267            //if (tx_start)
268            //    TXControl->start(DEFAULT_USRP_TX_CHANNEL);
269        } else {
270            std::cerr << "ERROR: USRP Commander::configure(), unknown property: " << props[i].id << std::endl;
271            throw CF::PropertySet::InvalidConfiguration();
272        }
273    }
274
275}
Note: See TracBrowser for help on using the browser.