commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r5609 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Sat, 2 Jun 2007 14:20:54 -0600 (MDT)

Author: gnychis
Date: 2007-06-02 14:20:54 -0600 (Sat, 02 Jun 2007)
New Revision: 5609

Modified:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/test_usrp_inband.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.mbh
   
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_stub.cc
Log:
Checking in new automated test cases with USRP stub.

Have a temporarily working "defer" mechanism for usrp_server until it is built 
in to the m-block.

Summary of new cases under 'basics':
  - messages are not lost when there is a delay opening the USRP, they are 
queued
  - xmit fails before an open request
  - xmit successful after open with stub
  - xmit fails after close
  - trying to open when already open fails
  - close when already closed (or never opened) fails


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   2007-06-02 20:20:54 UTC (rev 5609)
@@ -40,6 +40,8 @@
 
 static pmt_t s_cmd_open = pmt_intern("cmd-open");
 static pmt_t s_response_open = pmt_intern("response-open");
+static pmt_t s_cmd_close = pmt_intern("cmd-close");
+static pmt_t s_response_close = pmt_intern("response-close");
 static pmt_t s_cmd_allocate_channel = pmt_intern("cmd-allocate-channel");
 static pmt_t s_response_allocate_channel = 
pmt_intern("response-allocate-channel");
 static pmt_t s_send_allocate_channel = pmt_intern("send-allocate-channel");
@@ -91,14 +93,18 @@
   d_nrecvd=0;
   d_nmsgs_to_recv = 7;
   d_nstatus=0;
-  d_nstatus_to_recv = 3;
+  d_nstatus_to_recv = 4;
   
   d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL);
   d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
   d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
+ 
+  // Use the stub with the usrp_server
+  pmt_t usrp_server_dict = pmt_make_dict();
+  pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"), 
pmt_intern("usrp_usb_interface_stub"));
 
   // Test the TX side
-  define_component("server", "usrp_server", PMT_NIL);
+  define_component("server", "usrp_server", pmt_list1(usrp_server_dict));
   connect("self", "tx0", "server", "tx0");
   connect("self", "rx0", "server", "rx0");
   connect("self", "cs", "server", "cs");
@@ -111,6 +117,7 @@
 qa_alloc_top::initial_transition()
 {
   // Retrieve information about the USRP, then run tests
+  d_cs->send(s_cmd_open, pmt_list2(PMT_T, pmt_from_long(0)));
   d_cs->send(s_cmd_max_capacity, pmt_list1(PMT_F));
   d_cs->send(s_cmd_ntx_chan, pmt_list1(PMT_F));
   d_cs->send(s_cmd_nrx_chan, pmt_list1(PMT_F));
@@ -251,14 +258,18 @@
   d_nalloc_recvd=0;
   d_nalloc_to_recv = 0;
   d_nstatus=0;
-  d_nstatus_to_recv = 3;
+  d_nstatus_to_recv = 4;
   
   d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL);
   d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
   d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
 
+  // Use the stub with the usrp_server
+  pmt_t usrp_server_dict = pmt_make_dict();
+  pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"), 
pmt_intern("usrp_usb_interface_stub"));
+
   // Test the TX side
-  define_component("server", "usrp_server", PMT_NIL);
+  define_component("server", "usrp_server", pmt_list1(usrp_server_dict));
   connect("self", "tx0", "server", "tx0");
   connect("self", "rx0", "server", "rx0");
   connect("self", "cs", "server", "cs");
