commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5635 - gnuradio/branches/developers/eb/ibu/usrp/host/


From: eb
Subject: [Commit-gnuradio] r5635 - gnuradio/branches/developers/eb/ibu/usrp/host/apps
Date: Sun, 3 Jun 2007 09:57:20 -0600 (MDT)

Author: eb
Date: 2007-06-03 09:57:20 -0600 (Sun, 03 Jun 2007)
New Revision: 5635

Modified:
   gnuradio/branches/developers/eb/ibu/usrp/host/apps/test_usrp_inband_tx.cc
Log:
work-in-progress on inband tx test

Modified: 
gnuradio/branches/developers/eb/ibu/usrp/host/apps/test_usrp_inband_tx.cc
===================================================================
--- gnuradio/branches/developers/eb/ibu/usrp/host/apps/test_usrp_inband_tx.cc   
2007-06-03 14:14:56 UTC (rev 5634)
+++ gnuradio/branches/developers/eb/ibu/usrp/host/apps/test_usrp_inband_tx.cc   
2007-06-03 15:57:20 UTC (rev 5635)
@@ -79,10 +79,14 @@
 
   state_t      d_state;
   long         d_nsamples_to_send;
-  long         d_nsamples_transmitted;
+  long         d_nsamples_xmitted;
+  long         d_nframes_xmitted;
+  long         d_samples_per_frame;
+  bool         d_done_sending;
 
   // for generating sine wave output
   ui_nco<float,float>  d_nco;
+  double               d_amplitude;
 
  public:
   test_usrp_tx(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
@@ -97,11 +101,18 @@
   void send_packets();
   void enter_transmitting();
   void build_and_send_next_frame();
+  void handle_xmit_response(pmt_t invocation_handle);
+  void enter_closing_channel();
 };
 
 test_usrp_tx::test_usrp_tx(mb_runtime *runtime, const std::string 
&instance_name, pmt_t user_arg)
   : mb_mblock(runtime, instance_name, user_arg),
-    d_state(INIT), d_nsamples_to_send((long) 40e6), d_nsamples_transmitted(0)
+    d_state(INIT), d_nsamples_to_send((long) 40e6),
+    d_nsamples_xmitted(0),
+    d_nframes_xmitted(0),
+    d_samples_per_frame((long)(126 * 3.5)),    // non-full packet
+    d_done_sending(false),
+    d_amplitude(16384)
 { 
   // std::cout << "[TEST_USRP_TX] Initializing...\n";
   
@@ -123,6 +134,15 @@
 
   connect("self", "tx0", "server", "tx0");
   connect("self", "cs", "server", "cs");
+
+  // initialize NCO
+  double freq = 100e3;
+  int interp = 32;                         // 32 -> 4MS/s
+  double sample_rate = 128e6 / interp; 
+  d_nco.set_freq(2*M_PI * freq/sample_rate);
+
+  // FIXME need to somehow set the interp rate in the USRP.
+  // for now, we'll have the low-level code hardwire it.
 }
 
 test_usrp_tx::~test_usrp_tx()
@@ -140,9 +160,12 @@
 {
   pmt_t        event = msg->signal();
   pmt_t data = msg->data();
+
+  pmt_t handle = PMT_F;
   pmt_t status = PMT_F;
+  std::string error_msg;
   
-  std::cout << msg << std::endl;
+  // std::cout << msg << std::endl;
 
   switch(d_state){
   case OPENING_USRP:
@@ -153,10 +176,8 @@
        return;
       }
       else {
-       std::cerr << "failed to open usrp:" << data
-                 << "status = " << status << std::endl;
-       shutdown_all(PMT_F);
-       return;
+       error_msg = "failed to open usrp:";
+       goto bail;
       }
     }
     goto unhandled;
@@ -171,15 +192,28 @@
        return;
       }
       else {
-       std::cerr << "failed to allocate channel:" 
-                 << "status = " << status << std::endl;
-       shutdown_all(PMT_F);
+       error_msg = "failed to allocate channel:";
+       goto bail;
+      }
+    }
+    goto unhandled;
+
+  case TRANSMITTING:
+    if (pmt_eq(event, s_response_xmit_raw_frame)){
+      handle = pmt_nth(0, data);
+      status = pmt_nth(1, data);
+
+      if (pmt_eq(status, PMT_T)){
+       handle_xmit_response(handle);
        return;
       }
+      else {
+       error_msg = "bad response-xmit-raw-frame:";
+       goto bail;
+      }
     }
     goto unhandled;
 
-  case TRANSMITTING:
   case CLOSING_CHANNEL:
   case CLOSING_USRP:
   default:
@@ -187,6 +221,12 @@
   }
   return;
 
+ bail:
+  std::cerr << error_msg << data
+           << "status = " << status << std::endl;
+  shutdown_all(PMT_F);
+  return;
+
  unhandled:
   std::cout << "test_usrp_inband_tx: unhandled msg: " << msg
            << "in state "<< d_state << std::endl;
@@ -221,14 +261,78 @@
 test_usrp_tx::enter_transmitting()
 {
   d_state = TRANSMITTING;
-  d_nsamples_transmitted = 0;
+  d_nsamples_xmitted = 0;
+
+  build_and_send_next_frame(); // fire off 4 to start pipeline
   build_and_send_next_frame();
+  build_and_send_next_frame();
+  build_and_send_next_frame();
 }
 
 void
 test_usrp_tx::build_and_send_next_frame()
 {
+  // allocate the uniform vector for the samples
+  // FIXME perhaps hold on to this between calls
+
+  long nsamples_this_frame =
+    std::min(d_nsamples_to_send - d_nsamples_xmitted,
+            d_samples_per_frame);
+
+  if (nsamples_this_frame == 0){
+    d_done_sending = true;
+    return;
+  }
+    
+
+  size_t nshorts = 2 * nsamples_this_frame;    // 16-bit I & Q
+  pmt_t uvec = pmt_make_s16vector(nshorts, 0);
+  size_t ignore;
+  int16_t *samples = pmt_s16vector_writeable_elements(uvec, ignore);
+
+  // fill in the complex sinusoid
+
+  for (int i = 0; i < nsamples_this_frame; i++){
+    gr_complex s;
+    d_nco.sincos(&s, 1, d_amplitude);
+    // write 16-bit I & Q
+    samples[2*i] =   (int16_t) s.real();
+    samples[2*i+1] = (int16_t) s.imag();
+  }
+
+  pmt_t timestamp = pmt_from_long(0xffffffff); // NOW
+  d_tx->send(s_cmd_xmit_raw_frame,
+            pmt_list4(pmt_from_long(d_nframes_xmitted),  // invocation-handle
+                      d_tx_chan,                         // channel
+                      uvec,                              // the samples
+                      timestamp));
+
+  d_nsamples_xmitted += nsamples_this_frame;
+  d_nframes_xmitted++;
+}
+
+
+void
+test_usrp_tx::handle_xmit_response(pmt_t handle)
+{
+  if (d_done_sending &&
+      pmt_to_long(handle) == (d_nframes_xmitted - 1)){
+    // We're done sending and have received all responses
+    enter_closing_channel();
+  }
+
+  build_and_send_next_frame();
+}
+
+void
+test_usrp_tx::enter_closing_channel()
+{
+  d_state = CLOSING_CHANNEL;
+  std::cout << "enter_closing_channel\n";
+  
   // FIXME
+
+  shutdown_all(PMT_T);
 }
 
 





reply via email to

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