commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r6380 - in gnuradio/branches/developers/gnychis/inband


From: gnychis
Subject: [Commit-gnuradio] r6380 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps-inband lib/inband
Date: Mon, 10 Sep 2007 10:16:05 -0600 (MDT)

Author: gnychis
Date: 2007-09-10 10:16:05 -0600 (Mon, 10 Sep 2007)
New Revision: 6380

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_overrun.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_rx.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
Log:
Overrun test ready, however there is a memory leak on the RX side that needs to
be found.


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_overrun.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_overrun.cc
       2007-09-10 15:28:43 UTC (rev 6379)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_overrun.cc
       2007-09-10 16:16:05 UTC (rev 6380)
@@ -39,30 +39,11 @@
 #include <iostream>
 #include <fstream>
 
-// Signal set for the USRP server
-static pmt_t s_cmd_allocate_channel = pmt_intern("cmd-allocate-channel");
-static pmt_t s_cmd_close = pmt_intern("cmd-close");
-static pmt_t s_cmd_deallocate_channel = pmt_intern("cmd-deallocate-channel");
-static pmt_t s_cmd_open = pmt_intern("cmd-open");
-static pmt_t s_cmd_start_recv_raw_samples = 
pmt_intern("cmd-start-recv-raw-samples");
-static pmt_t s_cmd_stop_recv_raw_samples = 
pmt_intern("cmd-stop-recv-raw-samples");
-static pmt_t s_cmd_to_control_channel = pmt_intern("cmd-to-control-channel");
-static pmt_t s_cmd_xmit_raw_frame  = pmt_intern("cmd-xmit-raw-frame");
-static pmt_t s_cmd_max_capacity  = pmt_intern("cmd-max-capacity");
-static pmt_t s_cmd_ntx_chan  = pmt_intern("cmd-ntx-chan");
-static pmt_t s_cmd_nrx_chan  = pmt_intern("cmd-nrx-chan");
-static pmt_t s_cmd_current_capacity_allocation  = 
pmt_intern("cmd-current-capacity-allocation");
-static pmt_t s_response_allocate_channel = 
pmt_intern("response-allocate-channel");
-static pmt_t s_response_close = pmt_intern("response-close");
-static pmt_t s_response_deallocate_channel = 
pmt_intern("response-deallocate-channel");
-static pmt_t s_response_from_control_channel = 
pmt_intern("response-from-control-channel");
-static pmt_t s_response_open = pmt_intern("response-open");
-static pmt_t s_response_recv_raw_samples = 
pmt_intern("response-recv-raw-samples");
-static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame");
-static pmt_t s_response_max_capacity = pmt_intern("response-max-capacity");
-static pmt_t s_response_ntx_chan = pmt_intern("response-ntx-chan");
-static pmt_t s_response_nrx_chan = pmt_intern("response-nrx-chan");
-static pmt_t s_response_current_capacity_allocation  = 
pmt_intern("response-current-capacity-allocation");
+// Include the symbols needed for communication with USRP server
+#include <symbols_usrp_server_cs.h>
+#include <symbols_usrp_channel.h>
+#include <symbols_usrp_low_level_cs.h>
+#include <symbols_usrp_rx.h>
 
 static bool verbose = true;
 
@@ -85,6 +66,11 @@
 
   std::ofstream d_ofile;
 
+  long d_n_overruns;
+
+  long d_samples_recvd;
+  long d_samples_to_recv;
+
  public:
   test_usrp_rx(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
   ~test_usrp_rx();
@@ -103,7 +89,10 @@
 };
 
 test_usrp_rx::test_usrp_rx(mb_runtime *runtime, const std::string 
&instance_name, pmt_t user_arg)
-  : mb_mblock(runtime, instance_name, user_arg)
+  : mb_mblock(runtime, instance_name, user_arg),
+    d_n_overruns(0),
+    d_samples_recvd(0),
+    d_samples_to_recv(1e6)
 { 
   
   d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL);
@@ -117,15 +106,10 @@
                pmt_intern("rbf"),
                pmt_intern("nanocell9.rbf"));
 
-  // Set TX and RX interpolations
   pmt_dict_set(usrp_dict,
-               pmt_intern("interp-tx"),
+               pmt_intern("decim-rx"),
                pmt_from_long(128));
 
-  pmt_dict_set(usrp_dict,
-               pmt_intern("decim-rx"),
-               pmt_from_long(16));
-
   define_component("server", "usrp_server", usrp_dict);
 
   connect("self", "rx0", "server", "rx0");