@@ -270,6 +281,7 @@
 qa_dealloc_top::initial_transition()
 {
   // Retrieve information about the USRP, then run tests
+  d_cs->send(s_cmd_open, pmt_list2(PMT_T, pmt_from_long(0)));
   d_cs->send(s_cmd_max_capacity, pmt_list1(PMT_F));
   d_cs->send(s_cmd_ntx_chan, pmt_list1(PMT_F));
   d_cs->send(s_cmd_nrx_chan, pmt_list1(PMT_F));
@@ -442,18 +454,12 @@
   long d_max_capacity;
   long d_ntx_chan, d_nrx_chan;
 
-  long d_nstatus;
-  long d_nstatus_to_recv;
+  long d_tx_chan;
+  long d_rx_chan;
 
-  long d_nalloc_to_recv;
-  long d_nalloc_recvd;
+  long d_nmsg_to_recv;
+  long d_nmsg_recvd;
 
-  long d_ndealloc_to_recv;
-  long d_ndealloc_recvd;
-
-  std::vector<long> d_tx_chans;
-  std::vector<long> d_rx_chans;
-
  public:
   qa_basic_top(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
   ~qa_basic_top();
@@ -463,26 +469,28 @@
  protected:
   void check_allocation(mb_message_sptr msg);
   void check_deallocation(mb_message_sptr msg);
-  void allocate_max();
-  void deallocate_all();
+  void check_xmit(mb_message_sptr msg);
+  void check_cs(mb_message_sptr msg);
+  void run_tests();
 };
 
 qa_basic_top::qa_basic_top(mb_runtime *runtime, const std::string 
&instance_name, pmt_t user_arg)
   : mb_mblock(runtime, instance_name, user_arg)
 { 
-  d_ndealloc_recvd=0;
-  d_ndealloc_to_recv = 0;
-  d_nalloc_recvd=0;
-  d_nalloc_to_recv = 0;
-  d_nstatus=0;
-  d_nstatus_to_recv = 3;
+
+  d_nmsg_to_recv=14;
+  d_nmsg_recvd=0;
   
   d_rx = define_port("rx0", "usrp-rx", false, mb_port::INTERNAL);
   d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
   d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
 
+  // Use the stub with the usrp_server
+  pmt_t usrp_server_dict = pmt_make_dict();
+  pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"), 
pmt_intern("usrp_usb_interface_stub"));
+
   // Test the TX side
-  define_component("server", "usrp_server", PMT_NIL);
+  define_component("server", "usrp_server", pmt_list1(usrp_server_dict));
   connect("self", "tx0", "server", "tx0");
   connect("self", "rx0", "server", "rx0");
   connect("self", "cs", "server", "cs");
@@ -493,109 +501,70 @@
 void
 qa_basic_top::initial_transition()
 {
-  // Retrieve information about the USRP, then run tests
-  d_cs->send(s_cmd_max_capacity, pmt_list1(PMT_F));
-  d_cs->send(s_cmd_ntx_chan, pmt_list1(PMT_F));
-  d_cs->send(s_cmd_nrx_chan, pmt_list1(PMT_F));
+  run_tests();
 }
 
 void
-qa_basic_top::allocate_max()
+qa_basic_top::run_tests()
 {
-  std::cout << "[qa_basic_top] Max allocating...\n";
+  std::cout << "[qa_basic_top] Starting tests\n";
 
-  // Keep allocating until we hit the maximum number of channels
-  for(int i=0; i < d_ntx_chan; i++) {
-    d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
-    d_nalloc_to_recv++;
-  }
-  for(int i=0; i < d_nrx_chan; i++) {
-    d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
-    d_nalloc_to_recv++;
-  }
-}
+  // Should not be able to allocate an RX or TX until opened
+  d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_F, pmt_from_long(1)));
+  d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_F, pmt_from_long(1)));
 
-void
-qa_basic_top::deallocate_all() {
+  // A transmit before an open should fail
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(PMT_F, pmt_from_long(0), 
pmt_make_u32vector(transport_pkt::max_payload()/4, 0), pmt_from_long(0)));
   
-  // Deallocate all of the channels that were allocated from allocate_max()
-  for(int i=0; i < (int)d_tx_chans.size(); i++) {
-    d_tx->send(s_cmd_deallocate_channel, pmt_list2(PMT_T, 
pmt_from_long(d_tx_chans[i])));
-    d_ndealloc_to_recv++;
-  }
-  for(int i=0; i < (int)d_rx_chans.size(); i++) {
-    d_rx->send(s_cmd_deallocate_channel, pmt_list2(PMT_T, 
pmt_from_long(d_rx_chans[i])));
-    d_ndealloc_to_recv++;
-  }
+  // Open, and now try an xmit again which should be successful
+  d_cs->send(s_cmd_open, pmt_list2(PMT_T, pmt_from_long(0)));
+  d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
+  d_rx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
 
-  // Should get permission denied errors trying to re-dealloc the channels, as 
we no
-  // longer have permission to them after deallocating
-  for(int i=0; i < (int)d_tx_chans.size(); i++) {
-    d_tx->send(s_cmd_deallocate_channel, 
pmt_list2(pmt_from_long(usrp_server::PERMISSION_DENIED), 
pmt_from_long(d_tx_chans[i])));
-    d_ndealloc_to_recv++;
-  }
-  for(int i=0; i < (int)d_rx_chans.size(); i++) {
-    d_rx->send(s_cmd_deallocate_channel, 
pmt_list2(pmt_from_long(usrp_server::PERMISSION_DENIED), 
pmt_from_long(d_rx_chans[i])));
-    d_ndealloc_to_recv++;
-  }
+  // To simplify the test case, we know that the returned channels are 0, when 
we have defer implemented we can avoid this easier
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(PMT_T, pmt_from_long(0), 
pmt_make_u32vector(transport_pkt::max_payload()/4, 0), pmt_from_long(0)));
 
-  // Try to deallocate a channel that doesn't exist on both sides, the last 
element in the vectors
-  // is the highest channel number, so we take that plus 1
-  d_ndealloc_to_recv+=2;
-  d_tx->send(s_cmd_deallocate_channel, 
pmt_list2(pmt_from_long(usrp_server::CHANNEL_INVALID), 
pmt_from_long(d_rx_chans.back()+1)));
-  d_rx->send(s_cmd_deallocate_channel, 
pmt_list2(pmt_from_long(usrp_server::CHANNEL_INVALID), 
pmt_from_long(d_rx_chans.back()+1)));
+  // Close should be successful
+  d_cs->send(s_cmd_close, pmt_list1(PMT_T));
 
+  // After closing, a new allocate and transmit raw frame should fail again.  
It should also be deferred
+  d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_F, pmt_from_long(1)));
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(PMT_F, pmt_from_long(d_tx_chan), 
pmt_make_u32vector(transport_pkt::max_payload()/4, 0), pmt_from_long(0)));
 
