Beispiel #1
0
uint32_t _extract_port_number(
    std::string radio_src_string, uhd::property_tree::sptr ptree)
{
    std::string s_val = "0";
    std::vector<std::string> radio_strings;
    boost::algorithm::split(radio_strings,
        radio_src_string,
        boost::is_any_of("_/"),
        boost::token_compress_on);
    boost::to_lower(radio_strings[0]);
    if (radio_strings.size() < 3) {
        throw uhd::runtime_error(str(
            boost::format("%s is an invalid GPIO source string.") % radio_src_string));
    }
    size_t radio_num = std::stoi(radio_strings[1]);
    size_t port_num  = std::stoi(radio_strings[2]);
    if (radio_strings[0] != "radio") {
        throw uhd::runtime_error(
            "Front panel GPIO bank can only accept a radio block as its driver.");
    }
    std::string radio_port_out  = "Radio_" + radio_strings[1] + "/ports/out";
    std::string radio_port_path = radio_port_out + "/" + radio_strings[2];
    auto found                  = ptree->exists(fs_path("xbar") / radio_port_path);
    if (not found) {
        throw uhd::runtime_error(
            str(boost::format("Could not find radio port %s.\n") % radio_port_path));
    }
    size_t port_size = ptree->list(fs_path("xbar") / radio_port_out).size();
    return radio_num * port_size + port_num;
}
Beispiel #2
0
void mpmd_impl::init_property_tree(
    uhd::property_tree::sptr tree, fs_path mb_path, mpmd_mboard_impl* mb)
{
    /*** Device info ****************************************************/
    if (not tree->exists("/name")) {
        tree->create<std::string>("/name").set(
            mb->device_info.get("description", "Unknown MPM device"));
    }
    tree->create<std::string>(mb_path / "name")
        .set(mb->device_info.get("name", "UNKNOWN"));
    tree->create<std::string>(mb_path / "serial")
        .set(mb->device_info.get("serial", "n/a"));
    tree->create<std::string>(mb_path / "connection")
        .set(mb->device_info.get("connection", "UNKNOWN"));
    tree->create<size_t>(mb_path / "link_max_rate").set(1e9 / 8);
    tree->create<std::string>(mb_path / "mpm_version")
        .set(mb->device_info.get("mpm_version", "UNKNOWN"));
    tree->create<std::string>(mb_path / "fpga_version")
        .set(mb->device_info.get("fpga_version", "UNKNOWN"));
    tree->create<std::string>(mb_path / "fpga_version_hash")
        .set(mb->device_info.get("fpga_version_hash", "UNKNOWN"));

    /*** Clocking *******************************************************/
    tree->create<std::string>(mb_path / "clock_source/value")
        .add_coerced_subscriber([mb](const std::string& clock_source) {
            mb->rpc->notify_with_token(
                MPMD_DEFAULT_INIT_TIMEOUT, "set_clock_source", clock_source);
        })
        .set_publisher([mb]() {
            return mb->rpc->request_with_token<std::string>("get_clock_source");
        });
    tree->create<std::vector<std::string>>(mb_path / "clock_source/options")
        .set_publisher([mb]() {
            return mb->rpc->request_with_token<std::vector<std::string>>(
                "get_clock_sources");
        });
    tree->create<std::string>(mb_path / "time_source/value")
        .add_coerced_subscriber([mb](const std::string& time_source) {
            mb->rpc->notify_with_token(
                MPMD_DEFAULT_INIT_TIMEOUT, "set_time_source", time_source);
        })
        .set_publisher([mb]() {
            return mb->rpc->request_with_token<std::string>("get_time_source");
        });
    tree->create<std::vector<std::string>>(mb_path / "time_source/options")
        .set_publisher([mb]() {
            return mb->rpc->request_with_token<std::vector<std::string>>(
                "get_time_sources");
        });

    /*** Sensors ********************************************************/
    auto sensor_list =
        mb->rpc->request_with_token<std::vector<std::string>>("get_mb_sensors");
    UHD_LOG_DEBUG("MPMD", "Found " << sensor_list.size() << " motherboard sensors.");
    for (const auto& sensor_name : sensor_list) {
        UHD_LOG_TRACE("MPMD", "Adding motherboard sensor `" << sensor_name << "'");
        tree->create<sensor_value_t>(mb_path / "sensors" / sensor_name)
            .set_publisher([mb, sensor_name]() {
                auto sensor_val = sensor_value_t(
                    mb->rpc->request_with_token<sensor_value_t::sensor_map_t>(
                        MPMD_DEFAULT_INIT_TIMEOUT, "get_mb_sensor", sensor_name));
                return sensor_val;
            })
            .set_coercer([](const sensor_value_t&) {
                throw uhd::runtime_error("Trying to write read-only sensor value!");
                return sensor_value_t("", "", "");
            });
    }

    /*** EEPROM *********************************************************/
    tree->create<uhd::usrp::mboard_eeprom_t>(mb_path / "eeprom")
        .add_coerced_subscriber([mb](const uhd::usrp::mboard_eeprom_t& mb_eeprom) {
            eeprom_map_t eeprom_map;
            for (const auto& key : mb_eeprom.keys()) {
                eeprom_map[key] =
                    std::vector<uint8_t>(mb_eeprom[key].cbegin(), mb_eeprom[key].cend());
            }
            mb->rpc->notify_with_token(
                MPMD_DEFAULT_INIT_TIMEOUT, "set_mb_eeprom", eeprom_map);
        })
        .set_publisher([mb]() {
            auto mb_eeprom =
                mb->rpc->request_with_token<std::map<std::string, std::string>>(
                    "get_mb_eeprom");
            uhd::usrp::mboard_eeprom_t mb_eeprom_dict(
                mb_eeprom.cbegin(), mb_eeprom.cend());
            return mb_eeprom_dict;
        });

    /*** Updateable Components ******************************************/
    std::vector<std::string> updateable_components =
        mb->rpc->request<std::vector<std::string>>("list_updateable_components");
    // TODO: Check the 'id' against the registered property
    UHD_LOG_DEBUG("MPMD",
        "Found " << updateable_components.size()
                 << " updateable motherboard components.");
    for (const auto& comp_name : updateable_components) {
        UHD_LOG_TRACE("MPMD", "Adding motherboard component: " << comp_name);
        tree->create<uhd::usrp::component_files_t>(mb_path / "components" / comp_name)
            .set_coercer([mb](const uhd::usrp::component_files_t& comp_files) {
                return _update_component(comp_files, mb);
            })
            .set_publisher([mb, comp_name]() {
                return _get_component_info(comp_name, mb);
            }); // Done adding component to property tree
    }

    /*** MTUs ***********************************************************/
    tree->create<size_t>(mb_path / "mtu/recv")
        .add_coerced_subscriber([](const size_t) {
            throw uhd::runtime_error("Attempting to write read-only value (MTU)!");
        })
        .set_publisher([mb]() { return mb->get_mtu(uhd::RX_DIRECTION); });
    tree->create<size_t>(mb_path / "mtu/send")
        .add_coerced_subscriber([](const size_t) {
            throw uhd::runtime_error("Attempting to write read-only value (MTU)!");
        })
        .set_publisher([mb]() { return mb->get_mtu(uhd::TX_DIRECTION); });
}
Beispiel #3
0
void print_tree(const uhd::fs_path &path, uhd::property_tree::sptr tree){
    std::cout << path << std::endl;
    for(const std::string &name:  tree->list(path)){
        print_tree(path / name, tree);
    }
}