commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r8984 - gnuradio/branches/developers/gnychis/inband/us


From: gnychis
Subject: [Commit-gnuradio] r8984 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Wed, 23 Jul 2008 13:04:53 -0600 (MDT)

Author: gnychis
Date: 2008-07-23 13:04:52 -0600 (Wed, 23 Jul 2008)
New Revision: 8984

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.h
Log:
adding in ability to read USRP data from file rather than a sine

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.cc
    2008-07-23 01:27:48 UTC (rev 8983)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.cc
    2008-07-23 19:04:52 UTC (rev 8984)
@@ -55,7 +55,8 @@
     d_samples_per_frame((long)(126)),
     d_decim_rx(128),
     d_amplitude(16384),
-    d_disk_write(false)
+    d_disk_write(false),
+    d_data_from_file(false)
 {
 
   // Information about the rates are passed all the way from the app in the 
form
@@ -64,6 +65,7 @@
   pmt_t usrp_dict = user_arg;
 
   if (pmt_is_dict(usrp_dict)) {
+    
     // Read the RX decimation rate
     if(pmt_t decim_rx = pmt_dict_ref(usrp_dict, 
                                       pmt_intern("decim-rx"), 
@@ -71,6 +73,23 @@
       if(!pmt_eqv(decim_rx, PMT_NIL)) 
         d_decim_rx = pmt_to_long(decim_rx);
     }
+
+    // In case the user wants the data from the USRP to be a packet dump,
+    // specified as a file name
+    if(pmt_t rx_data = pmt_dict_ref(usrp_dict,
+                                      pmt_intern("fake-rx-data"),
+                                      PMT_NIL)) {
+      if(!pmt_eqv(rx_data, PMT_NIL)) {
+        std::string fname = pmt_symbol_to_string(rx_data);
+        d_rx_data.open(fname.c_str(),std::ios::binary|std::ios::in);
+        if(!d_rx_data.is_open()) {
+          std::cerr << "[USRP_RX_STUB] RX data file " << fname
+                    << " could not be opened\n";
+          shutdown_all(PMT_F);
+        }
+        d_data_from_file = true;
+      }
+    }
   }
 
   d_cs = define_port("cs", "usrp-rx-cs", true, mb_port::EXTERNAL);
@@ -93,6 +112,8 @@
 {
   if(d_disk_write)
     d_ofile.close();
+  if(d_data_from_file)
+    d_rx_data.close();
 }
 
 void 
@@ -110,9 +131,13 @@
   if (pmt_eq(msg->signal(), s_timeout)
       && !pmt_eq(msg->data(), s_done)) {
   
-    if(!usrp_rx_stop_stub) 
-      read_and_respond();
-    else {  // requested to stop
+    if(!usrp_rx_stop_stub) {
+      if(d_data_from_file)
+        read_and_respond_file();
+      else
+        read_and_respond_sine();
+      check_cs_queue();
+    } else {  // requested to stop
       cancel_timeout(msg->metadata());
       usrp_rx_stop_stub=false;
       if(verbose)
@@ -156,7 +181,7 @@
 }
 
 void
-usrp_rx_stub::read_and_respond()
+usrp_rx_stub::read_and_respond_sine()
 {
 
   long nsamples_this_frame = d_samples_per_frame;
@@ -207,11 +232,40 @@
 
   
   d_cs->send(s_response_usrp_rx_read, pmt_list3(PMT_NIL, PMT_T, v_pkt));
+}
 
-  // Now lets check the shared CS queue between the TX and RX stub.  Each
-  // element in a queue is a list where the first element is an invocation
-  // handle and the second element is a PMT u8 vect representation of the
-  // CS packet response which can just be passed transparently.
+void
+usrp_rx_stub::read_and_respond_file()
+{
+  
+  size_t ignore;
+  bool underrun;
+  unsigned int n_read;
+  unsigned int pkt_size = sizeof(transport_pkt);
+
+  pmt_t v_pkt = pmt_make_u8vector(pkt_size, 0);
+  transport_pkt *pkt = 
+    (transport_pkt *) pmt_u8vector_writable_elements(v_pkt, ignore);
+
+  if(d_rx_data.eof()) {
+    std::cerr << "[USRP_RX_STUB] End of RX data file\n";
+    d_rx_data.close();
+    shutdown_all(PMT_T);
+  }
+
+  d_rx_data.read((char *)pkt, pkt_size);
+
+  d_cs->send(s_response_usrp_rx_read, 
+             pmt_list3(PMT_NIL, PMT_T, v_pkt));
+}
+
+// Now lets check the shared CS queue between the TX and RX stub.  Each
+// element in a queue is a list where the first element is an invocation
+// handle and the second element is a PMT u8 vect representation of the
+// CS packet response which can just be passed transparently.
+void
+usrp_rx_stub::check_cs_queue()
+{
   while(!d_cs_queue.empty()) {
     
     pmt_t cs_pkt = d_cs_queue.front();
@@ -224,12 +278,10 @@
                pmt_list3(invocation_handle, 
                          PMT_T, 
                          v_pkt));  // Take the front CS pkt
-
     
     if(verbose)
       std::cout << "[USRP_RX_STUB] Received CS response from TX stub\n";
   }
-
 }
 
 REGISTER_MBLOCK_CLASS(usrp_rx_stub);

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.h 
    2008-07-23 01:27:48 UTC (rev 8983)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx_stub.h 
    2008-07-23 19:04:52 UTC (rev 8984)
@@ -61,6 +61,9 @@
   bool d_disk_write;
 
   std::ofstream d_ofile;
+
+  bool d_data_from_file;
+  std::ifstream d_rx_data;
   
  public:
   usrp_rx_stub(mb_runtime *rt, const std::string &instance_name, pmt_t 
user_arg);
@@ -69,7 +72,9 @@
   void handle_message(mb_message_sptr msg);
 
  private:
-  void read_and_respond();
+  void read_and_respond_file();
+  void read_and_respond_sine();
+  void check_cs_queue();
   void read_data();
   void start_packet_timer();
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]