diff options
Diffstat (limited to 'host/include')
-rw-r--r-- | host/include/uhd.h | 2 | ||||
-rw-r--r-- | host/include/uhd/error.h | 37 | ||||
-rw-r--r-- | host/include/uhd/types/CMakeLists.txt | 2 | ||||
-rw-r--r-- | host/include/uhd/types/device_addrs.h | 87 | ||||
-rw-r--r-- | host/include/uhd/types/string_vector.h | 86 | ||||
-rw-r--r-- | host/include/uhd/usrp/usrp.h | 177 | ||||
-rw-r--r-- | host/include/uhd/usrp_clock/usrp_clock.h | 11 |
7 files changed, 145 insertions, 257 deletions
diff --git a/host/include/uhd.h b/host/include/uhd.h index 1f8f9e896..8647e25e4 100644 --- a/host/include/uhd.h +++ b/host/include/uhd.h @@ -21,10 +21,10 @@ #include <uhd/config.h> #include <uhd/error.h> -#include <uhd/types/device_addrs.h> #include <uhd/types/metadata.h> #include <uhd/types/ranges.h> #include <uhd/types/sensors.h> +#include <uhd/types/string_vector.h> #include <uhd/types/tune_request.h> #include <uhd/types/tune_result.h> #include <uhd/types/usrp_info.h> diff --git a/host/include/uhd/error.h b/host/include/uhd/error.h index 845d741dc..f0ac41d1f 100644 --- a/host/include/uhd/error.h +++ b/host/include/uhd/error.h @@ -18,6 +18,8 @@ #ifndef INCLUDED_UHD_ERROR_H #define INCLUDED_UHD_ERROR_H +#include <stdlib.h> + //! UHD error codes /*! * Each error code corresponds to a specific uhd::exception, with @@ -81,8 +83,14 @@ typedef enum { #include <boost/exception/diagnostic_information.hpp> +#include <string> + UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e); +UHD_API const std::string& get_c_global_error_string(); + +UHD_API void set_c_global_error_string(const std::string &msg); + /*! * This macro runs the given C++ code, and if there are any exceptions * thrown, they are caught and converted to the corresponding UHD error @@ -91,17 +99,22 @@ UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e); #define UHD_SAFE_C(...) \ try{ __VA_ARGS__ } \ catch (const uhd::exception &e) { \ + set_c_global_error_string(e.what()); \ return error_from_uhd_exception(&e); \ } \ - catch (const boost::exception&) { \ + catch (const boost::exception &e) { \ + set_c_global_error_string(boost::diagnostic_information(e)); \ return UHD_ERROR_BOOSTEXCEPT; \ } \ - catch (const std::exception&) { \ + catch (const std::exception &e) { \ + set_c_global_error_string(e.what()); \ return UHD_ERROR_STDEXCEPT; \ } \ catch (...) { \ + set_c_global_error_string("Unrecognized exception caught."); \ return UHD_ERROR_UNKNOWN; \ } \ + set_c_global_error_string("None"); \ return UHD_ERROR_NONE; /*! @@ -113,24 +126,44 @@ UHD_API uhd_error error_from_uhd_exception(const uhd::exception* e); h->last_error.clear(); \ try{ __VA_ARGS__ } \ catch (const uhd::exception &e) { \ + set_c_global_error_string(e.what()); \ h->last_error = e.what(); \ return error_from_uhd_exception(&e); \ } \ catch (const boost::exception &e) { \ + set_c_global_error_string(boost::diagnostic_information(e)); \ h->last_error = boost::diagnostic_information(e); \ return UHD_ERROR_BOOSTEXCEPT; \ } \ catch (const std::exception &e) { \ + set_c_global_error_string(e.what()); \ h->last_error = e.what(); \ return UHD_ERROR_STDEXCEPT; \ } \ catch (...) { \ + set_c_global_error_string("Unrecognized exception caught."); \ h->last_error = "Unrecognized exception caught."; \ return UHD_ERROR_UNKNOWN; \ } \ h->last_error = "None"; \ + set_c_global_error_string("None"); \ return UHD_ERROR_NONE; +extern "C" { +#endif + +//! Return the last error string reported by UHD +/*! + * Functions that do not take in UHD structs/handles will place any error + * strings into a buffer that can be queried with this function. Functions that + * do take in UHD structs/handles will place their error strings in both locations. + */ +uhd_error uhd_get_last_error( + char* error_out, + size_t strbuffer_len +); +#ifdef __cplusplus +} #endif #endif /* INCLUDED_UHD_ERROR_H */ diff --git a/host/include/uhd/types/CMakeLists.txt b/host/include/uhd/types/CMakeLists.txt index 07a752806..3f34782e2 100644 --- a/host/include/uhd/types/CMakeLists.txt +++ b/host/include/uhd/types/CMakeLists.txt @@ -45,10 +45,10 @@ UHD_INSTALL(FILES IF(ENABLE_C_API) UHD_INSTALL(FILES - device_addrs.h metadata.h ranges.h sensors.h + string_vector.h tune_request.h tune_result.h usrp_info.h diff --git a/host/include/uhd/types/device_addrs.h b/host/include/uhd/types/device_addrs.h deleted file mode 100644 index 3acc7f179..000000000 --- a/host/include/uhd/types/device_addrs.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2015 Ettus Research - * - * 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 <http://www.gnu.org/licenses/>. - */ - -#ifndef INCLUDED_UHD_TYPES_DEVICE_ADDRS_H -#define INCLUDED_UHD_TYPES_DEVICE_ADDRS_H - -#include <uhd/config.h> -#include <uhd/error.h> - -#include <stdlib.h> - -#ifdef __cplusplus -#include <uhd/types/device_addr.hpp> -#include <string> - -struct uhd_device_addrs_t { - uhd::device_addrs_t device_addrs_cpp; - std::string last_error; -}; - -extern "C" { -#else -struct uhd_device_addrs_t; -#endif - -//! C-level interface for interacting with a list of device addresses -/*! - * See uhd::device_addrs_t for more information. - */ -typedef struct uhd_device_addrs_t* uhd_device_addrs_handle; - -//! Instantiate a device_addrs handle. -UHD_API uhd_error uhd_device_addrs_make( - uhd_device_addrs_handle *h -); - -//! Safely destroy a device_addrs handle. -UHD_API uhd_error uhd_device_addrs_free( - uhd_device_addrs_handle *h -); - -//! Add a device address to the list in string form -UHD_API uhd_error uhd_device_addrs_push_back( - uhd_device_addrs_handle h, - const char* value -); - -//! Get the device information (in string form) at the given index -UHD_API uhd_error uhd_device_addrs_at( - uhd_device_addrs_handle h, - size_t index, - char* value_out, - size_t strbuffer_len -); - -//! Get the number of device addresses in this list -UHD_API uhd_error uhd_device_addrs_size( - uhd_device_addrs_handle h, - size_t *size_out -); - -//! Get the last error reported by the underlying object -UHD_API uhd_error uhd_device_addrs_last_error( - uhd_device_addrs_handle h, - char* error_out, - size_t strbuffer_len -); - -#ifdef __cplusplus -} -#endif - -#endif /* INCLUDED_UHD_TYPES_DEVICE_ADDRS_H */ diff --git a/host/include/uhd/types/string_vector.h b/host/include/uhd/types/string_vector.h new file mode 100644 index 000000000..685b05f3f --- /dev/null +++ b/host/include/uhd/types/string_vector.h @@ -0,0 +1,86 @@ +/* + * Copyright 2015 Ettus Research + * + * 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 <http://www.gnu.org/licenses/>. + */ + +#ifndef INCLUDED_UHD_TYPES_STRING_VECTOR_H +#define INCLUDED_UHD_TYPES_STRING_VECTOR_H + +#include <uhd/config.h> +#include <uhd/error.h> + +#include <stdlib.h> + +#ifdef __cplusplus +#include <string> +#include <vector> + +struct uhd_string_vector_t { + std::vector<std::string> string_vector_cpp; + std::string last_error; +}; + +extern "C" { +#else +//! C-level read-only interface for interacting with a string vector +struct uhd_string_vector_t; +#endif + +typedef struct uhd_string_vector_t uhd_string_vector_t; + +typedef uhd_string_vector_t* uhd_string_vector_handle; + +//! Instantiate a string_vector handle. +UHD_API uhd_error uhd_string_vector_make( + uhd_string_vector_handle *h +); + +//! Safely destroy a string_vector handle. +UHD_API uhd_error uhd_string_vector_free( + uhd_string_vector_handle *h +); + +//! Add a string to the list +UHD_API uhd_error uhd_string_vector_push_back( + uhd_string_vector_handle *h, + const char* value +); + +//! Get the string at the given index +UHD_API uhd_error uhd_string_vector_at( + uhd_string_vector_handle h, + size_t index, + char* value_out, + size_t strbuffer_len +); + +//! Get the number of strings in this list +UHD_API uhd_error uhd_string_vector_size( + uhd_string_vector_handle h, + size_t *size_out +); + +//! Get the last error reported by the underlying object +UHD_API uhd_error uhd_string_vector_last_error( + uhd_string_vector_handle h, + char* error_out, + size_t strbuffer_len +); + +#ifdef __cplusplus +} +#endif + +#endif /* INCLUDED_UHD_TYPES_STRING_VECTOR_H */ diff --git a/host/include/uhd/usrp/usrp.h b/host/include/uhd/usrp/usrp.h index 99a06b6e1..ab9c4d28f 100644 --- a/host/include/uhd/usrp/usrp.h +++ b/host/include/uhd/usrp/usrp.h @@ -20,10 +20,10 @@ #include <uhd/config.h> #include <uhd/error.h> -#include <uhd/types/device_addrs.h> #include <uhd/types/metadata.h> #include <uhd/types/ranges.h> #include <uhd/types/sensors.h> +#include <uhd/types/string_vector.h> #include <uhd/types/tune_request.h> #include <uhd/types/tune_result.h> #include <uhd/types/usrp_info.h> @@ -158,7 +158,7 @@ UHD_API uhd_error uhd_rx_streamer_recv( uhd_rx_streamer_handle h, void** buffs, size_t samps_per_buff, - uhd_rx_metadata_handle md, + uhd_rx_metadata_handle *md, double timeout, bool one_packet, size_t *items_recvd @@ -237,7 +237,7 @@ UHD_API uhd_error uhd_tx_streamer_send( uhd_tx_streamer_handle h, const void **buffs, size_t samps_per_buff, - uhd_tx_metadata_handle md, + uhd_tx_metadata_handle *md, double timeout, size_t *items_sent ); @@ -248,7 +248,7 @@ UHD_API uhd_error uhd_tx_streamer_send( */ UHD_API uhd_error uhd_tx_streamer_recv_async_msg( uhd_tx_streamer_handle h, - uhd_async_metadata_handle md, + uhd_async_metadata_handle *md, double timeout, bool *valid ); @@ -297,9 +297,8 @@ extern "C" { * See uhd::device::find() for more details. */ UHD_API uhd_error uhd_usrp_find( - uhd_device_addrs_handle h, const char* args, - size_t *num_found + uhd_string_vector_handle *strings_out ); //! Create a USRP handle. @@ -488,16 +487,6 @@ UHD_API uhd_error uhd_usrp_clear_command_time( size_t mboard ); -//! Issue a stream command to tell the device to send samples to the host -/*! - * See uhd::usrp::multi_usrp::issue_stream_command() for more details. - */ -UHD_API uhd_error uhd_usrp_issue_stream_cmd( - uhd_usrp_handle h, - uhd_stream_cmd_t *stream_cmd, - size_t chan -); - //! Set the time source for the given device /*! * See uhd::usrp::multi_usrp::set_time_source() for more details. @@ -520,23 +509,10 @@ UHD_API uhd_error uhd_usrp_get_time_source( ); //! Get a list of time sources for the given device -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of time sources. - * - * \param h USRP handle - * \param mboard which motherboard to use - * \param time_sources_out string buffer in which to place time sources - * \param strbuffer_len buffer length - * \param num_time_sources_out variable in which to place number of time sources - */ UHD_API uhd_error uhd_usrp_get_time_sources( uhd_usrp_handle h, size_t mboard, - char* time_sources_out, - size_t strbuffer_len, - size_t *num_time_sources_out + uhd_string_vector_handle *time_sources_out ); //! Set the given device's clock source @@ -561,23 +537,10 @@ UHD_API uhd_error uhd_usrp_get_clock_source( ); //! Get a list of clock sources for the given device -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of clock sources. - * - * \param h USRP handle - * \param mboard which motherboard to use - * \param clock_sources_out string buffer in which to place clock sources - * \param strbuffer_len buffer length - * \param num_clock_sources_out variable in which to place number of clock sources - */ UHD_API uhd_error uhd_usrp_get_clock_sources( uhd_usrp_handle h, size_t mboard, - char* clock_sources_out, - size_t strbuffer_len, - size_t *num_clock_sources_out + uhd_string_vector_handle *clock_sources_out ); //! Enable or disable sending the clock source to an output connector @@ -611,27 +574,14 @@ UHD_API uhd_error uhd_usrp_get_mboard_sensor( uhd_usrp_handle h, const char* name, size_t mboard, - uhd_sensor_value_handle sensor_value_out + uhd_sensor_value_handle *sensor_value_out ); //! Get a list of motherboard sensors for the given device -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of motherboard sensors. - * - * \param h USRP handle - * \param mboard which motherboard to use - * \param mboard_sensors_out string buffer in which to place motherboard sensors - * \param strbuffer_len buffer length - * \param num_mboard_sensors_out variable in which to place number of motherboard sensors - */ UHD_API uhd_error uhd_usrp_get_mboard_sensor_names( uhd_usrp_handle h, size_t mboard, - char* mboard_sensor_names_out, - size_t strbuffer_len, - size_t *num_mboard_sensors_out + uhd_string_vector_handle *mboard_sensor_names_out ); //! Perform a write on a user configuration register bus @@ -824,23 +774,10 @@ UHD_API uhd_error uhd_usrp_get_rx_gain_range( ); //! Get a list of RX gain names for the given channel -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of RX gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param rx_gain_names_out string buffer in which to place RX gain names - * \param strbuffer_len buffer length - * \param num_rx_gain_names_out variable in which to place number of RX gain names - */ UHD_API uhd_error uhd_usrp_get_rx_gain_names( uhd_usrp_handle h, size_t chan, - char* gain_names_out, - size_t strbuffer_len, - size_t *num_rx_gain_names_out + uhd_string_vector_handle *gain_names_out ); //! Set the RX antenna for the given channel @@ -859,43 +796,17 @@ UHD_API uhd_error uhd_usrp_get_rx_antenna( ); //! Get a list of RX antennas associated with the given channels -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of RX gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param rx_antennas_out string buffer in which to place RX antennas - * \param strbuffer_len buffer length - * \param num_rx_antennas_out variable in which to place number of RX gain names - */ UHD_API uhd_error uhd_usrp_get_rx_antennas( uhd_usrp_handle h, size_t chan, - char* antennas_out, - size_t strbuffer_len, - size_t *num_rx_antennas_out + uhd_string_vector_handle *antennas_out ); //! Get a list of RX sensors associated with the given channels -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of RX gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param sensor_names_out string buffer in which to place RX sensor names - * \param strbuffer_len buffer length - * \param num_rx_sensors_out variable in which to place number of RX sensor names - */ UHD_API uhd_error uhd_usrp_get_rx_sensor_names( uhd_usrp_handle h, size_t chan, - char* sensor_names_out, - size_t strbuffer_len, - size_t *num_rx_sensors_out + uhd_string_vector_handle *sensor_names_out ); //! Set the bandwidth for the given channel's RX frontend @@ -924,7 +835,7 @@ UHD_API uhd_error uhd_usrp_get_rx_sensor( uhd_usrp_handle h, const char* name, size_t chan, - uhd_sensor_value_handle sensor_value_out + uhd_sensor_value_handle *sensor_value_out ); //! Enable or disable RX DC offset correction for the given channel @@ -1077,23 +988,10 @@ UHD_API uhd_error uhd_usrp_get_normalized_tx_gain( ); //! Get a list of TX gain names for the given channel -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of TX gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param tx_gain_names_out string buffer in which to place TX gain names - * \param strbuffer_len buffer length - * \param num_tx_gain_names_out variable in which to place number of TX gain names - */ UHD_API uhd_error uhd_usrp_get_tx_gain_names( uhd_usrp_handle h, size_t chan, - char* gain_names_out, - size_t strbuffer_len, - size_t *num_tx_gain_names_out + uhd_string_vector_handle *gain_names_out ); //! Set the TX antenna for the given channel @@ -1112,23 +1010,10 @@ UHD_API uhd_error uhd_usrp_get_tx_antenna( ); //! Get a list of tx antennas associated with the given channels -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of tx gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param tx_antennas_out string buffer in which to place TX antennas - * \param strbuffer_len buffer length - * \param num_tx_antennas_out variable in which to place number of TX gain names - */ UHD_API uhd_error uhd_usrp_get_tx_antennas( uhd_usrp_handle h, size_t chan, - char* antennas_out, - size_t strbuffer_len, - size_t *num_tx_antennas_out + uhd_string_vector_handle *antennas_out ); //! Set the bandwidth for the given channel's TX frontend @@ -1157,27 +1042,14 @@ UHD_API uhd_error uhd_usrp_get_tx_sensor( uhd_usrp_handle h, const char* name, size_t chan, - uhd_sensor_value_handle sensor_value_out + uhd_sensor_value_handle *sensor_value_out ); //! Get a list of TX sensors associated with the given channels -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of TX gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param sensor_names_out string buffer in which to place TX sensor names - * \param strbuffer_len buffer length - * \param num_tx_sensors_out variable in which to place number of TX sensor names - */ UHD_API uhd_error uhd_usrp_get_tx_sensor_names( uhd_usrp_handle h, size_t chan, - char* sensor_names_out, - size_t strbuffer_len, - size_t *num_tx_sensors_out + uhd_string_vector_handle *sensor_names_out ); //! Enable or disable TX DC offset correction for the given channel @@ -1202,23 +1074,10 @@ UHD_API uhd_error uhd_usrp_set_tx_iq_balance_enabled( ***************************************************************************/ //! Get a list of GPIO banks associated with the given channels -/*! - * The list will be returned as a comma-delimited list that can - * be parsed with strtok(). The function will also return the number - * of TX gain names. - * - * \param h USRP handle - * \param channel which channel to use - * \param gpio_banks_out string buffer in which to place GPIO banks - * \param strbuffer_len buffer length - * \param num_gpio_banks_out variable in which to place number of GPIO banks - */ UHD_API uhd_error uhd_usrp_get_gpio_banks( uhd_usrp_handle h, size_t mboard, - char* gpio_banks_out, - size_t strbuffer_len, - size_t *num_gpio_banks_out + uhd_string_vector_handle *gpio_banks_out ); //! Set a GPIO attribute for a given GPIO bank diff --git a/host/include/uhd/usrp_clock/usrp_clock.h b/host/include/uhd/usrp_clock/usrp_clock.h index 4a9eb871e..39ce04c8c 100644 --- a/host/include/uhd/usrp_clock/usrp_clock.h +++ b/host/include/uhd/usrp_clock/usrp_clock.h @@ -20,8 +20,8 @@ #include <uhd/config.h> #include <uhd/error.h> -#include <uhd/types/device_addrs.h> #include <uhd/types/sensors.h> +#include <uhd/types/string_vector.h> #include <stdlib.h> #include <stdint.h> @@ -53,9 +53,8 @@ extern "C" { * See uhd::device::find() for more details. */ UHD_API uhd_error uhd_usrp_clock_find( - uhd_device_addrs_handle h, const char* args, - size_t *num_found + uhd_string_vector_t *devices_out ); //! Create a clock handle. @@ -109,16 +108,14 @@ UHD_API uhd_error uhd_usrp_clock_get_sensor( uhd_usrp_clock_handle h, const char* name, size_t board, - uhd_sensor_value_handle sensor_value_out + uhd_sensor_value_handle *sensor_value_out ); //! Get sensor names UHD_API uhd_error uhd_usrp_clock_get_sensor_names( uhd_usrp_clock_handle h, size_t board, - char *sensor_names_out, - size_t strbuffer_len, - size_t *num_sensors_out + uhd_string_vector_handle *sensor_names_out ); #ifdef __cplusplus |