diff options
author | Martin Braun <martin.braun@ettus.com> | 2017-08-22 18:13:37 -0700 |
---|---|---|
committer | michael-west <michael.west@ettus.com> | 2017-08-29 18:33:54 -0700 |
commit | 8a3038b6c7d22c09b66597329d6e14b30d294f16 (patch) | |
tree | 41732f669f886d4dac59684c500e0a7cd7fb13b6 /host/lib/usrp/dboard_eeprom_c.cpp | |
parent | 92515a0477fdf3da79b66cfdb918abf1d9dad613 (diff) | |
download | uhd-8a3038b6c7d22c09b66597329d6e14b30d294f16.tar.gz uhd-8a3038b6c7d22c09b66597329d6e14b30d294f16.tar.bz2 uhd-8a3038b6c7d22c09b66597329d6e14b30d294f16.zip |
C API: Dboard EEPROM revision error handling fix
For invalid dboard revisions stored in the EEPROM, provide a better
error message.
Diffstat (limited to 'host/lib/usrp/dboard_eeprom_c.cpp')
-rw-r--r-- | host/lib/usrp/dboard_eeprom_c.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/host/lib/usrp/dboard_eeprom_c.cpp b/host/lib/usrp/dboard_eeprom_c.cpp index e3ef4933f..9bfa48b66 100644 --- a/host/lib/usrp/dboard_eeprom_c.cpp +++ b/host/lib/usrp/dboard_eeprom_c.cpp @@ -19,6 +19,7 @@ #include <uhd/error.h> #include <boost/lexical_cast.hpp> +#include <boost/format.hpp> #include <string.h> @@ -79,12 +80,28 @@ uhd_error uhd_dboard_eeprom_set_serial( ) } +//! Convert a string into an int. If that doesn't work, craft our own exception +// instead of using the Boost exception. We need to put this separate from the +// caller function because of macro expansion. +int _convert_rev_with_exception(const std::string &rev_str) +{ + try { + return boost::lexical_cast<int>(rev_str); + } catch (const boost::bad_lexical_cast &) { + throw uhd::lookup_error(str( + boost::format("Error retrieving revision from string `%s`") + % rev_str + )); + } +} + uhd_error uhd_dboard_eeprom_get_revision( uhd_dboard_eeprom_handle h, int* revision_out ){ UHD_SAFE_C_SAVE_ERROR(h, - *revision_out = boost::lexical_cast<int>(h->dboard_eeprom_cpp.revision); + *revision_out = \ + _convert_rev_with_exception(h->dboard_eeprom_cpp.revision); ) } |