Changeset 8984

Show
Ignore:
Timestamp:
07/23/08 13:04:52
Author:
gnychis
Message:

adding in ability to read USRP data from file rather than a sine

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.cc

    r8436 r8984  
    5656    d_decim_rx(128), 
    5757    d_amplitude(16384), 
    58     d_disk_write(false) 
     58    d_disk_write(false), 
     59    d_data_from_file(false) 
    5960{ 
    6061 
     
    6566 
    6667  if (pmt_is_dict(usrp_dict)) { 
     68     
    6769    // Read the RX decimation rate 
    6870    if(pmt_t decim_rx = pmt_dict_ref(usrp_dict,  
     
    7274        d_decim_rx = pmt_to_long(decim_rx); 
    7375    } 
     76 
     77    // In case the user wants the data from the USRP to be a packet dump, 
     78    // specified as a file name 
     79    if(pmt_t rx_data = pmt_dict_ref(usrp_dict, 
     80                                      pmt_intern("fake-rx-data"), 
     81                                      PMT_NIL)) { 
     82      if(!pmt_eqv(rx_data, PMT_NIL)) { 
     83        std::string fname = pmt_symbol_to_string(rx_data); 
     84        d_rx_data.open(fname.c_str(),std::ios::binary|std::ios::in); 
     85        if(!d_rx_data.is_open()) { 
     86          std::cerr << "[USRP_RX_STUB] RX data file " << fname 
     87                    << " could not be opened\n"; 
     88          shutdown_all(PMT_F); 
     89        } 
     90        d_data_from_file = true; 
     91      } 
     92    } 
    7493  } 
    7594 
     
    94113  if(d_disk_write) 
    95114    d_ofile.close(); 
     115  if(d_data_from_file) 
     116    d_rx_data.close(); 
    96117} 
    97118 
     
    111132      && !pmt_eq(msg->data(), s_done)) { 
    112133   
    113     if(!usrp_rx_stop_stub)  
    114       read_and_respond(); 
    115     else {  // requested to stop 
     134    if(!usrp_rx_stop_stub) { 
     135      if(d_data_from_file) 
     136        read_and_respond_file(); 
     137      else 
     138        read_and_respond_sine(); 
     139      check_cs_queue(); 
     140    } else {  // requested to stop 
    116141      cancel_timeout(msg->metadata()); 
    117142      usrp_rx_stop_stub=false; 
     
    157182 
    158183void 
    159 usrp_rx_stub::read_and_respond() 
     184usrp_rx_stub::read_and_respond_sine() 
    160185{ 
    161186 
     
    208233   
    209234  d_cs->send(s_response_usrp_rx_read, pmt_list3(PMT_NIL, PMT_T, v_pkt)); 
    210  
    211   // Now lets check the shared CS queue between the TX and RX stub.  Each 
    212   // element in a queue is a list where the first element is an invocation 
    213   // handle and the second element is a PMT u8 vect representation of the 
    214   // CS packet response which can just be passed transparently. 
     235
     236 
     237void 
     238usrp_rx_stub::read_and_respond_file() 
     239
     240   
     241  size_t ignore; 
     242  bool underrun; 
     243  unsigned int n_read; 
     244  unsigned int pkt_size = sizeof(transport_pkt); 
     245 
     246  pmt_t v_pkt = pmt_make_u8vector(pkt_size, 0); 
     247  transport_pkt *pkt =  
     248    (transport_pkt *) pmt_u8vector_writable_elements(v_pkt, ignore); 
     249 
     250  if(d_rx_data.eof()) { 
     251    std::cerr << "[USRP_RX_STUB] End of RX data file\n"; 
     252    d_rx_data.close(); 
     253    shutdown_all(PMT_T); 
     254  } 
     255 
     256  d_rx_data.read((char *)pkt, pkt_size); 
     257 
     258  d_cs->send(s_response_usrp_rx_read,  
     259             pmt_list3(PMT_NIL, PMT_T, v_pkt)); 
     260
     261 
     262// Now lets check the shared CS queue between the TX and RX stub.  Each 
     263// element in a queue is a list where the first element is an invocation 
     264// handle and the second element is a PMT u8 vect representation of the 
     265// CS packet response which can just be passed transparently. 
     266void 
     267usrp_rx_stub::check_cs_queue() 
     268
    215269  while(!d_cs_queue.empty()) { 
    216270     
     
    225279                         PMT_T,  
    226280                         v_pkt));  // Take the front CS pkt 
    227  
    228281     
    229282    if(verbose) 
    230283      std::cout << "[USRP_RX_STUB] Received CS response from TX stub\n"; 
    231284  } 
    232  
    233285} 
    234286 
  • gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.h

    r8436 r8984  
    6262 
    6363  std::ofstream d_ofile; 
     64 
     65  bool d_data_from_file; 
     66  std::ifstream d_rx_data; 
    6467   
    6568 public: 
     
    7073 
    7174 private: 
    72   void read_and_respond(); 
     75  void read_and_respond_file(); 
     76  void read_and_respond_sine(); 
     77  void check_cs_queue(); 
    7378  void read_data(); 
    7479  void start_packet_timer();