commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r5602 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Sat, 2 Jun 2007 05:55:59 -0600 (MDT)

Author: gnychis
Date: 2007-06-02 05:55:59 -0600 (Sat, 02 Jun 2007)
New Revision: 5602

Added:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
Removed:
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.mbh
Modified:
   gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am
   
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_server.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h
   
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:
Intermediate checkin while writing new QA code for basic open/close semantics 
and also more focused on message ordering and delays from the USRP.

Added new "open queue" that queues up incoming commands inbetween when the USRP 
open request is sent and the open response is received.  This should be 
temporary until the defer mechanism is implemented in the m-block.

Changed usrp_usb_interface.mbh to usrp_interface.mbh with the protocol class to 
usrp-interface-cs to make it more clear that the same signal set will be used 
even if the low level technology changes (usb->gigabit)


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am    
    2007-06-02 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am    
    2007-06-02 11:55:59 UTC (rev 5602)
@@ -28,7 +28,7 @@
 
 EXTRA_DIST =                           \
        usrp_server.mbh         \
-       usrp_usb_interface.mbh 
+       usrp_interface.mbh 
 
 
 lib_LTLIBRARIES =                      \
@@ -41,13 +41,13 @@
 
 BUILT_SOURCES =                                \
        usrp_server_mbh.cc      \
-       usrp_usb_interface_mbh.cc 
+       usrp_interface_mbh.cc 
 
 usrp_server_mbh.cc : usrp_server.mbh
        $(COMPILE_MBH) usrp_server.mbh usrp_server_mbh.cc
 
-usrp_usb_interface_mbh.cc : usrp_usb_interface.mbh
-       $(COMPILE_MBH) usrp_usb_interface.mbh usrp_usb_interface_mbh.cc
+usrp_interface_mbh.cc : usrp_interface.mbh
+       $(COMPILE_MBH) usrp_interface.mbh usrp_interface_mbh.cc
 
 libusrp_inband_la_SOURCES =            \
        $(BUILT_SOURCES)                \

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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.cc
   2007-06-02 11:55:59 UTC (rev 5602)
@@ -57,7 +57,6 @@
 static pmt_t s_cmd_xmit_raw_frame  = pmt_intern("cmd-xmit-raw-frame");
 static pmt_t s_response_xmit_raw_frame = pmt_intern("response-xmit-raw-frame");
 
-
 // 
----------------------------------------------------------------------------------------------
 
 class qa_alloc_top : public mb_mblock
@@ -434,98 +433,191 @@
 
 // 
----------------------------------------------------------------------------------------------
 
-class qa_packets_top : public mb_mblock
+class qa_basic_top : public mb_mblock
 {
   mb_port_sptr d_tx;
   mb_port_sptr d_rx;
+  mb_port_sptr d_cs;
   
   long d_max_capacity;
   long d_ntx_chan, d_nrx_chan;
 
-  long d_xmit_to_recv;
-  long d_xmit_recvd;
+  long d_nstatus;
+  long d_nstatus_to_recv;
 
-  long d_tx_chan;
+  long d_nalloc_to_recv;
+  long d_nalloc_recvd;
 
+  long d_ndealloc_to_recv;
+  long d_ndealloc_recvd;
+
+  std::vector<long> d_tx_chans;
+  std::vector<long> d_rx_chans;
+
  public:
-  qa_packets_top(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
-  ~qa_packets_top();
+  qa_basic_top(mb_runtime *runtime, const std::string &instance_name, pmt_t 
user_arg);
+  ~qa_basic_top();
   void initial_transition();
   void handle_message(mb_message_sptr msg);
 
  protected:
-  void send_packets();
-  void check_xmit(mb_message_sptr msg);
   void check_allocation(mb_message_sptr msg);
   void check_deallocation(mb_message_sptr msg);
+  void allocate_max();
+  void deallocate_all();
 };
 
-qa_packets_top::qa_packets_top(mb_runtime *runtime, const std::string 
&instance_name, pmt_t user_arg)
+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_xmit_recvd=0;
-  d_xmit_to_recv=0;
-
+  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_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);
 
   // Test the TX side
