/* -*- c++ -*- */ /* * Copyright 2017 <+YOU OR YOUR COMPANY+>. * * This 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, or (at your option) * any later version. * * This software 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 software; see the file COPYING. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include "freqShift_impl.h" namespace gr { namespace multiaperture { freqShift::sptr freqShift::make( const gr::ettus::device3::sptr &dev, const ::uhd::stream_args_t &tx_stream_args, const ::uhd::stream_args_t &rx_stream_args, const int block_select, const int device_select ) { return gnuradio::get_initial_sptr( new freqShift_impl( dev, tx_stream_args, rx_stream_args, block_select, device_select ) ); } /* * The private constructor */ freqShift_impl::freqShift_impl( const gr::ettus::device3::sptr &dev, const ::uhd::stream_args_t &tx_stream_args, const ::uhd::stream_args_t &rx_stream_args, const int block_select, const int device_select ) : gr::ettus::rfnoc_block("freqShift"), gr::ettus::rfnoc_block_impl( dev, gr::ettus::rfnoc_block_impl::make_block_id("freqShift", block_select, device_select), tx_stream_args, rx_stream_args ) { //JJM 5/17/2017 message_port_register_in(pmt::mp("cfg")); set_msg_handler( pmt::mp("cfg"), boost::bind(&freqShift_impl::handle_cfg_message, this, _1) ); } /* * Our virtual destructor. */ freqShift_impl::~freqShift_impl() { } //JJM 5/3/2017 void freqShift_impl::handle_cfg_message(pmt::pmt_t msg) { /* If the PMT is a list, assume it's a list of pairs and recurse for each */ /* Works for dict too */ try { /* Because of PMT is just broken you and can't distinguish between * pair and dict, we have to call length() and see if it will throw * or not ... */ if (pmt::length(msg) > 0) { for (int i=0; ihandle_cfg_message(pmt::nth(i, msg)); return; } } catch(...) { } /* Handle the pairs */ if (pmt::is_pair(msg)) { pmt::pmt_t key(pmt::car(msg)); pmt::pmt_t val(pmt::cdr(msg)); int val_i; if (!pmt::is_symbol(key) || !pmt::is_integer(val)) return; val_i = pmt::to_long(val); try { const std::string key_str = pmt::symbol_to_string(key); this->set_arg(key_str, val_i); } catch (...) { GR_LOG_ERROR(d_logger, boost::format("Cannot set RFNoC block argument '%s'") % key); } } } } /* namespace multiaperture */ } /* namespace gr */