commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r5593 - gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband
Date: Fri, 1 Jun 2007 15:45:18 -0600 (MDT)

Author: gnychis
Date: 2007-06-01 15:45:18 -0600 (Fri, 01 Jun 2007)
New Revision: 5593

Added:
   
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.h
Modified:
   gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am
   
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_usb_interface.cc
Log:
The usrp_server constructor now takes a dictionary for setup.

The application can now specify the interface that it wants the usrp_server to 
use, such as the USRP or the stub.

The control/status also needs to be specified, else usrp_server needs to keep 
being updated with new branches to determine the c/s to use.

USRP and the stub use the same signal set, as they should be mirrors of each 
other aside from method implementation.


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-01 17:10:17 UTC (rev 5592)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am    
    2007-06-01 21:45:18 UTC (rev 5593)
@@ -28,7 +28,7 @@
 
 EXTRA_DIST =                           \
        usrp_server.mbh         \
-       usrp_usb_interface.mbh
+       usrp_usb_interface.mbh 
 
 
 lib_LTLIBRARIES =                      \
@@ -41,7 +41,7 @@
 
 BUILT_SOURCES =                                \
        usrp_server_mbh.cc      \
-       usrp_usb_interface_mbh.cc
+       usrp_usb_interface_mbh.cc 
 
 usrp_server_mbh.cc : usrp_server.mbh
        $(COMPILE_MBH) usrp_server.mbh usrp_server_mbh.cc
@@ -52,7 +52,8 @@
 libusrp_inband_la_SOURCES =            \
        $(BUILT_SOURCES)                \
        usrp_server.cc                  \
-       usrp_usb_interface.cc
+       usrp_usb_interface.cc   \
+       usrp_usb_interface_stub.cc
 
 libusrp_inband_la_LDFLAGS = $(NO_UNDEFINED) -version-info 0:0:0
 
@@ -62,14 +63,14 @@
        -lstdc++
 
 include_HEADERS =                      \
-       usrp_server.h                   
+       usrp_server.h                           \
+       usrp_inband_usb_packet.h        
 
 noinst_HEADERS =                       \
        qa_inband.h                     \
        qa_inband_packet_prims.h        \
        qa_inband_usrp_server.h         \
-       fake_usrp.h                                                             
\
-       usrp_inband_usb_packet.h        
+       fake_usrp.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-01 17:10:17 UTC (rev 5592)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/test_usrp_inband.cc
        2007-06-01 21:45:18 UTC (rev 5593)
@@ -59,6 +59,7 @@
 
 bool loopback_p = false;
 bool counting_p = false;
+bool fake_usrp_p = false;
 char *prog_name;
 
 static void
@@ -77,6 +78,7 @@
   fprintf (stderr, "usage: %s [-l]\n", prog_name);
   fprintf (stderr, "  [-l] digital loopback in FPGA\n");
   fprintf (stderr, "  [-c] counting in FPGA\n");
+  fprintf (stderr, "  [-f] fake usrp\n");
 
   exit(1);
 }
@@ -91,7 +93,7 @@
   mb_runtime_sptr rt = mb_make_runtime();
   pmt_t result = PMT_T;
 
-  while ((ch = getopt(argc, argv, "lc")) != EOF) {
+  while ((ch = getopt(argc, argv, "flc")) != EOF) {
     switch(ch) {
     
       case 'l':
@@ -101,6 +103,10 @@
       case 'c':
         counting_p = true;
         break;
+      
+      case 'f':
+        fake_usrp_p = true;
+        break;
 
       default:
         usage();
@@ -143,7 +149,16 @@
   d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
   
   // Test the TX side
-  define_component("server", "usrp_server", PMT_F);
+
+  // 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) {
+    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");
   connect("self", "cs", "server", "cs");
 }

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-01 17:10:17 UTC (rev 5592)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-06-01 21:45:18 UTC (rev 5593)
@@ -28,6 +28,7 @@
 #include <mb_class_registry.h>
 #include <vector>
 #include <usrp_usb_interface.h>
+#include <usrp_usb_interface_stub.h>
 
 typedef usrp_inband_usb_packet transport_pkt;   // makes conversion to gigabit 
easy
 
@@ -85,12 +86,31 @@
 usrp_server::usrp_server(mb_runtime *rt, const std::string &instance_name, 
pmt_t user_arg)
   : mb_mblock(rt, instance_name, user_arg)
 {
-  // define our ports
+
+  // 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"))) {
+      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";
+    }
+
+  }
+
   // control & status port
   d_cs = define_port("cs", "usrp-server-cs", true, mb_port::EXTERNAL); 
-  d_cs_usrp = define_port("cs_usrp", "usrp-usb-interface-cs", false, 
mb_port::INTERNAL);       
+  d_cs_usrp = define_port("cs_usrp", usrp_interface_cs, false, 
mb_port::INTERNAL);     
 
   // ports
   //
@@ -102,7 +122,7 @@
   }
 
   // connect to the USRP low level interface, usb can easily be changed to 
