| 1 | /**************************************************************************** |
|---|
| 2 | |
|---|
| 3 | Copyright 2005,2006 Virginia Polytechnic Institute and State University |
|---|
| 4 | |
|---|
| 5 | This file is part of the OSSIE USRP Device. |
|---|
| 6 | |
|---|
| 7 | OSSIE USRP 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 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 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 <vector> |
|---|
| 25 | |
|---|
| 26 | #include <omnithread.h> |
|---|
| 27 | |
|---|
| 28 | #include "usrp_standard.h" |
|---|
| 29 | #include "usrp_dbid.h" |
|---|
| 30 | #include "usrp_prims.h" |
|---|
| 31 | |
|---|
| 32 | #include "ossie/cf.h" |
|---|
| 33 | #include "ossie/PortTypes.h" |
|---|
| 34 | |
|---|
| 35 | #include "standardinterfaces/complexShort_u.h" |
|---|
| 36 | #include "standardinterfaces/complexShort_p.h" |
|---|
| 37 | #include "standardinterfaces/Radio_Control_p.h" |
|---|
| 38 | |
|---|
| 39 | #include "ossie/Device_impl.h" |
|---|
| 40 | |
|---|
| 41 | #include "flex.h" |
|---|
| 42 | #include "dbsrx.h" |
|---|
| 43 | #include "tvrx.h" |
|---|
| 44 | |
|---|
| 45 | // Definitions for provides ports |
|---|
| 46 | class USRP_i; |
|---|
| 47 | |
|---|
| 48 | class USRP_RX_Control_i : public standardInterfaces_i::RX_Control_p |
|---|
| 49 | |
|---|
| 50 | { |
|---|
| 51 | |
|---|
| 52 | public: |
|---|
| 53 | USRP_RX_Control_i(USRP_i *_usrp, const char* _name, const char* _domain); |
|---|
| 54 | void set_number_of_channels(unsigned long num); |
|---|
| 55 | void get_number_of_channels(unsigned long &num); |
|---|
| 56 | |
|---|
| 57 | void get_gain_range(unsigned long channel, float &gmin, float &gmax, float &gstep); |
|---|
| 58 | void set_gain(unsigned long channel, float gain); |
|---|
| 59 | void get_gain(unsigned long channel, float &gain); |
|---|
| 60 | |
|---|
| 61 | void get_frequency_range(unsigned long channel, float &fmin, float &fmax, float &fstep); |
|---|
| 62 | void set_frequency(unsigned long channel, float f); |
|---|
| 63 | void get_frequency(unsigned long channel, float &f); |
|---|
| 64 | |
|---|
| 65 | void start(unsigned long channel); |
|---|
| 66 | void stop(unsigned long channel); |
|---|
| 67 | |
|---|
| 68 | void set_values(const CF::Properties &values); |
|---|
| 69 | |
|---|
| 70 | void set_decimation_rate(unsigned long channel, unsigned long M); |
|---|
| 71 | void get_decimation_range(unsigned long channel, unsigned long &dmin, unsigned long &dmax, unsigned long &dstep); |
|---|
| 72 | |
|---|
| 73 | void set_data_packet_size(unsigned long channel, unsigned long N); |
|---|
| 74 | |
|---|
| 75 | private: |
|---|
| 76 | USRP_RX_Control_i(); // No default constructor |
|---|
| 77 | USRP_RX_Control_i(const USRP_RX_Control_i &); // No copying |
|---|
| 78 | |
|---|
| 79 | /// return pointer to daughterboard |
|---|
| 80 | void get_db_reference(unsigned long channel, db_base *& db); |
|---|
| 81 | |
|---|
| 82 | USRP_i *usrp; |
|---|
| 83 | |
|---|
| 84 | float db_lo_freq; |
|---|
| 85 | float db_lo_offset; |
|---|
| 86 | bool lo_locked; |
|---|
| 87 | |
|---|
| 88 | }; |
|---|
| 89 | |
|---|
| 90 | class USRP_TX_Control_i : public standardInterfaces_i::TX_Control_p |
|---|
| 91 | |
|---|
| 92 | { |
|---|
| 93 | public: |
|---|
| 94 | USRP_TX_Control_i(USRP_i *_usrp, const char* _name, const char* _domain); |
|---|
| 95 | void set_number_of_channels(unsigned long num); |
|---|
| 96 | void get_number_of_channels(unsigned long &num); |
|---|
| 97 | |
|---|
| 98 | void get_gain_range(unsigned long channel, float &gmin, float &gmax, float &gstep); |
|---|
| 99 | void set_gain(unsigned long channel, float gain); |
|---|
| 100 | void get_gain(unsigned long channel, float &gain); |
|---|
| 101 | |
|---|
| 102 | void get_frequency_range(unsigned long channel, float &fmin, float &fmax, float &fstep); |
|---|
| 103 | void set_frequency(unsigned long channel, float f); |
|---|
| 104 | void get_frequency(unsigned long channel, float &f); |
|---|
| 105 | |
|---|
| 106 | void start(unsigned long channel); |
|---|
| 107 | void stop(unsigned long channel); |
|---|
| 108 | |
|---|
| 109 | void set_values(const CF::Properties &values); |
|---|
| 110 | |
|---|
| 111 | void set_interpolation_rate(unsigned long channel, unsigned long I); |
|---|
| 112 | void get_interpolation_range(unsigned long channel, unsigned long &imin, unsigned long &imax, unsigned long &istep); |
|---|
| 113 | |
|---|
| 114 | private: |
|---|
| 115 | USRP_TX_Control_i(); // No default constructor |
|---|
| 116 | USRP_TX_Control_i(const USRP_TX_Control_i &); // No copying |
|---|
| 117 | |
|---|
| 118 | /// return pointer to daughterboard |
|---|
| 119 | void get_db_reference(unsigned long channel, db_base *& db); |
|---|
| 120 | |
|---|
| 121 | USRP_i *usrp; |
|---|
| 122 | |
|---|
| 123 | float db_lo_freq; |
|---|
| 124 | float db_lo_offset; |
|---|
| 125 | bool lo_locked; |
|---|
| 126 | }; |
|---|
| 127 | |
|---|
| 128 | class TX_data_i : public POA_standardInterfaces::complexShort |
|---|
| 129 | |
|---|
| 130 | { |
|---|
| 131 | public: |
|---|
| 132 | TX_data_i(USRP_i *_usrp); |
|---|
| 133 | ~TX_data_i(); |
|---|
| 134 | |
|---|
| 135 | void pushPacket( |
|---|
| 136 | const PortTypes::ShortSequence &I, |
|---|
| 137 | const PortTypes::ShortSequence &Q, |
|---|
| 138 | const standardInterfaces::MetaData &packet_data); |
|---|
| 139 | |
|---|
| 140 | private: |
|---|
| 141 | USRP_i *usrp; |
|---|
| 142 | |
|---|
| 143 | short *tx_buf; |
|---|
| 144 | unsigned int tx_buf_idx; |
|---|
| 145 | int tx_buf_len; |
|---|
| 146 | |
|---|
| 147 | unsigned int tx_underruns; |
|---|
| 148 | }; |
|---|
| 149 | |
|---|
| 150 | // Definitions for uses ports |
|---|
| 151 | |
|---|
| 152 | // Main USRP device definition |
|---|
| 153 | |
|---|
| 154 | class USRP_i : public virtual Device_impl |
|---|
| 155 | |
|---|
| 156 | { |
|---|
| 157 | friend class USRP_RX_Control_i; |
|---|
| 158 | friend class USRP_TX_Control_i; |
|---|
| 159 | |
|---|
| 160 | public: |
|---|
| 161 | USRP_i(char *id, char *label, char *profile); |
|---|
| 162 | |
|---|
| 163 | /// Destructor |
|---|
| 164 | ~USRP_i(); |
|---|
| 165 | |
|---|
| 166 | static void do_rx_data_process(void *u) {((USRP_i *)u)->rx_data_process(); }; |
|---|
| 167 | static void do_tx_data_process(void *u) {((USRP_i *)u)->tx_data_process(); }; |
|---|
| 168 | |
|---|
| 169 | // Methods from the SCA definition |
|---|
| 170 | void start() throw (CF::Resource::StartError, CORBA::SystemException); |
|---|
| 171 | void stop() throw (CF::Resource::StopError, CORBA::SystemException); |
|---|
| 172 | CORBA::Object_ptr getPort(const char* portName) throw(CF::PortSupplier::UnknownPort, CORBA::SystemException); |
|---|
| 173 | void initialize() throw (CF::LifeCycle::InitializeError, CORBA::SystemException); |
|---|
| 174 | void configure(const CF::Properties &configProperties) throw (CORBA::SystemException, CF::PropertySet::InvalidConfiguration, CF::PropertySet::PartialConfiguration); |
|---|
| 175 | void query(CF::Properties &configProperties) throw (CORBA::SystemException, CF::UnknownProperties); |
|---|
| 176 | |
|---|
| 177 | void releaseObject() throw (CF::LifeCycle::ReleaseError, CORBA::SystemException); |
|---|
| 178 | |
|---|
| 179 | omni_mutex rx_run; |
|---|
| 180 | |
|---|
| 181 | // These mutex's protect port and usrp config operations |
|---|
| 182 | omni_mutex rx_control_access; |
|---|
| 183 | omni_mutex tx_control_access; |
|---|
| 184 | |
|---|
| 185 | |
|---|
| 186 | private: |
|---|
| 187 | USRP_i(); // No default constructor |
|---|
| 188 | USRP_i(const USRP_i&); // No copying |
|---|
| 189 | |
|---|
| 190 | /// Prints warning about unsupported USRP daughter boards |
|---|
| 191 | void PrintDaughterboardWarning(const char * db_name); |
|---|
| 192 | |
|---|
| 193 | // Port objects |
|---|
| 194 | USRP_RX_Control_i* rx_control_port; |
|---|
| 195 | USRP_TX_Control_i* tx_control_port; |
|---|
| 196 | |
|---|
| 197 | standardInterfaces_i::complexShort_u* rx_data_1_port; |
|---|
| 198 | standardInterfaces_i::complexShort_u* rx_data_2_port; |
|---|
| 199 | standardInterfaces::MetaData* rx_metadata_1; |
|---|
| 200 | standardInterfaces::MetaData* rx_metadata_2; |
|---|
| 201 | |
|---|
| 202 | standardInterfaces_i::complexShort_p* tx_data_port; |
|---|
| 203 | standardInterfaces::MetaData* tx_metadata; |
|---|
| 204 | |
|---|
| 205 | // usrp variables |
|---|
| 206 | |
|---|
| 207 | usrp_standard_rx *usrp_rx; |
|---|
| 208 | usrp_standard_tx *usrp_tx; |
|---|
| 209 | |
|---|
| 210 | // Daughterboard data |
|---|
| 211 | int rx_db0; |
|---|
| 212 | int rx_db1; |
|---|
| 213 | int tx_db0; |
|---|
| 214 | int tx_db1; |
|---|
| 215 | |
|---|
| 216 | db_base *rx_db0_control; |
|---|
| 217 | db_base *rx_db1_control; |
|---|
| 218 | db_base *tx_db0_control; |
|---|
| 219 | db_base *tx_db1_control; |
|---|
| 220 | |
|---|
| 221 | omni_thread *rx_thread; |
|---|
| 222 | omni_thread *tx_thread; |
|---|
| 223 | |
|---|
| 224 | /// Main RX processing thread |
|---|
| 225 | void rx_data_process(); |
|---|
| 226 | |
|---|
| 227 | /// Main TX processing thread |
|---|
| 228 | void tx_data_process(); |
|---|
| 229 | |
|---|
| 230 | long set_rx_packet_count; |
|---|
| 231 | long rx_packet_count; ///< Number of packets to collect from USRP, -1 is forever |
|---|
| 232 | unsigned int rx_packet_size; ///< Number of samples to send to clients |
|---|
| 233 | unsigned int rx_data_size; ///< Size of words coming from USRP |
|---|
| 234 | unsigned int number_of_channels; |
|---|
| 235 | bool complex; ///< True for complex data from USRP |
|---|
| 236 | unsigned int rx_overruns; |
|---|
| 237 | |
|---|
| 238 | bool rx_active; |
|---|
| 239 | bool tx_active; |
|---|
| 240 | |
|---|
| 241 | }; |
|---|