-  
-  // Pass a dictionary to usrp_server which specifies which interface to use, 
the stub or USRP
-  pmt_t usrp_server_dict = pmt_make_dict();
-  pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"), 
pmt_intern("usrp_usb_interface_stub"));
-  pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface-cs"), 
pmt_intern("usrp-usb-interface-cs"));
-
-  define_component("server", "usrp_server", pmt_list1(usrp_server_dict));
+  define_component("server", "usrp_server", PMT_NIL);
   connect("self", "tx0", "server", "tx0");
+  connect("self", "rx0", "server", "rx0");
+  connect("self", "cs", "server", "cs");
 }
 
-qa_packets_top::~qa_packets_top(){}
+qa_basic_top::~qa_basic_top(){}
 
 void
-qa_packets_top::initial_transition()
+qa_basic_top::initial_transition()
 {
-  // need a channel to send on for testing, bytes don't matter right now
-  d_tx->send(s_cmd_allocate_channel, pmt_list2(PMT_T, pmt_from_long(1)));
+  // 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));
 }
 
 void
-qa_packets_top::handle_message(mb_message_sptr msg)
+qa_basic_top::allocate_max()
 {
+  std::cout << "[qa_basic_top] Max allocating...\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++;
+  }
+}
+
+void
+qa_basic_top::deallocate_all() {
+  
+  // 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++;
+  }
+
+  // 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++;
+  }
+
+  // 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)));
+
+
+  // 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)));
+}
+
+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())) {
+  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)) {
       check_allocation(msg);
     }
-    else if(pmt_eq(msg->signal(), s_response_xmit_raw_frame)) {
-      check_xmit(msg);
+    
+    if(pmt_eq(msg->signal(), s_response_deallocate_channel)){
+      check_deallocation(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);
+
+      if(pmt_eqv(expected_result, result))
+        shutdown_all(PMT_T);
+      else
+        shutdown_all(PMT_F);
+    }
+    
+    d_nstatus++;
+
+    if(d_nstatus==d_nstatus_to_recv)
+      allocate_max();
+  }
 }
 
 void
-qa_packets_top::check_xmit(mb_message_sptr msg)
+qa_basic_top::check_deallocation(mb_message_sptr msg)
 {
   pmt_t data = msg->data();
 
-  pmt_t invocation_handle = pmt_nth(0, data);
-  pmt_t status = pmt_nth(1, data);
-  
-  d_xmit_recvd++;
+  pmt_t expected_result = pmt_nth(0, data);
+  pmt_t result = pmt_nth(1, data);
 
-  if(!pmt_eqv(status, PMT_T)) {
-    std::cout << "[qa_packets_top] Error response from raw frame xmit\n"; 
+  d_ndealloc_recvd++;
+
+  if(!pmt_eqv(expected_result, result)) {
+    std::cout << "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";
   }
-
-  if(d_xmit_recvd==d_xmit_to_recv) {
-    std::cout << "[qa_packets_top] Received all expected xmit responses, 
shutting down\n";
-    shutdown_all(PMT_T);
-  }
 }
 
 void
-qa_packets_top::check_allocation(mb_message_sptr msg)
+qa_basic_top::check_allocation(mb_message_sptr msg)
 {
   pmt_t data = msg->data();
 
@@ -533,48 +625,35 @@
   pmt_t status = pmt_nth(1, data);
   pmt_t channel = pmt_nth(2, data);
   
+  d_nalloc_recvd++;
+
   if(pmt_eqv(status, PMT_F)) {
-    std::cout << "[qa_packets_top] Unexpected error response when allocating 
channels\n";
+    std::cout << "[qa_basic_top] Unexpected error response when allocating 
channels\n";
     shutdown_all(PMT_F);
   } else {
-    std::cout << "[qa_packets_top] Received channel allocation for channel " 
<< pmt_to_long(channel) << "\n";
     // store all of the allocate channel numbers
     if(pmt_eq(msg->port_id(), d_tx->port_symbol()))
-      d_tx_chan = pmt_to_long(channel);
-
-    // after allocating some channel, start the TX test
-    send_packets();
+      d_tx_chans.push_back(pmt_to_long(channel));
+    if(pmt_eq(msg->port_id(), d_rx->port_symbol()))
+      d_rx_chans.push_back(pmt_to_long(channel));
   }
-}
 
-void
-qa_packets_top::send_packets()
-{
-  // NOTE:  The invocation handle is used as the expected number of USB 
packets for visual examination
-  
-  // Test 1:  less than the payload size of a single USB packet
-  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(1), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(1, 0), pmt_from_long(0)));
-  d_xmit_to_recv++;
+  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] << " ";
 