@@ -154,95 +138,120 @@
   std::string error_msg;
   
   switch(d_state){
-  case OPENING_USRP:
-    if (pmt_eq(event, s_response_open)){
-      status = pmt_nth(1, data);
-      if (pmt_eq(status, PMT_T)){
-        allocate_channel();
-        return;
+    
+    //----------------------------- OPENING_USRP ----------------------------//
+    // We only expect a response from opening the USRP which should be 
succesful
+    // or failed.
+    case OPENING_USRP:
+      if (pmt_eq(event, s_response_open)){
+        status = pmt_nth(1, data);
+        if (pmt_eq(status, PMT_T)){
+          allocate_channel();
+          return;
+        }
+        else {
+          error_msg = "failed to open usrp:";
+          goto bail;
+        }
       }
-      else {
-        error_msg = "failed to open usrp:";
-        goto bail;
-      }
-    }
-    goto unhandled;
-    
-  case ALLOCATING_CHANNEL:
-    if (pmt_eq(event, s_response_allocate_channel)){
-      status = pmt_nth(1, data);
-      d_rx_chan = pmt_nth(2, data);
+      goto unhandled;
+      
+    //----------------------- ALLOCATING CHANNELS --------------------//
+    // Allocate an RX channel to perform the overrun test.
+    case ALLOCATING_CHANNEL:
+      if (pmt_eq(event, s_response_allocate_channel)){
+        status = pmt_nth(1, data);
+        d_rx_chan = pmt_nth(2, data);
 
-      if (pmt_eq(status, PMT_T)){
-        enter_receiving();
-        return;
+        if (pmt_eq(status, PMT_T)){
+          enter_receiving();
+          return;
+        }
+        else {
+          error_msg = "failed to allocate channel:";
+          goto bail;
+        }
       }
-      else {
-        error_msg = "failed to allocate channel:";
-        goto bail;
-      }
-    }
-    goto unhandled;
+      goto unhandled;
 
-  case RECEIVING:
-    if (pmt_eq(event, s_response_recv_raw_samples)){
-      status = pmt_nth(1, data);
+    //--------------------------- RECEIVING ------------------------------//
+    // In the receiving state, we receive samples until the specified amount
+    // while counting the number of overruns.
+    case RECEIVING:
+      if (pmt_eq(event, s_response_recv_raw_samples)){
+        status = pmt_nth(1, data);
 
-      if (pmt_eq(status, PMT_T)){
-        handle_response_recv_raw_samples(data);
-        return;
+        if (pmt_eq(status, PMT_T)){
+          handle_response_recv_raw_samples(data);
+          return;
+        }
+        else {
+          error_msg = "bad response-xmit-raw-frame:";
+          goto bail;
+        }
       }
-      else {
-        error_msg = "bad response-xmit-raw-frame:";
-        goto bail;
+      goto unhandled;
+    
+    //------------------------- CLOSING CHANNEL ----------------------------//
+    // Check deallocation response for the RX channel 
+    case CLOSING_CHANNEL:
+      if (pmt_eq(event, s_response_deallocate_channel)){
+        status = pmt_nth(1, data);
+
+        if (pmt_eq(status, PMT_T)){
+          close_usrp();
+          return;
+        }
+        else {
+          error_msg = "failed to deallocate channel:";
+          goto bail;
+        }
       }
-    }
-    goto unhandled;
 
-  case CLOSING_CHANNEL:
-    if (pmt_eq(event, s_response_deallocate_channel)){
-      status = pmt_nth(1, data);
-
-      if (pmt_eq(status, PMT_T)){
-        close_usrp();
+      // Alternately, we ignore all response recv samples while waiting for the
+      // channel to actually close
+      if (pmt_eq(event, s_response_recv_raw_samples))
         return;
-      }
-      else {
-        error_msg = "failed to deallocate channel:";
-        goto bail;
-      }
-    }
-    goto unhandled;
 
-  case CLOSING_USRP:
-    if (pmt_eq(event, s_response_close)){
-      status = pmt_nth(1, data);
+      goto unhandled;
 
-      if (pmt_eq(status, PMT_T)){
-        shutdown_all(PMT_T);
-        return;
+    //--------------------------- CLOSING USRP ------------------------------//
+    // Once we have received a successful USRP close response, we shutdown all
+    // mblocks and exit.
+    case CLOSING_USRP:
+      if (pmt_eq(event, s_response_close)){
+        status = pmt_nth(1, data);
+
+        if (pmt_eq(status, PMT_T)){
+          std::cout << "\nOverruns: " << d_n_overruns << std::endl;
+          fflush(stdout);
+          shutdown_all(PMT_T);
+          return;
+        }
+        else {
+          error_msg = "failed to close USRP:";
+          goto bail;
+        }
       }
-      else {
-        error_msg = "failed to close USRP:";
-        goto bail;
-      }
-    }
-    goto unhandled;
+      goto unhandled;
 
-  default:
-    goto unhandled;
+    default:
+      goto unhandled;
   }
   return;
 
+ // An error occured, print it, and shutdown all m-blocks
  bail:
   std::cerr << error_msg << data
            << "status = " << status << std::endl;
   shutdown_all(PMT_F);
   return;
 
+ // Received an unhandled message for a specific state
  unhandled:
-  std::cout << "test_usrp_inband_rx: unhandled msg: " << msg
-           << "in state "<< d_state << std::endl;
+  if(verbose && !pmt_eq(event, pmt_intern("%shutdown")))
+    std::cout << "test_usrp_inband_tx: unhandled msg: " << msg
+              << "in state "<< d_state << std::endl;
 }
 
 
@@ -253,6 +262,9 @@
 
   d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, which_usrp));
   d_state = OPENING_USRP;
+  
+  if(verbose)
+    std::cout << "[TEST_USRP_INBAND_OVERRUN] Opening the USRP\n";
 }
 
 void
@@ -260,6 +272,9 @@
 {
   d_cs->send(s_cmd_close, pmt_list1(PMT_NIL));
   d_state = CLOSING_USRP;
+  
+  if(verbose)
+    std::cout << "[TEST_USRP_INBAND_OVERRUN] Closing the USRP\n";
 }
 
 void
@@ -268,6 +283,9 @@
   long capacity = (long) 16e6;
   d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, 
pmt_from_long(capacity)));
   d_state = ALLOCATING_CHANNEL;
