summaryrefslogtreecommitdiff
path: root/gr-uhd/lib/usrp_common.h
diff options
context:
space:
mode:
Diffstat (limited to 'gr-uhd/lib/usrp_common.h')
-rw-r--r--gr-uhd/lib/usrp_common.h47
1 files changed, 28 insertions, 19 deletions
diff --git a/gr-uhd/lib/usrp_common.h b/gr-uhd/lib/usrp_common.h
index f7fead4f5c..732bcef63c 100644
--- a/gr-uhd/lib/usrp_common.h
+++ b/gr-uhd/lib/usrp_common.h
@@ -28,6 +28,7 @@
#include <boost/make_shared.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/convert.hpp>
+#include <iostream>
namespace gr {
namespace uhd {
@@ -35,27 +36,35 @@ namespace gr {
//! Helper function for msg_handler_command:
// - Extracts command and the command value from the command PMT
// - Returns true if the command PMT is well formed
- // - If a channel is given, return that as well, otherwise return -1
+ // - If a channel is given, return that as well, otherwise set the channel to -1
static bool _unpack_chan_command(
- std::string &command,
- pmt::pmt_t &cmd_val,
- int &chan,
- const pmt::pmt_t &cmd_pmt
+ std::string &command,
+ pmt::pmt_t &cmd_val,
+ int &chan,
+ const pmt::pmt_t &cmd_pmt
) {
- chan = -1; // Default value
- if (pmt::is_tuple(cmd_pmt) and (pmt::length(cmd_pmt) == 2 or pmt::length(cmd_pmt) == 3)) {
- command = pmt::symbol_to_string(pmt::tuple_ref(cmd_pmt, 0));
- cmd_val = pmt::tuple_ref(cmd_pmt, 1);
- if (pmt::length(cmd_pmt) == 3) {
- chan = pmt::to_long(pmt::tuple_ref(cmd_pmt, 1));
- }
- }
- else if (pmt::is_pair(cmd_pmt)) {
- command = pmt::symbol_to_string(pmt::car(cmd_pmt));
- cmd_val = pmt::car(cmd_pmt);
- }
- else {
- return false;
+ try {
+ chan = -1; // Default value
+ if (pmt::is_tuple(cmd_pmt) and (pmt::length(cmd_pmt) == 2 or pmt::length(cmd_pmt) == 3)) {
+ command = pmt::symbol_to_string(pmt::tuple_ref(cmd_pmt, 0));
+ cmd_val = pmt::tuple_ref(cmd_pmt, 1);
+ if (pmt::length(cmd_pmt) == 3) {
+ chan = pmt::to_long(pmt::tuple_ref(cmd_pmt, 2));
+ }
+ }
+ else if (pmt::is_pair(cmd_pmt)) {
+ command = pmt::symbol_to_string(pmt::car(cmd_pmt));
+ cmd_val = pmt::cdr(cmd_pmt);
+ if (pmt::is_pair(cmd_val)) {
+ chan = pmt::to_long(pmt::car(cmd_val));
+ cmd_val = pmt::cdr(cmd_val);
+ }
+ }
+ else {
+ return false;
+ }
+ } catch (pmt::wrong_type w) {
+ return false;
}
return true;
}