root/ossiedev/branches/jsnyder/trunk/platform/USRP2/src/USRP2_OSSIE.h @ 11057

Revision 11057, 9.2 KB (checked in by mcarrick, 3 years ago)

updating include paths

Line 
1/****************************************************************************
2
3Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University
4
5This file is part of the OSSIE USRP2 Device.
6
7OSSIE USRP2 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 USRP2 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 USRP2 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 <vector>
25
26#include <omnithread.h>
27#include <string.h> //Just for debug
28#include <stdexcept> //Just for debug
29#include <fstream>
30
31#include "usrp2/usrp2.h"
32#include <usrp2/rx_nop_handler.h>
33#include <usrp2/copiers.h>
34
35#include "db_base.h"
36#include "usrp_dbid.h"
37#include "usrp_prims.h"
38
39#include "ossie/cf.h"
40#include "ossie/PortTypes.h"
41
42#include "standardinterfaces/complexShort_u.h"
43#include "standardinterfaces/complexShort_p.h"
44#include "standardinterfaces/Radio_Control_p.h"
45
46#include "ossie/Device_impl.h"
47
48///\FIXME: note from gr-usrp2/src/usrp2_base.h
49//BIG ASS FIXME: get from lower layer MTU calculation
50#define USRP2_MIN_RX_SAMPLES 371
51#define USRP2_MAX_TX_SAMPLES 4096 //maximum number of complex short samples that can be transmitted per packet
52
53// Definitions for provides ports
54class USRP2_i;
55
56class USRP2_RX_Control_i : public standardInterfaces_i::RX_Control_p,
57        boost::noncopyable
58{
59public:
60    USRP2_RX_Control_i(USRP2_i *_usrp2, const char* _name, const char* _domain);
61
62    void set_number_of_channels(CORBA::ULong num);
63    void get_number_of_channels(CORBA::ULong &num);
64    void get_gain_range(CORBA::ULong channel, CORBA::Float &gmin,
65                        CORBA::Float &gmax, CORBA::Float &gstep);
66    void set_gain(CORBA::ULong channel, CORBA::Float gain);
67    void get_gain(CORBA::ULong channel, CORBA::Float &gain);
68    void get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin,
69                             CORBA::Float &fmax, CORBA::Float &fstep);
70    void set_frequency(CORBA::ULong channel, CORBA::Float f);
71    void get_frequency(CORBA::ULong channel, CORBA::Float &f);
72
73    void start(CORBA::ULong channel);
74    void stop(CORBA::ULong channel);
75
76    void set_values(const CF::Properties &values);
77    void set_decimation_rate(CORBA::ULong channel, CORBA::ULong M);
78    void get_decimation_range(CORBA::ULong channel, CORBA::ULong &dmin,
79                              CORBA::ULong &dmax, CORBA::ULong &dstep);
80    void set_data_packet_size(CORBA::ULong channel, CORBA::ULong N);
81
82private:
83    USRP2_RX_Control_i();  // No default constructor
84    USRP2_i *usrp2;
85};
86
87class USRP2_TX_Control_i : public standardInterfaces_i::TX_Control_p,
88        boost::noncopyable
89{
90public:
91    USRP2_TX_Control_i(USRP2_i *_usrp2, const char* _name, const char* _domain);
92
93    void set_number_of_channels(CORBA::ULong num);
94    void get_number_of_channels(CORBA::ULong &num);
95    void get_gain_range(CORBA::ULong channel, CORBA::Float &gmin,
96                        CORBA::Float &gmax, CORBA::Float &gstep);
97    void set_gain(CORBA::ULong channel, CORBA::Float gain);
98    void get_gain(CORBA::ULong channel, CORBA::Float &gain);
99    void get_frequency_range(CORBA::ULong channel, CORBA::Float &fmin,
100                             CORBA::Float &fmax, CORBA::Float &fstep);
101    void set_frequency(CORBA::ULong channel, CORBA::Float f);
102    void get_frequency(CORBA::ULong channel, CORBA::Float &f);
103
104    void start(CORBA::ULong channel);
105    void stop(CORBA::ULong channel);
106
107    void set_values(const CF::Properties &values);
108    void set_interpolation_rate(CORBA::ULong channel, CORBA::ULong I);
109    void get_interpolation_range(CORBA::ULong channel, CORBA::ULong &imin,
110                                 CORBA::ULong &imax, CORBA::ULong &istep);
111
112private:
113    USRP2_TX_Control_i();  // No default constructor
114    USRP2_i *usrp2;
115};
116
117class TX_data_i : public POA_standardInterfaces::complexShort
118{
119public:
120    TX_data_i(USRP2_i *_usrp2);
121    ~TX_data_i();
122
123    void pushPacket(const PortTypes::ShortSequence &I,
124                    const PortTypes::ShortSequence &Q);
125
126private:
127    USRP2_i *usrp2;
128
129    short *tx_buf;
130    unsigned int tx_buf_idx;
131    int tx_buf_len;
132    unsigned int tx_underruns;
133};
134
135/*
136///\FIXME: This is a blunt copy of gr-usrp2/src/ossie_cs_handler()
137class ossie_cs_handler : public usrp2::rx_nop_handler
138{
139  std::complex<int16_t> *d_dest;
140  int count; //just for debug
141
142  // Private constructor
143  ossie_cs_handler(uint64_t max_samples, uint64_t max_quantum, std::complex<int16_t> *dest)
144    : rx_nop_handler(max_samples, max_quantum), d_dest(dest), count(0) {}
145
146  public:
147  // Shared pointer to one of these
148  typedef boost::shared_ptr<ossie_cs_handler> sptr;
149
150  // Factory function to return a shared pointer to a new instance
151  static sptr make(uint64_t max_samples, uint64_t max_quantum, std::complex<int16_t> *dest)
152  {
153      return sptr(new ossie_cs_handler(max_samples, max_quantum, dest));
154  }
155
156  // Invoked by USRP2 API when samples are available
157  bool operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata)
158  {
159std::cout<<"Counter = "<< count++<< " nitems = "<< nitems<<std::endl;
160      // Copy/reformat/endian swap USRP2 data to destination buffer
161      usrp2::copy_u2_16sc_to_host_16sc(nitems, items, d_dest);
162      d_dest += nitems;
163      // FIXME: do something with metadata
164
165      // Call parent to determine if there is room to be called again
166      return rx_nop_handler::operator()(items, nitems, metadata);
167  }
168  ~ossie_cs_handler(){};
169};*/
170
171
172class ossie_cs_handler : public usrp2::rx_nop_handler
173{
174    std::complex<int16_t>* host_items;
175
176public:
177
178    ossie_cs_handler(std::complex<int16_t>* items_ptr,  uint64_t max_samples, uint64_t max_quantum=0)
179            : usrp2::rx_nop_handler(max_samples,max_quantum), host_items(items_ptr) {}
180
181    ~ossie_cs_handler() {};
182
183    bool
184    operator()(const uint32_t *items, size_t nitems, const usrp2::rx_metadata *metadata) {
185        //std::cout<<"OSSIE_Handler:: # items : "<<nitems<<std::endl;
186        bool ok = rx_nop_handler::operator()(items, nitems, metadata);
187
188        //size_t host_nitems = nitems;
189
190        usrp2::copy_u2_16sc_to_host_16sc(nitems, items, host_items);
191
192        return ok;
193    }
194};
195
196
197class USRP2_i : public virtual Device_impl, boost::noncopyable
198{
199    friend class USRP2_RX_Control_i;
200    friend class USRP2_TX_Control_i;
201
202public:
203    USRP2_i(char *id, char *label, char *profile);
204
205    static void do_rx_data_process(void *u) {
206        ((USRP2_i *)u)->rx_data_process();
207    };
208    static void do_tx_data_process(void *u) {
209        ((USRP2_i *)u)->tx_data_process();
210    };
211
212// Methods from the SCA definition
213    void start()
214    throw (CF::Resource::StartError, CORBA::SystemException);
215    void stop()
216    throw (CF::Resource::StopError, CORBA::SystemException);
217    CORBA::Object_ptr getPort(const char* portName)
218    throw(CF::PortSupplier::UnknownPort, CORBA::SystemException);
219    void initialize()
220    throw (CF::LifeCycle::InitializeError, CORBA::SystemException);
221    void configure(const CF::Properties &configProperties)
222    throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration,
223           CF::PropertySet::PartialConfiguration);
224    void query(CF::Properties &configProperties)
225    throw (CORBA::SystemException, CF::UnknownProperties);
226    void releaseObject()
227    throw (CF::LifeCycle::ReleaseError, CORBA::SystemException);
228
229    omni_mutex rx_run;
230
231// These mutex's protect port and usrp2 config operations
232    omni_mutex rx_control_access;
233    omni_mutex tx_control_access;
234
235private:
236    USRP2_i();  // No default constructor
237
238// Port objects
239    USRP2_RX_Control_i* rx_control_port;
240    USRP2_TX_Control_i* tx_control_port;
241
242    standardInterfaces_i::complexShort_u* rx_data_1_port;
243    standardInterfaces_i::complexShort_u* rx_data_2_port;
244
245    standardInterfaces_i::complexShort_p* tx_data_port;
246
247// usrp2 variables
248    usrp2::usrp2::sptr usrp2_ptr;
249//    ossie_cs_handler rx_short_buffer;
250
251// Daughterboard data
252//
253// A vector of subdevices is associated for each daughterboard with libusrp2.
254// Only a single subdevice (the first) is supported at this time.
255    int rx_db0;
256    int tx_db0;
257
258    db_base_sptr rx_db0_control;
259    db_base_sptr tx_db0_control;
260
261    omni_thread *rx_thread;
262    omni_thread *tx_thread;
263
264    void rx_data_process();
265    void tx_data_process();
266
267    long set_rx_packet_count;
268    long rx_packet_count;           ///< Number of packets to collect from USRP2, -1 is forever
269    unsigned int rx_packet_size;    ///< Number of samples to send to clients
270    unsigned int rx_data_size;      ///< Size of words coming from USRP2
271    unsigned int number_of_channels;
272    bool complex;                   ///< True for complex data from USRP2
273    unsigned int rx_overruns;
274    unsigned int rx_missing;
275
276    volatile bool rx_active;
277    volatile bool tx_active;
278};
Note: See TracBrowser for help on using the browser.