four_multi
Multi-Antenna,Multi-Node,Multi-Band,Multi-Cell
core/four_multi.hpp
00001 // Copyright 2011-2013, Per Zetterberg, KTH Royal Institute of Technology
00002 //
00003 // This program is free software: you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation, either version 3 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
00015 //
00016 
00017 #ifndef FOUR_MULTI_HPP
00018 #define FOUR_MULTI_HPP
00019 
00020 
00021 #include <iostream>
00022 #include <complex>
00023 #include <uhd/types/clock_config.hpp>
00024 #include "gps.hpp"
00025 #include "simulator.hpp"
00026 #include <boost/thread/thread.hpp>
00027 
00028   
00029 namespace po = boost::program_options;
00030 using namespace boost;
00031 
00032 
00039 enum burst_t {TX=0,RX=1,START=2,END=3,
00040               CALIB_TXRX=4,CALIB_RXTX=5,CALIB_RXRX=6,CALIB_TXTX=7};
00041 
00042 #define IS_CALIB_BURST(x) (x.what>3)
00043 
00044 
00046 struct frame_settings {
00050   std::vector<double> frequency;
00054   std::vector<double> gain_rx;
00058   std::vector<double> gain_tx;
00061   uhd::time_spec_t time;
00063   burst_t what;
00067   uint32_t small_buffer_length;
00068   uint32_t tx_repeats;
00069 
00070 
00071   frame_settings(void) { small_buffer_length=0;tx_repeats=0;};
00072 };
00073 
00074 
00082 class four_multi_node { 
00083   friend void simulate(std::vector<four_multi_node*> *nodes,channel_model *c);
00084   friend class super_node;
00085  private: friend class node_process_class;
00086   
00087  
00088   class usrp_thread_function_class;
00089   
00090   class udp_function_thread_class;
00091 
00092   public:
00093 
00107     void run(void);
00108     void run(const char* device_name, uint32_t gps_time_combined);
00109 
00110 
00131     four_multi_node(uint32_t buffer_length, uint32_t no_ant1, uint32_t no_ant2, bool use_external_10MHz,bool same_antenna,
00132                        uint32_t node_ix, std::vector<std::string> IP_addresses,
00133                bool simulate,uint32_t skip_ant);
00134 
00135 
00136 
00137 
00139    uint32_t node_ix(void){return d_node_ix;};
00140 
00158   void save_raw_input_on_file(uint32_t max_no_frames_to_save,std::string direcory_name="/usr/local/meas_data/");
00159 
00161   void dont_save_raw_input_on_file(void);
00162 
00164   double wait_time_for_transmissions_to_finish; 
00167   bool set_time_on_pps;
00168   
00171   bool skip_hw_set_during_init;
00172 
00173   bool use_udp;
00177    protected:
00178   
00188    void x2_tx(uint32_t other_node_ix ,const void *pointer_to_data, 
00189                 uint32_t num_bytes);
00190 
00197    void x2_tx_udp(uint32_t other_node_ix ,const void *pointer_to_data, 
00198                 uint32_t num_bytes);
00199 
00207    void x2_tx_tcp(uint32_t other_node_ix ,const void *  pointer_to_data, 
00208                 uint32_t num_bytes);
00209 
00210 
00221    void x2_rx(uint32_t other_node_ix ,void  * const pointer_to_data, 
00222                 uint32_t num_bytes);
00223  
00230    void x2_rx(std::vector<uint32_t> other_node_ixs ,
00231               std::vector<void  *> const pointers_to_data,  
00232 std::vector<uint32_t> num_bytess);
00233 
00234 
00241    void x2_rx_tcp(uint32_t other_node_ix ,void  * const pointer_to_data, 
00242                 uint32_t num_bytes);
00243 
00250    void x2_rx_udp(uint32_t other_node_ix ,void  * const pointer_to_data, 
00251                 uint32_t num_bytes);
00252 
00253 
00261    void x2_rx_tcp(std::vector<uint32_t> other_node_ixs ,std::vector<void  *>
00262 const pointers_to_data,  std::vector<uint32_t> num_bytess);
00263 
00264 
00272    void x2_rx_udp(std::vector<uint32_t> other_node_ixs ,std::vector<void  *> 
00273 const pointers_to_data, 
00274              std::vector<uint32_t> num_bytess);
00275 
00276 
00289     virtual frame_settings node_process(void)=0;  
00296     virtual frame_settings node_init(void)=0;
00297 
00300     virtual void end_of_run(void)=0;
00301   
00302   
00303   
00304 
00305 
00306     uint32_t d_buffer_length, d_no_ant1, d_no_ant2, d_no_ant;
00307     uint32_t d_node_ix, d_skip_ant;
00308 
00309     bool save_input_on_file;
00310     std::string raw_data_dir;
00311     uint32_t no_rx_buffer_stored_so_far, d_max_no_frames_to_save;
00312     void save_logged_raw_data(void);
00313     void log_raw_buffer(uint32_t number_of_samples);
00314 
00315 
00316     void set_trx_params(frame_settings fs_new, frame_settings fs_old);
00317     void set_trx_params(frame_settings fs); 
00318 
00319 
00320     usrp_thread_function_class *m1;
00321     usrp_thread_function_class *m2;
00322 
00323 
00324   /*
00325     void init(uint32_t buffer_length,uint32_t no_ant1, uint32_t no_ant2 , bool use_external_10MHz,
00326               bool use_same_antenna,uint32_t node_ix, 
00327               std::vector<std::string> IP_addresses,bool simulate);
00328   */
00329     void init(uint32_t buffer_length);
00330 
00331 
00332 
00333     std::vector<std::string> d_IP_addresses;
00334     std::string d_args;
00335     
00336     double d_rate;
00337     static const time_t time_available_for_trigger=1; // Seconds
00338     static const time_t headroom_after_trigger=1; // Seconds
00339     
00340 
00341     bool d_use_external_10MHz;
00342     bool d_use_same_antenna;
00343 
00344     bool d_simulate;     //Is this a simulation run ?
00345     void **feedback_buffers;  // Used in simulator only
00346     bool *feedback_buffers_empty;  // Used in the simulator only
00347     uint32_t num_nodes; // Used in the simulator only
00348     bool never_run;  // run method never called.
00349 
00350     void *feedback_buffer_simulate;
00351 
00352     frame_settings d_old_frame_settings;
00353 
00354     //std::vector<const void *> d_tx_buffers;
00355     
00356     std::vector<void *> d_tx_buffers;
00357     std::vector<void *> d_rx_buffers;
00358     std::vector<void *> d_rx_storage_buffers;
00359 
00360    private:
00361   
00362   //void change_buffer_length(uint32_t new_buffer_length);
00364    four_multi_node(uint32_t no_ant1, uint32_t no_ant2, bool use_external_10MHz,bool same_antenna,
00365                        uint32_t node_ix, std::vector<std::string> IP_addresses,
00366                bool simulate,uint32_t skip_ant);
00367 
00368    
00369 } ;
00370 
00371 
00372 
00373 
00374 #endif
 All Classes Functions Variables