-  // The used capacity should be back to 0 now that we've deallocated 
everything
-  d_cs->send(s_cmd_current_capacity_allocation, pmt_list1(pmt_from_long(0)));
+  // Reopen and retry
+  d_cs->send(s_cmd_open, pmt_list2(PMT_T, pmt_from_long(0)));
+  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(PMT_T, pmt_from_long(d_tx_chan), 
pmt_make_u32vector(transport_pkt::max_payload()/4, 0), pmt_from_long(0)));
+
+  // A final close which should be successful, with a failing close (can't 
close it twice)
+  d_cs->send(s_cmd_close, pmt_list1(PMT_T));
+  d_cs->send(s_cmd_close, pmt_list1(PMT_F));
+  
 }
 
+
 void
 qa_basic_top::handle_message(mb_message_sptr msg)
 {
   pmt_t data = msg->data();
+
   if (pmt_eq(msg->port_id(), d_tx->port_symbol())
        || pmt_eq(msg->port_id(), d_rx->port_symbol())) {
     
-    if(pmt_eq(msg->signal(), s_response_allocate_channel)) {
+    if(pmt_eq(msg->signal(), s_response_allocate_channel)) 
       check_allocation(msg);
-    }
     
-    if(pmt_eq(msg->signal(), s_response_deallocate_channel)){
-      check_deallocation(msg);
-    }
+    if(pmt_eq(msg->signal(), s_response_xmit_raw_frame)) 
+      check_xmit(msg);
   }
   
   if (pmt_eq(msg->port_id(), d_cs->port_symbol())) {
-      
-    if(pmt_eq(msg->signal(), s_response_max_capacity)) {
-      d_max_capacity = pmt_to_long(pmt_nth(1, data));
-      std::cout << "[qa_basic_top] USRP has max capacity of " << 
d_max_capacity << "\n";
-    }
-    else if(pmt_eq(msg->signal(), s_response_ntx_chan)) {
-      d_ntx_chan = pmt_to_long(pmt_nth(1, data));
-      std::cout << "[qa_basic_top] USRP tx channels: " << d_ntx_chan << "\n";
-    }
-    else if(pmt_eq(msg->signal(), s_response_nrx_chan)) {
-      d_nrx_chan = pmt_to_long(pmt_nth(1, data));
-      std::cout << "[qa_basic_top] USRP rx channels: " << d_nrx_chan << "\n";
-    }
-    else if(pmt_eq(msg->signal(), s_response_current_capacity_allocation)) {
-      // the final command is a capacity check which should be 0, then we 
shutdown
-      pmt_t expected_result = pmt_nth(0, data);
-      pmt_t result = pmt_nth(1, data);
+      check_cs(msg);
+  }
 
-      if(pmt_eqv(expected_result, result))
-        shutdown_all(PMT_T);
-      else
-        shutdown_all(PMT_F);
-    }
-    
-    d_nstatus++;
+  d_nmsg_recvd++;
 
-    if(d_nstatus==d_nstatus_to_recv)
-      allocate_max();
-  }
+  if(d_nmsg_to_recv == d_nmsg_recvd)
+    shutdown_all(PMT_T);
 }
 
 void
@@ -606,13 +575,11 @@
   pmt_t expected_result = pmt_nth(0, data);
   pmt_t result = pmt_nth(1, data);
 
-  d_ndealloc_recvd++;
-
   if(!pmt_eqv(expected_result, result)) {
-    std::cout << "Got: " << result << " Expected: " << expected_result << "\n";
+    std::cout << "[qa_basic_top] FAILED check_deallocation... Got: " << result 
<< " Expected: " << expected_result << "\n";
     shutdown_all(PMT_F);
   } else {
-    std::cout << "[qa_basic_top] Received expected deallocation response for 
message " << d_ndealloc_recvd << "\n";
+    std::cout << "[qa_basic_top] Received expected deallocation response for 
message\n";
   }
 }
 
