Merge branch 'maint'
[debian/gnuradio] / gr-usrp2 / src / usrp2_sink_16sc.cc
index bbd85563c8e5dea28e107a80e9df8f651f2fa491..75cc1f4a6bebb5857ce4fe1ee9df03f2f8680c5c 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #ifdef HAVE_CONFIG_H
-#include "config.h"
+#include <config.h>
 #endif
 
 #include <usrp2_sink_16sc.h>
 #include <gr_io_signature.h>
 #include <iostream>
 
+// FIXME hack until VRT replaces libusrp2
+#define U2_MIN_SAMPLES 9
+
 usrp2_sink_16sc_sptr
 usrp2_make_sink_16sc(const std::string &ifc, const std::string &mac_addr) 
   throw (std::runtime_error)
 {
-  return usrp2_sink_16sc_sptr(new usrp2_sink_16sc(ifc, mac_addr));
+  return gnuradio::get_initial_sptr(new usrp2_sink_16sc(ifc, mac_addr));
 }
 
 usrp2_sink_16sc::usrp2_sink_16sc(const std::string &ifc, const std::string &mac_addr) 
@@ -57,15 +60,31 @@ usrp2_sink_16sc::work(int noutput_items,
 {
   std::complex<int16_t> *in = (std::complex<int16_t> *)input_items[0];
 
+  // FIXME: Current libusrp2 can't handle short packets.
+  // Returning 0 assumes there will be more samples
+  // the next round...
+  if (noutput_items < U2_MIN_SAMPLES)
+    return 0;
+
   usrp2::tx_metadata metadata;
-  metadata.timestamp = -1;
-  metadata.send_now = 1;
+
+  // Set TX metadata to either start time or now
+  if (d_should_wait == true) {
+    metadata.timestamp = d_tx_time;
+    metadata.send_now = 0;
+    d_should_wait = false;
+  }
+  else {
+    metadata.timestamp = -1;
+    metadata.send_now = 1;
+  }
   metadata.start_of_burst = 1;
 
-  bool ok = d_u2->tx_16sc(0,  // FIXME: someday, streams will have channel numbers
-                         in, noutput_items, &metadata);
-  if (!ok)
-    std::cerr << "usrp2_sink_16sc: tx_complex_int16 failed" << std::endl;
+  bool ok = d_u2->tx_16sc(0, in, noutput_items, &metadata);
+  if (!ok){
+    std::cerr << "usrp2_sink_16sc: tx_16sc failed" << std::endl;
+    return -1; // say we're done
+  }
 
   return noutput_items;
 }