commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8653 - usrp2/branches/features/host-ng/host-ng/lib


From: jcorgan
Subject: [Commit-gnuradio] r8653 - usrp2/branches/features/host-ng/host-ng/lib
Date: Sun, 22 Jun 2008 15:25:21 -0600 (MDT)

Author: jcorgan
Date: 2008-06-22 15:25:21 -0600 (Sun, 22 Jun 2008)
New Revision: 8653

Modified:
   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_impl.cc
   usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h
Log:
Implement command timeouts

Modified: usrp2/branches/features/host-ng/host-ng/lib/control.cc
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/control.cc      2008-06-22 
20:17:25 UTC (rev 8652)
+++ usrp2/branches/features/host-ng/host-ng/lib/control.cc      2008-06-22 
21:25:21 UTC (rev 8653)
@@ -23,6 +23,7 @@
 #include <config.h>
 #endif
 
+#include <omni_time.h>
 #include "control.h"
 #include <iostream>
 
@@ -35,16 +36,15 @@
 
   pending_reply::~pending_reply()
   {
-    signal();
+    signal(); // Needed?
   }
 
   int
-  pending_reply::wait(unsigned int msecs)
+  pending_reply::wait(double secs)
   {
-    // TODO: implement timeout by using timedwait()
     omni_mutex_lock l(d_mutex);
-    d_cond.wait();
-    return 1;
+    omni_time abs_timeout = omni_time::time(omni_time(secs));
+    return d_cond.timedwait(abs_timeout.d_secs, abs_timeout.d_nsecs);
   }
 
   void

Modified: usrp2/branches/features/host-ng/host-ng/lib/control.h
===================================================================
--- usrp2/branches/features/host-ng/host-ng/lib/control.h       2008-06-22 
20:17:25 UTC (rev 8652)
+++ usrp2/branches/features/host-ng/host-ng/lib/control.h       2008-06-22 
21:25:21 UTC (rev 8653)
@@ -50,10 +50,6 @@
   /*!
    * Control mechanism to allow API calls to block waiting for reply packets
    */    
-  class pending_reply;
-  typedef std::list<pending_reply *> pending_reply_list_t;
-  typedef pending_reply_list_t::iterator pending_reply_iter_t;
-
   class pending_reply
   {
   private:
@@ -80,7 +76,7 @@
      * Returns: 1 = ok, reply packet in buffer
      *          0 = timeout
      */
-    int wait(unsigned int msecs);
+    int wait(double secs);
 
     /*!
      * Allows creating thread to resume after copying reply into buffer
@@ -98,7 +94,7 @@
     void *buffer() const { return d_buffer; }
 
     /*!
-     * Retrieve destinateion buffer length
+     * Retrieve destination buffer length
      */
     size_t len() const { return d_len; }
   };

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-22 
20:17:25 UTC (rev 8652)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.cc   2008-06-22 
21:25:21 UTC (rev 8653)
@@ -194,7 +194,7 @@
     cmd.op.gain = htons(u2_double_to_fxpt_gain(gain));
     
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
       return false;
 
     bool success = (ntohs(reply.ok) == 1);
@@ -219,7 +219,7 @@
     cmd.op.freq_lo = htonl(u2_fxpt_freq_lo(fxpt));
     
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
       return false;
 
     bool success = (ntohs(reply.ok) == 1);
@@ -262,7 +262,7 @@
     cmd.op.decim = htonl(decimation_factor);
     
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
       return false;
 
     bool success = (ntohs(reply.ok) == 1);
@@ -286,7 +286,7 @@
     cmd.op.scale_iq = htonl(((scale_i & 0xffff) << 16) | (scale_q & 0xffff));
     
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
       return false;
 
     bool success = (ntohs(reply.ok) == 1);
@@ -317,7 +317,7 @@
     cmd.eop.len = sizeof(cmd.eop);
     
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
       return false;
 
     bool success = (reply.ok == 1);
@@ -344,7 +344,7 @@
     cmd.eop.len = sizeof(cmd.eop);
     
     pending_reply p(cmd.op.rid, &reply, sizeof(reply));
-    if (!transmit_cmd(&cmd, sizeof(cmd), &p, 100))
+    if (!transmit_cmd(&cmd, sizeof(cmd), &p, DEF_CMD_TIMEOUT))
       return false;
 
     bool success = (reply.ok == 1);
@@ -383,20 +383,23 @@
   }
 
   bool
-  usrp2::impl::transmit_cmd(void *cmd, int len, pending_reply *p, unsigned int 
msecs)
+  usrp2::impl::transmit_cmd(void *cmd, int len, pending_reply *p, double secs)
   {
     if (p)    
       d_pending_replies[p->rid()] = p;
     
     // Transmit command
-    if (d_buffer->tx_frame(cmd, len) != 1)
+    if (d_buffer->tx_frame(cmd, len) != 1) {
+      d_pending_replies[p->rid()] = 0;
       return false;
+    }
 
-    if (p && msecs > 0)
-      if (p->wait(msecs) == 0)
-        return false;
-
-    return true;
+    int res = 1;
+    if (p)
+      res = p->wait(secs);
+      
+    d_pending_replies[p->rid()] = 0;
+    return res == 1;
   }
 
   data_handler::result

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-22 
20:17:25 UTC (rev 8652)
+++ usrp2/branches/features/host-ng/host-ng/lib/usrp2_impl.h    2008-06-22 
21:25:21 UTC (rev 8653)
@@ -23,10 +23,11 @@
 #include <usrp2/data_handler.h>
 #include <usrp2_eth_packet.h>
 #include "control.h"
-
 #include <string>
-#include <list>
 
+#define NRIDS 256
+#define DEF_CMD_TIMEOUT 0.1 // seconds
+
 namespace usrp2 {
   
   class eth_buffer;
@@ -51,7 +52,7 @@
     unsigned int  d_num_rx_lost;
     unsigned int  d_num_rx_bytes;
     
-    pending_reply *d_pending_replies[256]; // indexed by 8-bit reply id
+    pending_reply *d_pending_replies[NRIDS]; // indexed by 8-bit reply id
 
     static bool parse_mac_addr(const std::string &s, u2_mac_addr_t *p);
     void init_et_hdrs(u2_eth_packet_t *p, const std::string &dst);
@@ -59,7 +60,7 @@
                       int word0_flags, int chan, uint32_t timestamp);
     void stop_bg();
     void init_config_rx_v2_cmd(op_config_rx_v2_cmd *cmd);
-    bool transmit_cmd(void *cmd, int len, pending_reply *p, unsigned int 
msecs=0);
+    bool transmit_cmd(void *cmd, int len, pending_reply *p, double secs=0.0);
     virtual data_handler::result operator()(const void *base, size_t len);
     data_handler::result handle_control_packet(const void *base, size_t len);
     data_handler::result handle_data_packet(const void *base, size_t len);





reply via email to

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