commit-gnuradio
[Top][All Lists]
Advanced

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

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


From: gnychis
Subject: [Commit-gnuradio] r5690 - in gnuradio/branches/developers/gnychis/inband/usrp/host: apps lib/inband
Date: Tue, 5 Jun 2007 09:43:50 -0600 (MDT)

Author: gnychis
Date: 2007-06-05 09:43:50 -0600 (Tue, 05 Jun 2007)
New Revision: 5690

Added:
   gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.cc
   gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.h
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.h
Removed:
   
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/apps/test_usrp_inband_tx.cc
   gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am
   
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
   gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx.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:
Removing usrp_usb_interface_stub since it is no longer the lowest level and the 
lowest level should be stubbed.

This also simplifies the "stubbing" since usrp_tx and usrp_rx are very simple 
with no state and just read/write.

usrp_tx and usrp_rx are the new lowest level interfaces to the usrp.

Adding in usrp_tx_stub which is complete.

usrp_tx and usrp_tx_stub work, but need to be "logically" tested still.

The dictionary interface to specify the stubs are the same, however the keys 
are now:
  "usrp-tx" -> "usrp_tx_stub"
  "usrp-rx" -> "usrp_rx_stub"

This will get passed down all the way to usrp_usb_interface who will stub them.


Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
   2007-06-05 15:17:55 UTC (rev 5689)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/apps/test_usrp_inband_tx.cc
   2007-06-05 15:43:50 UTC (rev 5690)
@@ -110,8 +110,8 @@
     d_state(INIT), d_nsamples_to_send((long) 40e6),
     d_nsamples_xmitted(0),
     d_nframes_xmitted(0),
-    //d_samples_per_frame((long)(126 * 3.5)),  // non-full packet
-    d_samples_per_frame((long)(126 * 4)),      // full packet
+    d_samples_per_frame((long)(126 * 3.5)),    // non-full packet
+    //d_samples_per_frame((long)(126 * 4)),    // full packet
     d_done_sending(false),
     d_amplitude(16384)
 { 
@@ -120,19 +120,20 @@
   d_tx = define_port("tx0", "usrp-tx", false, mb_port::INTERNAL);
   d_cs = define_port("cs", "usrp-server-cs", false, mb_port::INTERNAL);
   
-  //bool fake_usrp_p = true;
-  bool fake_usrp_p = false;
+  bool fake_usrp_p = true;
+  //bool fake_usrp_p = false;
 
   // 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_t usrp_dict = pmt_make_dict();
 
-  if(fake_usrp_p)
-    pmt_dict_set(usrp_server_dict, pmt_intern("usrp-interface"),
-                pmt_intern("usrp_usb_interface_stub"));
+  if(fake_usrp_p) {
+    pmt_dict_set(usrp_dict, 
+                 pmt_intern("usrp-tx"),
+                            pmt_intern("usrp_tx_stub"));
+  }
 
-  define_component("server", "usrp_server", usrp_server_dict);
+  define_component("server", "usrp_server", usrp_dict);
 
   connect("self", "tx0", "server", "tx0");
   connect("self", "cs", "server", "cs");
@@ -305,7 +306,7 @@
   // allocate the uniform vector for the samples
   // FIXME perhaps hold on to this between calls
 
-#if 0
+#if 1
   long nsamples_this_frame =
     std::min(d_nsamples_to_send - d_nsamples_xmitted,
             d_samples_per_frame);

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-05 15:17:55 UTC (rev 5689)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/Makefile.am    
    2007-06-05 15:43:50 UTC (rev 5690)
@@ -57,7 +57,8 @@
        $(BUILT_SOURCES)                                                \
        usrp_server.cc                                                  \
        usrp_usb_interface.cc                           \
-       usrp_usb_interface_stub.cc      \
+       usrp_tx.cc                                                              
        \
+       usrp_tx_stub.cc                                                 \
        usrp_rx.cc
 
 libusrp_inband_la_LDFLAGS = $(NO_UNDEFINED) -version-info 0:0:0
@@ -71,7 +72,8 @@
        usrp_server.h                   \
        usrp_usb_interface.h            \
        usrp_inband_usb_packet.h        \
-       usrp_usb_interface_stub.h       \
+       usrp_tx_stub.h                                          \
+       usrp_tx.h                                                               
        \
        usrp_rx.h
 
 noinst_HEADERS =                       \

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-05 15:17:55 UTC (rev 5689)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_interface.mbh
 2007-06-05 15:43:50 UTC (rev 5690)
@@ -47,7 +47,7 @@
    (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)
+   (response-usrp-write invocation-handle status channel)
    (response-usrp-read invocation-handle status data)
    )
   )