@@ -621,36 +588,57 @@
 {
   pmt_t data = msg->data();
 
-  pmt_t invocation_handle = pmt_nth(0, data);
-  pmt_t status = pmt_nth(1, data);
+  pmt_t expected_result = pmt_nth(0, data);
+  pmt_t result = pmt_nth(1, data);
   pmt_t channel = pmt_nth(2, data);
   
-  d_nalloc_recvd++;
-
-  if(pmt_eqv(status, PMT_F)) {
-    std::cout << "[qa_basic_top] Unexpected error response when allocating 
channels\n";
+  if(!pmt_eqv(expected_result, result)) {
+    std::cout << "[qa_basic_top] FAILED check_allocation... Got: " << result 
<< " Expected: " << expected_result << " for event " << msg->signal() << ")\n";
     shutdown_all(PMT_F);
   } else {
+    std::cout << "[qa_basic_top] Received expected allocation response for 
message\n";
+  }
+  
+  if(pmt_eqv(result, PMT_T)) {
     // store all of the allocate channel numbers
     if(pmt_eq(msg->port_id(), d_tx->port_symbol()))
-      d_tx_chans.push_back(pmt_to_long(channel));
+      d_tx_chan = pmt_to_long(channel);
     if(pmt_eq(msg->port_id(), d_rx->port_symbol()))
-      d_rx_chans.push_back(pmt_to_long(channel));
+      d_rx_chan = pmt_to_long(channel);
   }
+}
 
-  if(d_nalloc_recvd == d_nalloc_to_recv) {
-    
-    std::cout << "[qa_basic_top] Allocated TX channels: ";
-    for(int i=0; i < (int)d_tx_chans.size(); i++)
-      std::cout << d_tx_chans[i] << " ";
+void
+qa_basic_top::check_xmit(mb_message_sptr msg)
+{
+  pmt_t data = msg->data();
 
-    std::cout << "\n[qa_basic_top] Allocated RX channels: ";
-    for(int i=0; i < (int)d_rx_chans.size(); i++)
-      std::cout << d_rx_chans[i] << " ";
-    std::cout << "\n";
+  pmt_t expected_result = pmt_nth(0, data);
+  pmt_t result = pmt_nth(1, data);
+  
+  if(!pmt_eqv(expected_result, result)) {
+    std::cout << "[qa_basic_top] FAILED check_xmit... Got: " << result << " 
Expected: " << expected_result << " for event " << msg->signal() << ")\n";
+    shutdown_all(PMT_F);
+  } else {
+    std::cout << "[qa_basic_top] Received expected xmit response for 
message\n";
+  }
+}
 
-    deallocate_all();   // once we've allocated all of our channels, try to 
dealloc them
+void
+qa_basic_top::check_cs(mb_message_sptr msg)
+{
+  pmt_t data = msg->data();
+
+  pmt_t expected_result = pmt_nth(0, data);
+  pmt_t result = pmt_nth(1, data);
+
+  if(!pmt_eqv(expected_result, result)) {
+    std::cout << "[qa_basic_top] FAILED check_cs... Got: " << result << " 
Expected: " << expected_result << " for event " << msg->signal() << "\n";
+    shutdown_all(PMT_F);
+  } else {
+    std::cout << "[qa_basic_top] Received expected CS response for message (" 
<< msg->signal() << ")\n";
   }
+
 }
 
 REGISTER_MBLOCK_CLASS(qa_basic_top);
@@ -658,45 +646,43 @@
 // 
----------------------------------------------------------------------------------------------
 
 void 
-qa_inband_usrp_server::test_chan_allocation()
+qa_inband_usrp_server::test_basics()
 {
   mb_runtime_sptr rt = mb_make_runtime();
   pmt_t result = PMT_T;
 
   std::cout << "\n\n----------------------------\n";
-  std::cout << "    RUNNING ALLOCATION TESTS  \n";
+  std::cout << "    RUNNING BASIC TESTS  \n";
 
-  rt->run("top", "qa_alloc_top", PMT_F, &result);
-  
+  rt->run("top", "qa_basic_top", PMT_F, &result);
+
   CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
 }
 
-void
-qa_inband_usrp_server::test_chan_deallocation()
+void 
+qa_inband_usrp_server::test_chan_allocation()
 {
   mb_runtime_sptr rt = mb_make_runtime();
   pmt_t result = PMT_T;
 
   std::cout << "\n\n----------------------------\n";
-  std::cout << "  RUNNING DEALLOCATION TESTS  \n";
+  std::cout << "    RUNNING ALLOCATION TESTS  \n";
 
-  rt->run("top", "qa_dealloc_top", PMT_F, &result);
+  rt->run("top", "qa_alloc_top", PMT_F, &result);
   
   CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
 }
 
-void 
-qa_inband_usrp_server::test_basics()
+void
+qa_inband_usrp_server::test_chan_deallocation()
 {
   mb_runtime_sptr rt = mb_make_runtime();
   pmt_t result = PMT_T;
 
   std::cout << "\n\n----------------------------\n";
-  std::cout << "    RUNNING BASIC TESTS  \n";
+  std::cout << "  RUNNING DEALLOCATION TESTS  \n";
 
-  rt->run("top", "qa_basic_top", PMT_F, &result);
+  rt->run("top", "qa_dealloc_top", PMT_F, &result);
   
   CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
 }
-
-

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
    2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
    2007-06-02 20:20:54 UTC (rev 5609)
@@ -28,9 +28,9 @@
 class qa_inband_usrp_server : public CppUnit::TestCase {
 
   CPPUNIT_TEST_SUITE(qa_inband_usrp_server);
+  CPPUNIT_TEST(test_basics);
   CPPUNIT_TEST(test_chan_allocation);
   CPPUNIT_TEST(test_chan_deallocation);
-  CPPUNIT_TEST(test_basics);
   CPPUNIT_TEST_SUITE_END();
 
  private:

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/test_usrp_inband.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/test_usrp_inband.cc
        2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/test_usrp_inband.cc
        2007-06-02 20:20:54 UTC (rev 5609)
@@ -285,7 +285,7 @@
   if(counting_p)
     rx_mode |= usrp_standard_rx::FPGA_MODE_COUNTING;
 
-  d_cs->send(s_cmd_open, pmt_list3(PMT_NIL, usrp, pmt_from_long(rx_mode)));
+  d_cs->send(s_cmd_open, pmt_list2(PMT_NIL, usrp));
 }
 
 void

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
 2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
 2007-06-02 20:20:54 UTC (rev 5609)
@@ -34,7 +34,7 @@
 (define-protocol-class usrp-interface-cs
 
   (:outgoing
-   (cmd-usrp-open invocation-handle which-usrp rx-mode)
+   (cmd-usrp-open invocation-handle which-usrp)
    (cmd-usrp-close invocation-handle)
    (cmd-usrp-ntx-chan invocation-handle)
    (cmd-usrp-nrx-chan invocation-handle)

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-06-02 20:20:54 UTC (rev 5609)
@@ -115,91 +115,40 @@
     d_rx.push_back(define_port("rx"+str(port), "usrp-rx", true, 
mb_port::EXTERNAL));
   }
 
-  // connect to the USRP low level interface, usb can easily be changed to 
gigabit
   define_component("usrp", usrp_interface, PMT_F);
   connect("self", "cs_usrp", "usrp", "cs");
 
-  // Request the number of TX and RX channels from the USRP for initialization
-  d_cs_usrp->send(s_cmd_usrp_ntx_chan, pmt_list1(PMT_NIL));
-  d_cs_usrp->send(s_cmd_usrp_nrx_chan, pmt_list1(PMT_NIL));
+  d_defer=false;
+  d_opened=false;
 
-  // Set everything to uninitialized
-  d_init.req_open=0;
-  d_init.open=0;
-  d_init.tx=0;
-  d_init.rx=0;
-  d_init.fully_initialized=0;
+  // FIXME: needs to be returned from open, if we want to use this
+  d_nrx_chan = 2;
+  d_ntx_chan = 2;
 
-}
-
-usrp_server::~usrp_server()
-{
-}
-
-
-void
-usrp_server::initial_transition()
-{
-  // the initial transition
-}
-
-void 
-usrp_server::initialize_tx_chans(pmt_t data)
-{
-  
-  pmt_t invocation_handle = pmt_nth(0, data);
-  pmt_t chans = pmt_nth(1, data);
-
-  d_ntx_chan = pmt_to_long(chans);
-
   // Initialize capacity on each channel to 0 and to no owner
   // Also initialize the USRP standard tx/rx pointers to NULL
   for(int chan=0; chan < d_ntx_chan; chan++) {
     d_chaninfo_tx[chan].assigned_capacity = 0;
     d_chaninfo_tx[chan].owner = PMT_NIL;
   }
-
-  std::cout << "[USRP_SERVER] Initialized " << chans << " TX chans\n";
-
-  d_init.tx=1;
-  check_initialization();
-}
-
-void 
-usrp_server::initialize_rx_chans(pmt_t data)
-{
-  
-  pmt_t invocation_handle = pmt_nth(0, data);
-  pmt_t chans = pmt_nth(1, data);
-
-  d_nrx_chan = pmt_to_long(chans);
-
   for(int chan=0; chan < d_nrx_chan; chan++) {
     d_chaninfo_rx[chan].assigned_capacity = 0;
     d_chaninfo_rx[chan].owner = PMT_NIL;
   }
   
-  std::cout << "[USRP_SERVER] Initialized " << chans << " RX chans\n";
-
-  d_init.rx=1;
-  check_initialization();
 }
 
-void
-usrp_server::check_initialization()
+usrp_server::~usrp_server()
 {
-  if(d_init.rx && d_init.tx) {
-    d_init.fully_initialized=1;   // used by the message handler
+}
 
-    // Parse the messages that were queued while unitialized
-    for(int i=0; i < (int)d_init_queue.size(); i++)
-      handle_message(d_init_queue[i]);
 
-    d_init_queue.clear();
-  }
+void
+usrp_server::initial_transition()
+{
+  // the initial transition
 }
 
-
 void
 usrp_server::handle_message(mb_message_sptr msg)
 {
@@ -218,37 +167,62 @@
 
   // It would be nice if this were all table driven, and we could
   // compute our state transition as f(current_state, port_id, signal)
+  
+  // A message from the USRP CS, which should *only* be responses
+  //
+  // It is important that this set come before checking messages of any other
+  // components.  This is since we always want to listen to the low level USRP
+  // server, even if we aren't initialized we are waiting for responses to
+  // become initialized.  Likewise, after the usrp_server is "closed", we
+  // still want to pass responses back from the low level.
+  if (pmt_eq(port_id, d_cs_usrp->port_symbol())) { 
 
-  // Check for messages that lead to full initialization of the USRP server
-  if(!d_init.fully_initialized) {
+    if(pmt_eq(event, s_response_usrp_open)) {
+      // pass the response back over the regular CS port
+      invocation_handle = pmt_nth(0, data);
+      pmt_t status = pmt_nth(1, data);
+      d_cs->send(s_response_open, pmt_list2(invocation_handle, status));
 
-    std::cout << "[USRP_SERVER] Received msg while uninitialized\n";
+      if(pmt_eqv(status,PMT_T)) {
+        d_opened = true;
+        d_defer = false;
+        recall_defer_queue();
+      }
 
-    if (pmt_eq(port_id, d_cs_usrp->port_symbol())) {
-      if(pmt_eq(event, s_response_usrp_ntx_chan)) {
-        initialize_tx_chans(data);
-        return;
+      return;
+    }
+    else if (pmt_eq(event, s_response_usrp_close)) {
+      invocation_handle = pmt_nth(0, data);
+      pmt_t status = pmt_nth(1, data);
+      d_cs->send(s_response_close, pmt_list2(invocation_handle, status));
+      
+      if(pmt_eqv(status,PMT_T)) {
+        d_opened = false;
+        d_defer = false;
+        recall_defer_queue();
       }
-      else if (pmt_eq(event, s_response_usrp_nrx_chan)) {
-        initialize_rx_chans(data);
-        return;
-      }
+      
+      return;
     }
-    
-    // If we're not initialized and the message is not understood to be part 
of the
-    // initialization, we queue it
-    d_init_queue.push_back(msg);
+    else if (pmt_eq(event, s_response_usrp_write)) {
+      
+      invocation_handle = pmt_nth(0, data);
+      long channel = pmt_to_long(pmt_nth(1, data));
+      pmt_t status = pmt_nth(2, data);
 
-    return;
+      // Find the port through the owner of the channel
+      long port = tx_port_index(d_chaninfo_tx[channel].owner);
+      d_tx[port]->send(s_response_xmit_raw_frame, pmt_list2(invocation_handle, 
status));
+      return;
+    }
+
+    goto unhandled;
   }
-  
-  // The other case where we need to queue messages is when the user has
-  // sent an open request, but the open response has not been recieved yet
-  //
-  // We have to make sure the message is not an open response though ;)
-  if(d_init.req_open && !d_init.open && !pmt_eqv(event, s_response_usrp_open)) 
{
-    std::cout << "[USRP_SERVER] Received msg while waiting for open 
response\n";
-    d_open_queue.push_back(msg);
+
+  // Checking for defer on all other messages
+  if(d_defer) {
+    std::cout << "[USRP_SERVER] Received msg while deferring (" << 
msg->signal() << ")\n";
+    d_defer_queue.push(msg);
     return;
   }
 
@@ -256,43 +230,68 @@
 
     if (pmt_eq(event, s_cmd_open)){
 
+      // Reject if already open
+      if(d_opened) {
+        invocation_handle = pmt_nth(0, data);
+        d_cs->send(s_response_open, pmt_list2(invocation_handle, PMT_F));
+        return;
+      }
+
       // the parameters are the same to the low level interface, so we just 
pass 'data' along
       d_cs_usrp->send(s_cmd_usrp_open, data);
 
-      // Set that the user has requested an open, as there is a delay in 
opening
-      // we do not want to throw out the rest of their commands, just queue 
them
-      // until it is fully initialized
-      d_init.req_open = 1;
+      d_defer = true;
       
       return;
     }
     else if (pmt_eq(event, s_cmd_close)){
       invocation_handle = pmt_nth(0, data);
+      if(!d_opened) { 
+        d_cs->send(s_response_close, pmt_list2(invocation_handle, PMT_F));
+        return;
+      }
+      
+      d_defer = true;
+      d_cs_usrp->send(s_cmd_usrp_close, pmt_list1(invocation_handle));
 
-      d_cs_usrp->send(s_cmd_usrp_close, pmt_list1(PMT_NIL));
-
       return;
     }
     else if (pmt_eq(event, s_cmd_max_capacity)) {
       invocation_handle = pmt_nth(0, data);
+      if(!d_opened) { 
+        d_cs->send(s_response_max_capacity, pmt_list3(invocation_handle, 
PMT_F, pmt_from_long(0)));
+        return;
+      }
       reply_data = pmt_list2(invocation_handle, pmt_from_long(max_capacity()));
       d_cs->send(s_response_max_capacity, reply_data);
       return;
     }
     else if (pmt_eq(event, s_cmd_ntx_chan)) {
       invocation_handle = pmt_nth(0, data);
+      if(!d_opened) { 
+        d_cs->send(s_response_ntx_chan, pmt_list3(invocation_handle, PMT_F, 
pmt_from_long(0)));
+        return;
+      }
       reply_data = pmt_list2(invocation_handle, pmt_from_long(d_ntx_chan));
       d_cs->send(s_response_ntx_chan, reply_data);
       return;
     }
     else if (pmt_eq(event, s_cmd_nrx_chan)) {
       invocation_handle = pmt_nth(0, data);
+      if(!d_opened) { 
+        d_cs->send(s_response_nrx_chan, pmt_list3(invocation_handle, PMT_F, 
pmt_from_long(0)));
+        return;
+      }
       reply_data = pmt_list2(invocation_handle, pmt_from_long(d_nrx_chan));
       d_cs->send(s_response_nrx_chan, reply_data);
       return;
     }
     else if (pmt_eq(event, s_cmd_current_capacity_allocation)) {
       invocation_handle = pmt_nth(0, data);
+      if(!d_opened) { 
+        d_cs->send(s_response_current_capacity_allocation, 
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+        return;
+      }
       reply_data = pmt_list2(invocation_handle, 
pmt_from_long(current_capacity_allocation()));
       d_cs->send(s_response_current_capacity_allocation, reply_data);
       return;
@@ -300,69 +299,50 @@
     goto unhandled;
   }
 
-  // A message from the USRP CS, which should *only* be responses
-  if (pmt_eq(port_id, d_cs_usrp->port_symbol())) { 
 
-    if(pmt_eq(event, s_response_usrp_open)) {
-      // pass the response back over the regular CS port
-      invocation_handle = pmt_nth(0, data);
-      pmt_t status = pmt_nth(1, data);
-      d_cs->send(s_response_open, pmt_list2(invocation_handle, status));
+  if (pmt_eq(event, s_cmd_allocate_channel)){
+    if(!d_opened) {    // check the USRP was opened
+      pmt_t invocation_handle = pmt_nth(0, data);
 
-      if(pmt_eqv(status,PMT_T)) {
-
-        d_init.open=1;
-
-        std::cout << "[USRP_SERVER] Fully opened, parsing open queue\n";
-    
-        // Parse the messages that were queued while waiting for an open 
response
-        for(int i=0; i < (int)d_open_queue.size(); i++)
-          handle_message(d_open_queue[i]);
-
-        d_open_queue.clear();
+      long port;
+      if((port = tx_port_index(port_id)) != -1) {
+        d_tx[port]->send(s_response_allocate_channel, 
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+      } else {
+        port = rx_port_index(port_id);
+        d_rx[port]->send(s_response_allocate_channel, 
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
       }
-
       return;
     }
-    else if (pmt_eq(event, s_response_usrp_close)) {
-      invocation_handle = pmt_nth(0, data);
-      pmt_t status = pmt_nth(1, data);
-      d_cs->send(s_response_close, pmt_list2(invocation_handle, status));
-      return;
-    }
-    else if (pmt_eq(event, s_response_usrp_write)) {
 
-      invocation_handle = pmt_nth(0, data);
-      long channel = pmt_to_long(pmt_nth(1, data));
-      pmt_t status = pmt_nth(2, data);
-
-      // Find the port through the owner of the channel
-      long port = tx_port_index(d_chaninfo_tx[channel].owner);
-      d_tx[port]->send(s_response_xmit_raw_frame, pmt_list2(invocation_handle, 
status));
-      return;
-    }
-
-    goto unhandled;
-  }
-
-  if (pmt_eq(event, s_cmd_allocate_channel)){
     handle_cmd_allocate_channel(port_id, data);
     return;
   }
 
   if (pmt_eq(event, s_cmd_deallocate_channel)) {
+    if(!d_opened) {    // check the USRP was opened
+      pmt_t invocation_handle = pmt_nth(0, data);
+
+      long port;
+      if((port = tx_port_index(port_id)) != -1) {
+        d_tx[port]->send(s_response_allocate_channel, 
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+      } else {
+        port = rx_port_index(port_id);
+        d_rx[port]->send(s_response_allocate_channel, 
pmt_list3(invocation_handle, PMT_F, pmt_from_long(0)));
+      }
+      return;
+    }
+
     handle_cmd_deallocate_channel(port_id, data);
     return;
   }
     
   if (pmt_eq(event, s_cmd_xmit_raw_frame)){
-
-    if(!d_init.open && !d_init.req_open) {    // check the USRP was opened
-      std::cerr << "[USRP_SERVER] ERROR: Cannot transmit frame until USRP is 
opened\n";
-      d_tx[tx_port_index(port_id)]->send(s_response_xmit_raw_frame, 
pmt_list2(invocation_handle, PMT_F));
+    if(!d_opened) {    // check the USRP was opened
+      pmt_t invocation_handle = pmt_nth(0, data);
+      long port = tx_port_index(port_id);
+      d_tx[port]->send(s_response_xmit_raw_frame, pmt_list2(invocation_handle, 
PMT_F));
       return;
     }
-
     handle_cmd_xmit_raw_frame(port_id, data);
     return;
   }
@@ -538,7 +518,7 @@
   long timestamp = pmt_to_long(pmt_nth(3, data));
   
   long port;
-  
+
   // Check that the channel number is valid, and that the caller is the owner
   // of the channel to send the frame
   if((port = tx_port_index(port_id)) != -1) {
@@ -580,12 +560,30 @@
 
     pkts[n_packets-1].set_end_of_burst();   // set the last packet's end of 
burst
 
-    std::cout << "[USRP_SERVER] Received raw frame for invocation " << 
pmt_to_long(invocation_handle) << " --> " << n_packets << " packets\n";
+    std::cout << "[USRP_SERVER] Received raw frame invocation: " << 
invocation_handle << std::endl;
 
     // The actual response to the write will be generated by a 
s_response_usrp_write
-    d_cs_usrp->send(s_cmd_usrp_write, pmt_list4(PMT_NIL, 
pmt_from_long(channel), v_packets, 
pmt_from_long(n_packets*transport_pkt::max_pkt_size())));
+    d_cs_usrp->send(s_cmd_usrp_write, pmt_list4(invocation_handle, 
pmt_from_long(channel), v_packets, 
pmt_from_long(n_packets*transport_pkt::max_pkt_size())));
 
   }
 }
 
+void
+usrp_server::recall_defer_queue()
+{
+
+  std::vector<mb_message_sptr> recall;
+
+  while(!d_defer_queue.empty()) {
+    recall.push_back(d_defer_queue.front());
+    d_defer_queue.pop();
+  }
+
+  // Parse the messages that were queued while waiting for an open response
+  for(int i=0; i < recall.size(); i++) 
+    handle_message(recall[i]);
+
+  return;
+}
+
 REGISTER_MBLOCK_CLASS(usrp_server);

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-06-02 20:20:54 UTC (rev 5609)
@@ -23,6 +23,7 @@
 
 #include <mb_mblock.h>
 #include <vector>
+#include <queue>
 
 /*!
  * \brief Implements the lowest-level mblock usb_interface to the USRP
@@ -60,22 +61,11 @@
   struct channel_info d_chaninfo_tx[D_MAX_CHANNELS];
   struct channel_info d_chaninfo_rx[D_MAX_CHANNELS];
 
-  std::vector<mb_message_sptr> d_init_queue;
-  std::vector<mb_message_sptr> d_open_queue;
+  std::queue<mb_message_sptr> d_defer_queue;
 
-  // components we need information about from the FPGA
-  // that we will block service on until we get responses.
-  // All messages are queued until then.
-  struct initialized {
-    bool req_open;
-    bool open;
-    bool tx;
-    bool rx;
-    bool fully_initialized;
-  };
+  bool d_defer;
+  bool d_opened;
 
-  struct initialized d_init;
-  
 public:
   usrp_server(mb_runtime *rt, const std::string &instance_name, pmt_t 
user_arg);
   ~usrp_server();
@@ -93,9 +83,7 @@
   int rx_port_index(pmt_t port_id);
   int tx_port_index(pmt_t port_id);
   long current_capacity_allocation();
-  void initialize_tx_chans(pmt_t data);
-  void initialize_rx_chans(pmt_t data);
-  void check_initialization();
+  void recall_defer_queue();
 };
 
 #endif /* INCLUDED_USRP_SERVER_H */

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.mbh
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.mbh
    2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.mbh
    2007-06-02 20:20:54 UTC (rev 5609)
@@ -237,7 +237,7 @@
 (define-protocol-class usrp-server-cs
 
   (:outgoing
-   (cmd-open invocation-handle which-usrp rx-mode)
+   (cmd-open invocation-handle which-usrp)
    (cmd-close invocation-handle)
    (cmd-max-capacity invocation-handle)
    (cmd-ntx-chan invocation-handle)
@@ -248,9 +248,9 @@
   (:incoming
    (response-open invocation-handle status)
    (response-close invocation-handle status)
-   (response-max-capacity invocation-handle capacity)
-   (response-ntx-chan invocation-handle ntx-chan)
-   (response-nrx-chan invocation-handle nrx-chan)
-   (response-current-capacity-allocation invocation-handle capacity)
+   (response-max-capacity invocation-handle status capacity)
+   (response-ntx-chan invocation-handle status ntx-chan)
+   (response-nrx-chan invocation-handle status nrx-chan)
+   (response-current-capacity-allocation invocation-handle status capacity)
    )
   )

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-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
      2007-06-02 20:20:54 UTC (rev 5609)
@@ -113,13 +113,8 @@
 {
   pmt_t invocation_handle = pmt_nth(0, data);
   long which_usrp = pmt_to_long(pmt_nth(1, data));
-  pmt_t prx_mode = pmt_nth(2, data);
   pmt_t reply_data;
-  long rx_mode = 0;
 
-  if(!pmt_eqv(prx_mode, PMT_NIL))
-    rx_mode = pmt_to_long(prx_mode);
-
   std::cout << "[USRP_USB_INTERFACE] Handling open request for USRP " << 
which_usrp << "\n";
 
   // Open up a standard RX and TX for communication with the USRP
@@ -153,7 +148,7 @@
     16,               // interp = 32.0MB/s
     d_nrx_chan,                
     -1,               // mux
-    rx_mode,
+    0,                // set blank mode to start
     4096,             // USB block size
     16);              // number of blocks for async transfers
 
@@ -174,10 +169,6 @@
   d_urx->start();   // FIXME: currently causing a hang
   
   std::cout << "[USRP_USB_INTERFACE] Setup RX channel\n";
-  if(rx_mode & usrp_standard_rx::FPGA_MODE_LOOPBACK)
-    std::cout << "[USRP_USB_INTERFACE]   - loopback enabled\n";
-  if(rx_mode & usrp_standard_rx::FPGA_MODE_COUNTING)
-    std::cout << "[USRP_USB_INTERFACE]   - counting enabled\n";
 
   d_cs->send(s_response_usrp_open, pmt_list2(invocation_handle, PMT_T));
 }

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.cc
 2007-06-02 20:20:42 UTC (rev 5608)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.cc
 2007-06-02 20:20:54 UTC (rev 5609)
@@ -118,6 +118,8 @@
 
   std::cout << "[USRP_USB_INTERFACE_STUB] Handling open request for USRP " << 
which_usrp << "\n";
 
+  usleep(2 * 1000000);  // artificial time to open the interface
+
   d_cs->send(s_response_usrp_open, pmt_list2(invocation_handle, PMT_T));
 }
 
@@ -125,9 +127,12 @@
 usrp_usb_interface_stub::handle_cmd_write(pmt_t data)
 {
   pmt_t invocation_handle = pmt_nth(0, data);
+  pmt_t channel = pmt_nth(1, data);
   
-  d_cs->send(s_response_usrp_write, pmt_list2(invocation_handle, PMT_T));
+  d_cs->send(s_response_usrp_write, pmt_list3(invocation_handle, channel, 
PMT_T));
 
+  std::cout << "[USRP_USB_INTERFACE_STUB] Successful write\n";
+
   return;
 }
 
@@ -138,13 +143,9 @@
   
   std::cout << "[USRP_USB_INTERFACE_STUB] Handling close request for USRP\n";
 
-  delete d_utx;
-
-  delete d_urx;
-
   d_cs->send(s_response_usrp_close, pmt_list2(invocation_handle, PMT_T));
 
-  shutdown_all(PMT_T);
+  return;
 }
 
 





reply via email to

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