diff options
Diffstat (limited to 'gr-uhd')
-rw-r--r-- | gr-uhd/grc/uhd_simple_source.xml | 43 | ||||
-rw-r--r-- | gr-uhd/lib/uhd_simple_source.cc | 6 | ||||
-rw-r--r-- | gr-uhd/lib/utils.cc | 49 | ||||
-rw-r--r-- | gr-uhd/lib/utils.h | 30 |
4 files changed, 126 insertions, 2 deletions
diff --git a/gr-uhd/grc/uhd_simple_source.xml b/gr-uhd/grc/uhd_simple_source.xml new file mode 100644 index 000000000..90bde1cd3 --- /dev/null +++ b/gr-uhd/grc/uhd_simple_source.xml @@ -0,0 +1,43 @@ +<?xml version="1.0"?> +<!-- +################################################### +## UHD Simple Source +################################################### + --> +<block> + <name>UHD Simple Source</name> + <key>uhd_simple_source</key> + <category>UHD</category> + <import>from gnuradio import uhd</import> + <make>uhd.simple_source($args, "$type.type")</make> + <param> + <name>Output Type</name> + <key>type</key> + <type>enum</type> + <option> + <name>Complex</name> + <key>complex</key> + <opt>type:32fc</opt> + <opt>vlen:1</opt> + </option> + <option> + <name>Short</name> + <key>short</key> + <opt>type:16sc</opt> + <opt>vlen:2</opt> + </option> + </param> + <param> + <name>Args</name> + <key>args</key> + <value></value> + <type>string</type> + </param> + <source> + <name>out</name> + <type>$type</type> + <vlen>$type.vlen</vlen> + </source> + <doc> + </doc> +</block> diff --git a/gr-uhd/lib/uhd_simple_source.cc b/gr-uhd/lib/uhd_simple_source.cc index 4bd3622f3..360b91434 100644 --- a/gr-uhd/lib/uhd_simple_source.cc +++ b/gr-uhd/lib/uhd_simple_source.cc @@ -92,10 +92,12 @@ int uhd_simple_source::work( gr_vector_void_star &output_items ){ + const size_t max_samples = wax::cast<size_t>((*_dev)[uhd::DEVICE_PROP_MAX_RX_SAMPLES]); + size_t total_items_read = 0; size_t count = 0; uhd::metadata_t metadata; - while(total_items_read == 0 or total_items_read + 1500/_sizeof_samp < size_t(noutput_items)){ + while(total_items_read == 0 or total_items_read + max_samples < size_t(noutput_items)){ size_t items_read = _dev->recv( boost::asio::buffer( (uint8_t *)output_items[0]+(total_items_read*_sizeof_samp), @@ -114,7 +116,7 @@ int uhd_simple_source::work( //the timeout part boost::this_thread::sleep(boost::posix_time::milliseconds(1)); - count++; if (count > 50) break; + if (++count > 50) break; } return total_items_read; diff --git a/gr-uhd/lib/utils.cc b/gr-uhd/lib/utils.cc new file mode 100644 index 000000000..6b2121064 --- /dev/null +++ b/gr-uhd/lib/utils.cc @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#include "utils.h" +#include <boost/algorithm/string.hpp> +#include <boost/algorithm/string/trim.hpp> +#include <boost/foreach.hpp> + +static std::string trim(const std::string &in){ + return boost::algorithm::trim_copy(in); +} + +uhd::device_addr_t args_to_device_addr(const std::string &args){ + uhd::device_addr_t addr; + + //split the args at the semi-colons + std::vector<std::string> pairs; + boost::split(pairs, args, boost::is_any_of(";")); + BOOST_FOREACH(std::string pair, pairs){ + if (trim(pair) == "") continue; + + //split the key value pairs at the equals + std::vector<std::string> key_val; + boost::split(key_val, pair, boost::is_any_of("=")); + if (key_val.size() != 2) throw std::runtime_error("invalid args string: "+args); + addr[trim(key_val[0])] = trim(key_val[1]); + } + + return addr; +} diff --git a/gr-uhd/lib/utils.h b/gr-uhd/lib/utils.h new file mode 100644 index 000000000..7530faba2 --- /dev/null +++ b/gr-uhd/lib/utils.h @@ -0,0 +1,30 @@ +/* -*- c++ -*- */ +/* + * Copyright 2010 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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. + * + * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, + * Boston, MA 02110-1301, USA. + */ + +#ifndef INCLUDED_NOINST_UTILS_H +#define INCLUDED_NOINST_UTILS_H + +#include <uhd/device_addr.hpp> + +uhd::device_addr_t args_to_device_addr(const std::string &args); + +#endif /* INCLUDED_NOINST_UTILS_H */ |