aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2017-04-21 00:07:22 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2017-04-21 00:07:22 +0200
commit1810a2c6a34207caedf5a88bc4e5d38080e764ed (patch)
treeb6a6074b8c9ee47881330256dd002f76fb26029b /src
parent156ee71cbb3c94d5d77a5afcc376cd512ce8fe9d (diff)
downloaddabmod-1810a2c6a34207caedf5a88bc4e5d38080e764ed.tar.gz
dabmod-1810a2c6a34207caedf5a88bc4e5d38080e764ed.tar.bz2
dabmod-1810a2c6a34207caedf5a88bc4e5d38080e764ed.zip
Put UHD async msg to separate thread
Diffstat (limited to 'src')
-rw-r--r--src/OutputUHD.cpp110
-rw-r--r--src/OutputUHD.h6
2 files changed, 62 insertions, 54 deletions
diff --git a/src/OutputUHD.cpp b/src/OutputUHD.cpp
index e4b57bc..6679e62 100644
--- a/src/OutputUHD.cpp
+++ b/src/OutputUHD.cpp
@@ -780,21 +780,6 @@ void UHDWorker::handle_frame(const struct UHDWorkerFrameData *frame)
}
tx_frame(frame, timestamp_discontinuity);
-
- auto time_now = std::chrono::steady_clock::now();
- if (last_print_time + std::chrono::seconds(1) < time_now) {
- if (num_underflows or num_late_packets) {
- etiLog.log(info,
- "OutputUHD status (usrp time: %f): "
- "%d underruns and %d late packets since last status.\n",
- usrp_time,
- num_underflows, num_late_packets);
- }
- num_underflows = 0;
- num_late_packets = 0;
-
- last_print_time = time_now;
- }
}
void UHDWorker::tx_frame(const struct UHDWorkerFrameData *frame, bool ts_update)
@@ -834,51 +819,70 @@ void UHDWorker::tx_frame(const struct UHDWorkerFrameData *frame, bool ts_update)
"UHDWorker::process() unable to write to device, skipping frame!\n");
break;
}
-
- print_async_metadata(frame);
}
}
-void UHDWorker::print_async_metadata(const struct UHDWorkerFrameData *frame)
+void UHDWorker::print_async_metadata()
{
- uhd::async_metadata_t async_md;
- if (uwd->myUsrp->get_device()->recv_async_msg(async_md, 0)) {
- const char* uhd_async_message = "";
- bool failure = false;
- switch (async_md.event_code) {
- case uhd::async_metadata_t::EVENT_CODE_BURST_ACK:
- break;
- case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW:
- uhd_async_message = "Underflow";
- num_underflows++;
- break;
- case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR:
- uhd_async_message = "Packet loss between host and device.";
- failure = true;
- break;
- case uhd::async_metadata_t::EVENT_CODE_TIME_ERROR:
- uhd_async_message = "Packet had time that was late.";
- num_late_packets++;
- break;
- case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET:
- uhd_async_message = "Underflow occurred inside a packet.";
- failure = true;
- break;
- case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST:
- uhd_async_message = "Packet loss within a burst.";
- failure = true;
- break;
- default:
- uhd_async_message = "unknown event code";
- failure = true;
- break;
+ while (uwd->running) {
+ uhd::async_metadata_t async_md;
+ if (uwd->myUsrp->get_device()->recv_async_msg(async_md, 1)) {
+ const char* uhd_async_message = "";
+ bool failure = false;
+ switch (async_md.event_code) {
+ case uhd::async_metadata_t::EVENT_CODE_BURST_ACK:
+ break;
+ case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW:
+ uhd_async_message = "Underflow";
+ num_underflows++;
+ break;
+ case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR:
+ uhd_async_message = "Packet loss between host and device.";
+ failure = true;
+ break;
+ case uhd::async_metadata_t::EVENT_CODE_TIME_ERROR:
+ uhd_async_message = "Packet had time that was late.";
+ num_late_packets++;
+ break;
+ case uhd::async_metadata_t::EVENT_CODE_UNDERFLOW_IN_PACKET:
+ uhd_async_message = "Underflow occurred inside a packet.";
+ failure = true;
+ break;
+ case uhd::async_metadata_t::EVENT_CODE_SEQ_ERROR_IN_BURST:
+ uhd_async_message = "Packet loss within a burst.";
+ failure = true;
+ break;
+ default:
+ uhd_async_message = "unknown event code";
+ failure = true;
+ break;
+ }
+
+ if (failure) {
+ etiLog.level(alert) <<
+ "Received Async UHD Message '" <<
+ uhd_async_message << "' at time " <<
+ md.time_spec.get_real_secs();
+
+ }
}
- if (failure) {
- etiLog.level(alert) << "Near frame " <<
- frame->ts.fct << ": Received Async UHD Message '" <<
- uhd_async_message << "'";
+ auto time_now = std::chrono::steady_clock::now();
+ if (last_print_time + std::chrono::seconds(1) < time_now) {
+ const double usrp_time =
+ uwd->myUsrp->get_time_now().get_real_secs();
+
+ if (num_underflows or num_late_packets) {
+ etiLog.log(info,
+ "OutputUHD status (usrp time: %f): "
+ "%d underruns and %d late packets since last status.\n",
+ usrp_time,
+ num_underflows, num_late_packets);
+ }
+ num_underflows = 0;
+ num_late_packets = 0;
+ last_print_time = time_now;
}
}
}
diff --git a/src/OutputUHD.h b/src/OutputUHD.h
index cbf159f..d42245f 100644
--- a/src/OutputUHD.h
+++ b/src/OutputUHD.h
@@ -125,6 +125,8 @@ class UHDWorker {
void start(struct UHDWorkerData *uhdworkerdata) {
uwd->running = true;
uhd_thread = boost::thread(&UHDWorker::process_errhandler, this);
+ async_rx_thread = boost::thread(
+ &UHDWorker::print_async_metadata, this);
}
void stop() {
@@ -133,6 +135,7 @@ class UHDWorker {
}
uhd_thread.interrupt();
uhd_thread.join();
+ async_rx_thread.join();
}
~UHDWorker() {
@@ -155,13 +158,14 @@ class UHDWorker {
// Used to print statistics once a second
std::chrono::steady_clock::time_point last_print_time;
- void print_async_metadata(const struct UHDWorkerFrameData *frame);
+ void print_async_metadata(void);
void handle_frame(const struct UHDWorkerFrameData *frame);
void tx_frame(const struct UHDWorkerFrameData *frame, bool ts_update);
struct UHDWorkerData *uwd;
boost::thread uhd_thread;
+ boost::thread async_rx_thread;
uhd::tx_streamer::sptr myTxStream;