commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8627 - in usrp2/branches/features/host-ng/host-ng: ap


From: jcorgan
Subject: [Commit-gnuradio] r8627 - in usrp2/branches/features/host-ng/host-ng: apps include/usrp2 lib
Date: Thu, 19 Jun 2008 14:36:34 -0600 (MDT)

Author: jcorgan
Date: 2008-06-19 14:36:28 -0600 (Thu, 19 Jun 2008)
New Revision: 8627

Added:
   usrp2/branches/features/host-ng/host-ng/include/usrp2/tune_result.h
Modified:
   usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc
   usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am
   usrp2/branches/features/host-ng/host-ng/include/usrp2/usrp2.h
   usrp2/branches/features/host-ng/host-ng/lib/control.cc
   usrp2/branches/features/host-ng/host-ng/lib/control.h
   usrp2/branches/features/host-ng/host-ng/lib/usrp2.cc
   usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
   usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
Log:
Work-in-progress.  Now parsing command replies. Still needs reply timeouts and 
consolidate status parsing.

Modified: usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc  2008-06-19 
20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/apps/test_usrp2.cc  2008-06-19 
20:36:28 UTC (rev 8627)
@@ -21,6 +21,7 @@
 #endif
 
 #include <usrp2/usrp2.h>
+#include <usrp2/tune_result.h>
 #include <gr_realtime.h>
 #include <iostream>
 #include <string.h>