@@ -60,11 +60,11 @@
 (define-protocol-class usrp-tx-cs
 
   (:outgoing
-   (cmd-usrp-tx-write invocation-handle data)
+   (cmd-usrp-tx-write invocation-handle channel data tx-handle)
    )
 
   (:incoming
-   (response-usrp-rx-write invocation-handle status)
+   (response-usrp-tx-write invocation-handle status channel)
    )
   )
 
@@ -80,7 +80,7 @@
    )
 
   (:incoming
-   (response-usrp-rx-read invocation-handle data)
+   (response-usrp-rx-read invocation-handle status data)
 
    ;; There is currently no response to a stop reading
    )

Modified: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx.cc
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx.cc 
2007-06-05 15:17:55 UTC (rev 5689)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_rx.cc 
2007-06-05 15:43:50 UTC (rev 5690)
@@ -85,7 +85,8 @@
   d_urx = boost::any_cast<usrp_standard_rx *>(pmt_any_ref(pmt_nth(1, data)));
 
   pmt_t v_pkt = pmt_make_u8vector(pkt_size, 0);
-  transport_pkt *pkt = (transport_pkt *) 
pmt_u8vector_writeable_elements(v_pkt, ignore);
+  transport_pkt *pkt = 
+    (transport_pkt *) pmt_u8vector_writeable_elements(v_pkt, ignore);
 
   if(verbose)
     std::cout << "[usrp_rx] Waiting for packets..\n";
@@ -96,11 +97,11 @@
 
     if(n_read != pkt_size) {
       std::cerr << "[usrp_rx] Error reading packet, shutting down\n";
-      shutdown_all(PMT_F);
+      d_cs->send(s_response_usrp_rx_read, pmt_list3(PMT_NIL, PMT_F, PMT_NIL));
       return;
     }
 
-    d_cs->send(s_response_usrp_rx_read, pmt_list2(PMT_NIL, v_pkt));
+    d_cs->send(s_response_usrp_rx_read, pmt_list3(PMT_NIL, PMT_T, v_pkt));
     if(verbose)
       std::cout << "[usrp_rx] Read 1 packet\n";
   }

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-05 15:17:55 UTC (rev 5689)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_server.cc 
    2007-06-05 15:43:50 UTC (rev 5690)
@@ -28,7 +28,6 @@
 #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
 
@@ -93,22 +92,9 @@
   d_fake_rx(false)
 {
 
-  // Default USRP interface
-  std::string usrp_interface = "usrp_usb_interface";
-
-  // a dictionary is given for usrp server parameters, such as the interface 
to use
+  // Dictionary for arguments to all of the components
   pmt_t usrp_dict = user_arg;
   
-  if (pmt_is_dict(usrp_dict) && pmt_dict_has_key(usrp_dict, 
pmt_intern("usrp-interface"))){
-    usrp_interface =
-      pmt_symbol_to_string(pmt_dict_ref(usrp_dict,
-                                       pmt_intern("usrp-interface"),
-                                       PMT_NIL));
-  }
-
-  if (verbose)
-    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);   
@@ -130,7 +116,7 @@
                                mb_port::EXTERNAL));
   }
 
-  define_component("usrp", usrp_interface, PMT_F);
+  define_component("usrp", "usrp_usb_interface", usrp_dict);
   connect("self", "cs_usrp", "usrp", "cs");
 
   d_defer=false;
