From 498454f8dcad5ca844f50f8d476539b8d9d938ec Mon Sep 17 00:00:00 2001 From: f4exb Date: Tue, 9 May 2017 02:47:45 +0200 Subject: [PATCH] LimeSDR support: built-in LimeSuite for Debian --- CMakeLists.txt | 1 + debian/rules | 2 +- devices/limesdr/CMakeLists.txt | 15 ++ liblimesuite/CMakeLists.txt | 11 +- liblimesuite/src/BuiltinConnections.cpp | 45 ++++++ liblimesuite/src/SystemResources.cpp | 205 ++++++++++++++++++++++++ liblimesuite/src/VersionInfo.cpp | 36 +++++ 7 files changed, 310 insertions(+), 5 deletions(-) create mode 100644 liblimesuite/src/BuiltinConnections.cpp create mode 100644 liblimesuite/src/SystemResources.cpp create mode 100644 liblimesuite/src/VersionInfo.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e1f288ff7..dd9474312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -561,6 +561,7 @@ if (BUILD_DEBIAN) add_subdirectory(librtlsdr) add_subdirectory(libbladerf) add_subdirectory(libmirisdr) + add_subdirectory(liblimesuite) endif (BUILD_DEBIAN) add_subdirectory(devices) diff --git a/debian/rules b/debian/rules index 921507832..ef34f1ad5 100755 --- a/debian/rules +++ b/debian/rules @@ -21,5 +21,5 @@ # dh_make generated override targets # This is example for Cmake (See https://bugs.debian.org/641051 ) override_dh_auto_configure: - dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/opt/sdrangel -DBUILD_TYPE=DEBIAN -DLIBCM256CCSRC=/z1/development/cm256cc -DLIBDSDCCSRC=/z1/development/dsdcc -DLIBAIRSPYSRC=/z1/development/libairspy -DLIBHACKRFSRC=/z1/development/hackrf/host -DLIBRTLSDRSRC=/z1/development/librtlsdr.f4exb -DLIBMBELIBSRC=/z1/development/mbelib -DLIBSERIALDVSRC=/z1/development/serialDV -DLIBBLADERFSRC=/z1/softs/bladeRF -DLIBBLADERFCOMMONSRC=/z1/softs/bladeRF/host/common -DLIBBLADERFLIBSRC=/z1/softs/bladeRF/host/libraries/libbladeRF -DLIBMIRISDRSRC=/z1/development/libmirisdr-4 + dh_auto_configure -- -DCMAKE_INSTALL_PREFIX=/opt/sdrangel -DBUILD_TYPE=DEBIAN -DLIBCM256CCSRC=/z1/development/cm256cc -DLIBDSDCCSRC=/z1/development/dsdcc -DLIBAIRSPYSRC=/z1/development/libairspy -DLIBHACKRFSRC=/z1/development/hackrf/host -DLIBRTLSDRSRC=/z1/development/librtlsdr.f4exb -DLIBMBELIBSRC=/z1/development/mbelib -DLIBSERIALDVSRC=/z1/development/serialDV -DLIBBLADERFSRC=/z1/softs/bladeRF -DLIBBLADERFCOMMONSRC=/z1/softs/bladeRF/host/common -DLIBBLADERFLIBSRC=/z1/softs/bladeRF/host/libraries/libbladeRF -DLIBMIRISDRSRC=/z1/development/libmirisdr-4 -DLIMESUITESRC=/z1/softs/LimeSuite diff --git a/devices/limesdr/CMakeLists.txt b/devices/limesdr/CMakeLists.txt index 799a66bba..ec89b9e5c 100644 --- a/devices/limesdr/CMakeLists.txt +++ b/devices/limesdr/CMakeLists.txt @@ -12,11 +12,19 @@ set(limesdrdevice_HEADERS devicelimesdrshared.h ) +if (BUILD_DEBIAN) +include_directories( + . + ${CMAKE_CURRENT_BINARY_DIR} + ${LIMESUITESRC}/src +) +else (BUILD_DEBIAN) include_directories( . ${CMAKE_CURRENT_BINARY_DIR} ${LIMESUITE_INCLUDE_DIR} ) +endif (BUILD_DEBIAN) add_definitions(${QT_DEFINITIONS}) add_definitions(-DQT_SHARED) @@ -25,9 +33,16 @@ add_library(limesdrdevice SHARED ${limesdrdevice_SOURCES} ) +if (BUILD_DEBIAN) +target_link_libraries(limesdrdevice + limesuite + sdrbase +) +else (BUILD_DEBIAN) target_link_libraries(limesdrdevice ${LIMESUITE_LIBRARY} sdrbase ) +endif (BUILD_DEBIAN) install(TARGETS limesdrdevice DESTINATION lib) diff --git a/liblimesuite/CMakeLists.txt b/liblimesuite/CMakeLists.txt index 790f290eb..9ca801b55 100644 --- a/liblimesuite/CMakeLists.txt +++ b/liblimesuite/CMakeLists.txt @@ -6,7 +6,7 @@ set(limesuite_SOURCES ${LIBLIMESUITESRC}/src/ADF4002/ADF4002.cpp ${LIBLIMESUITESRC}/src/API/lms7_api.cpp ${LIBLIMESUITESRC}/src/API/lms7_device.cpp - ${LIBLIMESUITESRC}/src/ConnectionRegistry/BuiltinConnections.in.cpp + src/BuiltinConnections.cpp ${LIBLIMESUITESRC}/src/ConnectionRegistry/ConnectionHandle.cpp ${LIBLIMESUITESRC}/src/ConnectionRegistry/ConnectionRegistry.cpp ${LIBLIMESUITESRC}/src/ConnectionRegistry/ConnectionRegistry.cpp @@ -18,7 +18,7 @@ set(limesuite_SOURCES ${LIBLIMESUITESRC}/src/Connection_uLimeSDR/Connection_uLimeSDR.cpp ${LIBLIMESUITESRC}/src/Connection_uLimeSDR/Connection_uLimeSDREntry.cpp ${LIBLIMESUITESRC}/src/Connection_uLimeSDR/Connection_uLimeSDRing.cpp - ${LIBLIMESUITESRC}/src/Connection_uLimeSDR/DRV_DriverInterface.cpp +# ${LIBLIMESUITESRC}/src/Connection_uLimeSDR/DRV_DriverInterface.cpp ${LIBLIMESUITESRC}/src/ConnectionXillybus/ConnectionXillybus.cpp ${LIBLIMESUITESRC}/src/ConnectionXillybus/ConnectionXillybusEntry.cpp ${LIBLIMESUITESRC}/src/ConnectionXillybus/ConnectionXillybusing.cpp @@ -44,8 +44,8 @@ set(limesuite_SOURCES ${LIBLIMESUITESRC}/src/Si5351C/Si5351C.cpp ${LIBLIMESUITESRC}/src/ErrorReporting.cpp ${LIBLIMESUITESRC}/src/Logger.cpp - ${LIBLIMESUITESRC}/src/SystemResources.in.cpp - ${LIBLIMESUITESRC}/src/VersionInfo.in.cpp + src/SystemResources.cpp + src/VersionInfo.cpp ) set(limesuite_HEADERS @@ -94,14 +94,17 @@ include_directories( ${LIBLIMESUITESRC}/src ${LIBLIMESUITESRC}/src/ADF4002 ${LIBLIMESUITESRC}/src/ConnectionRegistry + ${LIBLIMESUITESRC}/src/FPGA_common ${LIBLIMESUITESRC}/src/GFIR ${LIBLIMESUITESRC}/src/lms7002m ${LIBLIMESUITESRC}/src/lms7002m_mcu ${LIBLIMESUITESRC}/src/Si5351C ${LIBLIMESUITESRC}/src/protocols + ${LIBLIMESUITESRC}/external/cpp-feather-ini-parser ./include ) +set (CMAKE_CXX_STANDARD 11) add_definitions(-DQT_SHARED) add_library(limesuite SHARED diff --git a/liblimesuite/src/BuiltinConnections.cpp b/liblimesuite/src/BuiltinConnections.cpp new file mode 100644 index 000000000..592650b3e --- /dev/null +++ b/liblimesuite/src/BuiltinConnections.cpp @@ -0,0 +1,45 @@ +/*********************************************************************** + * This is a collection of all built-in connections that are included + * with the library. Additional connections can be added dynamically. + **********************************************************************/ + +/* #undef ENABLE_EVB7COM */ +#define ENABLE_STREAM +/* #undef ENABLE_STREAM_UNITE */ +/* #undef ENABLE_NOVENARF7 */ +#define ENABLE_uLimeSDR +#define ENABLE_PCIE_XILLYBUS + +void __loadConnectionEVB7COMEntry(void); +void __loadConnectionSTREAMEntry(void); +void __loadConnectionSTREAM_UNITEEntry(void); +void __loadConnectionNovenaRF7Entry(void); +void __loadConnection_uLimeSDREntry(void); +void __loadConnectionXillybusEntry(void); + +void __loadAllConnections(void) +{ + #ifdef ENABLE_EVB7COM + __loadConnectionEVB7COMEntry(); + #endif + + #ifdef ENABLE_STREAM + __loadConnectionSTREAMEntry(); + #endif + + #ifdef ENABLE_STREAM_UNITE + __loadConnectionSTREAM_UNITEEntry(); + #endif + + #ifdef ENABLE_uLimeSDR + __loadConnection_uLimeSDREntry(); + #endif + + #ifdef ENABLE_NOVENARF7 + __loadConnectionNovenaRF7Entry(); + #endif + + #ifdef ENABLE_PCIE_XILLYBUS + __loadConnectionXillybusEntry(); + #endif +} diff --git a/liblimesuite/src/SystemResources.cpp b/liblimesuite/src/SystemResources.cpp new file mode 100644 index 000000000..70d39e968 --- /dev/null +++ b/liblimesuite/src/SystemResources.cpp @@ -0,0 +1,205 @@ +/** +@file SystemResources.h +@author Lime Microsystems +@brief APIs for locating system resources. +*/ + +#include "SystemResources.h" +#include "ErrorReporting.h" + +#include //getenv, system +#include +#include +#include + +#ifdef _MSC_VER +#include +#include +#include + +//access mode constants +#define F_OK 0 +#define R_OK 2 +#define W_OK 4 +#endif + +#ifdef __unix__ +#include +#include +#endif + +#include +#include //stat + +std::string lime::getLimeSuiteRoot(void) +{ + //first check the environment variable + const char *limeSuiteRoot = std::getenv("LIME_SUITE_ROOT"); + if (limeSuiteRoot != nullptr) return limeSuiteRoot; + + // Get the path to the current dynamic linked library. + // The path to this library can be used to determine + // the installation root without prior knowledge. + #if defined(_MSC_VER) && defined(LIME_DLL) + char path[MAX_PATH]; + HMODULE hm = NULL; + if (GetModuleHandleExA( + GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | + GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, + (LPCSTR) &lime::getLimeSuiteRoot, &hm)) + { + const DWORD size = GetModuleFileNameA(hm, path, sizeof(path)); + if (size != 0) + { + const std::string libPath(path, size); + const size_t slash0Pos = libPath.find_last_of("/\\"); + const size_t slash1Pos = libPath.substr(0, slash0Pos).find_last_of("/\\"); + if (slash0Pos != std::string::npos && slash1Pos != std::string::npos) + return libPath.substr(0, slash1Pos); + } + } + #endif //_MSC_VER && LIME_DLL + + return "/opt/install/LimeSuite"; +} + +std::string lime::getHomeDirectory(void) +{ + //first check the HOME environment variable + const char *userHome = std::getenv("HOME"); + if (userHome != nullptr) return userHome; + + //use unix user id lookup to get the home directory + #ifdef __unix__ + const char *pwDir = getpwuid(getuid())->pw_dir; + if (pwDir != nullptr) return pwDir; + #endif + + return ""; +} + +/*! + * The generic location for data storage with user permission level. + */ +static std::string getBareAppDataDirectory(void) +{ + //always check APPDATA (usually windows, but can be set for linux) + const char *appDataDir = std::getenv("APPDATA"); + if (appDataDir != nullptr) return appDataDir; + + //use windows API to query for roaming app data directory + #ifdef _MSC_VER + char csidlAppDataDir[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_APPDATA, NULL, 0, csidlAppDataDir))) + { + return csidlAppDataDir; + } + #endif + + //xdg freedesktop standard location environment variable + #ifdef __unix__ + const char *xdgDataHome = std::getenv("XDG_DATA_HOME"); + if (xdgDataHome != nullptr) return xdgDataHome; + #endif + + //xdg freedesktop standard location for data in home directory + return lime::getHomeDirectory() + "/.local/share"; +} + +std::string lime::getAppDataDirectory(void) +{ + return getBareAppDataDirectory() + "/LimeSuite"; +} + +std::string lime::getConfigDirectory(void) +{ + //xdg standard is XDG_CONFIG_HOME or $HOME/.config + //but historically we have used $HOME/.limesuite + return lime::getHomeDirectory() + "/.limesuite"; +} + +std::vector lime::listImageSearchPaths(void) +{ + std::vector imageSearchPaths; + + //separator for search paths in the environment variable + #ifdef _MSC_VER + static const char sep = ';'; + #else + static const char sep = ':'; + #endif + + //check the environment's search path + const char *imagePathEnv = std::getenv("LIME_IMAGE_PATH"); + if (imagePathEnv != nullptr) + { + std::stringstream imagePaths(imagePathEnv); + std::string imagePath; + while (std::getline(imagePaths, imagePath, sep)) + { + if (imagePath.empty()) continue; + imageSearchPaths.push_back(imagePath); + } + } + + //search directories in the user's home directory + imageSearchPaths.push_back(lime::getAppDataDirectory() + "/images"); + + //search global installation directories + imageSearchPaths.push_back(lime::getLimeSuiteRoot() + "/share/LimeSuite/images"); + + return imageSearchPaths; +} + +std::string lime::locateImageResource(const std::string &name) +{ + for (const auto &searchPath : lime::listImageSearchPaths()) + { + const std::string fullPath(searchPath + "/17.03/" + name); + if (access(fullPath.c_str(), R_OK) == 0) return fullPath; + } + return ""; +} + +int lime::downloadImageResource(const std::string &name) +{ + const std::string destDir(lime::getAppDataDirectory() + "/images/17.03"); + const std::string destFile(destDir + "/" + name); + const std::string sourceUrl("http://downloads.myriadrf.org/project/limesuite/17.03/" + name); + + //check if the directory already exists + struct stat s; + if (stat(destDir.c_str(), &s) == 0) + { + if ((s.st_mode & S_IFDIR) == 0) + { + return lime::ReportError("Not a directory: %s", destDir.c_str()); + } + } + + //create images directory + else + { + #ifdef __unix__ + const std::string mkdirCmd("mkdir -p \""+destDir+"\""); + #else + const std::string mkdirCmd("md.exe \""+destDir+"\""); + #endif + int result = std::system(mkdirCmd.c_str()); + if (result != 0) return lime::ReportError(result, "Failed: %s", mkdirCmd.c_str()); + } + + //check for write access + if (access(destDir.c_str(), W_OK) != 0) lime::ReportError("Cannot write: %s", destDir.c_str()); + + //download the file + #ifdef __unix__ + const std::string dnloadCmd("wget --output-document=\""+destFile+"\" \""+sourceUrl+"\""); + #else + const std::string dnloadCmd("powershell.exe -Command \"(new-object System.Net.WebClient).DownloadFile('"+sourceUrl+"', '"+destFile+"')\""); + #endif + int result = std::system(dnloadCmd.c_str()); + if (result != 0) return lime::ReportError(result, "Failed: %s", dnloadCmd.c_str()); + + return 0; +} diff --git a/liblimesuite/src/VersionInfo.cpp b/liblimesuite/src/VersionInfo.cpp new file mode 100644 index 000000000..c29de1d90 --- /dev/null +++ b/liblimesuite/src/VersionInfo.cpp @@ -0,0 +1,36 @@ +/** +@file VersionInfo.cpp +@author Lime Microsystems +@brief API for querying version and build information. +*/ + +#include "VersionInfo.h" +#include + +#define QUOTE_(x) #x +#define QUOTE(x) QUOTE_(x) + +std::string lime::GetLibraryVersion(void) +{ + return "17.03.0-gaa726d64"; +} + +std::string lime::GetBuildTimestamp(void) +{ + return "2017-04-17"; +} + +std::string lime::GetAPIVersion(void) +{ + const std::string verStr(QUOTE(LIME_SUITE_API_VERSION)); + std::stringstream ss; + ss << std::stoi(verStr.substr(2, 4)) << "." + << std::stoi(verStr.substr(6, 2)) << "." + << std::stoi(verStr.substr(8, 2)); + return ss.str(); +} + +std::string lime::GetABIVersion(void) +{ + return "17.03-1"; +}