pax_global_header00006660000000000000000000000064145644373760014535gustar00rootroot0000000000000052 comment=422a9b306f765499dd3e9a4c3400fa39816dcfdb SoapyPlutoSDR-soapy-plutosdr-0.2.2/000077500000000000000000000000001456443737600172315ustar00rootroot00000000000000SoapyPlutoSDR-soapy-plutosdr-0.2.2/CMakeLists.txt000066400000000000000000000070251456443737600217750ustar00rootroot00000000000000######################################################################## # Project setup ######################################################################## cmake_minimum_required(VERSION 2.8.9) project(SoapyPlutoSDR CXX) # select build type to get optimization flags if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE "Release") message(STATUS "Build type not specified: defaulting to release.") endif(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") find_package(SoapySDR NO_MODULE) if (NOT SoapySDR_FOUND) message(FATAL_ERROR "Soapy SDR development files not found...") endif () ######################################################################## # Find libiio ######################################################################## list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}) find_package(LibIIO 0.9 REQUIRED) if (LibIIO_FOUND) message(STATUS "LibIIO_INCLUDE_DIRS: ${LibIIO_INCLUDE_DIRS}") message(STATUS "LibIIO_LIBRARIES: ${LibIIO_LIBRARIES}") message(STATUS "LibIIO_DEFINITIONS: ${LibIIO_DEFINITIONS}") endif() include_directories(${LibIIO_INCLUDE_DIRS}) #enable c++11 features if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang") #C++11 is a required language feature for this project include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_STD_CXX11) if(HAS_STD_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") else(HAS_STD_CXX11) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wc++11-extensions") endif() #Thread support enabled (not the same as -lpthread) list(APPEND LibIIO_LIBRARIES -pthread) #disable warnings for unused parameters add_compile_options(-Wall -Wextra -pedantic -Wno-unused-parameter) endif() ######################################################################## # Find libad9361 ######################################################################## find_package(LibAD9361) if (LibAD9361_FOUND) message(STATUS "LibAD9361_INCLUDE_DIRS: ${LibAD9361_INCLUDE_DIRS}") message(STATUS "LibAD9361_LIBRARIES: ${LibAD9361_LIBRARIES}") message(STATUS "LibAD9361_DEFINITIONS: ${LibAD9361_DEFINITIONS}") include_directories(${LibAD9361_INCLUDE_DIRS}) add_definitions(-DHAS_AD9361_IIO) endif() ######################################################################## # Find libusb ######################################################################## find_package(LibUSB) if(LibUSB_FOUND) message(STATUS "LibUSB_INCLUDE_DIRS: ${LibUSB_INCLUDE_DIRS}") message(STATUS "LibUSB_LIBRARIES: ${LibUSB_LIBRARIES}") message(STATUS "LibUSB_DEFINITIONS: ${LibUSB_DEFINITIONS}") include_directories(${LibUSB_INCLUDE_DIRS}) add_definitions(-DHAS_LIBUSB1) #disable warnings for libusb.h add_compile_options($<$:-Wno-zero-length-array>) endif() SOAPY_SDR_MODULE_UTIL( TARGET PlutoSDRSupport SOURCES PlutoSDR_Registration.cpp PlutoSDR_Settings.cpp PlutoSDR_Streaming.cpp LIBRARIES ${LibIIO_LIBRARIES} ${LibAD9361_LIBRARIES} ${LibUSB_LIBRARIES} ) ######################################################################## # uninstall target ######################################################################## add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) SoapyPlutoSDR-soapy-plutosdr-0.2.2/Changelog.txt000066400000000000000000000021561456443737600216650ustar00rootroot00000000000000Release 0.2.2 (2024-02-18) ========================== - Fix src increment for rx_streamer recv on non direct-copy - Add uri key to match devices, ensure that libiio context is a PlutoSDR - Add libusb check for known ADALM-Pluto VID:PID - Set label when PlutoSDR is USB-connected - Disable automatic gain by default - Add CS8 TX direct copy, fix CS12 TX direct copy - Fix for backend scan errors - Fix undefined default warnings - Add getSampleRateRange() API Release 0.2.1 (2021-01-23) ========================== - Various fixes to cmake find package modules - Fix sample rates between 25e6/48 and 25e6/12 - Fix hasDCOffsetMode to return false - Fix crash on non-PlutoSDR IIO context - Fix powerdown state in setupStream/closeStream - Fix TX getStreamMTU Release 0.2.0 (2019-06-22) ========================== - Added support for sensors: temperature and power - Stream improvements: mtu changes, added CS12 support - Fix pthread link for SoapySDR upstream cmake changes - Fixed typo in spelling of PlutoSDR support module Release 0.1.0 (2018-12-21) ========================== - Initial release of Soapy PlutoSDR support module SoapyPlutoSDR-soapy-plutosdr-0.2.2/FindLibAD9361.cmake000066400000000000000000000025271456443737600223000ustar00rootroot00000000000000# - Try to find libad9361-iio # Once done this will define # # LibAD9361_FOUND - system has libad9361 # LibAD9361_INCLUDE_DIRS - the libad9361 include directory # LibAD9361_LIBRARIES - Link these to use libad9361 # LibAD9361_DEFINITIONS - Compiler switches required for using libad9361 # LibAD9361_VERSION - the libad9361 version # # Redistribution and use is allowed according to the terms of the New BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # find_package(PkgConfig) pkg_check_modules(PC_LibAD9361 QUIET libad9361) set(LibAD9361_DEFINITIONS ${PC_LibAD9361_CFLAGS_OTHER}) find_path(LibAD9361_INCLUDE_DIR ad9361.h HINTS ${PC_LibAD9361_INCLUDEDIR} ${PC_LibAD9361_INCLUDE_DIRS} PATH_SUFFIXES libad9361-iio) find_library(LibAD9361_LIBRARY NAMES ad9361 libad9361 HINTS ${PC_LibAD9361_LIBDIR} ${PC_LibAD9361_LIBRARY_DIRS}) set(LibAD9361_VERSION ${PC_LibAD9361_VERSION}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibAD9361 REQUIRED_VARS LibAD9361_LIBRARY LibAD9361_INCLUDE_DIR VERSION_VAR LibAD9361_VERSION) mark_as_advanced(LibAD9361_INCLUDE_DIR LibAD9361_LIBRARY) if (LibAD9361_FOUND) set(LibAD9361_LIBRARIES ${LibAD9361_LIBRARY}) set(LibAD9361_INCLUDE_DIRS ${LibAD9361_INCLUDE_DIR}) endif() SoapyPlutoSDR-soapy-plutosdr-0.2.2/FindLibIIO.cmake000066400000000000000000000023031456443737600221010ustar00rootroot00000000000000# - Try to find libiio # Once done this will define # # LibIIO_FOUND - system has libiio # LibIIO_INCLUDE_DIRS - the libiio include directory # LibIIO_LIBRARIES - Link these to use libiio # LibIIO_DEFINITIONS - Compiler switches required for using libiio # LibIIO_VERSION - the libiio version # # Redistribution and use is allowed according to the terms of the New BSD license. # For details see the accompanying COPYING-CMAKE-SCRIPTS file. # find_package(PkgConfig) pkg_check_modules(PC_LibIIO QUIET libiio) set(LibIIO_DEFINITIONS ${PC_LibIIO_CFLAGS_OTHER}) find_path(LibIIO_INCLUDE_DIR iio.h HINTS ${PC_LibIIO_INCLUDEDIR} ${PC_LibIIO_INCLUDE_DIRS} PATH_SUFFIXES libiio) find_library(LibIIO_LIBRARY NAMES iio libiio HINTS ${PC_LibIIO_LIBDIR} ${PC_LibIIO_LIBRARY_DIRS}) set(LibIIO_VERSION ${PC_LibIIO_VERSION}) include(FindPackageHandleStandardArgs) find_package_handle_standard_args(LibIIO REQUIRED_VARS LibIIO_LIBRARY LibIIO_INCLUDE_DIR VERSION_VAR LibIIO_VERSION) mark_as_advanced(LibIIO_INCLUDE_DIR LibIIO_LIBRARY) set(LibIIO_LIBRARIES ${LibIIO_LIBRARY}) set(LibIIO_INCLUDE_DIRS ${LibIIO_INCLUDE_DIR}) SoapyPlutoSDR-soapy-plutosdr-0.2.2/FindLibUSB.cmake000066400000000000000000000033431456443737600221170ustar00rootroot00000000000000# - Try to find LibUSB-1.0 # Once done this will define # # LibUSB_FOUND - System has libusb # LibUSB_INCLUDE_DIRS - The libusb include directories # LibUSB_LIBRARIES - The libraries needed to use libusb # LibUSB_DEFINITIONS - Compiler switches required for using libusb # LibUSB_VERSION - the libusb version # find_package(PkgConfig) pkg_check_modules(PC_LibUSB QUIET libusb-1.0) set(LibUSB_DEFINITIONS ${PC_LibUSB_CFLAGS_OTHER}) find_path(LibUSB_INCLUDE_DIR NAMES libusb.h HINTS ${PC_LibUSB_INCLUDE_DIRS} PATH_SUFFIXES libusb-1.0 PATHS /usr/include /usr/local/include ) #standard library name for libusb-1.0 set(libusb1_library_names usb-1.0) #libusb-1.0 compatible library on freebsd if((CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") OR (CMAKE_SYSTEM_NAME STREQUAL "kFreeBSD")) list(APPEND libusb1_library_names usb) endif() #libusb-1.0 name on Windows (from PothosSDR distribution) if(CMAKE_SYSTEM_NAME STREQUAL "Windows") list(APPEND libusb1_library_names libusb-1.0) endif() find_library(LibUSB_LIBRARY NAMES ${libusb1_library_names} HINTS ${PC_LibUSB_LIBRARY_DIRS} PATHS /usr/lib /usr/local/lib ) set(LibUSB_VERSION ${PC_LibUSB_VERSION}) include(FindPackageHandleStandardArgs) # handle the QUIETLY and REQUIRED arguments and set LibUSB_FOUND to TRUE # if all listed variables are TRUE find_package_handle_standard_args(LibUSB REQUIRED_VARS LibUSB_LIBRARY LibUSB_INCLUDE_DIR VERSION_VAR LibUSB_VERSION) mark_as_advanced(LibUSB_LIBRARY LibUSB_INCLUDE_DIR LibUSB_VERSION) set(LibUSB_LIBRARIES ${LibUSB_LIBRARY} ) set(LibUSB_INCLUDE_DIRS ${LibUSB_INCLUDE_DIR} ) SoapyPlutoSDR-soapy-plutosdr-0.2.2/LICENSE000066400000000000000000000635351456443737600202520ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. (This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.) Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} Copyright (C) {year} {fullname} This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. {signature of Ty Coon}, 1 April 1990 Ty Coon, President of Vice That's all there is to it! SoapyPlutoSDR-soapy-plutosdr-0.2.2/PlutoSDR_Registration.cpp000066400000000000000000000117301456443737600241450ustar00rootroot00000000000000#include "SoapyPlutoSDR.hpp" #include #include #include #include #ifdef HAS_LIBUSB1 #include #endif static std::vector results; static std::vector find_PlutoSDR(const SoapySDR::Kwargs &args) { if (!results.empty()) return results; ssize_t ret = 0; iio_context *ctx = nullptr; iio_scan_context *scan_ctx; iio_context_info **info; SoapySDR::Kwargs options; // Backends can error, scan each one individually // The filtered "usb" backend is available starting from Libiio 0.24 std::vector backends = {"local", "usb=0456:b673", "ip"}; for (std::vector::iterator it = backends.begin(); it != backends.end(); it++) { if (*it == "usb=0456:b673") { #ifdef HAS_LIBUSB1 // Abort early if no known ADALM-Pluto USB VID:PID (0456:b673) is found, // that way we won't block USB access for other drivers' enumeration on Libiio before 0.24. libusb_context *usb_ctx = nullptr; int r = libusb_init(&usb_ctx); if (r < 0) { SoapySDR_logf(SOAPY_SDR_WARNING, "libusb init error (%d)\n", r); } else { // This is what libusb_open_device_with_vid_pid(usb_ctx, 0x0456, 0xb673) does, // but without actually opening a device. struct libusb_device **devs; // this is cached in libusb, we won't block USB access for other drivers r = libusb_get_device_list(usb_ctx, &devs); if (r < 0) { SoapySDR_logf(SOAPY_SDR_WARNING, "libusb get device list error (%d)\n", r); continue; // iio scan context will most likely fail too? } bool found = false; struct libusb_device *dev; size_t i = 0; while ((dev = devs[i++]) != NULL) { struct libusb_device_descriptor desc; // this is cached in libusb, we won't block USB access for other drivers r = libusb_get_device_descriptor(dev, &desc); if (r < 0) { break; } if (desc.idVendor == 0x0456 && desc.idProduct == 0xb673) { found = true; break; } } libusb_free_device_list(devs, 1); if (found) { SoapySDR_logf(SOAPY_SDR_DEBUG, "ADALM-Pluto VID:PID found"); } else { SoapySDR_logf(SOAPY_SDR_DEBUG, "No ADALM-Pluto VID:PID found"); continue; } } #endif // Defer to other drivers, prevent a race condition on USB enumeration with Libiio before 0.24, // the value of 500ms has not been confirmed and might be 50ms to 1s possibly. std::this_thread::sleep_for(std::chrono::milliseconds(500)); } scan_ctx = iio_create_scan_context(it->c_str(), 0); if (scan_ctx == nullptr) { SoapySDR_logf(SOAPY_SDR_WARNING, "Unable to setup %s scan\n", it->c_str()); continue; } info = nullptr; ret = iio_scan_context_get_info_list(scan_ctx, &info); if (ret < 0) { SoapySDR_logf(SOAPY_SDR_WARNING, "Unable to scan %s: %li\n", it->c_str(), (long)ret); iio_context_info_list_free(info); iio_scan_context_destroy(scan_ctx); continue; } options["device"] = "PlutoSDR"; if (ret == 0) { iio_context_info_list_free(info); iio_scan_context_destroy(scan_ctx); //no devices discovered, the user must specify a hostname if (args.count("hostname") == 0) continue; //try to connect at the specified hostname ctx = iio_create_network_context(args.at("hostname").c_str()); if (ctx == nullptr) continue; //failed to connect options["hostname"] = args.at("hostname"); std::ostringstream label_str; label_str << options["device"] << " #0 " << options["hostname"]; options["label"] = label_str.str(); results.push_back(options); if (ctx != nullptr) iio_context_destroy(ctx); } else { for (int i = 0; i < ret; i++) { ctx = iio_create_context_from_uri(iio_context_info_get_uri(info[i])); if (ctx != nullptr) { options["uri"] = std::string(iio_context_info_get_uri(info[i])); // check if discovered libiio context can be a PlutoSDR (and not some other sensor), // it must contain "ad9361-phy", "cf-ad9361-lpc" and "cf-ad9361-dds-core-lpc" devices iio_device *dev = iio_context_find_device(ctx, "ad9361-phy"); iio_device *rx_dev = iio_context_find_device(ctx, "cf-ad9361-lpc"); iio_device *tx_dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); if (dev != nullptr && rx_dev != nullptr && tx_dev != nullptr) { // if uri is specified in kwargs, discovered uri must match if (args.count("uri") == 0 || options["uri"] == args.at("uri")) { std::ostringstream label_str; label_str << options["device"] << " #" << i << " " << options["uri"]; options["label"] = label_str.str(); results.push_back(options); } } if (ctx != nullptr) iio_context_destroy(ctx); } } iio_context_info_list_free(info); iio_scan_context_destroy(scan_ctx); } } return results; } static SoapySDR::Device *make_PlutoSDR(const SoapySDR::Kwargs &args) { return new SoapyPlutoSDR(args); } static SoapySDR::Registry register_plutosdr("plutosdr", &find_PlutoSDR, &make_PlutoSDR, SOAPY_SDR_ABI_VERSION); SoapyPlutoSDR-soapy-plutosdr-0.2.2/PlutoSDR_Settings.cpp000066400000000000000000000470201456443737600232740ustar00rootroot00000000000000#include "SoapyPlutoSDR.hpp" #ifdef HAS_AD9361_IIO #include #endif static iio_context *ctx = nullptr; SoapyPlutoSDR::SoapyPlutoSDR( const SoapySDR::Kwargs &args ): dev(nullptr), rx_dev(nullptr),tx_dev(nullptr), decimation(false), interpolation(false), rx_stream(nullptr) { gainMode = false; if (args.count("label") != 0) SoapySDR_logf( SOAPY_SDR_INFO, "Opening %s...", args.at("label").c_str()); if(ctx == nullptr) { if(args.count("uri") != 0) { ctx = iio_create_context_from_uri(args.at("uri").c_str()); }else if(args.count("hostname")!=0){ ctx = iio_create_network_context(args.at("hostname").c_str()); }else{ ctx = iio_create_default_context(); } } if (ctx == nullptr) { SoapySDR_logf(SOAPY_SDR_ERROR, "no device context found."); throw std::runtime_error("no device context found"); } dev = iio_context_find_device(ctx, "ad9361-phy"); rx_dev = iio_context_find_device(ctx, "cf-ad9361-lpc"); tx_dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); if (dev == nullptr || rx_dev == nullptr || tx_dev == nullptr) { SoapySDR_logf(SOAPY_SDR_ERROR, "no device found in this context."); throw std::runtime_error("no device found in this context"); } this->setAntenna(SOAPY_SDR_RX, 0, "A_BALANCED"); this->setGainMode(SOAPY_SDR_RX, 0, false); this->setAntenna(SOAPY_SDR_TX, 0, "A"); } SoapyPlutoSDR::~SoapyPlutoSDR(void){ long long samplerate=0; if(decimation){ iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", false),"sampling_frequency",&samplerate); iio_channel_attr_write_longlong(iio_device_find_channel(rx_dev, "voltage0", false),"sampling_frequency", samplerate); } if(interpolation){ iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", true),"sampling_frequency",&samplerate); iio_channel_attr_write_longlong(iio_device_find_channel(tx_dev, "voltage0", true),"sampling_frequency", samplerate); } if(ctx) { iio_context_destroy(ctx); ctx = nullptr; } } /******************************************************************* * Identification API ******************************************************************/ std::string SoapyPlutoSDR::getDriverKey( void ) const { return "PlutoSDR"; } std::string SoapyPlutoSDR::getHardwareKey( void ) const { return "ADALM-PLUTO"; } SoapySDR::Kwargs SoapyPlutoSDR::getHardwareInfo( void ) const { SoapySDR::Kwargs info; unsigned int major, minor; char git_tag[8]; iio_library_get_version(&major, &minor, git_tag); char lib_ver[100]; snprintf(lib_ver, 100, "%u.%u (git tag: %s)", major, minor, git_tag); info["library_version"] = lib_ver; iio_context_get_version(ctx, &major, &minor, git_tag); char backend_ver[100]; snprintf(backend_ver, 100, "%u.%u (git tag: %s)", major, minor, git_tag); info["backend_version"] = backend_ver; unsigned int nb_ctx_attrs = iio_context_get_attrs_count(ctx); for (unsigned int i = 0; i < nb_ctx_attrs; i++) { const char *key, *value; iio_context_get_attr(ctx, i, &key, &value); info[key] = value; } return info; } /******************************************************************* * Channels API ******************************************************************/ size_t SoapyPlutoSDR::getNumChannels( const int dir ) const { return(1); } bool SoapyPlutoSDR::getFullDuplex( const int direction, const size_t channel ) const { return(true); } /******************************************************************* * Sensor API ******************************************************************/ bool SoapyPlutoSDR::is_sensor_channel(struct iio_channel *chn) const { return (!iio_channel_is_output(chn) && (iio_channel_find_attr(chn, "raw") || iio_channel_find_attr(chn, "input"))); } double SoapyPlutoSDR::double_from_buf(const char *buf) const { std::istringstream val_as_string(buf); val_as_string.imbue(std::locale::classic()); // ignore global C++ locale double val = 0.0; val_as_string >> val; return val; } double SoapyPlutoSDR::get_sensor_value(struct iio_channel *chn) const { char buf[32]; double val = 0.0; if (iio_channel_find_attr(chn, "input")) { if (iio_channel_attr_read(chn, "input", buf, sizeof(buf)) > 0) { val = double_from_buf(buf); } } else { if (iio_channel_attr_read(chn, "raw", buf, sizeof(buf)) > 0) { val = double_from_buf(buf); } if (iio_channel_find_attr(chn, "offset")) { if (iio_channel_attr_read(chn, "offset", buf, sizeof(buf)) > 0) { val += double_from_buf(buf); } } if (iio_channel_find_attr(chn, "scale")) { if (iio_channel_attr_read(chn, "scale", buf, sizeof(buf)) > 0) { val *= double_from_buf(buf); } } } return val / 1000.0; } std::string SoapyPlutoSDR::id_to_unit(const std::string& id) const { static std::map id_to_unit_table = { { "current", "A" }, { "power", "W" }, { "temp", "C" }, { "voltage", "V" }, }; for (auto it_match : id_to_unit_table) { //if the id starts with a known prefix, retreive its unit. if (id.substr(0, it_match.first.size()) == it_match.first) { return it_match.second; } } return std::string(); } std::vector SoapyPlutoSDR::listSensors(void) const { /* iio:device2: xadc 10 channels found: temp0: (input) voltage0: vccint (input) voltage1: vccaux (input) voltage2: vccbram (input) voltage3: vccpint (input) voltage4: vccpaux (input) voltage5: vccoddr (input) voltage6: vrefp (input) voltage7: vrefn (input) voltage8: (input) iio:device0: adm1177 2 channels found: current0: (input) voltage0: (input) iio:device1: ad9361-phy 9 channels found: temp0: (input) voltage2: (input) */ std::vector sensors; sensors.push_back("xadc_temp0"); sensors.push_back("xadc_voltage0"); sensors.push_back("xadc_voltage1"); sensors.push_back("xadc_voltage2"); sensors.push_back("xadc_voltage3"); sensors.push_back("xadc_voltage4"); sensors.push_back("xadc_voltage5"); sensors.push_back("xadc_voltage6"); sensors.push_back("xadc_voltage7"); sensors.push_back("xadc_voltage8"); sensors.push_back("adm1177_current0"); sensors.push_back("adm1177_voltage0"); sensors.push_back("ad9361-phy_temp0"); sensors.push_back("ad9361-phy_voltage2"); return sensors; } SoapySDR::ArgInfo SoapyPlutoSDR::getSensorInfo(const std::string &key) const { SoapySDR::ArgInfo info; std::size_t dash = key.find("_"); if (dash < std::string::npos) { std::string deviceStr = key.substr(0, dash); std::string channelStr = key.substr(dash + 1); iio_device *dev = iio_context_find_device(ctx, deviceStr.c_str()); if (!dev) return info; iio_channel *chn = iio_device_find_channel(dev, channelStr.c_str(), false); if (!chn) return info; const char *name = iio_channel_get_name(chn); info.key = key; if (name) info.name = name; info.type = SoapySDR::ArgInfo::FLOAT; info.value = "0.0"; info.units = id_to_unit(channelStr); } return info; } std::string SoapyPlutoSDR::readSensor(const std::string &key) const { std::string sensorValue; std::size_t dash = key.find("_"); if (dash < std::string::npos) { std::string deviceStr = key.substr(0, dash); std::string channelStr = key.substr(dash + 1); iio_device *dev = iio_context_find_device(ctx, deviceStr.c_str()); if (!dev) return sensorValue; iio_channel *chn = iio_device_find_channel(dev, channelStr.c_str(), false); if (!chn) return sensorValue; double value = get_sensor_value(chn); sensorValue.assign(std::to_string(value)); } return sensorValue; } /******************************************************************* * Settings API ******************************************************************/ SoapySDR::ArgInfoList SoapyPlutoSDR::getSettingInfo(void) const { SoapySDR::ArgInfoList setArgs; return setArgs; } void SoapyPlutoSDR::writeSetting(const std::string &key, const std::string &value) { } std::string SoapyPlutoSDR::readSetting(const std::string &key) const { std::string info; return info; } /******************************************************************* * Antenna API ******************************************************************/ std::vector SoapyPlutoSDR::listAntennas( const int direction, const size_t channel ) const { std::vector options; if(direction == SOAPY_SDR_RX) options.push_back( "A_BALANCED" ); if(direction == SOAPY_SDR_TX) options.push_back( "A" ); return(options); } void SoapyPlutoSDR::setAntenna( const int direction, const size_t channel, const std::string &name ) { if (direction == SOAPY_SDR_RX) { std::lock_guard lock(rx_device_mutex); iio_channel_attr_write(iio_device_find_channel(dev, "voltage0", false), "rf_port_select", name.c_str()); } else if (direction == SOAPY_SDR_TX) { std::lock_guard lock(tx_device_mutex); iio_channel_attr_write(iio_device_find_channel(dev, "voltage0", true), "rf_port_select", name.c_str()); } } std::string SoapyPlutoSDR::getAntenna( const int direction, const size_t channel ) const { std::string options; if (direction == SOAPY_SDR_RX) { options = "A_BALANCED"; } else if (direction == SOAPY_SDR_TX) { options = "A"; } return options; } /******************************************************************* * Frontend corrections API ******************************************************************/ bool SoapyPlutoSDR::hasDCOffsetMode( const int direction, const size_t channel ) const { return(false); } /******************************************************************* * Gain API ******************************************************************/ std::vector SoapyPlutoSDR::listGains( const int direction, const size_t channel ) const { std::vector options; options.push_back("PGA"); return(options); } bool SoapyPlutoSDR::hasGainMode(const int direction, const size_t channel) const { if (direction == SOAPY_SDR_RX) return true; return false; } void SoapyPlutoSDR::setGainMode( const int direction, const size_t channel, const bool automatic ) { gainMode = automatic; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); if (gainMode) { iio_channel_attr_write(iio_device_find_channel(dev, "voltage0", false), "gain_control_mode", "slow_attack"); }else{ iio_channel_attr_write(iio_device_find_channel(dev, "voltage0", false), "gain_control_mode", "manual"); } } } bool SoapyPlutoSDR::getGainMode(const int direction, const size_t channel) const { return gainMode; } void SoapyPlutoSDR::setGain( const int direction, const size_t channel, const double value ) { long long gain = (long long) value; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); iio_channel_attr_write_longlong(iio_device_find_channel(dev, "voltage0", false),"hardwaregain", gain); } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); gain = gain - 89; iio_channel_attr_write_longlong(iio_device_find_channel(dev, "voltage0", true),"hardwaregain", gain); } } void SoapyPlutoSDR::setGain( const int direction, const size_t channel, const std::string &name, const double value ) { this->setGain(direction,channel,value); } double SoapyPlutoSDR::getGain( const int direction, const size_t channel, const std::string &name ) const { long long gain = 0; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", false),"hardwaregain",&gain )!=0) return 0; } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", true),"hardwaregain",&gain )!=0) return 0; gain = gain + 89; } return double(gain); } SoapySDR::Range SoapyPlutoSDR::getGainRange( const int direction, const size_t channel, const std::string &name ) const { if(direction==SOAPY_SDR_RX) return(SoapySDR::Range(0, 73)); return(SoapySDR::Range(0,89)); } /******************************************************************* * Frequency API ******************************************************************/ void SoapyPlutoSDR::setFrequency( const int direction, const size_t channel, const std::string &name, const double frequency, const SoapySDR::Kwargs &args ) { long long freq = (long long)frequency; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); iio_channel_attr_write_longlong(iio_device_find_channel(dev, "altvoltage0", true),"frequency", freq); } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); iio_channel_attr_write_longlong(iio_device_find_channel(dev, "altvoltage1", true),"frequency", freq); } } double SoapyPlutoSDR::getFrequency( const int direction, const size_t channel, const std::string &name ) const { long long freq = 0; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(dev, "altvoltage0", true),"frequency",&freq )!=0) return 0; } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(dev, "altvoltage1", true),"frequency",&freq )!=0) return 0; } return double(freq); } SoapySDR::ArgInfoList SoapyPlutoSDR::getFrequencyArgsInfo(const int direction, const size_t channel) const { SoapySDR::ArgInfoList freqArgs; return freqArgs; } std::vector SoapyPlutoSDR::listFrequencies( const int direction, const size_t channel ) const { std::vector names; names.push_back( "RF" ); return(names); } SoapySDR::RangeList SoapyPlutoSDR::getFrequencyRange( const int direction, const size_t channel, const std::string &name ) const { return(SoapySDR::RangeList( 1, SoapySDR::Range( 70000000, 6000000000ull ) ) ); } /******************************************************************* * Sample Rate API ******************************************************************/ void SoapyPlutoSDR::setSampleRate( const int direction, const size_t channel, const double rate ) { long long samplerate =(long long) rate; #ifdef HAS_AD9361_IIO int const fir = 4; // assume ad9361_set_bb_rate() will load x4 FIR if needed #else int const fir = 1; #endif // note: sample rates below 25e6/12 need x8 decimation/interpolation or x4 FIR to 25e6/48, // below 25e6/96 need x8 decimation/interpolation and x4 FIR, minimum is 25e6/384 // if libad9361 is available it will load an approporiate FIR. if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); decimation = false; if (samplerate < (25e6 / (12 * fir))) { if (samplerate * 8 < (25e6 / 48)) { SoapySDR_logf(SOAPY_SDR_CRITICAL, "sample rate is not supported."); } else if (samplerate * 8 < (25e6 / 12)) { SoapySDR_logf(SOAPY_SDR_NOTICE, "sample rate needs a FIR setting loaded."); } decimation = true; samplerate = samplerate * 8; } iio_channel_attr_write_longlong(iio_device_find_channel(dev, "voltage0", false),"sampling_frequency", samplerate); iio_channel_attr_write_longlong(iio_device_find_channel(rx_dev, "voltage0", false), "sampling_frequency", decimation?samplerate/8:samplerate); if(rx_stream) rx_stream->set_buffer_size_by_samplerate(decimation ? samplerate / 8 : samplerate); } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); interpolation = false; if (samplerate < (25e6 / (12 * fir))) { if (samplerate * 8 < (25e6 / 48)) { SoapySDR_logf(SOAPY_SDR_CRITICAL, "sample rate is not supported."); } else if (samplerate * 8 < (25e6 / 12)) { SoapySDR_logf(SOAPY_SDR_NOTICE, "sample rate needs a FIR setting loaded."); } interpolation = true; samplerate = samplerate * 8; } iio_channel_attr_write_longlong(iio_device_find_channel(dev, "voltage0", true),"sampling_frequency", samplerate); iio_channel_attr_write_longlong(iio_device_find_channel(tx_dev, "voltage0", true), "sampling_frequency", interpolation?samplerate / 8:samplerate); } #ifdef HAS_AD9361_IIO if(ad9361_set_bb_rate(dev,(unsigned long)samplerate)) SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to set BB rate."); #endif } double SoapyPlutoSDR::getSampleRate( const int direction, const size_t channel ) const { long long samplerate = 0; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(rx_dev, "voltage0", false),"sampling_frequency",&samplerate )!=0) return 0; } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(tx_dev, "voltage0", true),"sampling_frequency",&samplerate)!=0) return 0; } return double(samplerate); } std::vector SoapyPlutoSDR::listSampleRates( const int direction, const size_t channel ) const { std::vector options; options.push_back(65105);//25M/48/8+1 options.push_back(1e6); options.push_back(2e6); options.push_back(3e6); options.push_back(4e6); options.push_back(5e6); options.push_back(6e6); options.push_back(7e6); options.push_back(8e6); options.push_back(9e6); options.push_back(10e6); return(options); } SoapySDR::RangeList SoapyPlutoSDR::getSampleRateRange( const int direction, const size_t channel ) const { SoapySDR::RangeList results; // note that there are some gaps and rounding errors since we get truncated values form IIO // e.g. 25e6/12 = 2083333.333 is read as 2083333 but written as 2083334 #ifdef HAS_AD9361_IIO // assume ad9361_set_bb_rate(), if available, will load x4 FIR as needed // below 25e6/96 needs x8 decimation/interpolation and x4 FIR, minimum is 25e6/384 results.push_back(SoapySDR::Range(25e6 / 384, 61440000)); #else // sample rates below 25e6/12 need x8 decimation/interpolation (or x4 FIR to 25e6/48) results.push_back(SoapySDR::Range(25e6 / 96, 61440000)); #endif return results; } void SoapyPlutoSDR::setBandwidth( const int direction, const size_t channel, const double bw ) { long long bandwidth = (long long) bw; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); iio_channel_attr_write_longlong(iio_device_find_channel(dev, "voltage0", false),"rf_bandwidth", bandwidth); } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); iio_channel_attr_write_longlong(iio_device_find_channel(dev, "voltage0", true),"rf_bandwidth", bandwidth); } } double SoapyPlutoSDR::getBandwidth( const int direction, const size_t channel ) const { long long bandwidth = 0; if(direction==SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", false),"rf_bandwidth",&bandwidth )!=0) return 0; } else if(direction==SOAPY_SDR_TX){ std::lock_guard lock(tx_device_mutex); if(iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", true),"rf_bandwidth",&bandwidth )!=0) return 0; } return double(bandwidth); } std::vector SoapyPlutoSDR::listBandwidths( const int direction, const size_t channel ) const { std::vector options; options.push_back(0.2e6); options.push_back(1e6); options.push_back(2e6); options.push_back(3e6); options.push_back(4e6); options.push_back(5e6); options.push_back(6e6); options.push_back(7e6); options.push_back(8e6); options.push_back(9e6); options.push_back(10e6); return(options); } SoapyPlutoSDR-soapy-plutosdr-0.2.2/PlutoSDR_Streaming.cpp000066400000000000000000000501701456443737600234250ustar00rootroot00000000000000#include "SoapyPlutoSDR.hpp" #include #include #include #include #include #include #include //TODO: Need to be a power of 2 for maximum efficiency ? # define DEFAULT_RX_BUFFER_SIZE (1 << 16) std::vector SoapyPlutoSDR::getStreamFormats(const int direction, const size_t channel) const { std::vector formats; formats.push_back(SOAPY_SDR_CS8); formats.push_back(SOAPY_SDR_CS12); formats.push_back(SOAPY_SDR_CS16); formats.push_back(SOAPY_SDR_CF32); return formats; } std::string SoapyPlutoSDR::getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const { if (direction == SOAPY_SDR_RX) { fullScale = 2048; // RX expects 12 bit samples LSB aligned } else if (direction == SOAPY_SDR_TX) { fullScale = 32768; // TX expects 12 bit samples MSB aligned } return SOAPY_SDR_CS16; } SoapySDR::ArgInfoList SoapyPlutoSDR::getStreamArgsInfo(const int direction, const size_t channel) const { SoapySDR::ArgInfoList streamArgs; return streamArgs; } bool SoapyPlutoSDR::IsValidRxStreamHandle(SoapySDR::Stream* handle) const { if (handle == nullptr) { return false; } //handle is an opaque pointer hiding either rx_stream or tx_streamer: //check that the handle matches one of them, consistently with direction: if (rx_stream) { //test if these handles really belong to us: if (reinterpret_cast(handle) == rx_stream.get()) { return true; } } return false; } bool SoapyPlutoSDR::IsValidTxStreamHandle(SoapySDR::Stream* handle) const { if (handle == nullptr) { return false; } //handle is an opaque pointer hiding either rx_stream or tx_streamer: //check that the handle matches one of them, consistently with direction: if (tx_stream) { //test if these handles really belong to us: if (reinterpret_cast(handle) == tx_stream.get()) { return true; } } return false; } SoapySDR::Stream *SoapyPlutoSDR::setupStream( const int direction, const std::string &format, const std::vector &channels, const SoapySDR::Kwargs &args ) { //check the format plutosdrStreamFormat streamFormat; if (format == SOAPY_SDR_CF32) { SoapySDR_log(SOAPY_SDR_INFO, "Using format CF32."); streamFormat = PLUTO_SDR_CF32; } else if (format == SOAPY_SDR_CS16) { SoapySDR_log(SOAPY_SDR_INFO, "Using format CS16."); streamFormat = PLUTO_SDR_CS16; } else if (format == SOAPY_SDR_CS12) { SoapySDR_log(SOAPY_SDR_INFO, "Using format CS12."); streamFormat = PLUTO_SDR_CS12; } else if (format == SOAPY_SDR_CS8) { SoapySDR_log(SOAPY_SDR_INFO, "Using format CS8."); streamFormat = PLUTO_SDR_CS8; } else { throw std::runtime_error( "setupStream invalid format '" + format + "' -- Only CS8, CS12, CS16 and CF32 are supported by SoapyPlutoSDR module."); } if(direction == SOAPY_SDR_RX){ std::lock_guard lock(rx_device_mutex); iio_channel_attr_write_bool( iio_device_find_channel(dev, "altvoltage0", true), "powerdown", false); // Turn ON RX LO this->rx_stream = std::unique_ptr(new rx_streamer (rx_dev, streamFormat, channels, args)); return reinterpret_cast(this->rx_stream.get()); } else if (direction == SOAPY_SDR_TX) { std::lock_guard lock(tx_device_mutex); iio_channel_attr_write_bool( iio_device_find_channel(dev, "altvoltage1", true), "powerdown", false); // Turn ON TX LO this->tx_stream = std::unique_ptr(new tx_streamer (tx_dev, streamFormat, channels, args)); return reinterpret_cast(this->tx_stream.get()); } return nullptr; } void SoapyPlutoSDR::closeStream( SoapySDR::Stream *handle) { //scope lock: { std::lock_guard lock(rx_device_mutex); if (IsValidRxStreamHandle(handle)) { this->rx_stream.reset(); iio_channel_attr_write_bool( iio_device_find_channel(dev, "altvoltage0", true), "powerdown", true); // Turn OFF RX LO } } //scope lock : { std::lock_guard lock(tx_device_mutex); if (IsValidTxStreamHandle(handle)) { this->tx_stream.reset(); iio_channel_attr_write_bool( iio_device_find_channel(dev, "altvoltage1", true), "powerdown", true); // Turn OFF TX LO } } } size_t SoapyPlutoSDR::getStreamMTU( SoapySDR::Stream *handle) const { std::lock_guard lock(rx_device_mutex); if (IsValidRxStreamHandle(handle)) { return this->rx_stream->get_mtu_size(); } if (IsValidTxStreamHandle(handle)) { return 4096; } return 0; } int SoapyPlutoSDR::activateStream( SoapySDR::Stream *handle, const int flags, const long long timeNs, const size_t numElems ) { if (flags & ~SOAPY_SDR_END_BURST) return SOAPY_SDR_NOT_SUPPORTED; std::lock_guard lock(rx_device_mutex); if (IsValidRxStreamHandle(handle)) { return this->rx_stream->start(flags, timeNs, numElems); } return 0; } int SoapyPlutoSDR::deactivateStream( SoapySDR::Stream *handle, const int flags, const long long timeNs ) { //scope lock: { std::lock_guard lock(rx_device_mutex); if (IsValidRxStreamHandle(handle)) { return this->rx_stream->stop(flags, timeNs); } } //scope lock : { std::lock_guard lock(tx_device_mutex); if (IsValidTxStreamHandle(handle)) { this->tx_stream->flush(); return 0; } } return 0; } int SoapyPlutoSDR::readStream( SoapySDR::Stream *handle, void * const *buffs, const size_t numElems, int &flags, long long &timeNs, const long timeoutUs ) { //the spin_mutex is especially very useful here for minimum overhead ! std::lock_guard lock(rx_device_mutex); if (IsValidRxStreamHandle(handle)) { return int(this->rx_stream->recv(buffs, numElems, flags, timeNs, timeoutUs)); } else { return SOAPY_SDR_NOT_SUPPORTED; } } int SoapyPlutoSDR::writeStream( SoapySDR::Stream *handle, const void * const *buffs, const size_t numElems, int &flags, const long long timeNs, const long timeoutUs ) { std::lock_guard lock(tx_device_mutex); if (IsValidTxStreamHandle(handle)) { return this->tx_stream->send(buffs, numElems, flags, timeNs, timeoutUs);; } else { return SOAPY_SDR_NOT_SUPPORTED; } } int SoapyPlutoSDR::readStreamStatus( SoapySDR::Stream *stream, size_t &chanMask, int &flags, long long &timeNs, const long timeoutUs) { return SOAPY_SDR_NOT_SUPPORTED; } void rx_streamer::set_buffer_size_by_samplerate(const size_t samplerate) { //Adapt buffer size (= MTU) as a tradeoff to minimize readStream overhead but at //the same time allow realtime applications. Keep it a power of 2 which seems to be better. //so try to target very roughly 60fps [30 .. 100] readStream calls / s for realtime applications. int rounded_nb_samples_per_call = (int)::round(samplerate / 60.0); int power_of_2_nb_samples = 0; while (rounded_nb_samples_per_call > (1 << power_of_2_nb_samples)) { power_of_2_nb_samples++; } this->set_buffer_size(1 << power_of_2_nb_samples); SoapySDR_logf(SOAPY_SDR_INFO, "Auto setting Buffer Size: %lu", (unsigned long)buffer_size); //Recompute MTU from buffer size change. //We always set MTU size = Buffer Size. //On buffer size adjustment to sample rate, //MTU can be changed accordingly safely here. set_mtu_size(this->buffer_size); } void rx_streamer::set_mtu_size(const size_t mtu_size) { this->mtu_size = mtu_size; SoapySDR_logf(SOAPY_SDR_INFO, "Set MTU Size: %lu", (unsigned long)mtu_size); } rx_streamer::rx_streamer(const iio_device *_dev, const plutosdrStreamFormat _format, const std::vector &channels, const SoapySDR::Kwargs &args): dev(_dev), buffer_size(DEFAULT_RX_BUFFER_SIZE), buf(nullptr), format(_format), mtu_size(DEFAULT_RX_BUFFER_SIZE) { if (dev == nullptr) { SoapySDR_logf(SOAPY_SDR_ERROR, "cf-ad9361-lpc not found!"); throw std::runtime_error("cf-ad9361-lpc not found!"); } unsigned int nb_channels = iio_device_get_channels_count(dev), i; for (i = 0; i < nb_channels; i++) iio_channel_disable(iio_device_get_channel(dev, i)); //default to channel 0, if none were specified const std::vector &channelIDs = channels.empty() ? std::vector{0} : channels; for (i = 0; i < channelIDs.size() * 2; i++) { struct iio_channel *chn = iio_device_get_channel(dev, i); iio_channel_enable(chn); channel_list.push_back(chn); } if ( args.count( "bufflen" ) != 0 ){ try { size_t bufferLength = std::stoi(args.at("bufflen")); if (bufferLength > 0) this->set_buffer_size(bufferLength); } catch (const std::invalid_argument &){} }else{ long long samplerate; iio_channel_attr_read_longlong(iio_device_find_channel(dev, "voltage0", false),"sampling_frequency",&samplerate); this->set_buffer_size_by_samplerate(samplerate); } } rx_streamer::~rx_streamer() { if (buf) { iio_buffer_cancel(buf); iio_buffer_destroy(buf); } for (unsigned int i = 0; i < channel_list.size(); ++i) { iio_channel_disable(channel_list[i]); } } size_t rx_streamer::recv(void * const *buffs, const size_t numElems, int &flags, long long &timeNs, const long timeoutUs) { // if (items_in_buffer <= 0) { // auto before = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); if (!buf) { return 0; } ssize_t ret = iio_buffer_refill(buf); // auto after = std::chrono::duration_cast(std::chrono::high_resolution_clock::now().time_since_epoch()).count(); if (ret < 0) return SOAPY_SDR_TIMEOUT; items_in_buffer = (unsigned long)ret / iio_buffer_step(buf); // SoapySDR_logf(SOAPY_SDR_INFO, "iio_buffer_refill took %d ms to refill %d items", (int)(after - before), items_in_buffer); byte_offset = 0; } size_t items = std::min(items_in_buffer,numElems); ptrdiff_t buf_step = iio_buffer_step(buf); if (direct_copy) { // optimize for single RX, 2 channel (I/Q), same endianess direct copy // note that RX is 12 bits LSB aligned, i.e. fullscale 2048 uint8_t *src = (uint8_t *)iio_buffer_start(buf) + byte_offset; int16_t const *src_ptr = (int16_t *)src; if (format == PLUTO_SDR_CS16) { ::memcpy(buffs[0], src_ptr, 2 * sizeof(int16_t) * items); } else if (format == PLUTO_SDR_CF32) { float *dst_cf32 = (float *)buffs[0]; for (size_t index = 0; index < items * 2; ++index) { *dst_cf32 = float(*src_ptr) / 2048.0f; src_ptr++; dst_cf32++; } } else if (format == PLUTO_SDR_CS12) { int8_t *dst_cs12 = (int8_t *)buffs[0]; for (size_t index = 0; index < items; ++index) { int16_t i = *src_ptr++; int16_t q = *src_ptr++; // produce 24 bit (iiqIQQ), note the input is LSB aligned, scale=2048 // note: byte0 = i[7:0]; byte1 = {q[3:0], i[11:8]}; byte2 = q[11:4]; *dst_cs12++ = uint8_t(i); *dst_cs12++ = uint8_t((q << 4) | ((i >> 8) & 0x0f)); *dst_cs12++ = uint8_t(q >> 4); } } else if (format == PLUTO_SDR_CS8) { int8_t *dst_cs8 = (int8_t *)buffs[0]; for (size_t index = 0; index < items * 2; index++) { *dst_cs8 = int8_t(*src_ptr >> 4); src_ptr++; dst_cs8++; } } } else { int16_t conv = 0, *conv_ptr = &conv; for (unsigned int i = 0; i < channel_list.size(); i++) { iio_channel *chn = channel_list[i]; unsigned int index = i / 2; uint8_t *src = (uint8_t *)iio_buffer_first(buf, chn) + byte_offset; if (format == PLUTO_SDR_CS16) { int16_t *dst_cs16 = (int16_t *)buffs[index]; for (size_t j = 0; j < items; ++j) { iio_channel_convert(chn, conv_ptr, src); src += buf_step; dst_cs16[j * 2 + i] = conv; } } else if (format == PLUTO_SDR_CF32) { float *dst_cf32 = (float *)buffs[index]; for (size_t j = 0; j < items; ++j) { iio_channel_convert(chn, conv_ptr, src); src += buf_step; dst_cf32[j * 2 + i] = float(conv) / 2048.0f; } } else if (format == PLUTO_SDR_CS8) { int8_t *dst_cs8 = (int8_t *)buffs[index]; for (size_t j = 0; j < items; ++j) { iio_channel_convert(chn, conv_ptr, src); src += buf_step; dst_cs8[j * 2 + i] = int8_t(conv >> 4); } } } } items_in_buffer -= items; byte_offset += items * iio_buffer_step(buf); return(items); } int rx_streamer::start(const int flags, const long long timeNs, const size_t numElems) { //force proper stop before stop(flags, timeNs); // re-create buffer buf = iio_device_create_buffer(dev, buffer_size, false); if (!buf) { SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to create buffer!"); throw std::runtime_error("Unable to create buffer!\n"); } direct_copy = has_direct_copy(); SoapySDR_logf(SOAPY_SDR_INFO, "Has direct RX copy: %d", (int)direct_copy); return 0; } int rx_streamer::stop(const int flags, const long long timeNs) { //cancel first if (buf) { iio_buffer_cancel(buf); } //then destroy if (buf) { iio_buffer_destroy(buf); buf = nullptr; } items_in_buffer = 0; byte_offset = 0; return 0; } void rx_streamer::set_buffer_size(const size_t _buffer_size){ if (!buf || this->buffer_size != _buffer_size) { //cancel first if (buf) { iio_buffer_cancel(buf); } //then destroy if (buf) { iio_buffer_destroy(buf); } items_in_buffer = 0; byte_offset = 0; buf = iio_device_create_buffer(dev, _buffer_size, false); if (!buf) { SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to create buffer!"); throw std::runtime_error("Unable to create buffer!\n"); } } this->buffer_size=_buffer_size; } size_t rx_streamer::get_mtu_size() { return this->mtu_size; } // return wether can we optimize for single RX, 2 channel (I/Q), same endianess direct copy bool rx_streamer::has_direct_copy() { if (channel_list.size() != 2) // one RX with I + Q return false; ptrdiff_t buf_step = iio_buffer_step(buf); if (buf_step != 2 * sizeof(int16_t)) return false; if (iio_buffer_start(buf) != iio_buffer_first(buf, channel_list[0])) return false; int16_t test_dst, test_src = 0x1234; iio_channel_convert(channel_list[0], &test_dst, (const void *)&test_src); return test_src == test_dst; } tx_streamer::tx_streamer(const iio_device *_dev, const plutosdrStreamFormat _format, const std::vector &channels, const SoapySDR::Kwargs &args) : dev(_dev), format(_format), buf(nullptr) { if (dev == nullptr) { SoapySDR_logf(SOAPY_SDR_ERROR, "cf-ad9361-dds-core-lpc not found!"); throw std::runtime_error("cf-ad9361-dds-core-lpc not found!"); } unsigned int nb_channels = iio_device_get_channels_count(dev), i; for (i = 0; i < nb_channels; i++) iio_channel_disable(iio_device_get_channel(dev, i)); //default to channel 0, if none were specified const std::vector &channelIDs = channels.empty() ? std::vector{0} : channels; for (i = 0; i < channelIDs.size() * 2; i++) { iio_channel *chn = iio_device_get_channel(dev, i); iio_channel_enable(chn); channel_list.push_back(chn); } buf_size = 4096; items_in_buf = 0; buf = iio_device_create_buffer(dev, buf_size, false); if (!buf) { SoapySDR_logf(SOAPY_SDR_ERROR, "Unable to create buffer!"); throw std::runtime_error("Unable to create buffer!"); } direct_copy = has_direct_copy(); SoapySDR_logf(SOAPY_SDR_INFO, "Has direct TX copy: %d", (int)direct_copy); } tx_streamer::~tx_streamer(){ if (buf) { iio_buffer_destroy(buf); } for(unsigned int i=0;i 0) { if (items_in_buf < buf_size) { ptrdiff_t buf_step = iio_buffer_step(buf); uint8_t *buf_ptr = (uint8_t *)iio_buffer_start(buf) + items_in_buf * buf_step; uint8_t *buf_end = (uint8_t *)iio_buffer_end(buf); memset(buf_ptr, 0, buf_end - buf_ptr); } ssize_t ret = iio_buffer_push(buf); items_in_buf = 0; if (ret < 0) { return ret; } return int(ret / iio_buffer_step(buf)); } return 0; } // return wether can we optimize for single TX, 2 channel (I/Q), same endianess direct copy bool tx_streamer::has_direct_copy() { if (channel_list.size() != 2) // one TX with I/Q return false; ptrdiff_t buf_step = iio_buffer_step(buf); if (buf_step != 2 * sizeof(int16_t)) return false; if (iio_buffer_start(buf) != iio_buffer_first(buf, channel_list[0])) return false; int16_t test_dst, test_src = 0x1234; iio_channel_convert_inverse(channel_list[0], &test_dst, (const void *)&test_src); return test_src == test_dst; } SoapyPlutoSDR-soapy-plutosdr-0.2.2/README.md000066400000000000000000000021101456443737600205020ustar00rootroot00000000000000# Soapy SDR module for Pluto SDR ## Installation instructions ``` git clone https://github.com/pothosware/SoapyPlutoSDR cd SoapyPlutoSDR mkdir build cd build cmake .. make sudo make install ``` ## Dependencies - [libiio](https://github.com/analogdevicesinc/libiio) - [libad9361](https://github.com/analogdevicesinc/libad9361-iio) - [SoapySDR](https://github.com/pothosware/SoapySDR) ## Documentation * https://github.com/pothosware/SoapyPlutoSDR/wiki Note that the Frequency Correction API is not implemented, it's recommended that you adjust the `xo_correction` value with the observed PPM in the Pluto device `config.txt`. ## PothosSDR Note that installation with PothosSDR is optional as "PlutoSDR SoapySDR binding (experimental)" and not selected by default. This is due to possible problems with other libusb devices, see [#24](https://github.com/pothosware/SoapyPlutoSDR/issues/24) and [libiio#586](https://github.com/analogdevicesinc/libiio/issues/586) ## Licensing information GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 SoapyPlutoSDR-soapy-plutosdr-0.2.2/SoapyPlutoSDR.hpp000066400000000000000000000217231456443737600224370ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include typedef enum plutosdrStreamFormat { PLUTO_SDR_CF32, PLUTO_SDR_CS16, PLUTO_SDR_CS12, PLUTO_SDR_CS8 } plutosdrStreamFormat; class rx_streamer { public: rx_streamer(const iio_device *dev, const plutosdrStreamFormat format, const std::vector &channels, const SoapySDR::Kwargs &args); ~rx_streamer(); size_t recv(void * const *buffs, const size_t numElems, int &flags, long long &timeNs, const long timeoutUs=100000); int start(const int flags, const long long timeNs, const size_t numElems); int stop(const int flags, const long long timeNs=100000); void set_buffer_size_by_samplerate(const size_t _samplerate); size_t get_mtu_size(); private: void set_buffer_size(const size_t _buffer_size); void set_mtu_size(const size_t mtu_size); bool has_direct_copy(); std::vector channel_list; const iio_device *dev; size_t buffer_size; size_t byte_offset; size_t items_in_buffer; iio_buffer *buf; const plutosdrStreamFormat format; bool direct_copy; size_t mtu_size; }; class tx_streamer { public: tx_streamer(const iio_device *dev, const plutosdrStreamFormat format, const std::vector &channels, const SoapySDR::Kwargs &args); ~tx_streamer(); int send(const void * const *buffs,const size_t numElems,int &flags,const long long timeNs,const long timeoutUs ); int flush(); private: int send_buf(); bool has_direct_copy(); std::vector channel_list; const iio_device *dev; const plutosdrStreamFormat format; iio_buffer *buf; size_t buf_size; size_t items_in_buf; bool direct_copy; }; // A local spin_mutex usable with std::lock_guard //for lightweight locking for short periods. class pluto_spin_mutex { public: pluto_spin_mutex() = default; pluto_spin_mutex(const pluto_spin_mutex&) = delete; pluto_spin_mutex& operator=(const pluto_spin_mutex&) = delete; ~pluto_spin_mutex() { lock_state.clear(std::memory_order_release); } void lock() { while (lock_state.test_and_set(std::memory_order_acquire)); } void unlock() { lock_state.clear(std::memory_order_release); } private: std::atomic_flag lock_state = ATOMIC_FLAG_INIT; }; class SoapyPlutoSDR : public SoapySDR::Device{ public: SoapyPlutoSDR( const SoapySDR::Kwargs & args ); ~SoapyPlutoSDR(); /******************************************************************* * Identification API ******************************************************************/ std::string getDriverKey( void ) const; std::string getHardwareKey( void ) const; SoapySDR::Kwargs getHardwareInfo( void ) const; /******************************************************************* * Channels API ******************************************************************/ size_t getNumChannels( const int ) const; bool getFullDuplex( const int direction, const size_t channel ) const; /******************************************************************* * Stream API ******************************************************************/ std::vector getStreamFormats(const int direction, const size_t channel) const; std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const; SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const; SoapySDR::Stream *setupStream( const int direction, const std::string &format, const std::vector &channels = std::vector(), const SoapySDR::Kwargs &args = SoapySDR::Kwargs() ); void closeStream( SoapySDR::Stream *stream ); size_t getStreamMTU( SoapySDR::Stream *stream ) const; int activateStream( SoapySDR::Stream *stream, const int flags = 0, const long long timeNs = 0, const size_t numElems = 0 ); int deactivateStream( SoapySDR::Stream *stream, const int flags = 0, const long long timeNs = 0 ); int readStream( SoapySDR::Stream *stream, void * const *buffs, const size_t numElems, int &flags, long long &timeNs, const long timeoutUs = 100000 ); int writeStream( SoapySDR::Stream *stream, const void * const *buffs, const size_t numElems, int &flags, const long long timeNs = 0, const long timeoutUs = 100000); int readStreamStatus( SoapySDR::Stream *stream, size_t &chanMask, int &flags, long long &timeNs, const long timeoutUs ); /******************************************************************* * Sensor API ******************************************************************/ std::vector listSensors(void) const; SoapySDR::ArgInfo getSensorInfo(const std::string &key) const; std::string readSensor(const std::string &key) const; /******************************************************************* * Settings API ******************************************************************/ SoapySDR::ArgInfoList getSettingInfo(void) const; void writeSetting(const std::string &key, const std::string &value); std::string readSetting(const std::string &key) const; /******************************************************************* * Antenna API ******************************************************************/ std::vector listAntennas( const int direction, const size_t channel ) const; void setAntenna( const int direction, const size_t channel, const std::string &name ); std::string getAntenna( const int direction, const size_t channel ) const; /******************************************************************* * Frontend corrections API ******************************************************************/ bool hasDCOffsetMode( const int direction, const size_t channel ) const; /******************************************************************* * Gain API ******************************************************************/ std::vector listGains( const int direction, const size_t channel ) const; bool hasGainMode(const int direction, const size_t channel) const; void setGainMode( const int direction, const size_t channel, const bool automatic ); bool getGainMode( const int direction, const size_t channel ) const; void setGain( const int direction, const size_t channel, const double value ); void setGain( const int direction, const size_t channel, const std::string &name, const double value ); double getGain( const int direction, const size_t channel, const std::string &name ) const; SoapySDR::Range getGainRange( const int direction, const size_t channel, const std::string &name ) const; /******************************************************************* * Frequency API ******************************************************************/ void setFrequency( const int direction, const size_t channel, const std::string &name, const double frequency, const SoapySDR::Kwargs &args = SoapySDR::Kwargs() ); double getFrequency( const int direction, const size_t channel, const std::string &name ) const; SoapySDR::ArgInfoList getFrequencyArgsInfo(const int direction, const size_t channel) const; std::vector listFrequencies( const int direction, const size_t channel ) const; SoapySDR::RangeList getFrequencyRange( const int direction, const size_t channel, const std::string &name ) const; /******************************************************************* * Sample Rate API ******************************************************************/ void setSampleRate( const int direction, const size_t channel, const double rate ); double getSampleRate( const int direction, const size_t channel ) const; std::vector listSampleRates( const int direction, const size_t channel ) const; void setBandwidth( const int direction, const size_t channel, const double bw ); double getBandwidth( const int direction, const size_t channel ) const; std::vector listBandwidths( const int direction, const size_t channel ) const; SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const; private: bool IsValidRxStreamHandle(SoapySDR::Stream* handle) const; bool IsValidTxStreamHandle(SoapySDR::Stream* handle) const; bool is_sensor_channel(struct iio_channel *chn) const; double double_from_buf(const char *buf) const; double get_sensor_value(struct iio_channel *chn) const; std::string id_to_unit(const std::string &id) const; iio_device *dev; iio_device *rx_dev; iio_device *tx_dev; bool gainMode; mutable pluto_spin_mutex rx_device_mutex; mutable pluto_spin_mutex tx_device_mutex; bool decimation, interpolation; std::unique_ptr rx_stream; std::unique_ptr tx_stream; }; SoapyPlutoSDR-soapy-plutosdr-0.2.2/cmake/000077500000000000000000000000001456443737600203115ustar00rootroot00000000000000SoapyPlutoSDR-soapy-plutosdr-0.2.2/cmake/cmake_uninstall.cmake.in000066400000000000000000000020131456443737600250650ustar00rootroot00000000000000if(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") message(FATAL_ERROR "Cannot find install manifest: @CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) string(REGEX REPLACE "\n" ";" files "${files}") foreach(file ${files}) message(STATUS "Uninstalling $ENV{DESTDIR}${file}") if(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") exec_program( "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" OUTPUT_VARIABLE rm_out RETURN_VALUE rm_retval ) if(NOT "${rm_retval}" STREQUAL 0) message(FATAL_ERROR "Problem when removing $ENV{DESTDIR}${file}") endif(NOT "${rm_retval}" STREQUAL 0) else(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") message(STATUS "File $ENV{DESTDIR}${file} does not exist.") endif(IS_SYMLINK "$ENV{DESTDIR}${file}" OR EXISTS "$ENV{DESTDIR}${file}") endforeach(file) SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/000077500000000000000000000000001456443737600204535ustar00rootroot00000000000000SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/changelog000066400000000000000000000011231456443737600223220ustar00rootroot00000000000000soapyplutosdr (0.2.2-1) unstable; urgency=low * Release 0.2.2 (2024-02-18) -- Josh Blum Sun, 18 Feb 2024 11:31:29 -0000 soapyplutosdr (0.2.1-1) unstable; urgency=low * Release 0.2.1 (2021-01-23) -- Josh Blum Sat, 23 Jan 2021 10:06:56 -0000 soapyplutosdr (0.2.0-1) unstable; urgency=low * Release 0.2.0 (2019-06-22) -- Josh Blum Sat, 22 Jun 2019 07:50:37 -0000 soapyplutosdr (0.1.0-1) unstable; urgency=low * Release 0.1.0 (2018-12-21) -- Josh Blum Sun, 30 Dec 2018 09:56:58 -0600 SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/compat000066400000000000000000000000021456443737600216510ustar00rootroot000000000000009 SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/control000066400000000000000000000017731456443737600220660ustar00rootroot00000000000000Source: soapyplutosdr Section: libs Priority: optional Maintainer: Josh Blum Build-Depends: debhelper (>= 9.0.0), cmake, libiio-dev, libad9361-dev, libsoapysdr-dev Standards-Version: 4.5.0 Homepage: https://github.com/pothosware/SoapyPlutoSDR/wiki Vcs-Git: https://github.com/pothosware/SoapyPlutoSDR.git Vcs-Browser: https://github.com/pothosware/SoapyPlutoSDR Package: soapysdr0.7-module-plutosdr Architecture: any Multi-Arch: same Depends: ${shlibs:Depends}, ${misc:Depends} Description: Soapy PlutoSDR - PlutoSDR device support for Soapy SDR. A Soapy module that supports PlutoSDR devices within the Soapy API. Package: soapysdr-module-plutosdr Architecture: all Depends: soapysdr0.7-module-plutosdr, ${misc:Depends} Description: Soapy PlutoSDR - PlutoSDR device support for Soapy SDR. A Soapy module that supports PlutoSDR devices within the Soapy API. . This is an empty dependency package that pulls in the PlutoSDR module for the default version of libsoapysdr. SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/copyright000066400000000000000000000007711456443737600224130ustar00rootroot00000000000000Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: soapyplutosdr Source: https://github.com/pothosware/SoapyPlutoSDR/wiki Files: * Copyright: Copyright (c) 2017 Wei Jiang Copyright (c) 2018 Josh Blum Copyright (c) 2018 Adrian Musceac Copyright (c) 2018 Christian W. Zuckschwerdt License: LGPL-2.1 On Debian systems, the full text of the GNU Lesser General Public License version 2.1 can be found in the file `/usr/share/common-licenses/LGPL-2.1'. SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/docs000066400000000000000000000000121456443737600213170ustar00rootroot00000000000000README.md SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/rules000077500000000000000000000006161456443737600215360ustar00rootroot00000000000000#!/usr/bin/make -f # -*- makefile -*- DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) export DEB_HOST_MULTIARCH # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 %: dh $@ --buildsystem=cmake --parallel override_dh_auto_configure: dh_auto_configure -- -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" override_dh_installchangelogs: dh_installchangelogs Changelog.txt SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/soapysdr0.7-module-plutosdr.install000066400000000000000000000000121456443737600272620ustar00rootroot00000000000000usr/lib/* SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/source/000077500000000000000000000000001456443737600217535ustar00rootroot00000000000000SoapyPlutoSDR-soapy-plutosdr-0.2.2/debian/source/format000066400000000000000000000000141456443737600231610ustar00rootroot000000000000003.0 (quilt)