@@ -237,8 +223,8 @@
     //--------------- USRP WRITE --------------//
     else if (pmt_eq(event, s_response_usrp_write)) {
       
-      long channel = pmt_to_long(pmt_nth(1, data));
-      pmt_t status = pmt_nth(2, data);
+      pmt_t status = pmt_nth(1, data);
+      long channel = pmt_to_long(pmt_nth(2, data));
 
       // Find the port through the owner of the channel
       long port = tx_port_index(d_chaninfo_tx[channel].owner);

Added: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.cc
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.cc 
                        (rev 0)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.cc 
2007-06-05 15:43:50 UTC (rev 5690)
@@ -0,0 +1,112 @@
+/* -*- 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_tx.h>
+#include <usrp_inband_usb_packet.h>
+#include <fpga_regs_common.h>
+#include "usrp_standard.h"
+#include <stdio.h>
+
+typedef usrp_inband_usb_packet transport_pkt;
+
+static const bool verbose = false;
+
+static pmt_t s_cmd_usrp_tx_write = pmt_intern("cmd-usrp-tx-write");
+static pmt_t s_response_usrp_tx_write = pmt_intern("response-usrp-tx-write");
+
+usrp_tx::usrp_tx(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-tx-cs", true, mb_port::EXTERNAL);
+  
+}
+
+usrp_tx::~usrp_tx() 
+{
+}
+
+void 
+usrp_tx::initial_transition()
+{
+  
+}
+
+void
+usrp_tx::handle_message(mb_message_sptr msg)
+{
+  pmt_t event = msg->signal();
+  pmt_t port_id = msg->port_id();
+  pmt_t data = msg->data(); 
+
+  // Theoretically only have 1 message to ever expect, but
+  // want to make sure its at least what we want
+  if(pmt_eq(port_id, d_cs->port_symbol())) {
+    
+    if(pmt_eqv(event, s_cmd_usrp_tx_write))
+      write(data);
+  }
+}
+
+void
+usrp_tx::write(pmt_t data)
+{
+  pmt_t invocation_handle = pmt_nth(0, data);
+  pmt_t channel = pmt_nth(1, data);
+  pmt_t v_packets = pmt_nth(2, data);
+  d_utx = boost::any_cast<usrp_standard_tx *>(pmt_any_ref(pmt_nth(3, data)));
+
+  size_t n_bytes;
+  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, n_bytes);
+
+  int ret = d_utx->write (pkts, n_bytes, &underrun);
+  
+  if (0 && underrun)
+    fprintf(stderr, "uU");
+
+  if (ret == (int) n_bytes) {
+    if (verbose)
+      std::cout << "[usrp_server] Write of " << n_bytes << " successful\n";
+    // need to respond with the channel so the USRP server knows who to 
forward the result of
+    // the write to by looking up the owner of the channel
+    d_cs->send(s_response_usrp_tx_write,
+              pmt_list3(invocation_handle, PMT_T, channel));
+  }
+  else {
+    if (verbose)
+      std::cout << "[usrp_server] Error writing " << n_bytes << " bytes to USB 
bus\n";
+    d_cs->send(s_response_usrp_tx_write,
+              pmt_list3(invocation_handle, PMT_F, channel));
+  }
+
+  return;
+}
+
+REGISTER_MBLOCK_CLASS(usrp_tx);

Added: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.h
===================================================================
--- gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.h  
                        (rev 0)
+++ gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx.h  
2007-06-05 15:43:50 UTC (rev 5690)
@@ -0,0 +1,51 @@
+/* -*- 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_TX_H
+#define INCLUDED_USRP_TX_H
+
+#include <mb_mblock.h>
+#include <vector>
+#include "usrp_standard.h"
+
+/*!
+ * \brief Implements the low level usb interface to the USRP
+ */
+class usrp_tx : public mb_mblock
+{
+ public:
+
+  mb_port_sptr d_cs;
+  usrp_standard_tx* d_utx;
+  
+ public:
+  usrp_tx(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg);
+  ~usrp_tx();
+  void initial_transition();
+  void handle_message(mb_message_sptr msg);
+
+ private:
+  void write(pmt_t data);
+ 
+};
+  
+
+#endif /* INCLUDED_USRP_TX_H */
+

Added: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
                            (rev 0)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.cc
    2007-06-05 15:43:50 UTC (rev 5690)
@@ -0,0 +1,109 @@
+/* -*- 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_tx_stub.h>
+#include <usrp_inband_usb_packet.h>
+#include <fpga_regs_common.h>
+#include "usrp_standard.h"
+#include <stdio.h>
+#include <fstream>
+
+typedef usrp_inband_usb_packet transport_pkt;
+
+static const bool verbose = false;
+
+static pmt_t s_cmd_usrp_tx_write = pmt_intern("cmd-usrp-tx-write");
+static pmt_t s_response_usrp_tx_write = pmt_intern("response-usrp-tx-write");
+
+usrp_tx_stub::usrp_tx_stub(mb_runtime *rt, const std::string &instance_name, 
pmt_t user_arg)
+  : mb_mblock(rt, instance_name, user_arg),
+    d_disk_write(false)
+{
+  d_cs = define_port("cs", "usrp-tx-cs", true, mb_port::EXTERNAL);
+  
+  d_disk_write=true;
+  
+  if(d_disk_write)
+    d_ofile.open("pdump.dat",std::ios::binary|std::ios::out);
+}
+
+usrp_tx_stub::~usrp_tx_stub() 
+{
+  if(d_disk_write)
+    d_ofile.close();
+}
+
+void 
+usrp_tx_stub::initial_transition()
+{
+  
+}
+
+void
+usrp_tx_stub::handle_message(mb_message_sptr msg)
+{
+  pmt_t event = msg->signal();
+  pmt_t port_id = msg->port_id();
+  pmt_t data = msg->data(); 
+
+  // Theoretically only have 1 message to ever expect, but
+  // want to make sure its at least what we want
+  if(pmt_eq(port_id, d_cs->port_symbol())) {
+    
+    if(pmt_eqv(event, s_cmd_usrp_tx_write))
+      write(data);
+  }
+}
+
+void
+usrp_tx_stub::write(pmt_t data)
+{
+  pmt_t invocation_handle = pmt_nth(0, data);
+  pmt_t channel = pmt_nth(1, data);
+  pmt_t v_packets = pmt_nth(2, data);
+  d_utx = boost::any_cast<usrp_standard_tx *>(pmt_any_ref(pmt_nth(3, data)));
+
+  size_t n_bytes;
+  bool underrun;  // this will need to go, as it is taken care of in the 
packet headers
+
+  if(d_disk_write) {
+    transport_pkt *pkts = (transport_pkt *) 
pmt_u8vector_writeable_elements(v_packets, n_bytes);
+    long n_packets = static_cast<long>(std::ceil(n_bytes / 
(double)transport_pkt::max_payload()));
+    
+    for(int i=0; i<(int)n_packets; i++) 
+      d_ofile.write((const char*) pkts[i].payload(), pkts[i].payload_len());
+  }
+
+  d_cs->send(s_response_usrp_tx_write,
+       pmt_list3(invocation_handle, PMT_T, channel));
+
+  return;
+}
+
+REGISTER_MBLOCK_CLASS(usrp_tx_stub);

Added: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.h
===================================================================
--- 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.h 
                            (rev 0)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_tx_stub.h 
    2007-06-05 15:43:50 UTC (rev 5690)
@@ -0,0 +1,56 @@
+/* -*- 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_TX_STUB_H
+#define INCLUDED_USRP_TX_STUB_H
+
+#include <mb_mblock.h>
+#include <vector>
+#include "usrp_standard.h"
+#include <fstream>
+
+/*!
+ * \brief Implements the low level usb interface to the USRP
+ */
+class usrp_tx_stub : public mb_mblock
+{
+ public:
+
+  mb_port_sptr d_cs;
+  usrp_standard_tx* d_utx;
+  
+  std::ofstream d_ofile;
+
+  bool d_disk_write;
+
+ public:
+  usrp_tx_stub(mb_runtime *rt, const std::string &instance_name, pmt_t 
user_arg);
+  ~usrp_tx_stub();
+  void initial_transition();
+  void handle_message(mb_message_sptr msg);
+
+ private:
+  void write(pmt_t data);
+ 
+};
+  
+
+#endif /* INCLUDED_USRP_TX_STUB_H */
+

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-05 15:17:55 UTC (rev 5689)
+++ 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface.cc
      2007-06-05 15:43:50 UTC (rev 5690)
@@ -30,6 +30,7 @@
 #include <usrp_inband_usb_packet.h>
 #include <fpga_regs_common.h>
 #include "usrp_rx.h"
+#include "usrp_tx.h"
 #include "usrp_standard.h"
 #include <stdio.h>
 
@@ -51,6 +52,8 @@
 // TX and RX signals
 static pmt_t s_cmd_usrp_rx_start_reading = 
pmt_intern("cmd-usrp-rx-start-reading");
 static pmt_t s_response_usrp_rx_read = pmt_intern("response-usrp-rx-read");
+static pmt_t s_cmd_usrp_tx_write = pmt_intern("cmd-usrp-tx-write");
+static pmt_t s_response_usrp_tx_write = pmt_intern("response-usrp-tx-write");
 
 static const bool verbose = false;
 
@@ -59,12 +62,46 @@
   : mb_mblock(rt, instance_name, user_arg),
   d_fpga_debug(false)
 {
+  // Dictionary for arguments to all of the components
+  pmt_t usrp_dict = user_arg;
+  
+  // Default TX/RX interface
+  std::string tx_interface = "usrp_tx";
+  std::string rx_interface = "usrp_rx";
+  
+  if (pmt_is_dict(usrp_dict)) {
+
+    if(pmt_dict_has_key(usrp_dict, pmt_intern("usrp-tx")))
+      tx_interface =
+        pmt_symbol_to_string(pmt_dict_ref(usrp_dict,
+            pmt_intern("usrp-tx"),
+            PMT_NIL));
+    
+    if(pmt_dict_has_key(usrp_dict, pmt_intern("usrp-rx")))
+      rx_interface =
+        pmt_symbol_to_string(pmt_dict_ref(usrp_dict,
+            pmt_intern("usrp-rx"),
+            PMT_NIL));
+  
+  }
+  
+  if (verbose) {
+    std::cout << "[USRP_USB_INTERFACE] Using TX interface: " 
+              << tx_interface << "\n";
+
+    std::cout << "[USRP_USB_INTERFACE] Using RX interface: " 
+              << rx_interface << "\n";
+  }
+
   d_cs = define_port("cs", "usrp-interface-cs", true, mb_port::EXTERNAL);      
   d_rx_cs = define_port("rx_cs", "usrp-rx-cs", false, mb_port::INTERNAL);      
+  d_tx_cs = define_port("tx_cs", "usrp-tx-cs", false, mb_port::INTERNAL);      
 
   // Connect to TX and RX
-  define_component("rx", "usrp_rx", PMT_F);
+  define_component("tx", tx_interface, PMT_F);
+  define_component("rx", rx_interface, PMT_F);
   connect("self", "rx_cs", "rx", "cs");
+  connect("self", "tx_cs", "tx", "cs");
   
   // FIX ME: the code should query the FPGA to retrieve the number of channels 
and such
   d_ntx_chan = 2;
@@ -144,16 +181,39 @@
 
     // Relay reads back up
     if(pmt_eq(event, s_response_usrp_rx_read))  {
+
+      pmt_t invocation_handle = pmt_nth(0, data);
+      pmt_t status = pmt_nth(1, data);
+      pmt_t samples = pmt_nth(2, data);
       d_cs->send(s_response_usrp_read,
-                 pmt_list3(PMT_NIL,
-                           PMT_T,
-                           pmt_nth(1,data))); // FIXME: clean
+                 pmt_list3(invocation_handle,
+                           status,
+                           samples));
       return;
     }
 
     goto unhandled;
   }
