diff options
author | Lane Kolbly <lane.kolbly@ni.com> | 2021-01-06 11:34:05 -0600 |
---|---|---|
committer | Aaron Rossetto <aaron.rossetto@ni.com> | 2021-01-11 12:23:24 -0600 |
commit | c9b35e3b7107ab82c0e3978b7cbfd76ba98e2407 (patch) | |
tree | 3e161a882f8005baf04b3a802dc7636a579643e2 /host/lib/usrp/mpmd | |
parent | 7f765f4f2be719473ee329c00f7125a785057deb (diff) | |
download | uhd-c9b35e3b7107ab82c0e3978b7cbfd76ba98e2407.tar.gz uhd-c9b35e3b7107ab82c0e3978b7cbfd76ba98e2407.tar.bz2 uhd-c9b35e3b7107ab82c0e3978b7cbfd76ba98e2407.zip |
Create C++ wrappers for MPM RPC calls
This gives us type-safety, as well as allowing us to create unit tests for
RFNoC radio_controls without having to create actual RPC servers and clients
in the unit tests.
This change also fixes a bug in mpmd_mb_controller::set_sync_source, where
it was calling the wrong MPM function.
Diffstat (limited to 'host/lib/usrp/mpmd')
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_mb_controller.cpp | 55 | ||||
-rw-r--r-- | host/lib/usrp/mpmd/mpmd_mboard_impl.cpp | 2 |
2 files changed, 25 insertions, 32 deletions
diff --git a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp index 0a9cc54f0..dba8713c4 100644 --- a/host/lib/usrp/mpmd/mpmd_mb_controller.cpp +++ b/host/lib/usrp/mpmd/mpmd_mb_controller.cpp @@ -15,25 +15,23 @@ constexpr size_t MPMD_DEFAULT_LONG_TIMEOUT = 30000; // ms } // namespace mpmd_mb_controller::mpmd_mb_controller( - uhd::rpc_client::sptr rpcc, uhd::device_addr_t device_info) + uhd::usrp::mpmd_rpc_iface::sptr rpcc, uhd::device_addr_t device_info) : _rpc(rpcc), _device_info(device_info) { - const size_t num_tks = _rpc->request_with_token<size_t>("get_num_timekeepers"); + const size_t num_tks = _rpc->get_num_timekeepers(); for (size_t tk_idx = 0; tk_idx < num_tks; tk_idx++) { register_timekeeper(tk_idx, std::make_shared<mpmd_timekeeper>(tk_idx, _rpc)); } // Enumerate sensors - auto sensor_list = - _rpc->request_with_token<std::vector<std::string>>("get_mb_sensors"); + auto sensor_list = _rpc->get_mb_sensors(); UHD_LOG_DEBUG("MPMD", "Found " << sensor_list.size() << " motherboard sensors."); _sensor_names.insert(sensor_list.cbegin(), sensor_list.cend()); // Enumerate GPIO banks that are under mb_controller control - _gpio_banks = _rpc->request_with_token<std::vector<std::string>>("get_gpio_banks"); + _gpio_banks = _rpc->get_gpio_banks(); for (const auto& bank : _gpio_banks) { - _gpio_srcs.insert({bank, - _rpc->request_with_token<std::vector<std::string>>("get_gpio_srcs", bank)}); + _gpio_srcs.insert({bank, _rpc->get_gpio_srcs(bank)}); } } @@ -42,27 +40,27 @@ mpmd_mb_controller::mpmd_mb_controller( *****************************************************************************/ uint64_t mpmd_mb_controller::mpmd_timekeeper::get_ticks_now() { - return _rpc->request_with_token<uint64_t>("get_timekeeper_time", _tk_idx, false); + return _rpc->get_timekeeper_time(_tk_idx, false); } uint64_t mpmd_mb_controller::mpmd_timekeeper::get_ticks_last_pps() { - return _rpc->request_with_token<uint64_t>("get_timekeeper_time", _tk_idx, true); + return _rpc->get_timekeeper_time(_tk_idx, true); } void mpmd_mb_controller::mpmd_timekeeper::set_ticks_now(const uint64_t ticks) { - _rpc->notify_with_token("set_timekeeper_time", _tk_idx, ticks, false); + _rpc->set_timekeeper_time(_tk_idx, ticks, false); } void mpmd_mb_controller::mpmd_timekeeper::set_ticks_next_pps(const uint64_t ticks) { - _rpc->notify_with_token("set_timekeeper_time", _tk_idx, ticks, true); + _rpc->set_timekeeper_time(_tk_idx, ticks, true); } void mpmd_mb_controller::mpmd_timekeeper::set_period(const uint64_t period_ns) { - _rpc->notify_with_token("set_tick_period", _tk_idx, period_ns); + _rpc->set_tick_period(_tk_idx, period_ns); } void mpmd_mb_controller::mpmd_timekeeper::update_tick_rate(const double tick_rate) @@ -80,32 +78,32 @@ std::string mpmd_mb_controller::get_mboard_name() const void mpmd_mb_controller::set_time_source(const std::string& source) { - _rpc->notify_with_token(MPMD_DEFAULT_LONG_TIMEOUT, "set_time_source", source); + _rpc->get_raw_rpc_client()->notify_with_token(MPMD_DEFAULT_LONG_TIMEOUT, "set_time_source", source); } std::string mpmd_mb_controller::get_time_source() const { - return _rpc->request_with_token<std::string>("get_time_source"); + return _rpc->get_time_source(); } std::vector<std::string> mpmd_mb_controller::get_time_sources() const { - return _rpc->request_with_token<std::vector<std::string>>("get_time_sources"); + return _rpc->get_time_sources(); } void mpmd_mb_controller::set_clock_source(const std::string& source) { - _rpc->notify_with_token(MPMD_DEFAULT_LONG_TIMEOUT, "set_clock_source", source); + _rpc->get_raw_rpc_client()->notify_with_token(MPMD_DEFAULT_LONG_TIMEOUT, "set_clock_source", source); } std::string mpmd_mb_controller::get_clock_source() const { - return _rpc->request_with_token<std::string>("get_clock_source"); + return _rpc->get_clock_source(); } std::vector<std::string> mpmd_mb_controller::get_clock_sources() const { - return _rpc->request_with_token<std::vector<std::string>>("get_clock_sources"); + return _rpc->get_clock_sources(); } void mpmd_mb_controller::set_sync_source( @@ -123,23 +121,20 @@ void mpmd_mb_controller::set_sync_source(const device_addr_t& sync_source) for (const auto& key : sync_source.keys()) { sync_source_map[key] = sync_source.get(key); } - _rpc->notify_with_token( - MPMD_DEFAULT_LONG_TIMEOUT, "set_clock_source", sync_source_map); + _rpc->get_raw_rpc_client()->notify_with_token( + MPMD_DEFAULT_LONG_TIMEOUT, "set_sync_source", sync_source_map); } device_addr_t mpmd_mb_controller::get_sync_source() const { - const auto sync_source_map = - _rpc->request_with_token<std::map<std::string, std::string>>("get_sync_source"); + const auto sync_source_map = _rpc->get_sync_source(); return device_addr_t(sync_source_map); } std::vector<device_addr_t> mpmd_mb_controller::get_sync_sources() { std::vector<device_addr_t> result; - const auto sync_sources = - _rpc->request_with_token<std::vector<std::map<std::string, std::string>>>( - "get_sync_sources"); + const auto sync_sources = _rpc->get_sync_sources(); for (auto& sync_source : sync_sources) { result.push_back(device_addr_t(sync_source)); } @@ -164,8 +159,7 @@ sensor_value_t mpmd_mb_controller::get_sensor(const std::string& name) if (!_sensor_names.count(name)) { throw uhd::key_error(std::string("Invalid motherboard sensor name: ") + name); } - return sensor_value_t( - _rpc->request_with_token<sensor_value_t::sensor_map_t>("get_mb_sensor", name)); + return sensor_value_t(_rpc->get_mb_sensor(name)); } std::vector<std::string> mpmd_mb_controller::get_sensor_names() @@ -176,8 +170,7 @@ std::vector<std::string> mpmd_mb_controller::get_sensor_names() uhd::usrp::mboard_eeprom_t mpmd_mb_controller::get_eeprom() { - auto mb_eeprom = - _rpc->request_with_token<std::map<std::string, std::string>>("get_mb_eeprom"); + auto mb_eeprom = _rpc->get_mb_eeprom(); uhd::usrp::mboard_eeprom_t mb_eeprom_dict(mb_eeprom.cbegin(), mb_eeprom.cend()); return mb_eeprom_dict; } @@ -202,7 +195,7 @@ std::vector<std::string> mpmd_mb_controller::get_gpio_src(const std::string& ban UHD_LOG_ERROR("MPMD", "Invalid GPIO bank: `" << bank << "'"); throw uhd::key_error(std::string("Invalid GPIO bank: ") + bank); } - return _rpc->request_with_token<std::vector<std::string>>("get_gpio_src", bank); + return _rpc->get_gpio_src(bank); } void mpmd_mb_controller::set_gpio_src( @@ -212,5 +205,5 @@ void mpmd_mb_controller::set_gpio_src( UHD_LOG_ERROR("MPMD", "Invalid GPIO bank: `" << bank << "'"); throw uhd::key_error(std::string("Invalid GPIO bank: ") + bank); } - _rpc->notify_with_token("set_gpio_src", bank, src); + _rpc->set_gpio_src(bank, src); } diff --git a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp index 9fa0d43de..ac620f3e0 100644 --- a/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp +++ b/host/lib/usrp/mpmd/mpmd_mboard_impl.cpp @@ -308,7 +308,7 @@ mpmd_mboard_impl::mpmd_mboard_impl( if (!mb_args.has_key("skip_init")) { // Initialize mb_iface and mb_controller mb_iface = std::make_unique<mpmd_mb_iface>(mb_args, rpc); - mb_ctrl = std::make_shared<rfnoc::mpmd_mb_controller>(rpc, device_info); + mb_ctrl = std::make_shared<rfnoc::mpmd_mb_controller>(std::make_shared<uhd::usrp::mpmd_rpc>(rpc), device_info); } // Note -- when skip_init is used, these are not initialized, and trying // to use them will result in a null pointer dereference exception! } |