-  // Test 2: 1 packet, of exact size... since we are using 32-bit samples we 
divide by 4
-  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(1), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4, 
0), pmt_from_long(0)));
-  d_xmit_to_recv++;
+    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";
 
-  // Test 3: 2 packets, a spill over of 1 sample into the second packet
-  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(2), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4+1, 
0), pmt_from_long(0)));
-  d_xmit_to_recv++;
-
-  // Test 4: 2 packets of exact payload size
-  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(2), 
pmt_from_long(d_tx_chan), pmt_make_u32vector(transport_pkt::max_payload()/4*2, 
0), pmt_from_long(0)));
-  d_xmit_to_recv++;
-  
-  // Test 4: 2 full packets, and 1 packet with a single sample (which is 3)
-  d_tx->send(s_cmd_xmit_raw_frame, pmt_list4(pmt_from_long(3), 
pmt_from_long(d_tx_chan), 
pmt_make_u32vector(transport_pkt::max_payload()/4*2+1, 0), pmt_from_long(0)));
-  d_xmit_to_recv++;
-
+    deallocate_all();   // once we've allocated all of our channels, try to 
dealloc them
+  }
 }
 
-REGISTER_MBLOCK_CLASS(qa_packets_top);
+REGISTER_MBLOCK_CLASS(qa_basic_top);
 
 // 
----------------------------------------------------------------------------------------------
 
@@ -606,16 +685,18 @@
   CPPUNIT_ASSERT(pmt_equal(PMT_T, result));
 }
 
-void
-qa_inband_usrp_server::test_packets()
+void 
+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 PACKET TESTS  \n";
+  std::cout << "    RUNNING BASIC TESTS  \n";
 
-  rt->run("top", "qa_packets_top", PMT_F, &result);
-
+  rt->run("top", "qa_basic_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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/qa_inband_usrp_server.h
    2007-06-02 11:55:59 UTC (rev 5602)
@@ -30,13 +30,13 @@
   CPPUNIT_TEST_SUITE(qa_inband_usrp_server);
   CPPUNIT_TEST(test_chan_allocation);
   CPPUNIT_TEST(test_chan_deallocation);
-  CPPUNIT_TEST(test_packets);
+  CPPUNIT_TEST(test_basics);
   CPPUNIT_TEST_SUITE_END();
 
  private:
   void test_chan_allocation();
   void test_chan_deallocation();
-  void test_packets();
+  void test_basics();
 };
 
 #endif /* INCLUDED_QA_INBAND_USRP_SERVER_H */

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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/test_usrp_inband.cc
        2007-06-02 11:55:59 UTC (rev 5602)
@@ -153,10 +153,8 @@
   // Pass a dictionary to usrp_server which specifies which interface to use, 
the stub or USRP
   pmt_t usrp_server_dict = pmt_make_dict();
 
-  if(fake_usrp_p) {
+  if(fake_usrp_p)
     pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"), 
pmt_intern("usrp_usb_interface_stub"));
-    pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface-cs"), 
pmt_intern("usrp-usb-interface-cs"));
-  }
 
   define_component("server", "usrp_server", pmt_list1(usrp_server_dict));
   connect("self", "tx0", "server", "tx0");

Copied: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
 (from rev 5583, 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.mbh)
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
                         (rev 0)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
 2007-06-02 11:55:59 UTC (rev 5602)