+  
+  //---------------- TX ------------------//
+  if (pmt_eq(port_id, d_tx_cs->port_symbol())) {       
 
+    if(pmt_eq(event, s_response_usrp_tx_write))  {
+
+      pmt_t invocation_handle = pmt_nth(0, data);
+      pmt_t status = pmt_nth(1, data);
+      pmt_t channel = pmt_nth(2, data);
+
+      d_cs->send(s_response_usrp_write,
+                 pmt_list3(invocation_handle,
+                           status,
+                           channel));
+      return;
+    }
+
+    goto unhandled;
+  }
+
  unhandled:
   std::cout << "[usrp_usb_interface] unhandled msg: " << msg << std::endl;
 }
@@ -251,35 +311,17 @@
 usrp_usb_interface::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);
-  
-  size_t n_bytes;
-  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, n_bytes);
+  pmt_t channel = pmt_nth(1, data);
+  pmt_t pkts = pmt_nth(2, data);
 
-  int ret = d_utx->write (pkts, n_bytes, &underrun);
+  pmt_t tx_handle = pmt_make_any(d_utx);
 
-  if (0 && underrun)
-    fprintf(stderr, "uU");
+  d_tx_cs->send(s_cmd_usrp_tx_write, 
+                pmt_list4(invocation_handle, 
+                          channel,
+                          pkts,
+                          tx_handle));
 
-  if (ret == (int) n_bytes) {
-    if (verbose)
-      std::cout << "[usrp_server] Write of " << n_bytes << " successful\n";
-    // need to respond with the channel so the USRP server knows who to 
forward the result of
-    // the write to by looking up the owner of the channel
-    d_cs->send(s_response_usrp_write,
-              pmt_list3(invocation_handle, pmt_from_long(channel), PMT_T));
-  }
-  else {
-    if (verbose)
-      std::cout << "[usrp_server] Error writing " << n_bytes << " bytes to USB 
bus\n";
-    // need to respond with the channel so the USRP server knows who to 
forward the result of
-    // the write to by looking up the owner of the channel
-    d_cs->send(s_response_usrp_write, pmt_list3(invocation_handle, 
pmt_from_long(channel), PMT_F));
-  }
-
   return;
 }
 

Deleted: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.cc

Deleted: 
gnuradio/branches/developers/gnychis/inband/usrp/host/lib/inband/usrp_usb_interface_stub.h





reply via email to

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