├── .gitignore ├── Makefile ├── README.md ├── libmirisdr-2 ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── Doxyfile.in ├── HOWTO ├── Makefile.am ├── README ├── build.sh ├── cmake │ ├── Modules │ │ ├── FindLibUSB.cmake │ │ ├── FindThreads.cmake │ │ └── Version.cmake │ └── cmake_uninstall.cmake.in ├── configure.ac ├── git-version-gen ├── include │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── mirisdr.h │ └── mirisdr_export.h ├── libmirisdr.pc.in ├── mirisdr.rules └── src │ ├── CMakeLists.txt │ ├── Makefile.am │ ├── adc.c │ ├── async.c │ ├── async.h │ ├── constants.h │ ├── convenience.c │ ├── convert │ ├── 252_s16.c │ ├── 336_s16.c │ ├── 384_s16.c │ ├── 504_s16.c │ ├── 504_s8.c │ └── base.c │ ├── devices.c │ ├── gain.c │ ├── gain.h │ ├── getopt │ ├── getopt.c │ └── getopt.h │ ├── hard.c │ ├── hard.h │ ├── libmirisdr.c │ ├── miri_fm.c │ ├── miri_sdr.c │ ├── reg.c │ ├── soft.c │ ├── soft.h │ ├── streaming.c │ ├── structs.h │ └── sync.c ├── librtlsdr ├── .gitignore ├── .travis.yml ├── AUTHORS ├── CMakeLists.txt ├── COPYING ├── Doxyfile.in ├── Makefile.am ├── README ├── cmake │ └── cmake_uninstall.cmake.in ├── configure.ac ├── 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_gpio.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 ├── star_fm ├── Makefile ├── Readme.txt ├── convenience.c ├── convenience.h ├── display.c └── star_fm.c └── starsdr ├── COPYING ├── COPYING.LESSER ├── Makefile ├── display.c ├── mirisdr.h ├── mirisdr_export.h ├── rtl-sdr.h ├── rtl-sdr_export.h ├── starsdr_ext.h ├── starsdr_mirics.c └── starsdr_rtlsdr.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.sw[op] 2 | out 3 | star_fm/star_fm 4 | rtl_biast 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # (c) 2016 Outernet Inc 2 | # This file is part of StarSDR. 3 | 4 | # StarSDR is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Lesseer General Public License as 6 | # published by the Free Software Foundation, either version 3 of 7 | # the License, or (at your option) any later version. 8 | 9 | # StarSDR 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 Lesser General Public License for more details. 13 | 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with StarSDR. If not, see . 16 | 17 | # cross compile examples 18 | # for arm: 19 | # CC=arm-buildroot-linux-gnueabihf-gcc make libs 20 | # for x64 21 | # make libs 22 | # for x32 23 | # CFLAGS=-m32 make libs 24 | 25 | CC ?=gcc 26 | CC_PATH=$(shell which $(CC)) 27 | PKGCONFIG=$(shell dirname $(CC_PATH))/pkg-config 28 | OUTDIR=$(shell pwd)/out/ 29 | LIBUSB_CFLAGS=$(shell $(PKGCONFIG) libusb-1.0 --cflags) 30 | LIBUSB_LFLAGS=$(shell $(PKGCONFIG) libusb-1.0 --libs) 31 | PREFIX ?= /usr/local 32 | BINDIR = $(PREFIX)/bin 33 | SDRD = $(PREFIX)/sdr.d 34 | RTLDIR = $(SDRD)/starsdr-rtlsdr 35 | MIRDIR = $(SDRD)/starsdr-mirics 36 | 37 | 38 | .PHONY: clean clean_all libs all libmirisdr librtlsdr starsdr rtl_fm star_fm \ 39 | outdir release installables install uninstall 40 | 41 | libs: outdir libmirisdr librtlsdr starsdr 42 | 43 | installables: libs rtl_biast 44 | 45 | all: libs star_fm rtl_biast 46 | 47 | install: 48 | install -Dm755 ./rtl_biast $(BINDIR)/rtl_biast 49 | install -Dm755 $(OUTDIR)/librtlsdr.so $(RTLDIR)/librtlsdr.so 50 | install -Dm755 $(OUTDIR)libstarsdr_rtlsdr.so $(RTLDIR)/libstarsdr.so 51 | install -Dm755 $(OUTDIR)/libmirisdr.so $(MIRDIR)/libmirisdr.so 52 | install -Dm755 $(OUTDIR)libstarsdr_mirics.so $(MIRDIR)/libstarsdr.so 53 | 54 | uninstall: 55 | -rm -rf $(SDRD) 56 | -rm $(BINDIR)/rtl_biast 57 | 58 | clean: 59 | rm -rf $(OUTDIR) 60 | 61 | clean_all: clean 62 | make -C star_fm clean 63 | rm -f rtl_biast 64 | 65 | outdir: 66 | mkdir -p $(OUTDIR) 67 | 68 | libmirisdr: libmirisdr-2/src/libmirisdr.c 69 | $(CC) -Wall -O3 -fPIC $(CFLAGS) $(LIBSDR_CFLAGS) -shared \ 70 | -o $(OUTDIR)libmirisdr.so -Ilibmirisdr-2/include $(LIBUSB_CFLAGS) $^ $(LFLAGS) $(LIBSDR_LFLAGS) $(LIBUSB_LFLAGS) 71 | 72 | librtlsdr: $(addprefix librtlsdr/src/, librtlsdr.c tuner_e4k.c tuner_fc0012.c tuner_fc0013.c tuner_fc2580.c tuner_r82xx.c) 73 | $(CC) -Wall -Wno-unused-function -Wno-unused-variable -O3 -fPIC $(CFLAGS) $(LIBSDR_CFLAGS) -shared -o $(OUTDIR)librtlsdr.so \ 74 | -Ilibrtlsdr/include $(LIBUSB_CFLAGS) $^ $(LFLAGS) $(LIBSDR_LFLAGS) $(LIBUSB_LFLAGS) 75 | 76 | starsdr: 77 | OUTDIR=$(OUTDIR) DEPS=$(OUTDIR) CC=$(CC) CFLAGS=$(CFLAGS) LFLAGS=$(LFLAGS) FLAGS=$(FLAGS) make -C starsdr 78 | cp starsdr/starsdr_ext.h $(OUTDIR) 79 | 80 | star_fm: 81 | DEPS=$(OUTDIR) CC=$(CC) CFLAGS=$(CFLAGS) LFLAGS=$(LFLAGS) FLAGS=$(FLAGS) make -C star_fm 82 | 83 | rtl_biast: librtlsdr/src/rtl_biast.c 84 | $(CC) -Wall -O3 $(CFLAGS) -o rtl_biast -Ilibrtlsdr/include -I$(OUTDIR) $^ $(LFLAGS) -L$(OUTDIR) -lrtlsdr 85 | 86 | release: libs 87 | mv $(OUTDIR) starsdr_release_$(VER) 88 | tar acf starsdr_release_$(VER).tgz starsdr_release_$(VER) 89 | mv starsdr_release_$(VER).tgz starsdr_release_$(VER) .. 90 | echo Made starsdr_release_$(VER) 91 | 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # StarSDR - Utilities for SDRs 2 | 3 | ## Installing the build dependencies 4 | 5 | To build StarSDR, build tools will need to be installed. On most distros, the 6 | build tools usually come as a single package/metapackage that are named 7 | `build-essential`, `base-devel`, and similar. Additionally `pkg-config` and 8 | development headers for `libusb` 1.0 should also be installed. 9 | 10 | Here are some ways to install them on different distros. 11 | 12 | Ubuntu/Debian and derivatives: 13 | 14 | $ sudo apt-get install build-essential pkg-config libusb-1.0-0-dev 15 | 16 | Fedora: 17 | 18 | $ sudo yum groupinstall "Development Tools" "Development Libraries" 19 | $ sudo yum install libusb1 pkgconfig 20 | 21 | Arch Linux: 22 | 23 | $ sudo pacman -Sy base-devel pkg-config libusb 24 | 25 | Opensuse: 26 | 27 | $ sudo zypper install --type pattern devel_basis 28 | $ sudo zypper install pkg-config libusb-1_0 29 | 30 | **Note:** If your distro is not covered here and you are not sure how to 31 | install the build tools, try searching online for ‘build-essential equivalent 32 | for **’. 33 | 34 | ## Compiling and installing 35 | 36 | To compile and install, run the following commands: 37 | 38 | $ make installables 39 | $ sudo make install 40 | 41 | By default, this results in libraries being installed in `/usr/local/sdr.d`, 42 | and `rtl_biast` being installed in `/usr/local/bin`. If you want to change the 43 | install location, use the `PREFIX` variable: 44 | 45 | $ sudo make PREFIX='/my/path' install 46 | -------------------------------------------------------------------------------- /libmirisdr-2/AUTHORS: -------------------------------------------------------------------------------- 1 | Miroslav Slugen 2 | -------------------------------------------------------------------------------- /libmirisdr-2/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2012 OSMOCOM Project 2 | # 3 | # This file is part of MiriSDR 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 | # Project setup 22 | ######################################################################## 23 | cmake_minimum_required(VERSION 2.6) 24 | project(mirisdr C) 25 | 26 | #select the release build type by default to get optimization flags 27 | if(NOT CMAKE_BUILD_TYPE) 28 | set(CMAKE_BUILD_TYPE "Release") 29 | message(STATUS "Build type not specified: defaulting to release.") 30 | endif(NOT CMAKE_BUILD_TYPE) 31 | set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") 32 | 33 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) 34 | 35 | # Set the version information here 36 | set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes 37 | set(VERSION_INFO_MINOR_VERSION 0) # increment minor on feature-level changes 38 | set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs 39 | include(Version) # setup version info 40 | 41 | ######################################################################## 42 | # Compiler specific setup 43 | ######################################################################## 44 | if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32) 45 | ADD_DEFINITIONS(-Wall) 46 | ADD_DEFINITIONS(-Wextra) 47 | ADD_DEFINITIONS(-Wno-unused) 48 | ADD_DEFINITIONS(-Wsign-compare) 49 | #http://gcc.gnu.org/wiki/Visibility 50 | add_definitions(-fvisibility=hidden) 51 | endif() 52 | 53 | ######################################################################## 54 | # Find build dependencies 55 | ######################################################################## 56 | find_package(PkgConfig) 57 | find_package(LibUSB) 58 | set(THREADS_USE_PTHREADS_WIN32 true) 59 | find_package(Threads) 60 | 61 | if(NOT LIBUSB_FOUND) 62 | message(FATAL_ERROR "LibUSB 1.0 required to compile MiriSDR") 63 | endif() 64 | 65 | ######################################################################## 66 | # Setup the include and linker paths 67 | ######################################################################## 68 | include_directories( 69 | ${CMAKE_SOURCE_DIR}/include 70 | ${LIBUSB_INCLUDE_DIR} 71 | ) 72 | 73 | #link_directories( 74 | # ... 75 | #) 76 | 77 | # Set component parameters 78 | #set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) 79 | 80 | ######################################################################## 81 | # Create uninstall target 82 | ######################################################################## 83 | configure_file( 84 | ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in 85 | ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake 86 | @ONLY) 87 | 88 | add_custom_target(uninstall 89 | ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake 90 | ) 91 | 92 | ######################################################################## 93 | # Add subdirectories 94 | ######################################################################## 95 | add_subdirectory(include) 96 | add_subdirectory(src) 97 | 98 | ######################################################################## 99 | # Create Pkg Config File 100 | ######################################################################## 101 | FOREACH(inc ${LIBUSB_INCLUDE_DIR}) 102 | LIST(APPEND MIRISDR_PC_CFLAGS "-I${inc}") 103 | ENDFOREACH(inc) 104 | 105 | FOREACH(lib ${LIBUSB_LIBRARY_DIRS}) 106 | LIST(APPEND MIRISDR_PC_LIBS "-L${lib}") 107 | ENDFOREACH(lib) 108 | 109 | # use space-separation format for the pc file 110 | STRING(REPLACE ";" " " MIRISDR_PC_CFLAGS "${MIRISDR_PC_CFLAGS}") 111 | STRING(REPLACE ";" " " MIRISDR_PC_LIBS "${MIRISDR_PC_LIBS}") 112 | 113 | # unset these vars to avoid hard-coded paths to cross environment 114 | IF(CMAKE_CROSSCOMPILING) 115 | UNSET(MIRISDR_PC_CFLAGS) 116 | UNSET(MIRISDR_PC_LIBS) 117 | ENDIF(CMAKE_CROSSCOMPILING) 118 | 119 | set(prefix ${CMAKE_INSTALL_PREFIX}) 120 | set(exec_prefix \${prefix}) 121 | set(libdir \${exec_prefix}/lib) 122 | set(includedir \${prefix}/include) 123 | 124 | CONFIGURE_FILE( 125 | ${CMAKE_CURRENT_SOURCE_DIR}/libmirisdr.pc.in 126 | ${CMAKE_CURRENT_BINARY_DIR}/libmirisdr.pc 127 | @ONLY) 128 | 129 | INSTALL( 130 | FILES ${CMAKE_CURRENT_BINARY_DIR}/libmirisdr.pc 131 | DESTINATION lib/pkgconfig 132 | ) 133 | 134 | ######################################################################## 135 | # Print Summary 136 | ######################################################################## 137 | MESSAGE(STATUS "Building for version: ${VERSION} / ${LIBVER}") 138 | MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}") 139 | -------------------------------------------------------------------------------- /libmirisdr-2/HOWTO: -------------------------------------------------------------------------------- 1 | # vytvoření 2 | git init 3 | git add . 4 | git commit -m "Initial commit" 5 | git remote add libmirisdr-2 http://code.google.com/p/libmirisdr-2/ 6 | git push libmirisdr-2 master 7 | 8 | # doplnění 9 | git add * 10 | git commit -m 'co se změnilo' 11 | git push libmirisdr-2 master 12 | -------------------------------------------------------------------------------- /libmirisdr-2/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 = libosmosdr.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 | EXTRA_DIST = git-version-gen 17 | 18 | if HAVE_DOXYGEN 19 | 20 | pkgdocdir=$(docdir)/$(PACKAGE)-$(VERSION) 21 | doc_htmldir=$(pkgdocdir)/html 22 | 23 | doc_html_DATA = $(top_builddir)/doc/html.tar 24 | 25 | $(doc_html_DATA): $(top_builddir)/doc/html/index.html 26 | cd $(top_builddir)/doc && tar cf html.tar html 27 | 28 | $(top_builddir)/doc/html/index.html: $(SOURCES) Doxyfile 29 | @rm -rf doc 30 | mkdir -p doc 31 | $(DOXYGEN) Doxyfile 32 | 33 | install-data-hook: 34 | cd $(DESTDIR)$(doc_htmldir) && tar xf html.tar --strip-components 1 && rm -f html.tar 35 | 36 | uninstall-hook: 37 | cd $(DESTDIR) && rm -rf $(doc_htmldir) 38 | 39 | DX_CLEAN = doc/{html,latex}/* doc/html.tar 40 | 41 | endif 42 | 43 | MOSTLYCLEANFILES = $(DX_CLEAN) 44 | -------------------------------------------------------------------------------- /libmirisdr-2/README: -------------------------------------------------------------------------------- 1 | For more information see: 2 | http://sdr.osmocom.org 3 | -------------------------------------------------------------------------------- /libmirisdr-2/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | mkdir build 4 | pushd ./build 5 | cmake ../ 6 | make 7 | popd 8 | -------------------------------------------------------------------------------- /libmirisdr-2/cmake/Modules/FindLibUSB.cmake: -------------------------------------------------------------------------------- 1 | if(NOT LIBUSB_FOUND) 2 | pkg_check_modules (LIBUSB_PKG libusb-1.0) 3 | find_path(LIBUSB_INCLUDE_DIR NAMES libusb.h 4 | PATHS 5 | ${LIBUSB_PKG_INCLUDE_DIRS} 6 | /usr/include/libusb-1.0 7 | /usr/include 8 | /usr/local/include 9 | ) 10 | 11 | find_library(LIBUSB_LIBRARIES NAMES usb-1.0 12 | PATHS 13 | ${LIBUSB_PKG_LIBRARY_DIRS} 14 | /usr/lib 15 | /usr/local/lib 16 | ) 17 | 18 | if(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) 19 | set(LIBUSB_FOUND TRUE CACHE INTERNAL "libusb-1.0 found") 20 | message(STATUS "Found libusb-1.0: ${LIBUSB_INCLUDE_DIR}, ${LIBUSB_LIBRARIES}") 21 | else(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) 22 | set(LIBUSB_FOUND FALSE CACHE INTERNAL "libusb-1.0 found") 23 | message(STATUS "libusb-1.0 not found.") 24 | endif(LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) 25 | 26 | mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES) 27 | 28 | endif(NOT LIBUSB_FOUND) 29 | -------------------------------------------------------------------------------- /libmirisdr-2/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 | -------------------------------------------------------------------------------- /libmirisdr-2/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 | -------------------------------------------------------------------------------- /libmirisdr-2/configure.ac: -------------------------------------------------------------------------------- 1 | AC_INIT([libmirisdr], 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 | LT_INIT 15 | AC_PROG_LIBTOOL 16 | 17 | PKG_CHECK_MODULES(LIBUSB, libusb-1.0 >= 1.0) 18 | LIBS="$LIBS $LIBUSB_LIBS" 19 | CFLAGS="$CFLAGS $LIBUSB_CFLAGS" 20 | 21 | AC_PATH_PROG(DOXYGEN,doxygen,false) 22 | AM_CONDITIONAL(HAVE_DOXYGEN, test $DOXYGEN != false) 23 | 24 | AC_CONFIG_MACRO_DIR([m4]) 25 | 26 | dnl checks for header files 27 | AC_HEADER_STDC 28 | AC_CHECK_HEADERS(sys/types.h) 29 | 30 | # pc variables 31 | AC_SUBST(MIRISDR_PC_LIBS,["$LIBS"]) 32 | AC_SUBST(MIRISDR_PC_CFLAGS,["$CFLAGS"]) 33 | 34 | # The following test is taken from WebKit's webkit.m4 35 | saved_CFLAGS="$CFLAGS" 36 | CFLAGS="$CFLAGS -fvisibility=hidden " 37 | AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden]) 38 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])], 39 | [ AC_MSG_RESULT([yes]) 40 | SYMBOL_VISIBILITY="-fvisibility=hidden"], 41 | AC_MSG_RESULT([no])) 42 | CFLAGS="$saved_CFLAGS" 43 | AC_SUBST(SYMBOL_VISIBILITY) 44 | 45 | AC_MSG_CHECKING(whether compiler understands -Wall) 46 | old_CFLAGS="$CFLAGS" 47 | CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused -Wsign-compare" 48 | AC_TRY_COMPILE([],[], 49 | AC_MSG_RESULT(yes), 50 | AC_MSG_RESULT(no) 51 | CFLAGS="$old_CFLAGS") 52 | 53 | dnl Generate the output 54 | AC_CONFIG_HEADER(config.h) 55 | 56 | AC_OUTPUT( 57 | libmirisdr.pc 58 | include/Makefile 59 | src/Makefile 60 | Makefile 61 | Doxyfile 62 | ) 63 | -------------------------------------------------------------------------------- /libmirisdr-2/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 | -------------------------------------------------------------------------------- /libmirisdr-2/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2012 OSMOCOM Project 2 | # 3 | # This file is part of MiriSDR 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 | mirisdr.h 25 | mirisdr_export.h 26 | DESTINATION include 27 | ) 28 | -------------------------------------------------------------------------------- /libmirisdr-2/include/Makefile.am: -------------------------------------------------------------------------------- 1 | mirisdr_HEADERS = mirisdr.h mirisdr_export.h 2 | 3 | mirisdrdir = $(includedir) 4 | -------------------------------------------------------------------------------- /libmirisdr-2/include/mirisdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 by Steve Markgraf 3 | * Copyright (C) 2012 by Dimitri Stolnikov 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 __MIRISDR_H 20 | #define __MIRISDR_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #define mirisdr_STATIC 27 | 28 | /* uncommnet to get extended debug */ 29 | //#define MIRISDR_DEBUG 30 | 31 | #include 32 | #include 33 | 34 | typedef struct mirisdr_dev mirisdr_dev_t; 35 | 36 | /* devices */ 37 | MIRISDR_API uint32_t mirisdr_get_device_count (void); 38 | MIRISDR_API const char *mirisdr_get_device_name (uint32_t index); 39 | MIRISDR_API int mirisdr_get_device_usb_strings (uint32_t index, char *manufact, char *product, char *serial); 40 | 41 | /* main */ 42 | MIRISDR_API int mirisdr_open (mirisdr_dev_t **p, uint32_t index); 43 | MIRISDR_API int mirisdr_close (mirisdr_dev_t *p); 44 | MIRISDR_API int mirisdr_reset (mirisdr_dev_t *p); /* extra */ 45 | MIRISDR_API int mirisdr_reset_buffer (mirisdr_dev_t *p); 46 | MIRISDR_API int mirisdr_get_usb_strings (mirisdr_dev_t *dev, char *manufact, char *product, char *serial); 47 | 48 | /* sync */ 49 | MIRISDR_API int mirisdr_read_sync (mirisdr_dev_t *p, void *buf, int len, int *n_read); 50 | 51 | /* async */ 52 | typedef void(*mirisdr_read_async_cb_t) (unsigned char *buf, uint32_t len, void *ctx); 53 | MIRISDR_API int mirisdr_read_async (mirisdr_dev_t *p, mirisdr_read_async_cb_t cb, void *ctx, uint32_t num, uint32_t len); 54 | MIRISDR_API int mirisdr_cancel_async (mirisdr_dev_t *p); 55 | MIRISDR_API int mirisdr_cancel_async_now (mirisdr_dev_t *p); /* extra */ 56 | MIRISDR_API int mirisdr_start_async (mirisdr_dev_t *p); /* extra */ 57 | MIRISDR_API int mirisdr_stop_async (mirisdr_dev_t *p); /* extra */ 58 | 59 | /* adc */ 60 | MIRISDR_API int mirisdr_adc_init (mirisdr_dev_t *p); /* extra */ 61 | 62 | /* rate control */ 63 | MIRISDR_API int mirisdr_set_sample_rate (mirisdr_dev_t *p, uint32_t rate); 64 | MIRISDR_API uint32_t mirisdr_get_sample_rate (mirisdr_dev_t *p); 65 | 66 | /* sample format control */ 67 | MIRISDR_API int mirisdr_set_sample_format (mirisdr_dev_t *p, char *v); /* extra */ 68 | MIRISDR_API const char *mirisdr_get_sample_format (mirisdr_dev_t *p); /* extra */ 69 | 70 | /* streaming control */ 71 | MIRISDR_API int mirisdr_streaming_start (mirisdr_dev_t *p); /* extra */ 72 | MIRISDR_API int mirisdr_streaming_stop (mirisdr_dev_t *p); /* extra */ 73 | 74 | /* frequency */ 75 | MIRISDR_API int mirisdr_set_center_freq (mirisdr_dev_t *p, uint32_t freq); 76 | MIRISDR_API uint32_t mirisdr_get_center_freq (mirisdr_dev_t *p); 77 | MIRISDR_API int mirisdr_set_if_freq (mirisdr_dev_t *p, uint32_t freq); /* extra */ 78 | MIRISDR_API uint32_t mirisdr_get_if_freq (mirisdr_dev_t *p); /* extra */ 79 | MIRISDR_API int mirisdr_set_xtal_freq (mirisdr_dev_t *p, uint32_t freq);/* extra */ 80 | MIRISDR_API uint32_t mirisdr_get_xtal_freq (mirisdr_dev_t *p); /* extra */ 81 | MIRISDR_API int mirisdr_set_bandwidth (mirisdr_dev_t *p, uint32_t bw); /* extra */ 82 | MIRISDR_API uint32_t mirisdr_get_bandwidth (mirisdr_dev_t *p); /* extra */ 83 | MIRISDR_API int mirisdr_set_offset_tuning (mirisdr_dev_t *p, int on); /* extra */ 84 | 85 | /* not implemented yet */ 86 | MIRISDR_API int mirisdr_set_freq_correction (mirisdr_dev_t *p, int ppm); 87 | MIRISDR_API int mirisdr_set_direct_sampling (mirisdr_dev_t *p, int on); 88 | 89 | /* transfer */ 90 | MIRISDR_API int mirisdr_set_transfer (mirisdr_dev_t *p, char *v); /* extra */ 91 | MIRISDR_API const char *mirisdr_get_transfer (mirisdr_dev_t *p); /* extra */ 92 | 93 | /* gain */ 94 | MIRISDR_API int mirisdr_set_gain (mirisdr_dev_t *p); /* extra */ 95 | MIRISDR_API int mirisdr_get_tuner_gains (mirisdr_dev_t *dev, float *gains); 96 | MIRISDR_API int mirisdr_set_tuner_gain (mirisdr_dev_t *p, int gain); 97 | MIRISDR_API int mirisdr_get_tuner_gain (mirisdr_dev_t *p); /* extra */ 98 | MIRISDR_API int mirisdr_set_tuner_gain_mode (mirisdr_dev_t *p, int mode); 99 | MIRISDR_API int mirisdr_get_tuner_gain_mode (mirisdr_dev_t *p); /* extra */ 100 | MIRISDR_API int mirisdr_set_mixer_gain (mirisdr_dev_t *p, int gain); /* extra */ 101 | MIRISDR_API int mirisdr_set_lna_gain (mirisdr_dev_t *p, int gain); /* extra */ 102 | MIRISDR_API int mirisdr_set_baseband_gain (mirisdr_dev_t *p, int gain); /* extra */ 103 | MIRISDR_API int mirisdr_get_mixer_gain (mirisdr_dev_t *p); /* extra */ 104 | MIRISDR_API int mirisdr_get_lna_gain (mirisdr_dev_t *p); /* extra */ 105 | MIRISDR_API int mirisdr_get_baseband_gain (mirisdr_dev_t *p); /* extra */ 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* __MIRISDR_H */ 112 | -------------------------------------------------------------------------------- /libmirisdr-2/include/mirisdr_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #ifndef __MIRISDR_EXPORT_H 19 | #define __MIRISDR_EXPORT_H 20 | 21 | #if defined __GNUC__ 22 | # if __GNUC__ >= 4 23 | # define __SDR_EXPORT __attribute__((visibility("default"))) 24 | # define __SDR_IMPORT __attribute__((visibility("default"))) 25 | # else 26 | # define __SDR_EXPORT 27 | # define __SDR_IMPORT 28 | # endif 29 | #elif _MSC_VER 30 | # define __SDR_EXPORT __declspec(dllexport) 31 | # define __SDR_IMPORT __declspec(dllimport) 32 | #else 33 | # define __SDR_EXPORT 34 | # define __SDR_IMPORT 35 | #endif 36 | 37 | #ifndef mirisdr_STATIC 38 | # ifdef mirisdr_EXPORTS 39 | # define MIRISDR_API __SDR_EXPORT 40 | # else 41 | # define MIRISDR_API __SDR_IMPORT 42 | # endif 43 | #else 44 | # define MIRISDR_API 45 | #endif 46 | #endif /* __MIRISDR_EXPORT_H */ 47 | -------------------------------------------------------------------------------- /libmirisdr-2/libmirisdr.pc.in: -------------------------------------------------------------------------------- 1 | prefix=@prefix@ 2 | exec_prefix=@exec_prefix@ 3 | libdir=@libdir@ 4 | includedir=@includedir@ 5 | 6 | Name: MiriSDR Library 7 | Description: C Utility Library 8 | Version: @VERSION@ 9 | Cflags: -I${includedir}/ @MIRISDR_PC_CFLAGS@ 10 | Libs: -L${libdir} -lmirisdr -lusb-1.0 11 | Libs.private: @MIRISDR_PC_LIBS@ 12 | -------------------------------------------------------------------------------- /libmirisdr-2/mirisdr.rules: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2012 Osmocom MiriSDR 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 | # Mirics MSi2500 default (e.g. VTX3D card) 19 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1df7", ATTRS{idProduct}=="2500", MODE:="0666" 20 | 21 | # IO-DATA GV-TV100 stick 22 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="04bb", ATTRS{idProduct}=="0537", MODE:="0666" 23 | -------------------------------------------------------------------------------- /libmirisdr-2/src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2012 OSMOCOM Project 2 | # 3 | # This file is part of MiriSDR 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 | # Setup library 22 | ######################################################################## 23 | add_library(mirisdr_shared SHARED 24 | libmirisdr.c 25 | ) 26 | 27 | target_link_libraries(mirisdr_shared 28 | ${LIBUSB_LIBRARIES} 29 | ) 30 | 31 | set_target_properties(mirisdr_shared PROPERTIES DEFINE_SYMBOL "mirisdr_EXPORTS") 32 | set_target_properties(mirisdr_shared PROPERTIES OUTPUT_NAME mirisdr) 33 | set_target_properties(mirisdr_shared PROPERTIES SOVERSION ${MAJOR_VERSION}) 34 | set_target_properties(mirisdr_shared PROPERTIES VERSION ${LIBVER}) 35 | 36 | add_library(mirisdr_static STATIC 37 | libmirisdr.c 38 | ) 39 | 40 | if(WIN32) 41 | add_library(libgetopt_static STATIC 42 | getopt/getopt.c 43 | ) 44 | endif() 45 | 46 | target_link_libraries(mirisdr_static 47 | ${LIBUSB_LIBRARIES} 48 | ) 49 | 50 | set_property(TARGET mirisdr_static APPEND PROPERTY COMPILE_DEFINITIONS "mirisdr_STATIC" ) 51 | 52 | if(NOT WIN32) 53 | # Force same library filename for static and shared variants of the library 54 | set_target_properties(mirisdr_static PROPERTIES OUTPUT_NAME mirisdr) 55 | endif() 56 | 57 | ######################################################################## 58 | # Build utility 59 | ######################################################################## 60 | add_executable(miri_sdr miri_sdr.c) 61 | add_executable(miri_fm miri_fm.c) 62 | set(INSTALL_TARGETS mirisdr_shared mirisdr_static miri_sdr miri_fm) 63 | 64 | target_link_libraries(miri_sdr mirisdr_shared 65 | ${LIBUSB_LIBRARIES} 66 | ${CMAKE_THREAD_LIBS_INIT} 67 | ) 68 | 69 | target_link_libraries(miri_fm mirisdr_shared 70 | ${LIBUSB_LIBRARIES} 71 | ${CMAKE_THREAD_LIBS_INIT} 72 | ) 73 | 74 | if(UNIX) 75 | target_link_libraries(miri_fm m) 76 | endif() 77 | 78 | if(WIN32) 79 | target_link_libraries(miri_sdr libgetopt_static) 80 | target_link_libraries(miri_fm libgetopt_static) 81 | set_property(TARGET miri_sdr APPEND PROPERTY COMPILE_DEFINITIONS "mirisdr_STATIC" ) 82 | set_property(TARGET miri_fm APPEND PROPERTY COMPILE_DEFINITIONS "mirisdr_STATIC" ) 83 | endif() 84 | 85 | ######################################################################## 86 | # Install built library files & utilities 87 | ######################################################################## 88 | install(TARGETS ${INSTALL_TARGETS} 89 | LIBRARY DESTINATION lib${LIB_SUFFIX} # .so/.dylib file 90 | ARCHIVE DESTINATION lib${LIB_SUFFIX} # .lib file 91 | RUNTIME DESTINATION bin # .dll file 92 | ) 93 | -------------------------------------------------------------------------------- /libmirisdr-2/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:0:0 4 | 5 | INCLUDES = $(all_includes) -I$(top_srcdir)/include 6 | AM_CFLAGS = ${CFLAGS} -fPIC ${SYMBOL_VISIBILITY} 7 | 8 | lib_LTLIBRARIES = libmirisdr.la 9 | 10 | libmirisdr_la_SOURCES = libmirisdr.c 11 | libmirisdr_la_LDFLAGS = -version-info $(LIBVERSION) 12 | 13 | bin_PROGRAMS = miri_sdr miri_fm 14 | 15 | miri_sdr_SOURCES = miri_sdr.c 16 | miri_sdr_LDADD = libmirisdr.la 17 | 18 | miri_fm_SOURCES = miri_fm.c 19 | miri_fm_LDADD = libmirisdr.la $(LIBM) 20 | -------------------------------------------------------------------------------- /libmirisdr-2/src/adc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | int mirisdr_adc_init (mirisdr_dev_t *p) { 19 | if (!p) goto failed; 20 | 21 | /* inicializace - statická */ 22 | mirisdr_write_reg(p, 0x08, 0x006080); /* kernel driver */ 23 | mirisdr_write_reg(p, 0x05, 0x00000c); 24 | mirisdr_write_reg(p, 0x00, 0x000200); 25 | mirisdr_write_reg(p, 0x02, 0x004801); 26 | mirisdr_write_reg(p, 0x08, 0x00f380); /* kernel driver */ 27 | 28 | return 0; 29 | 30 | failed: 31 | return -1; 32 | } 33 | -------------------------------------------------------------------------------- /libmirisdr-2/src/async.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #define DEFAULT_ISO_BUFFER 1024 19 | #define DEFAULT_ISO_BUFFERS 3 20 | #define DEFAULT_ISO_PACKETS 8 21 | #define DEFAULT_ISO_TIMEOUT 1000 22 | 23 | #define DEFAULT_BULK_BUFFER 16384 24 | #define DEFAULT_BULK_TIMEOUT 1000 25 | 26 | #define DEFAULT_BUF_NUMBER 32 27 | -------------------------------------------------------------------------------- /libmirisdr-2/src/constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #define CTRL_TIMEOUT 2000 19 | 20 | #define DEFAULT_RATE 2000000 21 | #define DEFAULT_FREQ 90000000 22 | #define DEFAULT_GAIN 43 23 | -------------------------------------------------------------------------------- /libmirisdr-2/src/convert/252_s16.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 14 bitový formát 4 | * 1024 bajtů odpovídá 504 hodnotám 5 | * struktura: 6 | * 16b hlavička 7 | * 1008b bloků obsahujících 504 14b hodnot tvářících se jako 16b 8 | */ 9 | static int mirisdr_samples_convert_252_s16 (mirisdr_dev_t *p, unsigned char* buf, uint8_t *dst8, int cnt) { 10 | int i, i_max, j, ret = 0; 11 | uint32_t addr = 0; 12 | uint8_t *src = buf; 13 | int16_t *dst = (int16_t*) dst8; 14 | 15 | /* dostáváme 1-3 1024 bytů dlouhé bloky */ 16 | for (i_max = cnt >> 10, i = 0; i < i_max; i++, src+= 1008) { 17 | /* pozice hlavičky */ 18 | addr = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0; 19 | 20 | /* potenciálně ztracená data */ 21 | if ((i == 0) && (addr != p->addr)) { 22 | fprintf(stderr, "%u samples lost, %d, %08x:%08x\n", addr - p->addr, cnt, p->addr, addr); 23 | } 24 | 25 | /* přeskočíme hlavičku 16 bitů, 252 I+Q párů */ 26 | for (src+= 16, j = 0; j < 1008; j+= 4, ret+= 2) { 27 | /* maximální rozsah */ 28 | dst[ret + 0] = (src[j + 0]) | (src[j + 1] << 8); 29 | dst[ret + 1] = (src[j + 2]) | (src[j + 3] << 8); 30 | //dst[ret + 0] = src[j + 1]; 31 | //dst[ret + 1] = src[j + 3]; 32 | } 33 | } 34 | 35 | p->addr = addr + 252; 36 | 37 | /* total used bytes */ 38 | return ret * 2; 39 | } 40 | -------------------------------------------------------------------------------- /libmirisdr-2/src/convert/336_s16.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 12 bitový formát 4 | * 1024 bajtů odpovídá 672 hodnotám 5 | * struktura: 6 | * 16b hlavička 7 | * 1008b bloků obsahujících 672 12b hodnot 8 | */ 9 | static int mirisdr_samples_convert_336_s16 (mirisdr_dev_t *p, unsigned char* buf, uint8_t *dst8, int cnt) { 10 | int i, i_max, j, ret = 0; 11 | uint32_t addr = 0; 12 | uint8_t *src = buf; 13 | int16_t *dst = (int16_t*) dst8; 14 | 15 | /* dostáváme 1-3 1024 bytů dlouhé bloky */ 16 | for (i_max = cnt >> 10, i = 0; i < i_max; i++, src+= 1008) { 17 | /* pozice hlavičky */ 18 | addr = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0; 19 | 20 | /* potenciálně ztracená data */ 21 | if ((i == 0) && (addr != p->addr)) { 22 | fprintf(stderr, "%u samples lost, %d, %08x:%08x\n", addr - p->addr, cnt, p->addr, addr); 23 | } 24 | 25 | /* přeskočíme hlavičku 16 bitů, 336 I+Q párů */ 26 | for (src+= 16, j = 0; j < 1008; j+= 3, ret+= 2) { 27 | /* plný rozsah zaručí správné znaménko */ 28 | dst[ret + 0] = ((src[j + 0] & 0xff) << 4) | ((src[j + 1] & 0x0f) << 12); 29 | dst[ret + 1] = ((src[j + 1] & 0xf0) << 0) | ((src[j + 2] & 0xff) << 8); 30 | } 31 | } 32 | 33 | p->addr = addr + 336; 34 | 35 | /* total used bytes */ 36 | return ret * 2; 37 | } 38 | -------------------------------------------------------------------------------- /libmirisdr-2/src/convert/384_s16.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 10+2 bitový formát 4 | * 1024 bajtů odpovídá 768 hodnotám 5 | * struktura: 6 | * 16b hlavička 7 | * 984b 6 bloků o velikosti 164b 8 | * 160b = 128x 10b hodnot 9 | * 4b = posun vlevo 2b 10 | * 24b kontrolní součet 11 | */ 12 | static int mirisdr_samples_convert_384_s16 (mirisdr_dev_t *p, unsigned char* buf, uint8_t *dst8, int cnt) { 13 | int i, i_max, j, k, ret = 0; 14 | uint32_t addr = 0, shift; 15 | uint8_t *src = buf; 16 | int16_t *dst = (int16_t*) dst8; 17 | 18 | /* dostáváme 1-3 1024 bytů dlouhé bloky, poslední část je 24 bitů, tu nezpracováváme */ 19 | for (i_max = cnt >> 10, i = 0; i < i_max; i++, src+= 24) { 20 | /* pozice hlavičky */ 21 | addr = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0; 22 | 23 | /* potenciálně ztracená data */ 24 | if ((i == 0) && (addr != p->addr)) { 25 | fprintf(stderr, "%u samples lost, %d, %08x:%08x\n", addr - p->addr, cnt, p->addr, addr); 26 | } 27 | 28 | /* přeskočíme hlavičku 16 bitů, 6 bloků, poslední 4 bajtový posuvný blok zpracujeme */ 29 | for (src+= 16, j = 0; j < 6; j++, src+= 4) { 30 | /* 2 bity pro každou hodnotu - určení posunu */ 31 | shift = src[160 + 3] << 24 | src[160 + 2] << 16 | src[160 + 1] << 8 | src[160 + 0] << 0; 32 | 33 | /* 16x 10 bajtů */ 34 | for (k = 0; k < 16; k++, src+= 10, ret+= 8) { 35 | /* 10 bajtů na 8 vzorků, plný rozsah zaručí správné znaménko */ 36 | dst[ret + 0] = ((src[0] & 0xff) << 6) | ((src[1] & 0x03) << 14); 37 | dst[ret + 1] = ((src[1] & 0xfc) << 4) | ((src[2] & 0x0f) << 12); 38 | dst[ret + 2] = ((src[2] & 0xf0) << 2) | ((src[3] & 0x3f) << 10); 39 | dst[ret + 3] = ((src[3] & 0xc0) << 0) | ((src[4] & 0xff) << 8); 40 | dst[ret + 4] = ((src[5] & 0xff) << 6) | ((src[6] & 0x03) << 14); 41 | dst[ret + 5] = ((src[6] & 0xfc) << 4) | ((src[7] & 0x0f) << 12); 42 | dst[ret + 6] = ((src[7] & 0xf0) << 2) | ((src[8] & 0x3f) << 10); 43 | dst[ret + 7] = ((src[8] & 0xc0) << 0) | ((src[9] & 0xff) << 8); 44 | 45 | /* posun vpravo respektuje signed bit */ 46 | switch ((shift >> (2 * k)) & 0x3) { 47 | case 0: 48 | dst[ret + 0]>>= 2; 49 | dst[ret + 1]>>= 2; 50 | dst[ret + 2]>>= 2; 51 | dst[ret + 3]>>= 2; 52 | dst[ret + 4]>>= 2; 53 | dst[ret + 5]>>= 2; 54 | dst[ret + 6]>>= 2; 55 | dst[ret + 7]>>= 2; 56 | break; 57 | case 1: 58 | dst[ret + 0]>>= 1; 59 | dst[ret + 1]>>= 1; 60 | dst[ret + 2]>>= 1; 61 | dst[ret + 3]>>= 1; 62 | dst[ret + 4]>>= 1; 63 | dst[ret + 5]>>= 1; 64 | dst[ret + 6]>>= 1; 65 | dst[ret + 7]>>= 1; 66 | break; 67 | /* 2 = 3 */ 68 | } 69 | } 70 | } 71 | } 72 | 73 | p->addr = addr + 384; 74 | 75 | /* total used bytes */ 76 | return ret * 2; 77 | } 78 | -------------------------------------------------------------------------------- /libmirisdr-2/src/convert/504_s16.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 8 bitový formát 4 | * 1024 bajtů odpovídá 1008 hodnotám 5 | * struktura: 6 | * 16b hlavička 7 | * 1008b bloků obsahujících 1008 8b hodnot 8 | */ 9 | static int mirisdr_samples_convert_504_s16 (mirisdr_dev_t *p, unsigned char* buf, uint8_t *dst8, int cnt) { 10 | int i, i_max, j, ret = 0; 11 | uint32_t addr = 0; 12 | uint8_t *src = buf; 13 | int16_t *dst = (int16_t*) dst8; 14 | 15 | /* dostáváme 1-3 1024 bytů dlouhé bloky */ 16 | for (i_max = cnt >> 10, i = 0; i < i_max; i++, src+= 1008) { 17 | /* pozice hlavičky */ 18 | addr = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0; 19 | 20 | /* potenciálně ztracená data */ 21 | if ((i == 0) && (addr != p->addr)) { 22 | fprintf(stderr, "%u samples lost, %d, %08x:%08x\n", addr - p->addr, cnt, p->addr, addr); 23 | } 24 | 25 | /* přeskočíme hlavičku 16 bitů, 504 I+Q párů */ 26 | for (src+= 16, j = 0; j < 1008; j+= 2, ret+= 2) { 27 | /* bitovým posunem zajistíme plný rozsah a zároveň správné znaménko */ 28 | dst[ret + 0] = src[j + 0] << 8; 29 | dst[ret + 1] = src[j + 1] << 8; 30 | } 31 | } 32 | 33 | p->addr = addr + 504; 34 | 35 | /* total used bytes */ 36 | return ret * 2; 37 | } 38 | -------------------------------------------------------------------------------- /libmirisdr-2/src/convert/504_s8.c: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 8 bitový formát 4 | * 1024 bajtů odpovídá 1008 hodnotám 5 | * struktura: 6 | * 16b hlavička 7 | * 1008b bloků obsahujících 1008 8b hodnot 8 | */ 9 | static int mirisdr_samples_convert_504_s8 (mirisdr_dev_t *p, unsigned char* src, uint8_t *dst, int cnt) { 10 | int i, ret = 0; 11 | uint32_t addr = src[3] << 24 | src[2] << 16 | src[1] << 8 | src[0] << 0; 12 | 13 | /* ztracená data */ 14 | if (p->addr != addr) { 15 | fprintf(stderr, "%u samples lost, %d, %08x:%08x\n", addr - p->addr, cnt, p->addr, addr); 16 | p->addr = addr; 17 | } 18 | 19 | for (i = 16; i < cnt; i+= 1024, ret+= 1008) { 20 | memcpy(dst + ret, src + i, 1008); 21 | p->addr+= 504; 22 | } 23 | 24 | //no_data: 25 | return ret; 26 | } 27 | -------------------------------------------------------------------------------- /libmirisdr-2/src/convert/base.c: -------------------------------------------------------------------------------- 1 | 2 | #include "252_s16.c" 3 | #include "336_s16.c" 4 | #include "384_s16.c" 5 | #include "504_s16.c" 6 | #include "504_s8.c" 7 | 8 | -------------------------------------------------------------------------------- /libmirisdr-2/src/devices.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | static mirisdr_device_t mirisdr_devices[] = { 19 | { 0x1df7, 0x2500, "Mirics MSi2500 default (e.g. VTX3D card)", "Mirics", "MSi2500"}, 20 | { 0x2040, 0xd300, "Hauppauge WinTV 133559 LF", "Hauppauge", "WinTV 133559 LF"}, 21 | { 0x07ca, 0x8591, "AverMedia A859 Pure DVBT", "AverTV", "A859 Pure DVBT"}, 22 | { 0x04bb, 0x0537, "IO-DATA GV-TV100 stick", "IO-DATA", "GV-TV100"}, 23 | { 0x0511, 0x0037, "Logitec LDT-1S310U/J", "Logitec", "LDT-1S310U/J"} 24 | }; 25 | 26 | static mirisdr_device_t *mirisdr_device_get (uint16_t vid, uint16_t pid) { 27 | size_t i; 28 | 29 | for (i = 0; i < sizeof(mirisdr_devices) / sizeof(mirisdr_device_t); i++) { 30 | if ((mirisdr_devices[i].vid == vid) && (mirisdr_devices[i].pid == pid)) return &mirisdr_devices[i]; 31 | } 32 | 33 | return NULL; 34 | } 35 | 36 | /* počet dostupných zařízení */ 37 | uint32_t mirisdr_get_device_count (void) { 38 | ssize_t i, i_max; 39 | uint32_t ret = 0; 40 | libusb_context *ctx; 41 | libusb_device **list; 42 | struct libusb_device_descriptor dd; 43 | 44 | libusb_init(&ctx); 45 | 46 | i_max = libusb_get_device_list(ctx, &list); 47 | 48 | for (i = 0; i < i_max; i++) { 49 | libusb_get_device_descriptor(list[i], &dd); 50 | 51 | if (mirisdr_device_get(dd.idVendor, dd.idProduct)) ret++; 52 | } 53 | 54 | libusb_free_device_list(list, 1); 55 | 56 | libusb_exit(ctx); 57 | 58 | return ret; 59 | } 60 | 61 | /* název zařízení */ 62 | const char *mirisdr_get_device_name (uint32_t index) { 63 | ssize_t i, i_max; 64 | size_t j = 0; 65 | libusb_context *ctx; 66 | libusb_device **list; 67 | struct libusb_device_descriptor dd; 68 | mirisdr_device_t *device = NULL; 69 | 70 | libusb_init(&ctx); 71 | i_max = libusb_get_device_list(ctx, &list); 72 | 73 | for (i = 0; i < i_max; i++) { 74 | libusb_get_device_descriptor(list[i], &dd); 75 | 76 | if ((device = mirisdr_device_get(dd.idVendor, dd.idProduct)) && 77 | (j++ == index)) { 78 | libusb_free_device_list(list, 1); 79 | libusb_exit(ctx); 80 | return device->name; 81 | } 82 | } 83 | 84 | libusb_free_device_list(list, 1); 85 | libusb_exit(ctx); 86 | 87 | return ""; 88 | } 89 | 90 | /* vlastní implementace */ 91 | int mirisdr_get_device_usb_strings (uint32_t index, char *manufact, char *product, char *serial) { 92 | ssize_t i, i_max; 93 | size_t j = 0; 94 | libusb_context *ctx; 95 | libusb_device **list; 96 | struct libusb_device_descriptor dd; 97 | mirisdr_device_t *device = NULL; 98 | 99 | libusb_init(&ctx); 100 | i_max = libusb_get_device_list(ctx, &list); 101 | 102 | for (i = 0; i < i_max; i++) { 103 | libusb_get_device_descriptor(list[i], &dd); 104 | 105 | if ((device = mirisdr_device_get(dd.idVendor, dd.idProduct)) && 106 | (j++ == index)) { 107 | strcpy(manufact, device->manufacturer); 108 | strcpy(product, device->product); 109 | sprintf(serial, "%08u", index + 1); 110 | libusb_free_device_list(list, 1); 111 | libusb_exit(ctx); 112 | return 0; 113 | } 114 | } 115 | 116 | memset(manufact, 0, 256); 117 | memset(product, 0, 256); 118 | memset(serial, 0, 256); 119 | 120 | libusb_free_device_list(list, 1); 121 | libusb_exit(ctx); 122 | 123 | return -1; 124 | } -------------------------------------------------------------------------------- /libmirisdr-2/src/gain.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #include "gain.h" 19 | 20 | int mirisdr_set_gain (mirisdr_dev_t *p) { 21 | uint32_t reg1 = 1, reg6 = 6; 22 | 23 | //fprintf(stderr, "gain baseband: %d, lna: %d, mixer: %d\n", p->gain_baseband, p->gain_lna, p->gain_mixer); 24 | 25 | /* Receiver Gain Control */ 26 | /* 0-3 => registr */ 27 | /* 4-9 => baseband, 0 - 59, 60-63 je stejné jako 59 */ 28 | /* 10-11 => mixer gain reduction pouze pro AM režim */ 29 | /* 12 => mixer gain reduction -19dB */ 30 | /* 13 => lna gain reduction -24dB */ 31 | /* 14-16 => DC kalibrace */ 32 | /* 17 => zrychlená DC kalibrace */ 33 | reg1|= p->gain_baseband << 4; 34 | reg1|= 0x0 << 10; 35 | reg1|= p->gain_mixer << 12; 36 | reg1|= p->gain_lna << 13; 37 | reg1|= MIRISDR_DC_OFFSET_CALIBRATION_ONE_SHOT << 14; 38 | reg1|= MIRISDR_DC_OFFSET_CALIBRATION_SPEEDUP_OFF << 17; 39 | mirisdr_write_reg(p, 0x09, reg1); 40 | 41 | /* DC Offset Calibration setup */ 42 | reg6|= 0x3F << 4; 43 | reg6|= 0xFFF << 10; 44 | mirisdr_write_reg(p, 0x09, reg6); 45 | 46 | return 0; 47 | } 48 | 49 | int mirisdr_get_tuner_gains (mirisdr_dev_t *dev, float *gains) { 50 | int i; 51 | 52 | if (gains) { 53 | for (i = 0; i <= 102; i++) { 54 | gains[i] = (float) i; 55 | } 56 | } 57 | else { 58 | i = 103; 59 | } 60 | 61 | return i; 62 | } 63 | 64 | int mirisdr_set_tuner_gain (mirisdr_dev_t *p, int gain) { 65 | p->gain = gain; 66 | 67 | /* 68 | * Pro VHF režim je lna zapnutý +24dB, mixer +19dB a baseband 69 | * je možné nastavovat plynule od 0 - 59 dB, z toho je maximální 70 | * zesílení 102 dB 71 | */ 72 | if (p->gain > 102) { 73 | p->gain = 102; 74 | } else if (p->gain < 0) { 75 | goto gain_auto; 76 | } 77 | 78 | /* Nejvyšší citlivost vždy bez redukce mixeru a lna */ 79 | if (p->gain >= 43) { 80 | p->gain_lna = 0; 81 | p->gain_mixer = 0; 82 | p->gain_baseband = 59 - (p->gain - 43); 83 | } else if (p->gain >= 19) { 84 | p->gain_lna = 1; 85 | p->gain_mixer = 0; 86 | p->gain_baseband = 59 - (p->gain - 19); 87 | } else { 88 | p->gain_lna = 1; 89 | p->gain_mixer = 1; 90 | p->gain_baseband = 59 - p->gain; 91 | } 92 | 93 | return mirisdr_set_gain(p); 94 | 95 | gain_auto: 96 | return mirisdr_set_tuner_gain_mode(p, 0); 97 | } 98 | 99 | int mirisdr_get_tuner_gain (mirisdr_dev_t *p) { 100 | int gain = 0; 101 | 102 | if (p->gain < 0) goto gain_auto; 103 | 104 | gain+= 59 - p->gain_baseband; 105 | 106 | if (!p->gain_lna) gain+= 24; 107 | if (!p->gain_mixer) gain+= 19; 108 | 109 | return gain; 110 | 111 | gain_auto: 112 | return -1; 113 | } 114 | 115 | int mirisdr_set_tuner_gain_mode (mirisdr_dev_t *p, int mode) { 116 | if (!mode) { 117 | p->gain = -1; 118 | fprintf(stderr, "gain mode: auto\n"); 119 | mirisdr_write_reg(p, 0x09, 0x014281); 120 | mirisdr_write_reg(p, 0x09, 0x3FFFF6); 121 | } else if (p->gain < 0) { 122 | fprintf(stderr, "gain mode: manual\n"); 123 | p->gain = DEFAULT_GAIN; 124 | } 125 | 126 | return 0; 127 | } 128 | 129 | int mirisdr_get_tuner_gain_mode (mirisdr_dev_t *p) { 130 | return (p->gain < 0) ? 0 : 1; 131 | } 132 | 133 | int mirisdr_set_mixer_gain (mirisdr_dev_t *p, int gain) { 134 | p->gain_mixer = gain; 135 | 136 | return mirisdr_set_gain(p); 137 | } 138 | 139 | int mirisdr_set_lna_gain (mirisdr_dev_t *p, int gain) { 140 | p->gain_lna = gain; 141 | 142 | return mirisdr_set_gain(p); 143 | } 144 | 145 | int mirisdr_set_baseband_gain (mirisdr_dev_t *p, int gain) { 146 | p->gain_baseband = gain; 147 | 148 | return mirisdr_set_gain(p); 149 | } 150 | 151 | int mirisdr_get_mixer_gain (mirisdr_dev_t *p) { 152 | return p->gain_mixer; 153 | } 154 | 155 | int mirisdr_get_lna_gain (mirisdr_dev_t *p) { 156 | return p->gain_lna; 157 | } 158 | 159 | int mirisdr_get_baseband_gain (mirisdr_dev_t *p) { 160 | return p->gain_baseband; 161 | } 162 | 163 | 164 | -------------------------------------------------------------------------------- /libmirisdr-2/src/gain.h: -------------------------------------------------------------------------------- 1 | 2 | /*** Register 1: Receiver Gain Control ***/ 3 | 4 | /* reg1: 4:9 (BBGAIN0 - BBGAIN5) */ 5 | #define MIRISDR_BASEBAND_GAIN_REDUCTION_MIN 0 6 | #define MIRISDR_BASEBAND_GAIN_REDUCTION_MAX 0x3B 7 | 8 | /* reg1: 10:11 (MIXBU0, MIXBU1) - AM port 1 */ 9 | #define MIRISDR_AM_PORT1_BLOCKUP_CONVERT_GAIN_REDUCTION_0DB 0 10 | #define MIRISDR_AM_PORT1_BLOCKUP_CONVERT_GAIN_REDUCTION_6DB 1 11 | #define MIRISDR_AM_PORT1_BLOCKUP_CONVERT_GAIN_REDUCTION_12DB 2 12 | #define MIRISDR_AM_PORT1_BLOCKUP_CONVERT_GAIN_REDUCTION_18DB 3 13 | 14 | /* reg1: 10:11 (MIXBU0, MIXBU1) - AM port 2 */ 15 | #define MIRISDR_AM_PORT2_BLOCKUP_CONVERT_GAIN_REDUCTION_0DB 0 16 | #define MIRISDR_AM_PORT2_BLOCKUP_CONVERT_GAIN_REDUCTION_24DB 3 17 | 18 | /* reg1: 12 (MIXL) */ 19 | #define MIRISDR_LNA_GAIN_REDUCTION_OFF 0 20 | #define MIRISDR_LNA_GAIN_REDUCTION_ON 1 21 | 22 | /* reg1: 13 (LNAGR) */ 23 | #define MIRISDR_MIXER_GAIN_REDUCTION_OFF 0 24 | #define MIRISDR_MIXER_GAIN_REDUCTION_ON 1 25 | 26 | /* reg1: 14:16 (DCCAL0 - DCCAL2) */ 27 | #define MIRISDR_DC_OFFSET_CALIBRATION_STATIC 0 28 | #define MIRISDR_DC_OFFSET_CALIBRATION_PERIODIC1 1 29 | #define MIRISDR_DC_OFFSET_CALIBRATION_PERIODIC2 2 30 | #define MIRISDR_DC_OFFSET_CALIBRATION_PERIODIC3 3 31 | #define MIRISDR_DC_OFFSET_CALIBRATION_ONE_SHOT 4 32 | #define MIRISDR_DC_OFFSET_CALIBRATION_CONTINUOUS 5 33 | 34 | /* reg1: 17 (DCCAL_SPEEDUP) */ 35 | #define MIRISDR_DC_OFFSET_CALIBRATION_SPEEDUP_OFF 0 36 | #define MIRISDR_DC_OFFSET_CALIBRATION_SPEEDUP_ON 1 37 | 38 | /*** Register 6: DC Offset Calibration setup ***/ 39 | 40 | /* reg6: 4:7 (DCTRK_TIM0 - DCTRK_TIM3) */ 41 | 42 | /* reg6: 8:21 (DCRATE_TIM0 - DCRATE_TIM11) */ 43 | -------------------------------------------------------------------------------- /libmirisdr-2/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 | -------------------------------------------------------------------------------- /libmirisdr-2/src/hard.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #include "hard.h" 19 | #include 20 | 21 | /* nastavení parametrů které vyžadují restart */ 22 | int mirisdr_set_hard (mirisdr_dev_t *p) { 23 | int streaming = 0; 24 | uint32_t reg3 = 0, reg4 = 0; 25 | uint64_t i, vco, n, fract; 26 | 27 | /* při změně registrů musíme zastavit streamování */ 28 | if (p->async_status == MIRISDR_ASYNC_RUNNING) { 29 | streaming = 1; 30 | if (mirisdr_stop_async(p) < 0) goto failed; 31 | } 32 | 33 | /* omezení rozsahu */ 34 | if (p->rate > MIRISDR_SAMPLE_RATE_MAX) { 35 | fprintf(stderr, "can't set rate %u, setting maximum rate: %d\n", p->rate, MIRISDR_SAMPLE_RATE_MAX); 36 | p->rate = MIRISDR_SAMPLE_RATE_MAX; 37 | } else if (p->rate < MIRISDR_SAMPLE_RATE_MIN) { 38 | fprintf(stderr, "can't set rate %u, setting minimum rate: %d\n", p->rate, MIRISDR_SAMPLE_RATE_MIN); 39 | p->rate = MIRISDR_SAMPLE_RATE_MIN; 40 | } 41 | 42 | /* automatická volba formátu */ 43 | if (p->format_auto == MIRISDR_FORMAT_AUTO_ON) { 44 | if (p->rate <= 6048000) { 45 | p->format = MIRISDR_FORMAT_252_S16; 46 | } else if (p->rate <= 8064000) { 47 | p->format = MIRISDR_FORMAT_336_S16; 48 | } else if (p->rate <= 9216000) { 49 | p->format = MIRISDR_FORMAT_384_S16; 50 | } else { 51 | p->format = MIRISDR_FORMAT_504_S16; 52 | } 53 | } 54 | 55 | /* typ forámtu a šířka pásma */ 56 | switch (p->format) { 57 | case MIRISDR_FORMAT_252_S16: 58 | /* maximum rate 6.048 Msps | 24.576 MB/s | 196.608 Mbit/s */ 59 | fprintf(stderr, "format: 252\n"); 60 | mirisdr_write_reg(p, 0x07, 0x000094); 61 | p->addr = 252 + 2; 62 | break; 63 | case MIRISDR_FORMAT_336_S16: 64 | /* maximum rate 8.064 Msps | 24.576 MB/s | 196.608 Mbit/s */ 65 | fprintf(stderr, "format: 336\n"); 66 | mirisdr_write_reg(p, 0x07, 0x000085); 67 | p->addr = 336 + 2; 68 | break; 69 | case MIRISDR_FORMAT_384_S16: 70 | /* maximum rate 9.216 Msps | 24.576 MB/s | 196.608 Mbit/s */ 71 | fprintf(stderr, "format: 384\n"); 72 | mirisdr_write_reg(p, 0x07, 0x0000a5); 73 | p->addr = 384 + 2; 74 | break; 75 | case MIRISDR_FORMAT_504_S16: 76 | case MIRISDR_FORMAT_504_S8: 77 | /* maximum rate 12.096 Msps | 24.576 MB/s | 196.608 Mbit/s */ 78 | fprintf(stderr, "format: 504\n"); 79 | mirisdr_write_reg(p, 0x07, 0x000c94); 80 | p->addr = 504 + 2; 81 | break; 82 | } 83 | 84 | /* 85 | * Výpočet dělení vzorkovací frekvence 86 | * Min: >= 1.3 Msps 87 | * Max: <= 15 Msps, od 12,096 Msps prokládaně 88 | * Poznámka: Nastavení vyšší frekvence než 15 Msps uvede tuner do speciálního 89 | * režimu kdy není možné přepnout rate zpět, stejně tak nastavení nižší 90 | * frekvence než je 571429 sps, protože pak bude N menší jak 2, což není 91 | * přípustný stav. 92 | */ 93 | for (i = 4; i < 16; i+= 2) { 94 | vco = (uint64_t) p->rate * i * 12; 95 | if (vco >= 202000000UL) break; 96 | } 97 | 98 | /* z předchozího výpočtu je N minimálně 4 */ 99 | n = vco / 48000000UL; 100 | fract = 0x200000UL * (vco % 48000000UL) / 48000000UL; 101 | 102 | fprintf(stderr, "rate: %u, vco: %" PRIu64 " (%" PRIu64 "), n: %" PRIu64 ", fraction: %" PRIu64 "\n", p->rate, vco, (i / 2) - 1, n, fract); 103 | 104 | /* nastavení vzorkovací frekvence */ 105 | reg3|= (0x03 & 3) << 0; /* ?? */ 106 | reg3|= (0x07 & (i / 2 - 1)) << 2; /* rozlišení */ 107 | reg3|= (0x03 & 0) << 5; /* ?? */ 108 | reg3|= (0x01 & (fract >> 20)) << 7; /* +0.5 */ 109 | reg3|= (0x0f & n) << 8; /* hlavní rozsah */ 110 | switch (p->format) { /* AGC */ 111 | case MIRISDR_FORMAT_252_S16: 112 | reg3|= (0x0f & 0x01) << 12; 113 | break; 114 | case MIRISDR_FORMAT_336_S16: 115 | reg3|= (0x0f & 0x05) << 12; 116 | break; 117 | case MIRISDR_FORMAT_384_S16: 118 | reg3|= (0x0f & 0x09) << 12; 119 | break; 120 | case MIRISDR_FORMAT_504_S16: 121 | case MIRISDR_FORMAT_504_S8: 122 | reg3|= (0x0f & 0x0d) << 12; 123 | break; 124 | } 125 | reg3|= (0x01 & 1) << 16; /* ?? */ 126 | 127 | /* registr pro detailní nastavení vzorkovací frekvence */ 128 | reg4|= (0xfffff & fract) << 0; 129 | 130 | mirisdr_write_reg(p, 0x04, reg4); 131 | mirisdr_write_reg(p, 0x03, reg3); 132 | 133 | /* opětovné spuštění streamu */ 134 | if ((streaming) && 135 | (mirisdr_start_async(p) < 0)) goto failed; 136 | 137 | return 0; 138 | 139 | failed: 140 | return -1; 141 | } 142 | 143 | 144 | int mirisdr_set_sample_rate (mirisdr_dev_t *p, uint32_t rate) { 145 | p->rate = rate; 146 | 147 | return mirisdr_set_hard(p); 148 | } 149 | 150 | uint32_t mirisdr_get_sample_rate (mirisdr_dev_t *p) { 151 | return p->rate; 152 | } 153 | 154 | int mirisdr_set_sample_format (mirisdr_dev_t *p, char *v) { 155 | if (!strcmp(v, "AUTO")) { 156 | p->format_auto = MIRISDR_FORMAT_AUTO_ON; 157 | } else { 158 | p->format_auto = MIRISDR_FORMAT_AUTO_OFF; 159 | if (!strcmp(v, "252_S16")) { 160 | p->format = MIRISDR_FORMAT_252_S16; 161 | } else if (!strcmp(v, "336_S16")) { 162 | p->format = MIRISDR_FORMAT_336_S16; 163 | } else if (!strcmp(v, "384_S16")) { 164 | p->format = MIRISDR_FORMAT_384_S16; 165 | } else if (!strcmp(v, "504_S16")) { 166 | p->format = MIRISDR_FORMAT_504_S16; 167 | } else if (!strcmp(v, "504_S8")) { 168 | p->format = MIRISDR_FORMAT_504_S8; 169 | } else { 170 | fprintf(stderr, "unsupported format: %s\n", v); 171 | goto failed; 172 | } 173 | } 174 | 175 | return mirisdr_set_hard(p); 176 | 177 | failed: 178 | return -1; 179 | } 180 | 181 | const char *mirisdr_get_sample_format (mirisdr_dev_t *p) { 182 | if (p->format_auto == MIRISDR_FORMAT_AUTO_ON) return "AUTO"; 183 | 184 | switch (p->format) { 185 | case MIRISDR_FORMAT_252_S16: 186 | return "252_S16"; 187 | case MIRISDR_FORMAT_336_S16: 188 | return "336_S16"; 189 | case MIRISDR_FORMAT_384_S16: 190 | return "384_S16"; 191 | case MIRISDR_FORMAT_504_S16: 192 | return "504_S16"; 193 | case MIRISDR_FORMAT_504_S8: 194 | return "504_S8"; 195 | } 196 | 197 | return ""; 198 | } 199 | 200 | -------------------------------------------------------------------------------- /libmirisdr-2/src/hard.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #define MIRISDR_SAMPLE_RATE_MIN 200000 19 | // limit SAMPLE RATE to maximum supported with 14-bit samples 20 | #define MIRISDR_SAMPLE_RATE_MAX 6048000 21 | -------------------------------------------------------------------------------- /libmirisdr-2/src/libmirisdr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | /* potřebné funkce */ 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #ifndef _WIN32 27 | #include 28 | #define min(a, b) (((a) < (b)) ? (a) : (b)) 29 | #endif 30 | 31 | #include 32 | 33 | #ifndef LIBUSB_CALL 34 | #define LIBUSB_CALL 35 | #endif 36 | 37 | /* hlavní hlavičkový soubor */ 38 | #include "mirisdr.h" 39 | 40 | /* interní definice */ 41 | #include "constants.h" 42 | #include "structs.h" 43 | 44 | /* interní funkce - inline */ 45 | #include "reg.c" 46 | #include "adc.c" 47 | #include "convert/base.c" 48 | #include "async.c" 49 | #include "devices.c" 50 | #include "gain.c" 51 | #include "hard.c" 52 | #include "streaming.c" 53 | #include "soft.c" 54 | #include "sync.c" 55 | 56 | int mirisdr_open (mirisdr_dev_t **p, uint32_t index) { 57 | mirisdr_dev_t *dev = NULL; 58 | libusb_device **list, *device = NULL; 59 | struct libusb_device_descriptor dd; 60 | ssize_t i, i_max; 61 | size_t count = 0; 62 | int r; 63 | 64 | *p = NULL; 65 | 66 | if (!(dev = malloc(sizeof(*dev)))) return -ENOMEM; 67 | 68 | memset(dev, 0, sizeof(*dev)); 69 | 70 | /* ostatní parametry */ 71 | dev->index = index; 72 | 73 | libusb_init(&dev->ctx); 74 | 75 | i_max = libusb_get_device_list(dev->ctx, &list); 76 | 77 | for (i = 0; i < i_max; i++) { 78 | libusb_get_device_descriptor(list[i], &dd); 79 | 80 | if ((mirisdr_device_get(dd.idVendor, dd.idProduct)) && 81 | (count++ == index)) { 82 | device = list[i]; 83 | break; 84 | } 85 | } 86 | 87 | /* nenašli jsme zařízení */ 88 | if (!device) { 89 | libusb_free_device_list(list, 1); 90 | fprintf(stderr, "no miri device %u found\n", dev->index); 91 | goto failed; 92 | } 93 | 94 | /* otevření zařízení */ 95 | if ((r = libusb_open(device, &dev->dh)) < 0) { 96 | libusb_free_device_list(list, 1); 97 | fprintf(stderr, "failed to open miri usb device %u with code %d\n", dev->index, r); 98 | goto failed; 99 | } 100 | 101 | libusb_free_device_list(list, 1); 102 | 103 | /* reset je potřeba, jinak občas zařízení odmítá komunikovat */ 104 | mirisdr_reset(dev); 105 | 106 | /* ještě je třeba vždy ukončit i streamování, které může být při otevření aktivní */ 107 | mirisdr_streaming_stop(dev); 108 | 109 | if ((r = libusb_claim_interface(dev->dh, 0)) < 0) { 110 | fprintf(stderr, "failed to claim miri usb device %u with code %d\n", dev->index, r); 111 | goto failed; 112 | } 113 | 114 | /* inicializace tuneru */ 115 | dev->freq = DEFAULT_FREQ; 116 | dev->rate = DEFAULT_RATE; 117 | dev->gain = DEFAULT_GAIN; 118 | 119 | dev->gain_lna = 0; 120 | dev->gain_mixer = 0; 121 | dev->gain_baseband = 43; 122 | dev->if_freq = MIRISDR_IF_ZERO; 123 | dev->format_auto = MIRISDR_FORMAT_AUTO_ON; 124 | dev->bandwidth = MIRISDR_BW_8MHZ; 125 | dev->xtal = MIRISDR_XTAL_24M; 126 | 127 | /* ISOC is more stable but works only on Unix systems */ 128 | #ifndef _WIN32 129 | dev->transfer = MIRISDR_TRANSFER_ISOC; 130 | #else 131 | dev->transfer = MIRISDR_TRANSFER_BULK; 132 | #endif 133 | 134 | mirisdr_adc_init(dev); 135 | mirisdr_set_hard(dev); 136 | mirisdr_set_soft(dev); 137 | mirisdr_set_gain(dev); 138 | 139 | *p = dev; 140 | 141 | return 0; 142 | 143 | failed: 144 | if (dev) { 145 | if (dev->dh) { 146 | libusb_release_interface(dev->dh, 0); 147 | libusb_close(dev->dh); 148 | } 149 | if (dev->ctx) libusb_exit(dev->ctx); 150 | free(dev); 151 | } 152 | 153 | return -1; 154 | } 155 | 156 | int mirisdr_close (mirisdr_dev_t *p) { 157 | if (!p) goto failed; 158 | 159 | /* ukončení async čtení okamžitě */ 160 | mirisdr_cancel_async_now(p); 161 | 162 | /* deinicializace tuneru */ 163 | if (p->dh) { 164 | libusb_release_interface(p->dh, 0); 165 | libusb_close(p->dh); 166 | } 167 | 168 | if (p->ctx) libusb_exit(p->ctx); 169 | 170 | free(p); 171 | 172 | return 0; 173 | 174 | failed: 175 | return -1; 176 | } 177 | 178 | int mirisdr_reset (mirisdr_dev_t *p) { 179 | int r; 180 | 181 | if (!p) goto failed; 182 | if (!p->dh) goto failed; 183 | 184 | /* měli bychom uvolnit zařízení předem? */ 185 | 186 | if ((r = libusb_reset_device(p->dh)) < 0) { 187 | fprintf(stderr, "failed to reset miri usb device %u with code %d\n", p->index, r); 188 | goto failed; 189 | } 190 | 191 | return 0; 192 | 193 | failed: 194 | return -1; 195 | } 196 | 197 | int mirisdr_reset_buffer (mirisdr_dev_t *p) { 198 | if (!p) goto failed; 199 | if (!p->dh) goto failed; 200 | 201 | /* zatím není jasné k čemu by bylo, proto pouze provedeme reset async části */ 202 | mirisdr_stop_async(p); 203 | mirisdr_start_async(p); 204 | 205 | return 0; 206 | 207 | failed: 208 | return -1; 209 | } 210 | 211 | int mirisdr_get_usb_strings (mirisdr_dev_t *dev, char *manufact, char *product, char *serial) { 212 | fprintf(stderr, "mirisdr_get_usb_strings not implemented yet\n"); 213 | 214 | memset(manufact, 0, 256); 215 | memset(product, 0, 256); 216 | memset(serial, 0, 256); 217 | 218 | return 0; 219 | } 220 | -------------------------------------------------------------------------------- /libmirisdr-2/src/reg.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | int mirisdr_write_reg (mirisdr_dev_t *p, uint8_t reg, uint32_t val) { 19 | uint16_t value = (val & 0xff) << 8 | reg; 20 | uint16_t index = (val >> 8) & 0xffff; 21 | 22 | if (!p) goto failed; 23 | if (!p->dh) goto failed; 24 | 25 | #ifdef MIRISDR_DEBUG 26 | fprintf(stderr, "write reg: 0x%02x, val 0x%08x\n", reg, val); 27 | #endif 28 | 29 | return libusb_control_transfer(p->dh, 0x42, 0x41, value, index, NULL, 0, CTRL_TIMEOUT); 30 | 31 | failed: 32 | return -1; 33 | } 34 | -------------------------------------------------------------------------------- /libmirisdr-2/src/soft.h: -------------------------------------------------------------------------------- 1 | 2 | /*** Register 0: IC Mode / Power Control ***/ 3 | 4 | /* reg0: 4:8 (AM_MODE, VHF_MODE, B3_MODE, B45_MODE, BL_MODE) */ 5 | #define MIRISDR_MODE_AM 0x01 6 | #define MIRISDR_MODE_VHF 0x02 7 | #define MIRISDR_MODE_B3 0x04 8 | #define MIRISDR_MODE_B45 0x08 9 | #define MIRISDR_MODE_BL 0x10 10 | 11 | /* reg0: 9 (AM_MODE2) */ 12 | #define MIRISDR_UPCONVERT_MIXER_OFF 0 13 | #define MIRISDR_UPCONVERT_MIXER_ON 1 14 | 15 | /* reg0: 10 (RF_SYNTH) */ 16 | #define MIRISDR_RF_SYNTHESIZER_OFF 0 17 | #define MIRISDR_RF_SYNTHESIZER_ON 1 18 | 19 | /* reg0: 11 (AM_PORT_SEL) */ 20 | #define MIRISDR_AM_PORT1 0 21 | #define MIRISDR_AM_PORT2 1 22 | 23 | /* reg0: 12:13 (FIL_MODE_SEL0, FIL_MODE_SEL1) */ 24 | #define MIRISDR_IF_MODE_2048KHZ 0 25 | #define MIRISDR_IF_MODE_1620KHZ 1 26 | #define MIRISDR_IF_MODE_450KHZ 2 27 | #define MIRISDR_IF_MODE_ZERO 3 28 | 29 | /* reg0: 14:16 (FIL_BW_SEL0 - FIL_BW_SEL2) */ 30 | 31 | /* reg0: 17:19 (XTAL_SEL0 - XTAL_SEL2) */ 32 | 33 | /* reg0: 20:22 (IF_LPMODE0 - IF_LPMODE2) */ 34 | #define MIRISDR_IF_LPMODE_NORMAL 0 35 | #define MIRISDR_IF_LPMODE_ONLY_Q 1 36 | #define MIRISDR_IF_LPMODE_ONLY_I 2 37 | #define MIRISDR_IF_LPMODE_LOW_POWER 4 38 | 39 | /* reg0: 23 (VCO_LPMODE) */ 40 | #define MIRISDR_VCO_LPMODE_NORMAL 0 41 | #define MIRISDR_VCO_LPMODE_LOW_POWER 1 42 | 43 | /*** Register 2: Synthesizer Programming ***/ 44 | 45 | /* reg2: 4:15 (FRAC0 - FRAC11) */ 46 | 47 | /* reg2: 16:21 (INT0 - INT5) */ 48 | 49 | /* reg2: 22 (LNACAL_EN) */ 50 | #define MIRISDR_LBAND_LNA_CALIBRATION_OFF 0 51 | #define MIRISDR_LBAND_LNA_CALIBRATION_ON 1 52 | 53 | /*** Register 6: RF Synthesizer Configuration ***/ 54 | 55 | /* reg5: 4:15 (THRESH0 - THRESH11) */ 56 | 57 | /* reg5: 16:21 (reserved) */ 58 | #define MIRISDR_RF_SYNTHESIZER_RESERVED_PROGRAMMING 0x28 59 | -------------------------------------------------------------------------------- /libmirisdr-2/src/streaming.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | int mirisdr_streaming_start (mirisdr_dev_t *p) { 19 | if (!p) goto failed; 20 | if (!p->dh) goto failed; 21 | 22 | libusb_control_transfer(p->dh, 0x42, 0x43, 0x0, 0x0, NULL, 0, CTRL_TIMEOUT); 23 | 24 | return 0; 25 | 26 | failed: 27 | return -1; 28 | } 29 | 30 | int mirisdr_streaming_stop (mirisdr_dev_t *p) { 31 | if (!p) goto failed; 32 | if (!p->dh) goto failed; 33 | 34 | libusb_control_transfer(p->dh, 0x42, 0x45, 0x0, 0x0, NULL, 0, CTRL_TIMEOUT); 35 | 36 | return 0; 37 | 38 | failed: 39 | return -1; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /libmirisdr-2/src/structs.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | typedef struct mirisdr_device { 19 | uint16_t vid; 20 | uint16_t pid; 21 | const char *name; 22 | const char *manufacturer; 23 | const char *product; 24 | } mirisdr_device_t; 25 | 26 | struct mirisdr_dev { 27 | libusb_context *ctx; 28 | struct libusb_device_handle *dh; 29 | 30 | /* parametry */ 31 | uint32_t index; 32 | uint32_t freq; 33 | uint32_t rate; 34 | int gain; 35 | int gain_lna; 36 | int gain_mixer; 37 | int gain_baseband; 38 | enum { 39 | MIRISDR_FORMAT_AUTO_ON = 0, 40 | MIRISDR_FORMAT_AUTO_OFF 41 | } format_auto; 42 | enum { 43 | MIRISDR_FORMAT_252_S16 = 0, 44 | MIRISDR_FORMAT_336_S16, 45 | MIRISDR_FORMAT_384_S16, 46 | MIRISDR_FORMAT_504_S16, 47 | MIRISDR_FORMAT_504_S8 48 | } format; 49 | enum { 50 | MIRISDR_BW_200KHZ = 0, 51 | MIRISDR_BW_300KHZ, 52 | MIRISDR_BW_600KHZ, 53 | MIRISDR_BW_1536KHZ, 54 | MIRISDR_BW_5MHZ, 55 | MIRISDR_BW_6MHZ, 56 | MIRISDR_BW_7MHZ, 57 | MIRISDR_BW_8MHZ 58 | } bandwidth; 59 | enum { 60 | MIRISDR_IF_ZERO = 0, 61 | MIRISDR_IF_450KHZ, 62 | MIRISDR_IF_1620KHZ, 63 | MIRISDR_IF_2048KHZ 64 | } if_freq; 65 | enum { 66 | MIRISDR_XTAL_19_2M = 0, 67 | MIRISDR_XTAL_22M, 68 | MIRISDR_XTAL_24M, 69 | MIRISDR_XTAL_24_576M, 70 | MIRISDR_XTAL_26M, 71 | MIRISDR_XTAL_38_4M 72 | } xtal; 73 | enum { 74 | MIRISDR_TRANSFER_BULK = 0, 75 | MIRISDR_TRANSFER_ISOC 76 | } transfer; 77 | 78 | /* async */ 79 | enum { 80 | MIRISDR_ASYNC_INACTIVE = 0, 81 | MIRISDR_ASYNC_CANCELING, 82 | MIRISDR_ASYNC_RUNNING, 83 | MIRISDR_ASYNC_PAUSED, 84 | MIRISDR_ASYNC_FAILED 85 | } async_status; 86 | mirisdr_read_async_cb_t cb; 87 | void *cb_ctx; 88 | size_t xfer_buf_num; 89 | struct libusb_transfer **xfer; 90 | unsigned char **xfer_buf; 91 | size_t xfer_out_len; 92 | size_t xfer_out_pos; 93 | unsigned char *xfer_out; 94 | uint32_t addr; 95 | }; 96 | 97 | -------------------------------------------------------------------------------- /libmirisdr-2/src/sync.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | /* pouze pro bulk transfer a je třeba doplnit konverze formátů */ 19 | int mirisdr_read_sync (mirisdr_dev_t *p, void *buf, int len, int *n_read) { 20 | if (!p) goto failed; 21 | 22 | return libusb_bulk_transfer(p->dh, 0x81, buf, len, n_read, DEFAULT_BULK_TIMEOUT); 23 | 24 | failed: 25 | return -1; 26 | } -------------------------------------------------------------------------------- /librtlsdr/.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 | -------------------------------------------------------------------------------- /librtlsdr/.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 | -------------------------------------------------------------------------------- /librtlsdr/AUTHORS: -------------------------------------------------------------------------------- 1 | Steve Markgraf 2 | Dimitri Stolnikov 3 | Hoernchen 4 | Kyle Keen 5 | -------------------------------------------------------------------------------- /librtlsdr/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 | ######################################################################## 22 | # Project setup 23 | ######################################################################## 24 | cmake_minimum_required(VERSION 2.6) 25 | project(rtlsdr C) 26 | 27 | #select the release build type by default to get optimization flags 28 | if(NOT CMAKE_BUILD_TYPE) 29 | set(CMAKE_BUILD_TYPE "Release") 30 | message(STATUS "Build type not specified: defaulting to release.") 31 | endif(NOT CMAKE_BUILD_TYPE) 32 | set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "") 33 | 34 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules) 35 | 36 | if(NOT LIB_INSTALL_DIR) 37 | set(LIB_INSTALL_DIR lib) 38 | endif() 39 | 40 | # Set the version information here 41 | set(VERSION_INFO_MAJOR_VERSION 0) # increment major on api compatibility changes 42 | set(VERSION_INFO_MINOR_VERSION 5) # increment minor on feature-level changes 43 | set(VERSION_INFO_PATCH_VERSION git) # increment patch for bug fixes and docs 44 | include(Version) # setup version info 45 | 46 | ######################################################################## 47 | # Compiler specific setup 48 | ######################################################################## 49 | if(CMAKE_COMPILER_IS_GNUCC AND NOT WIN32) 50 | ADD_DEFINITIONS(-Wall) 51 | ADD_DEFINITIONS(-Wextra) 52 | ADD_DEFINITIONS(-Wno-unused-parameter) 53 | ADD_DEFINITIONS(-Wno-unused) 54 | ADD_DEFINITIONS(-Wsign-compare) 55 | ADD_DEFINITIONS(-Wdeclaration-after-statement) 56 | #http://gcc.gnu.org/wiki/Visibility 57 | add_definitions(-fvisibility=hidden) 58 | endif() 59 | 60 | ######################################################################## 61 | # Find build dependencies 62 | ######################################################################## 63 | find_package(PkgConfig) 64 | find_package(LibUSB) 65 | set(THREADS_USE_PTHREADS_WIN32 true) 66 | find_package(Threads) 67 | 68 | if(NOT LIBUSB_FOUND) 69 | message(FATAL_ERROR "LibUSB 1.0 required to compile rtl-sdr") 70 | endif() 71 | if(NOT THREADS_FOUND) 72 | message(FATAL_ERROR "pthreads(-win32) required to compile rtl-sdr") 73 | endif() 74 | ######################################################################## 75 | # Setup the include and linker paths 76 | ######################################################################## 77 | include_directories( 78 | ${CMAKE_SOURCE_DIR}/include 79 | ${LIBUSB_INCLUDE_DIR} 80 | ${THREADS_PTHREADS_INCLUDE_DIR} 81 | ) 82 | 83 | #link_directories( 84 | # ... 85 | #) 86 | 87 | # Set component parameters 88 | #set(INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include CACHE INTERNAL "" FORCE) 89 | 90 | ######################################################################## 91 | # Create uninstall target 92 | ######################################################################## 93 | configure_file( 94 | ${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in 95 | ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake 96 | @ONLY) 97 | 98 | add_custom_target(uninstall 99 | ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake 100 | ) 101 | 102 | ######################################################################## 103 | # Install udev rules 104 | ######################################################################## 105 | option(INSTALL_UDEV_RULES "Install udev rules for RTL-SDR" OFF) 106 | if (INSTALL_UDEV_RULES) 107 | install ( 108 | FILES rtl-sdr.rules 109 | DESTINATION "/etc/udev/rules.d" 110 | COMPONENT "udev" 111 | ) 112 | else (INSTALL_UDEV_RULES) 113 | message (STATUS "Udev rules not being installed, install them with -DINSTALL_UDEV_RULES=ON") 114 | endif (INSTALL_UDEV_RULES) 115 | 116 | option(DETACH_KERNEL_DRIVER "Detach kernel driver if loaded" OFF) 117 | if (DETACH_KERNEL_DRIVER) 118 | message (STATUS "Building with kernel driver detaching enabled") 119 | add_definitions(-DDETACH_KERNEL_DRIVER=1) 120 | else (DETACH_KERNEL_DRIVER) 121 | message (STATUS "Building with kernel driver detaching disabled, use -DDETACH_KERNEL_DRIVER=ON to enable") 122 | endif (DETACH_KERNEL_DRIVER) 123 | 124 | ######################################################################## 125 | # Add subdirectories 126 | ######################################################################## 127 | add_subdirectory(include) 128 | add_subdirectory(src) 129 | 130 | ######################################################################## 131 | # Create Pkg Config File 132 | ######################################################################## 133 | FOREACH(inc ${LIBUSB_INCLUDE_DIR}) 134 | LIST(APPEND RTLSDR_PC_CFLAGS "-I${inc}") 135 | ENDFOREACH(inc) 136 | 137 | FOREACH(lib ${LIBUSB_LIBRARY_DIRS}) 138 | LIST(APPEND RTLSDR_PC_LIBS "-L${lib}") 139 | ENDFOREACH(lib) 140 | 141 | # use space-separation format for the pc file 142 | STRING(REPLACE ";" " " RTLSDR_PC_CFLAGS "${RTLSDR_PC_CFLAGS}") 143 | STRING(REPLACE ";" " " RTLSDR_PC_LIBS "${RTLSDR_PC_LIBS}") 144 | 145 | # unset these vars to avoid hard-coded paths to cross environment 146 | IF(CMAKE_CROSSCOMPILING) 147 | UNSET(RTLSDR_PC_CFLAGS) 148 | UNSET(RTLSDR_PC_LIBS) 149 | ENDIF(CMAKE_CROSSCOMPILING) 150 | 151 | set(prefix ${CMAKE_INSTALL_PREFIX}) 152 | set(exec_prefix \${prefix}) 153 | set(libdir \${exec_prefix}/${LIB_INSTALL_DIR}) 154 | set(includedir \${prefix}/include) 155 | 156 | CONFIGURE_FILE( 157 | ${CMAKE_CURRENT_SOURCE_DIR}/librtlsdr.pc.in 158 | ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc 159 | @ONLY) 160 | 161 | INSTALL( 162 | FILES ${CMAKE_CURRENT_BINARY_DIR}/librtlsdr.pc 163 | DESTINATION ${LIB_INSTALL_DIR}/pkgconfig 164 | ) 165 | 166 | ######################################################################## 167 | # Print Summary 168 | ######################################################################## 169 | MESSAGE(STATUS "Building for version: ${VERSION} / ${LIBVER}") 170 | MESSAGE(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}") 171 | -------------------------------------------------------------------------------- /librtlsdr/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 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 | cd $(DESTDIR) && rm -rf $(doc_htmldir) 44 | 45 | DX_CLEAN = doc/{html,latex}/* doc/html.tar 46 | 47 | endif 48 | 49 | MOSTLYCLEANFILES = $(DX_CLEAN) 50 | -------------------------------------------------------------------------------- /librtlsdr/README: -------------------------------------------------------------------------------- 1 | rtl-sdr 2 | turns your Realtek RTL2832 based DVB dongle into a SDR receiver 3 | ====================================================================== 4 | 5 | For more information see: 6 | http://sdr.osmocom.org/trac/wiki/rtl-sdr 7 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | # The following test is taken from WebKit's webkit.m4 53 | saved_CFLAGS="$CFLAGS" 54 | CFLAGS="$CFLAGS -fvisibility=hidden " 55 | AC_MSG_CHECKING([if ${CC} supports -fvisibility=hidden]) 56 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([char foo;])], 57 | [ AC_MSG_RESULT([yes]) 58 | SYMBOL_VISIBILITY="-fvisibility=hidden"], 59 | AC_MSG_RESULT([no])) 60 | CFLAGS="$saved_CFLAGS" 61 | AC_SUBST(SYMBOL_VISIBILITY) 62 | 63 | AC_MSG_CHECKING(whether compiler understands -Wall) 64 | old_CFLAGS="$CFLAGS" 65 | CFLAGS="$CFLAGS -Wall -Wextra -Wno-unused-parameter -Wno-unused -Wsign-compare -Wdeclaration-after-statement" 66 | AC_TRY_COMPILE([],[], 67 | AC_MSG_RESULT(yes), 68 | AC_MSG_RESULT(no) 69 | CFLAGS="$old_CFLAGS") 70 | 71 | AC_ARG_ENABLE(driver-detach, 72 | [ --enable-driver-detach Enable detaching of kernel driver (disabled by default)], 73 | [if test x$enableval = xyes; then 74 | CFLAGS="$CFLAGS -DDETACH_KERNEL_DRIVER" 75 | fi]) 76 | 77 | dnl Generate the output 78 | AC_CONFIG_HEADER(config.h) 79 | 80 | AC_OUTPUT( 81 | librtlsdr.pc 82 | include/Makefile 83 | src/Makefile 84 | Makefile 85 | Doxyfile 86 | ) 87 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/include/rtlsdr_i2c.h: -------------------------------------------------------------------------------- 1 | #ifndef __I2C_H 2 | #define __I2C_H 3 | 4 | uint32_t rtlsdr_get_tuner_clock(void *dev); 5 | int rtlsdr_i2c_write_fn(void *dev, uint8_t addr, uint8_t *buf, int len); 6 | int rtlsdr_i2c_read_fn(void *dev, uint8_t addr, uint8_t *buf, int len); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | uint8_t fil_cal_code; 84 | uint8_t input; 85 | int has_lock; 86 | int init_done; 87 | 88 | /* Store current mode */ 89 | uint32_t delsys; 90 | enum r82xx_tuner_type type; 91 | 92 | uint32_t bw; /* in MHz */ 93 | 94 | void *rtl_dev; 95 | }; 96 | 97 | struct r82xx_freq_range { 98 | uint32_t freq; 99 | uint8_t open_d; 100 | uint8_t rf_mux_ploy; 101 | uint8_t tf_c; 102 | uint8_t xtal_cap20p; 103 | uint8_t xtal_cap10p; 104 | uint8_t xtal_cap0p; 105 | }; 106 | 107 | enum r82xx_delivery_system { 108 | SYS_UNDEFINED, 109 | SYS_DVBT, 110 | SYS_DVBT2, 111 | SYS_ISDBT, 112 | }; 113 | 114 | int r82xx_standby(struct r82xx_priv *priv); 115 | int r82xx_init(struct r82xx_priv *priv); 116 | int r82xx_set_freq(struct r82xx_priv *priv, uint32_t freq); 117 | int r82xx_set_gain(struct r82xx_priv *priv, int set_manual_gain, int gain); 118 | int r82xx_set_bandwidth(struct r82xx_priv *priv, int bandwidth, uint32_t rate); 119 | 120 | #endif 121 | -------------------------------------------------------------------------------- /librtlsdr/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}/ @RTLSDR_PC_CFLAGS@ 10 | Libs: -L${libdir} -lrtlsdr -lusb-1.0 11 | Libs.private: @RTLSDR_PC_LIBS@ 12 | -------------------------------------------------------------------------------- /librtlsdr/m4/.gitignore: -------------------------------------------------------------------------------- 1 | /libtool.m4 2 | /lt*.m4 3 | -------------------------------------------------------------------------------- /librtlsdr/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", MODE:="0666" 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", MODE:="0666" 23 | 24 | # DigitalNow Quad DVB-T PCI-E card (4x FC0012?) 25 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6680", MODE:="0666" 26 | 27 | # Leadtek WinFast DTV Dongle mini D (FC0012) 28 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0413", ATTRS{idProduct}=="6f0f", MODE:="0666" 29 | 30 | # Genius TVGo DVB-T03 USB dongle (Ver. B) 31 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0458", ATTRS{idProduct}=="707f", MODE:="0666" 32 | 33 | # Terratec Cinergy T Stick Black (rev 1) (FC0012) 34 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00a9", MODE:="0666" 35 | 36 | # Terratec NOXON rev 1 (FC0013) 37 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b3", MODE:="0666" 38 | 39 | # Terratec Deutschlandradio DAB Stick (FC0013) 40 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b4", MODE:="0666" 41 | 42 | # Terratec NOXON DAB Stick - Radio Energy (FC0013) 43 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b5", MODE:="0666" 44 | 45 | # Terratec Media Broadcast DAB Stick (FC0013) 46 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b7", MODE:="0666" 47 | 48 | # Terratec BR DAB Stick (FC0013) 49 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b8", MODE:="0666" 50 | 51 | # Terratec WDR DAB Stick (FC0013) 52 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00b9", MODE:="0666" 53 | 54 | # Terratec MuellerVerlag DAB Stick (FC0013) 55 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00c0", MODE:="0666" 56 | 57 | # Terratec Fraunhofer DAB Stick (FC0013) 58 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00c6", MODE:="0666" 59 | 60 | # Terratec Cinergy T Stick RC (Rev.3) (E4000) 61 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00d3", MODE:="0666" 62 | 63 | # Terratec T Stick PLUS (E4000) 64 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00d7", MODE:="0666" 65 | 66 | # Terratec NOXON rev 2 (E4000) 67 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="0ccd", ATTRS{idProduct}=="00e0", MODE:="0666" 68 | 69 | # PixelView PV-DT235U(RN) (FC0012) 70 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1554", ATTRS{idProduct}=="5020", MODE:="0666" 71 | 72 | # Astrometa DVB-T/DVB-T2 (R828D) 73 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="15f4", ATTRS{idProduct}=="0131", MODE:="0666" 74 | 75 | # Compro Videomate U620F (E4000) 76 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0620", MODE:="0666" 77 | 78 | # Compro Videomate U650F (E4000) 79 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0650", MODE:="0666" 80 | 81 | # Compro Videomate U680F (E4000) 82 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="185b", ATTRS{idProduct}=="0680", MODE:="0666" 83 | 84 | # GIGABYTE GT-U7300 (FC0012) 85 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d393", MODE:="0666" 86 | 87 | # DIKOM USB-DVBT HD 88 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d394", MODE:="0666" 89 | 90 | # Peak 102569AGPK (FC0012) 91 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d395", MODE:="0666" 92 | 93 | # KWorld KW-UB450-T USB DVB-T Pico TV (TUA9001) 94 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d397", MODE:="0666" 95 | 96 | # Zaapa ZT-MINDVBZP (FC0012) 97 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d398", MODE:="0666" 98 | 99 | # SVEON STV20 DVB-T USB & FM (FC0012) 100 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d39d", MODE:="0666" 101 | 102 | # Twintech UT-40 (FC0013) 103 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3a4", MODE:="0666" 104 | 105 | # ASUS U3100MINI_PLUS_V2 (FC0013) 106 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3a8", MODE:="0666" 107 | 108 | # SVEON STV27 DVB-T USB & FM (FC0013) 109 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3af", MODE:="0666" 110 | 111 | # SVEON STV21 DVB-T USB & FM 112 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1b80", ATTRS{idProduct}=="d3b0", MODE:="0666" 113 | 114 | # Dexatek DK DVB-T Dongle (Logilink VG0002A) (FC2580) 115 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1101", MODE:="0666" 116 | 117 | # Dexatek DK DVB-T Dongle (MSI DigiVox mini II V3.0) 118 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1102", MODE:="0666" 119 | 120 | # Dexatek DK 5217 DVB-T Dongle (FC2580) 121 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1103", MODE:="0666" 122 | 123 | # MSI DigiVox Micro HD (FC2580) 124 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1d19", ATTRS{idProduct}=="1104", MODE:="0666" 125 | 126 | # Sweex DVB-T USB (FC0012) 127 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="a803", MODE:="0666" 128 | 129 | # GTek T803 (FC0012) 130 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="b803", MODE:="0666" 131 | 132 | # Lifeview LV5TDeluxe (FC0012) 133 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="c803", MODE:="0666" 134 | 135 | # MyGica TD312 (FC0012) 136 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="d286", MODE:="0666" 137 | 138 | # PROlectrix DV107669 (FC0012) 139 | SUBSYSTEMS=="usb", ATTRS{idVendor}=="1f4d", ATTRS{idProduct}=="d803", MODE:="0666" 140 | -------------------------------------------------------------------------------- /librtlsdr/src/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 | MACRO(RTLSDR_APPEND_SRCS) 21 | LIST(APPEND rtlsdr_srcs ${ARGV}) 22 | ENDMACRO(RTLSDR_APPEND_SRCS) 23 | 24 | RTLSDR_APPEND_SRCS( 25 | librtlsdr.c 26 | tuner_e4k.c 27 | tuner_fc0012.c 28 | tuner_fc0013.c 29 | tuner_fc2580.c 30 | tuner_r82xx.c 31 | ) 32 | 33 | ######################################################################## 34 | # Set up Windows DLL resource files 35 | ######################################################################## 36 | IF(MSVC) 37 | include(${CMAKE_SOURCE_DIR}/cmake/Modules/Version.cmake) 38 | 39 | configure_file( 40 | ${CMAKE_CURRENT_SOURCE_DIR}/rtlsdr.rc.in 41 | ${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc 42 | @ONLY) 43 | 44 | RTLSDR_APPEND_SRCS(${CMAKE_CURRENT_BINARY_DIR}/rtlsdr.rc) 45 | ENDIF(MSVC) 46 | 47 | ######################################################################## 48 | # Setup shared library variant 49 | ######################################################################## 50 | add_library(rtlsdr_shared SHARED ${rtlsdr_srcs}) 51 | target_link_libraries(rtlsdr_shared ${LIBUSB_LIBRARIES}) 52 | set_target_properties(rtlsdr_shared PROPERTIES DEFINE_SYMBOL "rtlsdr_EXPORTS") 53 | set_target_properties(rtlsdr_shared PROPERTIES OUTPUT_NAME rtlsdr) 54 | set_target_properties(rtlsdr_shared PROPERTIES SOVERSION ${MAJOR_VERSION}) 55 | set_target_properties(rtlsdr_shared PROPERTIES VERSION ${LIBVER}) 56 | 57 | ######################################################################## 58 | # Setup static library variant 59 | ######################################################################## 60 | add_library(rtlsdr_static STATIC ${rtlsdr_srcs}) 61 | target_link_libraries(rtlsdr_static ${LIBUSB_LIBRARIES}) 62 | set_property(TARGET rtlsdr_static APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 63 | if(NOT WIN32) 64 | # Force same library filename for static and shared variants of the library 65 | set_target_properties(rtlsdr_static PROPERTIES OUTPUT_NAME rtlsdr) 66 | endif() 67 | 68 | ######################################################################## 69 | # Setup libraries used in executables 70 | ######################################################################## 71 | add_library(convenience_static STATIC 72 | convenience/convenience.c 73 | ) 74 | 75 | if(WIN32) 76 | add_library(libgetopt_static STATIC 77 | getopt/getopt.c 78 | ) 79 | target_link_libraries(convenience_static 80 | rtlsdr_shared 81 | ) 82 | endif() 83 | 84 | ######################################################################## 85 | # Build utility 86 | ######################################################################## 87 | add_executable(rtl_sdr rtl_sdr.c) 88 | add_executable(rtl_tcp rtl_tcp.c) 89 | add_executable(rtl_test rtl_test.c) 90 | add_executable(rtl_fm rtl_fm.c) 91 | add_executable(rtl_eeprom rtl_eeprom.c) 92 | add_executable(rtl_adsb rtl_adsb.c) 93 | add_executable(rtl_power rtl_power.c) 94 | set(INSTALL_TARGETS rtlsdr_shared rtlsdr_static rtl_sdr rtl_tcp rtl_test rtl_fm rtl_eeprom rtl_adsb rtl_power) 95 | 96 | target_link_libraries(rtl_sdr rtlsdr_shared convenience_static 97 | ${LIBUSB_LIBRARIES} 98 | ${CMAKE_THREAD_LIBS_INIT} 99 | ) 100 | target_link_libraries(rtl_tcp rtlsdr_shared convenience_static 101 | ${LIBUSB_LIBRARIES} 102 | ${CMAKE_THREAD_LIBS_INIT} 103 | ) 104 | target_link_libraries(rtl_test rtlsdr_shared convenience_static 105 | ${LIBUSB_LIBRARIES} 106 | ${CMAKE_THREAD_LIBS_INIT} 107 | ) 108 | target_link_libraries(rtl_fm rtlsdr_shared convenience_static 109 | ${LIBUSB_LIBRARIES} 110 | ${CMAKE_THREAD_LIBS_INIT} 111 | ) 112 | target_link_libraries(rtl_eeprom rtlsdr_shared convenience_static 113 | ${LIBUSB_LIBRARIES} 114 | ${CMAKE_THREAD_LIBS_INIT} 115 | ) 116 | target_link_libraries(rtl_adsb rtlsdr_shared convenience_static 117 | ${LIBUSB_LIBRARIES} 118 | ${CMAKE_THREAD_LIBS_INIT} 119 | ) 120 | target_link_libraries(rtl_power rtlsdr_shared convenience_static 121 | ${LIBUSB_LIBRARIES} 122 | ${CMAKE_THREAD_LIBS_INIT} 123 | ) 124 | if(UNIX) 125 | target_link_libraries(rtl_fm m) 126 | target_link_libraries(rtl_adsb m) 127 | target_link_libraries(rtl_power m) 128 | if(APPLE) 129 | target_link_libraries(rtl_test m) 130 | else() 131 | target_link_libraries(rtl_test m rt) 132 | endif() 133 | endif() 134 | 135 | if(WIN32) 136 | target_link_libraries(rtl_sdr libgetopt_static) 137 | target_link_libraries(rtl_tcp ws2_32 libgetopt_static) 138 | target_link_libraries(rtl_test libgetopt_static) 139 | target_link_libraries(rtl_fm libgetopt_static) 140 | target_link_libraries(rtl_eeprom libgetopt_static) 141 | target_link_libraries(rtl_adsb libgetopt_static) 142 | target_link_libraries(rtl_power libgetopt_static) 143 | set_property(TARGET rtl_sdr APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 144 | set_property(TARGET rtl_tcp APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 145 | set_property(TARGET rtl_test APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 146 | set_property(TARGET rtl_fm APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 147 | set_property(TARGET rtl_eeprom APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 148 | set_property(TARGET rtl_adsb APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 149 | set_property(TARGET rtl_power APPEND PROPERTY COMPILE_DEFINITIONS "rtlsdr_STATIC" ) 150 | endif() 151 | ######################################################################## 152 | # Install built library files & utilities 153 | ######################################################################## 154 | install(TARGETS ${INSTALL_TARGETS} 155 | LIBRARY DESTINATION ${LIB_INSTALL_DIR} # .so/.dylib file 156 | ARCHIVE DESTINATION ${LIB_INSTALL_DIR} # .lib file 157 | RUNTIME DESTINATION bin # .dll file 158 | ) 159 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | case 'm': 53 | case 'M': 54 | suff *= 1e3; 55 | case 'k': 56 | case 'K': 57 | suff *= 1e3; 58 | suff *= atof(s); 59 | s[len-1] = last; 60 | return suff; 61 | } 62 | s[len-1] = last; 63 | return atof(s); 64 | } 65 | 66 | double atoft(char *s) 67 | /* time suffixes, returns seconds */ 68 | { 69 | char last; 70 | int len; 71 | double suff = 1.0; 72 | len = strlen(s); 73 | last = s[len-1]; 74 | s[len-1] = '\0'; 75 | switch (last) { 76 | case 'h': 77 | case 'H': 78 | suff *= 60; 79 | case 'm': 80 | case 'M': 81 | suff *= 60; 82 | case 's': 83 | case 'S': 84 | suff *= atof(s); 85 | s[len-1] = last; 86 | return suff; 87 | } 88 | s[len-1] = last; 89 | return atof(s); 90 | } 91 | 92 | double atofp(char *s) 93 | /* percent suffixes */ 94 | { 95 | char last; 96 | int len; 97 | double suff = 1.0; 98 | len = strlen(s); 99 | last = s[len-1]; 100 | s[len-1] = '\0'; 101 | switch (last) { 102 | case '%': 103 | suff *= 0.01; 104 | suff *= atof(s); 105 | s[len-1] = last; 106 | return suff; 107 | } 108 | s[len-1] = last; 109 | return atof(s); 110 | } 111 | 112 | int nearest_gain(rtlsdr_dev_t *dev, int target_gain) 113 | { 114 | int i, r, err1, err2, count, nearest; 115 | int* gains; 116 | r = rtlsdr_set_tuner_gain_mode(dev, 1); 117 | if (r < 0) { 118 | fprintf(stderr, "WARNING: Failed to enable manual gain.\n"); 119 | return r; 120 | } 121 | count = rtlsdr_get_tuner_gains(dev, NULL); 122 | if (count <= 0) { 123 | return 0; 124 | } 125 | gains = malloc(sizeof(int) * count); 126 | count = rtlsdr_get_tuner_gains(dev, gains); 127 | nearest = gains[0]; 128 | for (i=0; i= 0 && device < device_count) { 263 | fprintf(stderr, "Using device %d: %s\n", 264 | device, rtlsdr_get_device_name((uint32_t)device)); 265 | return device; 266 | } 267 | /* does string exact match a serial */ 268 | for (i = 0; i < device_count; i++) { 269 | rtlsdr_get_device_usb_strings(i, vendor, product, serial); 270 | if (strcmp(s, serial) != 0) { 271 | continue;} 272 | device = i; 273 | fprintf(stderr, "Using device %d: %s\n", 274 | device, rtlsdr_get_device_name((uint32_t)device)); 275 | return device; 276 | } 277 | /* does string prefix match a serial */ 278 | for (i = 0; i < device_count; i++) { 279 | rtlsdr_get_device_usb_strings(i, vendor, product, serial); 280 | if (strncmp(s, serial, strlen(s)) != 0) { 281 | continue;} 282 | device = i; 283 | fprintf(stderr, "Using device %d: %s\n", 284 | device, rtlsdr_get_device_name((uint32_t)device)); 285 | return device; 286 | } 287 | /* does string suffix match a serial */ 288 | for (i = 0; i < device_count; i++) { 289 | rtlsdr_get_device_usb_strings(i, vendor, product, serial); 290 | offset = strlen(serial) - strlen(s); 291 | if (offset < 0) { 292 | continue;} 293 | if (strncmp(s, serial+offset, strlen(s)) != 0) { 294 | continue;} 295 | device = i; 296 | fprintf(stderr, "Using device %d: %s\n", 297 | device, rtlsdr_get_device_name((uint32_t)device)); 298 | return device; 299 | } 300 | fprintf(stderr, "No matching devices found.\n"); 301 | return -1; 302 | } 303 | 304 | // vim: tabstop=8:softtabstop=8:shiftwidth=8:noexpandtab 305 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /librtlsdr/src/rtl_biast.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_ir; 47 | int remote_wakeup; 48 | } rtlsdr_config_t; 49 | 50 | 51 | void usage(void) 52 | { 53 | fprintf(stderr, 54 | "rtl_biast, a tool for turning the RTL-SDR.com \n" 55 | "bias tee ON and OFF. Example to turn on the \n" 56 | "bias tee: rtl_biast -d 0 -b 1\n\n" 57 | "Usage:\n" 58 | "\t[-d device_index (default: 0)]\n" 59 | "\t[-b bias_on (default: 0)]\n"); 60 | exit(1); 61 | } 62 | 63 | int main(int argc, char **argv) 64 | { 65 | int r, opt; 66 | uint32_t dev_index = 0; 67 | uint32_t bias_on = 0; 68 | 69 | while ((opt = getopt(argc, argv, "d:b:h?")) != -1) { 70 | switch (opt) { 71 | case 'd': 72 | dev_index = atoi(optarg); 73 | break; 74 | case 'b': 75 | bias_on = atoi(optarg); 76 | break; 77 | default: 78 | usage(); 79 | break; 80 | } 81 | } 82 | 83 | r = rtlsdr_open(&dev, dev_index); 84 | 85 | rtlsdr_set_bias_tee(dev, bias_on); 86 | 87 | //rtlsdr_set_direct_sampling(dev, 1); 88 | 89 | 90 | rtlsdr_close(dev); 91 | 92 | return r >= 0 ? r : -r; 93 | } 94 | -------------------------------------------------------------------------------- /librtlsdr/src/rtl_gpio.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "rtl-sdr.h" 11 | #include "convenience/convenience.h" 12 | 13 | static rtlsdr_dev_t *dev = NULL; 14 | 15 | 16 | void usage(void) 17 | { 18 | fprintf(stderr, 19 | "rtl_gpio, read/write gpio on RTL2832 based DVB-T receivers\n\n" 20 | "Usage:\n" 21 | "\t[-g gpio bit to read/write, default 0\n" 22 | "\t[-v value to write: 0 or 1, default 0\n" 23 | "\t[-o set gpio to output, default\n" 24 | "\t[-i set gpio to input, read value, -v if given is ignored\n" 25 | "\t[-d device\n"); 26 | exit(1); 27 | } 28 | 29 | 30 | 31 | int main(int argc, char **argv) 32 | { 33 | int dev_index = 0; 34 | int dev_given = 0; 35 | int gpio_bit = 0; 36 | int gpio_value = -1; 37 | int gpio_input = 0; 38 | int r; 39 | int opt; 40 | 41 | while ((opt = getopt(argc, argv, "d:g:v:oi")) != -1) { 42 | switch (opt) { 43 | case 'd': 44 | dev_index = verbose_device_search(optarg); 45 | dev_given = 1; 46 | break; 47 | case 'g': 48 | gpio_bit = (uint32_t)atof(optarg); 49 | break; 50 | case 'v': 51 | gpio_value = ((uint32_t)atof(optarg)==0)? 0 : 1; 52 | break; 53 | case 'o': 54 | gpio_input = 0;// output mode 55 | break; 56 | case 'i': 57 | gpio_input = 1; 58 | break; 59 | default: 60 | usage(); 61 | break; 62 | } 63 | } 64 | 65 | if (!dev_given) { 66 | dev_index = verbose_device_search("0"); 67 | } 68 | 69 | if (dev_index < 0) { 70 | exit(1); 71 | } 72 | 73 | r = rtlsdr_open(&dev, (uint32_t)dev_index); 74 | if (r < 0) { 75 | fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index); 76 | exit(1); 77 | } 78 | 79 | /* Reset endpoint before we start reading from it (mandatory) */ 80 | verbose_reset_buffer(dev); 81 | 82 | if (gpio_input) { // put gpio in input mode, and read from it, print value 83 | rtlsdr_set_gpio_input(dev, gpio_bit); 84 | r = rtlsdr_get_gpio_bit(dev, gpio_bit); 85 | printf("%d\n", r); 86 | } else { // put gpio in output mode, write value to it, print old value. 87 | rtlsdr_set_gpio_output(dev, gpio_bit); 88 | r = rtlsdr_get_gpio_bit(dev, gpio_bit); 89 | printf("%d\n", r); 90 | if (gpio_value > -1) 91 | rtlsdr_set_gpio_bit(dev, gpio_bit, gpio_value); 92 | } 93 | 94 | rtlsdr_close(dev); 95 | 96 | return r >= 0 ? r : -r; 97 | } 98 | 99 | -------------------------------------------------------------------------------- /librtlsdr/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 | "\tfilename (a '-' dumps samples to stdout)\n\n"); 59 | exit(1); 60 | } 61 | 62 | #ifdef _WIN32 63 | BOOL WINAPI 64 | sighandler(int signum) 65 | { 66 | if (CTRL_C_EVENT == signum) { 67 | fprintf(stderr, "Signal caught, exiting!\n"); 68 | do_exit = 1; 69 | rtlsdr_cancel_async(dev); 70 | return TRUE; 71 | } 72 | return FALSE; 73 | } 74 | #else 75 | static void sighandler(int signum) 76 | { 77 | fprintf(stderr, "Signal caught, exiting!\n"); 78 | do_exit = 1; 79 | rtlsdr_cancel_async(dev); 80 | } 81 | #endif 82 | 83 | static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx) 84 | { 85 | if (ctx) { 86 | if (do_exit) 87 | return; 88 | 89 | if ((bytes_to_read > 0) && (bytes_to_read < len)) { 90 | len = bytes_to_read; 91 | do_exit = 1; 92 | rtlsdr_cancel_async(dev); 93 | } 94 | 95 | if (fwrite(buf, 1, len, (FILE*)ctx) != len) { 96 | fprintf(stderr, "Short write, samples lost, exiting!\n"); 97 | rtlsdr_cancel_async(dev); 98 | } 99 | 100 | if (bytes_to_read > 0) 101 | bytes_to_read -= len; 102 | } 103 | } 104 | 105 | int main(int argc, char **argv) 106 | { 107 | #ifndef _WIN32 108 | struct sigaction sigact; 109 | #endif 110 | char *filename = NULL; 111 | int n_read; 112 | int r, opt; 113 | int gain = 0; 114 | int ppm_error = 0; 115 | int sync_mode = 0; 116 | FILE *file; 117 | uint8_t *buffer; 118 | int dev_index = 0; 119 | int dev_given = 0; 120 | uint32_t frequency = 100000000; 121 | uint32_t samp_rate = DEFAULT_SAMPLE_RATE; 122 | uint32_t out_block_size = DEFAULT_BUF_LENGTH; 123 | 124 | while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:S")) != -1) { 125 | switch (opt) { 126 | case 'd': 127 | dev_index = verbose_device_search(optarg); 128 | dev_given = 1; 129 | break; 130 | case 'f': 131 | frequency = (uint32_t)atofs(optarg); 132 | break; 133 | case 'g': 134 | gain = (int)(atof(optarg) * 10); /* tenths of a dB */ 135 | break; 136 | case 's': 137 | samp_rate = (uint32_t)atofs(optarg); 138 | break; 139 | case 'p': 140 | ppm_error = atoi(optarg); 141 | break; 142 | case 'b': 143 | out_block_size = (uint32_t)atof(optarg); 144 | break; 145 | case 'n': 146 | bytes_to_read = (uint32_t)atof(optarg) * 2; 147 | break; 148 | case 'S': 149 | sync_mode = 1; 150 | break; 151 | default: 152 | usage(); 153 | break; 154 | } 155 | } 156 | 157 | if (argc <= optind) { 158 | usage(); 159 | } else { 160 | filename = argv[optind]; 161 | } 162 | 163 | if(out_block_size < MINIMAL_BUF_LENGTH || 164 | out_block_size > MAXIMAL_BUF_LENGTH ){ 165 | fprintf(stderr, 166 | "Output block size wrong value, falling back to default\n"); 167 | fprintf(stderr, 168 | "Minimal length: %u\n", MINIMAL_BUF_LENGTH); 169 | fprintf(stderr, 170 | "Maximal length: %u\n", MAXIMAL_BUF_LENGTH); 171 | out_block_size = DEFAULT_BUF_LENGTH; 172 | } 173 | 174 | buffer = malloc(out_block_size * sizeof(uint8_t)); 175 | 176 | if (!dev_given) { 177 | dev_index = verbose_device_search("0"); 178 | } 179 | 180 | if (dev_index < 0) { 181 | exit(1); 182 | } 183 | 184 | r = rtlsdr_open(&dev, (uint32_t)dev_index); 185 | if (r < 0) { 186 | fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index); 187 | exit(1); 188 | } 189 | #ifndef _WIN32 190 | sigact.sa_handler = sighandler; 191 | sigemptyset(&sigact.sa_mask); 192 | sigact.sa_flags = 0; 193 | sigaction(SIGINT, &sigact, NULL); 194 | sigaction(SIGTERM, &sigact, NULL); 195 | sigaction(SIGQUIT, &sigact, NULL); 196 | sigaction(SIGPIPE, &sigact, NULL); 197 | #else 198 | SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE ); 199 | #endif 200 | /* Set the sample rate */ 201 | verbose_set_sample_rate(dev, samp_rate); 202 | 203 | /* Set the frequency */ 204 | verbose_set_frequency(dev, frequency); 205 | 206 | if (0 == gain) { 207 | /* Enable automatic gain */ 208 | verbose_auto_gain(dev); 209 | } else { 210 | /* Enable manual gain */ 211 | gain = nearest_gain(dev, gain); 212 | verbose_gain_set(dev, gain); 213 | } 214 | 215 | verbose_ppm_set(dev, ppm_error); 216 | 217 | if(strcmp(filename, "-") == 0) { /* Write samples to stdout */ 218 | file = stdout; 219 | #ifdef _WIN32 220 | _setmode(_fileno(stdin), _O_BINARY); 221 | #endif 222 | } else { 223 | file = fopen(filename, "wb"); 224 | if (!file) { 225 | fprintf(stderr, "Failed to open %s\n", filename); 226 | goto out; 227 | } 228 | } 229 | 230 | /* Reset endpoint before we start reading from it (mandatory) */ 231 | verbose_reset_buffer(dev); 232 | 233 | if (sync_mode) { 234 | fprintf(stderr, "Reading samples in sync mode...\n"); 235 | while (!do_exit) { 236 | r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read); 237 | if (r < 0) { 238 | fprintf(stderr, "WARNING: sync read failed.\n"); 239 | break; 240 | } 241 | 242 | if ((bytes_to_read > 0) && (bytes_to_read < (uint32_t)n_read)) { 243 | n_read = bytes_to_read; 244 | do_exit = 1; 245 | } 246 | 247 | if (fwrite(buffer, 1, n_read, file) != (size_t)n_read) { 248 | fprintf(stderr, "Short write, samples lost, exiting!\n"); 249 | break; 250 | } 251 | 252 | if ((uint32_t)n_read < out_block_size) { 253 | fprintf(stderr, "Short read, samples lost, exiting!\n"); 254 | break; 255 | } 256 | 257 | if (bytes_to_read > 0) 258 | bytes_to_read -= n_read; 259 | } 260 | } else { 261 | fprintf(stderr, "Reading samples in async mode...\n"); 262 | r = rtlsdr_read_async(dev, rtlsdr_callback, (void *)file, 263 | 0, out_block_size); 264 | } 265 | 266 | if (do_exit) 267 | fprintf(stderr, "\nUser cancel, exiting...\n"); 268 | else 269 | fprintf(stderr, "\nLibrary error %d, exiting...\n", r); 270 | 271 | if (file != stdout) 272 | fclose(file); 273 | 274 | rtlsdr_close(dev); 275 | free (buffer); 276 | out: 277 | return r >= 0 ? r : -r; 278 | } 279 | -------------------------------------------------------------------------------- /librtlsdr/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 | -------------------------------------------------------------------------------- /star_fm/Makefile: -------------------------------------------------------------------------------- 1 | # (c) 2016 Outernet Inc 2 | # This file is part of StarSDR. 3 | 4 | # StarSDR is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Lesseer General Public License as 6 | # published by the Free Software Foundation, either version 3 of 7 | # the License, or (at your option) any later version. 8 | 9 | # StarSDR 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 Lesser General Public License for more details. 13 | 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with StarSDR. If not, see . 16 | 17 | 18 | .PHONY: all clean 19 | 20 | all: star_fm 21 | 22 | star_fm: star_fm.c convenience.c 23 | rm -f ./libstarsdr.so 24 | ln -s $(DEPS)libstarsdr_mirics.so ./libstarsdr.so 25 | $(CC) -Wall -O3 $(CFLAGS) -o star_fm -I../include -I$(DEPS) $^ -Wl,--allow-shlib-undefined $(LFLAGS) -L$(DEPS) -L. -lpthread -lm -lstarsdr 26 | rm -f ./libstarsdr.so 27 | 28 | display: display.c 29 | $(CROSS_COMPILE)gcc -Wall -O3 -Wno-unused-result -o display $^ -lX11 30 | 31 | clean: 32 | rm -f star_fm display 33 | 34 | 35 | -------------------------------------------------------------------------------- /star_fm/Readme.txt: -------------------------------------------------------------------------------- 1 | 2 | # examples 3 | rm -f ./libstarsdr.so; ln -s ../out/libstarsdr_rtlsdr.so ./libstarsdr.so ; sudo LD_LIBRARY_PATH=./:../out/ ./star_fm -f 98.3e6 -s 200000 -r 32000 - | aplay -r 32k -f S16_LE 4 | rm -f ./libstarsdr.so; ln -s ../out/libstarsdr_mirics.so ./libstarsdr.so ; sudo LD_LIBRARY_PATH=./:../out/ ./star_fm -f 98.3e6 -s 200000 -r 32000 - | aplay -r 32k -f S16_LE 5 | 6 | # display can be used with a mkfifo and -w param to star_fm 7 | 8 | 9 | -------------------------------------------------------------------------------- /star_fm/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 | float nearest_gain(starsdr_device *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(starsdr_device *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(starsdr_device *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(starsdr_device *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(starsdr_device *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(starsdr_device *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(starsdr_device *dev, float 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(starsdr_device *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(starsdr_device *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 | -------------------------------------------------------------------------------- /star_fm/display.c: -------------------------------------------------------------------------------- 1 | // parts (C) 2016 Outernet Inc 2 | // derived from code by Brian Hammond, 1996 3 | 4 | /* 5 | # (c) 2016 Outernet Inc 6 | # This file is part of StarSDR. 7 | 8 | # StarSDR is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesseer General Public License as 10 | # published by the Free Software Foundation, either version 3 of 11 | # the License, or (at your option) any later version. 12 | 13 | # StarSDR is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU Lesser General Public License for more details. 17 | 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with StarSDR. If not, see . 20 | */ 21 | 22 | /* include the X library headers */ 23 | #include 24 | #include 25 | #include 26 | 27 | /* include some silly stuff */ 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | /* here are our X variables */ 34 | Display *dis; 35 | int screen; 36 | Window win; 37 | GC gc; 38 | 39 | /* here are our X routines declared! */ 40 | void init_x(); 41 | void close_x(); 42 | void redraw(); 43 | 44 | #define MAXPOINTS 1000 45 | #define WINSIZE 512 46 | 47 | XPoint points[MAXPOINTS]; 48 | 49 | 50 | unsigned long black,white; 51 | 52 | 53 | void plot(int num_samples) { 54 | XSetForeground(dis,gc,black); 55 | XDrawPoints(dis, win, gc, points, num_samples, CoordModeOrigin); 56 | //mode Specifies the coordinate mode. You can pass CoordModeOrigin or CoordModePrevious. 57 | }; 58 | 59 | 60 | void read_n_draw(int n) { 61 | int m; 62 | int16_t i,q; 63 | for(m=0;m> 0) + (WINSIZE>>1); 66 | points[m].y = (q >> 0) + (WINSIZE>>1); 67 | } 68 | plot(n); 69 | } 70 | 71 | 72 | int main () { 73 | XEvent event; /* the XEvent declaration !!! */ 74 | KeySym key; /* a dealie-bob to handle KeyPress Events */ 75 | char text[255]; /* a char buffer for KeyPress Events */ 76 | 77 | init_x(); 78 | int count=0; 79 | int maxcount=10; 80 | /* look for events forever... */ 81 | while(1) { 82 | /* get the next event and stuff it into our event variable. 83 | Note: only events we set the mask for are detected! 84 | */ 85 | count++; 86 | if (count>maxcount) 87 | XClearWindow(dis, win); 88 | 89 | // XNextEvent(dis, &event); 90 | read_n_draw(MAXPOINTS); 91 | 92 | if (event.type==Expose && event.xexpose.count==0) { 93 | /* the window was exposed redraw it! */ 94 | redraw(); 95 | } 96 | if (event.type==KeyPress&& 97 | XLookupString(&event.xkey,text,255,&key,0)==1) { 98 | /* use the XLookupString routine to convert the invent 99 | KeyPress data into regular text. Weird but necessary... 100 | */ 101 | if (text[0]=='q') { 102 | close_x(); 103 | } 104 | printf("You pressed the %c key!\n",text[0]); 105 | } 106 | if (event.type==ButtonPress) { 107 | /* tell where the mouse Button was Pressed */ 108 | int x=event.xbutton.x, 109 | y=event.xbutton.y; 110 | 111 | strcpy(text,"X is FUN!"); 112 | XSetForeground(dis,gc,rand()%event.xbutton.x%255); 113 | XDrawString(dis,win,gc,x,y, text, strlen(text)); 114 | } 115 | } 116 | 117 | return 0; 118 | } 119 | 120 | 121 | void init_x() { 122 | /* get the colors black and white (see section for details) */ 123 | // unsigned long black,white; 124 | 125 | dis=XOpenDisplay((char *)0); 126 | screen=DefaultScreen(dis); 127 | black=BlackPixel(dis,screen), 128 | white=WhitePixel(dis, screen); 129 | win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0, 130 | WINSIZE, WINSIZE, 5,black, white); 131 | XSetStandardProperties(dis,win,"Howdy","Hi",None,NULL,0,NULL); 132 | XSelectInput(dis, win, ExposureMask|ButtonPressMask|KeyPressMask); 133 | gc=XCreateGC(dis, win, 0,0); 134 | XSetBackground(dis,gc,white); 135 | XSetForeground(dis,gc,black); 136 | XClearWindow(dis, win); 137 | XMapRaised(dis, win); 138 | }; 139 | 140 | void close_x() { 141 | XFreeGC(dis, gc); 142 | XDestroyWindow(dis,win); 143 | XCloseDisplay(dis); 144 | exit(1); 145 | }; 146 | 147 | void redraw() { 148 | XClearWindow(dis, win); 149 | }; 150 | 151 | -------------------------------------------------------------------------------- /starsdr/COPYING.LESSER: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /starsdr/Makefile: -------------------------------------------------------------------------------- 1 | # (c) 2016 Outernet Inc 2 | # This file is part of StarSDR. 3 | 4 | # StarSDR is free software: you can redistribute it and/or modify 5 | # it under the terms of the GNU Lesseer General Public License as 6 | # published by the Free Software Foundation, either version 3 of 7 | # the License, or (at your option) any later version. 8 | 9 | # StarSDR 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 Lesser General Public License for more details. 13 | 14 | # You should have received a copy of the GNU Lesser General Public 15 | # License along with StarSDR. If not, see . 16 | 17 | 18 | .PHONY: all starsdr_mirics starsdr_rtlsdr 19 | 20 | ifneq (,$(findstring GUI,$(FLAGS))) 21 | CFLAGS += -DGUI 22 | LFLAGS += -lX11 23 | endif 24 | 25 | ifneq (,$(findstring DCFILTER,$(FLAGS))) 26 | CFLAGS += -DDCFILTER 27 | endif 28 | 29 | all: starsdr_mirics starsdr_rtlsdr 30 | 31 | starsdr_mirics: starsdr_mirics.c starsdr_ext.h 32 | $(CC) -Wall -O3 -fPIC $(CFLAGS) -shared \ 33 | -o ${OUTDIR}libstarsdr_mirics.so starsdr_mirics.c -I. $(LFLAGS) -L${DEPS} -lmirisdr 34 | 35 | starsdr_rtlsdr: starsdr_rtlsdr.c starsdr_ext.h 36 | $(CC) -Wall -O3 -fPIC $(CFLAGS) -shared -o ${OUTDIR}libstarsdr_rtlsdr.so starsdr_rtlsdr.c -I. $(LFLAGS) -L${DEPS} -lrtlsdr 37 | 38 | -------------------------------------------------------------------------------- /starsdr/display.c: -------------------------------------------------------------------------------- 1 | // parts (C) 2016 Outernet Inc 2 | // derived from code by Brian Hammond, 1996 3 | 4 | /* 5 | # (c) 2016 Outernet Inc 6 | # This file is part of StarSDR. 7 | 8 | # StarSDR is free software: you can redistribute it and/or modify 9 | # it under the terms of the GNU Lesseer General Public License as 10 | # published by the Free Software Foundation, either version 3 of 11 | # the License, or (at your option) any later version. 12 | 13 | # StarSDR is distributed in the hope that it will be useful, 14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | # GNU Lesser General Public License for more details. 17 | 18 | # You should have received a copy of the GNU Lesser General Public 19 | # License along with StarSDR. If not, see . 20 | */ 21 | 22 | /* include the X library headers */ 23 | #include 24 | #include 25 | #include 26 | 27 | /* include some silly stuff */ 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | /* here are our X variables */ 34 | Display *dis; 35 | int screen; 36 | Window win; 37 | GC gc; 38 | 39 | /* here are our X routines declared! */ 40 | void redraw(); 41 | 42 | #define MAXPOINTS 25000 43 | //#define WINSIZE 512 44 | int winsize; 45 | int batches; 46 | 47 | XPoint *points; 48 | 49 | 50 | unsigned long black,white; 51 | 52 | 53 | void plot(int num_samples) { 54 | XSetForeground(dis,gc,black); 55 | XDrawPoints(dis, win, gc, points, num_samples, CoordModeOrigin); 56 | }; 57 | 58 | 59 | void read_n_draw(int16_t *d, int n) { 60 | int m; 61 | for(m=0;m> 5) + (winsize>>1); 63 | points[m].y = (d[2*m+1] >> 5) + (winsize>>1); 64 | } 65 | plot(n); 66 | } 67 | 68 | 69 | void const_plot (int16_t *data, int num_points) { 70 | static int count=0; 71 | count++; 72 | 73 | if (count>batches) 74 | { 75 | XClearWindow(dis, win); 76 | count = 0; 77 | } 78 | read_n_draw(data, num_points); 79 | 80 | } 81 | 82 | 83 | void const_init(int b, int ws) { 84 | winsize = ws; 85 | batches =b ; 86 | points = malloc(sizeof(XPoint)*2*MAXPOINTS); 87 | batches = batches; 88 | dis=XOpenDisplay((char *)0); 89 | screen=DefaultScreen(dis); 90 | black=BlackPixel(dis,screen), 91 | white=WhitePixel(dis, screen); 92 | win=XCreateSimpleWindow(dis,DefaultRootWindow(dis),0,0, 93 | winsize, winsize, 5,black, white); 94 | XSetStandardProperties(dis,win,"Constelation","StarSDR",None,NULL,0,NULL); 95 | XSelectInput(dis, win, ExposureMask); 96 | gc=XCreateGC(dis, win, 0,0); 97 | XSetBackground(dis,gc,white); 98 | XSetForeground(dis,gc,black); 99 | XClearWindow(dis, win); 100 | XMapRaised(dis, win); 101 | }; 102 | 103 | void const_close() { 104 | XFreeGC(dis, gc); 105 | XDestroyWindow(dis,win); 106 | XCloseDisplay(dis); 107 | //exit(1); 108 | }; 109 | 110 | void redraw() { 111 | XClearWindow(dis, win); 112 | }; 113 | 114 | -------------------------------------------------------------------------------- /starsdr/mirisdr.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 by Steve Markgraf 3 | * Copyright (C) 2012 by Dimitri Stolnikov 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 __MIRISDR_H 20 | #define __MIRISDR_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #define mirisdr_STATIC 27 | 28 | /* uncommnet to get extended debug */ 29 | //#define MIRISDR_DEBUG 30 | 31 | #include 32 | #include 33 | 34 | typedef struct mirisdr_dev mirisdr_dev_t; 35 | 36 | /* devices */ 37 | MIRISDR_API uint32_t mirisdr_get_device_count (void); 38 | MIRISDR_API const char *mirisdr_get_device_name (uint32_t index); 39 | MIRISDR_API int mirisdr_get_device_usb_strings (uint32_t index, char *manufact, char *product, char *serial); 40 | 41 | /* main */ 42 | MIRISDR_API int mirisdr_open (mirisdr_dev_t **p, uint32_t index); 43 | MIRISDR_API int mirisdr_close (mirisdr_dev_t *p); 44 | MIRISDR_API int mirisdr_reset (mirisdr_dev_t *p); /* extra */ 45 | MIRISDR_API int mirisdr_reset_buffer (mirisdr_dev_t *p); 46 | MIRISDR_API int mirisdr_get_usb_strings (mirisdr_dev_t *dev, char *manufact, char *product, char *serial); 47 | 48 | /* sync */ 49 | MIRISDR_API int mirisdr_read_sync (mirisdr_dev_t *p, void *buf, int len, int *n_read); 50 | 51 | /* async */ 52 | typedef void(*mirisdr_read_async_cb_t) (unsigned char *buf, uint32_t len, void *ctx); 53 | MIRISDR_API int mirisdr_read_async (mirisdr_dev_t *p, mirisdr_read_async_cb_t cb, void *ctx, uint32_t num, uint32_t len); 54 | MIRISDR_API int mirisdr_cancel_async (mirisdr_dev_t *p); 55 | MIRISDR_API int mirisdr_cancel_async_now (mirisdr_dev_t *p); /* extra */ 56 | MIRISDR_API int mirisdr_start_async (mirisdr_dev_t *p); /* extra */ 57 | MIRISDR_API int mirisdr_stop_async (mirisdr_dev_t *p); /* extra */ 58 | 59 | /* adc */ 60 | MIRISDR_API int mirisdr_adc_init (mirisdr_dev_t *p); /* extra */ 61 | 62 | /* rate control */ 63 | MIRISDR_API int mirisdr_set_sample_rate (mirisdr_dev_t *p, uint32_t rate); 64 | MIRISDR_API uint32_t mirisdr_get_sample_rate (mirisdr_dev_t *p); 65 | 66 | /* sample format control */ 67 | MIRISDR_API int mirisdr_set_sample_format (mirisdr_dev_t *p, char *v); /* extra */ 68 | MIRISDR_API const char *mirisdr_get_sample_format (mirisdr_dev_t *p); /* extra */ 69 | 70 | /* streaming control */ 71 | MIRISDR_API int mirisdr_streaming_start (mirisdr_dev_t *p); /* extra */ 72 | MIRISDR_API int mirisdr_streaming_stop (mirisdr_dev_t *p); /* extra */ 73 | 74 | /* frequency */ 75 | MIRISDR_API int mirisdr_set_center_freq (mirisdr_dev_t *p, uint32_t freq); 76 | MIRISDR_API uint32_t mirisdr_get_center_freq (mirisdr_dev_t *p); 77 | MIRISDR_API int mirisdr_set_if_freq (mirisdr_dev_t *p, uint32_t freq); /* extra */ 78 | MIRISDR_API uint32_t mirisdr_get_if_freq (mirisdr_dev_t *p); /* extra */ 79 | MIRISDR_API int mirisdr_set_xtal_freq (mirisdr_dev_t *p, uint32_t freq);/* extra */ 80 | MIRISDR_API uint32_t mirisdr_get_xtal_freq (mirisdr_dev_t *p); /* extra */ 81 | MIRISDR_API int mirisdr_set_bandwidth (mirisdr_dev_t *p, uint32_t bw); /* extra */ 82 | MIRISDR_API uint32_t mirisdr_get_bandwidth (mirisdr_dev_t *p); /* extra */ 83 | MIRISDR_API int mirisdr_set_offset_tuning (mirisdr_dev_t *p, int on); /* extra */ 84 | 85 | /* not implemented yet */ 86 | MIRISDR_API int mirisdr_set_freq_correction (mirisdr_dev_t *p, int ppm); 87 | MIRISDR_API int mirisdr_set_direct_sampling (mirisdr_dev_t *p, int on); 88 | 89 | /* transfer */ 90 | MIRISDR_API int mirisdr_set_transfer (mirisdr_dev_t *p, char *v); /* extra */ 91 | MIRISDR_API const char *mirisdr_get_transfer (mirisdr_dev_t *p); /* extra */ 92 | 93 | /* gain */ 94 | MIRISDR_API int mirisdr_set_gain (mirisdr_dev_t *p); /* extra */ 95 | MIRISDR_API int mirisdr_get_tuner_gains (mirisdr_dev_t *dev, float *gains); 96 | MIRISDR_API int mirisdr_set_tuner_gain (mirisdr_dev_t *p, int gain); 97 | MIRISDR_API int mirisdr_get_tuner_gain (mirisdr_dev_t *p); /* extra */ 98 | MIRISDR_API int mirisdr_set_tuner_gain_mode (mirisdr_dev_t *p, int mode); 99 | MIRISDR_API int mirisdr_get_tuner_gain_mode (mirisdr_dev_t *p); /* extra */ 100 | MIRISDR_API int mirisdr_set_mixer_gain (mirisdr_dev_t *p, int gain); /* extra */ 101 | MIRISDR_API int mirisdr_set_lna_gain (mirisdr_dev_t *p, int gain); /* extra */ 102 | MIRISDR_API int mirisdr_set_baseband_gain (mirisdr_dev_t *p, int gain); /* extra */ 103 | MIRISDR_API int mirisdr_get_mixer_gain (mirisdr_dev_t *p); /* extra */ 104 | MIRISDR_API int mirisdr_get_lna_gain (mirisdr_dev_t *p); /* extra */ 105 | MIRISDR_API int mirisdr_get_baseband_gain (mirisdr_dev_t *p); /* extra */ 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif /* __MIRISDR_H */ 112 | -------------------------------------------------------------------------------- /starsdr/mirisdr_export.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 by Miroslav Slugen . 16 | */ 17 | 18 | #ifndef __MIRISDR_EXPORT_H 19 | #define __MIRISDR_EXPORT_H 20 | 21 | #if defined __GNUC__ 22 | # if __GNUC__ >= 4 23 | # define __SDR_EXPORT __attribute__((visibility("default"))) 24 | # define __SDR_IMPORT __attribute__((visibility("default"))) 25 | # else 26 | # define __SDR_EXPORT 27 | # define __SDR_IMPORT 28 | # endif 29 | #elif _MSC_VER 30 | # define __SDR_EXPORT __declspec(dllexport) 31 | # define __SDR_IMPORT __declspec(dllimport) 32 | #else 33 | # define __SDR_EXPORT 34 | # define __SDR_IMPORT 35 | #endif 36 | 37 | #ifndef mirisdr_STATIC 38 | # ifdef mirisdr_EXPORTS 39 | # define MIRISDR_API __SDR_EXPORT 40 | # else 41 | # define MIRISDR_API __SDR_IMPORT 42 | # endif 43 | #else 44 | # define MIRISDR_API 45 | #endif 46 | #endif /* __MIRISDR_EXPORT_H */ 47 | -------------------------------------------------------------------------------- /starsdr/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 | -------------------------------------------------------------------------------- /starsdr/starsdr_ext.h: -------------------------------------------------------------------------------- 1 | // modified from sdrio_ext.h, Copyright Scott Cutler 2 | 3 | /* 4 | # (c) 2016 Outernet Inc 5 | # This file is part of StarSDR. 6 | 7 | # StarSDR is free software: you can redistribute it and/or modify 8 | # it under the terms of the GNU Lesseer General Public License as 9 | # published by the Free Software Foundation, either version 3 of 10 | # the License, or (at your option) any later version. 11 | 12 | # StarSDR 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 Lesser General Public License for more details. 16 | 17 | # You should have received a copy of the GNU Lesser General Public 18 | # License along with StarSDR. If not, see . 19 | */ 20 | 21 | #include 22 | typedef uint8_t starsdr_uint8; 23 | typedef int8_t starsdr_int8; 24 | 25 | typedef uint16_t starsdr_uint16; 26 | typedef int16_t starsdr_int16; 27 | 28 | typedef uint32_t starsdr_uint32; 29 | typedef int32_t starsdr_int32; 30 | 31 | typedef uint64_t starsdr_uint64; 32 | typedef int64_t starsdr_int64; 33 | 34 | typedef float starsdr_float32; 35 | typedef double starsdr_float64; 36 | 37 | 38 | struct starsdr_device_t; 39 | typedef struct starsdr_device_t starsdr_device; 40 | 41 | typedef enum 42 | { 43 | starsdr_gain_mode_agc, 44 | starsdr_gain_mode_manual 45 | } starsdr_gain_mode; 46 | 47 | typedef enum 48 | { 49 | starsdr_caps_rx, 50 | starsdr_caps_tx, 51 | starsdr_caps_agc 52 | } starsdr_caps; 53 | 54 | 55 | typedef starsdr_int32 (*starsdr_rx_async_callback)(void *context, starsdr_int16 *samples, starsdr_int32 num_samples); 56 | typedef starsdr_int32 (*starsdr_tx_async_callback)(void *context, starsdr_int16 *samples, starsdr_int32 num_samples); 57 | 58 | 59 | 60 | #if __GNUC__ >= 4 61 | #define STARSDREXPORT __attribute__ ((visibility ("default"))) 62 | #else 63 | #define STARSDREXPORT 64 | #endif 65 | 66 | 67 | typedef starsdr_int32 (*starsdr_init_t)(); 68 | 69 | typedef starsdr_int32 (*starsdr_get_num_devices_t)(); 70 | 71 | typedef starsdr_device * (*starsdr_open_device_t)(starsdr_uint32 device_index); 72 | typedef starsdr_int32 (*starsdr_close_device_t)(starsdr_device *dev); 73 | 74 | typedef const char * (*starsdr_get_device_string_t)(starsdr_uint32 device_index); 75 | 76 | typedef starsdr_int32 (*starsdr_set_rx_samplerate_t)(starsdr_device *dev, starsdr_uint64 sample_rate); 77 | typedef starsdr_int32 (*starsdr_set_rx_frequency_t)(starsdr_device *dev, starsdr_uint64 frequency); 78 | 79 | typedef starsdr_int32 (*starsdr_set_tx_samplerate_t)(starsdr_device *dev, starsdr_uint64 sample_rate); 80 | typedef starsdr_int32 (*starsdr_set_tx_frequency_t)(starsdr_device *dev, starsdr_uint64 frequency); 81 | 82 | typedef starsdr_int32 (*starsdr_start_rx_t)(starsdr_device *dev, starsdr_rx_async_callback callback, void *context, int usb_buffer_num_samples); 83 | typedef starsdr_int32 (*starsdr_stop_rx_t)(starsdr_device *dev); 84 | 85 | typedef starsdr_int32 (*starsdr_start_tx_t)(starsdr_device *dev, starsdr_tx_async_callback callback, void *context); 86 | typedef starsdr_int32 (*starsdr_stop_tx_t)(starsdr_device *dev); 87 | 88 | typedef starsdr_int32 (*starsdr_get_num_samplerates_t)(starsdr_device *dev); 89 | typedef void (*starsdr_get_samplerates_t)(starsdr_device *dev, starsdr_uint32 *sample_rates_out); 90 | 91 | typedef starsdr_int64 (*starsdr_get_rx_frequency_t)(starsdr_device *dev); 92 | typedef starsdr_int64 (*starsdr_get_rx_samplerate_t)(starsdr_device *dev); 93 | 94 | typedef starsdr_int64 (*starsdr_get_tx_frequency_t)(starsdr_device *dev); 95 | typedef starsdr_int64 (*starsdr_get_tx_samplerate_t)(starsdr_device *dev); 96 | 97 | typedef starsdr_int32 (*starsdr_set_rx_gain_mode_t)(starsdr_device *dev, starsdr_gain_mode gain_mode); 98 | typedef starsdr_int32 (*starsdr_get_rx_gain_range_t)(starsdr_device *dev, starsdr_float32 *min, starsdr_float32 *max); 99 | typedef starsdr_int32 (*starsdr_set_rx_gain_t)(starsdr_device *dev, starsdr_float32 gain); 100 | 101 | typedef starsdr_int32 (*starsdr_get_tx_gain_range_t)(starsdr_device *dev, starsdr_float32 *min, starsdr_float32 *max); 102 | typedef starsdr_int32 (*starsdr_set_tx_gain_t)(starsdr_device *dev, starsdr_float32 gain); 103 | 104 | typedef void (*starsdr_get_tuning_range_t)(starsdr_device *dev, starsdr_uint64 *min, starsdr_uint64 *max); 105 | typedef starsdr_int32 (*starsdr_get_caps_t)(starsdr_device *dev, starsdr_caps caps); 106 | 107 | typedef starsdr_float32 (*starsdr_get_tuner_gain_t) (starsdr_device *dev); 108 | 109 | typedef starsdr_int32 (*starsdr_get_tuner_gains_t) (starsdr_device *dev, starsdr_float32 *gains); 110 | 111 | typedef starsdr_int32 (*starsdr_get_sample_bitsize_t) (starsdr_device *dev); 112 | 113 | #ifdef __cplusplus 114 | extern "C" { 115 | #endif 116 | 117 | STARSDREXPORT starsdr_int32 starsdr_init(); 118 | 119 | STARSDREXPORT starsdr_int32 starsdr_get_num_devices(); 120 | 121 | STARSDREXPORT starsdr_device * starsdr_open_device(starsdr_uint32 device_index); 122 | STARSDREXPORT starsdr_int32 starsdr_close_device(starsdr_device *dev); 123 | 124 | STARSDREXPORT const char * starsdr_get_device_string(starsdr_uint32 device_index); 125 | 126 | STARSDREXPORT starsdr_int32 starsdr_set_rx_samplerate(starsdr_device *dev, starsdr_uint64 sample_rate); 127 | STARSDREXPORT starsdr_int32 starsdr_set_rx_frequency(starsdr_device *dev, starsdr_uint64 frequency); 128 | 129 | STARSDREXPORT starsdr_int32 starsdr_set_tx_samplerate(starsdr_device *dev, starsdr_uint64 sample_rate); 130 | STARSDREXPORT starsdr_int32 starsdr_set_tx_frequency(starsdr_device *dev, starsdr_uint64 frequency); 131 | 132 | STARSDREXPORT starsdr_int32 starsdr_start_rx(starsdr_device *dev, starsdr_rx_async_callback callback, void *context, int usb_buffer_num_samples); 133 | STARSDREXPORT starsdr_int32 starsdr_stop_rx(starsdr_device *dev); 134 | 135 | STARSDREXPORT starsdr_int32 starsdr_start_tx(starsdr_device *dev, starsdr_rx_async_callback callback, void *context); 136 | STARSDREXPORT starsdr_int32 starsdr_stop_tx(starsdr_device *dev); 137 | 138 | STARSDREXPORT starsdr_int32 starsdr_get_num_samplerates(starsdr_device *dev); 139 | STARSDREXPORT void starsdr_get_samplerates(starsdr_device *dev, starsdr_uint32 *sample_rates_out); 140 | 141 | STARSDREXPORT starsdr_int64 starsdr_get_rx_frequency(starsdr_device *dev); 142 | STARSDREXPORT starsdr_int64 starsdr_get_rx_samplerate(starsdr_device *dev); 143 | 144 | STARSDREXPORT starsdr_int64 starsdr_get_tx_frequency(starsdr_device *dev); 145 | STARSDREXPORT starsdr_int64 starsdr_get_tx_samplerate(starsdr_device *dev); 146 | 147 | STARSDREXPORT starsdr_int32 starsdr_set_rx_gain_mode(starsdr_device *dev, starsdr_gain_mode gain_mode); 148 | STARSDREXPORT starsdr_int32 starsdr_get_rx_gain_range(starsdr_device *dev, starsdr_float32 *min, starsdr_float32 *max); 149 | STARSDREXPORT starsdr_int32 starsdr_set_rx_gain(starsdr_device *dev, starsdr_float32 gain); 150 | 151 | STARSDREXPORT starsdr_int32 starsdr_get_tx_gain_range(starsdr_device *dev, starsdr_float32 *min, starsdr_float32 *max); 152 | STARSDREXPORT starsdr_int32 starsdr_set_tx_gain(starsdr_device *dev, starsdr_float32 gain); 153 | 154 | STARSDREXPORT void starsdr_get_tuning_range(starsdr_device *dev, starsdr_uint64 *min, starsdr_uint64 *max); 155 | STARSDREXPORT starsdr_int32 starsdr_get_caps(starsdr_device *dev, starsdr_caps caps); 156 | 157 | STARSDREXPORT starsdr_float32 starsdr_get_tuner_gain(starsdr_device *dev); 158 | 159 | STARSDREXPORT starsdr_int32 starsdr_get_tuner_gains(starsdr_device *dev, starsdr_float32 *gains); 160 | 161 | STARSDREXPORT starsdr_int32 starsdr_get_sample_bitsize(starsdr_device *dev); 162 | 163 | #ifdef __cplusplus 164 | } 165 | #endif 166 | --------------------------------------------------------------------------------