From bc615618b320969adfd9f59e38719705cdaf159f Mon Sep 17 00:00:00 2001 From: Martin Braun Date: Wed, 14 Mar 2018 16:22:17 -0700 Subject: example: Refactor gpio.cpp Minor changes: - Remove some Boost usage - Minor formatting changes --- host/examples/gpio.cpp | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/host/examples/gpio.cpp b/host/examples/gpio.cpp index 1551489dd..d89bf7d1c 100644 --- a/host/examples/gpio.cpp +++ b/host/examples/gpio.cpp @@ -67,14 +67,14 @@ #include #include #include -#include #include #include -#include -#include #include #include +#include +#include #include +#include static const std::string GPIO_DEFAULT_CPU_FORMAT = "fc32"; static const std::string GPIO_DEFAULT_OTW_FORMAT = "sc16"; @@ -112,17 +112,27 @@ std::string to_bit_string(uint32_t val, const size_t num_bits) void output_reg_values( const std::string bank, const uhd::usrp::multi_usrp::sptr &usrp, - const size_t num_bits) -{ - std::vector attrs = boost::assign::list_of("CTRL")("DDR")("ATR_0X")("ATR_RX")("ATR_TX")("ATR_XX")("OUT")("READBACK"); + const size_t num_bits +) { + const std::vector attrs = { + "CTRL", + "DDR", + "ATR_0X", + "ATR_RX", + "ATR_TX", + "ATR_XX", + "OUT", + "READBACK" + }; std::cout << (boost::format("%10s ") % "Bit"); for (int i = num_bits - 1; i >= 0; i--) std::cout << (boost::format(" %2d") % i); std::cout << std::endl; - for(std::string &attr: attrs) - { - std::cout << (boost::format("%10s:%s") - % attr % to_bit_string(uint32_t(usrp->get_gpio_attr(bank, attr)), num_bits)) + for (const auto &attr : attrs) { + const uint32_t gpio_bits = uint32_t(usrp->get_gpio_attr(bank, attr)); + std::cout + << (boost::format("%10s:%s") + % attr % to_bit_string(gpio_bits, num_bits)) << std::endl; } } @@ -303,7 +313,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]) { rb = usrp->get_gpio_attr(gpio, "READBACK"); std::cout << "\rREADBACK: " << to_bit_string(rb, num_bits); - boost::this_thread::sleep(boost::posix_time::milliseconds(10)); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); } std::cout << std::endl; } @@ -315,7 +325,7 @@ int UHD_SAFE_MAIN(int argc, char *argv[]) stop_time = usrp->get_time_now() + dwell_time; while (not stop_signal_called and usrp->get_time_now() < stop_time) { - boost::this_thread::sleep(boost::posix_time::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); } rb = usrp->get_gpio_attr(gpio, "READBACK"); expected = GPIO_BIT(4) | GPIO_BIT(0); -- cgit v1.2.3