@@ -40,6 +41,7 @@
   fprintf(stderr, "  -h                   show this message and exit\n");
   fprintf(stderr, "  -e ETH_INTERFACE     specify ethernet interface 
[default=eth0]\n");
   fprintf(stderr, "  -m MAC_ADDR          mac address of USRP2 HH:HH 
[default=first one found]\n");
+  fprintf(stderr, "  -f FREQUENCY         specify receive center frequency in 
Hz [default=0.0]\n");
 }
 
 int
@@ -48,7 +50,8 @@
   // options and their defaults
   const char *interface = "eth0";
   const char *mac_addr_str = "";
-
+  double freq = 0.0;
+  
   int ch;
 
   while ((ch = getopt(argc, argv, "he:m:")) != EOF){
@@ -62,6 +65,10 @@
       mac_addr_str = optarg;
       break;
 
+    case 'f':
+      freq = optarg;
+      break;
+
     case 'h':
     default:
       usage(argv[0]);
@@ -75,13 +82,26 @@
 
   usrp2::usrp2::sptr u2 = usrp2::usrp2::make(interface, mac_addr_str);
   
-  u2->set_rx_gain(1.0);
-  u2->set_rx_freq(0.0, NULL);
-  u2->set_rx_decim(5);
-  u2->start_rx_streaming();
+  if (!u2->set_rx_gain(1.0))
+    exit(1);
+
+  usrp2::tune_result tr;
+  if (!u2->set_rx_freq(16e6, &tr))
+    exit(1);
+
+  printf("baseband_freq=%f\n", tr.baseband_freq);
+  printf("     ddc_freq=%f\n", tr.dxc_freq);
+  printf("residual_freq=%f\n", tr.residual_freq);
+  printf("     inverted=%s\n", tr.spectrum_inverted ? "yes" : "no");
   
+  if (!u2->set_rx_decim(5))
+    exit(1);
+    
+  if (!u2->start_rx_streaming())
+    exit(1);;
+  
   struct timespec ts;
-  ts.tv_sec = 10;
+  ts.tv_sec = 4;
   ts.tv_nsec = 0;
   int r = nanosleep(&ts, 0);
   if (r == -1)
@@ -89,7 +109,7 @@
   
   u2->stop_rx_streaming();
   
-  ts.tv_sec = 2;
+  ts.tv_sec = 1;
   r = nanosleep(&ts, 0);
   if (r == -1)
     perror("nanosleep");

Modified: usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am
===================================================================
--- usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am   
2008-06-19 20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/include/usrp2/Makefile.am   
2008-06-19 20:36:28 UTC (rev 8627)
@@ -24,4 +24,5 @@
 usrp2include_HEADERS = \
        copy_handler.h \
        data_handler.h \
+       tune_result.h \
        usrp2.h

Added: usrp2/branches/features/host-ng/host-ng/include/usrp2/tune_result.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/include/usrp2/tune_result.h         
                (rev 0)
+++ usrp2/branches/features/host-ng/host-ng/include/usrp2/tune_result.h 
2008-06-19 20:36:28 UTC (rev 8627)
@@ -0,0 +1,45 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2008 Free Software Foundation, Inc.
+ *
+ * This program 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_TUNE_RESULT_H
+#define INCLUDED_TUNE_RESULT_H
+
+namespace usrp2 {
+
+  class tune_result
+  {
+  public:
+    // RF frequency that corresponds to DC in the IF
+    double baseband_freq;
+
+    // frequency programmed into the DDC/DUC
+    double dxc_freq;
+
+    // residual frequency (typically < 0.01 Hz)
+    double residual_freq;
+
+    // is the spectrum inverted?
+    bool spectrum_inverted;
+
+    tune_result()
+      : baseband_freq(0), dxc_freq(0), residual_freq(0), 
spectrum_inverted(false) {}
+  };
+
+} // namespace usrp2
+
+#endif /* INCLUDED_TUNE_RESULT_H */

Modified: usrp2/branches/features/host-ng/host-ng/include/usrp2/usrp2.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/include/usrp2/usrp2.h       
2008-06-19 20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/include/usrp2/usrp2.h       
2008-06-19 20:36:28 UTC (rev 8627)
@@ -41,29 +41,8 @@
 
 props_vector_t find(const std::string &ifc, const std::string &addr=""); 
 
-/*!
- * Structure to hold results of tuning
- */
-class usrp2_tune_result
-{
-public:
-  // RF frequency that corresponds to DC in the IF
-  double baseband_freq;
+class tune_result;
 
-  // frequency programmed into the DDC/DUC
-  double dxc_freq;
-
-  // residual frequency (typically < 0.01 Hz)
-  double residual_freq;
-
-  // is the spectrum inverted?
-  bool  spectrum_inverted;
-
-  usrp2_tune_result()
-    : baseband_freq(0), dxc_freq(0), residual_freq(0), 
spectrum_inverted(false) {}
-  ~usrp2_tune_result();
-};
-
 class usrp2 : boost::noncopyable
 {
 public:
@@ -98,7 +77,7 @@
   /*!
    * Set receiver center frequency
    */
-  bool set_rx_freq(double frequency, usrp2_tune_result *result);
+  bool set_rx_freq(double frequency, tune_result *result);
 
   /*!
    * Set receiver sample rate decimation

Modified: usrp2/branches/features/host-ng/host-ng/lib/control.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/control.cc      2008-06-19 
20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/lib/control.cc      2008-06-19 
20:36:28 UTC (rev 8627)
@@ -28,7 +28,7 @@
 
 namespace usrp2 {
 
-  pending_reply::pending_reply(int rid, void *buffer, int len)
+  pending_reply::pending_reply(unsigned int rid, void *buffer, unsigned int 
len)
     : d_rid(rid), d_mutex(), d_cond(&d_mutex), d_buffer(buffer), d_len(len)
   {
   }

Modified: usrp2/branches/features/host-ng/host-ng/lib/control.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/control.h       2008-06-19 
20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/lib/control.h       2008-06-19 
20:36:28 UTC (rev 8627)
@@ -57,18 +57,18 @@
   class pending_reply
   {
   private:
-    int             d_rid;
+    unsigned int    d_rid;
     omni_mutex      d_mutex;
     omni_condition  d_cond;
     void           *d_buffer;
-    int             d_len;
+    unsigned int    d_len;
 
   public:  
     /*!
      * Construct a pending reply from the reply ID, response packet
      * buffer, and buffer length.
      */
-    pending_reply(int rid, void *buffer, int len);
+    pending_reply(unsigned int rid, void *buffer, unsigned int len);
 
     /*!
      * Destructor. Signals creating thread.
@@ -90,12 +90,17 @@
     /*!
      * Retrieve pending reply ID
      */
-    int rid() const { return d_rid; }
+    unsigned int rid() const { return d_rid; }
 
     /*!
      * Retrieve destination buffer address
      */
     void *buffer() const { return d_buffer; }
+
+   /*!
+    * Retrieve destinateion buffer length
+    */
+    unsigned int len() const { return d_len; }
   };
   
 } // namespace usrp2

Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2.cc        2008-06-19 
20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2.cc        2008-06-19 
20:36:28 UTC (rev 8627)
@@ -52,7 +52,7 @@
   }
   
   bool
-  usrp2::set_rx_freq(double frequency, usrp2_tune_result *result)
+  usrp2::set_rx_freq(double frequency, tune_result *result)
   {
     return d_impl->set_rx_freq(frequency, result);
   }

Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc   2008-06-19 
20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc   2008-06-19 
20:36:28 UTC (rev 8627)
@@ -21,6 +21,7 @@
 #endif
 
 #include <usrp2/usrp2.h>
+#include <usrp2/tune_result.h>
 #include <usrp2_types.h>
 #include "usrp2_impl.h"
 #include "usrp2_thread.h"
@@ -173,7 +174,7 @@
     init_etf_hdrs(&cmd->h, d_addr, 0, CONTROL_CHAN, -1);
     cmd->op.opcode = OP_CONFIG_RX_V2;
     cmd->op.len = sizeof(cmd->op);
-    cmd->op.rid = d_next_rid++; // TODO: reserve rid=0
+    cmd->op.rid = d_next_rid++;
     cmd->eop.opcode = OP_EOP;
     cmd->eop.len = sizeof(cmd->eop);
   }
