├── .gitignore ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── Doxyfile.in ├── Makefile.am ├── README ├── cmake ├── Modules │ └── Version.cmake ├── cmake_uninstall.cmake.in └── rtlsdrConfig.cmake ├── configure.ac ├── contrib └── jenkins.sh ├── debian ├── README.Debian ├── changelog ├── compat ├── control ├── copyright ├── copyright-scan-patterns.yml ├── heatmap.py ├── librtlsdr-dev.acc ├── librtlsdr-dev.dirs ├── librtlsdr-dev.install ├── librtlsdr0.dirs ├── librtlsdr0.install ├── librtlsdr0.maintscript ├── librtlsdr0.metainfo.xml ├── librtlsdr0.udev ├── rtl-sdr-blacklist.conf ├── rtl-sdr.dirs ├── rtl-sdr.examples ├── rtl-sdr.install ├── rtl-sdr.manpages ├── rtl_adsb.1 ├── rtl_eeprom.1 ├── rtl_fm.1 ├── rtl_power.1 ├── rtl_sdr.1 ├── rtl_tcp.1 ├── rtl_test.1 ├── rules ├── source │ └── format └── watch ├── git-version-gen ├── include ├── CMakeLists.txt ├── Makefile.am ├── reg_field.h ├── rtl-sdr.h ├── rtl-sdr_export.h ├── rtlsdr_i2c.h ├── tuner_e4k.h ├── tuner_fc0012.h ├── tuner_fc0013.h ├── tuner_fc2580.h └── tuner_r82xx.h ├── librtlsdr.pc.in ├── m4 └── .gitignore ├── rtl-sdr.rules └── src ├── CMakeLists.txt ├── Makefile.am ├── convenience ├── convenience.c └── convenience.h ├── getopt ├── getopt.c └── getopt.h ├── librtlsdr.c ├── rtl_adsb.c ├── rtl_biast.c ├── rtl_eeprom.c ├── rtl_fm.c ├── rtl_power.c ├── rtl_sdr.c ├── rtl_tcp.c ├── rtl_test.c ├── rtlsdr.rc.in ├── tuner_e4k.c ├── tuner_fc0012.c ├── tuner_fc0013.c ├── tuner_fc2580.c └── tuner_r82xx.c /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | Makefile.in 3 | .deps 4 | .libs 5 | *.o 6 | *.lo 7 | *.la 8 | *.pc 9 | aclocal.m4 10 | acinclude.m4 11 | aminclude.am 12 | m4/*.m4 13 | autom4te.cache 14 | config.h* 15 | config.sub 16 | config.log 17 | config.status 18 | config.guess 19 | configure 20 | depcomp 21 | missing 22 | ltmain.sh 23 | install-sh 24 | stamp-h1 25 | libtool 26 | Doxyfile 27 | 28 | .tarball-version 29 | .version 30 | 31 | .*.swp 32 | 33 | doc/ 34 | 35 | src/rtl_sdr 36 | src/rtl_tcp 37 | 38 | CMakeCache.txt 39 | */CMakeFiles 40 | CMakeFiles 41 | *.cmake 42 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | 6 | before_install: 7 | - sudo apt-get update -qq 8 | - sudo apt-get install -qq libusb-1.0-0-dev 9 | 10 | script: cmake . && make && sudo make install 11 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Steve Markgraf 2 | Dimitri Stolnikov 3 | Hoernchen 4 | Kyle Keen 5 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2012-2020 Osmocom Project 2 | # 3 | # This file is part of rtl-sdr 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | 19 | ######################################################################## 20 | # Project setup 21 | ######################################################################## 22 | cmake_minimum_required(VERSION 3.7.2) 23 | 24 | # workaround for https://gitlab.kitware.com/cmake/cmake/issues/16967 25 | if(${CMAKE_VERSION} VERSION_LESS "3.12.0") 26 | project(rtlsdr) 27 | else() 28 | project(rtlsdr C) 29 | endif() 30 | 31 | #select the release build type by default to get optimization flags 32 | if(NOT CMAKE_BUILD_TYPE) 33 | set(CMAKE_BUILD_TYPE "Release") 34 | message(STATUS "Build type not specified: defaulting to release.") 35 | endif(NOT CMAKE_BUILD_TYPE) 36 | 37 | list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) 38 | 39 | include(GNUInstallDirs) 40 | include(GenerateExportHeader) 41 | include(CMakePackageConfigHelpers) 42 | 43 | # Set the version information here 44 | set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes 45 | set(VERSION_INFO_MINOR_VERSION 6) # increment minor on feature-level changes 46 | set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs 47 | include(Version) # setup version info 48 | 49 | ######################################################################## 50 | # Compiler specific setup 51 | ######################################################################## 52 | if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32) 53 | ADD_DEFINITIONS(-Wall) 54 | ADD_DEFINITIONS(-Wextra) 55 | ADD_DEFINITIONS(-Wno-unused-parameter) 56 | ADD_DEFINITIONS(-Wno-unused) 57 | ADD_DEFINITIONS(-Wsign-compare) 58 | ADD_DEFINITIONS(-Wdeclaration-after-statement) 59 | #http://gcc.gnu.org/wiki/Visibility 60 | add_definitions(-fvisibility=hidden) 61 | elseif(MSVC14 OR MSVC14) 62 | #pthread-w32 issue, timespec is now part of time.h 63 | ADD_DEFINITIONS(-D_TIMESPEC_DEFINED) 64 | endif() 65 | 66 | ######################################################################## 67 | # Find build dependencies 68 | ######################################################################## 69 | find_package(Threads) 70 | find_package(PkgConfig) 71 | 72 | if(PKG_CONFIG_FOUND) 73 | pkg_check_modules(LIBUSB libusb-1.0 IMPORTED_TARGET) 74 | else() 75 | set(LIBUSB_LIBRARIES "" CACHE STRING "manual libusb path") 76 | set(LIBUSB_INCLUDE_DIRS "" CACHE STRING "manual libusb includepath") 77 | endif() 78 | 79 | if(MSVC) 80 | set(THREADS_PTHREADS_LIBRARY "" CACHE STRING "manual pthread-win32 path") 81 | set(THREADS_PTHREADS_INCLUDE_DIR "" CACHE STRING "manual pthread-win32 includepath") 82 | else() 83 | set(THREADS_PTHREADS_LIBRARY "" CACHE INTERNAL "manual pthread-win32 path") 84 | set(THREADS_PTHREADS_INCLUDE_DIR "" CACHE INTERNAL "manual pthread-win32 includepath") 85 | endif() 86 | 87 | if(PKG_CONFIG_FOUND AND NOT LIBUSB_FOUND) 88 | message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr") 89 | endif() 90 | if(NOT THREADS_FOUND) 91 | message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr") 92 | endif() 93 | 94 | ######################################################################## 95 | # Create uninstall target 96 | ######################################################################## 97 | configure_file( 98 | ${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in 99 | ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake 100 | @ONLY) 101 | 102 | add_custom_target(uninstall 103 | ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake 104 | ) 105 | 106 | ######################################################################## 107 | # Install udev rules 108 | ######################################################################## 109 | option(INSTALL_UDEV_RULES "Install udev rules for RTL-SDR" OFF) 110 | if (INSTALL_UDEV_RULES) 111 | install ( 112 | FILES rtl-sdr.rules 113 | DESTINATION "/etc/udev/rules.d" 114 | COMPONENT "udev" 115 | ) 116 | else (INSTALL_UDEV_RULES) 117 | message (STATUS "Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON") 118 | endif (INSTALL_UDEV_RULES) 119 | 120 | option(DETACH_KERNEL_DRIVER "Detach kernel driver if loaded" OFF) 121 | if (DETACH_KERNEL_DRIVER) 122 | message (STATUS "Building with kernel driver detaching enabled") 123 | add_definitions(-DDETACH_KERNEL_DRIVER=1) 124 | else (DETACH_KERNEL_DRIVER) 125 | message (STATUS "Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable") 126 | endif (DETACH_KERNEL_DRIVER) 127 | 128 | option(ENABLE_ZEROCOPY "Enable usbfs zero-copy support" OFF) 129 | if (ENABLE_ZEROCOPY) 130 | message (STATUS "Building with usbfs zero-copy support enabled") 131 | add_definitions(-DENABLE_ZEROCOPY=1) 132 | else (ENABLE_ZEROCOPY) 133 | message (STATUS "Building with usbfs zero-copy support disabled, use -DENABLE_ZEROCOPY=ON to enable") 134 | endif (ENABLE_ZEROCOPY) 135 | 136 | ######################################################################## 137 | # Install public header files 138 | ######################################################################## 139 | install(FILES 140 | include/rtl-sdr.h 141 | include/rtl-sdr_export.h 142 | DESTINATION include 143 | ) 144 | 145 | ######################################################################## 146 | # Add subdirectories 147 | ######################################################################## 148 | add_subdirectory(src) 149 | 150 | ######################################################################## 151 | # Create Pkg Config File 152 | ######################################################################## 153 | FOREACH(inc ${LIBUSB_INCLUDEDIR}) 154 | LIST(APPEND RTLSDR_PC_CFLAGS "-I${inc}") 155 | ENDFOREACH(inc) 156 | 157 | FOREACH(lib ${LIBUSB_LIBRARY_DIRS}) 158 | LIST(APPEND RTLSDR_PC_LIBS "-L${lib}") 159 | ENDFOREACH(lib) 160 | 161 | # use space-separation format for the pc file 162 | STRING(REPLACE ";" " " RTLSDR_PC_CFLAGS "${RTLSDR_PC_CFLAGS}") 163 | STRING(REPLACE ";" " " RTLSDR_PC_LIBS "${RTLSDR_PC_LIBS}") 164 | 165 | # unset these vars to avoid hard-coded paths to cross environment 166 | IF(CMAKE_CROSSCOMPILING) 167 | UNSET(RTLSDR_PC_CFLAGS) 168 | UNSET(RTLSDR_PC_LIBS) 169 | ENDIF(CMAKE_CROSSCOMPILING) 170 | 171 | set(prefix "${CMAKE_INSTALL_PREFIX}") 172 | set(exec_prefix \${prefix}) 173 | set(includedir \${prefix}/include) 174 | set(libdir \${exec_prefix}/lib) 175 | 176 | CONFIGURE_FILE( 177 | ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in 178 | ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc 179 | @ONLY) 180 | 181 | INSTALL( 182 | FILES ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc 183 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig 184 | ) 185 | 186 | ######################################################################## 187 | # Create CMake Config File 188 | ######################################################################## 189 | write_basic_package_version_file( 190 | "${CMAKE_CURRENT_BINARY_DIR}/rtlsdr/rtlsdrConfigVersion.cmake" 191 | VERSION ${VERSION} 192 | COMPATIBILITY AnyNewerVersion 193 | ) 194 | 195 | configure_file(cmake/rtlsdrConfig.cmake 196 | "${CMAKE_CURRENT_BINARY_DIR}/rtlsdr/rtlsdrConfig.cmake" 197 | COPYONLY 198 | ) 199 | 200 | set(ConfigPackageLocation lib/cmake/rtlsdr) 201 | install(EXPORT RTLSDR-export 202 | FILE rtlsdrTargets.cmake 203 | NAMESPACE rtlsdr:: 204 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rtlsdr/ 205 | ) 206 | install( 207 | FILES 208 | cmake/rtlsdrConfig.cmake 209 | "${CMAKE_CURRENT_BINARY_DIR}/rtlsdr/rtlsdrConfigVersion.cmake" 210 | DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/rtlsdr/ 211 | COMPONENT Devel 212 | ) 213 | 214 | ######################################################################## 215 | # Print Summary 216 | ######################################################################## 217 | MESSAGE(STATUS "Building for version: ${VERSION} / ${LIBVER}") 218 | MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}") 219 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | AUTOMAKE_OPTIONS = foreign dist-bzip2 1.6 2 | ACLOCAL_AMFLAGS = -I m4 3 | 4 | INCLUDES = $(all_includes) -I$(top_srcdir)/include 5 | SUBDIRS = include src 6 | 7 | pkgconfigdir = $(libdir)/pkgconfig 8 | pkgconfig_DATA = librtlsdr.pc 9 | 10 | BUILT_SOURCES = $(top_srcdir)/.version 11 | $(top_srcdir)/.version: 12 | echo $(VERSION) > $@-t && mv $@-t $@ 13 | dist-hook: 14 | echo $(VERSION) > $(distdir)/.tarball-version 15 | 16 | install-udev-rules: 17 | $(INSTALL_DATA) rtl-sdr.rules /etc/udev/rules.d 18 | 19 | uninstall-udev-rules: 20 | rm -rf /etc/udev/rules.d/rtl-sdr.rules 21 | 22 | EXTRA_DIST = git-version-gen .version 23 | 24 | if HAVE_DOXYGEN 25 | 26 | pkgdocdir=$(docdir)/$(PACKAGE)-$(VERSION) 27 | doc_htmldir=$(pkgdocdir)/html 28 | 29 | doc_html_DATA = $(top_builddir)/doc/html.tar 30 | 31 | $(doc_html_DATA): $(top_builddir)/doc/html/index.html 32 | cd $(top_builddir)/doc && tar cf html.tar html 33 | 34 | $(top_builddir)/doc/html/index.html: $(SOURCES) Doxyfile 35 | @rm -rf doc 36 | mkdir -p doc 37 | $(DOXYGEN) Doxyfile 38 | 39 | install-data-hook: 40 | cd $(DESTDIR)$(doc_htmldir) && tar xf html.tar --strip-components 1 && rm -f html.tar 41 | 42 | uninstall-hook: 43 | rm -rf $(DESTDIR)/$(doc_htmldir) 44 | 45 | DX_CLEAN = doc/{html,latex}/* doc/html.tar 46 | 47 | endif 48 | 49 | MOSTLYCLEANFILES = $(DX_CLEAN) 50 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | rtl-sdr 2 | turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | ====================================================================== 4 | 5 | For more information see: 6 | https://osmocom.org/projects/rtl-sdr/wiki 7 | 8 | ********************************************************************** 9 | 10 | ***************************** 11 | Modified RTL-SDR Blog Version 12 | ***************************** 13 | 14 | 25-August-2023: Brought up to date with latest Osmocom upstream, and added some new features like auto-direct sampling. Also made the force bias tee function stronger, so it cant be turned off when the bias tee is forced, even when calling the bias tee function. Remove the rtl_tcp ringbuffer changes as this seems to cause more trouble that it helps. 15 | 16 | 1) VCO PLL current fix - Improves stability at frequencies above ~1.5 GHz https://www.rtl-sdr.com/beta-testing-a-modified-rtl-sdr-driver-for-l-band-heat-issues/ 17 | 2) Enabled direct sampling for rtl_tcp 18 | 3) Hack to force the bias tee to always be on by setting the unused IR endpoint bit to 0 in the EEPROM. Example to force the BT to be always ON "rtl_eeprom -b 1", to remove forced BT "rtl_eeprom -b 0" 19 | 4) Repurposed "offset tuning" to toggle bias tee ON/OFF. We can now use the "offset tuning" button in SDR# and other programs to toggle the bias tee if there is no specific button in the GUI. 20 | 5) Support added for R828D RTL-SDR Blog V4 based dongles. 21 | 6) Auto direct sampling. For R820T/R860 dongles like the RTL-SDR Blog V3 the code will automatically change to direct sampling mode when the frequency is below 24 MHz. It will also automatically change back to normal sampling when the frequency is above 24 MHz. There is no need to manually change the sampling mode anymore for these dongles. 22 | 23 | BIAS TEE NOTE: Always take care that you do not enable the bias tee when the device is connected to a short circuited antenna unless there is an inline LNA. However. if you did by accident, don't worry as the circuit is dually protected with a self-resetting thermal fuse and built in protection on the LDO. Just try not to short it out for days at a time, otherwise you could eventually degrade the thermal fuse. 24 | 25 | Note that hack 3) will only work if your system is using this driver. If your system or software is using another driver fork, then the EEPROM information will not be read. So make sure you completely clean your system of the previous drivers first (with the information below) and ensure you run sudo make install after compiling. On Windows, make sure you are using this code's rtlsdr.dll file. 26 | 27 | ******************** 28 | Installation (Linux): 29 | ******************** 30 | 31 | ***NOTE*** 32 | If you previously installed librtlsdr-dev via the package manager you should remove this first BEFORE installing these drivers. To completely remove these drivers use the following commands 33 | 34 | sudo apt purge ^librtlsdr 35 | sudo rm -rvf /usr/lib/librtlsdr* /usr/include/rtl-sdr* /usr/local/lib/librtlsdr* /usr/local/include/rtl-sdr* /usr/local/include/rtl_* /usr/local/bin/rtl_* 36 | 37 | ***Now install the drivers*** 38 | 39 | sudo apt update 40 | sudo apt install libusb-1.0-0-dev git cmake pkg-config 41 | git clone https://github.com/rtlsdrblog/rtl-sdr-blog 42 | cd rtl-sdr-blog/ 43 | mkdir build 44 | cd build 45 | cmake ../ -DINSTALL_UDEV_RULES=ON 46 | make 47 | sudo make install 48 | sudo cp ../rtl-sdr.rules /etc/udev/rules.d/ 49 | sudo ldconfig 50 | echo 'blacklist dvb_usb_rtl28xxu' | sudo tee --append /etc/modprobe.d/blacklist-dvb_usb_rtl28xxu.conf 51 | 52 | *********************** 53 | Alternative Debian Package Installation Method: 54 | *********************** 55 | 56 | If you have a system reliant on the Debian packages (eg. FlightRadar24, FlightAware, ADSBExchange images) you can update them directly using this method: 57 | 58 | sudo apt update 59 | sudo apt install libusb-1.0-0-dev git cmake 60 | sudo apt install debhelper 61 | 62 | git clone https://github.com/rtlsdrblog/rtl-sdr-blog 63 | cd rtl-sdr-blog 64 | sudo dpkg-buildpackage -b --no-sign 65 | cd .. 66 | 67 | sudo dpkg -i librtlsdr0_*.deb 68 | sudo dpkg -i librtlsdr-dev_*.deb 69 | sudo dpkg -i rtl-sdr_*.deb 70 | 71 | ********************** 72 | Installation (MacOS): 73 | ********************** 74 | 75 | First make sure you have installed homebrew and xcode. Open a terminal and run: 76 | 77 | brew uninstall rtl-sdr 78 | brew install cmake 79 | brew install libusb 80 | brew install pkgconfig 81 | git clone https://github.com/rtlsdrblog/rtl-sdr-blog 82 | cd rtl-sdr-blog 83 | mkdir build 84 | cd build/ 85 | cmake ../ 86 | make LIBRARY_PATH=/usr/local/lib 87 | sudo make install 88 | 89 | *********************** 90 | Installation (Windows): 91 | *********************** 92 | 93 | Download the Release.zip file from the Releases page. For SDR# extract the rtlsdr.dll file from the x86 folder to the SDR#. For most other x64 programs, use the rtlsdr.dll file in the x64 folder. 94 | -------------------------------------------------------------------------------- /cmake/Modules/Version.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2013 OSMOCOM Project 2 | # 3 | # This file is part of rtl-sdr 4 | # 5 | # rtl-sdr is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3, or (at your option) 8 | # any later version. 9 | # 10 | # rtl-sdr is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with rtl-sdr; see the file COPYING. If not, write to 17 | # the Free Software Foundation, Inc., 51 Franklin Street, 18 | # Boston, MA 02110-1301, USA. 19 | 20 | if(DEFINED __INCLUDED_VERSION_CMAKE) 21 | return() 22 | endif() 23 | set(__INCLUDED_VERSION_CMAKE TRUE) 24 | 25 | # VERSION_INFO_* variables must be provided by user 26 | set(MAJOR_VERSION ${VERSION_INFO_MAJOR_VERSION}) 27 | set(MINOR_VERSION ${VERSION_INFO_MINOR_VERSION}) 28 | set(PATCH_VERSION ${VERSION_INFO_PATCH_VERSION}) 29 | 30 | ######################################################################## 31 | # Extract the version string from git describe. 32 | ######################################################################## 33 | find_package(Git QUIET) 34 | 35 | if(GIT_FOUND) 36 | message(STATUS "Extracting version information from git describe...") 37 | execute_process( 38 | COMMAND ${GIT_EXECUTABLE} describe --always --abbrev=4 --long 39 | OUTPUT_VARIABLE GIT_DESCRIBE OUTPUT_STRIP_TRAILING_WHITESPACE 40 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 41 | ) 42 | else() 43 | set(GIT_DESCRIBE "v${MAJOR_VERSION}.${MINOR_VERSION}.x-xxx-xunknown") 44 | endif() 45 | 46 | ######################################################################## 47 | # Use the logic below to set the version constants 48 | ######################################################################## 49 | if("${PATCH_VERSION}" STREQUAL "git") 50 | # VERSION: 3.6git-xxx-gxxxxxxxx 51 | # LIBVER: 3.6git 52 | set(VERSION "${GIT_DESCRIBE}") 53 | set(LIBVER "${MAJOR_VERSION}.${MINOR_VERSION}${PATCH_VERSION}") 54 | else() 55 | # This is a numbered release. 56 | # VERSION: 3.6.1 57 | # LIBVER: 3.6.1 58 | set(VERSION "${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}") 59 | set(LIBVER "${VERSION}") 60 | endif() 61 | -------------------------------------------------------------------------------- /cmake/cmake_uninstall.cmake.in: -------------------------------------------------------------------------------- 1 | # http://www.vtk.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F 2 | 3 | IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 4 | MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") 5 | ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") 6 | 7 | FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) 8 | STRING(REGEX REPLACE "\n" ";" files "${files}") 9 | FOREACH(file ${files}) 10 | MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") 11 | IF(EXISTS "$ENV{DESTDIR}${file}") 12 | EXEC_PROGRAM( 13 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 14 | OUTPUT_VARIABLE rm_out 15 | RETURN_VALUE rm_retval 16 | ) 17 | IF(NOT "${rm_retval}" STREQUAL 0) 18 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 19 | ENDIF(NOT "${rm_retval}" STREQUAL 0) 20 | ELSEIF(IS_SYMLINK "$ENV{DESTDIR}${file}") 21 | EXEC_PROGRAM( 22 | "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" 23 | OUTPUT_VARIABLE rm_out 24 | RETURN_VALUE rm_retval 25 | ) 26 | IF(NOT "${rm_retval}" STREQUAL 0) 27 | MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") 28 | ENDIF(NOT "${rm_retval}" STREQUAL 0) 29 | ELSE(EXISTS "$ENV{DESTDIR}${file}") 30 | MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") 31 | ENDIF(EXISTS "$ENV{DESTDIR}${file}") 32 | ENDFOREACH(file) 33 | -------------------------------------------------------------------------------- /cmake/rtlsdrConfig.cmake: -------------------------------------------------------------------------------- 1 | include(FindPkgConfig) 2 | pkg_check_modules(LIBUSB libusb-1.0 IMPORTED_TARGET) 3 | 4 | get_filename_component(RTLSDR_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 5 | 6 | if(NOT TARGET rtlsdr::rtlsdr) 7 | include("${RTLSDR_CMAKE_DIR}/rtlsdrTargets.cmake") 8 | endif() 9 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([librtlsdr], 2 | m4_esyscmd([./git-version-gen .tarball-version]), 3 | [osmocom-sdr@lists.osmocom.org]) 4 | 5 | AM_INIT_AUTOMAKE([dist-bzip2]) 6 | 7 | dnl kernel style compile messages 8 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 9 | 10 | dnl checks for programs 11 | AC_PROG_MAKE_SET 12 | AC_PROG_CC 13 | AC_PROG_INSTALL 14 | AM_PROG_CC_C_O 15 | LT_INIT 16 | AC_PROG_LIBTOOL 17 | 18 | PKG_CHECK_MODULES(LIBUSB, libusb-1.0 >= 1.0) 19 | LIBS="$LIBS $LIBUSB_LIBS" 20 | CFLAGS="$CFLAGS $LIBUSB_CFLAGS" 21 | 22 | AC_PATH_PROG(DOXYGEN,doxygen,false) 23 | AM_CONDITIONAL(HAVE_DOXYGEN, test $DOXYGEN != false) 24 | 25 | AC_CONFIG_MACRO_DIR([m4]) 26 | 27 | dnl checks for header files 28 | AC_HEADER_STDC 29 | AC_CHECK_HEADERS(sys/types.h) 30 | AC_CHECK_HEADERS(pthread.h,, [AC_MSG_ERROR([pthread.h required])]) 31 | 32 | # pc variables 33 | AC_SUBST(RTLSDR_PC_LIBS,["$LIBS"]) 34 | AC_SUBST(RTLSDR_PC_CFLAGS,["$CFLAGS"]) 35 | 36 | dnl checks for required libraries 37 | dnl pthreads 38 | AC_CHECK_LIB(pthread, pthread_create, [LIBS="$LIBS -lpthread"]) 39 | 40 | dnl libmath (for rtl_fm) 41 | AC_CHECK_LIB(m, atan2, [LIBS="$LIBS -lm"]) 42 | 43 | dnl libmath (for rtl_adsb) 44 | AC_CHECK_LIB(m, sqrt, [LIBS="$LIBS -lm"]) 45 | 46 | dnl libmath (for rtl_power) 47 | AC_CHECK_LIB(m, atan2, [LIBS="$LIBS -lm"]) 48 | 49 | dnl librealtime (for rtl_test) 50 | AC_CHECK_LIB(rt, clock_gettime, [LIBS="$LIBS -lrt"]) 51 | 52 | AC_ARG_ENABLE(sanitize, 53 | [AS_HELP_STRING([--enable-sanitize], [Compile with address sanitizer enabled], )], 54 | [sanitize=$enableval], [sanitize="no"]) 55 | if test x"$sanitize" = x"yes" 56 | then 57 | CFLAGS="$CFLAGS -fsanitize=address -fsanitize=undefined" 58 | CPPFLAGS="$CPPFLAGS -fsanitize=address -fsanitize=undefined" 59 | fi 60 | 61 | AC_ARG_ENABLE(werror, 62 | [AS_HELP_STRING( 63 | [--enable-werror], 64 | [Turn all compiler warnings into errors, with exceptions: 65 | a) deprecation (allow upstream to mark deprecation without breaking builds); 66 | b) "#warning" pragmas (allow to remind ourselves of errors without breaking builds) 67 | ] 68 | )], 69 | [werror=$enableval], [werror="no"]) 70 | if test x"$werror" = x"yes" 71 | then 72 | WERROR_FLAGS="-Werror" 73 | WERROR_FLAGS+=" -Wno-error=deprecated -Wno-error=deprecated-declarations" 74 | WERROR_FLAGS+=" -Wno-error=cpp" # "#warning" 75 | CFLAGS="$CFLAGS $WERROR_FLAGS" 76 | CPPFLAGS="$CPPFLAGS $WERROR_FLAGS" 77 | fi 78 | 79 | # The following test is taken from WebKit's webkit.m4 80 | saved_CFLAGS="$CFLAGS" 81 | CFLAGS="$CFLAGS -fvisibility=hidden " 82 | AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden]) 83 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])], 84 | [ AC_MSG_RESULT([yes]) 85 | SYMBOL_VISIBILITY="-fvisibility=hidden"], 86 | AC_MSG_RESULT([no])) 87 | CFLAGS="$saved_CFLAGS" 88 | AC_SUBST(SYMBOL_VISIBILITY) 89 | 90 | AC_MSG_CHECKING(whether compiler understands -Wall) 91 | old_CFLAGS="$CFLAGS" 92 | CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wno-unused -Wsign-compare -Wdeclaration-after-statement" 93 | AC_TRY_COMPILE([],[], 94 | AC_MSG_RESULT(yes), 95 | AC_MSG_RESULT(no) 96 | CFLAGS="$old_CFLAGS") 97 | 98 | AC_ARG_ENABLE(driver-detach, 99 | [ --enable-driver-detach Enable detaching of kernel driver (disabled by default)], 100 | [if test x$enableval = xyes; then 101 | CFLAGS="$CFLAGS -DDETACH_KERNEL_DRIVER" 102 | fi]) 103 | 104 | AC_ARG_ENABLE(zerocopy, 105 | [ --enable-zerocopy Enable usbfs zero-copy support (disabled by default)], 106 | [if test x$enableval = xyes; then 107 | CFLAGS="$CFLAGS -DENABLE_ZEROCOPY" 108 | fi]) 109 | 110 | dnl Generate the output 111 | AC_CONFIG_HEADER(config.h) 112 | 113 | AC_OUTPUT( 114 | librtlsdr.pc 115 | include/Makefile 116 | src/Makefile 117 | Makefile 118 | Doxyfile 119 | ) 120 | -------------------------------------------------------------------------------- /contrib/jenkins.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # jenkins build helper script for openbsc. This is how we build on jenkins.osmocom.org 3 | 4 | if ! [ -x "$(command -v osmo-build-dep.sh)" ]; then 5 | echo "Error: We need to have scripts/osmo-deps.sh from http://git.osmocom.org/osmo-ci/ in PATH !" 6 | exit 2 7 | fi 8 | 9 | 10 | set -ex 11 | 12 | base="$PWD" 13 | deps="$base/deps" 14 | inst="$deps/install" 15 | export deps inst 16 | 17 | osmo-clean-workspace.sh 18 | 19 | mkdir "$deps" || true 20 | 21 | set +x 22 | echo 23 | echo 24 | echo 25 | echo " =============================== rtl-sdr ===============================" 26 | echo 27 | set -x 28 | 29 | cd "$base" 30 | autoreconf --install --force 31 | ./configure --enable-sanitize --enable-werror 32 | $MAKE $PARALLEL_MAKE 33 | LD_LIBRARY_PATH="$inst/lib" $MAKE check \ 34 | || cat-testlogs.sh 35 | LD_LIBRARY_PATH="$inst/lib" \ 36 | DISTCHECK_CONFIGURE_FLAGS="--enable-werror" \ 37 | $MAKE distcheck \ 38 | || cat-testlogs.sh 39 | $MAKE maintainer-clean 40 | 41 | osmo-clean-workspace.sh 42 | -------------------------------------------------------------------------------- /debian/README.Debian: -------------------------------------------------------------------------------- 1 | rtl-sdr for Debian 2 | ------------------- 3 | 4 | In the beginning Antti Palosaari noticed that some digital video 5 | receiver tuners can be turned into a cheap software defined radio. 6 | 7 | Since there is also support in the Linux kernel to use these devices 8 | as digital video receivers, by default the hardware will be claimed 9 | by Linux keernel drivers for that purpose. 10 | 11 | Having these rtl-sdr packages installed likely means that these 12 | devices should be available for the alternate software defined 13 | radio use. 14 | 15 | The librtlsdr0 package in Debian has configuration files to 16 | help manage the conflicting uses: 17 | 18 | 1. Blacklists DVB-T kernel modules provided by the Linux kernel 19 | ------------------------------------------------------------------- 20 | 21 | Config file: 22 | /etc/modprobe.d/librtlsdr-blacklist.conf 23 | 24 | contains lines to blacklist dvb_usb_rtl28xxu, e4000 and rtl2832 25 | kernel modules. 26 | 27 | Should you wish to use a device via the Linux video receiver software 28 | while still having the librtlsdr0 package installed you may edit 29 | this file. (Placing a # at the beginning os a line makes it a comment.) 30 | 31 | Then unplug/plug the USB stick. 32 | 33 | Not that if rtl-sdr applications are then run, they will complain about 34 | failing to open the device. In that case, restore the blacklist and 35 | unplug/plug the USB stick. 36 | 37 | If librtlsdr-blacklist.conf does not exist, then rtl-sdr was built 38 | with the DETACH_KERNEL_DRIVER option. 39 | 40 | 2. Permissions 41 | -------------- 42 | 43 | Devices are available to users in the plugdev group. 44 | 45 | The librtlsdr0 package installs these default rules: 46 | /lib/udev/rules.d/60-librtlsdr0.rules 47 | 48 | If you have permissions issues, you may override these values 49 | with your own rules in /etc: 50 | 51 | /etc/udev/rules.d/60-librtlsdr0.rules 52 | 53 | After editing udev rules, run as root: 54 | udevadm control --reload-rules 55 | 56 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | rtl-sdr (0.7.0~rtlsdrblog1) unstable; urgency=medium 2 | 3 | 25-August-2023: Brought up to date with latest Osmocom upstream, and added some new features like auto-direct sampling. Also made the force bias tee function stronger, so it cant be turned off when the bias tee is forced, even when calling the bias tee function. Remove the rtl_tcp ringbuffer changes as this seems to cause more trouble that it helps. 4 | 1) VCO PLL current fix - Improves stability at frequencies above ~1.5 GHz https://www.rtl-sdr.com/beta-testing-a-modified-rtl-sdr-driver-for-l-band-heat-issues/ 5 | 2) Enabled direct sampling for rtl_tcp 6 | 3) Hack to force the bias tee to always be on by setting the unused IR endpoint bit to 0 in the EEPROM. Example to force the BT to be always ON "rtl_eeprom -b 1", to remove forced BT "rtl_eeprom -b 0" 7 | 4) Repurposed "offset tuning" to toggle bias tee ON/OFF. We can now use the "offset tuning" button in SDR# and other programs to toggle the bias tee if there is no specific button in the GUI. 8 | 5) Support added for R828D RTL-SDR Blog V4 based dongles. 9 | 6) Auto direct sampling. For R820T/R860 dongles like the RTL-SDR Blog V3 the code will automatically change to direct sampling mode when the frequency is below 24 MHz. It will also automatically change back to normal sampling when the frequency is above 24 MHz. There is no need to manually change the sampling mode anymore for these dongles. 10 | BIAS TEE NOTE: Always take care that you do not enable the bias tee when the device is connected to a short circuited antenna unless there is an inline LNA. However. if you did by accident, don't worry as the circuit is dually protected with a self-resetting thermal fuse and built in protection on the LDO. Just try not to short it out for days at a time, otherwise you could eventually degrade the thermal fuse. 11 | Note that hack 3) will only work if your system is using this driver. If your system or software is using another driver fork, then the EEPROM information will not be read. So make sure you completely clean your system of the previous drivers first (with the information below) and ensure you run sudo make install after compiling. On Windows, make sure you are using this code's rtlsdr.dll file. 12 | 13 | -- rtl-sdr-blog Wed, 13 Sep 2023 15:51:00 +1200 14 | 15 | rtl-sdr (0.6) unstable; urgency=medium 16 | 17 | * New upstream release 18 | * with modernize-cmake patch 19 | 20 | -- A. Maitland Bottoms Sat, 06 Oct 2018 20:28:26 -0400 21 | 22 | rtl-sdr (0.6~git) unstable; urgency=medium 23 | 24 | * New upstream release 25 | 26 | -- Harald Welte Sun, 06 Jun 2018 15:09:42 +0200 27 | 28 | rtl-sdr (0.5.4-1) unstable; urgency=medium 29 | 30 | * New upstream release 31 | * update to v0.5.4-3-ga854ae8 32 | use USB zero-copy transfers if possible 33 | 34 | -- A. Maitland Bottoms Sat, 12 May 2018 16:49:43 -0400 35 | 36 | rtl-sdr (0.5.3-14) unstable; urgency=medium 37 | 38 | * update to v0.5.3-20-g4520f00 (Closes: #892974) 39 | * minimal ipv6 support (Closes: #870804) 40 | * VCS to salsa 41 | * AppStream metadata.xml 42 | 43 | -- A. Maitland Bottoms Mon, 16 Apr 2018 20:45:53 -0400 44 | 45 | rtl-sdr (0.5.3-13) unstable; urgency=medium 46 | 47 | * build with libusb-1.0-0-dev stub on hurd-i386 48 | * initial ipv6 support for rtl_tcp... 49 | 50 | -- A. Maitland Bottoms Thu, 23 Nov 2017 15:59:40 -0500 51 | 52 | rtl-sdr (0.5.3-12) unstable; urgency=medium 53 | 54 | * add new HanfTek dongle 55 | * Bias T support (Closes: #854378, #842249) 56 | 57 | -- A. Maitland Bottoms Wed, 23 Aug 2017 23:31:27 -0400 58 | 59 | rtl-sdr (0.5.3-11) unstable; urgency=medium 60 | 61 | * correct invocation of rm_conffile (Thanks Chris!) (Closes: #838161) 62 | * drop uploaders line on advice of MIA team. (Closes: #836590) 63 | 64 | -- A. Maitland Bottoms Sat, 08 Oct 2016 11:17:47 -0400 65 | 66 | rtl-sdr (0.5.3-10) unstable; urgency=medium 67 | 68 | * remove rtl-sdr-blacklist.conf on upgrade. Thanks Bob! (Closes: #829517) 69 | 70 | -- A. Maitland Bottoms Sat, 09 Jul 2016 23:38:24 -0400 71 | 72 | rtl-sdr (0.5.3-9) unstable; urgency=medium 73 | 74 | * Edit of debian/librtlsdr0.udev in 0.5.3-8 was a no-op. Real fix 75 | done to debian/patches/use-udev-uaccess-rules. (Closes: #825073) 76 | 77 | -- A. Maitland Bottoms Wed, 25 May 2016 17:19:57 -0400 78 | 79 | rtl-sdr (0.5.3-8) unstable; urgency=high 80 | 81 | * Fix syntax errors for systemd-udevd in udev rules (Closes: #825073) 82 | 83 | -- A. Maitland Bottoms Tue, 24 May 2016 21:08:50 -0400 84 | 85 | rtl-sdr (0.5.3-7) unstable; urgency=medium 86 | 87 | * better udev rules (more like camera devices in libgphoto2-6) 88 | 89 | -- A. Maitland Bottoms Tue, 10 May 2016 19:20:27 -0400 90 | 91 | rtl-sdr (0.5.3-6) unstable; urgency=medium 92 | 93 | * Use ENV{ID_SOFTWARE_RADIO}=1 in udev rules (Closes: #823089) 94 | * Enable DETACH_KERNEL_DRIVER (Closes: 823022) 95 | * Make myself maintainer so I get the bug reports 96 | 97 | -- A. Maitland Bottoms Sun, 08 May 2016 12:12:13 -0400 98 | 99 | rtl-sdr (0.5.3-5) unstable; urgency=medium 100 | 101 | * Add watch fiule 102 | * place rtl-sdr -n comm section (Closes: #758077) 103 | * improve-librtlsdr-pc-file (Closes: #784912) 104 | * improve-scanning-range-parsing (LP: #1469478) 105 | 106 | -- A. Maitland Bottoms Sun, 23 Aug 2015 10:35:42 -0400 107 | 108 | rtl-sdr (0.5.3-4) unstable; urgency=low 109 | 110 | * Update to v0.5.3-12-ge3c03f7 111 | 112 | -- A. Maitland Bottoms Sat, 08 Aug 2015 23:43:54 -0400 113 | 114 | rtl-sdr (0.5.3-3) unstable; urgency=low 115 | 116 | * Update to v0.5.3-5-g6ee5573 117 | lib: handle events after canceling transfers 118 | lib: change default number of transfers to 15 119 | rtl_tcp: make all global variables static 120 | 121 | -- A. Maitland Bottoms Sun, 13 Apr 2014 10:48:49 -0400 122 | 123 | rtl-sdr (0.5.3-2) unstable; urgency=low 124 | 125 | * Upstream: lib: only print to stderr in tuner_r82xx_set_pll() 126 | * Update man pages (New -M (modulation) and -E (option) and ppm setting) 127 | * Have librtlsdr0 also install a blacklist for linux video drivers 128 | 129 | -- A. Maitland Bottoms Sat, 08 Feb 2014 22:40:06 -0500 130 | 131 | rtl-sdr (0.5.3-1) unstable; urgency=low 132 | 133 | * New upstream git tag release 134 | 135 | -- A. Maitland Bottoms Thu, 06 Feb 2014 20:45:38 -0500 136 | 137 | rtl-sdr (0.5.2.7.3ab6-1~bpo70+1) wheezy-backports; urgency=low 138 | 139 | * Rebuild for wheezy-backports. 140 | 141 | -- A. Maitland Bottoms Tue, 21 Jan 2014 19:34:16 -0500 142 | 143 | rtl-sdr (0.5.2.7.3ab6-1) unstable; urgency=low 144 | 145 | * New upstream snapshot 146 | 147 | -- A. Maitland Bottoms Sun, 29 Dec 2013 21:37:19 -0500 148 | 149 | rtl-sdr (0.5.1.14.360d-1~wheezy) stable; urgency=low 150 | 151 | * New upstream snapshot 152 | * GNU Radio LiveDVD 2013-1110 153 | 154 | -- A. Maitland Bottoms Mon, 11 Nov 2013 12:46:00 -0500 155 | 156 | rtl-sdr (0.5.0.4.4914-2) unstable; urgency=low 157 | 158 | * Use kfreebsd libusb 159 | 160 | -- A. Maitland Bottoms Fri, 01 Nov 2013 17:16:42 -0400 161 | 162 | rtl-sdr (0.5.0.4.4914-1) stable; urgency=low 163 | 164 | * New upstream snapshot (Closes: #701018). 165 | * Match GNU Radio live distribution version 166 | * Sponsored upload 167 | 168 | -- A. Maitland Bottoms Sat, 28 Sep 2013 16:55:08 -0400 169 | 170 | rtl-sdr (0.5.0+git20130715-1) unstable; urgency=low 171 | 172 | * Initial release (Closes: #701018). 173 | 174 | -- Adam Cécile (Le_Vert) Mon, 15 Jul 2013 15:51:05 +0200 175 | 176 | librtlsdr (0.0git3198f14-1) unstable; urgency=low 177 | 178 | * New upstream git 179 | 180 | -- A. Maitland Bottoms Mon, 14 May 2012 20:28:18 -0400 181 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: rtl-sdr 2 | Section: comm 3 | Priority: optional 4 | Maintainer: A. Maitland Bottoms 5 | Build-Depends: cmake, 6 | debhelper (>= 10~), 7 | libusb-1.0-0-dev [linux-any], 8 | libusb-dev [hurd-i386], 9 | libusb2-dev [kfreebsd-any], 10 | pkg-config 11 | Standards-Version: 4.1.4 12 | Homepage: http://sdr.osmocom.org/trac/wiki/rtl-sdr 13 | Vcs-Browser: https://salsa.debian.org/bottoms/pkg-rtl-sdr 14 | Vcs-Git: https://salsa.debian.org/bottoms/pkg-rtl-sdr.git 15 | 16 | Package: librtlsdr-dev 17 | Section: libdevel 18 | Architecture: any 19 | Pre-Depends: ${misc:Pre-Depends} 20 | Depends: librtlsdr0 (= ${binary:Version}), 21 | libusb-1.0-0-dev [!kfreebsd-any], 22 | libusb2-dev [kfreebsd-any], 23 | ${misc:Depends} 24 | Description: Software defined radio receiver for Realtek RTL2832U (development) 25 | rtl-sdr is a software defined radio (SDR) receiver software for certain 26 | low-cost DVB-T/DAB(+) USB dongles based on the Realtek RTL2832U chip. 27 | . 28 | This package contains development files. 29 | 30 | Package: librtlsdr0 31 | Section: libs 32 | Architecture: any 33 | Pre-Depends: ${misc:Pre-Depends} 34 | Depends: ${misc:Depends}, ${shlibs:Depends} 35 | Multi-Arch: same 36 | Description: Software defined radio receiver for Realtek RTL2832U (library) 37 | rtl-sdr is a software defined radio (SDR) receiver software for certain 38 | low-cost DVB-T/DAB(+) USB dongles based on the Realtek RTL2832U chip. 39 | . 40 | This package contains the shared library. 41 | 42 | Package: rtl-sdr 43 | Architecture: any 44 | Depends: librtlsdr0 (= ${binary:Version}), ${misc:Depends}, ${shlibs:Depends} 45 | Description: Software defined radio receiver for Realtek RTL2832U (tools) 46 | rtl-sdr is a software defined radio (SDR) receiver software for certain 47 | low-cost DVB-T/DAB(+) USB dongles based on the Realtek RTL2832U chip. 48 | . 49 | This package contains a set of command line utilities: 50 | * rtl_adsb: a simple ADS-B decoder for RTL2832 based DVB-T receivers 51 | * rtl_eeprom: an EEPROM programming tool for RTL2832 based DVB-T receivers 52 | * rtl_fm: a narrow band FM demodulator for RTL2832 based DVB-T receivers 53 | * rtl_sdr: an I/Q recorder for RTL2832 based DVB-T receivers 54 | * rtl_tcp: an I/Q spectrum server for RTL2832 based DVB-T receivers 55 | * rtl_test: a benchmark tool for RTL2832 based DVB-T receivers 56 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 2 | Upstream-Name: rtl-sdr 3 | Upstream-Contact: http://sdr.osmocom.org/trac/wiki/rtl-sdr 4 | Source: 5 | git clone git://git.osmocom.org/rtl-sdr.git 6 | The upstream package source tarball was generated from the tag: 7 | git archive --format=tar --prefix=rtl-sdr-0.5.2.7.3ab6/ 3ab6ff | gzip > ../rtl-sdr_0.5.2.7.3ab6.orig.tar.gz 8 | Comment: 9 | Debian packages sponsored by A. Maitland Bottoms, 10 | based upon packaging work by Adam Cécile. 11 | . 12 | Upstream Authors: 13 | Steve Markgraf 14 | Dimitri Stolnikov 15 | Hoernchen 16 | Kyle Keen 17 | Copyright: 2012,2013 OSMOCOM Project 18 | License: GPL-2.0+ 19 | 20 | Files: * 21 | Copyright: 2012, 2013, OSMOCOM Project 22 | License: GPL-3+ 23 | 24 | Files: debian/* 25 | Copyright: 2013 Adam Cécile (Le_Vert) 26 | 2012,2013 A. Maitland Bottoms 27 | License: GPL-2.0+ 28 | 29 | Files: debian/librtlsdr0.udev 30 | Copyright: 2012, 2013, Osmocom rtl-sdr project 31 | License: GPL-3+ 32 | 33 | Files: debian/rtl_adsb.1 34 | Copyright: Copyright (c) 2013, A. Maitland Bottoms 35 | License: GPL-2.0+ 36 | 37 | Files: debian/rtl_eeprom.1 38 | debian/rtl_test.1 39 | Copyright: Copyright (c) 2013, A. Maitland Bottoms 40 | License: GPL-2+ 41 | 42 | Files: git-version-gen 43 | Copyright: 2007-2010, Free Software Foundation, Inc. 44 | License: GPL-3+ 45 | 46 | Files: include/* 47 | Copyright: 2012, Steve Markgraf 48 | 2012, Hans-Frieder Vogt 49 | License: GPL-2+ 50 | 51 | Files: include/CMakeLists.txt 52 | Copyright: 2012, 2013, OSMOCOM Project 53 | License: GPL-3+ 54 | 55 | Files: include/rtl-sdr.h 56 | Copyright: 2012, Dimitri Stolnikov 57 | 2012, 2013, Steve Markgraf 58 | License: GPL-2+ 59 | 60 | Files: include/rtl-sdr_export.h 61 | Copyright: 2012, Hoernchen 62 | License: GPL-2+ 63 | 64 | Files: include/tuner_e4k.h 65 | Copyright: 2012, Sylvain Munaut 66 | 2012, Hoernchen 67 | 2011, 2012, Harald Welte 68 | License: GPL-2+ 69 | 70 | Files: include/tuner_fc2580.h 71 | Copyright: Steve Markgraf 72 | License: GPL-2.0+ 73 | 74 | Files: include/tuner_r82xx.h 75 | Copyright: 2013, Steve Markgraf 76 | 2013, Mauro Carvalho Chehab 77 | License: GPL-2+ 78 | 79 | Files: rtl-sdr.rules 80 | Copyright: 2012, 2013, Osmocom rtl-sdr project 81 | License: GPL-3+ 82 | 83 | Files: src/* 84 | Copyright: 2012, Steve Markgraf 85 | License: GPL-2+ 86 | 87 | Files: src/CMakeLists.txt 88 | Copyright: 2012, 2013, OSMOCOM Project 89 | License: GPL-3+ 90 | 91 | Files: src/Makefile.am 92 | Copyright: 2012 Steve Markgraf 93 | 2012 Dimitri Stolnikov 94 | License: GPL-2.0+ 95 | 96 | Files: src/convenience/* 97 | Copyright: 2014, Kyle Keen 98 | License: GPL-2+ 99 | 100 | Files: src/getopt/* 101 | Copyright: 88-96, 98, 99, 1987, 2000, 2001 102 | License: LGPL-2.1+ 103 | 104 | Files: src/getopt/getopt.h 105 | Copyright: 1989-1994, 1996-1999, 2001, Free Software Foundation, Inc. 106 | License: LGPL-2.1+ 107 | 108 | Files: src/librtlsdr.c 109 | Copyright: 2012-2014, Steve Markgraf 110 | 2012, Dimitri Stolnikov 111 | License: GPL-2+ 112 | 113 | Files: src/rtl_adsb.c 114 | Copyright: 2012, Youssef Touil 115 | 2012, Steve Markgraf 116 | 2012, Kyle Keen 117 | 2012, Ian Gilmour 118 | 2012, Hoernchen 119 | License: GPL-2+ 120 | 121 | Files: src/rtl_fm.c 122 | Copyright: 2013, Elias Oenal 123 | 2012, Steve Markgraf 124 | 2012, Kyle Keen 125 | 2012, Hoernchen 126 | License: GPL-2+ 127 | 128 | Files: src/rtl_power.c 129 | Copyright: 2012, Steve Markgraf 130 | 2012, Kyle Keen 131 | 2012, Hoernchen 132 | License: GPL-2+ 133 | 134 | Files: src/rtl_tcp.c 135 | Copyright: 2012, Steve Markgraf 136 | 2012, 2013, Hoernchen 137 | License: GPL-2+ 138 | 139 | Files: src/rtl_test.c 140 | Copyright: 2014, Michael Tatarinov 141 | 2012-2014, Steve Markgraf 142 | 2012-2014, Kyle Keen 143 | License: GPL-2+ 144 | 145 | Files: src/tuner_e4k.c 146 | Copyright: 2012, Sylvain Munaut 147 | 2012, Hoernchen 148 | 2011, 2012, Harald Welte 149 | License: GPL-2+ 150 | 151 | Files: src/tuner_fc0012.c 152 | Copyright: 2012, Steve Markgraf 153 | 2012, Hans-Frieder Vogt 154 | License: GPL-2+ 155 | 156 | Files: src/tuner_fc0013.c 157 | Copyright: 2012, Steve Markgraf 158 | 2012, Hans-Frieder Vogt 159 | 2010, Fitipower Integrated Technology Inc 160 | License: GPL-2+ 161 | 162 | Files: src/tuner_fc2580.c 163 | Copyright: Steve Markgraf 164 | Dimitri Stolnikov 165 | License: GPL-2.0+ 166 | 167 | Files: src/tuner_r82xx.c 168 | Copyright: 2013, Steve Markgraf 169 | 2013, Mauro Carvalho Chehab 170 | License: GPL-2+ 171 | 172 | License: GPL-2+ 173 | This program is free software; you can redistribute it and/or modify 174 | it under the terms of the GNU General Public License as published by 175 | the Free Software Foundation; version 2 dated June, 1991, or (at 176 | your option) any later version. 177 | . 178 | On Debian systems, the complete text of version 2 of the GNU General 179 | Public License can be found in '/usr/share/common-licenses/GPL-2'. 180 | 181 | License: GPL-2.0+ 182 | This package is free software; you can redistribute it and/or modify 183 | it under the terms of the GNU General Public License as published by 184 | the Free Software Foundation; either version 2 of the License, or 185 | (at your option) any later version. 186 | . 187 | This package is distributed in the hope that it will be useful, 188 | but WITHOUT ANY WARRANTY; without even the implied warranty of 189 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 190 | GNU General Public License for more details. 191 | . 192 | You should have received a copy of the GNU General Public License 193 | along with this program. If not, see 194 | . 195 | On Debian systems, the complete text of the GNU General 196 | Public License version 2 can be found in "/usr/share/common-licenses/GPL-2". 197 | 198 | License: GPL-3+ 199 | This program is free software: you can redistribute it and/or modify 200 | it under the terms of the GNU General Public License as published by 201 | the Free Software Foundation, either version 3 of the License, or 202 | (at your option) any later version. 203 | . 204 | This program is distributed in the hope that it will be useful, 205 | but WITHOUT ANY WARRANTY; without even the implied warranty of 206 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 207 | GNU General Public License for more details. 208 | . 209 | You should have received a copy of the GNU General Public License 210 | along with this program. If not, see . 211 | . 212 | On Debian systems, the complete text of the GNU Lesser General 213 | Public License can be found in "/usr/share/common-licenses/GPL-3". 214 | 215 | License: LGPL-2.1+ 216 | This package is free software; you can redistribute it and/or 217 | modify it under the terms of the GNU Lesser General Public 218 | License as published by the Free Software Foundation; either 219 | version 2.1 of the License, or (at your option) any later version. 220 | . 221 | This package is distributed in the hope that it will be useful, 222 | but WITHOUT ANY WARRANTY; without even the implied warranty of 223 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 224 | Lesser General Public License for more details. 225 | . 226 | You should have received a copy of the GNU General Public License 227 | along with this program. If not, see . 228 | . 229 | On Debian systems, the complete text of the GNU Lesser General 230 | Public License can be found in "/usr/share/common-licenses/LGPL-2". 231 | -------------------------------------------------------------------------------- /debian/copyright-scan-patterns.yml: -------------------------------------------------------------------------------- 1 | ignore : 2 | suffixes : 3 | - in 4 | -------------------------------------------------------------------------------- /debian/heatmap.py: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python2 2 | 3 | from PIL import Image, ImageDraw, ImageFont 4 | import sys, gzip, math, colorsys, datetime 5 | from collections import defaultdict 6 | from itertools import * 7 | 8 | # todo: matplotlib powered --interactive 9 | # arbitrary freq marker spacing 10 | 11 | path = sys.argv[1] 12 | output = sys.argv[2] 13 | 14 | raw_data = lambda: open(path) 15 | if path.endswith('.gz'): 16 | raw_data = lambda: gzip.open(path, 'rb') 17 | 18 | def frange(start, stop, step): 19 | i = 0 20 | while (i*step + start <= stop): 21 | yield i*step + start 22 | i += 1 23 | 24 | print("loading") 25 | 26 | freqs = set() 27 | f_cache = set() 28 | times = set() 29 | labels = set() 30 | min_z = 0 31 | max_z = -100 32 | start, stop = None, None 33 | for line in raw_data(): 34 | line = [s.strip() for s in line.strip().split(',')] 35 | line = [line[0], line[1]] + [float(s) for s in line[2:] if s] 36 | 37 | low = line[2] 38 | high = line[3] 39 | step = line[4] 40 | f_key = (int(low), int(high), step) 41 | if f_key not in f_cache: 42 | freqs.update(list(frange(int(low), int(high), step))) 43 | freqs.add(high) 44 | labels.add(low) 45 | f_cache.add(f_key) 46 | 47 | t = line[0] + ' ' + line[1] 48 | times.add(t) 49 | 50 | zs = line[6:] 51 | min_z = min(min_z, min(z for z in zs if not math.isinf(z))) 52 | max_z = max(max_z, max(zs)) 53 | 54 | if start is None: 55 | start = datetime.datetime.strptime(line[0] + ' ' + line[1], '%Y-%m-%d %H:%M:%S') 56 | stop = datetime.datetime.strptime(line[0] + ' ' + line[1], '%Y-%m-%d %H:%M:%S') 57 | 58 | freqs = list(sorted(list(freqs))) 59 | times = list(sorted(list(times))) 60 | labels = list(sorted(list(labels))) 61 | 62 | if len(labels) == 1: 63 | delta = (max(freqs) - min(freqs)) / (len(freqs) / 500) 64 | delta = round(delta / 10**int(math.log10(delta))) * 10**int(math.log10(delta)) 65 | delta = int(delta) 66 | lower = int(math.ceil(min(freqs) / delta) * delta) 67 | labels = list(range(lower, int(max(freqs)), delta)) 68 | 69 | print("x: %i, y: %i, z: (%f, %f)" % (len(freqs), len(times), min_z, max_z)) 70 | 71 | def rgb2(z): 72 | g = (z - min_z) / (max_z - min_z) 73 | return (int(g*255), int(g*255), 50) 74 | 75 | def rgb3(z): 76 | g = (z - min_z) / (max_z - min_z) 77 | c = colorsys.hsv_to_rgb(0.65-(g-0.08), 1, 0.2+g) 78 | return (int(c[0]*256),int(c[1]*256),int(c[2]*256)) 79 | 80 | print("drawing") 81 | img = Image.new("RGB", (len(freqs), len(times))) 82 | pix = img.load() 83 | x_size = img.size[0] 84 | for line in raw_data(): 85 | line = [s.strip() for s in line.strip().split(',')] 86 | line = [line[0], line[1]] + [float(s) for s in line[2:] if s] 87 | t = line[0] + ' ' + line[1] 88 | if t not in times: 89 | continue # happens with live files 90 | y = times.index(t) 91 | low = line[2] 92 | high = line[3] 93 | step = line[4] 94 | x_start = freqs.index(low) 95 | for i in range(len(line[6:])): 96 | x = x_start + i 97 | if x >= x_size: 98 | continue 99 | z = line[6+i] 100 | # fast check for nan/-inf 101 | if not z >= min_z: 102 | z = min_z 103 | pix[x,y] = rgb2(z) 104 | 105 | print("labeling") 106 | draw = ImageDraw.Draw(img) 107 | font = ImageFont.load_default() 108 | pixel_width = step 109 | for label in labels: 110 | y = 10 111 | #x = freqs.index(label) 112 | x = int((label-min(freqs)) / pixel_width) 113 | s = '%.3fMHz' % (label/1000000.0) 114 | draw.text((x, y), s, font=font, fill='white') 115 | 116 | duration = stop - start 117 | duration = duration.seconds 118 | pixel_height = duration / len(times) 119 | hours = int(duration / 3600) 120 | minutes = int((duration - 3600*hours) / 60) 121 | draw.text((2, img.size[1] - 45), 'Duration: %i:%02i' % (hours, minutes), font=font, fill='white') 122 | draw.text((2, img.size[1] - 35), 'Range: %.2fMHz - %.2fMHz' % (min(freqs)/1e6, max(freqs)/1e6), font=font, fill='white') 123 | draw.text((2, img.size[1] - 25), 'Pixel: %.2fHz x %is' % (pixel_width, int(round(pixel_height))), font=font, fill='white') 124 | draw.text((2, img.size[1] - 15), 'Started: {0}'.format(start), font=font, fill='white') 125 | # bin size 126 | 127 | print("saving") 128 | img.save(output) 129 | 130 | 131 | 132 | 133 | 134 | 135 | -------------------------------------------------------------------------------- /debian/librtlsdr-dev.acc: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -fPIC 6 | -g 7 | -O2 8 | -fstack-protector-strong 9 | -Wformat 10 | -Werror=format-security 11 | -Wdate-time 12 | -D_FORTIFY_SOURCE=2 13 | -fvisibility=hidden 14 | -Wsign-compare 15 | -Wall 16 | -Wno-uninitialized 17 | 18 | 19 | 20 | debian/librtlsdr-dev/usr/include/ 21 | 22 | 23 | 24 | debian/librtlsdr0/usr/lib/ 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /debian/librtlsdr-dev.dirs: -------------------------------------------------------------------------------- 1 | usr/lib 2 | usr/include 3 | -------------------------------------------------------------------------------- /debian/librtlsdr-dev.install: -------------------------------------------------------------------------------- 1 | usr/include/* 2 | usr/lib/*/lib*.a 3 | usr/lib/*/lib*.so 4 | usr/lib/*/pkgconfig/* 5 | usr/lib/*/cmake/* 6 | -------------------------------------------------------------------------------- /debian/librtlsdr0.dirs: -------------------------------------------------------------------------------- 1 | etc/modprobe.d 2 | usr/lib 3 | -------------------------------------------------------------------------------- /debian/librtlsdr0.install: -------------------------------------------------------------------------------- 1 | usr/lib/*/lib*.so.* 2 | debian/librtlsdr0.metainfo.xml usr/share/metainfo 3 | -------------------------------------------------------------------------------- /debian/librtlsdr0.maintscript: -------------------------------------------------------------------------------- 1 | rm_conffile /etc/modprobe.d/rtl-sdr-blacklist.conf 0.5.3-10~ 2 | -------------------------------------------------------------------------------- /debian/librtlsdr0.metainfo.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | librtlsdr0 4 | GPL-2+ 5 | librtlsdr0 6 | Control of rtl-sdr radio receiver 7 | 8 |