@@ -0,0 +1,51 @@
+;; -*- scheme -*- ; not really, but tells emacs how to format this
+;;
+;; Copyright 2007 Free Software Foundation, Inc.
+;; 
+;; This file is part of GNU Radio
+;; 
+;; GNU Radio is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 2, or (at your option)
+;; any later version.
+;; 
+;; GNU Radio is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+;; 
+;; You should have received a copy of the GNU General Public License along
+;; with this program; if not, write to the Free Software Foundation, Inc.,
+;; 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+;;
+
+;; ----------------------------------------------------------------
+;;              This is an mblock header file
+;;
+;; The format is very much a work-in-progress.
+;; It'll be compiled to C++.
+;; ----------------------------------------------------------------
+
+;; ----------------------------------------------------------------
+;; tx-channels
+;;
+;; Handles a query for the number of tx-channels
+
+(define-protocol-class usrp-interface-cs
+
+  (:outgoing
+   (cmd-usrp-open invocation-handle which-usrp rx-mode)
+   (cmd-usrp-close invocation-handle)
+   (cmd-usrp-ntx-chan invocation-handle)
+   (cmd-usrp-nrx-chan invocation-handle)
+   (cmd-usrp-write invocation-handle channel data n-bytes)
+   )
+
+  (:incoming
+   (response-usrp-open invocation-handle status)
+   (response-usrp-close invocation-handle status)
+   (response-usrp-ntx-chan invocation-handle ntx-chan)
+   (response-usrp-nrx-chan invocation-handle nrx-chan)
+   (response-usrp-write invocation-handle channel status)
+   )
+  )

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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-06-02 11:55:59 UTC (rev 5602)
@@ -89,28 +89,22 @@
 
   // Default USRP interface
   std::string usrp_interface = "usrp_usb_interface";
-  std::string usrp_interface_cs = "usrp-usb-interface-cs";
 
   // a dictionary is given for usrp server parameters, such as the interface 
to use
   pmt_t usrp_dict = pmt_nth(0, user_arg);
   
   if(!pmt_eqv(usrp_dict, PMT_NIL)) {
 
-    if(pmt_dict_has_key(usrp_dict, pmt_intern("usrp-interface"))) {
+    if(pmt_dict_has_key(usrp_dict, pmt_intern("usrp-interface"))) 
       usrp_interface = pmt_write_string(pmt_dict_ref(usrp_dict, 
pmt_intern("usrp-interface"), PMT_NIL));
-      std::cout << "[USRP_SERVER] Using interface: " << usrp_interface << "\n";
-    }
-    
-    if(pmt_dict_has_key(usrp_dict, pmt_intern("usrp-interface-cs"))) {
-      usrp_interface_cs = pmt_write_string(pmt_dict_ref(usrp_dict, 
pmt_intern("usrp-interface-cs"), PMT_NIL));
-      std::cout << "[USRP_SERVER] Using CS interface: " << usrp_interface << 
"\n";
-    }
 
   }
+      
+  std::cout << "[USRP_SERVER] Using interface: " << usrp_interface << "\n";
 
   // control & status port
   d_cs = define_port("cs", "usrp-server-cs", true, mb_port::EXTERNAL); 
-  d_cs_usrp = define_port("cs_usrp", usrp_interface_cs, false, 
mb_port::INTERNAL);     
+  d_cs_usrp = define_port("cs_usrp", "usrp-interface-cs", false, 
mb_port::INTERNAL);   
 
   // ports
   //
@@ -130,6 +124,8 @@
   d_cs_usrp->send(s_cmd_usrp_nrx_chan, pmt_list1(PMT_NIL));
 
   // 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;
@@ -238,13 +234,23 @@
         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);
 
     return;
   }
+  
+  // 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);
+    return;
+  }
 
   if (pmt_eq(port_id, d_cs->port_symbol())){   // message came in on our 
control/status port
 
@@ -252,6 +258,11 @@
 
       // 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;
       
       return;
     }
@@ -297,6 +308,20 @@
       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_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();
+      }
+
       return;
     }
     else if (pmt_eq(event, s_response_usrp_close)) {
@@ -331,6 +356,13 @@
   }
     
   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));