@@ -181,6 +182,9 @@
   bool 
   usrp2::impl::set_rx_gain(double gain)
   {
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << "usrp2: setting rx gain to " << gain << "...";
+
     op_config_rx_v2_cmd cmd;
     op_config_rx_reply_v2_t reply;
 
@@ -192,13 +196,18 @@
     if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
       return false;
 
-    // Process reply here
-    return true;
+    bool success = (ntohs(reply.ok) == 1);
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << (success ? "ok." : "fail.") << std::endl;
+    return success;
   }
   
   bool
-  usrp2::impl::set_rx_freq(double frequency, usrp2_tune_result *result)
+  usrp2::impl::set_rx_freq(double frequency, tune_result *result)
   {
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << "usrp2: setting rx freq to " << frequency << "...";
+
     op_config_rx_v2_cmd cmd;
     op_config_rx_reply_v2_t reply;
 
@@ -212,13 +221,38 @@
     if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
       return false;
 
-    // Process reply here
-    return true;
+    bool success = (ntohs(reply.ok) == 1);
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << (success ? "ok." : "fail.") << std::endl;
+
+    if (result && success) {
+      result->baseband_freq =
+        u2_fxpt_freq_to_double( 
+          u2_fxpt_freq_from_hilo(ntohl(reply.baseband_freq_hi), 
+                                ntohl(reply.baseband_freq_lo)));
+
+      result->dxc_freq =
+        u2_fxpt_freq_to_double( 
+          u2_fxpt_freq_from_hilo(ntohl(reply.ddc_freq_hi), 
+                                ntohl(reply.ddc_freq_lo)));
+
+      result->residual_freq =
+        u2_fxpt_freq_to_double( 
+          u2_fxpt_freq_from_hilo(ntohl(reply.residual_freq_hi), 
+                                ntohl(reply.residual_freq_lo)));
+
+      result->spectrum_inverted = (bool)(ntohs(reply.inverted) == 1);
+    }
+
+    return success;
   }
   
   bool
   usrp2::impl::set_rx_decim(int decimation_factor)
   {
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << "usrp2: setting rx decimation to " << decimation_factor << 
"...";
+
     op_config_rx_v2_cmd cmd;
     op_config_rx_reply_v2_t reply;
 
@@ -230,13 +264,19 @@
     if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
       return false;
 
-    // Process reply here
-    return true;
+    bool success = (ntohs(reply.ok) == 1);
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << (success ? "ok." : "fail.") << std::endl;
+    return success;
   }
   
   bool
   usrp2::impl::set_rx_scale_iq(int scale_i, int scale_q)
   {
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << "usrp2: setting rx scale to ("
+                << scale_i << ", " << scale_q << ")...";
+
     op_config_rx_v2_cmd cmd;
     op_config_rx_reply_v2_t reply;
 
@@ -248,55 +288,69 @@
     if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
       return false;
 
-    // Process reply here
-    return true;
+    bool success = (ntohs(reply.ok) == 1);
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << (success ? "ok." : "fail.") << std::endl;
+    return success;
   }
   
   bool
   usrp2::impl::start_rx_streaming(unsigned int items_per_frame)
   {
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << "usrp2: starting rx streaming...";
+
     // Assume for now rx format is complex floats
     if (items_per_frame == 0)
       items_per_frame = 250; // TODO: calculate from d_itemsize;
     
     op_start_rx_streaming_cmd cmd;
-    //op_start_rx_streaming_reply_t reply;
+    op_generic_t reply;
 
     memset(&cmd, 0, sizeof(cmd));
     init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
     cmd.op.opcode = OP_START_RX_STREAMING;
     cmd.op.len = sizeof(cmd.op);
+    cmd.op.rid = d_next_rid++;
     cmd.op.items_per_frame = htonl(items_per_frame);
     cmd.eop.opcode = OP_EOP;
     cmd.eop.len = sizeof(cmd.eop);
     
-    //pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), NULL))
+    pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
       return false;
 
-    // Process reply here
-    return true;
+    bool success = (reply.ok == 1);
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << (success ? "ok." : "fail.") << std::endl;
+    return success;
   }
   
   bool
   usrp2::impl::stop_rx_streaming()
   {
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << "usrp2: stopping rx streaming...";
+
     op_stop_rx_cmd cmd;
-    //op_stop_rx_reply_t reply;
+    op_generic_t reply;
 
     memset(&cmd, 0, sizeof(cmd));
     init_etf_hdrs(&cmd.h, d_addr, 0, CONTROL_CHAN, -1);
     cmd.op.opcode = OP_STOP_RX;
     cmd.op.len = sizeof(cmd.op);
+    cmd.op.rid = d_next_rid++;
     cmd.eop.opcode = OP_EOP;
     cmd.eop.len = sizeof(cmd.eop);
     
-    //pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), NULL))
+    pending_reply p(cmd.op.rid, &reply, sizeof(reply));
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
       return false;
 
-    // Process reply here
-    return true;
+    bool success = (reply.ok == 1);
+    if (USRP2_IMPL_DEBUG)
+      std::cerr << (success ? "ok." : "fail.") << std::endl;
+    return success;
   }
   
   void