gigabit
-  define_component("usrp", "usrp_usb_interface", PMT_F);
+  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

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-01 17:10:17 UTC (rev 5592)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
      2007-06-01 21:45:18 UTC (rev 5593)
@@ -29,10 +29,7 @@
 #include <usrp_usb_interface.h>
 #include <usrp_inband_usb_packet.h>
 #include "usrp_standard.h"
-#include <fake_usrp.h>
 
-#define FAKE_USRP_TESTS
-
 typedef usrp_inband_usb_packet transport_pkt;
 
 static pmt_t s_cmd_usrp_open = pmt_intern("cmd-usrp-open");
@@ -121,9 +118,6 @@
 
   std::cout << "[USRP_USB_INTERFACE] Handling open request for USRP " << 
which_usrp << "\n";
 
-// do not execute any of this code when a fake USRP is being used, just send a 
true response
-#ifndef FAKE_USRP_TESTS
-
   // Open up a standard RX and TX for communication with the USRP
    
   d_utx = usrp_standard_tx::make (which_usrp,
@@ -173,7 +167,7 @@
     return;
   }
 
-  // d_urx->start()   // FIXME: currently causing a hang
+  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)
@@ -181,8 +175,6 @@
   if(rx_mode & usrp_standard_rx::FPGA_MODE_COUNTING)
     std::cout << "[USRP_USB_INTERFACE]   - counting enabled\n";
 
-#endif
-
   d_cs->send(s_response_usrp_open, pmt_list2(invocation_handle, PMT_T));
 }
 
@@ -199,8 +191,6 @@
   
   transport_pkt *pkts = (transport_pkt *) 
pmt_u8vector_writeable_elements(v_packets, psize);
 
-#ifndef FAKE_USRP_TESTS
-
   int ret = d_utx->write (pkts, n_bytes, &underrun);
 
   if (ret == n_bytes) {
@@ -216,21 +206,6 @@
     d_cs->send(s_response_usrp_write, pmt_list3(invocation_handle, 
pmt_from_long(channel), PMT_F));
   }
 
-#else
-
-  // 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);
-
-#endif
-
   return;
 }
 

Added: 
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
                         (rev 0)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.cc
 2007-06-01 21:45:18 UTC (rev 5593)