+      return;
+    }
+
     handle_cmd_xmit_raw_frame(port_id, data);
     return;
   }

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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.h  
    2007-06-02 11:55:59 UTC (rev 5602)
@@ -61,14 +61,17 @@
   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;
 
   // 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 {
-    long tx;
-    long rx;
-    long fully_initialized;
+    bool req_open;
+    bool open;
+    bool tx;
+    bool rx;
+    bool fully_initialized;
   };
 
   struct initialized d_init;

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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
      2007-06-02 11:55:59 UTC (rev 5602)
@@ -47,7 +47,7 @@
 usrp_usb_interface::usrp_usb_interface(mb_runtime *rt, const std::string 
&instance_name, pmt_t user_arg)
   : mb_mblock(rt, instance_name, user_arg)
 {
-  d_cs = define_port("cs", "usrp-usb-interface-cs", true, mb_port::EXTERNAL);  
+  d_cs = define_port("cs", "usrp-interface-cs", true, mb_port::EXTERNAL);      
   
   // FIX ME: the code should query the FPGA to retrieve the number of channels 
and such
   d_ntx_chan = 2;
@@ -113,9 +113,13 @@
 {
   pmt_t invocation_handle = pmt_nth(0, data);
   long which_usrp = pmt_to_long(pmt_nth(1, data));
-  long rx_mode = pmt_to_long(pmt_nth(2, 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

Deleted: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.mbh

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 00:28:16 UTC (rev 5601)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.cc
 2007-06-02 11:55:59 UTC (rev 5602)
@@ -29,7 +29,6 @@
 #include <usrp_usb_interface_stub.h>
 #include <usrp_inband_usb_packet.h>
 #include "usrp_standard.h"
-#include <fake_usrp.h>
 
 typedef usrp_inband_usb_packet transport_pkt;
 
@@ -48,7 +47,7 @@
 usrp_usb_interface_stub::usrp_usb_interface_stub(mb_runtime *rt, const 
std::string &instance_name, pmt_t user_arg)
   : mb_mblock(rt, instance_name, user_arg)
 {
-  d_cs = define_port("cs", "usrp-usb-interface-cs", true, mb_port::EXTERNAL);  
+  d_cs = define_port("cs", "usrp-interface-cs", true, mb_port::EXTERNAL);      
   
   // FIX ME: the code should query the FPGA to retrieve the number of channels 
and such
   d_ntx_chan = 2;
@@ -114,7 +113,7 @@
 {
   pmt_t invocation_handle = pmt_nth(0, data);
   long which_usrp = pmt_to_long(pmt_nth(1, data));
-  long rx_mode = pmt_to_long(pmt_nth(2, data));
+  pmt_t rx_mode = pmt_nth(2, data);
   pmt_t reply_data;
 
   std::cout << "[USRP_USB_INTERFACE_STUB] Handling open request for USRP " << 
which_usrp << "\n";
@@ -126,26 +125,9 @@
 usrp_usb_interface_stub::handle_cmd_write(pmt_t data)
 {
   pmt_t invocation_handle = pmt_nth(0, data);
-  long channel = pmt_to_long(pmt_nth(1, data));
-  pmt_t v_packets = pmt_nth(2, data);
-  long n_bytes = pmt_to_long(pmt_nth(3, data));
   
-  size_t psize;
-  bool underrun;  // this will need to go, as it is taken care of in the 
packet headers
-  
-  transport_pkt *pkts = (transport_pkt *) 
pmt_u8vector_writeable_elements(v_packets, psize);
+  d_cs->send(s_response_usrp_write, pmt_list2(invocation_handle, PMT_T));
 
-  // setup a fake USRP and write to the fake USB bus
-  fake_usrp usrp;
-  pmt_t reply_data;
-
-  if(!usrp.write_bus(pkts, n_bytes))
-    reply_data = pmt_list3(invocation_handle, pmt_from_long(channel), PMT_F);
-  else
-    reply_data = pmt_list3(invocation_handle, pmt_from_long(channel), PMT_T);
-    
-  d_cs->send(s_response_usrp_write, reply_data);
-
   return;
 }
 





reply via email to

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