+  
+  if(verbose)
+    std::cout << "[TEST_USRP_INBAND_OVERRUN] Requesting RX channel 
allocation\n";
 }
 
 void
@@ -278,6 +296,9 @@
   d_rx->send(s_cmd_start_recv_raw_samples,
              pmt_list2(PMT_F,
                        d_rx_chan));
+
+  if(verbose)
+    std::cout << "[TEST_USRP_INBAND_OVERRUN] Receiving...\n";
 }
 
 void
@@ -289,26 +310,40 @@
   pmt_t timestamp = pmt_nth(3, data);
   pmt_t properties = pmt_nth(4, data);
 
-  size_t n_bytes;
-  
-  const char *samples = (const char *) pmt_uniform_vector_elements(v_samples, 
n_bytes);
+  d_samples_recvd += pmt_length(v_samples) / 4;
 
-  if(verbose) {
-    std::cout << ".";
-    fflush(stdout);
+  // Check for overrun
+  if(!pmt_is_dict(properties)) {
+    std::cout << "[TEST_USRP_INBAND_OVERRUN] Recv samples dictionary is 
improper\n";
+    return;
   }
 
-  if (pmt_is_dict(properties)) {
-    // Read the RSSI
-    if(pmt_t rssi = pmt_dict_ref(properties, 
-                                 pmt_intern("rssi"), 
-                                 PMT_NIL)) {
-      if(!pmt_eqv(rssi, PMT_NIL) && verbose && 0) 
-        std::cout << "RSSI: " << rssi << std::endl;
+  if(pmt_t overrun = pmt_dict_ref(properties, 
+                                  pmt_intern("overrun"), 
+                                  PMT_NIL)) {
+    if(pmt_eqv(overrun, PMT_T)) {
+      d_n_overruns++;
+
+      if(verbose && 0)
+        std::cout << "[TEST_USRP_INBAND_OVERRUN] Underrun\n";
     }
+    else {
+    if(verbose && 0)
+      std::cout << "[TEST_USRP_INBAND_OVERRUN] No overrun\n" << overrun 
<<std::endl;
+    }
+  } else {
+
+    if(verbose && 0)
+      std::cout << "[TEST_USRP_INBAND_OVERRUN] No overrun\n";
   }
-  
 
+  // Check if the number samples we have received meets the test
+  if(d_samples_recvd >= d_samples_to_recv) {
+    d_rx->send(s_cmd_stop_recv_raw_samples, pmt_list2(PMT_NIL, d_rx_chan));
+    enter_closing_channel();
+    return;
+  }
+
 }
 
 void
@@ -316,7 +351,12 @@
 {
   d_state = CLOSING_CHANNEL;
   
+  sleep(2);
+  
   d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_NIL, d_rx_chan));
+  
+  if(verbose)
+    std::cout << "[TEST_USRP_INBAND_OVERRUN] Deallocating RX channel\n";
 }
 
 REGISTER_MBLOCK_CLASS(test_usrp_rx);

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_rx.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_rx.cc
    2007-09-10 15:28:43 UTC (rev 6379)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps-inband/test_usrp_inband_rx.cc
    2007-09-10 16:16:05 UTC (rev 6380)
@@ -64,7 +64,7 @@
 static pmt_t s_response_nrx_chan = pmt_intern("response-nrx-chan");
 static pmt_t s_response_current_capacity_allocation  = 
pmt_intern("response-current-capacity-allocation");
 
-static bool verbose = true;
+static bool verbose = false;
 
 class test_usrp_rx : public mb_mblock
 {

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
      2007-09-10 15:28:43 UTC (rev 6379)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
      2007-09-10 16:16:05 UTC (rev 6380)
@@ -53,8 +53,8 @@
   : mb_mblock(rt, instance_name, user_arg),
   d_fpga_debug(false),
   d_fake_usrp(false),
-  d_interp_tx(16),
-  d_decim_rx(16),
+  d_interp_tx(128),
+  d_decim_rx(128),
   d_rf_freq(10e6),
   d_rbf("inband_tx_rx.rbf")
 {





reply via email to

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