9 | rtl-sdr is a software defined radio (SDR) receiver software for certain 10 | low-cost DVB-T/DAB(+) USB dongles based on the Realtek RTL2832U chip. 11 |

12 |
13 | 14 | usb:v0BDAp2832d* 15 | usb:v0BDAp2838d* 16 | usb:v0413p6680d* 17 | usb:v0413p6F0Fd* 18 | usb:v0458p707Fd* 19 | usb:v0CCDp00A9d* 20 | usb:v0CCDp00B3d* 21 | usb:v0CCDp00B4d* 22 | usb:v0CCDp00B5d* 23 | usb:v0CCDp00B7d* 24 | usb:v0CCDp00B8d* 25 | usb:v0CCDp00B9d* 26 | usb:v0CCDp00C0d* 27 | usb:v0CCDp00C6d* 28 | usb:v0CCDp00D3d* 29 | usb:v0CCDp00D7d* 30 | usb:v0CCDp00E0d* 31 | usb:v1554p5020d* 32 | usb:v15F4p0131d* 33 | usb:v15F4p0133d* 34 | usb:v185Bp0620d* 35 | usb:v185Bp0650d* 36 | usb:v185Bp0680d* 37 | usb:v1B80pD393d* 38 | usb:v1B80pD394d* 39 | usb:v1B80pD395d* 40 | usb:v1B80pD397d* 41 | usb:v1B80pD398d* 42 | usb:v1B80pD39Dd* 43 | usb:v1B80pD3A4d* 44 | usb:v1B80pD3A8d* 45 | usb:v1B80pD3AFd* 46 | usb:v1B80pD3B0d* 47 | usb:v1D19p1101d* 48 | usb:v1D19p1102d* 49 | usb:v1D19p1103d* 50 | usb:v1D19p1104d* 51 | usb:v1F4DpA803d* 52 | usb:v1F4DpB803d* 53 | usb:v1F4DpC803d* 54 | usb:v1F4DpD286d* 55 | usb:v1F4DpD803d* 56 | 57 |
58 | -------------------------------------------------------------------------------- /debian/librtlsdr0.udev: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2012-2013 Osmocom rtl-sdr project 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # MODE="0664", GROUP="plugdev" 17 | 18 | # original RTL2832U vid/pid (hama nano, for example) 19 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2832", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 20 | 21 | # RTL2832U OEM vid/pid, e.g. ezcap EzTV668 (E4000), Newsky TV28T (E4000/R820T) etc. 22 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 23 | 24 | # DigitalNow Quad DVB-T PCI-E card (4x FC0012?) 25 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6680", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 26 | 27 | # Leadtek WinFast DTV Dongle mini D (FC0012) 28 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6f0f", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 29 | 30 | # Genius TVGo DVB-T03 USB dongle (Ver. B) 31 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0458", ATTRS{idProduct}=="707f", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 32 | 33 | # Terratec Cinergy T Stick Black (rev 1) (FC0012) 34 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00a9", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 35 | 36 | # Terratec NOXON rev 1 (FC0013) 37 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b3", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 38 | 39 | # Terratec Deutschlandradio DAB Stick (FC0013) 40 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b4", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 41 | 42 | # Terratec NOXON DAB Stick - Radio Energy (FC0013) 43 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b5", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 44 | 45 | # Terratec Media Broadcast DAB Stick (FC0013) 46 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b7", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 47 | 48 | # Terratec BR DAB Stick (FC0013) 49 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b8", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 50 | 51 | # Terratec WDR DAB Stick (FC0013) 52 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b9", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 53 | 54 | # Terratec MuellerVerlag DAB Stick (FC0013) 55 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00c0", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 56 | 57 | # Terratec Fraunhofer DAB Stick (FC0013) 58 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00c6", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 59 | 60 | # Terratec Cinergy T Stick RC (Rev.3) (E4000) 61 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00d3", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 62 | 63 | # Terratec T Stick PLUS (E4000) 64 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00d7", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 65 | 66 | # Terratec NOXON rev 2 (E4000) 67 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00e0", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 68 | 69 | # PixelView PV-DT235U(RN) (FC0012) 70 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1554", ATTRS{idProduct}=="5020", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 71 | 72 | # Astrometa DVB-T/DVB-T2 (R828D) 73 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="15f4", ATTRS{idProduct}=="0131", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 74 | 75 | # Compro Videomate U620F (E4000) 76 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0620", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 77 | 78 | # Compro Videomate U650F (E4000) 79 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0650", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 80 | 81 | # Compro Videomate U680F (E4000) 82 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0680", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 83 | 84 | # GIGABYTE GT-U7300 (FC0012) 85 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d393", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 86 | 87 | # DIKOM USB-DVBT HD 88 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d394", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 89 | 90 | # Peak 102569AGPK (FC0012) 91 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d395", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 92 | 93 | # KWorld KW-UB450-T USB DVB-T Pico TV (TUA9001) 94 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d397", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 95 | 96 | # Zaapa ZT-MINDVBZP (FC0012) 97 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d398", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 98 | 99 | # SVEON STV20 DVB-T USB & FM (FC0012) 100 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d39d", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 101 | 102 | # Twintech UT-40 (FC0013) 103 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3a4", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 104 | 105 | # ASUS U3100MINI_PLUS_V2 (FC0013) 106 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3a8", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 107 | 108 | # SVEON STV27 DVB-T USB & FM (FC0013) 109 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3af", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 110 | 111 | # SVEON STV21 DVB-T USB & FM 112 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3b0", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 113 | 114 | # Dexatek DK DVB-T Dongle (Logilink VG0002A) (FC2580) 115 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1101", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 116 | 117 | # Dexatek DK DVB-T Dongle (MSI DigiVox mini II V3.0) 118 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1102", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 119 | 120 | # Dexatek DK 5217 DVB-T Dongle (FC2580) 121 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1103", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 122 | 123 | # MSI DigiVox Micro HD (FC2580) 124 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1104", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 125 | 126 | # Sweex DVB-T USB (FC0012) 127 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="a803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 128 | 129 | # GTek T803 (FC0012) 130 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="b803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 131 | 132 | # Lifeview LV5TDeluxe (FC0012) 133 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="c803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 134 | 135 | # MyGica TD312 (FC0012) 136 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="d286", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 137 | 138 | # PROlectrix DV107669 (FC0012) 139 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="d803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 140 | -------------------------------------------------------------------------------- /debian/rtl-sdr-blacklist.conf: -------------------------------------------------------------------------------- 1 | # This system has librtlsdr0 installed in order to 2 | # use digital video broadcast receivers as generic 3 | # software defined radios. 4 | blacklist dvb_usb_rtl28xxu 5 | blacklist e4000 6 | blacklist rtl2832 7 | -------------------------------------------------------------------------------- /debian/rtl-sdr.dirs: -------------------------------------------------------------------------------- 1 | usr/bin 2 | -------------------------------------------------------------------------------- /debian/rtl-sdr.examples: -------------------------------------------------------------------------------- 1 | debian/heatmap.py 2 | -------------------------------------------------------------------------------- /debian/rtl-sdr.install: -------------------------------------------------------------------------------- 1 | usr/bin/* 2 | -------------------------------------------------------------------------------- /debian/rtl-sdr.manpages: -------------------------------------------------------------------------------- 1 | debian/rtl_adsb.1 2 | debian/rtl_eeprom.1 3 | debian/rtl_fm.1 4 | debian/rtl_power.1 5 | debian/rtl_sdr.1 6 | debian/rtl_tcp.1 7 | debian/rtl_test.1 8 | -------------------------------------------------------------------------------- /debian/rtl_adsb.1: -------------------------------------------------------------------------------- 1 | .TH "rtl_adsb" 1 "0.5.0" RTL-SDR "User Commands" 2 | .SH NAME 3 | rtl_adsb \- a simple ADS-B decoder 4 | .SH DESCRIPTION 5 | Uses a re-purposed DVB-T receiver as a software defined 6 | radio to receive and decode ADS-B data. Written by Kyle Keen 7 | and incorporated in the osmocom rtl-sdr project. 8 | .LP 9 | Automatic dependent surveillance-broadcast, ADS-B, consists 10 | of position and other status data transmitted by aircraft 11 | in support of air traffic control in order to improve safety 12 | of flight. 13 | .LP 14 | Much software is available for the RTL2832. Most of the user-level 15 | packages rely on the librtlsdr library which comes as part of the 16 | rtl-sdr codebase. This codebase contains both the library itself and 17 | also a number of command line tools such as rtl_test, rtl_sdr, 18 | rtl_tcp, and rtl_fm. These command line tools use the library to test 19 | for the existence of RTL2832 devices and to perform basic data 20 | transfer functions to and from the device. 21 | .LP 22 | Because most of the RTL2832 devices are connected using USB, the 23 | librtlsdr library depends on the libusb library to communicate with 24 | the device. 25 | .SH USAGE 26 | With a suitable antenna for receiving the 1090 MHz signal attached 27 | to the rtl-sdr supported device, this program will output the 28 | data decoded from that signal. 29 | .SH SYNOPSIS 30 | .B rtl_adsb [-R] [-g gain] [-p ppm] [output file] 31 | .SH OPTIONS 32 | .IP "-d device_index (default: 0)" 33 | .IP "-V verbove output (default: off)" 34 | .IP "-S show short frames (default: off)" 35 | .IP "-Q quality (0: no sanity checks, 0.5: half bit, 1: one bit (default), 2: two bits)" 36 | .IP "-e allowed_errors (default: 5)" 37 | .IP "-g tuner_gain (default: automatic)" 38 | .IP "-p ppm_error (default: 0)" 39 | .IP tfilename 40 | (a '-' dumps samples to stdout) 41 | (omitting the filename also uses stdout) 42 | .SH EXAMPLES 43 | .IP "Streaming with netcat:" 44 | rtl_adsb | netcat -lp 8080 45 | 46 | while true; do rtl_adsb | nc -lp 8080; done 47 | .IP "Streaming with socat:" 48 | rtl_adsb | socat -u - TCP4:sdrsharp.com:47806 49 | .SH SEE ALSO 50 | RTL-SDR wiki documentation: 51 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 52 | .LP 53 | Other rtl-sdr programs: 54 | .sp 55 | rtl_eeprom(1), rtl_fm(1), rtl_sdr(1), rtl_tcp(1), rtl_test(1) 56 | .SH AUTHOR 57 | This manual page was written by Maitland Bottoms 58 | for the Debian project (but may be used by others). 59 | .SH COPYRIGHT 60 | Copyright (c) 2013 A. Maitland Bottoms 61 | .LP 62 | This program is free software: you can redistribute it and/or modify 63 | it under the terms of the GNU General Public License as published by 64 | the Free Software Foundation, either version 2 of the License, or 65 | (at your option) any later version. 66 | .LP 67 | This program is distributed in the hope that it will be useful, 68 | but WITHOUT ANY WARRANTY; without even the implied warranty of 69 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 70 | GNU General Public License for more details. 71 | -------------------------------------------------------------------------------- /debian/rtl_eeprom.1: -------------------------------------------------------------------------------- 1 | .TH "rtl_eeprom" 1 "0.5.0" RTL-SDR "User Commands" 2 | .SH NAME 3 | rtl-eeprom \- EEPROM programming tool for RTL2832 based DVB-T receivers 4 | .SH DESCRIPTION 5 | Dumps configuration and also writes EEPROM configuration. 6 | Written by Steve Markgraf and incorporated in the osmocom rtl-sdr project. 7 | .LP 8 | Use at your own risk, especially -w! 9 | .LP 10 | Much software is available for the RTL2832. Most of the user-level 11 | packages rely on the librtlsdr library which comes as part of the 12 | rtl-sdr codebase. This codebase contains both the library itself and 13 | also a number of command line tools such as rtl_test, rtl_sdr, 14 | rtl_tcp, and rtl_fm. These command line tools use the library to test 15 | for the existence of RTL2832 devices and to perform basic data 16 | transfer functions to and from the device. 17 | .LP 18 | Because most of the RTL2832 devices are connected using USB, the 19 | librtlsdr library depends on the libusb library to communicate with 20 | the device. 21 | .SH USAGE 22 | Writing bad information to the EEPROM will make your 23 | device useless. 24 | .SH SYNOPSIS 25 | .B rtl_eeprom [OPTIONS] 26 | .SH OPTIONS 27 | .IP "-d device_index (default: 0)" 28 | .IP "-m set manufacturer string" 29 | .IP "-p set product string" 30 | .IP "-s set serial number string" 31 | .IP "-i <0,1> disable/enable IR-endpoint" 32 | .IP "-g generate default config and write to device" 33 | can be one of: 34 | realtek Realtek default (as without EEPROM) 35 | realtek_oem Realtek default OEM with EEPROM 36 | noxon Terratec NOXON DAB Stick 37 | terratec_black Terratec T Stick Black 38 | terratec_plus Terratec T Stick+ (DVB-T/DAB) 39 | .IP "-w write dumped file to device" 40 | .IP "-r dump EEPROM to file" 41 | .IP "-h display this help text" 42 | .LP 43 | Use on your own risk, especially -w! 44 | .SH SEE ALSO 45 | RTL-SDR wiki documentation: 46 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 47 | .LP 48 | Other rtl-sdr programs: 49 | .sp 50 | rtl_adsb(1), rtl_fm(1), rtl_sdr(1), rtl_tcp(1), rtl_test(1) 51 | .SH AUTHOR 52 | This manual page was written by Maitland Bottoms 53 | for the Debian project (but may be used by others). 54 | .SH COPYRIGHT 55 | Copyright (c) 2013 A. Maitland Bottoms 56 | .LP 57 | This program is free software: you can redistribute it and/or modify 58 | it under the terms of the GNU General Public License as published by 59 | the Free Software Foundation, either version 2 of the License, or 60 | (at your option) any later version. 61 | .LP 62 | This program is distributed in the hope that it will be useful, 63 | but WITHOUT ANY WARRANTY; without even the implied warranty of 64 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 65 | GNU General Public License for more details. 66 | -------------------------------------------------------------------------------- /debian/rtl_fm.1: -------------------------------------------------------------------------------- 1 | .TH "rtl_adsb" 1 "0.5.0" RTL-SDR "User Commands" 2 | .SH NAME 3 | rtl_fm \- a simple FM demodulator for RTL2832 based DVB-T receivers 4 | .SH DESCRIPTION 5 | Uses a re-purposed DVB-T receiver as a software defined 6 | radio to receive narrow band FM signals and demodulate 7 | to audio. Written for and incorporated in the osmocom rtl-sdr project. 8 | .LP 9 | Narrowband FM is commonly used by public service agencies and 10 | commercial dispatch operations in the VHF and UHF bands. 11 | Also can demodulate Wideband FM, as found in the 88-108 MHz FM 12 | broadcast band. 13 | Experimental options include AM, LSB, USB and DSB demodulation. 14 | .LP 15 | Much software is available for the RTL2832. Most of the user-level 16 | packages rely on the librtlsdr library which comes as part of the 17 | rtl-sdr codebase. This codebase contains both the library itself and 18 | also a number of command line tools such as rtl_test, rtl_sdr, 19 | rtl_tcp, and rtl_fm. These command line tools use the library to test 20 | for the existence of RTL2832 devices and to perform basic data 21 | transfer functions to and from the device. 22 | .LP 23 | Because most of the RTL2832 devices are connected using USB, the 24 | librtlsdr library depends on the libusb library to communicate with 25 | the device. 26 | .SH USAGE 27 | With a suitable antenna for receiving the signal attached 28 | to the rtl-sdr supported device, this program will output the 29 | digital audio data decoded from that signal. The data can be 30 | listened to by piping to Sox or aplay applications to play the 31 | stream on the computer sound card. 32 | .SH SYNOPSIS 33 | .B rtl_fm [-f freq] [-options] [filename] 34 | .SH OPTIONS 35 | .IP "-f frequency_to_tune_to [Hz]" 36 | use multiple -f for scanning, (requires squelch) 37 | ranges supported, -f 118M:137M:25k 38 | .IP "[-M modulation (default: fm)]" 39 | fm, wbfm, raw, am, usb, lsb 40 | wbfm == -M fm -s 170k -o 4 -A fast -r 32k -l 0 -E deemp 41 | raw mode outputs 2x16 bit IQ pairs 42 | .IP "-s sample_rate (default: 24k)" 43 | .IP "-d device_index (default: 0)" 44 | .IP "-g tuner_gain (default: automatic)" 45 | .IP "-l squelch_level (default: 0/off)" 46 | .IP "-o oversampling (default: 1, 4 recommended)" 47 | for fm squelch is inverted 48 | .IP "[-o oversampling (default: 1, 4 recommended)]" 49 | .IP "-p ppm_error (default: 0)" 50 | .IP "[-E enable_option (default: none)]" 51 | use multiple -E to enable multiple options 52 | edge: enable lower edge tuning 53 | dc: enable dc blocking filter 54 | deemp: enable de-emphasis filter 55 | direct: enable direct sampling 56 | offset: enable offset tuning 57 | .IP "filename ('-' means stdout)" 58 | omitting the filename also uses stdout 59 | .SH Experimental options 60 | .IP "[-r resample_rate (default: none / same as -s)]" 61 | .IP "[-t squelch_delay (default: 10)]" 62 | +values will mute/scan, -values will exit 63 | .IP "[-F fir_size (default: off)]" 64 | enables low-leakage downsample filter 65 | size can be 0 or 9. 0 has bad roll off 66 | .IP "-A std/fast/lut choose atan math (default: std)" 67 | .IP filename 68 | (a '-' dumps samples to stdout) 69 | (omitting the filename also uses stdout) 70 | .SH EXAMPLES 71 | Produces signed 16 bit ints, use Sox or aplay to hear them. 72 | .IP "rtl_fm ... - | play -t raw -r 24k -es -b 16 -c 1 -V1 -" 73 | | aplay -r 24k -f S16_LE -t raw -c 1 74 | -M wbfm | play -r 32k ... 75 | .IP "rtl_fm ... -s 22050 - | multimon -t raw /dev/stdin" 76 | .SH SEE ALSO 77 | RTL-SDR wiki documentation: 78 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 79 | .LP 80 | Rtl_fm Guide: 81 | .B http://kmkeen.com/rtl-demod-guide/ 82 | .LP 83 | .sp 84 | sox(1), play(1), aplay(1) 85 | .LP 86 | Other rtl-sdr programs: 87 | .sp 88 | rtl_adsb(1), rtl_eeprom(1), rtl_sdr(1), rtl_tcp(1), rtl_test(1) 89 | .SH AUTHOR 90 | This manual page was written by Maitland Bottoms 91 | for the Debian project (but may be used by others). 92 | .SH COPYRIGHT 93 | Copyright (c) 2013 A. Maitland Bottoms 94 | .LP 95 | This program is free software: you can redistribute it and/or modify 96 | it under the terms of the GNU General Public License as published by 97 | the Free Software Foundation, either version 2 of the License, or 98 | (at your option) any later version. 99 | .LP 100 | This program is distributed in the hope that it will be useful, 101 | but WITHOUT ANY WARRANTY; without even the implied warranty of 102 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 103 | GNU General Public License for more details. 104 | -------------------------------------------------------------------------------- /debian/rtl_power.1: -------------------------------------------------------------------------------- 1 | .TH rtl_power: "1" "0.5.1" RTL_SDR "User Commands" 2 | .SH NAME 3 | rtl_power: \- wideband spectrum monitor utility 4 | .SH DESCRIPTION 5 | Uses a re-purposed DVB-T receiver as a software defined 6 | radio to receive signals in I/Q data form. Written for 7 | and incorporated in the osmocom rtl-sdr project. 8 | .SH USAGE 9 | rtl_power, a simple FFT logger for RTL2832 based DVB\-T receivers 10 | .PP 11 | This tool gathers signal data over a very wide area of the frequency spectrum, 12 | and then that data can be used to find active areas of the spectrum. 13 | .PP 14 | Use: rtl_power \fB\-f\fR freq_range [\-options] [filename] 15 | .HP 16 | \fB\-f\fR lower:upper:bin_size [Hz] 17 | .IP 18 | (bin size is a maximum, smaller more convenient bins 19 | .TP 20 | will be used. 21 | valid range 1Hz \- 2.8MHz) 22 | .IP 23 | [\-i integration_interval (default: 10 seconds)] 24 | .IP 25 | (buggy if a full sweep takes longer than the interval) 26 | .IP 27 | [\-1 enables single\-shot mode (default: off)] 28 | [\-e exit_timer (default: off/0)] 29 | [\-d device_index (default: 0)] 30 | [\-g tuner_gain (default: automatic)] 31 | [\-p ppm_error (default: 0)] 32 | filename (a '\-' dumps samples to stdout) 33 | .IP 34 | (omitting the filename also uses stdout) 35 | .SS "Experimental options:" 36 | .IP 37 | [\-w window (default: rectangle)] 38 | .IP 39 | (hamming, blackman, blackman\-harris, hann\-poisson, bartlett, youssef) 40 | .IP 41 | [\-c crop_percent (default: 0%, recommended: 20%\-50%)] 42 | .IP 43 | (discards data at the edges, 100% discards everything) 44 | (has no effect for bins larger than 1MHz) 45 | .IP 46 | [\-F fir_size (default: disabled)] 47 | .IP 48 | (enables low\-leakage downsample filter, 49 | .TP 50 | fir_size can be 0 or 9. 51 | 0 has bad roll off, 52 | .IP 53 | try with '\-c 50%') 54 | .IP 55 | [\-P enables peak hold (default: off)] 56 | [\-D enable direct sampling (default: off)] 57 | [\-O enable offset tuning (default: off)] 58 | .SS "CSV FFT output columns:" 59 | .IP 60 | date, time, Hz low, Hz high, Hz step, samples, dbm, dbm, ... 61 | .SH EXAMPLES 62 | .IP 63 | rtl_power \fB\-f\fR 88M:108M:125k fm_stations.csv 64 | .IP 65 | (creates 160 bins across the FM band, 66 | .IP 67 | individual stations should be visible) 68 | .IP 69 | rtl_power \fB\-f\fR 100M:1G:1M \fB\-i\fR 5m \fB\-1\fR survey.csv 70 | .IP 71 | (a five minute low res scan of nearly everything) 72 | .IP 73 | rtl_power \fB\-f\fR ... \fB\-i\fR 15m \fB\-1\fR log.csv 74 | .IP 75 | (integrate for 15 minutes and exit afterwards) 76 | .IP 77 | rtl_power \fB\-f\fR ... \fB\-e\fR 1h | gzip > log.csv.gz 78 | .IP 79 | (collect data for one hour and compress it on the fly) 80 | .SS "Convert CSV to a waterfall graphic with:" 81 | .IP 82 | http://kmkeen.com/tmp/heatmap.py.txt 83 | .PP 84 | rtl_power, a simple FFT logger for RTL2832 based DVB\-T receivers 85 | .PP 86 | Use: rtl_power \fB\-f\fR freq_range [\-options] [filename] 87 | .HP 88 | \fB\-f\fR lower:upper:bin_size [Hz] 89 | .IP 90 | (bin size is a maximum, smaller more convenient bins 91 | .TP 92 | will be used. 93 | valid range 1Hz \- 2.8MHz) 94 | .IP 95 | [\-i integration_interval (default: 10 seconds)] 96 | .IP 97 | (buggy if a full sweep takes longer than the interval) 98 | .IP 99 | [\-1 enables single\-shot mode (default: off)] 100 | [\-e exit_timer (default: off/0)] 101 | [\-d device_index (default: 0)] 102 | [\-g tuner_gain (default: automatic)] 103 | [\-p ppm_error (default: 0)] 104 | filename (a '\-' dumps samples to stdout) 105 | .IP 106 | (omitting the filename also uses stdout) 107 | .SS "Experimental options:" 108 | .IP 109 | [\-w window (default: rectangle)] 110 | .IP 111 | (hamming, blackman, blackman\-harris, hann\-poisson, bartlett, youssef) 112 | .IP 113 | [\-c crop_percent (default: 0%, recommended: 20%\-50%)] 114 | .IP 115 | (discards data at the edges, 100% discards everything) 116 | (has no effect for bins larger than 1MHz) 117 | .IP 118 | [\-F fir_size (default: disabled)] 119 | .IP 120 | (enables low\-leakage downsample filter, 121 | .TP 122 | fir_size can be 0 or 9. 123 | 0 has bad roll off, 124 | .IP 125 | try with '\-c 50%') 126 | .IP 127 | [\-P enables peak hold (default: off)] 128 | [\-D enable direct sampling (default: off)] 129 | [\-O enable offset tuning (default: off)] 130 | .SS "CSV FFT output columns:" 131 | .IP 132 | date, time, Hz low, Hz high, Hz step, samples, dbm, dbm, ... 133 | .IP 134 | rtl_power \fB\-f\fR 88M:108M:125k fm_stations.csv 135 | .IP 136 | (creates 160 bins across the FM band, 137 | .IP 138 | individual stations should be visible) 139 | .IP 140 | rtl_power \fB\-f\fR 100M:1G:1M \fB\-i\fR 5m \fB\-1\fR survey.csv 141 | .IP 142 | (a five minute low res scan of nearly everything) 143 | .IP 144 | rtl_power \fB\-f\fR ... \fB\-i\fR 15m \fB\-1\fR log.csv 145 | .IP 146 | (integrate for 15 minutes and exit afterwards) 147 | .IP 148 | rtl_power \fB\-f\fR ... \fB\-e\fR 1h | gzip > log.csv.gz 149 | .IP 150 | (collect data for one hour and compress it on the fly) 151 | .SS "Convert CSV to a waterfall graphic with:" 152 | .IP 153 | http://kmkeen.com/tmp/heatmap.py.txt 154 | .SH "SEE ALSO" 155 | .LP 156 | RTL-SDR wiki documentation: 157 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 158 | .LP 159 | Other rtl-sdr programs: 160 | .sp 161 | rtl_adsb(1), rtl_eeprom(1), rtl_fm(1), rtl_sdr(1), rtl_tcp(1), rtl_test(1) 162 | .SH AUTHOR 163 | This manual page was written by Maitland Bottoms 164 | for the Debian project (but may be used by others). 165 | .SH COPYRIGHT 166 | Copyright (c) 2013 A. Maitland Bottoms 167 | .LP 168 | This program is free software: you can redistribute it and/or modify 169 | it under the terms of the GNU General Public License as published by 170 | the Free Software Foundation, either version 2 of the License, or 171 | (at your option) any later version. 172 | .LP 173 | This program is distributed in the hope that it will be useful, 174 | but WITHOUT ANY WARRANTY; without even the implied warranty of 175 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 176 | GNU General Public License for more details. 177 | -------------------------------------------------------------------------------- /debian/rtl_sdr.1: -------------------------------------------------------------------------------- 1 | .TH "rtl_sdr" 1 "0.5.0" RTL-SDR "User Commands" 2 | .SH NAME 3 | rtl-sdr \- an I/Q recorder for RTL2832 based DVB-T receivers 4 | .SH DESCRIPTION 5 | Uses a re-purposed DVB-T receiver as a software defined 6 | radio to receive signals in I/Q data form. Written for 7 | and incorporated in the osmocom rtl-sdr project. 8 | .LP 9 | In-Phase and Quadrature Phase data can faithfully represent 10 | all of the information in a band of frequencies centered 11 | on a carrier signal frequency. 12 | .LP 13 | Much software is available for the RTL2832. Most of the user-level 14 | packages rely on the librtlsdr library which comes as part of the 15 | rtl-sdr codebase. This codebase contains both the library itself and 16 | also a number of command line tools such as rtl_test, rtl_sdr, 17 | rtl_tcp, and rtl_fm. These command line tools use the library to test 18 | for the existence of RTL2832 devices and to perform basic data 19 | transfer functions to and from the device. 20 | .LP 21 | Because most of the RTL2832 devices are connected using USB, the 22 | librtlsdr library depends on the libusb library to communicate with 23 | the device. 24 | .SH USAGE 25 | This program captures information from a band of frequencies 26 | and outputs the data in a form useful to other software radio 27 | programs. 28 | .SH SYNOPSIS 29 | .B rtl_adsb [-f freq] [OPTIONS] [output file] 30 | .SH OPTIONS 31 | .IP "-f frequency_to_tune_to [Hz]" 32 | .IP "-s samplerate (default: 2048000 Hz)" 33 | .IP "-d device_index (default: 0)" 34 | .IP "-g gain (default: 0 for auto)" 35 | .IP "-p ppm_error (default: 0)" 36 | .IP "-b output_block_size (default: 16 * 16384)" 37 | .IP "-n number of samples to read (default: 0, infinite)" 38 | .IP "-S force sync output (default: async)" 39 | .IP tfilename 40 | (a '-' dumps samples to stdout) 41 | .SH EXAMPLES 42 | .IP "Example: To tune to 392.0 MHz, and set the sample-rate to 1.8 MS/s, use:" 43 | ./rtl_sdr /tmp/capture.bin -s 1.8e6 -f 392e6 44 | .LP 45 | to record samples to a file or to forward the data to a fifo. 46 | .LP 47 | If the device can't be opened, make sure you have the appropriate 48 | rights to access the device (install udev-rules from the repository, 49 | or run it as root). 50 | .SH SEE ALSO 51 | gnuradio(1) 52 | .LP 53 | RTL-SDR wiki documentation: 54 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 55 | .LP 56 | Other rtl-sdr programs: 57 | .sp 58 | rtl_adsb(1), rtl_eeprom(1), rtl_fm(1), rtl_power(1), rtl_tcp(1), rtl_test(1) 59 | .SH AUTHOR 60 | This manual page was written by Maitland Bottoms 61 | for the Debian project (but may be used by others). 62 | .SH COPYRIGHT 63 | Copyright (c) 2013 A. Maitland Bottoms 64 | .LP 65 | This program is free software: you can redistribute it and/or modify 66 | it under the terms of the GNU General Public License as published by 67 | the Free Software Foundation, either version 2 of the License, or 68 | (at your option) any later version. 69 | .LP 70 | This program is distributed in the hope that it will be useful, 71 | but WITHOUT ANY WARRANTY; without even the implied warranty of 72 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 73 | GNU General Public License for more details. 74 | -------------------------------------------------------------------------------- /debian/rtl_tcp.1: -------------------------------------------------------------------------------- 1 | .TH "rtl_tcp" 1 "0.5.0" RTL-SDR "User Commands" 2 | .SH NAME 3 | rtl_tcp \- an I/Q spectrum server for RTL2832 based DVB-T receivers 4 | .SH DESCRIPTION 5 | Uses a re-purposed DVB-T receiver as a software defined 6 | radio to receive and send I/Q data via TCP network to another 7 | demodulation, decoding or logging apllication. Written for 8 | and incorporated into the osmocom rtl-sdr project. 9 | .LP 10 | Much software is available for the RTL2832. Most of the user-level 11 | packages rely on the librtlsdr library which comes as part of the 12 | rtl-sdr codebase. This codebase contains both the library itself and 13 | also a number of command line tools such as rtl_test, rtl_sdr, 14 | rtl_tcp, and rtl_fm. These command line tools use the library to test 15 | for the existence of RTL2832 devices and to perform basic data 16 | transfer functions to and from the device. 17 | .LP 18 | Because most of the RTL2832 devices are connected using USB, the 19 | librtlsdr library depends on the libusb library to communicate with 20 | the device. 21 | .SH USAGE 22 | Run this program on a machine with an rtl-sdr supported 23 | device connected and it will provide I/Q data to other applications 24 | via TCP/IP. 25 | .SH SYNOPSIS 26 | .B rtl_tcp [OPTIONS] 27 | .SH OPTIONS 28 | .IP "-a listen address" 29 | .IP "-p listen port (default: 1234)" 30 | .IP "-f frequency to tune to [Hz]" 31 | .IP "-g gain (default: 0 for auto)" 32 | .IP "-s samplerate in Hz (default: 2048000 Hz)" 33 | .IP "-b number of buffers (default: 32, set by library)" 34 | .IP "-n max number of linked list buffers to keep (default: 500)" 35 | .IP "-d device_index (default: 0)" 36 | .IP "-P ppm_error (default: 0)" 37 | .SH Example: 38 | .IP "rtl_tcp -a 10.0.0.2 [-p listen port (default: 1234)]" 39 | Found 1 device(s). 40 | Found Elonics E4000 tuner 41 | Using Generic RTL2832U (e.g. hama nano) 42 | Tuned to 100000000 Hz. 43 | listening... 44 | .LP 45 | Use the device argument 'rtl_tcp=10.0.0.2:1234' in OsmoSDR (gr-osmosdr) source 46 | to receive samples in GRC and control rtl_tcp parameters (frequency, gain, ...). 47 | .LP 48 | use the rtl_tcp=... device argument in gr-osmosdr source to receive 49 | the samples in GRC and control the rtl settings remotely. 50 | .LP 51 | This application has been successfully crosscompiled for ARM and MIPS 52 | devices and is providing IQ data in a networked ADS-B setup at a rate 53 | of 2.4MSps. The gr-osmosdr source is being used together with an 54 | optimized gr-air-modes version (see Known Apps below). It is also 55 | available as a package in OpenWRT. 56 | .LP 57 | A use case is described ​https://sites.google.com/site/embrtlsdr/ 58 | .SH SEE ALSO 59 | gnuradio(1) 60 | .LP 61 | RTL-SDR wiki documentation: 62 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 63 | .LP 64 | Other rtl-sdr programs: 65 | .sp 66 | rtl_adsb(1), rtl_eeprom(1), rtl_fm(1), rtl_sdr(1), rtl_test(1) 67 | .SH AUTHOR 68 | This manual page was written by Maitland Bottoms 69 | for the Debian project (but may be used by others). 70 | .SH COPYRIGHT 71 | Copyright (c) 2013 A. Maitland Bottoms 72 | .LP 73 | This program is free software: you can redistribute it and/or modify 74 | it under the terms of the GNU General Public License as published by 75 | the Free Software Foundation, either version 2 of the License, or 76 | (at your option) any later version. 77 | .LP 78 | This program is distributed in the hope that it will be useful, 79 | but WITHOUT ANY WARRANTY; without even the implied warranty of 80 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 81 | GNU General Public License for more details. 82 | -------------------------------------------------------------------------------- /debian/rtl_test.1: -------------------------------------------------------------------------------- 1 | .TH "rtl_test" 1 "0.5.0" RTL-SDR "User Commands" 2 | .SH NAME 3 | rtl_test \- a benchmark tool for RTL2832 based DVB-T receivers 4 | .SH DESCRIPTION 5 | Test tuning range and functional sample rates of your device 6 | on your system. 7 | Uses a re-purposed DVB-T receiver as a software defined 8 | radio. Written for and incorporated into the osmocom rtl-sdr project. 9 | .LP 10 | Much software is available for the RTL2832. Most of the user-level 11 | packages rely on the librtlsdr library which comes as part of the 12 | rtl-sdr codebase. This codebase contains both the library itself and 13 | also a number of command line tools such as rtl_test, rtl_sdr, 14 | rtl_tcp, and rtl_fm. These command line tools use the library to test 15 | for the existence of RTL2832 devices and to perform basic data 16 | transfer functions to and from the device. 17 | .LP 18 | Because most of the RTL2832 devices are connected using USB, the 19 | librtlsdr library depends on the libusb library to communicate with 20 | the device. 21 | .SH SYNOPSIS 22 | .B rtl_test [OPTIONS] 23 | .SH OPTIONS 24 | .IP "-s samplerate (default: 2048000 Hz)" 25 | .IP "-d device_index (default: 0)" 26 | .IP "-t enable Elonics E4000 tuner benchmark]" 27 | .IP "-p enable PPM error measurement" 28 | .IP "-b output_block_size (default: 16 * 16384)" 29 | .IP "-S force sync output (default: async)" 30 | .SH EXAMPLES 31 | .IP "To check the possible tuning range (may heavily vary by some MHz depending on device and temperature), call" 32 | rtl_test -t 33 | .IP "To check the maximum samplerate possible on your machine, type (change the rate down until no sample loss occurs):" 34 | rtl_test -s 3.2e6 35 | .LP 36 | A samplerate of 2.4e6 is known to work even over tcp connections (see 37 | rtl_tcp above). A sample rate of 2.88e6 may work without lost samples 38 | but this may depend on your PC/Laptop's host interface. 39 | .SH SEE ALSO 40 | RTL-SDR wiki documentation: 41 | .B http://sdr.osmocom.org/trac/wiki/rtl-sdr 42 | .LP 43 | Other rtl-sdr programs: 44 | .sp 45 | rtl_adsb(1), rtl_eeprom(1), rtl_fm(1), rtl_sdr(1), rtl_tcp(1) 46 | .SH AUTHOR 47 | This manual page was written by Maitland Bottoms 48 | for the Debian project (but may be used by others). 49 | .SH COPYRIGHT 50 | Copyright (c) 2013 A. Maitland Bottoms 51 | .LP 52 | This program is free software: you can redistribute it and/or modify 53 | it under the terms of the GNU General Public License as published by 54 | the Free Software Foundation, either version 2 of the License, or 55 | (at your option) any later version. 56 | .LP 57 | This program is distributed in the hope that it will be useful, 58 | but WITHOUT ANY WARRANTY; without even the implied warranty of 59 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 60 | GNU General Public License for more details. 61 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH) 3 | export DEB_HOST_MULTIARCH 4 | 5 | %: 6 | dh $@ --buildsystem=cmake 7 | 8 | override_dh_auto_configure: debian/librtlsdr0.udev 9 | dh_auto_configure --buildsystem=cmake -- -DDETACH_KERNEL_DRIVER=ON \ 10 | -DINSTALL_UDEV_RULES=ON \ 11 | -DCMAKE_BUILD_TYPE=RelWithDebInfo 12 | 13 | debian/librtlsdr0.udev: rtl-sdr.rules 14 | cp -p rtl-sdr.rules debian/librtlsdr0.udev 15 | 16 | override_dh_acc: 17 | - dh_acc 18 | - cat debian/librtlsdr-dev/usr/lib/x86_64-linux-gnu/dh-acc/librtlsdr-dev_*_report.html 19 | -------------------------------------------------------------------------------- /debian/source/format: -------------------------------------------------------------------------------- 1 | 3.0 (native) 2 | -------------------------------------------------------------------------------- /debian/watch: -------------------------------------------------------------------------------- 1 | version=4 2 | opts="mode=git, gitmode=full, pgpmode=none" \ 3 | git://git.osmocom.org/rtl-sdr.git \ 4 | refs/tags/v([\d\.]+) debian uupdate 5 | -------------------------------------------------------------------------------- /git-version-gen: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # Print a version string. 3 | scriptversion=2010-01-28.01 4 | 5 | # Copyright (C) 2007-2010 Free Software Foundation, Inc. 6 | # 7 | # This program is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU General Public License as published by 9 | # the Free Software Foundation; either version 3 of the License, or 10 | # (at your option) any later version. 11 | # 12 | # This program is distributed in the hope that it will be useful, 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | # GNU General Public License for more details. 16 | # 17 | # You should have received a copy of the GNU General Public License 18 | # along with this program. If not, see . 19 | 20 | # This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/. 21 | # It may be run two ways: 22 | # - from a git repository in which the "git describe" command below 23 | # produces useful output (thus requiring at least one signed tag) 24 | # - from a non-git-repo directory containing a .tarball-version file, which 25 | # presumes this script is invoked like "./git-version-gen .tarball-version". 26 | 27 | # In order to use intra-version strings in your project, you will need two 28 | # separate generated version string files: 29 | # 30 | # .tarball-version - present only in a distribution tarball, and not in 31 | # a checked-out repository. Created with contents that were learned at 32 | # the last time autoconf was run, and used by git-version-gen. Must not 33 | # be present in either $(srcdir) or $(builddir) for git-version-gen to 34 | # give accurate answers during normal development with a checked out tree, 35 | # but must be present in a tarball when there is no version control system. 36 | # Therefore, it cannot be used in any dependencies. GNUmakefile has 37 | # hooks to force a reconfigure at distribution time to get the value 38 | # correct, without penalizing normal development with extra reconfigures. 39 | # 40 | # .version - present in a checked-out repository and in a distribution 41 | # tarball. Usable in dependencies, particularly for files that don't 42 | # want to depend on config.h but do want to track version changes. 43 | # Delete this file prior to any autoconf run where you want to rebuild 44 | # files to pick up a version string change; and leave it stale to 45 | # minimize rebuild time after unrelated changes to configure sources. 46 | # 47 | # It is probably wise to add these two files to .gitignore, so that you 48 | # don't accidentally commit either generated file. 49 | # 50 | # Use the following line in your configure.ac, so that $(VERSION) will 51 | # automatically be up-to-date each time configure is run (and note that 52 | # since configure.ac no longer includes a version string, Makefile rules 53 | # should not depend on configure.ac for version updates). 54 | # 55 | # AC_INIT([GNU project], 56 | # m4_esyscmd([build-aux/git-version-gen .tarball-version]), 57 | # [bug-project@example]) 58 | # 59 | # Then use the following lines in your Makefile.am, so that .version 60 | # will be present for dependencies, and so that .tarball-version will 61 | # exist in distribution tarballs. 62 | # 63 | # BUILT_SOURCES = $(top_srcdir)/.version 64 | # $(top_srcdir)/.version: 65 | # echo $(VERSION) > $@-t && mv $@-t $@ 66 | # dist-hook: 67 | # echo $(VERSION) > $(distdir)/.tarball-version 68 | 69 | case $# in 70 | 1) ;; 71 | *) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;; 72 | esac 73 | 74 | tarball_version_file=$1 75 | nl=' 76 | ' 77 | 78 | # First see if there is a tarball-only version file. 79 | # then try "git describe", then default. 80 | if test -f $tarball_version_file 81 | then 82 | v=`cat $tarball_version_file` || exit 1 83 | case $v in 84 | *$nl*) v= ;; # reject multi-line output 85 | [0-9]*) ;; 86 | *) v= ;; 87 | esac 88 | test -z "$v" \ 89 | && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2 90 | fi 91 | 92 | if test -n "$v" 93 | then 94 | : # use $v 95 | elif 96 | v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \ 97 | || git describe --abbrev=4 HEAD 2>/dev/null` \ 98 | && case $v in 99 | [0-9]*) ;; 100 | v[0-9]*) ;; 101 | *) (exit 1) ;; 102 | esac 103 | then 104 | # Is this a new git that lists number of commits since the last 105 | # tag or the previous older version that did not? 106 | # Newer: v6.10-77-g0f8faeb 107 | # Older: v6.10-g0f8faeb 108 | case $v in 109 | *-*-*) : git describe is okay three part flavor ;; 110 | *-*) 111 | : git describe is older two part flavor 112 | # Recreate the number of commits and rewrite such that the 113 | # result is the same as if we were using the newer version 114 | # of git describe. 115 | vtag=`echo "$v" | sed 's/-.*//'` 116 | numcommits=`git rev-list "$vtag"..HEAD | wc -l` 117 | v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; 118 | ;; 119 | esac 120 | 121 | # Change the first '-' to a '.', so version-comparing tools work properly. 122 | # Remove the "g" in git describe's output string, to save a byte. 123 | v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`; 124 | else 125 | v=UNKNOWN 126 | fi 127 | 128 | v=`echo "$v" |sed 's/^v//'` 129 | 130 | # Don't declare a version "dirty" merely because a time stamp has changed. 131 | git status > /dev/null 2>&1 132 | 133 | dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty= 134 | case "$dirty" in 135 | '') ;; 136 | *) # Append the suffix only if there isn't one already. 137 | case $v in 138 | *-dirty) ;; 139 | *) v="$v-dirty" ;; 140 | esac ;; 141 | esac 142 | 143 | # Omit the trailing newline, so that m4_esyscmd can use the result directly. 144 | echo "$v" | tr -d '\012' 145 | 146 | # Local variables: 147 | # eval: (add-hook 'write-file-hooks 'time-stamp) 148 | # time-stamp-start: "scriptversion=" 149 | # time-stamp-format: "%:y-%02m-%02d.%02H" 150 | # time-stamp-end: "$" 151 | # End: 152 | -------------------------------------------------------------------------------- /include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2012 OSMOCOM Project 2 | # 3 | # This file is part of rtl-sdr 4 | # 5 | # GNU Radio is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3, or (at your option) 8 | # any later version. 9 | # 10 | # GNU Radio is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with GNU Radio; see the file COPYING. If not, write to 17 | # the Free Software Foundation, Inc., 51 Franklin Street, 18 | # Boston, MA 02110-1301, USA. 19 | 20 | ######################################################################## 21 | # Install public header files 22 | ######################################################################## 23 | install(FILES 24 | rtl-sdr.h 25 | rtl-sdr_export.h 26 | DESTINATION include 27 | ) 28 | -------------------------------------------------------------------------------- /include/Makefile.am: -------------------------------------------------------------------------------- 1 | rtlsdr_HEADERS = rtl-sdr.h rtl-sdr_export.h 2 | 3 | noinst_HEADERS = reg_field.h rtlsdr_i2c.h tuner_e4k.h tuner_fc0012.h tuner_fc0013.h tuner_fc2580.h tuner_r82xx.h 4 | 5 | rtlsdrdir = $(includedir) 6 | -------------------------------------------------------------------------------- /include/reg_field.h: -------------------------------------------------------------------------------- 1 | #ifndef _REG_FIELD_H 2 | #define _REG_FIELD_H 3 | 4 | #include 5 | #include 6 | 7 | enum cmd_op { 8 | CMD_OP_GET = (1 << 0), 9 | CMD_OP_SET = (1 << 1), 10 | CMD_OP_EXEC = (1 << 2), 11 | }; 12 | 13 | enum pstate { 14 | ST_IN_CMD, 15 | ST_IN_ARG, 16 | }; 17 | 18 | struct strbuf { 19 | uint8_t idx; 20 | char buf[32]; 21 | }; 22 | 23 | struct cmd_state { 24 | struct strbuf cmd; 25 | struct strbuf arg; 26 | enum pstate state; 27 | void (*out)(const char *format, va_list ap); 28 | }; 29 | 30 | struct cmd { 31 | const char *cmd; 32 | uint32_t ops; 33 | int (*cb)(struct cmd_state *cs, enum cmd_op op, const char *cmd, 34 | int argc, char **argv); 35 | const char *help; 36 | }; 37 | 38 | /* structure describing a field in a register */ 39 | struct reg_field { 40 | uint8_t reg; 41 | uint8_t shift; 42 | uint8_t width; 43 | }; 44 | 45 | struct reg_field_ops { 46 | const struct reg_field *fields; 47 | const char **field_names; 48 | uint32_t num_fields; 49 | void *data; 50 | int (*write_cb)(void *data, uint32_t reg, uint32_t val); 51 | uint32_t (*read_cb)(void *data, uint32_t reg); 52 | }; 53 | 54 | uint32_t reg_field_read(struct reg_field_ops *ops, struct reg_field *field); 55 | int reg_field_write(struct reg_field_ops *ops, struct reg_field *field, uint32_t val); 56 | int reg_field_cmd(struct cmd_state *cs, enum cmd_op op, 57 | const char *cmd, int argc, char **argv, 58 | struct reg_field_ops *ops); 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /include/rtl-sdr_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | * Copyright (C) 2012 by Hoernchen 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #ifndef RTLSDR_EXPORT_H 20 | #define RTLSDR_EXPORT_H 21 | 22 | #if defined __GNUC__ 23 | # if __GNUC__ >= 4 24 | # define __SDR_EXPORT __attribute__((visibility("default"))) 25 | # define __SDR_IMPORT __attribute__((visibility("default"))) 26 | # else 27 | # define __SDR_EXPORT 28 | # define __SDR_IMPORT 29 | # endif 30 | #elif _MSC_VER 31 | # define __SDR_EXPORT __declspec(dllexport) 32 | # define __SDR_IMPORT __declspec(dllimport) 33 | #else 34 | # define __SDR_EXPORT 35 | # define __SDR_IMPORT 36 | #endif 37 | 38 | #ifndef rtlsdr_STATIC 39 | # ifdef rtlsdr_EXPORTS 40 | # define RTLSDR_API __SDR_EXPORT 41 | # else 42 | # define RTLSDR_API __SDR_IMPORT 43 | # endif 44 | #else 45 | #define RTLSDR_API 46 | #endif 47 | #endif /* RTLSDR_EXPORT_H */ 48 | -------------------------------------------------------------------------------- /include/rtlsdr_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_H 2 | #define __I2C_H 3 | 4 | int rtlsdr_check_dongle_model(void *dev, char *manufact_check, char *product_check); 5 | int rtlsdr_set_bias_tee_gpio(void *dev, int gpio, int on); 6 | uint32_t rtlsdr_get_tuner_clock(void *dev); 7 | int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len); 8 | int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /include/tuner_e4k.h: -------------------------------------------------------------------------------- 1 | #ifndef _E4K_TUNER_H 2 | #define _E4K_TUNER_H 3 | 4 | /* 5 | * Elonics E4000 tuner driver 6 | * 7 | * (C) 2011-2012 by Harald Welte 8 | * (C) 2012 by Sylvain Munaut 9 | * (C) 2012 by Hoernchen 10 | * 11 | * All Rights Reserved 12 | * 13 | * This program is free software; you can redistribute it and/or modify 14 | * it under the terms of the GNU General Public License as published by 15 | * the Free Software Foundation; either version 2 of the License, or 16 | * (at your option) any later version. 17 | * 18 | * This program is distributed in the hope that it will be useful, 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | * GNU General Public License for more details. 22 | * 23 | * You should have received a copy of the GNU General Public License 24 | * along with this program. If not, see . 25 | */ 26 | 27 | #define E4K_I2C_ADDR 0xc8 28 | #define E4K_CHECK_ADDR 0x02 29 | #define E4K_CHECK_VAL 0x40 30 | 31 | enum e4k_reg { 32 | E4K_REG_MASTER1 = 0x00, 33 | E4K_REG_MASTER2 = 0x01, 34 | E4K_REG_MASTER3 = 0x02, 35 | E4K_REG_MASTER4 = 0x03, 36 | E4K_REG_MASTER5 = 0x04, 37 | E4K_REG_CLK_INP = 0x05, 38 | E4K_REG_REF_CLK = 0x06, 39 | E4K_REG_SYNTH1 = 0x07, 40 | E4K_REG_SYNTH2 = 0x08, 41 | E4K_REG_SYNTH3 = 0x09, 42 | E4K_REG_SYNTH4 = 0x0a, 43 | E4K_REG_SYNTH5 = 0x0b, 44 | E4K_REG_SYNTH6 = 0x0c, 45 | E4K_REG_SYNTH7 = 0x0d, 46 | E4K_REG_SYNTH8 = 0x0e, 47 | E4K_REG_SYNTH9 = 0x0f, 48 | E4K_REG_FILT1 = 0x10, 49 | E4K_REG_FILT2 = 0x11, 50 | E4K_REG_FILT3 = 0x12, 51 | // gap 52 | E4K_REG_GAIN1 = 0x14, 53 | E4K_REG_GAIN2 = 0x15, 54 | E4K_REG_GAIN3 = 0x16, 55 | E4K_REG_GAIN4 = 0x17, 56 | // gap 57 | E4K_REG_AGC1 = 0x1a, 58 | E4K_REG_AGC2 = 0x1b, 59 | E4K_REG_AGC3 = 0x1c, 60 | E4K_REG_AGC4 = 0x1d, 61 | E4K_REG_AGC5 = 0x1e, 62 | E4K_REG_AGC6 = 0x1f, 63 | E4K_REG_AGC7 = 0x20, 64 | E4K_REG_AGC8 = 0x21, 65 | // gap 66 | E4K_REG_AGC11 = 0x24, 67 | E4K_REG_AGC12 = 0x25, 68 | // gap 69 | E4K_REG_DC1 = 0x29, 70 | E4K_REG_DC2 = 0x2a, 71 | E4K_REG_DC3 = 0x2b, 72 | E4K_REG_DC4 = 0x2c, 73 | E4K_REG_DC5 = 0x2d, 74 | E4K_REG_DC6 = 0x2e, 75 | E4K_REG_DC7 = 0x2f, 76 | E4K_REG_DC8 = 0x30, 77 | // gap 78 | E4K_REG_QLUT0 = 0x50, 79 | E4K_REG_QLUT1 = 0x51, 80 | E4K_REG_QLUT2 = 0x52, 81 | E4K_REG_QLUT3 = 0x53, 82 | // gap 83 | E4K_REG_ILUT0 = 0x60, 84 | E4K_REG_ILUT1 = 0x61, 85 | E4K_REG_ILUT2 = 0x62, 86 | E4K_REG_ILUT3 = 0x63, 87 | // gap 88 | E4K_REG_DCTIME1 = 0x70, 89 | E4K_REG_DCTIME2 = 0x71, 90 | E4K_REG_DCTIME3 = 0x72, 91 | E4K_REG_DCTIME4 = 0x73, 92 | E4K_REG_PWM1 = 0x74, 93 | E4K_REG_PWM2 = 0x75, 94 | E4K_REG_PWM3 = 0x76, 95 | E4K_REG_PWM4 = 0x77, 96 | E4K_REG_BIAS = 0x78, 97 | E4K_REG_CLKOUT_PWDN = 0x7a, 98 | E4K_REG_CHFILT_CALIB = 0x7b, 99 | E4K_REG_I2C_REG_ADDR = 0x7d, 100 | // FIXME 101 | }; 102 | 103 | #define E4K_MASTER1_RESET (1 << 0) 104 | #define E4K_MASTER1_NORM_STBY (1 << 1) 105 | #define E4K_MASTER1_POR_DET (1 << 2) 106 | 107 | #define E4K_SYNTH1_PLL_LOCK (1 << 0) 108 | #define E4K_SYNTH1_BAND_SHIF 1 109 | 110 | #define E4K_SYNTH7_3PHASE_EN (1 << 3) 111 | 112 | #define E4K_SYNTH8_VCOCAL_UPD (1 << 2) 113 | 114 | #define E4K_FILT3_DISABLE (1 << 5) 115 | 116 | #define E4K_AGC1_LIN_MODE (1 << 4) 117 | #define E4K_AGC1_LNA_UPDATE (1 << 5) 118 | #define E4K_AGC1_LNA_G_LOW (1 << 6) 119 | #define E4K_AGC1_LNA_G_HIGH (1 << 7) 120 | 121 | #define E4K_AGC6_LNA_CAL_REQ (1 << 4) 122 | 123 | #define E4K_AGC7_MIX_GAIN_AUTO (1 << 0) 124 | #define E4K_AGC7_GAIN_STEP_5dB (1 << 5) 125 | 126 | #define E4K_AGC8_SENS_LIN_AUTO (1 << 0) 127 | 128 | #define E4K_AGC11_LNA_GAIN_ENH (1 << 0) 129 | 130 | #define E4K_DC1_CAL_REQ (1 << 0) 131 | 132 | #define E4K_DC5_I_LUT_EN (1 << 0) 133 | #define E4K_DC5_Q_LUT_EN (1 << 1) 134 | #define E4K_DC5_RANGE_DET_EN (1 << 2) 135 | #define E4K_DC5_RANGE_EN (1 << 3) 136 | #define E4K_DC5_TIMEVAR_EN (1 << 4) 137 | 138 | #define E4K_CLKOUT_DISABLE 0x96 139 | 140 | #define E4K_CHFCALIB_CMD (1 << 0) 141 | 142 | #define E4K_AGC1_MOD_MASK 0xF 143 | 144 | enum e4k_agc_mode { 145 | E4K_AGC_MOD_SERIAL = 0x0, 146 | E4K_AGC_MOD_IF_PWM_LNA_SERIAL = 0x1, 147 | E4K_AGC_MOD_IF_PWM_LNA_AUTONL = 0x2, 148 | E4K_AGC_MOD_IF_PWM_LNA_SUPERV = 0x3, 149 | E4K_AGC_MOD_IF_SERIAL_LNA_PWM = 0x4, 150 | E4K_AGC_MOD_IF_PWM_LNA_PWM = 0x5, 151 | E4K_AGC_MOD_IF_DIG_LNA_SERIAL = 0x6, 152 | E4K_AGC_MOD_IF_DIG_LNA_AUTON = 0x7, 153 | E4K_AGC_MOD_IF_DIG_LNA_SUPERV = 0x8, 154 | E4K_AGC_MOD_IF_SERIAL_LNA_AUTON = 0x9, 155 | E4K_AGC_MOD_IF_SERIAL_LNA_SUPERV = 0xa, 156 | }; 157 | 158 | enum e4k_band { 159 | E4K_BAND_VHF2 = 0, 160 | E4K_BAND_VHF3 = 1, 161 | E4K_BAND_UHF = 2, 162 | E4K_BAND_L = 3, 163 | }; 164 | 165 | enum e4k_mixer_filter_bw { 166 | E4K_F_MIX_BW_27M = 0, 167 | E4K_F_MIX_BW_4M6 = 8, 168 | E4K_F_MIX_BW_4M2 = 9, 169 | E4K_F_MIX_BW_3M8 = 10, 170 | E4K_F_MIX_BW_3M4 = 11, 171 | E4K_F_MIX_BW_3M = 12, 172 | E4K_F_MIX_BW_2M7 = 13, 173 | E4K_F_MIX_BW_2M3 = 14, 174 | E4K_F_MIX_BW_1M9 = 15, 175 | }; 176 | 177 | enum e4k_if_filter { 178 | E4K_IF_FILTER_MIX, 179 | E4K_IF_FILTER_CHAN, 180 | E4K_IF_FILTER_RC 181 | }; 182 | struct e4k_pll_params { 183 | uint32_t fosc; 184 | uint32_t intended_flo; 185 | uint32_t flo; 186 | uint16_t x; 187 | uint8_t z; 188 | uint8_t r; 189 | uint8_t r_idx; 190 | uint8_t threephase; 191 | }; 192 | 193 | struct e4k_state { 194 | void *i2c_dev; 195 | uint8_t i2c_addr; 196 | enum e4k_band band; 197 | struct e4k_pll_params vco; 198 | void *rtl_dev; 199 | }; 200 | 201 | int e4k_init(struct e4k_state *e4k); 202 | int e4k_standby(struct e4k_state *e4k, int enable); 203 | int e4k_if_gain_set(struct e4k_state *e4k, uint8_t stage, int8_t value); 204 | int e4k_mixer_gain_set(struct e4k_state *e4k, int8_t value); 205 | int e4k_commonmode_set(struct e4k_state *e4k, int8_t value); 206 | int e4k_tune_freq(struct e4k_state *e4k, uint32_t freq); 207 | int e4k_tune_params(struct e4k_state *e4k, struct e4k_pll_params *p); 208 | uint32_t e4k_compute_pll_params(struct e4k_pll_params *oscp, uint32_t fosc, uint32_t intended_flo); 209 | int e4k_if_filter_bw_get(struct e4k_state *e4k, enum e4k_if_filter filter); 210 | int e4k_if_filter_bw_set(struct e4k_state *e4k, enum e4k_if_filter filter, 211 | uint32_t bandwidth); 212 | int e4k_if_filter_chan_enable(struct e4k_state *e4k, int on); 213 | int e4k_rf_filter_set(struct e4k_state *e4k); 214 | 215 | int e4k_manual_dc_offset(struct e4k_state *e4k, int8_t iofs, int8_t irange, int8_t qofs, int8_t qrange); 216 | int e4k_dc_offset_calibrate(struct e4k_state *e4k); 217 | int e4k_dc_offset_gen_table(struct e4k_state *e4k); 218 | 219 | int e4k_set_lna_gain(struct e4k_state *e4k, int32_t gain); 220 | int e4k_enable_manual_gain(struct e4k_state *e4k, uint8_t manual); 221 | int e4k_set_enh_gain(struct e4k_state *e4k, int32_t gain); 222 | #endif /* _E4K_TUNER_H */ 223 | -------------------------------------------------------------------------------- /include/tuner_fc0012.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0012 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * 6 | * modified for use in librtlsdr 7 | * Copyright (C) 2012 Steve Markgraf 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #ifndef _FC0012_H_ 26 | #define _FC0012_H_ 27 | 28 | #define FC0012_I2C_ADDR 0xc6 29 | #define FC0012_CHECK_ADDR 0x00 30 | #define FC0012_CHECK_VAL 0xa1 31 | 32 | int fc0012_init(void *dev); 33 | int fc0012_set_params(void *dev, uint32_t freq, uint32_t bandwidth); 34 | int fc0012_set_gain(void *dev, int gain); 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /include/tuner_fc0013.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0013 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * 6 | * modified for use in librtlsdr 7 | * Copyright (C) 2012 Steve Markgraf 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | * 23 | */ 24 | 25 | #ifndef _FC0013_H_ 26 | #define _FC0013_H_ 27 | 28 | #define FC0013_I2C_ADDR 0xc6 29 | #define FC0013_CHECK_ADDR 0x00 30 | #define FC0013_CHECK_VAL 0xa3 31 | 32 | int fc0013_init(void *dev); 33 | int fc0013_set_params(void *dev, uint32_t freq, uint32_t bandwidth); 34 | int fc0013_set_gain_mode(void *dev, int manual); 35 | int fc0013_set_lna_gain(void *dev, int gain); 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /include/tuner_fc2580.h: -------------------------------------------------------------------------------- 1 | #ifndef __TUNER_FC2580_H 2 | #define __TUNER_FC2580_H 3 | 4 | #define BORDER_FREQ 2600000 //2.6GHz : The border frequency which determines whether Low VCO or High VCO is used 5 | #define USE_EXT_CLK 0 //0 : Use internal XTAL Oscillator / 1 : Use External Clock input 6 | #define OFS_RSSI 57 7 | 8 | #define FC2580_I2C_ADDR 0xac 9 | #define FC2580_CHECK_ADDR 0x01 10 | #define FC2580_CHECK_VAL 0x56 11 | 12 | typedef enum { 13 | FC2580_UHF_BAND, 14 | FC2580_L_BAND, 15 | FC2580_VHF_BAND, 16 | FC2580_NO_BAND 17 | } fc2580_band_type; 18 | 19 | typedef enum { 20 | FC2580_FCI_FAIL, 21 | FC2580_FCI_SUCCESS 22 | } fc2580_fci_result_type; 23 | 24 | enum FUNCTION_STATUS 25 | { 26 | FUNCTION_SUCCESS, 27 | FUNCTION_ERROR, 28 | }; 29 | 30 | extern void fc2580_wait_msec(void *pTuner, int a); 31 | 32 | fc2580_fci_result_type fc2580_i2c_write(void *pTuner, unsigned char reg, unsigned char val); 33 | fc2580_fci_result_type fc2580_i2c_read(void *pTuner, unsigned char reg, unsigned char *read_data); 34 | 35 | /*============================================================================== 36 | fc2580 initial setting 37 | 38 | This function is a generic function which gets called to initialize 39 | 40 | fc2580 in DVB-H mode or L-Band TDMB mode 41 | 42 | 43 | 44 | ifagc_mode 45 | type : integer 46 | 1 : Internal AGC 47 | 2 : Voltage Control Mode 48 | 49 | ==============================================================================*/ 50 | fc2580_fci_result_type fc2580_set_init(void *pTuner, int ifagc_mode, unsigned int freq_xtal ); 51 | 52 | /*============================================================================== 53 | fc2580 frequency setting 54 | 55 | This function is a generic function which gets called to change LO Frequency 56 | 57 | of fc2580 in DVB-H mode or L-Band TDMB mode 58 | 59 | 60 | 61 | f_lo 62 | Value of target LO Frequency in 'kHz' unit 63 | ex) 2.6GHz = 2600000 64 | 65 | ==============================================================================*/ 66 | fc2580_fci_result_type fc2580_set_freq(void *pTuner, unsigned int f_lo, unsigned int freq_xtal ); 67 | 68 | 69 | /*============================================================================== 70 | fc2580 filter BW setting 71 | 72 | This function is a generic function which gets called to change Bandwidth 73 | 74 | frequency of fc2580's channel selection filter 75 | 76 | 77 | 78 | filter_bw 79 | 1 : 1.53MHz(TDMB) 80 | 6 : 6MHz 81 | 7 : 7MHz 82 | 8 : 7.8MHz 83 | 84 | 85 | ==============================================================================*/ 86 | fc2580_fci_result_type fc2580_set_filter( void *pTuner, unsigned char filter_bw, unsigned int freq_xtal ); 87 | 88 | // The following context is FC2580 tuner API source code 89 | // Definitions 90 | 91 | // AGC mode 92 | enum FC2580_AGC_MODE 93 | { 94 | FC2580_AGC_INTERNAL = 1, 95 | FC2580_AGC_EXTERNAL = 2, 96 | }; 97 | 98 | 99 | // Bandwidth mode 100 | enum FC2580_BANDWIDTH_MODE 101 | { 102 | FC2580_BANDWIDTH_1530000HZ = 1, 103 | FC2580_BANDWIDTH_6000000HZ = 6, 104 | FC2580_BANDWIDTH_7000000HZ = 7, 105 | FC2580_BANDWIDTH_8000000HZ = 8, 106 | }; 107 | 108 | // Manipulaing functions 109 | int 110 | fc2580_Initialize( 111 | void *pTuner 112 | ); 113 | 114 | int 115 | fc2580_SetRfFreqHz( 116 | void *pTuner, 117 | unsigned long RfFreqHz 118 | ); 119 | 120 | // Extra manipulaing functions 121 | int 122 | fc2580_SetBandwidthMode( 123 | void *pTuner, 124 | int BandwidthMode 125 | ); 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /include/tuner_r82xx.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Rafael Micro R820T/R828D driver 3 | * 4 | * Copyright (C) 2013 Mauro Carvalho Chehab 5 | * Copyright (C) 2013 Steve Markgraf 6 | * 7 | * This driver is a heavily modified version of the driver found in the 8 | * Linux kernel: 9 | * http://git.linuxtv.org/linux-2.6.git/history/HEAD:/drivers/media/tuners/r820t.c 10 | * 11 | * This program is free software: you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation, either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program. If not, see . 23 | */ 24 | 25 | #ifndef R82XX_H 26 | #define R82XX_H 27 | 28 | #define R820T_I2C_ADDR 0x34 29 | #define R828D_I2C_ADDR 0x74 30 | #define R828D_XTAL_FREQ 16000000 31 | 32 | #define R82XX_CHECK_ADDR 0x00 33 | #define R82XX_CHECK_VAL 0x69 34 | 35 | #define R82XX_IF_FREQ 3570000 36 | 37 | #define REG_SHADOW_START 5 38 | #define NUM_REGS 30 39 | #define NUM_IMR 5 40 | #define IMR_TRIAL 9 41 | 42 | #define VER_NUM 49 43 | 44 | enum r82xx_chip { 45 | CHIP_R820T, 46 | CHIP_R620D, 47 | CHIP_R828D, 48 | CHIP_R828, 49 | CHIP_R828S, 50 | CHIP_R820C, 51 | }; 52 | 53 | enum r82xx_tuner_type { 54 | TUNER_RADIO = 1, 55 | TUNER_ANALOG_TV, 56 | TUNER_DIGITAL_TV 57 | }; 58 | 59 | enum r82xx_xtal_cap_value { 60 | XTAL_LOW_CAP_30P = 0, 61 | XTAL_LOW_CAP_20P, 62 | XTAL_LOW_CAP_10P, 63 | XTAL_LOW_CAP_0P, 64 | XTAL_HIGH_CAP_0P 65 | }; 66 | 67 | struct r82xx_config { 68 | uint8_t i2c_addr; 69 | uint32_t xtal; 70 | enum r82xx_chip rafael_chip; 71 | unsigned int max_i2c_msg_len; 72 | int use_predetect; 73 | }; 74 | 75 | struct r82xx_priv { 76 | struct r82xx_config *cfg; 77 | 78 | uint8_t regs[NUM_REGS]; 79 | uint8_t buf[NUM_REGS + 1]; 80 | enum r82xx_xtal_cap_value xtal_cap_sel; 81 | uint16_t pll; /* kHz */ 82 | uint32_t int_freq; 83 | uint32_t rf_freq; 84 | uint8_t fil_cal_code; 85 | uint8_t input; 86 | int has_lock; 87 | int init_done; 88 | 89 | /* Store current mode */ 90 | uint32_t delsys; 91 | enum r82xx_tuner_type type; 92 | 93 | uint32_t bw; /* in MHz */ 94 | 95 | void *rtl_dev; 96 | }; 97 | 98 | struct r82xx_freq_range { 99 | uint32_t freq; 100 | uint8_t open_d; 101 | uint8_t rf_mux_ploy; 102 | uint8_t tf_c; 103 | uint8_t xtal_cap20p; 104 | uint8_t xtal_cap10p; 105 | uint8_t xtal_cap0p; 106 | }; 107 | 108 | enum r82xx_delivery_system { 109 | SYS_UNDEFINED, 110 | SYS_DVBT, 111 | SYS_DVBT2, 112 | SYS_ISDBT, 113 | }; 114 | 115 | int r82xx_standby(struct r82xx_priv *priv); 116 | int r82xx_init(struct r82xx_priv *priv); 117 | int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq); 118 | int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain); 119 | int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate); 120 | int r82xx_toggle_test(struct r82xx_priv *priv, int toggle); 121 | int r82xx_set_vga_gain(struct r82xx_priv *priv); 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /librtlsdr.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: RTL-SDR Library 7 | Description: C Utility Library 8 | Version: @VERSION@ 9 | Cflags: -I${includedir}/ 10 | Libs: -L${libdir} -lrtlsdr 11 | Libs.private: -lusb-1.0 @RTLSDR_PC_LIBS@ 12 | -------------------------------------------------------------------------------- /m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /lt*.m4 3 | -------------------------------------------------------------------------------- /rtl-sdr.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2012-2013 Osmocom rtl-sdr project 3 | # 4 | # This program is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation, either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | # 17 | 18 | # original RTL2832U vid/pid (hama nano, for example) 19 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2832", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 20 | 21 | # RTL2832U OEM vid/pid, e.g. ezcap EzTV668 (E4000), Newsky TV28T (E4000/R820T) etc. 22 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 23 | 24 | # DigitalNow Quad DVB-T PCI-E card (4x FC0012?) 25 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6680", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 26 | 27 | # Leadtek WinFast DTV Dongle mini D (FC0012) 28 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6f0f", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 29 | 30 | # Genius TVGo DVB-T03 USB dongle (Ver. B) 31 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0458", ATTRS{idProduct}=="707f", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 32 | 33 | # Terratec Cinergy T Stick Black (rev 1) (FC0012) 34 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00a9", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 35 | 36 | # Terratec NOXON rev 1 (FC0013) 37 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b3", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 38 | 39 | # Terratec Deutschlandradio DAB Stick (FC0013) 40 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b4", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 41 | 42 | # Terratec NOXON DAB Stick - Radio Energy (FC0013) 43 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b5", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 44 | 45 | # Terratec Media Broadcast DAB Stick (FC0013) 46 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b7", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 47 | 48 | # Terratec BR DAB Stick (FC0013) 49 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b8", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 50 | 51 | # Terratec WDR DAB Stick (FC0013) 52 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b9", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 53 | 54 | # Terratec MuellerVerlag DAB Stick (FC0013) 55 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00c0", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 56 | 57 | # Terratec Fraunhofer DAB Stick (FC0013) 58 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00c6", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 59 | 60 | # Terratec Cinergy T Stick RC (Rev.3) (E4000) 61 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00d3", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 62 | 63 | # Terratec T Stick PLUS (E4000) 64 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00d7", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 65 | 66 | # Terratec NOXON rev 2 (E4000) 67 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00e0", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 68 | 69 | # PixelView PV-DT235U(RN) (FC0012) 70 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1554", ATTRS{idProduct}=="5020", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 71 | 72 | # Astrometa DVB-T/DVB-T2 (R828D) 73 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="15f4", ATTRS{idProduct}=="0131", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 74 | 75 | # HanfTek DAB+FM+DVB-T 76 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="15f4", ATTRS{idProduct}=="0133", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 77 | 78 | # Compro Videomate U620F (E4000) 79 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0620", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 80 | 81 | # Compro Videomate U650F (E4000) 82 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0650", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 83 | 84 | # Compro Videomate U680F (E4000) 85 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0680", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 86 | 87 | # GIGABYTE GT-U7300 (FC0012) 88 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d393", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 89 | 90 | # DIKOM USB-DVBT HD 91 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d394", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 92 | 93 | # Peak 102569AGPK (FC0012) 94 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d395", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 95 | 96 | # KWorld KW-UB450-T USB DVB-T Pico TV (TUA9001) 97 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d397", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 98 | 99 | # Zaapa ZT-MINDVBZP (FC0012) 100 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d398", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 101 | 102 | # SVEON STV20 DVB-T USB & FM (FC0012) 103 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d39d", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 104 | 105 | # Twintech UT-40 (FC0013) 106 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3a4", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 107 | 108 | # ASUS U3100MINI_PLUS_V2 (FC0013) 109 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3a8", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 110 | 111 | # SVEON STV27 DVB-T USB & FM (FC0013) 112 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3af", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 113 | 114 | # SVEON STV21 DVB-T USB & FM 115 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3b0", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 116 | 117 | # Dexatek DK DVB-T Dongle (Logilink VG0002A) (FC2580) 118 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1101", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 119 | 120 | # Dexatek DK DVB-T Dongle (MSI DigiVox mini II V3.0) 121 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1102", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 122 | 123 | # Dexatek DK 5217 DVB-T Dongle (FC2580) 124 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1103", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 125 | 126 | # MSI DigiVox Micro HD (FC2580) 127 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1104", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 128 | 129 | # Sweex DVB-T USB (FC0012) 130 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="a803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 131 | 132 | # GTek T803 (FC0012) 133 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="b803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 134 | 135 | # Lifeview LV5TDeluxe (FC0012) 136 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="c803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 137 | 138 | # MyGica TD312 (FC0012) 139 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="d286", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 140 | 141 | # PROlectrix DV107669 (FC0012) 142 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="d803", ENV{ID_SOFTWARE_RADIO}="1", MODE="0660", GROUP="plugdev" 143 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2012-2020 Osmocom Project 2 | # 3 | # This file is part of rtl-sdr 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 2 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | ######################################################################## 19 | # Setup shared library variant 20 | ######################################################################## 21 | add_library(rtlsdr SHARED librtlsdr.c 22 | tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c) 23 | target_link_libraries(rtlsdr ${LIBUSB_LIBRARIES} ${THREADS_PTHREADS_LIBRARY}) 24 | target_include_directories(rtlsdr PUBLIC 25 | $ 26 | $ # /include 27 | ${LIBUSB_INCLUDE_DIRS} 28 | ${THREADS_PTHREADS_INCLUDE_DIR} 29 | ) 30 | set_target_properties(rtlsdr PROPERTIES DEFINE_SYMBOL "rtlsdr_EXPORTS") 31 | set_target_properties(rtlsdr PROPERTIES OUTPUT_NAME rtlsdr) 32 | set_target_properties(rtlsdr PROPERTIES SOVERSION ${MAJOR_VERSION}) 33 | set_target_properties(rtlsdr PROPERTIES VERSION ${LIBVER}) 34 | generate_export_header(rtlsdr) 35 | 36 | ######################################################################## 37 | # Setup static library variant 38 | ######################################################################## 39 | add_library(rtlsdr_static STATIC librtlsdr.c 40 | tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c) 41 | target_link_libraries(rtlsdr ${LIBUSB_LIBRARIES} ${THREADS_PTHREADS_LIBRARY}) 42 | target_include_directories(rtlsdr_static PUBLIC 43 | $ 44 | $ # /include 45 | ${LIBUSB_INCLUDE_DIRS} 46 | ${THREADS_PTHREADS_INCLUDE_DIR} 47 | ) 48 | set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 49 | if(NOT WIN32) 50 | # Force same library filename for static and shared variants of the library 51 | set_target_properties(rtlsdr_static PROPERTIES OUTPUT_NAME rtlsdr) 52 | endif() 53 | generate_export_header(rtlsdr_static) 54 | 55 | ######################################################################## 56 | # Set up Windows DLL resource files 57 | ######################################################################## 58 | IF(MSVC) 59 | include(${CMAKE_SOURCE_DIR}/cmake/Modules/Version.cmake) 60 | 61 | configure_file( 62 | ${CMAKE_CURRENT_SOURCE_DIR}/rtlsdr.rc.in 63 | ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc 64 | @ONLY) 65 | target_sources(rtlsdr PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) 66 | target_sources(rtlsdr_static PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) 67 | ENDIF(MSVC) 68 | 69 | ######################################################################## 70 | # Setup libraries used in executables 71 | ######################################################################## 72 | add_library(convenience_static STATIC 73 | convenience/convenience.c 74 | ) 75 | target_include_directories(convenience_static 76 | PRIVATE ${CMAKE_SOURCE_DIR}/include) 77 | if(WIN32) 78 | add_library(libgetopt_static STATIC 79 | getopt/getopt.c 80 | ) 81 | target_link_libraries(convenience_static 82 | rtlsdr 83 | ) 84 | endif() 85 | 86 | ######################################################################## 87 | # Build utility 88 | ######################################################################## 89 | add_executable(rtl_sdr rtl_sdr.c) 90 | add_executable(rtl_tcp rtl_tcp.c) 91 | add_executable(rtl_test rtl_test.c) 92 | add_executable(rtl_fm rtl_fm.c) 93 | add_executable(rtl_eeprom rtl_eeprom.c) 94 | add_executable(rtl_adsb rtl_adsb.c) 95 | add_executable(rtl_power rtl_power.c) 96 | add_executable(rtl_biast rtl_biast.c) 97 | set(INSTALL_TARGETS rtlsdr rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_biast) 98 | 99 | target_link_libraries(rtl_sdr rtlsdr convenience_static 100 | ${LIBUSB_LIBRARIES} 101 | ${CMAKE_THREAD_LIBS_INIT} 102 | ) 103 | target_link_libraries(rtl_tcp rtlsdr convenience_static 104 | ${LIBUSB_LIBRARIES} 105 | ${CMAKE_THREAD_LIBS_INIT} 106 | ) 107 | target_link_libraries(rtl_test rtlsdr convenience_static 108 | ${LIBUSB_LIBRARIES} 109 | ${CMAKE_THREAD_LIBS_INIT} 110 | ) 111 | target_link_libraries(rtl_fm rtlsdr convenience_static 112 | ${LIBUSB_LIBRARIES} 113 | ${CMAKE_THREAD_LIBS_INIT} 114 | ) 115 | target_link_libraries(rtl_eeprom rtlsdr convenience_static 116 | ${LIBUSB_LIBRARIES} 117 | ${CMAKE_THREAD_LIBS_INIT} 118 | ) 119 | target_link_libraries(rtl_adsb rtlsdr convenience_static 120 | ${LIBUSB_LIBRARIES} 121 | ${CMAKE_THREAD_LIBS_INIT} 122 | ) 123 | target_link_libraries(rtl_power rtlsdr convenience_static 124 | ${LIBUSB_LIBRARIES} 125 | ${CMAKE_THREAD_LIBS_INIT} 126 | ) 127 | target_link_libraries(rtl_biast rtlsdr convenience_static 128 | ${LIBUSB_LIBRARIES} 129 | ${CMAKE_THREAD_LIBS_INIT} 130 | ) 131 | if(UNIX) 132 | target_link_libraries(rtl_fm m) 133 | target_link_libraries(rtl_adsb m) 134 | target_link_libraries(rtl_power m) 135 | if(APPLE OR CMAKE_SYSTEM MATCHES "OpenBSD") 136 | target_link_libraries(rtl_test m) 137 | else() 138 | target_link_libraries(rtl_test m rt) 139 | endif() 140 | endif() 141 | 142 | if(WIN32) 143 | target_link_libraries(rtl_sdr libgetopt_static) 144 | target_link_libraries(rtl_tcp ws2_32 libgetopt_static) 145 | target_link_libraries(rtl_test libgetopt_static) 146 | target_link_libraries(rtl_fm libgetopt_static) 147 | target_link_libraries(rtl_eeprom libgetopt_static) 148 | target_link_libraries(rtl_adsb libgetopt_static) 149 | target_link_libraries(rtl_power libgetopt_static) 150 | target_link_libraries(rtl_biast libgetopt_static) 151 | set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 152 | set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 153 | set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 154 | set_property(TARGET rtl_fm APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 155 | set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 156 | set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 157 | set_property(TARGET rtl_power APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 158 | set_property(TARGET rtl_biast APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 159 | endif() 160 | ######################################################################## 161 | # Install built library files & utilities 162 | ######################################################################## 163 | install(TARGETS rtlsdr EXPORT RTLSDR-export 164 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so/.dylib file 165 | ) 166 | install(TARGETS rtlsdr_static EXPORT RTLSDR-export 167 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} # .so/.dylib file 168 | ) 169 | install(TARGETS rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power rtl_biast 170 | DESTINATION ${CMAKE_INSTALL_BINDIR} 171 | ) 172 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | # This is _NOT_ the library release version, it's an API version. 2 | # Please read Chapter 6 "Library interface versions" of the libtool documentation before making any modification 3 | LIBVERSION=0:5:0 4 | 5 | AUTOMAKE_OPTIONS = subdir-objects 6 | INCLUDES = $(all_includes) -I$(top_srcdir)/include 7 | noinst_HEADERS = convenience/convenience.h 8 | AM_CFLAGS = ${CFLAGS} -fPIC ${SYMBOL_VISIBILITY} 9 | 10 | lib_LTLIBRARIES = librtlsdr.la 11 | 12 | librtlsdr_la_SOURCES = librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c 13 | librtlsdr_la_LDFLAGS = -version-info $(LIBVERSION) 14 | 15 | bin_PROGRAMS = rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power 16 | 17 | rtl_sdr_SOURCES = rtl_sdr.c convenience/convenience.c 18 | rtl_sdr_LDADD = librtlsdr.la 19 | 20 | rtl_tcp_SOURCES = rtl_tcp.c convenience/convenience.c 21 | rtl_tcp_LDADD = librtlsdr.la 22 | 23 | rtl_test_SOURCES = rtl_test.c convenience/convenience.c 24 | rtl_test_LDADD = librtlsdr.la $(LIBM) 25 | 26 | rtl_fm_SOURCES = rtl_fm.c convenience/convenience.c 27 | rtl_fm_LDADD = librtlsdr.la $(LIBM) 28 | 29 | rtl_eeprom_SOURCES = rtl_eeprom.c convenience/convenience.c 30 | rtl_eeprom_LDADD = librtlsdr.la $(LIBM) 31 | 32 | rtl_adsb_SOURCES = rtl_adsb.c convenience/convenience.c 33 | rtl_adsb_LDADD = librtlsdr.la $(LIBM) 34 | 35 | rtl_power_SOURCES = rtl_power.c convenience/convenience.c 36 | rtl_power_LDADD = librtlsdr.la $(LIBM) 37 | -------------------------------------------------------------------------------- /src/convenience/convenience.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 by Kyle Keen 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* a collection of user friendly tools 19 | * todo: use strtol for more flexible int parsing 20 | * */ 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #ifndef _WIN32 27 | #include 28 | #else 29 | #include 30 | #include 31 | #include 32 | #define _USE_MATH_DEFINES 33 | #endif 34 | 35 | #include 36 | 37 | #include "rtl-sdr.h" 38 | 39 | double atofs(char *s) 40 | /* standard suffixes */ 41 | { 42 | char last; 43 | int len; 44 | double suff = 1.0; 45 | len = strlen(s); 46 | last = s[len-1]; 47 | s[len-1] = '\0'; 48 | switch (last) { 49 | case 'g': 50 | case 'G': 51 | suff *= 1e3; 52 | /* fall-through */ 53 | case 'm': 54 | case 'M': 55 | suff *= 1e3; 56 | /* fall-through */ 57 | case 'k': 58 | case 'K': 59 | suff *= 1e3; 60 | suff *= atof(s); 61 | s[len-1] = last; 62 | return suff; 63 | } 64 | s[len-1] = last; 65 | return atof(s); 66 | } 67 | 68 | double atoft(char *s) 69 | /* time suffixes, returns seconds */ 70 | { 71 | char last; 72 | int len; 73 | double suff = 1.0; 74 | len = strlen(s); 75 | last = s[len-1]; 76 | s[len-1] = '\0'; 77 | switch (last) { 78 | case 'h': 79 | case 'H': 80 | suff *= 60; 81 | /* fall-through */ 82 | case 'm': 83 | case 'M': 84 | suff *= 60; 85 | /* fall-through */ 86 | case 's': 87 | case 'S': 88 | suff *= atof(s); 89 | s[len-1] = last; 90 | return suff; 91 | } 92 | s[len-1] = last; 93 | return atof(s); 94 | } 95 | 96 | double atofp(char *s) 97 | /* percent suffixes */ 98 | { 99 | char last; 100 | int len; 101 | double suff = 1.0; 102 | len = strlen(s); 103 | last = s[len-1]; 104 | s[len-1] = '\0'; 105 | switch (last) { 106 | case '%': 107 | suff *= 0.01; 108 | suff *= atof(s); 109 | s[len-1] = last; 110 | return suff; 111 | } 112 | s[len-1] = last; 113 | return atof(s); 114 | } 115 | 116 | int nearest_gain(rtlsdr_dev_t *dev, int target_gain) 117 | { 118 | int i, r, err1, err2, count, nearest; 119 | int* gains; 120 | r = rtlsdr_set_tuner_gain_mode(dev, 1); 121 | if (r < 0) { 122 | fprintf(stderr, "WARNING: Failed to enable manual gain.\n"); 123 | return r; 124 | } 125 | count = rtlsdr_get_tuner_gains(dev, NULL); 126 | if (count <= 0) { 127 | return 0; 128 | } 129 | gains = malloc(sizeof(int) * count); 130 | count = rtlsdr_get_tuner_gains(dev, gains); 131 | nearest = gains[0]; 132 | for (i=0; i= 0 && device < device_count) { 267 | fprintf(stderr, "Using device %d: %s\n", 268 | device, rtlsdr_get_device_name((uint32_t)device)); 269 | return device; 270 | } 271 | /* does string exact match a serial */ 272 | for (i = 0; i < device_count; i++) { 273 | rtlsdr_get_device_usb_strings(i, vendor, product, serial); 274 | if (strcmp(s, serial) != 0) { 275 | continue;} 276 | device = i; 277 | fprintf(stderr, "Using device %d: %s\n", 278 | device, rtlsdr_get_device_name((uint32_t)device)); 279 | return device; 280 | } 281 | /* does string prefix match a serial */ 282 | for (i = 0; i < device_count; i++) { 283 | rtlsdr_get_device_usb_strings(i, vendor, product, serial); 284 | if (strncmp(s, serial, strlen(s)) != 0) { 285 | continue;} 286 | device = i; 287 | fprintf(stderr, "Using device %d: %s\n", 288 | device, rtlsdr_get_device_name((uint32_t)device)); 289 | return device; 290 | } 291 | /* does string suffix match a serial */ 292 | for (i = 0; i < device_count; i++) { 293 | rtlsdr_get_device_usb_strings(i, vendor, product, serial); 294 | offset = strlen(serial) - strlen(s); 295 | if (offset < 0) { 296 | continue;} 297 | if (strncmp(s, serial+offset, strlen(s)) != 0) { 298 | continue;} 299 | device = i; 300 | fprintf(stderr, "Using device %d: %s\n", 301 | device, rtlsdr_get_device_name((uint32_t)device)); 302 | return device; 303 | } 304 | fprintf(stderr, "No matching devices found.\n"); 305 | return -1; 306 | } 307 | 308 | // vim: tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab 309 | -------------------------------------------------------------------------------- /src/convenience/convenience.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014 by Kyle Keen 3 | * 4 | * This program is free software: you can redistribute it and/or modify 5 | * it under the terms of the GNU General Public License as published by 6 | * the Free Software Foundation, either version 2 of the License, or 7 | * (at your option) any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | * GNU General Public License for more details. 13 | * 14 | * You should have received a copy of the GNU General Public License 15 | * along with this program. If not, see . 16 | */ 17 | 18 | /* a collection of user friendly tools */ 19 | 20 | /*! 21 | * Convert standard suffixes (k, M, G) to double 22 | * 23 | * \param s a string to be parsed 24 | * \return double 25 | */ 26 | 27 | double atofs(char *s); 28 | 29 | /*! 30 | * Convert time suffixes (s, m, h) to double 31 | * 32 | * \param s a string to be parsed 33 | * \return seconds as double 34 | */ 35 | 36 | double atoft(char *s); 37 | 38 | /*! 39 | * Convert percent suffixe (%) to double 40 | * 41 | * \param s a string to be parsed 42 | * \return double 43 | */ 44 | 45 | double atofp(char *s); 46 | 47 | /*! 48 | * Find nearest supported gain 49 | * 50 | * \param dev the device handle given by rtlsdr_open() 51 | * \param target_gain in tenths of a dB 52 | * \return 0 on success 53 | */ 54 | 55 | int nearest_gain(rtlsdr_dev_t *dev, int target_gain); 56 | 57 | /*! 58 | * Set device frequency and report status on stderr 59 | * 60 | * \param dev the device handle given by rtlsdr_open() 61 | * \param frequency in Hz 62 | * \return 0 on success 63 | */ 64 | 65 | int verbose_set_frequency(rtlsdr_dev_t *dev, uint32_t frequency); 66 | 67 | /*! 68 | * Set device sample rate and report status on stderr 69 | * 70 | * \param dev the device handle given by rtlsdr_open() 71 | * \param samp_rate in samples/second 72 | * \return 0 on success 73 | */ 74 | 75 | int verbose_set_sample_rate(rtlsdr_dev_t *dev, uint32_t samp_rate); 76 | 77 | /*! 78 | * Enable or disable the direct sampling mode and report status on stderr 79 | * 80 | * \param dev the device handle given by rtlsdr_open() 81 | * \param on 0 means disabled, 1 I-ADC input enabled, 2 Q-ADC input enabled 82 | * \return 0 on success 83 | */ 84 | 85 | int verbose_direct_sampling(rtlsdr_dev_t *dev, int on); 86 | 87 | /*! 88 | * Enable offset tuning and report status on stderr 89 | * 90 | * \param dev the device handle given by rtlsdr_open() 91 | * \return 0 on success 92 | */ 93 | 94 | int verbose_offset_tuning(rtlsdr_dev_t *dev); 95 | 96 | /*! 97 | * Enable auto gain and report status on stderr 98 | * 99 | * \param dev the device handle given by rtlsdr_open() 100 | * \return 0 on success 101 | */ 102 | 103 | int verbose_auto_gain(rtlsdr_dev_t *dev); 104 | 105 | /*! 106 | * Set tuner gain and report status on stderr 107 | * 108 | * \param dev the device handle given by rtlsdr_open() 109 | * \param gain in tenths of a dB 110 | * \return 0 on success 111 | */ 112 | 113 | int verbose_gain_set(rtlsdr_dev_t *dev, int gain); 114 | 115 | /*! 116 | * Set the frequency correction value for the device and report status on stderr. 117 | * 118 | * \param dev the device handle given by rtlsdr_open() 119 | * \param ppm_error correction value in parts per million (ppm) 120 | * \return 0 on success 121 | */ 122 | 123 | int verbose_ppm_set(rtlsdr_dev_t *dev, int ppm_error); 124 | 125 | /*! 126 | * Reset buffer 127 | * 128 | * \param dev the device handle given by rtlsdr_open() 129 | * \return 0 on success 130 | */ 131 | 132 | int verbose_reset_buffer(rtlsdr_dev_t *dev); 133 | 134 | /*! 135 | * Find the closest matching device. 136 | * 137 | * \param s a string to be parsed 138 | * \return dev_index int, -1 on error 139 | */ 140 | 141 | int verbose_device_search(char *s); 142 | 143 | -------------------------------------------------------------------------------- /src/getopt/getopt.h: -------------------------------------------------------------------------------- 1 | /* Declarations for getopt. 2 | Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc. 3 | This file is part of the GNU C Library. 4 | 5 | The GNU C Library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | The GNU C Library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with the GNU C Library; if not, write to the Free 17 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 | 02111-1307 USA. */ 19 | 20 | #ifndef _GETOPT_H 21 | 22 | #ifndef __need_getopt 23 | # define _GETOPT_H 1 24 | #endif 25 | 26 | /* If __GNU_LIBRARY__ is not already defined, either we are being used 27 | standalone, or this is the first header included in the source file. 28 | If we are being used with glibc, we need to include , but 29 | that does not exist if we are standalone. So: if __GNU_LIBRARY__ is 30 | not defined, include , which will pull in for us 31 | if it's from glibc. (Why ctype.h? It's guaranteed to exist and it 32 | doesn't flood the namespace with stuff the way some other headers do.) */ 33 | #if !defined __GNU_LIBRARY__ 34 | # include 35 | #endif 36 | 37 | #ifdef __cplusplus 38 | extern "C" { 39 | #endif 40 | 41 | /* For communication from `getopt' to the caller. 42 | When `getopt' finds an option that takes an argument, 43 | the argument value is returned here. 44 | Also, when `ordering' is RETURN_IN_ORDER, 45 | each non-option ARGV-element is returned here. */ 46 | 47 | extern char *optarg; 48 | 49 | /* Index in ARGV of the next element to be scanned. 50 | This is used for communication to and from the caller 51 | and for communication between successive calls to `getopt'. 52 | 53 | On entry to `getopt', zero means this is the first call; initialize. 54 | 55 | When `getopt' returns -1, this is the index of the first of the 56 | non-option elements that the caller should itself scan. 57 | 58 | Otherwise, `optind' communicates from one call to the next 59 | how much of ARGV has been scanned so far. */ 60 | 61 | extern int optind; 62 | 63 | /* Callers store zero here to inhibit the error message `getopt' prints 64 | for unrecognized options. */ 65 | 66 | extern int opterr; 67 | 68 | /* Set to an option character which was unrecognized. */ 69 | 70 | extern int optopt; 71 | 72 | #ifndef __need_getopt 73 | /* Describe the long-named options requested by the application. 74 | The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector 75 | of `struct option' terminated by an element containing a name which is 76 | zero. 77 | 78 | The field `has_arg' is: 79 | no_argument (or 0) if the option does not take an argument, 80 | required_argument (or 1) if the option requires an argument, 81 | optional_argument (or 2) if the option takes an optional argument. 82 | 83 | If the field `flag' is not NULL, it points to a variable that is set 84 | to the value given in the field `val' when the option is found, but 85 | left unchanged if the option is not found. 86 | 87 | To have a long-named option do something other than set an `int' to 88 | a compiled-in constant, such as set a value from `optarg', set the 89 | option's `flag' field to zero and its `val' field to a nonzero 90 | value (the equivalent single-letter option character, if there is 91 | one). For long options that have a zero `flag' field, `getopt' 92 | returns the contents of the `val' field. */ 93 | 94 | struct option 95 | { 96 | # if (defined __STDC__ && __STDC__) || defined __cplusplus 97 | const char *name; 98 | # else 99 | char *name; 100 | # endif 101 | /* has_arg can't be an enum because some compilers complain about 102 | type mismatches in all the code that assumes it is an int. */ 103 | int has_arg; 104 | int *flag; 105 | int val; 106 | }; 107 | 108 | /* Names for the values of the `has_arg' field of `struct option'. */ 109 | 110 | # define no_argument 0 111 | # define required_argument 1 112 | # define optional_argument 2 113 | #endif /* need getopt */ 114 | 115 | 116 | /* Get definitions and prototypes for functions to process the 117 | arguments in ARGV (ARGC of them, minus the program name) for 118 | options given in OPTS. 119 | 120 | Return the option character from OPTS just read. Return -1 when 121 | there are no more options. For unrecognized options, or options 122 | missing arguments, `optopt' is set to the option letter, and '?' is 123 | returned. 124 | 125 | The OPTS string is a list of characters which are recognized option 126 | letters, optionally followed by colons, specifying that that letter 127 | takes an argument, to be placed in `optarg'. 128 | 129 | If a letter in OPTS is followed by two colons, its argument is 130 | optional. This behavior is specific to the GNU `getopt'. 131 | 132 | The argument `--' causes premature termination of argument 133 | scanning, explicitly telling `getopt' that there are no more 134 | options. 135 | 136 | If OPTS begins with `--', then non-option arguments are treated as 137 | arguments to the option '\0'. This behavior is specific to the GNU 138 | `getopt'. */ 139 | 140 | #if (defined __STDC__ && __STDC__) || defined __cplusplus 141 | # ifdef __GNU_LIBRARY__ 142 | /* Many other libraries have conflicting prototypes for getopt, with 143 | differences in the consts, in stdlib.h. To avoid compilation 144 | errors, only prototype getopt for the GNU C library. */ 145 | extern int getopt (int __argc, char *const *__argv, const char *__shortopts); 146 | # else /* not __GNU_LIBRARY__ */ 147 | extern int getopt (); 148 | # endif /* __GNU_LIBRARY__ */ 149 | 150 | # ifndef __need_getopt 151 | extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, 152 | const struct option *__longopts, int *__longind); 153 | extern int getopt_long_only (int __argc, char *const *__argv, 154 | const char *__shortopts, 155 | const struct option *__longopts, int *__longind); 156 | 157 | /* Internal only. Users should not call this directly. */ 158 | extern int _getopt_internal (int __argc, char *const *__argv, 159 | const char *__shortopts, 160 | const struct option *__longopts, int *__longind, 161 | int __long_only); 162 | # endif 163 | #else /* not __STDC__ */ 164 | extern int getopt (); 165 | # ifndef __need_getopt 166 | extern int getopt_long (); 167 | extern int getopt_long_only (); 168 | 169 | extern int _getopt_internal (); 170 | # endif 171 | #endif /* __STDC__ */ 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | /* Make sure we later can get all the definitions and declarations. */ 178 | #undef __need_getopt 179 | 180 | #endif /* getopt.h */ 181 | -------------------------------------------------------------------------------- /src/rtl_biast.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | * rtl_biast, tool to set bias tee gpio output 4 | * Copyright (C) 2012 by Steve Markgraf 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #ifndef _WIN32 25 | #include 26 | #else 27 | #include 28 | #include "getopt/getopt.h" 29 | #endif 30 | 31 | #include "rtl-sdr.h" 32 | #include "convenience/convenience.h" 33 | 34 | static rtlsdr_dev_t *dev = NULL; 35 | 36 | void usage(void) 37 | { 38 | fprintf(stderr, 39 | "rtl_biast, a tool for turning the RTL-SDR.com \n" 40 | "bias tee or any GPIO ON and OFF. Example to turn on the \n" 41 | "bias tee: rtl_biast -d 0 -b 1\n" 42 | "Any GPIO: rtl_biast -d 0 -g 1 -b 1\n\n" 43 | "Usage:\n" 44 | "\t[-d device_index (default: 0)]\n" 45 | "\t[-b bias_on (default: 0)]\n" 46 | "\t[-g GPIO select (default: 0)]\n"); 47 | exit(1); 48 | } 49 | 50 | int main(int argc, char **argv) 51 | { 52 | int i, r, opt; 53 | int dev_index = 0; 54 | int dev_given = 0; 55 | uint32_t bias_on = 0; 56 | uint32_t gpio_pin = 0; 57 | int device_count; 58 | 59 | while ((opt = getopt(argc, argv, "d:b:g:h?")) != -1) { 60 | switch (opt) { 61 | case 'd': 62 | dev_index = verbose_device_search(optarg); 63 | dev_given = 1; 64 | break; 65 | case 'b': 66 | bias_on = atoi(optarg); 67 | break; 68 | case 'g': 69 | gpio_pin = atoi(optarg); 70 | break; 71 | default: 72 | usage(); 73 | break; 74 | } 75 | } 76 | 77 | if (!dev_given) { 78 | dev_index = verbose_device_search("0"); 79 | } 80 | 81 | if (dev_index < 0) { 82 | exit(1); 83 | } 84 | 85 | r = rtlsdr_open(&dev, dev_index); 86 | rtlsdr_set_bias_tee_gpio(dev, gpio_pin, bias_on); 87 | 88 | exit: 89 | /* 90 | * Note - rtlsdr_close() in this tree does not clear the bias tee 91 | * GPIO line, so it leaves the bias tee enabled if a client program 92 | * doesn't explictly disable it. 93 | * 94 | * If that behaviour changes then another rtlsdr_close() will be 95 | * needed that takes some extension flags, and one of them should 96 | * be to either explicitly close the biast or leave it alone. 97 | */ 98 | rtlsdr_close(dev); 99 | 100 | return r >= 0 ? r : -r; 101 | } 102 | -------------------------------------------------------------------------------- /src/rtl_eeprom.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | * rtl_eeprom, EEPROM modification tool 4 | * Copyright (C) 2012 by Steve Markgraf 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 2 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | #ifndef _WIN32 25 | #include 26 | #else 27 | #include 28 | #include "getopt/getopt.h" 29 | #endif 30 | 31 | #include "rtl-sdr.h" 32 | 33 | #define EEPROM_SIZE 256 34 | #define MAX_STR_SIZE 256 35 | #define STR_OFFSET 0x09 36 | 37 | static rtlsdr_dev_t *dev = NULL; 38 | 39 | typedef struct rtlsdr_config { 40 | uint16_t vendor_id; 41 | uint16_t product_id; 42 | char manufacturer[MAX_STR_SIZE]; 43 | char product[MAX_STR_SIZE]; 44 | char serial[MAX_STR_SIZE]; 45 | int have_serial; 46 | int enable_bt; 47 | int remote_wakeup; 48 | } rtlsdr_config_t; 49 | 50 | void dump_config(rtlsdr_config_t *conf) 51 | { 52 | fprintf(stderr, "__________________________________________\n"); 53 | fprintf(stderr, "Vendor ID:\t\t0x%04x\n", conf->vendor_id); 54 | fprintf(stderr, "Product ID:\t\t0x%04x\n", conf->product_id); 55 | fprintf(stderr, "Manufacturer:\t\t%s\n", conf->manufacturer); 56 | fprintf(stderr, "Product:\t\t%s\n", conf->product); 57 | fprintf(stderr, "Serial number:\t\t%s\n", conf->serial); 58 | fprintf(stderr, "Serial number enabled:\t"); 59 | fprintf(stderr, conf->have_serial ? "yes\n": "no\n"); 60 | fprintf(stderr, "Bias Tee always on:\t"); 61 | fprintf(stderr, conf->enable_bt ? "no\n": "yes\n"); // 0 is ON for enable_bt 62 | fprintf(stderr, "Remote wakeup enabled:\t"); 63 | fprintf(stderr, conf->remote_wakeup ? "yes\n": "no\n"); 64 | fprintf(stderr, "__________________________________________\n"); 65 | } 66 | 67 | void usage(void) 68 | { 69 | fprintf(stderr, 70 | "rtl_eeprom, an EEPROM programming tool for " 71 | "RTL2832 based DVB-T receivers\n\n" 72 | "Usage:\n" 73 | "\t[-d device_index (default: 0)]\n" 74 | "\t[-m set manufacturer string]\n" 75 | "\t[-p set product string]\n" 76 | "\t[-s set serial number string]\n" 77 | "\t[-b <0,1> disable/enable force bias tee always on (0: OFF, 1: ON)]\n" 78 | "\t[-g generate default config and write to device]\n" 79 | "\t[ can be one of:]\n" 80 | "\t[ realtek\t\tRealtek default (as without EEPROM)]\n" 81 | "\t[ realtek_oem\t\tRealtek default OEM with EEPROM]\n" 82 | "\t[ noxon\t\tTerratec NOXON DAB Stick]\n" 83 | "\t[ terratec_black\tTerratec T Stick Black]\n" 84 | "\t[ terratec_plus\tTerratec T Stick+ (DVB-T/DAB)]\n" 85 | "\t[-w write dumped file to device]\n" 86 | "\t[-r dump EEPROM to file]\n" 87 | "\t[-h display this help text]\n" 88 | "\nUse on your own risk, especially -w!\n"); 89 | exit(1); 90 | } 91 | 92 | int get_string_descriptor(int pos, uint8_t *data, char *str) 93 | { 94 | int len, i, j = 0; 95 | 96 | len = data[pos]; 97 | 98 | if (data[pos + 1] != 0x03) 99 | fprintf(stderr, "Error: invalid string descriptor!\n"); 100 | 101 | for (i = 2; i < len; i += 2) 102 | str[j++] = data[pos + i]; 103 | 104 | str[j] = 0x00; 105 | 106 | return pos + i; 107 | } 108 | 109 | int set_string_descriptor(int pos, uint8_t *data, char *str) 110 | { 111 | int i = 0, j = 2; 112 | 113 | if (pos < 0) 114 | return -1; 115 | 116 | data[pos + 1] = 0x03; 117 | 118 | while (str[i] != 0x00) { 119 | if ((pos + j) >= 78) { 120 | fprintf(stderr, "Error: string too long, truncated!\n"); 121 | return -1; 122 | } 123 | data[pos + j++] = str[i++]; 124 | data[pos + j++] = 0x00; 125 | } 126 | 127 | data[pos] = j; 128 | 129 | return pos + j; 130 | } 131 | 132 | int parse_eeprom_to_conf(rtlsdr_config_t *conf, uint8_t *dat) 133 | { 134 | int pos; 135 | 136 | if ((dat[0] != 0x28) || (dat[1] != 0x32)) 137 | fprintf(stderr, "Error: invalid RTL2832 EEPROM header!\n"); 138 | 139 | conf->vendor_id = dat[2] | (dat[3] << 8); 140 | conf->product_id = dat[4] | (dat[5] << 8); 141 | conf->have_serial = (dat[6] == 0xa5) ? 1 : 0; 142 | conf->remote_wakeup = (dat[7] & 0x01) ? 1 : 0; 143 | conf->enable_bt = (dat[7] & 0x02) ? 1 : 0; 144 | 145 | pos = get_string_descriptor(STR_OFFSET, dat, conf->manufacturer); 146 | pos = get_string_descriptor(pos, dat, conf->product); 147 | get_string_descriptor(pos, dat, conf->serial); 148 | 149 | return 0; 150 | } 151 | 152 | int gen_eeprom_from_conf(rtlsdr_config_t *conf, uint8_t *dat) 153 | { 154 | int pos; 155 | 156 | dat[0] = 0x28; 157 | dat[1] = 0x32; 158 | dat[2] = conf->vendor_id & 0xff; 159 | dat[3] = (conf->vendor_id >> 8) & 0xff ; 160 | dat[4] = conf->product_id & 0xff; 161 | dat[5] = (conf->product_id >> 8) & 0xff; 162 | dat[6] = conf->have_serial ? 0xa5 : 0x00; 163 | dat[7] = 0x14; 164 | dat[7] |= conf->remote_wakeup ? 0x01 : 0x00; 165 | dat[7] |= conf->enable_bt ? 0x02 : 0x00; 166 | dat[8] = 0x02; 167 | 168 | pos = set_string_descriptor(STR_OFFSET, dat, conf->manufacturer); 169 | pos = set_string_descriptor(pos, dat, conf->product); 170 | pos = set_string_descriptor(pos, dat, conf->serial); 171 | 172 | dat[78] = 0x00; /* length of IR config */ 173 | 174 | return pos; 175 | } 176 | 177 | enum configs { 178 | CONF_NONE = 0, 179 | REALTEK, 180 | REALTEK_EEPROM, 181 | TERRATEC_NOXON, 182 | TERRATEC_T_BLACK, 183 | TERRATEC_T_PLUS, 184 | }; 185 | 186 | void gen_default_conf(rtlsdr_config_t *conf, int config) 187 | { 188 | switch (config) { 189 | case REALTEK: 190 | fprintf(stderr, "Realtek default (as without EEPROM)\n"); 191 | conf->vendor_id = 0x0bda; 192 | conf->product_id = 0x2832; 193 | strcpy(conf->manufacturer, "Generic"); 194 | strcpy(conf->product, "RTL2832U DVB-T"); 195 | strcpy(conf->serial, "0"); 196 | conf->have_serial = 1; 197 | conf->enable_bt = 0; 198 | conf->remote_wakeup = 1; 199 | break; 200 | case REALTEK_EEPROM: 201 | fprintf(stderr, "Realtek default OEM with EEPROM\n"); 202 | conf->vendor_id = 0x0bda; 203 | conf->product_id = 0x2838; 204 | strcpy(conf->manufacturer, "Realtek"); 205 | strcpy(conf->product, "RTL2838UHIDIR"); 206 | strcpy(conf->serial, "00000001"); 207 | conf->have_serial = 1; 208 | conf->enable_bt = 1; 209 | conf->remote_wakeup = 0; 210 | break; 211 | case TERRATEC_NOXON: 212 | fprintf(stderr, "Terratec NOXON DAB Stick\n"); 213 | conf->vendor_id = 0x0ccd; 214 | conf->product_id = 0x00b3; 215 | strcpy(conf->manufacturer, "NOXON"); 216 | strcpy(conf->product, "DAB Stick"); 217 | strcpy(conf->serial, "0"); 218 | conf->have_serial = 1; 219 | conf->enable_bt = 0; 220 | conf->remote_wakeup = 1; 221 | break; 222 | case TERRATEC_T_BLACK: 223 | fprintf(stderr, "Terratec T Stick Black\n"); 224 | conf->vendor_id = 0x0ccd; 225 | conf->product_id = 0x00a9; 226 | strcpy(conf->manufacturer, "Realtek"); 227 | strcpy(conf->product, "RTL2838UHIDIR"); 228 | strcpy(conf->serial, "00000001"); 229 | conf->have_serial = 1; 230 | conf->enable_bt = 1; 231 | conf->remote_wakeup = 0; 232 | break; 233 | case TERRATEC_T_PLUS: 234 | fprintf(stderr, "Terratec ran T Stick+\n"); 235 | conf->vendor_id = 0x0ccd; 236 | conf->product_id = 0x00d7; 237 | strcpy(conf->manufacturer, "Realtek"); 238 | strcpy(conf->product, "RTL2838UHIDIR"); 239 | strcpy(conf->serial, "00000001"); 240 | conf->have_serial = 1; 241 | conf->enable_bt = 1; 242 | conf->remote_wakeup = 0; 243 | break; 244 | default: 245 | break; 246 | }; 247 | } 248 | 249 | int main(int argc, char **argv) 250 | { 251 | int i, r, opt; 252 | uint32_t dev_index = 0; 253 | int device_count; 254 | char *filename = NULL; 255 | FILE *file = NULL; 256 | char *manuf_str = NULL; 257 | char *product_str = NULL; 258 | char *serial_str = NULL; 259 | uint8_t buf[EEPROM_SIZE]; 260 | rtlsdr_config_t conf; 261 | int flash_file = 0; 262 | int default_config = 0; 263 | int change = 0; 264 | int enable_bt = 0; 265 | char ch; 266 | 267 | while ((opt = getopt(argc, argv, "d:m:p:s:b:g:w:r:h?")) != -1) { 268 | switch (opt) { 269 | case 'd': 270 | dev_index = atoi(optarg); 271 | break; 272 | case 'm': 273 | manuf_str = optarg; 274 | change = 1; 275 | break; 276 | case 'p': 277 | product_str = optarg; 278 | change = 1; 279 | break; 280 | case 's': 281 | serial_str = optarg; 282 | change = 1; 283 | break; 284 | case 'b': 285 | enable_bt = (atoi(optarg) > 0) ? -1 : 1; 286 | //ir_endpoint = (atoi(optarg) > 0) ? 1 : -1; 287 | change = 1; 288 | break; 289 | case 'g': 290 | if (!strcmp(optarg, "realtek")) 291 | default_config = REALTEK; 292 | else if (!strcmp(optarg, "realtek_oem")) 293 | default_config = REALTEK_EEPROM; 294 | else if (!strcmp(optarg, "noxon")) 295 | default_config = TERRATEC_NOXON; 296 | else if (!strcmp(optarg, "terratec_black")) 297 | default_config = TERRATEC_T_BLACK; 298 | else if (!strcmp(optarg, "terratec_plus")) 299 | default_config = TERRATEC_T_PLUS; 300 | 301 | if (default_config != CONF_NONE) 302 | change = 1; 303 | break; 304 | case 'w': 305 | flash_file = 1; 306 | change = 1; 307 | /* fall-through */ 308 | case 'r': 309 | filename = optarg; 310 | break; 311 | default: 312 | usage(); 313 | break; 314 | } 315 | } 316 | 317 | device_count = rtlsdr_get_device_count(); 318 | if (!device_count) { 319 | fprintf(stderr, "No supported devices found.\n"); 320 | exit(1); 321 | } 322 | 323 | fprintf(stderr, "Found %d device(s):\n", device_count); 324 | for (i = 0; i < device_count; i++) 325 | fprintf(stderr, " %d: %s\n", i, rtlsdr_get_device_name(i)); 326 | fprintf(stderr, "\n"); 327 | 328 | fprintf(stderr, "Using device %d: %s\n", 329 | dev_index, 330 | rtlsdr_get_device_name(dev_index)); 331 | 332 | r = rtlsdr_open(&dev, dev_index); 333 | if (r < 0) { 334 | fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index); 335 | exit(1); 336 | } 337 | 338 | fprintf(stderr, "\n"); 339 | 340 | r = rtlsdr_read_eeprom(dev, buf, 0, EEPROM_SIZE); 341 | if (r < 0) { 342 | if (r == -3) 343 | fprintf(stderr, "No EEPROM has been found.\n"); 344 | else 345 | fprintf(stderr, "Failed to read EEPROM, err %i.\n", r); 346 | goto exit; 347 | } 348 | 349 | if (r < 0) 350 | return -1; 351 | 352 | fprintf(stderr, "Current configuration:\n"); 353 | parse_eeprom_to_conf(&conf, buf); 354 | dump_config(&conf); 355 | 356 | if (filename) { 357 | file = fopen(filename, flash_file ? "rb" : "wb"); 358 | if (!file) { 359 | fprintf(stderr, "Error opening file!\n"); 360 | goto exit; 361 | } 362 | if (flash_file) { 363 | if (fread(buf, 1, sizeof(buf), file) != sizeof(buf)) 364 | fprintf(stderr, "Error reading file!\n"); 365 | } else { 366 | if (fwrite(buf, 1, sizeof(buf), file) != sizeof(buf)) 367 | fprintf(stderr, "Short write, exiting!\n"); 368 | else 369 | fprintf(stderr, "\nDump to %s successful.\n", filename); 370 | } 371 | } 372 | 373 | if (manuf_str) 374 | strncpy((char*)&conf.manufacturer, manuf_str, MAX_STR_SIZE - 1); 375 | 376 | if (product_str) 377 | strncpy((char*)&conf.product, product_str, MAX_STR_SIZE - 1); 378 | 379 | if (serial_str) { 380 | conf.have_serial = 1; 381 | strncpy((char*)&conf.serial, serial_str, MAX_STR_SIZE - 1); 382 | } 383 | 384 | if (enable_bt != 0) 385 | conf.enable_bt = (enable_bt > 0) ? 1 : 0; 386 | 387 | if (!change) 388 | goto exit; 389 | 390 | fprintf(stderr, "\nNew configuration:\n"); 391 | 392 | if (default_config != CONF_NONE) 393 | gen_default_conf(&conf, default_config); 394 | 395 | if (!flash_file) { 396 | if (gen_eeprom_from_conf(&conf, buf) < 0) 397 | goto exit; 398 | } 399 | 400 | parse_eeprom_to_conf(&conf, buf); 401 | dump_config(&conf); 402 | 403 | fprintf(stderr, "Write new configuration to device [y/n]? "); 404 | 405 | while ((ch = getchar())) { 406 | if (ch != 'y') 407 | goto exit; 408 | else 409 | break; 410 | } 411 | 412 | r = rtlsdr_write_eeprom(dev, buf, 0, flash_file ? EEPROM_SIZE : 128); 413 | if (r < 0) 414 | fprintf(stderr, "Error while writing EEPROM: %i\n", r); 415 | else 416 | fprintf(stderr, "\nConfiguration successfully written.\n" 417 | "Please replug the device for changes" 418 | " to take effect.\n"); 419 | 420 | exit: 421 | if (file) 422 | fclose(file); 423 | 424 | rtlsdr_close(dev); 425 | 426 | return r >= 0 ? r : -r; 427 | } 428 | -------------------------------------------------------------------------------- /src/rtl_sdr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | * Copyright (C) 2012 by Steve Markgraf 4 | * 5 | * This program is free software: you can redistribute it and/or modify 6 | * it under the terms of the GNU General Public License as published by 7 | * the Free Software Foundation, either version 2 of the License, or 8 | * (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #ifndef _WIN32 26 | #include 27 | #else 28 | #include 29 | #include 30 | #include 31 | #include "getopt/getopt.h" 32 | #endif 33 | 34 | #include "rtl-sdr.h" 35 | #include "convenience/convenience.h" 36 | 37 | #define DEFAULT_SAMPLE_RATE 2048000 38 | #define DEFAULT_BUF_LENGTH (16 * 16384) 39 | #define MINIMAL_BUF_LENGTH 512 40 | #define MAXIMAL_BUF_LENGTH (256 * 16384) 41 | 42 | static int do_exit = 0; 43 | static uint32_t bytes_to_read = 0; 44 | static rtlsdr_dev_t *dev = NULL; 45 | 46 | void usage(void) 47 | { 48 | fprintf(stderr, 49 | "rtl_sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n" 50 | "Usage:\t -f frequency_to_tune_to [Hz]\n" 51 | "\t[-s samplerate (default: 2048000 Hz)]\n" 52 | "\t[-d device_index (default: 0)]\n" 53 | "\t[-g gain (default: 0 for auto)]\n" 54 | "\t[-p ppm_error (default: 0)]\n" 55 | "\t[-b output_block_size (default: 16 * 16384)]\n" 56 | "\t[-n number of samples to read (default: 0, infinite)]\n" 57 | "\t[-S force sync output (default: async)]\n" 58 | "\t[-D enable direct sampling (default: off)]\n" 59 | "\tfilename (a '-' dumps samples to stdout)\n\n"); 60 | exit(1); 61 | } 62 | 63 | #ifdef _WIN32 64 | BOOL WINAPI 65 | sighandler(int signum) 66 | { 67 | if (CTRL_C_EVENT == signum) { 68 | fprintf(stderr, "Signal caught, exiting!\n"); 69 | do_exit = 1; 70 | rtlsdr_cancel_async(dev); 71 | return TRUE; 72 | } 73 | return FALSE; 74 | } 75 | #else 76 | static void sighandler(int signum) 77 | { 78 | signal(SIGPIPE, SIG_IGN); 79 | fprintf(stderr, "Signal caught, exiting!\n"); 80 | do_exit = 1; 81 | rtlsdr_cancel_async(dev); 82 | } 83 | #endif 84 | 85 | static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) 86 | { 87 | if (ctx) { 88 | if (do_exit) 89 | return; 90 | 91 | if ((bytes_to_read > 0) && (bytes_to_read < len)) { 92 | len = bytes_to_read; 93 | do_exit = 1; 94 | rtlsdr_cancel_async(dev); 95 | } 96 | 97 | if (fwrite(buf, 1, len, (FILE*)ctx) != len) { 98 | fprintf(stderr, "Short write, samples lost, exiting!\n"); 99 | rtlsdr_cancel_async(dev); 100 | } 101 | 102 | if (bytes_to_read > 0) 103 | bytes_to_read -= len; 104 | } 105 | } 106 | 107 | int main(int argc, char **argv) 108 | { 109 | #ifndef _WIN32 110 | struct sigaction sigact; 111 | #endif 112 | char *filename = NULL; 113 | int n_read; 114 | int r, opt; 115 | int gain = 0; 116 | int ppm_error = 0; 117 | int direct_sampling = 0; 118 | int sync_mode = 0; 119 | FILE *file; 120 | uint8_t *buffer; 121 | int dev_index = 0; 122 | int dev_given = 0; 123 | uint32_t frequency = 100000000; 124 | uint32_t samp_rate = DEFAULT_SAMPLE_RATE; 125 | uint32_t out_block_size = DEFAULT_BUF_LENGTH; 126 | 127 | while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:SD")) != -1) { 128 | switch (opt) { 129 | case 'd': 130 | dev_index = verbose_device_search(optarg); 131 | dev_given = 1; 132 | break; 133 | case 'f': 134 | frequency = (uint32_t)atofs(optarg); 135 | break; 136 | case 'g': 137 | gain = (int)(atof(optarg) * 10); /* tenths of a dB */ 138 | break; 139 | case 's': 140 | samp_rate = (uint32_t)atofs(optarg); 141 | break; 142 | case 'p': 143 | ppm_error = atoi(optarg); 144 | break; 145 | case 'b': 146 | out_block_size = (uint32_t)atof(optarg); 147 | break; 148 | case 'n': 149 | bytes_to_read = (uint32_t)atof(optarg) * 2; 150 | break; 151 | case 'S': 152 | sync_mode = 1; 153 | break; 154 | case 'D': 155 | direct_sampling = 1; 156 | break; 157 | default: 158 | usage(); 159 | break; 160 | } 161 | } 162 | 163 | if (argc <= optind) { 164 | usage(); 165 | } else { 166 | filename = argv[optind]; 167 | } 168 | 169 | if(out_block_size < MINIMAL_BUF_LENGTH || 170 | out_block_size > MAXIMAL_BUF_LENGTH ){ 171 | fprintf(stderr, 172 | "Output block size wrong value, falling back to default\n"); 173 | fprintf(stderr, 174 | "Minimal length: %u\n", MINIMAL_BUF_LENGTH); 175 | fprintf(stderr, 176 | "Maximal length: %u\n", MAXIMAL_BUF_LENGTH); 177 | out_block_size = DEFAULT_BUF_LENGTH; 178 | } 179 | 180 | buffer = malloc(out_block_size * sizeof(uint8_t)); 181 | 182 | if (!dev_given) { 183 | dev_index = verbose_device_search("0"); 184 | } 185 | 186 | if (dev_index < 0) { 187 | exit(1); 188 | } 189 | 190 | r = rtlsdr_open(&dev, (uint32_t)dev_index); 191 | if (r < 0) { 192 | fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index); 193 | exit(1); 194 | } 195 | #ifndef _WIN32 196 | sigact.sa_handler = sighandler; 197 | sigemptyset(&sigact.sa_mask); 198 | sigact.sa_flags = 0; 199 | sigaction(SIGINT, &sigact, NULL); 200 | sigaction(SIGTERM, &sigact, NULL); 201 | sigaction(SIGQUIT, &sigact, NULL); 202 | sigaction(SIGPIPE, &sigact, NULL); 203 | #else 204 | SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE ); 205 | #endif 206 | 207 | /* Set direct sampling */ 208 | if (direct_sampling) 209 | verbose_direct_sampling(dev, 2); 210 | 211 | /* Set the sample rate */ 212 | verbose_set_sample_rate(dev, samp_rate); 213 | 214 | /* Set the frequency */ 215 | verbose_set_frequency(dev, frequency); 216 | 217 | if (0 == gain) { 218 | /* Enable automatic gain */ 219 | verbose_auto_gain(dev); 220 | } else { 221 | /* Enable manual gain */ 222 | gain = nearest_gain(dev, gain); 223 | verbose_gain_set(dev, gain); 224 | } 225 | 226 | verbose_ppm_set(dev, ppm_error); 227 | 228 | if(strcmp(filename, "-") == 0) { /* Write samples to stdout */ 229 | file = stdout; 230 | #ifdef _WIN32 231 | _setmode(_fileno(stdin), _O_BINARY); 232 | #endif 233 | } else { 234 | file = fopen(filename, "wb"); 235 | if (!file) { 236 | fprintf(stderr, "Failed to open %s\n", filename); 237 | goto out; 238 | } 239 | } 240 | 241 | /* Reset endpoint before we start reading from it (mandatory) */ 242 | verbose_reset_buffer(dev); 243 | 244 | if (sync_mode) { 245 | fprintf(stderr, "Reading samples in sync mode...\n"); 246 | while (!do_exit) { 247 | r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read); 248 | if (r < 0) { 249 | fprintf(stderr, "WARNING: sync read failed.\n"); 250 | break; 251 | } 252 | 253 | if ((bytes_to_read > 0) && (bytes_to_read < (uint32_t)n_read)) { 254 | n_read = bytes_to_read; 255 | do_exit = 1; 256 | } 257 | 258 | if (fwrite(buffer, 1, n_read, file) != (size_t)n_read) { 259 | fprintf(stderr, "Short write, samples lost, exiting!\n"); 260 | break; 261 | } 262 | 263 | if ((uint32_t)n_read < out_block_size) { 264 | fprintf(stderr, "Short read, samples lost, exiting!\n"); 265 | break; 266 | } 267 | 268 | if (bytes_to_read > 0) 269 | bytes_to_read -= n_read; 270 | } 271 | } else { 272 | fprintf(stderr, "Reading samples in async mode...\n"); 273 | r = rtlsdr_read_async(dev, rtlsdr_callback, (void *)file, 274 | 0, out_block_size); 275 | } 276 | 277 | if (do_exit) 278 | fprintf(stderr, "\nUser cancel, exiting...\n"); 279 | else 280 | fprintf(stderr, "\nLibrary error %d, exiting...\n", r); 281 | 282 | if (file != stdout) 283 | fclose(file); 284 | 285 | rtlsdr_close(dev); 286 | free (buffer); 287 | out: 288 | return r >= 0 ? r : -r; 289 | } 290 | -------------------------------------------------------------------------------- /src/rtl_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | * rtl_test, test and benchmark tool 4 | * 5 | * Copyright (C) 2012-2014 by Steve Markgraf 6 | * Copyright (C) 2012-2014 by Kyle Keen 7 | * Copyright (C) 2014 by Michael Tatarinov 8 | * 9 | * This program is free software: you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation, either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program. If not, see . 21 | */ 22 | 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #ifdef __APPLE__ 31 | #include 32 | #else 33 | #include 34 | #endif 35 | 36 | #ifndef _WIN32 37 | #include 38 | #else 39 | #include 40 | #include "getopt/getopt.h" 41 | #endif 42 | 43 | #include "rtl-sdr.h" 44 | #include "convenience/convenience.h" 45 | 46 | #define DEFAULT_SAMPLE_RATE 2048000 47 | #define DEFAULT_BUF_LENGTH (16 * 16384) 48 | #define MINIMAL_BUF_LENGTH 512 49 | #define MAXIMAL_BUF_LENGTH (256 * 16384) 50 | 51 | #define MHZ(x) ((x)*1000*1000) 52 | 53 | #define PPM_DURATION 10 54 | #define PPM_DUMP_TIME 5 55 | 56 | struct time_generic 57 | /* holds all the platform specific values */ 58 | { 59 | #ifndef _WIN32 60 | time_t tv_sec; 61 | long tv_nsec; 62 | #else 63 | long tv_sec; 64 | long tv_nsec; 65 | int init; 66 | LARGE_INTEGER frequency; 67 | LARGE_INTEGER ticks; 68 | #endif 69 | }; 70 | 71 | static enum { 72 | NO_BENCHMARK, 73 | TUNER_BENCHMARK, 74 | PPM_BENCHMARK 75 | } test_mode = NO_BENCHMARK; 76 | 77 | static int do_exit = 0; 78 | static rtlsdr_dev_t *dev = NULL; 79 | 80 | static uint32_t samp_rate = DEFAULT_SAMPLE_RATE; 81 | 82 | static uint32_t total_samples = 0; 83 | static uint32_t dropped_samples = 0; 84 | 85 | static unsigned int ppm_duration = PPM_DURATION; 86 | 87 | void usage(void) 88 | { 89 | fprintf(stderr, 90 | "rtl_test, a benchmark tool for RTL2832 based DVB-T receivers\n\n" 91 | "Usage:\n" 92 | "\t[-s samplerate (default: 2048000 Hz)]\n" 93 | "\t[-d device_index (default: 0)]\n" 94 | "\t[-t enable Elonics E4000 tuner benchmark]\n" 95 | #ifndef _WIN32 96 | "\t[-p[seconds] enable PPM error measurement (default: 10 seconds)]\n" 97 | #endif 98 | "\t[-b output_block_size (default: 16 * 16384)]\n" 99 | "\t[-S force sync output (default: async)]\n"); 100 | exit(1); 101 | } 102 | 103 | #ifdef _WIN32 104 | BOOL WINAPI 105 | sighandler(int signum) 106 | { 107 | if (CTRL_C_EVENT == signum) { 108 | fprintf(stderr, "Signal caught, exiting!\n"); 109 | do_exit = 1; 110 | rtlsdr_cancel_async(dev); 111 | return TRUE; 112 | } 113 | return FALSE; 114 | } 115 | #else 116 | static void sighandler(int signum) 117 | { 118 | signal(SIGPIPE, SIG_IGN); 119 | fprintf(stderr, "Signal caught, exiting!\n"); 120 | do_exit = 1; 121 | rtlsdr_cancel_async(dev); 122 | } 123 | #endif 124 | 125 | static void underrun_test(unsigned char *buf, uint32_t len, int mute) 126 | { 127 | uint32_t i, lost = 0; 128 | static uint8_t bcnt, uninit = 1; 129 | 130 | if (uninit) { 131 | bcnt = buf[0]; 132 | uninit = 0; 133 | } 134 | for (i = 0; i < len; i++) { 135 | if(bcnt != buf[i]) { 136 | lost += (buf[i] > bcnt) ? (buf[i] - bcnt) : (bcnt - buf[i]); 137 | bcnt = buf[i]; 138 | } 139 | 140 | bcnt++; 141 | } 142 | 143 | total_samples += len; 144 | dropped_samples += lost; 145 | if (mute) 146 | return; 147 | if (lost) 148 | printf("lost at least %d bytes\n", lost); 149 | 150 | } 151 | 152 | #ifndef _WIN32 153 | static int ppm_gettime(struct time_generic *tg) 154 | { 155 | int rv = ENOSYS; 156 | struct timespec ts; 157 | 158 | #ifdef __unix__ 159 | rv = clock_gettime(CLOCK_MONOTONIC, &ts); 160 | tg->tv_sec = ts.tv_sec; 161 | tg->tv_nsec = ts.tv_nsec; 162 | #elif __APPLE__ 163 | struct timeval tv; 164 | 165 | rv = gettimeofday(&tv, NULL); 166 | tg->tv_sec = tv.tv_sec; 167 | tg->tv_nsec = tv.tv_usec * 1000; 168 | #endif 169 | return rv; 170 | } 171 | #endif 172 | 173 | #ifdef _WIN32 174 | static int ppm_gettime(struct time_generic *tg) 175 | { 176 | int rv; 177 | int64_t frac; 178 | if (!tg->init) { 179 | QueryPerformanceFrequency(&tg->frequency); 180 | tg->init = 1; 181 | } 182 | rv = QueryPerformanceCounter(&tg->ticks); 183 | tg->tv_sec = tg->ticks.QuadPart / tg->frequency.QuadPart; 184 | frac = (int64_t)(tg->ticks.QuadPart - (tg->tv_sec * tg->frequency.QuadPart)); 185 | tg->tv_nsec = (long)(frac * 1000000000L / (int64_t)tg->frequency.QuadPart); 186 | return !rv; 187 | } 188 | #endif 189 | 190 | static int ppm_report(uint64_t nsamples, uint64_t interval) 191 | { 192 | double real_rate, ppm; 193 | 194 | real_rate = nsamples * 1e9 / interval; 195 | ppm = 1e6 * (real_rate / (double)samp_rate - 1.); 196 | return (int)round(ppm); 197 | } 198 | 199 | static void ppm_test(uint32_t len) 200 | { 201 | static uint64_t nsamples = 0; 202 | static uint64_t interval = 0; 203 | static uint64_t nsamples_total = 0; 204 | static uint64_t interval_total = 0; 205 | struct time_generic ppm_now; 206 | static struct time_generic ppm_recent; 207 | static enum { 208 | PPM_INIT_NO, 209 | PPM_INIT_DUMP, 210 | PPM_INIT_RUN 211 | } ppm_init = PPM_INIT_NO; 212 | 213 | ppm_gettime(&ppm_now); 214 | 215 | if (ppm_init != PPM_INIT_RUN) { 216 | /* 217 | * Kyle Keen wrote: 218 | * PPM_DUMP_TIME throws out the first N seconds of data. 219 | * The dongle's PPM is usually very bad when first starting up, 220 | * typically incorrect by more than twice the final value. 221 | * Discarding the first few seconds allows the value to stabilize much faster. 222 | */ 223 | if (ppm_init == PPM_INIT_NO) { 224 | ppm_recent.tv_sec = ppm_now.tv_sec + PPM_DUMP_TIME; 225 | ppm_init = PPM_INIT_DUMP; 226 | return; 227 | } 228 | if (ppm_init == PPM_INIT_DUMP && ppm_recent.tv_sec < ppm_now.tv_sec) 229 | return; 230 | ppm_recent = ppm_now; 231 | ppm_init = PPM_INIT_RUN; 232 | return; 233 | } 234 | 235 | nsamples += (uint64_t)(len / 2UL); 236 | interval = (uint64_t)(ppm_now.tv_sec - ppm_recent.tv_sec); 237 | if (interval < ppm_duration) 238 | return; 239 | interval *= 1000000000UL; 240 | interval += (int64_t)(ppm_now.tv_nsec - ppm_recent.tv_nsec); 241 | nsamples_total += nsamples; 242 | interval_total += interval; 243 | printf("real sample rate: %i current PPM: %i cumulative PPM: %i\n", 244 | (int)((1000000000UL * nsamples) / interval), 245 | ppm_report(nsamples, interval), 246 | ppm_report(nsamples_total, interval_total)); 247 | ppm_recent = ppm_now; 248 | nsamples = 0; 249 | } 250 | 251 | static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) 252 | { 253 | underrun_test(buf, len, 0); 254 | 255 | if (test_mode == PPM_BENCHMARK) 256 | ppm_test(len); 257 | } 258 | 259 | void e4k_benchmark(void) 260 | { 261 | uint32_t freq, gap_start = 0, gap_end = 0; 262 | uint32_t range_start = 0, range_end = 0; 263 | 264 | fprintf(stderr, "Benchmarking E4000 PLL...\n"); 265 | 266 | /* find tuner range start */ 267 | for (freq = MHZ(70); freq > MHZ(1); freq -= MHZ(1)) { 268 | if (rtlsdr_set_center_freq(dev, freq) < 0) { 269 | range_start = freq; 270 | break; 271 | } 272 | } 273 | 274 | /* find tuner range end */ 275 | for (freq = MHZ(2000); freq < MHZ(2300UL); freq += MHZ(1)) { 276 | if (rtlsdr_set_center_freq(dev, freq) < 0) { 277 | range_end = freq; 278 | break; 279 | } 280 | } 281 | 282 | /* find start of L-band gap */ 283 | for (freq = MHZ(1000); freq < MHZ(1300); freq += MHZ(1)) { 284 | if (rtlsdr_set_center_freq(dev, freq) < 0) { 285 | gap_start = freq; 286 | break; 287 | } 288 | } 289 | 290 | /* find end of L-band gap */ 291 | for (freq = MHZ(1300); freq > MHZ(1000); freq -= MHZ(1)) { 292 | if (rtlsdr_set_center_freq(dev, freq) < 0) { 293 | gap_end = freq; 294 | break; 295 | } 296 | } 297 | 298 | fprintf(stderr, "E4K range: %i to %i MHz\n", 299 | range_start/MHZ(1) + 1, range_end/MHZ(1) - 1); 300 | 301 | fprintf(stderr, "E4K L-band gap: %i to %i MHz\n", 302 | gap_start/MHZ(1), gap_end/MHZ(1)); 303 | } 304 | 305 | int main(int argc, char **argv) 306 | { 307 | #ifndef _WIN32 308 | struct sigaction sigact; 309 | #endif 310 | int n_read, r, opt, i; 311 | int sync_mode = 0; 312 | uint8_t *buffer; 313 | int dev_index = 0; 314 | int dev_given = 0; 315 | uint32_t out_block_size = DEFAULT_BUF_LENGTH; 316 | int count; 317 | int gains[100]; 318 | 319 | while ((opt = getopt(argc, argv, "d:s:b:tp::Sh")) != -1) { 320 | switch (opt) { 321 | case 'd': 322 | dev_index = verbose_device_search(optarg); 323 | dev_given = 1; 324 | break; 325 | case 's': 326 | samp_rate = (uint32_t)atof(optarg); 327 | break; 328 | case 'b': 329 | out_block_size = (uint32_t)atof(optarg); 330 | break; 331 | case 't': 332 | test_mode = TUNER_BENCHMARK; 333 | break; 334 | case 'p': 335 | test_mode = PPM_BENCHMARK; 336 | if (optarg) 337 | ppm_duration = atoi(optarg); 338 | break; 339 | case 'S': 340 | sync_mode = 1; 341 | break; 342 | case 'h': 343 | default: 344 | usage(); 345 | break; 346 | } 347 | } 348 | 349 | if(out_block_size < MINIMAL_BUF_LENGTH || 350 | out_block_size > MAXIMAL_BUF_LENGTH ){ 351 | fprintf(stderr, 352 | "Output block size wrong value, falling back to default\n"); 353 | fprintf(stderr, 354 | "Minimal length: %u\n", MINIMAL_BUF_LENGTH); 355 | fprintf(stderr, 356 | "Maximal length: %u\n", MAXIMAL_BUF_LENGTH); 357 | out_block_size = DEFAULT_BUF_LENGTH; 358 | } 359 | 360 | buffer = malloc(out_block_size * sizeof(uint8_t)); 361 | 362 | if (!dev_given) { 363 | dev_index = verbose_device_search("0"); 364 | } 365 | 366 | if (dev_index < 0) { 367 | exit(1); 368 | } 369 | 370 | r = rtlsdr_open(&dev, (uint32_t)dev_index); 371 | if (r < 0) { 372 | fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index); 373 | exit(1); 374 | } 375 | #ifndef _WIN32 376 | sigact.sa_handler = sighandler; 377 | sigemptyset(&sigact.sa_mask); 378 | sigact.sa_flags = 0; 379 | sigaction(SIGINT, &sigact, NULL); 380 | sigaction(SIGTERM, &sigact, NULL); 381 | sigaction(SIGQUIT, &sigact, NULL); 382 | sigaction(SIGPIPE, &sigact, NULL); 383 | #else 384 | SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE ); 385 | #endif 386 | count = rtlsdr_get_tuner_gains(dev, NULL); 387 | fprintf(stderr, "Supported gain values (%d): ", count); 388 | 389 | count = rtlsdr_get_tuner_gains(dev, gains); 390 | for (i = 0; i < count; i++) 391 | fprintf(stderr, "%.1f ", gains[i] / 10.0); 392 | fprintf(stderr, "\n"); 393 | 394 | /* Set the sample rate */ 395 | verbose_set_sample_rate(dev, samp_rate); 396 | 397 | if (test_mode == TUNER_BENCHMARK) { 398 | if (rtlsdr_get_tuner_type(dev) == RTLSDR_TUNER_E4000) 399 | e4k_benchmark(); 400 | else 401 | fprintf(stderr, "No E4000 tuner found, aborting.\n"); 402 | 403 | goto exit; 404 | } 405 | 406 | /* Enable test mode */ 407 | r = rtlsdr_set_testmode(dev, 1); 408 | 409 | /* Reset endpoint before we start reading from it (mandatory) */ 410 | verbose_reset_buffer(dev); 411 | 412 | if ((test_mode == PPM_BENCHMARK) && !sync_mode) { 413 | fprintf(stderr, "Reporting PPM error measurement every %u seconds...\n", ppm_duration); 414 | fprintf(stderr, "Press ^C after a few minutes.\n"); 415 | } 416 | 417 | if (test_mode == NO_BENCHMARK) { 418 | fprintf(stderr, "\nInfo: This tool will continuously" 419 | " read from the device, and report if\n" 420 | "samples get lost. If you observe no " 421 | "further output, everything is fine.\n\n"); 422 | } 423 | 424 | if (sync_mode) { 425 | fprintf(stderr, "Reading samples in sync mode...\n"); 426 | fprintf(stderr, "(Samples are being lost but not reported.)\n"); 427 | while (!do_exit) { 428 | r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read); 429 | if (r < 0) { 430 | fprintf(stderr, "WARNING: sync read failed.\n"); 431 | break; 432 | } 433 | 434 | if ((uint32_t)n_read < out_block_size) { 435 | fprintf(stderr, "Short read, samples lost, exiting!\n"); 436 | break; 437 | } 438 | underrun_test(buffer, n_read, 1); 439 | } 440 | } else { 441 | fprintf(stderr, "Reading samples in async mode...\n"); 442 | r = rtlsdr_read_async(dev, rtlsdr_callback, NULL, 443 | 0, out_block_size); 444 | } 445 | 446 | if (do_exit) { 447 | fprintf(stderr, "\nUser cancel, exiting...\n"); 448 | fprintf(stderr, "Samples per million lost (minimum): %i\n", (int)(1000000L * dropped_samples / total_samples)); 449 | } 450 | else 451 | fprintf(stderr, "\nLibrary error %d, exiting...\n", r); 452 | 453 | exit: 454 | rtlsdr_close(dev); 455 | free (buffer); 456 | 457 | return r >= 0 ? r : -r; 458 | } 459 | -------------------------------------------------------------------------------- /src/rtlsdr.rc.in: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | VS_VERSION_INFO VERSIONINFO 5 | FILEVERSION 0,0,0,0 6 | PRODUCTVERSION 0,0,0,0 7 | FILEFLAGSMASK 0x3fL 8 | #ifndef NDEBUG 9 | FILEFLAGS 0x0L 10 | #else 11 | FILEFLAGS 0x1L 12 | #endif 13 | FILEOS VOS__WINDOWS32 14 | FILETYPE VFT_DLL 15 | FILESUBTYPE VFT2_DRV_INSTALLABLE 16 | BEGIN 17 | BLOCK "StringFileInfo" 18 | BEGIN 19 | BLOCK "040904b0" 20 | BEGIN 21 | VALUE "FileDescription", "osmocom rtl-sdr" 22 | VALUE "FileVersion", "@VERSION@" 23 | VALUE "InternalName", "rtl-sdr.dll" 24 | VALUE "LegalCopyright", "Licensed under GPLv2" 25 | VALUE "OriginalFilename", "rtl-sdr.dll" 26 | VALUE "ProductName", "osmocom rtl-sdr" 27 | VALUE "ProductVersion", "@VERSION@" 28 | END 29 | END 30 | BLOCK "VarFileInfo" 31 | BEGIN 32 | VALUE "Translation", 0x409, 1200 33 | END 34 | END 35 | -------------------------------------------------------------------------------- /src/tuner_fc0012.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0012 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * 6 | * modified for use in librtlsdr 7 | * Copyright (C) 2012 Steve Markgraf 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or 12 | * (at your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | * GNU General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 | */ 23 | 24 | #include 25 | #include 26 | 27 | #include "rtlsdr_i2c.h" 28 | #include "tuner_fc0012.h" 29 | 30 | static int fc0012_writereg(void *dev, uint8_t reg, uint8_t val) 31 | { 32 | uint8_t data[2]; 33 | data[0] = reg; 34 | data[1] = val; 35 | 36 | if (rtlsdr_i2c_write_fn(dev, FC0012_I2C_ADDR, data, 2) < 0) 37 | return -1; 38 | 39 | return 0; 40 | } 41 | 42 | static int fc0012_readreg(void *dev, uint8_t reg, uint8_t *val) 43 | { 44 | uint8_t data = reg; 45 | 46 | if (rtlsdr_i2c_write_fn(dev, FC0012_I2C_ADDR, &data, 1) < 0) 47 | return -1; 48 | 49 | if (rtlsdr_i2c_read_fn(dev, FC0012_I2C_ADDR, &data, 1) < 0) 50 | return -1; 51 | 52 | *val = data; 53 | 54 | return 0; 55 | } 56 | 57 | /* Incomplete list of register settings: 58 | * 59 | * Name Reg Bits Desc 60 | * CHIP_ID 0x00 0-7 Chip ID (constant 0xA1) 61 | * RF_A 0x01 0-3 Number of count-to-9 cycles in RF 62 | * divider (suggested: 2..9) 63 | * RF_M 0x02 0-7 Total number of cycles (to-8 and to-9) 64 | * in RF divider 65 | * RF_K_HIGH 0x03 0-6 Bits 8..14 of fractional divider 66 | * RF_K_LOW 0x04 0-7 Bits 0..7 of fractional RF divider 67 | * RF_OUTDIV_A 0x05 3-7 Power of two required? 68 | * LNA_POWER_DOWN 0x06 0 Set to 1 to switch off low noise amp 69 | * RF_OUTDIV_B 0x06 1 Set to select 3 instead of 2 for the 70 | * RF output divider 71 | * VCO_SPEED 0x06 3 Select tuning range of VCO: 72 | * 0 = Low range, (ca. 1.1 - 1.5GHz) 73 | * 1 = High range (ca. 1.4 - 1.8GHz) 74 | * BANDWIDTH 0x06 6-7 Set bandwidth. 6MHz = 0x80, 7MHz=0x40 75 | * 8MHz=0x00 76 | * XTAL_SPEED 0x07 5 Set to 1 for 28.8MHz Crystal input 77 | * or 0 for 36MHz 78 | * 0x08 0-7 79 | * EN_CAL_RSSI 0x09 4 Enable calibrate RSSI 80 | * (Receive Signal Strength Indicator) 81 | * LNA_FORCE 0x0d 0 82 | * AGC_FORCE 0x0d ? 83 | * LNA_GAIN 0x13 3-4 Low noise amp gain 84 | * LNA_COMPS 0x15 3 ? 85 | * VCO_CALIB 0x0e 7 Set high then low to calibrate VCO 86 | * (fast lock?) 87 | * VCO_VOLTAGE 0x0e 0-6 Read Control voltage of VCO 88 | * (big value -> low freq) 89 | */ 90 | 91 | int fc0012_init(void *dev) 92 | { 93 | int ret = 0; 94 | unsigned int i; 95 | uint8_t reg[] = { 96 | 0x00, /* dummy reg. 0 */ 97 | 0x05, /* reg. 0x01 */ 98 | 0x10, /* reg. 0x02 */ 99 | 0x00, /* reg. 0x03 */ 100 | 0x00, /* reg. 0x04 */ 101 | 0x0f, /* reg. 0x05: may also be 0x0a */ 102 | 0x00, /* reg. 0x06: divider 2, VCO slow */ 103 | 0x00, /* reg. 0x07: may also be 0x0f */ 104 | 0xff, /* reg. 0x08: AGC Clock divide by 256, AGC gain 1/256, 105 | Loop Bw 1/8 */ 106 | 0x6e, /* reg. 0x09: Disable LoopThrough, Enable LoopThrough: 0x6f */ 107 | 0xb8, /* reg. 0x0a: Disable LO Test Buffer */ 108 | 0x82, /* reg. 0x0b: Output Clock is same as clock frequency, 109 | may also be 0x83 */ 110 | 0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */ 111 | 0x02, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, 0x02 for DVB-T */ 112 | 0x00, /* reg. 0x0e */ 113 | 0x00, /* reg. 0x0f */ 114 | 0x00, /* reg. 0x10: may also be 0x0d */ 115 | 0x00, /* reg. 0x11 */ 116 | 0x1f, /* reg. 0x12: Set to maximum gain */ 117 | 0x08, /* reg. 0x13: Set to Middle Gain: 0x08, 118 | Low Gain: 0x00, High Gain: 0x10, enable IX2: 0x80 */ 119 | 0x00, /* reg. 0x14 */ 120 | 0x04, /* reg. 0x15: Enable LNA COMPS */ 121 | }; 122 | 123 | #if 0 124 | switch (rtlsdr_get_tuner_clock(dev)) { 125 | case FC_XTAL_27_MHZ: 126 | case FC_XTAL_28_8_MHZ: 127 | reg[0x07] |= 0x20; 128 | break; 129 | case FC_XTAL_36_MHZ: 130 | default: 131 | break; 132 | } 133 | #endif 134 | reg[0x07] |= 0x20; 135 | 136 | // if (priv->dual_master) 137 | reg[0x0c] |= 0x02; 138 | 139 | for (i = 1; i < sizeof(reg); i++) { 140 | ret = fc0012_writereg(dev, i, reg[i]); 141 | if (ret) 142 | break; 143 | } 144 | 145 | return ret; 146 | } 147 | 148 | int fc0012_set_params(void *dev, uint32_t freq, uint32_t bandwidth) 149 | { 150 | int i, ret = 0; 151 | uint8_t reg[7], am, pm, multi, tmp; 152 | uint64_t f_vco; 153 | uint32_t xtal_freq_div_2; 154 | uint16_t xin, xdiv; 155 | int vco_select = 0; 156 | 157 | xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2; 158 | 159 | /* select frequency divider and the frequency of VCO */ 160 | if (freq < 37084000) { /* freq * 96 < 3560000000 */ 161 | multi = 96; 162 | reg[5] = 0x82; 163 | reg[6] = 0x00; 164 | } else if (freq < 55625000) { /* freq * 64 < 3560000000 */ 165 | multi = 64; 166 | reg[5] = 0x82; 167 | reg[6] = 0x02; 168 | } else if (freq < 74167000) { /* freq * 48 < 3560000000 */ 169 | multi = 48; 170 | reg[5] = 0x42; 171 | reg[6] = 0x00; 172 | } else if (freq < 111250000) { /* freq * 32 < 3560000000 */ 173 | multi = 32; 174 | reg[5] = 0x42; 175 | reg[6] = 0x02; 176 | } else if (freq < 148334000) { /* freq * 24 < 3560000000 */ 177 | multi = 24; 178 | reg[5] = 0x22; 179 | reg[6] = 0x00; 180 | } else if (freq < 222500000) { /* freq * 16 < 3560000000 */ 181 | multi = 16; 182 | reg[5] = 0x22; 183 | reg[6] = 0x02; 184 | } else if (freq < 296667000) { /* freq * 12 < 3560000000 */ 185 | multi = 12; 186 | reg[5] = 0x12; 187 | reg[6] = 0x00; 188 | } else if (freq < 445000000) { /* freq * 8 < 3560000000 */ 189 | multi = 8; 190 | reg[5] = 0x12; 191 | reg[6] = 0x02; 192 | } else if (freq < 593334000) { /* freq * 6 < 3560000000 */ 193 | multi = 6; 194 | reg[5] = 0x0a; 195 | reg[6] = 0x00; 196 | } else { 197 | multi = 4; 198 | reg[5] = 0x0a; 199 | reg[6] = 0x02; 200 | } 201 | 202 | f_vco = freq * multi; 203 | 204 | if (f_vco >= 3060000000U) { 205 | reg[6] |= 0x08; 206 | vco_select = 1; 207 | } 208 | 209 | /* From divided value (XDIV) determined the FA and FP value */ 210 | xdiv = (uint16_t)(f_vco / xtal_freq_div_2); 211 | if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2)) 212 | xdiv++; 213 | 214 | pm = (uint8_t)(xdiv / 8); 215 | am = (uint8_t)(xdiv - (8 * pm)); 216 | 217 | if (am < 2) { 218 | am += 8; 219 | pm--; 220 | } 221 | 222 | if (pm > 31) { 223 | reg[1] = am + (8 * (pm - 31)); 224 | reg[2] = 31; 225 | } else { 226 | reg[1] = am; 227 | reg[2] = pm; 228 | } 229 | 230 | if ((reg[1] > 15) || (reg[2] < 0x0b)) { 231 | fprintf(stderr, "[FC0012] no valid PLL combination " 232 | "found for %u Hz!\n", freq); 233 | return -1; 234 | } 235 | 236 | /* fix clock out */ 237 | reg[6] |= 0x20; 238 | 239 | /* From VCO frequency determines the XIN ( fractional part of Delta 240 | Sigma PLL) and divided value (XDIV) */ 241 | xin = (uint16_t)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000); 242 | xin = (xin << 15) / (xtal_freq_div_2 / 1000); 243 | if (xin >= 16384) 244 | xin += 32768; 245 | 246 | reg[3] = xin >> 8; /* xin with 9 bit resolution */ 247 | reg[4] = xin & 0xff; 248 | 249 | reg[6] &= 0x3f; /* bits 6 and 7 describe the bandwidth */ 250 | switch (bandwidth) { 251 | case 6000000: 252 | reg[6] |= 0x80; 253 | break; 254 | case 7000000: 255 | reg[6] |= 0x40; 256 | break; 257 | case 8000000: 258 | default: 259 | break; 260 | } 261 | 262 | /* modified for Realtek demod */ 263 | reg[5] |= 0x07; 264 | 265 | for (i = 1; i <= 6; i++) { 266 | ret = fc0012_writereg(dev, i, reg[i]); 267 | if (ret) 268 | goto exit; 269 | } 270 | 271 | /* VCO Calibration */ 272 | ret = fc0012_writereg(dev, 0x0e, 0x80); 273 | if (!ret) 274 | ret = fc0012_writereg(dev, 0x0e, 0x00); 275 | 276 | /* VCO Re-Calibration if needed */ 277 | if (!ret) 278 | ret = fc0012_writereg(dev, 0x0e, 0x00); 279 | 280 | if (!ret) { 281 | // msleep(10); 282 | ret = fc0012_readreg(dev, 0x0e, &tmp); 283 | } 284 | if (ret) 285 | goto exit; 286 | 287 | /* vco selection */ 288 | tmp &= 0x3f; 289 | 290 | if (vco_select) { 291 | if (tmp > 0x3c) { 292 | reg[6] &= ~0x08; 293 | ret = fc0012_writereg(dev, 0x06, reg[6]); 294 | if (!ret) 295 | ret = fc0012_writereg(dev, 0x0e, 0x80); 296 | if (!ret) 297 | ret = fc0012_writereg(dev, 0x0e, 0x00); 298 | } 299 | } else { 300 | if (tmp < 0x02) { 301 | reg[6] |= 0x08; 302 | ret = fc0012_writereg(dev, 0x06, reg[6]); 303 | if (!ret) 304 | ret = fc0012_writereg(dev, 0x0e, 0x80); 305 | if (!ret) 306 | ret = fc0012_writereg(dev, 0x0e, 0x00); 307 | } 308 | } 309 | 310 | exit: 311 | return ret; 312 | } 313 | 314 | int fc0012_set_gain(void *dev, int gain) 315 | { 316 | int ret; 317 | uint8_t tmp = 0; 318 | 319 | ret = fc0012_readreg(dev, 0x13, &tmp); 320 | 321 | /* mask bits off */ 322 | tmp &= 0xe0; 323 | 324 | switch (gain) { 325 | case -99: /* -9.9 dB */ 326 | tmp |= 0x02; 327 | break; 328 | case -40: /* -4 dB */ 329 | break; 330 | case 71: 331 | tmp |= 0x08; /* 7.1 dB */ 332 | break; 333 | case 179: 334 | tmp |= 0x17; /* 17.9 dB */ 335 | break; 336 | case 192: 337 | default: 338 | tmp |= 0x10; /* 19.2 dB */ 339 | break; 340 | } 341 | 342 | ret = fc0012_writereg(dev, 0x13, tmp); 343 | 344 | return ret; 345 | } 346 | -------------------------------------------------------------------------------- /src/tuner_fc0013.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Fitipower FC0013 tuner driver 3 | * 4 | * Copyright (C) 2012 Hans-Frieder Vogt 5 | * partially based on driver code from Fitipower 6 | * Copyright (C) 2010 Fitipower Integrated Technology Inc 7 | * 8 | * modified for use in librtlsdr 9 | * Copyright (C) 2012 Steve Markgraf 10 | * 11 | * This program is free software; you can redistribute it and/or modify 12 | * it under the terms of the GNU General Public License as published by 13 | * the Free Software Foundation; either version 2 of the License, or 14 | * (at your option) any later version. 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 | * 25 | */ 26 | 27 | #include 28 | #include 29 | 30 | #include "rtlsdr_i2c.h" 31 | #include "tuner_fc0013.h" 32 | 33 | static int fc0013_writereg(void *dev, uint8_t reg, uint8_t val) 34 | { 35 | uint8_t data[2]; 36 | data[0] = reg; 37 | data[1] = val; 38 | 39 | if (rtlsdr_i2c_write_fn(dev, FC0013_I2C_ADDR, data, 2) < 0) 40 | return -1; 41 | 42 | return 0; 43 | } 44 | 45 | static int fc0013_readreg(void *dev, uint8_t reg, uint8_t *val) 46 | { 47 | uint8_t data = reg; 48 | 49 | if (rtlsdr_i2c_write_fn(dev, FC0013_I2C_ADDR, &data, 1) < 0) 50 | return -1; 51 | 52 | if (rtlsdr_i2c_read_fn(dev, FC0013_I2C_ADDR, &data, 1) < 0) 53 | return -1; 54 | 55 | *val = data; 56 | 57 | return 0; 58 | } 59 | 60 | int fc0013_init(void *dev) 61 | { 62 | int ret = 0; 63 | unsigned int i; 64 | uint8_t reg[] = { 65 | 0x00, /* reg. 0x00: dummy */ 66 | 0x09, /* reg. 0x01 */ 67 | 0x16, /* reg. 0x02 */ 68 | 0x00, /* reg. 0x03 */ 69 | 0x00, /* reg. 0x04 */ 70 | 0x17, /* reg. 0x05 */ 71 | 0x02, /* reg. 0x06: LPF bandwidth */ 72 | 0x0a, /* reg. 0x07: CHECK */ 73 | 0xff, /* reg. 0x08: AGC Clock divide by 256, AGC gain 1/256, 74 | Loop Bw 1/8 */ 75 | 0x6e, /* reg. 0x09: Disable LoopThrough, Enable LoopThrough: 0x6f */ 76 | 0xb8, /* reg. 0x0a: Disable LO Test Buffer */ 77 | 0x82, /* reg. 0x0b: CHECK */ 78 | 0xfc, /* reg. 0x0c: depending on AGC Up-Down mode, may need 0xf8 */ 79 | 0x01, /* reg. 0x0d: AGC Not Forcing & LNA Forcing, may need 0x02 */ 80 | 0x00, /* reg. 0x0e */ 81 | 0x00, /* reg. 0x0f */ 82 | 0x00, /* reg. 0x10 */ 83 | 0x00, /* reg. 0x11 */ 84 | 0x00, /* reg. 0x12 */ 85 | 0x00, /* reg. 0x13 */ 86 | 0x50, /* reg. 0x14: DVB-t High Gain, UHF. 87 | Middle Gain: 0x48, Low Gain: 0x40 */ 88 | 0x01, /* reg. 0x15 */ 89 | }; 90 | #if 0 91 | switch (rtlsdr_get_tuner_clock(dev)) { 92 | case FC_XTAL_27_MHZ: 93 | case FC_XTAL_28_8_MHZ: 94 | reg[0x07] |= 0x20; 95 | break; 96 | case FC_XTAL_36_MHZ: 97 | default: 98 | break; 99 | } 100 | #endif 101 | reg[0x07] |= 0x20; 102 | 103 | // if (dev->dual_master) 104 | reg[0x0c] |= 0x02; 105 | 106 | for (i = 1; i < sizeof(reg); i++) { 107 | ret = fc0013_writereg(dev, i, reg[i]); 108 | if (ret < 0) 109 | break; 110 | } 111 | 112 | return ret; 113 | } 114 | 115 | int fc0013_rc_cal_add(void *dev, int rc_val) 116 | { 117 | int ret; 118 | uint8_t rc_cal; 119 | int val; 120 | 121 | /* push rc_cal value, get rc_cal value */ 122 | ret = fc0013_writereg(dev, 0x10, 0x00); 123 | if (ret) 124 | goto error_out; 125 | 126 | /* get rc_cal value */ 127 | ret = fc0013_readreg(dev, 0x10, &rc_cal); 128 | if (ret) 129 | goto error_out; 130 | 131 | rc_cal &= 0x0f; 132 | 133 | val = (int)rc_cal + rc_val; 134 | 135 | /* forcing rc_cal */ 136 | ret = fc0013_writereg(dev, 0x0d, 0x11); 137 | if (ret) 138 | goto error_out; 139 | 140 | /* modify rc_cal value */ 141 | if (val > 15) 142 | ret = fc0013_writereg(dev, 0x10, 0x0f); 143 | else if (val < 0) 144 | ret = fc0013_writereg(dev, 0x10, 0x00); 145 | else 146 | ret = fc0013_writereg(dev, 0x10, (uint8_t)val); 147 | 148 | error_out: 149 | return ret; 150 | } 151 | 152 | int fc0013_rc_cal_reset(void *dev) 153 | { 154 | int ret; 155 | 156 | ret = fc0013_writereg(dev, 0x0d, 0x01); 157 | if (!ret) 158 | ret = fc0013_writereg(dev, 0x10, 0x00); 159 | 160 | return ret; 161 | } 162 | 163 | static int fc0013_set_vhf_track(void *dev, uint32_t freq) 164 | { 165 | int ret; 166 | uint8_t tmp; 167 | 168 | ret = fc0013_readreg(dev, 0x1d, &tmp); 169 | if (ret) 170 | goto error_out; 171 | tmp &= 0xe3; 172 | if (freq <= 177500000) { /* VHF Track: 7 */ 173 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c); 174 | } else if (freq <= 184500000) { /* VHF Track: 6 */ 175 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x18); 176 | } else if (freq <= 191500000) { /* VHF Track: 5 */ 177 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x14); 178 | } else if (freq <= 198500000) { /* VHF Track: 4 */ 179 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x10); 180 | } else if (freq <= 205500000) { /* VHF Track: 3 */ 181 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x0c); 182 | } else if (freq <= 219500000) { /* VHF Track: 2 */ 183 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x08); 184 | } else if (freq < 300000000) { /* VHF Track: 1 */ 185 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x04); 186 | } else { /* UHF and GPS */ 187 | ret = fc0013_writereg(dev, 0x1d, tmp | 0x1c); 188 | } 189 | 190 | error_out: 191 | return ret; 192 | } 193 | 194 | int fc0013_set_params(void *dev, uint32_t freq, uint32_t bandwidth) 195 | { 196 | int i, ret = 0; 197 | uint8_t reg[7], am, pm, multi, tmp; 198 | uint64_t f_vco; 199 | uint32_t xtal_freq_div_2; 200 | uint16_t xin, xdiv; 201 | int vco_select = 0; 202 | 203 | xtal_freq_div_2 = rtlsdr_get_tuner_clock(dev) / 2; 204 | 205 | /* set VHF track */ 206 | ret = fc0013_set_vhf_track(dev, freq); 207 | if (ret) 208 | goto exit; 209 | 210 | if (freq < 300000000) { 211 | /* enable VHF filter */ 212 | ret = fc0013_readreg(dev, 0x07, &tmp); 213 | if (ret) 214 | goto exit; 215 | ret = fc0013_writereg(dev, 0x07, tmp | 0x10); 216 | if (ret) 217 | goto exit; 218 | 219 | /* disable UHF & disable GPS */ 220 | ret = fc0013_readreg(dev, 0x14, &tmp); 221 | if (ret) 222 | goto exit; 223 | ret = fc0013_writereg(dev, 0x14, tmp & 0x1f); 224 | if (ret) 225 | goto exit; 226 | } else if (freq <= 862000000) { 227 | /* disable VHF filter */ 228 | ret = fc0013_readreg(dev, 0x07, &tmp); 229 | if (ret) 230 | goto exit; 231 | ret = fc0013_writereg(dev, 0x07, tmp & 0xef); 232 | if (ret) 233 | goto exit; 234 | 235 | /* enable UHF & disable GPS */ 236 | ret = fc0013_readreg(dev, 0x14, &tmp); 237 | if (ret) 238 | goto exit; 239 | ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40); 240 | if (ret) 241 | goto exit; 242 | } else { 243 | /* disable VHF filter */ 244 | ret = fc0013_readreg(dev, 0x07, &tmp); 245 | if (ret) 246 | goto exit; 247 | ret = fc0013_writereg(dev, 0x07, tmp & 0xef); 248 | if (ret) 249 | goto exit; 250 | 251 | /* enable UHF & disable GPS */ 252 | ret = fc0013_readreg(dev, 0x14, &tmp); 253 | if (ret) 254 | goto exit; 255 | ret = fc0013_writereg(dev, 0x14, (tmp & 0x1f) | 0x40); 256 | if (ret) 257 | goto exit; 258 | } 259 | 260 | /* select frequency divider and the frequency of VCO */ 261 | if (freq < 37084000) { /* freq * 96 < 3560000000 */ 262 | multi = 96; 263 | reg[5] = 0x82; 264 | reg[6] = 0x00; 265 | } else if (freq < 55625000) { /* freq * 64 < 3560000000 */ 266 | multi = 64; 267 | reg[5] = 0x02; 268 | reg[6] = 0x02; 269 | } else if (freq < 74167000) { /* freq * 48 < 3560000000 */ 270 | multi = 48; 271 | reg[5] = 0x42; 272 | reg[6] = 0x00; 273 | } else if (freq < 111250000) { /* freq * 32 < 3560000000 */ 274 | multi = 32; 275 | reg[5] = 0x82; 276 | reg[6] = 0x02; 277 | } else if (freq < 148334000) { /* freq * 24 < 3560000000 */ 278 | multi = 24; 279 | reg[5] = 0x22; 280 | reg[6] = 0x00; 281 | } else if (freq < 222500000) { /* freq * 16 < 3560000000 */ 282 | multi = 16; 283 | reg[5] = 0x42; 284 | reg[6] = 0x02; 285 | } else if (freq < 296667000) { /* freq * 12 < 3560000000 */ 286 | multi = 12; 287 | reg[5] = 0x12; 288 | reg[6] = 0x00; 289 | } else if (freq < 445000000) { /* freq * 8 < 3560000000 */ 290 | multi = 8; 291 | reg[5] = 0x22; 292 | reg[6] = 0x02; 293 | } else if (freq < 593334000) { /* freq * 6 < 3560000000 */ 294 | multi = 6; 295 | reg[5] = 0x0a; 296 | reg[6] = 0x00; 297 | } else if (freq < 950000000) { /* freq * 4 < 3800000000 */ 298 | multi = 4; 299 | reg[5] = 0x12; 300 | reg[6] = 0x02; 301 | } else { 302 | multi = 2; 303 | reg[5] = 0x0a; 304 | reg[6] = 0x02; 305 | } 306 | 307 | f_vco = freq * multi; 308 | 309 | if (f_vco >= 3060000000U) { 310 | reg[6] |= 0x08; 311 | vco_select = 1; 312 | } 313 | 314 | /* From divided value (XDIV) determined the FA and FP value */ 315 | xdiv = (uint16_t)(f_vco / xtal_freq_div_2); 316 | if ((f_vco - xdiv * xtal_freq_div_2) >= (xtal_freq_div_2 / 2)) 317 | xdiv++; 318 | 319 | pm = (uint8_t)(xdiv / 8); 320 | am = (uint8_t)(xdiv - (8 * pm)); 321 | 322 | if (am < 2) { 323 | am += 8; 324 | pm--; 325 | } 326 | 327 | if (pm > 31) { 328 | reg[1] = am + (8 * (pm - 31)); 329 | reg[2] = 31; 330 | } else { 331 | reg[1] = am; 332 | reg[2] = pm; 333 | } 334 | 335 | if ((reg[1] > 15) || (reg[2] < 0x0b)) { 336 | fprintf(stderr, "[FC0013] no valid PLL combination " 337 | "found for %u Hz!\n", freq); 338 | return -1; 339 | } 340 | 341 | /* fix clock out */ 342 | reg[6] |= 0x20; 343 | 344 | /* From VCO frequency determines the XIN ( fractional part of Delta 345 | Sigma PLL) and divided value (XDIV) */ 346 | xin = (uint16_t)((f_vco - (f_vco / xtal_freq_div_2) * xtal_freq_div_2) / 1000); 347 | xin = (xin << 15) / (xtal_freq_div_2 / 1000); 348 | if (xin >= 16384) 349 | xin += 32768; 350 | 351 | reg[3] = xin >> 8; 352 | reg[4] = xin & 0xff; 353 | 354 | reg[6] &= 0x3f; /* bits 6 and 7 describe the bandwidth */ 355 | switch (bandwidth) { 356 | case 6000000: 357 | reg[6] |= 0x80; 358 | break; 359 | case 7000000: 360 | reg[6] |= 0x40; 361 | break; 362 | case 8000000: 363 | default: 364 | break; 365 | } 366 | 367 | /* modified for Realtek demod */ 368 | reg[5] |= 0x07; 369 | 370 | for (i = 1; i <= 6; i++) { 371 | ret = fc0013_writereg(dev, i, reg[i]); 372 | if (ret) 373 | goto exit; 374 | } 375 | 376 | ret = fc0013_readreg(dev, 0x11, &tmp); 377 | if (ret) 378 | goto exit; 379 | if (multi == 64) 380 | ret = fc0013_writereg(dev, 0x11, tmp | 0x04); 381 | else 382 | ret = fc0013_writereg(dev, 0x11, tmp & 0xfb); 383 | if (ret) 384 | goto exit; 385 | 386 | /* VCO Calibration */ 387 | ret = fc0013_writereg(dev, 0x0e, 0x80); 388 | if (!ret) 389 | ret = fc0013_writereg(dev, 0x0e, 0x00); 390 | 391 | /* VCO Re-Calibration if needed */ 392 | if (!ret) 393 | ret = fc0013_writereg(dev, 0x0e, 0x00); 394 | 395 | if (!ret) { 396 | // msleep(10); 397 | ret = fc0013_readreg(dev, 0x0e, &tmp); 398 | } 399 | if (ret) 400 | goto exit; 401 | 402 | /* vco selection */ 403 | tmp &= 0x3f; 404 | 405 | if (vco_select) { 406 | if (tmp > 0x3c) { 407 | reg[6] &= ~0x08; 408 | ret = fc0013_writereg(dev, 0x06, reg[6]); 409 | if (!ret) 410 | ret = fc0013_writereg(dev, 0x0e, 0x80); 411 | if (!ret) 412 | ret = fc0013_writereg(dev, 0x0e, 0x00); 413 | } 414 | } else { 415 | if (tmp < 0x02) { 416 | reg[6] |= 0x08; 417 | ret = fc0013_writereg(dev, 0x06, reg[6]); 418 | if (!ret) 419 | ret = fc0013_writereg(dev, 0x0e, 0x80); 420 | if (!ret) 421 | ret = fc0013_writereg(dev, 0x0e, 0x00); 422 | } 423 | } 424 | 425 | exit: 426 | return ret; 427 | } 428 | 429 | int fc0013_set_gain_mode(void *dev, int manual) 430 | { 431 | int ret = 0; 432 | uint8_t tmp = 0; 433 | 434 | ret |= fc0013_readreg(dev, 0x0d, &tmp); 435 | 436 | if (manual) 437 | tmp |= (1 << 3); 438 | else 439 | tmp &= ~(1 << 3); 440 | 441 | ret |= fc0013_writereg(dev, 0x0d, tmp); 442 | 443 | /* set a fixed IF-gain for now */ 444 | ret |= fc0013_writereg(dev, 0x13, 0x0a); 445 | 446 | return ret; 447 | } 448 | 449 | int fc0013_lna_gains[] ={ 450 | -99, 0x02, 451 | -73, 0x03, 452 | -65, 0x05, 453 | -63, 0x04, 454 | -63, 0x00, 455 | -60, 0x07, 456 | -58, 0x01, 457 | -54, 0x06, 458 | 58, 0x0f, 459 | 61, 0x0e, 460 | 63, 0x0d, 461 | 65, 0x0c, 462 | 67, 0x0b, 463 | 68, 0x0a, 464 | 70, 0x09, 465 | 71, 0x08, 466 | 179, 0x17, 467 | 181, 0x16, 468 | 182, 0x15, 469 | 184, 0x14, 470 | 186, 0x13, 471 | 188, 0x12, 472 | 191, 0x11, 473 | 197, 0x10 474 | }; 475 | 476 | #define GAIN_CNT (sizeof(fc0013_lna_gains) / sizeof(int) / 2) 477 | 478 | int fc0013_set_lna_gain(void *dev, int gain) 479 | { 480 | int ret = 0; 481 | unsigned int i; 482 | uint8_t tmp = 0; 483 | 484 | ret |= fc0013_readreg(dev, 0x14, &tmp); 485 | 486 | /* mask bits off */ 487 | tmp &= 0xe0; 488 | 489 | for (i = 0; i < GAIN_CNT; i++) { 490 | if ((fc0013_lna_gains[i*2] >= gain) || (i+1 == GAIN_CNT)) { 491 | tmp |= fc0013_lna_gains[i*2 + 1]; 492 | break; 493 | } 494 | } 495 | 496 | /* set gain */ 497 | ret |= fc0013_writereg(dev, 0x14, tmp); 498 | 499 | return ret; 500 | } 501 | --------------------------------------------------------------------------------