diff options
author | Ben Hilburn <ben.hilburn@ettus.com> | 2015-01-27 16:07:43 -0800 |
---|---|---|
committer | Ben Hilburn <ben.hilburn@ettus.com> | 2015-01-27 16:07:43 -0800 |
commit | 75d519706b9b0956307a6a4bdc53c36376f19f03 (patch) | |
tree | b2d2144c31c3ea04167ef7e3d1b14f7477c158cf /host/lib/transport/nirio | |
parent | 8d0d0d01c0a2a5ed1a01da4360226a64ab8117bc (diff) | |
download | uhd-75d519706b9b0956307a6a4bdc53c36376f19f03.tar.gz uhd-75d519706b9b0956307a6a4bdc53c36376f19f03.tar.bz2 uhd-75d519706b9b0956307a6a4bdc53c36376f19f03.zip |
Merging new UHD_IMAGES_DIR utilities and bug fixes.
Also includes NI-USRP Windows Registry Key fixes.
Diffstat (limited to 'host/lib/transport/nirio')
-rw-r--r-- | host/lib/transport/nirio/lvbitx/CMakeLists.txt | 7 | ||||
-rw-r--r-- | host/lib/transport/nirio/lvbitx/template_lvbitx.cpp | 6 | ||||
-rw-r--r-- | host/lib/transport/nirio/nifpga_lvbitx.cpp | 103 |
3 files changed, 5 insertions, 111 deletions
diff --git a/host/lib/transport/nirio/lvbitx/CMakeLists.txt b/host/lib/transport/nirio/lvbitx/CMakeLists.txt index 35cfaa456..b9a2a9f15 100644 --- a/host/lib/transport/nirio/lvbitx/CMakeLists.txt +++ b/host/lib/transport/nirio/lvbitx/CMakeLists.txt @@ -27,7 +27,7 @@ MACRO(LIBUHD_LVBITX_GEN_SOURCE_AND_BITSTREAM lvbitx binfile) ENDIF( ${binfile} STREQUAL "OFF" ) SET(OUTPUT_PATH_OPT --output-src-path=${CMAKE_CURRENT_BINARY_DIR}) - SET(IMAGES_PATH_OPT --uhd-images-path=${FPGA_IMAGES_DIR}) + SET(IMAGES_PATH_OPT --uhd-images-path=${UHD_IMAGES_DIR}) ADD_CUSTOM_COMMAND( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${lvbitxprefix}_lvbitx.hpp @@ -53,11 +53,6 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}) MESSAGE(STATUS "") MESSAGE(STATUS "Processing NI-RIO FPGA LVBITX Bitstreams...") -FILE(TO_NATIVE_PATH ${CMAKE_INSTALL_PREFIX}/share/uhd/images default_images_dir) -SET( FPGA_IMAGES_DIR ${default_images_dir} CACHE STRING "Path to installed FPGA image files." ) -OPTION( FPGA_IMAGES_DIR "Path to installed FPGA image files." "" ) -MESSAGE( STATUS " LVBITX install directory: ${FPGA_IMAGES_DIR}" ) - # X300 Stuff LIBUHD_LVBITX_GEN_SOURCE_AND_BITSTREAM(x300.lvbitx_base OFF) diff --git a/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp b/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp index a1899c771..8f1fb6b36 100644 --- a/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp +++ b/host/lib/transport/nirio/lvbitx/template_lvbitx.cpp @@ -8,6 +8,7 @@ #include <boost/filesystem/path.hpp> #include <boost/algorithm/string.hpp> #include <boost/regex.hpp> +#include <uhd/utils/paths.hpp> namespace uhd {{ namespace niusrprio {{ @@ -27,8 +28,9 @@ const char* {lvbitx_classname}_lvbitx::INPUT_FIFOS[] = {{{in_fifo_list} {lvbitx_classname}_lvbitx::{lvbitx_classname}_lvbitx(const std::string& option) {{ - boost::filesystem::path fpga_path(_get_fpga_images_dir(SEARCH_PATHS)); - fpga_path /= "usrp_{lvbitx_classname}_fpga_" + option + ".lvbitx"; + std::string fpga_file = "usrp_{lvbitx_classname}_fpga_" + option + ".lvbitx"; + boost::filesystem::path fpga_path(uhd::find_image_path(fpga_file, SEARCH_PATHS)); + _fpga_file_name = fpga_path.string(); _bitstream_checksum = _get_bitstream_checksum(_fpga_file_name); }} diff --git a/host/lib/transport/nirio/nifpga_lvbitx.cpp b/host/lib/transport/nirio/nifpga_lvbitx.cpp index b87d87a8d..8135a4d01 100644 --- a/host/lib/transport/nirio/nifpga_lvbitx.cpp +++ b/host/lib/transport/nirio/nifpga_lvbitx.cpp @@ -18,12 +18,8 @@ #include <uhd/transport/nirio/nifpga_lvbitx.h> #include <cstdlib> #include <string> -#include <iostream> #include <fstream> #include <streambuf> -#include <boost/foreach.hpp> -#include <boost/format.hpp> -#include <boost/filesystem.hpp> #include <boost/algorithm/string.hpp> #include <boost/regex.hpp> @@ -52,103 +48,4 @@ std::string nifpga_lvbitx::_get_bitstream_checksum(const std::string& file_path) return checksum; } -#ifdef UHD_PLATFORM_WIN32 -#include <windows.h> - -std::string _get_path_from_registry(const std::string& registry_key_path) -{ - boost::smatch reg_key_match; - //If a substring in the search path is enclosed in [] (square brackets) then it is interpreted as a registry path - if (not boost::regex_search(registry_key_path, reg_key_match, boost::regex("\\[(.+)\\](.*)", boost::regex::icase))) - return std::string(); - std::string reg_key_path = std::string(reg_key_match[1].first, reg_key_match[1].second); - std::string path_suffix = std::string(reg_key_match[2].first, reg_key_match[2].second); - - //Split the registry path into parent, key-path and value. - boost::smatch reg_parent_match; - if (not boost::regex_search(reg_key_path, reg_parent_match, boost::regex("^(.+?)\\\\(.+)\\\\(.+)$", boost::regex::icase))) - return std::string(); - std::string reg_parent = std::string(reg_parent_match[1].first, reg_parent_match[1].second); - std::string reg_path = std::string(reg_parent_match[2].first, reg_parent_match[2].second); - std::string reg_val_name = std::string(reg_parent_match[3].first, reg_parent_match[3].second); - - HKEY hkey_parent = HKEY_LOCAL_MACHINE; - if (reg_parent == "HKEY_LOCAL_MACHINE") hkey_parent = HKEY_LOCAL_MACHINE; - else if (reg_parent == "HKEY_CURRENT_USER") hkey_parent = HKEY_CURRENT_USER; - else if (reg_parent == "HKEY_CLASSES_ROOT") hkey_parent = HKEY_CLASSES_ROOT; - else if (reg_parent == "HKEY_CURRENT_CONFIG") hkey_parent = HKEY_CURRENT_CONFIG; - else if (reg_parent == "HKEY_USERS") hkey_parent = HKEY_CURRENT_USER; - - TCHAR value_buff[1024]; - DWORD value_buff_size = 1024*sizeof(TCHAR); - - //Get a handle to the key location - HKEY hkey_location; - if (RegOpenKeyExA(hkey_parent, reg_path.c_str(), NULL, KEY_QUERY_VALUE, &hkey_location) != ERROR_SUCCESS) - return std::string(); - - //Query key value - DWORD dw_type = REG_SZ; - if(RegQueryValueExA(hkey_location, reg_val_name.c_str(), NULL, &dw_type, (LPBYTE)value_buff, &value_buff_size) == ERROR_SUCCESS) { - RegCloseKey(hkey_location); - if (value_buff_size >= 1024*sizeof(TCHAR)) { - return std::string(); - } else { - std::string return_value(value_buff, value_buff_size-1); //value_buff_size includes the null terminator - return_value += path_suffix; - return return_value; - } - } else { - return std::string(); - } -} - -#endif /*UHD_PLATFORM_WIN32*/ - -std::string nifpga_lvbitx::_get_fpga_images_dir(const std::string search_paths) -{ - std::vector<std::string> search_path_vtr; - boost::split(search_path_vtr, search_paths, boost::is_any_of(",")); - - // - // Add the value of the UHD_IMAGES_DIR environment variable to the list of - // directories searched for a LVBITX image. - // - char* uhd_images_dir; -#ifdef UHD_PLATFORM_WIN32 - size_t len; - errno_t err = _dupenv_s(&uhd_images_dir, &len, "UHD_IMAGES_DIR"); - if(not err and uhd_images_dir != NULL) search_path_vtr.push_back(std::string(uhd_images_dir)); - free(uhd_images_dir); -#else - uhd_images_dir = getenv("UHD_IMAGES_DIR"); - if(uhd_images_dir != NULL) search_path_vtr.push_back(std::string(uhd_images_dir)); -#endif - - std::string lvbitx_dir; - //Traverse through the list of search paths. Priority: lexical - BOOST_FOREACH(std::string& search_path, search_path_vtr) { - boost::algorithm::trim(search_path); - if (search_path.empty()) continue; - -#ifdef UHD_PLATFORM_WIN32 - lvbitx_dir = _get_path_from_registry(search_path); - if (lvbitx_dir.empty()) { - //Could not read from the registry due to missing key, invalid values, etc - //Just use the search path. The is_directory check will fail if this is a - //registry path and we will move on to the next item in the list. - lvbitx_dir = search_path; - } -#else - lvbitx_dir = search_path; -#endif - - //If the current directory exists then stop traversing the search path list. - if (boost::filesystem::is_directory(lvbitx_dir)) break; - } - - return lvbitx_dir; -} - - }} |