@@ -369,13 +423,21 @@
     // subpacket, when (if?) the firmware starts sending them
     
     //int opcode = p[0];
-    //int oplen = p[1];
-    int rid = p[2];
-
+    unsigned int oplen = p[1];
+    unsigned int rid = p[2];
     omni_mutex_lock l(d_reply_mutex);
     pending_reply_iter_t rp;
     for (rp = d_pending_replies.begin(); rp != d_pending_replies.end(); rp++) {
       if ((*rp)->rid() == rid) {
+       unsigned int buflen = (*rp)->len();
+       if (oplen != buflen) {
+          std::cerr << "usrp2: mismatched command reply length ("
+                   << oplen << " != " << buflen << ")"
+                   << std::endl;
+       }     
+    
+       // Copy reply into caller's buffer
+       memcpy((*rp)->buffer(), p, std::min(oplen, buflen));
         DEBUG_LOG("s"); // pending blocked thread condition variable signaled
        (*rp)->signal();
        d_pending_replies.erase(rp);
@@ -383,7 +445,7 @@
       }
     }
 
-    // TODO: handle unsolicited or late replies
+    // TODO: handle unsolicited, USRP2 initiated, or late replies
     DEBUG_LOG("l");
     return 0; // release packet
   }

Modified: usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h    2008-06-19 
20:28:51 UTC (rev 8626)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h    2008-06-19 
20:36:28 UTC (rev 8627)
@@ -72,7 +72,7 @@
     
     void bg_loop();
     bool set_rx_gain(double gain);
-    bool set_rx_freq(double frequency, usrp2_tune_result *result);
+    bool set_rx_freq(double frequency, tune_result *result);
     bool set_rx_decim(int decimation_factor);
     bool set_rx_scale_iq(int scale_i, int scale_q);
     bool start_rx_streaming(unsigned int items_per_frame);





reply via email to

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