@@ -0,0 +1,169 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <iostream>
+#include <vector>
+#include <usb.h>
+#include <mb_class_registry.h>
+#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;
+
+static pmt_t s_cmd_usrp_open = pmt_intern("cmd-usrp-open");
+static pmt_t s_cmd_usrp_close = pmt_intern("cmd-usrp-close");
+static pmt_t s_cmd_usrp_write = pmt_intern("cmd-usrp-write");
+static pmt_t s_cmd_usrp_ntx_chan = pmt_intern("cmd-usrp-ntx-chan");
+static pmt_t s_cmd_usrp_nrx_chan = pmt_intern("cmd-usrp-nrx-chan");
+static pmt_t s_response_usrp_ntx_chan = pmt_intern("response-usrp-ntx-chan");
+static pmt_t s_response_usrp_nrx_chan = pmt_intern("response-usrp-nrx-chan");
+static pmt_t s_response_usrp_open = pmt_intern("response-usrp-open");
+static pmt_t s_response_usrp_close = pmt_intern("response-usrp-close");
+static pmt_t s_response_usrp_write = pmt_intern("response-usrp-write");
+
+// need to take number of TX and RX channels as parameter
+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);  
+  
+  // FIX ME: the code should query the FPGA to retrieve the number of channels 
and such
+  d_ntx_chan = 2;
+  d_nrx_chan = 2;
+
+  d_utx = NULL;
+  d_urx = NULL;
+}
+
+usrp_usb_interface_stub::~usrp_usb_interface_stub() 
+{ 
+
+}
+
+void 
+usrp_usb_interface_stub::initial_transition()
+{
+
+}
+
+void
+usrp_usb_interface_stub::handle_message(mb_message_sptr msg)
+{
+  pmt_t event = msg->signal();         // the "name" of the message
+  pmt_t port_id = msg->port_id();      // which port it came in on
+  pmt_t data = msg->data();
+  pmt_t invocation_handle;
+
+  // message came in on our control/status port
+  if (pmt_eq(port_id, d_cs->port_symbol())) {  
+
+    if (pmt_eq(event, s_cmd_usrp_open)){
+      handle_cmd_open(data);
+      return;
+    }
+    else if (pmt_eq(event, s_cmd_usrp_close)) {
+      handle_cmd_close(data);
+      return;
+    }
+    else if (pmt_eq(event, s_cmd_usrp_ntx_chan)) {
+      invocation_handle = pmt_nth(0, data);
+      d_cs->send(s_response_usrp_ntx_chan, pmt_list2(invocation_handle, 
pmt_from_long(d_ntx_chan)));
+      return;
+    }
+    else if (pmt_eq(event, s_cmd_usrp_nrx_chan)) {
+      invocation_handle = pmt_nth(0, data);
+      d_cs->send(s_response_usrp_nrx_chan, pmt_list2(invocation_handle, 
pmt_from_long(d_nrx_chan)));
+      return;
+    }
+    else if(pmt_eq(event, s_cmd_usrp_write)) {
+      handle_cmd_write(data);
+      return;
+    }
+    goto unhandled;
+  }
+
+ unhandled:
+  std::cout << "[USRP_USB_INTERFACE_STUB] unhandled msg: " << msg << std::endl;
+}
+
+void
+usrp_usb_interface_stub::handle_cmd_open(pmt_t data)
+{
+  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 reply_data;
+
+  std::cout << "[USRP_USB_INTERFACE_STUB] Handling open request for USRP " << 
which_usrp << "\n";
+
+  d_cs->send(s_response_usrp_open, pmt_list2(invocation_handle, PMT_T));
+}
+
+void
+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);
+
+  // 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;
+}
+
+void
+usrp_usb_interface_stub::handle_cmd_close(pmt_t data)
+{
+  pmt_t invocation_handle = pmt_nth(0, data);
+  
+  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);
+}
+
+
+REGISTER_MBLOCK_CLASS(usrp_usb_interface_stub);

Added: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.h
                          (rev 0)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.h
  2007-06-01 21:45:18 UTC (rev 5593)
@@ -0,0 +1,57 @@
+/* -*- c++ -*- */
+/*
+ * 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.
+ */
+#ifndef INCLUDED_USRP_USB_INTERFACE_STUB_H
+#define INCLUDED_USRP_USB_INTERFACE_STUB_H
+
+#include <mb_mblock.h>
+#include <vector>
+#include "usrp_standard.h"
+
+/*!
+ * \brief Implements the low level usb interface to the USRP
+ */
+class usrp_usb_interface_stub : public mb_mblock
+{
+ public:
+
+  usrp_standard_tx* d_utx;
+  usrp_standard_rx* d_urx;
+  
+  mb_port_sptr d_cs;
+  
+  long d_ntx_chan;
+  long d_nrx_chan;
+
+ public:
+  usrp_usb_interface_stub(mb_runtime *rt, const std::string &instance_name, 
pmt_t user_arg);
+  ~usrp_usb_interface_stub();
+  void initial_transition();
+  void handle_message(mb_message_sptr msg);
+
+ private:
+  void handle_cmd_open(pmt_t data);
+  void handle_cmd_close(pmt_t data);
+  void handle_cmd_write(pmt_t data);
+ 
+};
+  
+
+#endif /* INCLUDED_USRP_USB_INTERFACE_STUB_H */





reply via email to

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