From b71d0cbea9e1e107eeb1da51ef14fe6b9e983ee6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sat, 27 Mar 2010 14:27:55 -0700 Subject: refactored types.hpp into types directory --- host/include/uhd/CMakeLists.txt | 6 +- host/include/uhd/device.hpp | 4 +- host/include/uhd/device_addr.hpp | 69 -------------- host/include/uhd/dict.hpp | 154 -------------------------------- host/include/uhd/metadata.hpp | 61 ------------- host/include/uhd/simple_device.hpp | 4 +- host/include/uhd/time_spec.hpp | 55 ------------ host/include/uhd/transport/vrt.hpp | 2 +- host/include/uhd/types.hpp | 119 ------------------------ host/include/uhd/types/CMakeLists.txt | 30 +++++++ host/include/uhd/types/clock_config.hpp | 50 +++++++++++ host/include/uhd/types/device_addr.hpp | 45 ++++++++++ host/include/uhd/types/dict.hpp | 154 ++++++++++++++++++++++++++++++++ host/include/uhd/types/mac_addr.hpp | 39 ++++++++ host/include/uhd/types/metadata.hpp | 61 +++++++++++++ host/include/uhd/types/ranges.hpp | 46 ++++++++++ host/include/uhd/types/stream_cmd.hpp | 56 ++++++++++++ host/include/uhd/types/time_spec.hpp | 55 ++++++++++++ host/include/uhd/types/tune_result.hpp | 44 +++++++++ host/lib/CMakeLists.txt | 3 - host/lib/device.cpp | 6 +- host/lib/device_addr.cpp | 86 ------------------ host/lib/gain_handler.cpp | 24 ++--- host/lib/metadata.cpp | 37 -------- host/lib/simple_device.cpp | 5 +- host/lib/time_spec.cpp | 35 -------- host/lib/types.cpp | 113 +++++++++++++++++++++-- host/lib/usrp/dboard/basic.cpp | 26 +++--- host/lib/usrp/dboard_manager.cpp | 2 +- host/lib/usrp/usrp2/dboard_impl.cpp | 1 + host/lib/usrp/usrp2/dsp_impl.cpp | 6 +- host/lib/usrp/usrp2/mboard_impl.cpp | 3 +- host/lib/usrp/usrp2/usrp2_impl.hpp | 10 +-- host/test/addr_test.cpp | 5 +- host/test/gain_handler_test.cpp | 22 ++--- host/utils/discover_usrps.cpp | 2 +- 36 files changed, 752 insertions(+), 688 deletions(-) delete mode 100644 host/include/uhd/device_addr.hpp delete mode 100644 host/include/uhd/dict.hpp delete mode 100644 host/include/uhd/metadata.hpp delete mode 100644 host/include/uhd/time_spec.hpp delete mode 100644 host/include/uhd/types.hpp create mode 100644 host/include/uhd/types/CMakeLists.txt create mode 100644 host/include/uhd/types/clock_config.hpp create mode 100644 host/include/uhd/types/device_addr.hpp create mode 100644 host/include/uhd/types/dict.hpp create mode 100644 host/include/uhd/types/mac_addr.hpp create mode 100644 host/include/uhd/types/metadata.hpp create mode 100644 host/include/uhd/types/ranges.hpp create mode 100644 host/include/uhd/types/stream_cmd.hpp create mode 100644 host/include/uhd/types/time_spec.hpp create mode 100644 host/include/uhd/types/tune_result.hpp delete mode 100644 host/lib/device_addr.cpp delete mode 100644 host/lib/metadata.cpp delete mode 100644 host/lib/time_spec.cpp diff --git a/host/include/uhd/CMakeLists.txt b/host/include/uhd/CMakeLists.txt index 2203ea83e..0cebea095 100644 --- a/host/include/uhd/CMakeLists.txt +++ b/host/include/uhd/CMakeLists.txt @@ -17,20 +17,16 @@ ADD_SUBDIRECTORY(transport) +ADD_SUBDIRECTORY(types) ADD_SUBDIRECTORY(usrp) ADD_SUBDIRECTORY(utils) INSTALL(FILES config.hpp device.hpp - device_addr.hpp - dict.hpp gain_handler.hpp - metadata.hpp props.hpp simple_device.hpp - time_spec.hpp - types.hpp wax.hpp DESTINATION ${INCLUDE_DIR}/uhd ) diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 13b40febe..bab8afca6 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -19,9 +19,9 @@ #define INCLUDED_UHD_DEVICE_HPP #include -#include +#include +#include #include -#include #include #include #include diff --git a/host/include/uhd/device_addr.hpp b/host/include/uhd/device_addr.hpp deleted file mode 100644 index 7673faff0..000000000 --- a/host/include/uhd/device_addr.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#ifndef INCLUDED_UHD_DEVICE_ADDR_HPP -#define INCLUDED_UHD_DEVICE_ADDR_HPP - -#include -#include -#include -#include -#include -#include - -namespace uhd{ - - /*! - * Wrapper for an ethernet mac address. - * Provides conversion between string and binary formats. - */ - struct UHD_API mac_addr_t{ - boost::uint8_t mac_addr[6]; - mac_addr_t(const std::string &mac_addr_str = "00:00:00:00:00:00"); - std::string to_string(void) const; - }; - - /*! - * The device address args are just a mapping of key/value string pairs. - * When left empty, the discovery routine will try to find all usrps. - * The discovery can be narrowed down by specifying the transport type arguments. - * - * For example, to access a specific usrp2 one would specify the transport type - * ("type", "udp") and the transport args ("addr", ""). - */ - typedef dict device_addr_t; - typedef std::vector device_addrs_t; - - /*! - * Function to turn a device address into a string. - * Just having the operator<< below should be sufficient. - * However, boost format seems to complain with the % - * and this is just easier because it works. - * \param device_addr a device address instance - * \return the string representation - */ - namespace device_addr{ - UHD_API std::string to_string(const device_addr_t &device_addr); - } - -} //namespace uhd - -//ability to use types with stream operators -UHD_API std::ostream& operator<<(std::ostream &, const uhd::device_addr_t &); -UHD_API std::ostream& operator<<(std::ostream &, const uhd::mac_addr_t &); - -#endif /* INCLUDED_UHD_DEVICE_ADDR_HPP */ diff --git a/host/include/uhd/dict.hpp b/host/include/uhd/dict.hpp deleted file mode 100644 index f08493952..000000000 --- a/host/include/uhd/dict.hpp +++ /dev/null @@ -1,154 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#ifndef INCLUDED_UHD_DICT_HPP -#define INCLUDED_UHD_DICT_HPP - -#include -#include -#include -#include - -namespace uhd{ - - /*! - * A templated dictionary class with a python-like interface. - */ - template class dict{ - public: - typedef std::pair pair_t; - - /*! - * Create a new empty dictionary. - */ - dict(void){ - /* NOP */ - } - - /*! - * Input iterator constructor: - * Makes boost::assign::map_list_of work. - * \param first the begin iterator - * \param last the end iterator - */ - template - dict(InputIterator first, InputIterator last){ - for(InputIterator it = first; it != last; it++){ - _map.push_back(*it); - } - } - - /*! - * Destroy this dict. - */ - ~dict(void){ - /* NOP */ - } - - /*! - * Get the number of elements in this dict. - * \param the number of elements - */ - std::size_t size(void) const{ - return _map.size(); - } - - /*! - * Get a list of the keys in this dict. - * Key order depends on insertion precedence. - * \return vector of keys - */ - std::vector get_keys(void) const{ - std::vector keys; - BOOST_FOREACH(const pair_t &p, _map){ - keys.push_back(p.first); - } - return keys; - } - - /*! - * Get a list of the values in this dict. - * Value order depends on insertion precedence. - * \return vector of values - */ - std::vector get_vals(void) const{ - std::vector vals; - BOOST_FOREACH(const pair_t &p, _map){ - vals.push_back(p.second); - } - return vals; - } - - /*! - * Does the dictionary contain this key? - * \param key the key to look for - * \return true if found - */ - bool has_key(const Key &key) const{ - BOOST_FOREACH(const pair_t &p, _map){ - if (p.first == key) return true; - } - return false; - } - - /*! - * Get a value for the given key if it exists. - * If the key is not found throw an error. - * \param key the key to look for - * \return the value at the key - * \throw an exception when not found - */ - const Val &operator[](const Key &key) const{ - BOOST_FOREACH(const pair_t &p, _map){ - if (p.first == key) return p.second; - } - throw std::invalid_argument("key not found in dict"); - } - - /*! - * Set a value for the given key, however, in reality - * it really returns a reference which can be assigned to. - * \param key the key to set to - * \return a reference to the value - */ - Val &operator[](const Key &key){ - BOOST_FOREACH(pair_t &p, _map){ - if (p.first == key) return p.second; - } - _map.push_back(pair_t(key, Val())); - return _map.back().second; - } - - /*! - * Pop an item out of the dictionary. - * \param key the item key - * \return the value of the item - * \throw an exception when not found - */ - Val pop(const Key &key){ - Val val = (*this)[key]; - _map.remove(pair_t(key, val)); - return val; - } - - private: - std::list _map; //private container - }; - -} //namespace uhd - -#endif /* INCLUDED_UHD_DICT_HPP */ diff --git a/host/include/uhd/metadata.hpp b/host/include/uhd/metadata.hpp deleted file mode 100644 index 6d80f070d..000000000 --- a/host/include/uhd/metadata.hpp +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#ifndef INCLUDED_UHD_METADATA_HPP -#define INCLUDED_UHD_METADATA_HPP - -#include -#include - -namespace uhd{ - -/*! - * RX metadata structure for describing sent IF data. - * Includes stream ID, time specification, and fragmentation flags. - * The receive routines will convert IF data headers into metadata. - */ -struct UHD_API rx_metadata_t{ - boost::uint32_t stream_id; - time_spec_t time_spec; - bool has_stream_id; - bool has_time_spec; - bool is_fragment; - - //default constructor - rx_metadata_t(void); -}; - -/*! - * TX metadata structure for describing received IF data. - * Includes stream ID, time specification, and burst flags. - * The send routines will convert the metadata to IF data headers. - */ -struct UHD_API tx_metadata_t{ - boost::uint32_t stream_id; - time_spec_t time_spec; - bool has_stream_id; - bool has_time_spec; - bool start_of_burst; - bool end_of_burst; - - //default constructor - tx_metadata_t(void); -}; - -} //namespace uhd - -#endif /* INCLUDED_UHD_METADATA_HPP */ diff --git a/host/include/uhd/simple_device.hpp b/host/include/uhd/simple_device.hpp index bbe0258c7..52928367a 100644 --- a/host/include/uhd/simple_device.hpp +++ b/host/include/uhd/simple_device.hpp @@ -20,7 +20,9 @@ #include #include -#include +#include +#include +#include #include #include #include diff --git a/host/include/uhd/time_spec.hpp b/host/include/uhd/time_spec.hpp deleted file mode 100644 index e863746ba..000000000 --- a/host/include/uhd/time_spec.hpp +++ /dev/null @@ -1,55 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#ifndef INCLUDED_UHD_TIME_SPEC_HPP -#define INCLUDED_UHD_TIME_SPEC_HPP - -#include -#include -#include - -namespace uhd{ - - /*! - * A time_spec_t holds a seconds and ticks time value. - * The temporal width of a tick depends on the device's clock rate. - * The time_spec_t can be used when setting the time on devices - * and for controlling the start of streaming for applicable dsps. - */ - struct UHD_API time_spec_t{ - boost::uint32_t secs; - boost::uint32_t ticks; - - /*! - * Create a time_spec_t from seconds and ticks. - * \param new_secs the new seconds (default = 0) - * \param new_ticks the new ticks (default = 0) - */ - time_spec_t(boost::uint32_t new_secs = 0, boost::uint32_t new_ticks = 0); - - /*! - * Create a time_spec_t from boost posix time. - * \param time fine-grained boost posix time - * \param tick_rate the rate of ticks per second - */ - time_spec_t(boost::posix_time::ptime time, double tick_rate); - - }; - -} //namespace uhd - -#endif /* INCLUDED_UHD_TIME_SPEC_HPP */ diff --git a/host/include/uhd/transport/vrt.hpp b/host/include/uhd/transport/vrt.hpp index db2c57eba..04945b347 100644 --- a/host/include/uhd/transport/vrt.hpp +++ b/host/include/uhd/transport/vrt.hpp @@ -19,7 +19,7 @@ #define INCLUDED_UHD_TRANSPORT_VRT_HPP #include -#include +#include #include namespace uhd{ namespace transport{ diff --git a/host/include/uhd/types.hpp b/host/include/uhd/types.hpp deleted file mode 100644 index 3ad3dae82..000000000 --- a/host/include/uhd/types.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#ifndef INCLUDED_UHD_TYPES_HPP -#define INCLUDED_UHD_TYPES_HPP - -#include -#include -#include - -namespace uhd{ - - typedef float gain_t; //TODO REMOVE - typedef double freq_t; //TODO REMOVE - - /*! - * The gain range struct describes possible gain settings. - * The mimumum gain, maximum gain, and step size are in dB. - */ - struct UHD_API gain_range_t{ - float min, max, step; - gain_range_t(float min = 0.0, float max = 0.0, float step = 0.0); - }; - - /*! - * The frequency range struct describes possible frequency settings. - * Because tuning is very granular (sub-Hz), step size is not listed. - * The mimumum frequency and maximum frequency are in Hz. - */ - struct UHD_API freq_range_t{ - double min, max; - freq_range_t(double min = 0.0, double max = 0.0); - }; - - /*! - * The tune result struct holds result of a 2-phase tuning: - * The struct hold the result of tuning the dboard as - * the target and actual intermediate frequency. - * The struct hold the result of tuning the DDC/DUC as - * the target and actual digital converter frequency. - * It also tell us weather or not the spectrum is inverted. - */ - struct UHD_API tune_result_t{ - double target_inter_freq; - double actual_inter_freq; - double target_dxc_freq; - double actual_dxc_freq; - bool spectrum_inverted; - tune_result_t(void); - }; - - /*! - * Clock configuration settings: - * The source for the 10MHz reference clock. - * The source and polarity for the PPS clock. - */ - struct UHD_API clock_config_t{ - enum ref_source_t { - REF_INT, //internal reference - REF_SMA, //external sma port - REF_MIMO //mimo cable (usrp2 only) - } ref_source; - enum pps_source_t { - PPS_INT, //there is no internal - PPS_SMA, //external sma port - PPS_MIMO //mimo cable (usrp2 only) - } pps_source; - enum pps_polarity_t { - PPS_NEG, //negative edge - PPS_POS //positive edge - } pps_polarity; - clock_config_t(void); - }; - - /*! - * Command struct for configuration and control of streaming: - * - * A stream command defines how the device sends samples to the host. - * Streaming is controlled by submitting a stream command to the rx dsp. - * Granular control over what the device streams to the host can be - * achieved through submission of multiple (carefully-crafted) commands. - * - * The stream_now parameter controls when the stream begins. - * When true, the device will begin streaming ASAP. When false, - * the device will begin streaming at a time specified by time_spec. - * - * The continuous parameter controls the number of samples received. - * When true, the device continues streaming indefinitely. When false, - * the device will stream the number of samples specified by num_samps. - * - * Standard usage case: - * To start continuous streaming, set stream_now to true and continuous to true. - * To end continuous streaming, set stream_now to true and continuous to false. - */ - struct UHD_API stream_cmd_t{ - bool stream_now; - time_spec_t time_spec; - bool continuous; - size_t num_samps; - stream_cmd_t(void); - }; - -} //namespace uhd - -#endif /* INCLUDED_UHD_TYPES_HPP */ diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt new file mode 100644 index 000000000..10262dd65 --- /dev/null +++ b/host/include/uhd/types/CMakeLists.txt @@ -0,0 +1,30 @@ +# +# Copyright 2010 Ettus Research LLC +# +# This program 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 of the License, or +# (at your option) any later version. +# +# This program 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 program. If not, see . +# + + +INSTALL(FILES + clock_config.hpp + device_addr.hpp + dict.hpp + mac_addr.hpp + metadata.hpp + ranges.hpp + stream_cmd.hpp + time_spec.hpp + tune_result.hpp + DESTINATION ${INCLUDE_DIR}/uhd/types +) diff --git a/host/include/uhd/types/clock_config.hpp b/host/include/uhd/types/clock_config.hpp new file mode 100644 index 000000000..8b2fea016 --- /dev/null +++ b/host/include/uhd/types/clock_config.hpp @@ -0,0 +1,50 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_CLOCK_CONFIG_HPP +#define INCLUDED_UHD_TYPES_CLOCK_CONFIG_HPP + +#include + +namespace uhd{ + + /*! + * Clock configuration settings: + * The source for the 10MHz reference clock. + * The source and polarity for the PPS clock. + */ + struct UHD_API clock_config_t{ + enum ref_source_t { + REF_INT, //internal reference + REF_SMA, //external sma port + REF_MIMO //mimo cable (usrp2 only) + } ref_source; + enum pps_source_t { + PPS_INT, //there is no internal + PPS_SMA, //external sma port + PPS_MIMO //mimo cable (usrp2 only) + } pps_source; + enum pps_polarity_t { + PPS_NEG, //negative edge + PPS_POS //positive edge + } pps_polarity; + clock_config_t(void); + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_CLOCK_CONFIG_HPP */ diff --git a/host/include/uhd/types/device_addr.hpp b/host/include/uhd/types/device_addr.hpp new file mode 100644 index 000000000..d32dfa77e --- /dev/null +++ b/host/include/uhd/types/device_addr.hpp @@ -0,0 +1,45 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP +#define INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP + +#include +#include +#include +#include + +namespace uhd{ + + /*! + * The device address args are just a mapping of key/value string pairs. + * When left empty, the discovery routine will try to find all usrps. + * The discovery can be narrowed down by specifying the transport type arguments. + * + * For example, to access a specific usrp2 one would specify the transport type + * ("type", "udp") and the transport args ("addr", ""). + */ + class UHD_API device_addr_t : public dict{ + public: std::string to_string(void) const; + }; + + //handy typedef for a vector of device addresses + typedef std::vector device_addrs_t; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_DEVICE_ADDR_HPP */ diff --git a/host/include/uhd/types/dict.hpp b/host/include/uhd/types/dict.hpp new file mode 100644 index 000000000..5b9883704 --- /dev/null +++ b/host/include/uhd/types/dict.hpp @@ -0,0 +1,154 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_DICT_HPP +#define INCLUDED_UHD_TYPES_DICT_HPP + +#include +#include +#include +#include + +namespace uhd{ + + /*! + * A templated dictionary class with a python-like interface. + */ + template class dict{ + public: + typedef std::pair pair_t; + + /*! + * Create a new empty dictionary. + */ + dict(void){ + /* NOP */ + } + + /*! + * Input iterator constructor: + * Makes boost::assign::map_list_of work. + * \param first the begin iterator + * \param last the end iterator + */ + template + dict(InputIterator first, InputIterator last){ + for(InputIterator it = first; it != last; it++){ + _map.push_back(*it); + } + } + + /*! + * Destroy this dict. + */ + ~dict(void){ + /* NOP */ + } + + /*! + * Get the number of elements in this dict. + * \param the number of elements + */ + std::size_t size(void) const{ + return _map.size(); + } + + /*! + * Get a list of the keys in this dict. + * Key order depends on insertion precedence. + * \return vector of keys + */ + std::vector get_keys(void) const{ + std::vector keys; + BOOST_FOREACH(const pair_t &p, _map){ + keys.push_back(p.first); + } + return keys; + } + + /*! + * Get a list of the values in this dict. + * Value order depends on insertion precedence. + * \return vector of values + */ + std::vector get_vals(void) const{ + std::vector vals; + BOOST_FOREACH(const pair_t &p, _map){ + vals.push_back(p.second); + } + return vals; + } + + /*! + * Does the dictionary contain this key? + * \param key the key to look for + * \return true if found + */ + bool has_key(const Key &key) const{ + BOOST_FOREACH(const pair_t &p, _map){ + if (p.first == key) return true; + } + return false; + } + + /*! + * Get a value for the given key if it exists. + * If the key is not found throw an error. + * \param key the key to look for + * \return the value at the key + * \throw an exception when not found + */ + const Val &operator[](const Key &key) const{ + BOOST_FOREACH(const pair_t &p, _map){ + if (p.first == key) return p.second; + } + throw std::invalid_argument("key not found in dict"); + } + + /*! + * Set a value for the given key, however, in reality + * it really returns a reference which can be assigned to. + * \param key the key to set to + * \return a reference to the value + */ + Val &operator[](const Key &key){ + BOOST_FOREACH(pair_t &p, _map){ + if (p.first == key) return p.second; + } + _map.push_back(pair_t(key, Val())); + return _map.back().second; + } + + /*! + * Pop an item out of the dictionary. + * \param key the item key + * \return the value of the item + * \throw an exception when not found + */ + Val pop(const Key &key){ + Val val = (*this)[key]; + _map.remove(pair_t(key, val)); + return val; + } + + private: + std::list _map; //private container + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_DICT_HPP */ diff --git a/host/include/uhd/types/mac_addr.hpp b/host/include/uhd/types/mac_addr.hpp new file mode 100644 index 000000000..2cac7d343 --- /dev/null +++ b/host/include/uhd/types/mac_addr.hpp @@ -0,0 +1,39 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_MAC_ADDR_HPP +#define INCLUDED_UHD_TYPES_MAC_ADDR_HPP + +#include +#include +#include + +namespace uhd{ + + /*! + * Wrapper for an ethernet mac address. + * Provides conversion between string and binary formats. + */ + struct UHD_API mac_addr_t{ + boost::uint8_t mac_addr[6]; + mac_addr_t(const std::string &mac_addr_str = "00:00:00:00:00:00"); + std::string to_string(void) const; + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_MAC_ADDR_HPP */ diff --git a/host/include/uhd/types/metadata.hpp b/host/include/uhd/types/metadata.hpp new file mode 100644 index 000000000..6e93040d9 --- /dev/null +++ b/host/include/uhd/types/metadata.hpp @@ -0,0 +1,61 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_METADATA_HPP +#define INCLUDED_UHD_TYPES_METADATA_HPP + +#include +#include + +namespace uhd{ + + /*! + * RX metadata structure for describing sent IF data. + * Includes stream ID, time specification, and fragmentation flags. + * The receive routines will convert IF data headers into metadata. + */ + struct UHD_API rx_metadata_t{ + boost::uint32_t stream_id; + time_spec_t time_spec; + bool has_stream_id; + bool has_time_spec; + bool is_fragment; + + //default constructor + rx_metadata_t(void); + }; + + /*! + * TX metadata structure for describing received IF data. + * Includes stream ID, time specification, and burst flags. + * The send routines will convert the metadata to IF data headers. + */ + struct UHD_API tx_metadata_t{ + boost::uint32_t stream_id; + time_spec_t time_spec; + bool has_stream_id; + bool has_time_spec; + bool start_of_burst; + bool end_of_burst; + + //default constructor + tx_metadata_t(void); + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_METADATA_HPP */ diff --git a/host/include/uhd/types/ranges.hpp b/host/include/uhd/types/ranges.hpp new file mode 100644 index 000000000..a2057d1c8 --- /dev/null +++ b/host/include/uhd/types/ranges.hpp @@ -0,0 +1,46 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_RANGES_HPP +#define INCLUDED_UHD_TYPES_RANGES_HPP + +#include + +namespace uhd{ + + /*! + * The gain range struct describes possible gain settings. + * The mimumum gain, maximum gain, and step size are in dB. + */ + struct UHD_API gain_range_t{ + float min, max, step; + gain_range_t(float min = 0.0, float max = 0.0, float step = 0.0); + }; + + /*! + * The frequency range struct describes possible frequency settings. + * Because tuning is very granular (sub-Hz), step size is not listed. + * The mimumum frequency and maximum frequency are in Hz. + */ + struct UHD_API freq_range_t{ + double min, max; + freq_range_t(double min = 0.0, double max = 0.0); + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_RANGES_HPP */ diff --git a/host/include/uhd/types/stream_cmd.hpp b/host/include/uhd/types/stream_cmd.hpp new file mode 100644 index 000000000..97a6b73ce --- /dev/null +++ b/host/include/uhd/types/stream_cmd.hpp @@ -0,0 +1,56 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_STREAM_CMD_HPP +#define INCLUDED_UHD_TYPES_STREAM_CMD_HPP + +#include +#include + +namespace uhd{ + + /*! + * Command struct for configuration and control of streaming: + * + * A stream command defines how the device sends samples to the host. + * Streaming is controlled by submitting a stream command to the rx dsp. + * Granular control over what the device streams to the host can be + * achieved through submission of multiple (carefully-crafted) commands. + * + * The stream_now parameter controls when the stream begins. + * When true, the device will begin streaming ASAP. When false, + * the device will begin streaming at a time specified by time_spec. + * + * The continuous parameter controls the number of samples received. + * When true, the device continues streaming indefinitely. When false, + * the device will stream the number of samples specified by num_samps. + * + * Standard usage case: + * To start continuous streaming, set stream_now to true and continuous to true. + * To end continuous streaming, set stream_now to true and continuous to false. + */ + struct UHD_API stream_cmd_t{ + bool stream_now; + time_spec_t time_spec; + bool continuous; + size_t num_samps; + stream_cmd_t(void); + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_STREAM_CMD_HPP */ diff --git a/host/include/uhd/types/time_spec.hpp b/host/include/uhd/types/time_spec.hpp new file mode 100644 index 000000000..8c8f2bc25 --- /dev/null +++ b/host/include/uhd/types/time_spec.hpp @@ -0,0 +1,55 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_TIME_SPEC_HPP +#define INCLUDED_UHD_TYPES_TIME_SPEC_HPP + +#include +#include +#include + +namespace uhd{ + + /*! + * A time_spec_t holds a seconds and ticks time value. + * The temporal width of a tick depends on the device's clock rate. + * The time_spec_t can be used when setting the time on devices + * and for controlling the start of streaming for applicable dsps. + */ + struct UHD_API time_spec_t{ + boost::uint32_t secs; + boost::uint32_t ticks; + + /*! + * Create a time_spec_t from seconds and ticks. + * \param new_secs the new seconds (default = 0) + * \param new_ticks the new ticks (default = 0) + */ + time_spec_t(boost::uint32_t new_secs = 0, boost::uint32_t new_ticks = 0); + + /*! + * Create a time_spec_t from boost posix time. + * \param time fine-grained boost posix time + * \param tick_rate the rate of ticks per second + */ + time_spec_t(boost::posix_time::ptime time, double tick_rate); + + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_TIME_SPEC_HPP */ diff --git a/host/include/uhd/types/tune_result.hpp b/host/include/uhd/types/tune_result.hpp new file mode 100644 index 000000000..31742e1af --- /dev/null +++ b/host/include/uhd/types/tune_result.hpp @@ -0,0 +1,44 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program 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 of the License, or +// (at your option) any later version. +// +// This program 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 program. If not, see . +// + +#ifndef INCLUDED_UHD_TYPES_TUNE_RESULT_HPP +#define INCLUDED_UHD_TYPES_TUNE_RESULT_HPP + +#include + +namespace uhd{ + + /*! + * The tune result struct holds result of a 2-phase tuning: + * The struct hold the result of tuning the dboard as + * the target and actual intermediate frequency. + * The struct hold the result of tuning the DDC/DUC as + * the target and actual digital converter frequency. + * It also tell us weather or not the spectrum is inverted. + */ + struct UHD_API tune_result_t{ + double target_inter_freq; + double actual_inter_freq; + double target_dxc_freq; + double actual_dxc_freq; + bool spectrum_inverted; + tune_result_t(void); + }; + +} //namespace uhd + +#endif /* INCLUDED_UHD_TYPES_TUNE_RESULT_HPP */ diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt index 170d1d3bf..1eceb53ea 100644 --- a/host/lib/CMakeLists.txt +++ b/host/lib/CMakeLists.txt @@ -20,12 +20,9 @@ ######################################################################## SET(libuhd_sources device.cpp - device_addr.cpp gain_handler.cpp load_modules.cpp - metadata.cpp simple_device.cpp - time_spec.cpp types.cpp wax.cpp transport/if_addrs.cpp diff --git a/host/lib/device.cpp b/host/lib/device.cpp index 0bdbf5f23..833e7a0da 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -110,14 +110,14 @@ device::sptr device::make(const device_addr_t &hint, size_t which){ //check that we found any devices if (dev_addr_makers.size() == 0){ throw std::runtime_error(str( - boost::format("No devices found for ----->\n%s") % device_addr::to_string(hint) + boost::format("No devices found for ----->\n%s") % hint.to_string() )); } //check that the which index is valid if (dev_addr_makers.size() <= which){ throw std::runtime_error(str( - boost::format("No device at index %d for ----->\n%s") % which % device_addr::to_string(hint) + boost::format("No device at index %d for ----->\n%s") % which % hint.to_string() )); } diff --git a/host/lib/device_addr.cpp b/host/lib/device_addr.cpp deleted file mode 100644 index d26bb4b9d..000000000 --- a/host/lib/device_addr.cpp +++ /dev/null @@ -1,86 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#include -#include -#include -#include -#include -#include -#include - -//----------------------- u2 mac addr wrapper ------------------------// -uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str_){ - std::string mac_addr_str = (mac_addr_str_ == "")? "ff:ff:ff:ff:ff:ff" : mac_addr_str_; - - //ether_aton_r(str.c_str(), &mac_addr); - boost::uint8_t p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB - - try{ - //only allow patterns of xx:xx or xx:xx:xx:xx:xx:xx - //the IAB above will fill in for the shorter pattern - if (mac_addr_str.size() != 5 and mac_addr_str.size() != 17) - throw std::runtime_error("expected exactly 5 or 17 characters"); - - //split the mac addr hex string at the colons - std::vector hex_strs; - boost::split(hex_strs, mac_addr_str, boost::is_any_of(":")); - for (size_t i = 0; i < hex_strs.size(); i++){ - int hex_num; - std::istringstream iss(hex_strs[i]); - iss >> std::hex >> hex_num; - p[i] = boost::uint8_t(hex_num); - } - - } - catch(std::exception const& e){ - throw std::runtime_error(str( - boost::format("Invalid mac address: %s\n\t%s") % mac_addr_str % e.what() - )); - } - - memcpy(&mac_addr, p, sizeof(mac_addr)); -} - -std::string uhd::mac_addr_t::to_string(void) const{ - //ether_ntoa_r(&mac_addr, addr_buf); - const boost::uint8_t *p = reinterpret_cast(&mac_addr); - return str( - boost::format("%02x:%02x:%02x:%02x:%02x:%02x") - % int(p[0]) % int(p[1]) % int(p[2]) - % int(p[3]) % int(p[4]) % int(p[5]) - ); -} - -std::ostream& operator<<(std::ostream &os, const uhd::mac_addr_t &x){ - os << x.to_string(); - return os; -} - -//----------------------- usrp device_addr_t wrapper -------------------------// -std::string uhd::device_addr::to_string(const uhd::device_addr_t &device_addr){ - std::stringstream ss; - BOOST_FOREACH(std::string key, device_addr.get_keys()){ - ss << boost::format("%s: %s") % key % device_addr[key] << std::endl; - } - return ss.str(); -} - -std::ostream& operator<<(std::ostream &os, const uhd::device_addr_t &device_addr){ - os << uhd::device_addr::to_string(device_addr); - return os; -} diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp index 7b3dd266c..a6ae06c50 100644 --- a/host/lib/gain_handler.cpp +++ b/host/lib/gain_handler.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include #include @@ -47,7 +47,7 @@ private: is_equal_t _is_equal; prop_names_t get_gain_names(void); - gain_t get_overall_gain_val(void); + float get_overall_gain_val(void); gain_range_t get_overall_gain_range(void); template T get_named_prop(const wax::obj &prop, const std::string &name){ return _link[named_prop_t(prop, name)].as(); @@ -90,21 +90,21 @@ prop_names_t gain_handler_impl::get_gain_names(void){ return _link[_props.names].as(); } -gain_t gain_handler_impl::get_overall_gain_val(void){ - gain_t gain_val = 0; +float gain_handler_impl::get_overall_gain_val(void){ + float gain_val = 0; BOOST_FOREACH(std::string name, get_gain_names()){ - gain_val += get_named_prop(_props.value, name); + gain_val += get_named_prop(_props.value, name); } return gain_val; } gain_range_t gain_handler_impl::get_overall_gain_range(void){ - gain_t gain_min = 0, gain_max = 0, gain_step = 0; + float gain_min = 0, gain_max = 0, gain_step = 0; BOOST_FOREACH(std::string name, get_gain_names()){ - gain_range_t gain_tmp = get_named_prop(_props.range, name); - gain_min += gain_tmp.min; - gain_max += gain_tmp.max; - gain_step = std::max(gain_step, gain_tmp.step); + gain_range_t floatmp = get_named_prop(_props.range, name); + gain_min += floatmp.min; + gain_max += floatmp.max; + gain_step = std::max(gain_step, floatmp.step); } return gain_range_t(gain_min, gain_max, gain_step); } @@ -145,7 +145,7 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val) //not a gain value key... dont handle if (not _is_equal(key, _props.value)) return false; - gain_t gain_val = val.as(); + float gain_val = val.as(); //not a wildcard... dont handle (but check name and range) if (name != ""){ @@ -164,7 +164,7 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val) gain_range_t gain = get_named_prop(_props.range, name); //clip g to be within the allowed range - gain_t g = std::min(std::max(gain_val, gain.min), gain.max); + float g = std::min(std::max(gain_val, gain.min), gain.max); //set g to be a multiple of the step size g -= std::fmod(g, gain.step); //set g to be the new gain diff --git a/host/lib/metadata.cpp b/host/lib/metadata.cpp deleted file mode 100644 index 40fdb7c73..000000000 --- a/host/lib/metadata.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#include - -using namespace uhd; - -rx_metadata_t::rx_metadata_t(void){ - stream_id = 0; - has_stream_id = false; - time_spec = time_spec_t(); - has_time_spec = false; - is_fragment = false; -} - -tx_metadata_t::tx_metadata_t(void){ - stream_id = 0; - has_stream_id = false; - time_spec = time_spec_t(); - has_time_spec = false; - start_of_burst = false; - end_of_burst = false; -} diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp index 0eb69d9fa..95bc8fecc 100644 --- a/host/lib/simple_device.cpp +++ b/host/lib/simple_device.cpp @@ -19,7 +19,6 @@ #include #include #include -#include #include #include #include @@ -208,7 +207,7 @@ public: } float get_rx_gain(void){ - return _rx_subdev[SUBDEV_PROP_GAIN].as(); + return _rx_subdev[SUBDEV_PROP_GAIN].as(); } gain_range_t get_rx_gain_range(void){ @@ -264,7 +263,7 @@ public: } float get_tx_gain(void){ - return _tx_subdev[SUBDEV_PROP_GAIN].as(); + return _tx_subdev[SUBDEV_PROP_GAIN].as(); } gain_range_t get_tx_gain_range(void){ diff --git a/host/lib/time_spec.cpp b/host/lib/time_spec.cpp deleted file mode 100644 index 98bf28077..000000000 --- a/host/lib/time_spec.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// -// This program 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 of the License, or -// (at your option) any later version. -// -// This program 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 program. If not, see . -// - -#include - -using namespace uhd; - -time_spec_t::time_spec_t(boost::uint32_t new_secs, boost::uint32_t new_ticks){ - secs = new_secs; - ticks = new_ticks; -} - -static const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); -static double time_tick_rate = double(boost::posix_time::time_duration::ticks_per_second()); - -time_spec_t::time_spec_t(boost::posix_time::ptime time, double tick_rate){ - boost::posix_time::time_duration td = time - epoch; - secs = boost::uint32_t(td.total_seconds()); - double time_ticks_per_device_ticks = time_tick_rate/tick_rate; - ticks = boost::uint32_t(td.fractional_seconds()/time_ticks_per_device_ticks); -} diff --git a/host/lib/types.cpp b/host/lib/types.cpp index 273f87a2d..bd5dc8e26 100644 --- a/host/lib/types.cpp +++ b/host/lib/types.cpp @@ -15,12 +15,23 @@ // along with this program. If not, see . // -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace uhd; /*********************************************************************** - * gain range + * ranges **********************************************************************/ gain_range_t::gain_range_t(float min_, float max_, float step_){ min = min_; @@ -28,9 +39,6 @@ gain_range_t::gain_range_t(float min_, float max_, float step_){ step = step_; } -/*********************************************************************** - * freq range - **********************************************************************/ freq_range_t::freq_range_t(double min_, double max_){ min = min_; max = max_; @@ -64,3 +72,98 @@ stream_cmd_t::stream_cmd_t(void){ continuous = false; num_samps = 0; } + +/*********************************************************************** + * metadata + **********************************************************************/ +rx_metadata_t::rx_metadata_t(void){ + stream_id = 0; + has_stream_id = false; + time_spec = time_spec_t(); + has_time_spec = false; + is_fragment = false; +} + +tx_metadata_t::tx_metadata_t(void){ + stream_id = 0; + has_stream_id = false; + time_spec = time_spec_t(); + has_time_spec = false; + start_of_burst = false; + end_of_burst = false; +} + +/*********************************************************************** + * time spec + **********************************************************************/ +time_spec_t::time_spec_t(boost::uint32_t new_secs, boost::uint32_t new_ticks){ + secs = new_secs; + ticks = new_ticks; +} + +static const boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1)); +static double time_tick_rate = double(boost::posix_time::time_duration::ticks_per_second()); + +time_spec_t::time_spec_t(boost::posix_time::ptime time, double tick_rate){ + boost::posix_time::time_duration td = time - epoch; + secs = boost::uint32_t(td.total_seconds()); + double time_ticks_per_device_ticks = time_tick_rate/tick_rate; + ticks = boost::uint32_t(td.fractional_seconds()/time_ticks_per_device_ticks); +} + +/*********************************************************************** + * device addr + **********************************************************************/ +std::string device_addr_t::to_string(void) const{ + const device_addr_t &device_addr = *this; + std::stringstream ss; + BOOST_FOREACH(std::string key, device_addr.get_keys()){ + ss << boost::format("%s: %s") % key % device_addr[key] << std::endl; + } + return ss.str(); +} + +/*********************************************************************** + * mac addr + **********************************************************************/ +uhd::mac_addr_t::mac_addr_t(const std::string &mac_addr_str_){ + std::string mac_addr_str = (mac_addr_str_ == "")? "ff:ff:ff:ff:ff:ff" : mac_addr_str_; + + //ether_aton_r(str.c_str(), &mac_addr); + boost::uint8_t p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB + + try{ + //only allow patterns of xx:xx or xx:xx:xx:xx:xx:xx + //the IAB above will fill in for the shorter pattern + if (mac_addr_str.size() != 5 and mac_addr_str.size() != 17) + throw std::runtime_error("expected exactly 5 or 17 characters"); + + //split the mac addr hex string at the colons + std::vector hex_strs; + boost::split(hex_strs, mac_addr_str, boost::is_any_of(":")); + for (size_t i = 0; i < hex_strs.size(); i++){ + int hex_num; + std::istringstream iss(hex_strs[i]); + iss >> std::hex >> hex_num; + p[i] = boost::uint8_t(hex_num); + } + + } + catch(std::exception const& e){ + throw std::runtime_error(str( + boost::format("Invalid mac address: %s\n\t%s") % mac_addr_str % e.what() + )); + } + + memcpy(&mac_addr, p, sizeof(mac_addr)); +} + +std::string uhd::mac_addr_t::to_string(void) const{ + //ether_ntoa_r(&mac_addr, addr_buf); + const boost::uint8_t *p = reinterpret_cast(&mac_addr); + return str( + boost::format("%02x:%02x:%02x:%02x:%02x:%02x") + % int(p[0]) % int(p[1]) % int(p[2]) + % int(p[3]) % int(p[4]) % int(p[5]) + ); +} diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp index 07cb8d11c..2f29c8e0c 100644 --- a/host/lib/usrp/dboard/basic.cpp +++ b/host/lib/usrp/dboard/basic.cpp @@ -16,7 +16,7 @@ // #include -#include +#include #include #include #include @@ -34,26 +34,26 @@ using namespace boost::assign; **********************************************************************/ class basic_rx : public rx_dboard_base{ public: - basic_rx(ctor_args_t const& args, freq_t max_freq); + basic_rx(ctor_args_t const& args, double max_freq); ~basic_rx(void); void rx_get(const wax::obj &key, wax::obj &val); void rx_set(const wax::obj &key, const wax::obj &val); private: - freq_t _max_freq; + double _max_freq; }; class basic_tx : public tx_dboard_base{ public: - basic_tx(ctor_args_t const& args, freq_t max_freq); + basic_tx(ctor_args_t const& args, double max_freq); ~basic_tx(void); void tx_get(const wax::obj &key, wax::obj &val); void tx_set(const wax::obj &key, const wax::obj &val); private: - freq_t _max_freq; + double _max_freq; }; /*********************************************************************** @@ -85,7 +85,7 @@ UHD_STATIC_BLOCK(reg_dboards){ /*********************************************************************** * Basic and LF RX dboard **********************************************************************/ -basic_rx::basic_rx(ctor_args_t const& args, freq_t max_freq) : rx_dboard_base(args){ +basic_rx::basic_rx(ctor_args_t const& args, double max_freq) : rx_dboard_base(args){ _max_freq = max_freq; // set the gpios to safe values (all inputs) get_interface()->set_gpio_ddr(dboard_interface::GPIO_RX_BANK, 0x0000, 0xffff); @@ -113,7 +113,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - val = gain_t(0); + val = float(0); return; case SUBDEV_PROP_GAIN_RANGE: @@ -125,7 +125,7 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_FREQ: - val = freq_t(0); + val = double(0); return; case SUBDEV_PROP_FREQ_RANGE: @@ -164,7 +164,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()){ case SUBDEV_PROP_GAIN: - ASSERT_THROW(val.as() == gain_t(0)); + ASSERT_THROW(val.as() == float(0)); return; case SUBDEV_PROP_ANTENNA: @@ -196,7 +196,7 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){ /*********************************************************************** * Basic and LF TX dboard **********************************************************************/ -basic_tx::basic_tx(ctor_args_t const& args, freq_t max_freq) : tx_dboard_base(args){ +basic_tx::basic_tx(ctor_args_t const& args, double max_freq) : tx_dboard_base(args){ _max_freq = max_freq; // set the gpios to safe values (all inputs) get_interface()->set_gpio_ddr(dboard_interface::GPIO_TX_BANK, 0x0000, 0xffff); @@ -221,7 +221,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_GAIN: - val = gain_t(0); + val = float(0); return; case SUBDEV_PROP_GAIN_RANGE: @@ -233,7 +233,7 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){ return; case SUBDEV_PROP_FREQ: - val = freq_t(0); + val = double(0); return; case SUBDEV_PROP_FREQ_RANGE: @@ -272,7 +272,7 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){ switch(key.as()){ case SUBDEV_PROP_GAIN: - ASSERT_THROW(val.as() == gain_t(0)); + ASSERT_THROW(val.as() == float(0)); return; case SUBDEV_PROP_ANTENNA: diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp index 0f2189cd1..bc9bfbf14 100644 --- a/host/lib/usrp/dboard_manager.cpp +++ b/host/lib/usrp/dboard_manager.cpp @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/host/lib/usrp/usrp2/dboard_impl.cpp b/host/lib/usrp/usrp2/dboard_impl.cpp index 6b49ff29d..fd72aeaa4 100644 --- a/host/lib/usrp/usrp2/dboard_impl.cpp +++ b/host/lib/usrp/usrp2/dboard_impl.cpp @@ -16,6 +16,7 @@ // #include +#include #include #include "usrp2_impl.hpp" diff --git a/host/lib/usrp/usrp2/dsp_impl.cpp b/host/lib/usrp/usrp2/dsp_impl.cpp index 654096d14..40ef06a8c 100644 --- a/host/lib/usrp/usrp2/dsp_impl.cpp +++ b/host/lib/usrp/usrp2/dsp_impl.cpp @@ -35,7 +35,7 @@ template T log2(T num){ /*********************************************************************** * DDC Helper Methods **********************************************************************/ -static boost::uint32_t calculate_freq_word_and_update_actual_freq(freq_t &freq, freq_t clock_freq){ +static boost::uint32_t calculate_freq_word_and_update_actual_freq(double &freq, double clock_freq){ double scale_factor = std::pow(2.0, 32); //calculate the freq register word @@ -163,7 +163,7 @@ void usrp2_impl::ddc_set(const wax::obj &key, const wax::obj &val){ return; } else if (key_name == "freq"){ - freq_t new_freq = val.as(); + double new_freq = val.as(); ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); _ddc_freq = new_freq; //shadow @@ -283,7 +283,7 @@ void usrp2_impl::duc_set(const wax::obj &key, const wax::obj &val){ return; } else if (key_name == "freq"){ - freq_t new_freq = val.as(); + double new_freq = val.as(); ASSERT_THROW(new_freq <= get_master_clock_freq()/2.0); ASSERT_THROW(new_freq >= -get_master_clock_freq()/2.0); _duc_freq = new_freq; //shadow diff --git a/host/lib/usrp/usrp2/mboard_impl.cpp b/host/lib/usrp/usrp2/mboard_impl.cpp index e4706dcf0..b6919a738 100644 --- a/host/lib/usrp/usrp2/mboard_impl.cpp +++ b/host/lib/usrp/usrp2/mboard_impl.cpp @@ -16,6 +16,7 @@ // #include +#include #include "usrp2_impl.hpp" using namespace uhd; @@ -168,7 +169,7 @@ void usrp2_impl::mboard_get(const wax::obj &key_, wax::obj &val){ return; case MBOARD_PROP_CLOCK_RATE: - val = freq_t(get_master_clock_freq()); + val = double(get_master_clock_freq()); return; case MBOARD_PROP_RX_DSP: diff --git a/host/lib/usrp/usrp2/usrp2_impl.hpp b/host/lib/usrp/usrp2/usrp2_impl.hpp index 3a2963c5a..6535e7049 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.hpp +++ b/host/lib/usrp/usrp2/usrp2_impl.hpp @@ -19,9 +19,9 @@ #define INCLUDED_USRP2_IMPL_HPP #include -#include -#include -#include +#include +#include +#include #include #include #include @@ -173,14 +173,14 @@ private: //methods and shadows for the ddc dsp std::vector _allowed_decim_and_interp_rates; size_t _ddc_decim; - uhd::freq_t _ddc_freq; + double _ddc_freq; void init_ddc_config(void); void update_ddc_config(void); void issue_ddc_stream_cmd(const uhd::stream_cmd_t &stream_cmd); //methods and shadows for the duc dsp size_t _duc_interp; - uhd::freq_t _duc_freq; + double _duc_freq; void init_duc_config(void); void update_duc_config(void); diff --git a/host/test/addr_test.cpp b/host/test/addr_test.cpp index 148aee015..0c8f63b0a 100644 --- a/host/test/addr_test.cpp +++ b/host/test/addr_test.cpp @@ -16,13 +16,14 @@ // #include -#include +#include +#include BOOST_AUTO_TEST_CASE(test_mac_addr){ std::cout << "Testing mac addr..." << std::endl; const std::string mac_addr_str("00:01:23:45:67:89"); uhd::mac_addr_t mac_addr(mac_addr_str); std::cout << "Input: " << mac_addr_str << std::endl; - std::cout << "Output: " << mac_addr << std::endl; + std::cout << "Output: " << mac_addr.to_string() << std::endl; BOOST_CHECK_EQUAL(mac_addr_str, mac_addr.to_string()); } diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index 47acb30f0..e13063e06 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -17,9 +17,9 @@ #include #include -#include +#include +#include #include -#include #include #include @@ -84,7 +84,7 @@ private: //handle the get request conditioned on the key switch(key.as()){ case PROP_GAIN_VALUE: - _gain_values[name] = val.as(); + _gain_values[name] = val.as(); return; case PROP_GAIN_RANGE: @@ -94,7 +94,7 @@ private: } gain_handler::sptr _gain_handler; - uhd::dict _gain_values; + uhd::dict _gain_values; uhd::dict _gain_ranges; }; @@ -104,18 +104,18 @@ BOOST_AUTO_TEST_CASE(test_gain_handler){ gainful_obj go0; BOOST_CHECK_THROW( - go0[named_prop_t(PROP_GAIN_VALUE, "fail")].as(), + go0[named_prop_t(PROP_GAIN_VALUE, "fail")].as(), std::exception ); std::cout << "verifying the overall min, max, step" << std::endl; gain_range_t gain = go0[PROP_GAIN_RANGE].as(); - BOOST_CHECK_EQUAL(gain.min, gain_t(-10)); - BOOST_CHECK_EQUAL(gain.max, gain_t(100)); - BOOST_CHECK_EQUAL(gain.step, gain_t(1.5)); + BOOST_CHECK_EQUAL(gain.min, float(-10)); + BOOST_CHECK_EQUAL(gain.max, float(100)); + BOOST_CHECK_EQUAL(gain.step, float(1.5)); std::cout << "verifying the overall gain" << std::endl; - go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = gain_t(-5); - go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = gain_t(30); - BOOST_CHECK_EQUAL(go0[PROP_GAIN_VALUE].as(), gain_t(25)); + go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = float(-5); + go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = float(30); + BOOST_CHECK_EQUAL(go0[PROP_GAIN_VALUE].as(), float(25)); } diff --git a/host/utils/discover_usrps.cpp b/host/utils/discover_usrps.cpp index dc2b845bc..72c5b8822 100644 --- a/host/utils/discover_usrps.cpp +++ b/host/utils/discover_usrps.cpp @@ -63,7 +63,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ std::cout << "--------------------------------------------------" << std::endl; std::cout << "-- USRP Device " << i << std::endl; std::cout << "--------------------------------------------------" << std::endl; - std::cout << device_addrs[i] << std::endl << std::endl; + std::cout << device_addrs[i].to_string() << std::endl << std::endl; uhd::device::make(device_addrs[i]); //test make } -- cgit v1.2.3