Initial commit of files
This commit is contained in:
21
SoftwareDefined/HackRF/hackrf-2015.07.2/host/CMakeLists.txt
Normal file
21
SoftwareDefined/HackRF/hackrf-2015.07.2/host/CMakeLists.txt
Normal file
@ -0,0 +1,21 @@
|
||||
#top dir cmake project for libhackrf + tools
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project (hackrf_all)
|
||||
|
||||
add_subdirectory(libhackrf)
|
||||
add_subdirectory(hackrf-tools)
|
||||
|
||||
########################################################################
|
||||
# Create uninstall target
|
||||
########################################################################
|
||||
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||
@ONLY)
|
||||
|
||||
|
||||
add_custom_target(uninstall
|
||||
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||
)
|
||||
99
SoftwareDefined/HackRF/hackrf-2015.07.2/host/README.md
Normal file
99
SoftwareDefined/HackRF/hackrf-2015.07.2/host/README.md
Normal file
@ -0,0 +1,99 @@
|
||||
This repository contains host software (Linux/Windows) for HackRF, a project to
|
||||
produce a low cost, open source software radio platform.
|
||||
|
||||
##How to build the host software on Linux:
|
||||
|
||||
###Prerequisites for Linux (Debian/Ubuntu):
|
||||
|
||||
`sudo apt-get install build-essential cmake libusb-1.0-0-dev`
|
||||
|
||||
###Build host software on Linux:
|
||||
|
||||
`cd host`
|
||||
|
||||
`mkdir build`
|
||||
|
||||
`cd build`
|
||||
|
||||
`cmake ../ -DINSTALL_UDEV_RULES=ON`
|
||||
|
||||
`make`
|
||||
|
||||
`sudo make install`
|
||||
|
||||
`sudo ldconfig`
|
||||
|
||||
##Clean CMake temporary files/dirs:
|
||||
|
||||
`cd host/build`
|
||||
|
||||
`rm -rf *`
|
||||
|
||||
##How to build host software on Windows:
|
||||
|
||||
###Prerequisites for cygwin or mingw:
|
||||
|
||||
* cmake-2.8.12.1 or more see http://www.cmake.org/cmake/resources/software.html
|
||||
* libusbx-1.0.18 or more see http://sourceforge.net/projects/libusbx/files/latest/download?source=files
|
||||
* Install Windows driver for HackRF hardware or use Zadig see http://sourceforge.net/projects/libwdi/files/zadig
|
||||
- If you want to use Zadig select HackRF USB device and just install/replace it with WinUSB driver.
|
||||
|
||||
>**Note for Windows build:**
|
||||
You shall always execute hackrf-tools from Windows command shell and not from Cygwin or Mingw shell because on Cygwin/Mingw
|
||||
Ctrl C is not managed correctly and especially for hackrf_transfer the Ctrl C(abort) will not stop correctly and will corrupt the file.
|
||||
|
||||
###For Cygwin:
|
||||
|
||||
`cd host`
|
||||
|
||||
`mkdir build`
|
||||
|
||||
`cd build`
|
||||
|
||||
`cmake ../ -G "Unix Makefiles" -DCMAKE_LEGACY_CYGWIN_WIN32=1 -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/`
|
||||
|
||||
`make`
|
||||
|
||||
`make install`
|
||||
|
||||
|
||||
###For MinGW:
|
||||
|
||||
`cd host`
|
||||
|
||||
`mkdir build`
|
||||
|
||||
`cd build`
|
||||
|
||||
Normal version:
|
||||
|
||||
*
|
||||
`cmake ../ -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/`
|
||||
|
||||
Debug version:
|
||||
|
||||
*
|
||||
`cmake ../ -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/`
|
||||
|
||||
`make`
|
||||
|
||||
`make install`
|
||||
|
||||
###For Visual Studio 2012 x64
|
||||
`c:\hackrf\host\cmake>cmake ../ -G "Visual Studio 11 2012 Win64" -DLIBUSB_INCLUDE_DIR=c:\libusb-1.0.18-win\include\libusb-1.0 -DLIBUSB_LIBRARIES=c:\libusb-1.0.18-win\MS64\static\libusb-1.0.lib -DTHREADS_PTHREADS_INCLUDE_DIR=c:\pthreads-w32-2-9-1-release\Pre-built.2\include -DTHREADS_PTHREADS_WIN32_LIBRARY=c:\pthreads-w32-2-9-1-release\Pre-built.2\lib\x64\pthreadVC2.lib`
|
||||
|
||||
Solution file: `c:\hackrf\host\cmake\hackrf_all.sln`
|
||||
|
||||
##How to build host the software on FreeBSD
|
||||
|
||||
You can use the binary package:
|
||||
`# pkg install hackrf`
|
||||
|
||||
You can build and install from ports:
|
||||
`# cd /usr/ports/comms/hackrf`
|
||||
`# make install`
|
||||
|
||||
|
||||
principal author: Michael Ossmann <mike@ossmann.com>
|
||||
|
||||
http://greatscottgadgets.com/hackrf/
|
||||
@ -0,0 +1,32 @@
|
||||
# http://www.vtk.org/Wiki/CMake_FAQ#Can_I_do_.22make_uninstall.22_with_CMake.3F
|
||||
|
||||
IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||
MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"")
|
||||
ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt")
|
||||
|
||||
FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files)
|
||||
STRING(REGEX REPLACE "\n" ";" files "${files}")
|
||||
FOREACH(file ${files})
|
||||
MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"")
|
||||
IF(EXISTS "$ENV{DESTDIR}${file}")
|
||||
EXEC_PROGRAM(
|
||||
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||
OUTPUT_VARIABLE rm_out
|
||||
RETURN_VALUE rm_retval
|
||||
)
|
||||
IF(NOT "${rm_retval}" STREQUAL 0)
|
||||
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
|
||||
ENDIF(NOT "${rm_retval}" STREQUAL 0)
|
||||
ELSEIF(IS_SYMLINK "$ENV{DESTDIR}${file}")
|
||||
EXEC_PROGRAM(
|
||||
"@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\""
|
||||
OUTPUT_VARIABLE rm_out
|
||||
RETURN_VALUE rm_retval
|
||||
)
|
||||
IF(NOT "${rm_retval}" STREQUAL 0)
|
||||
MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"")
|
||||
ENDIF(NOT "${rm_retval}" STREQUAL 0)
|
||||
ELSE(EXISTS "$ENV{DESTDIR}${file}")
|
||||
MESSAGE(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.")
|
||||
ENDIF(EXISTS "$ENV{DESTDIR}${file}")
|
||||
ENDFOREACH(file)
|
||||
@ -0,0 +1,55 @@
|
||||
# - Try to find the libhackrf library
|
||||
# Once done this defines
|
||||
#
|
||||
# LIBHACKRF_FOUND - system has libhackrf
|
||||
# LIBHACKRF_INCLUDE_DIR - the libhackrf include directory
|
||||
# LIBHACKRF_LIBRARIES - Link these to use libhackrf
|
||||
|
||||
# Copyright (c) 2013 Benjamin Vernoux
|
||||
#
|
||||
|
||||
|
||||
if (LIBHACKRF_INCLUDE_DIR AND LIBHACKRF_LIBRARIES)
|
||||
|
||||
# in cache already
|
||||
set(LIBHACKRF_FOUND TRUE)
|
||||
|
||||
else (LIBHACKRF_INCLUDE_DIR AND LIBHACKRF_LIBRARIES)
|
||||
IF (NOT WIN32)
|
||||
# use pkg-config to get the directories and then use these values
|
||||
# in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_LIBHACKRF QUIET libhackrf)
|
||||
ENDIF(NOT WIN32)
|
||||
|
||||
FIND_PATH(LIBHACKRF_INCLUDE_DIR
|
||||
NAMES hackrf.h
|
||||
HINTS $ENV{LIBHACKRF_DIR}/include ${PC_LIBHACKRF_INCLUDEDIR}
|
||||
PATHS /usr/local/include/libhackrf /usr/include/libhackrf /usr/local/include
|
||||
/usr/include ${CMAKE_SOURCE_DIR}/../libhackrf/src
|
||||
/opt/local/include/libhackrf
|
||||
${LIBHACKRF_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
set(libhackrf_library_names hackrf)
|
||||
|
||||
FIND_LIBRARY(LIBHACKRF_LIBRARIES
|
||||
NAMES ${libhackrf_library_names}
|
||||
HINTS $ENV{LIBHACKRF_DIR}/lib ${PC_LIBHACKRF_LIBDIR}
|
||||
PATHS /usr/local/lib /usr/lib /opt/local/lib ${PC_LIBHACKRF_LIBDIR} ${PC_LIBHACKRF_LIBRARY_DIRS} ${CMAKE_SOURCE_DIR}/../libhackrf/src
|
||||
)
|
||||
|
||||
if(LIBHACKRF_INCLUDE_DIR)
|
||||
set(CMAKE_REQUIRED_INCLUDES ${LIBHACKRF_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
if(LIBHACKRF_LIBRARIES)
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${LIBHACKRF_LIBRARIES})
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBHACKRF DEFAULT_MSG LIBHACKRF_LIBRARIES LIBHACKRF_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED(LIBHACKRF_INCLUDE_DIR LIBHACKRF_LIBRARIES)
|
||||
|
||||
endif (LIBHACKRF_INCLUDE_DIR AND LIBHACKRF_LIBRARIES)
|
||||
@ -0,0 +1,246 @@
|
||||
# Updated FindThreads.cmake that supports pthread-win32
|
||||
# Downloaded from http://www.vtk.org/Bug/bug_view_advanced_page.php?bug_id=6399
|
||||
|
||||
# - This module determines the thread library of the system.
|
||||
#
|
||||
# The following variables are set
|
||||
# CMAKE_THREAD_LIBS_INIT - the thread library
|
||||
# CMAKE_USE_SPROC_INIT - are we using sproc?
|
||||
# CMAKE_USE_WIN32_THREADS_INIT - using WIN32 threads?
|
||||
# CMAKE_USE_PTHREADS_INIT - are we using pthreads
|
||||
# CMAKE_HP_PTHREADS_INIT - are we using hp pthreads
|
||||
#
|
||||
# If use of pthreads-win32 is desired, the following variables
|
||||
# can be set.
|
||||
#
|
||||
# THREADS_USE_PTHREADS_WIN32 -
|
||||
# Setting this to true searches for the pthreads-win32
|
||||
# port (since CMake 2.8.0)
|
||||
#
|
||||
# THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME
|
||||
# C = no exceptions (default)
|
||||
# (NOTE: This is the default scheme on most POSIX thread
|
||||
# implementations and what you should probably be using)
|
||||
# CE = C++ Exception Handling
|
||||
# SE = Structure Exception Handling (MSVC only)
|
||||
# (NOTE: Changing this option from the default may affect
|
||||
# the portability of your application. See pthreads-win32
|
||||
# documentation for more details.)
|
||||
#
|
||||
#======================================================
|
||||
# Example usage where threading library
|
||||
# is provided by the system:
|
||||
#
|
||||
# find_package(Threads REQUIRED)
|
||||
# add_executable(foo foo.cc)
|
||||
# target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})
|
||||
#
|
||||
# Example usage if pthreads-win32 is desired on Windows
|
||||
# or a system provided thread library:
|
||||
#
|
||||
# set(THREADS_USE_PTHREADS_WIN32 true)
|
||||
# find_package(Threads REQUIRED)
|
||||
# include_directories(${THREADS_PTHREADS_INCLUDE_DIR})
|
||||
#
|
||||
# add_executable(foo foo.cc)
|
||||
# target_link_libraries(foo ${CMAKE_THREAD_LIBS_INIT})
|
||||
#
|
||||
|
||||
INCLUDE (CheckIncludeFiles)
|
||||
INCLUDE (CheckLibraryExists)
|
||||
SET(Threads_FOUND FALSE)
|
||||
|
||||
IF(WIN32 AND NOT CYGWIN AND THREADS_USE_PTHREADS_WIN32)
|
||||
SET(_Threads_ptwin32 true)
|
||||
ENDIF()
|
||||
|
||||
# Do we have sproc?
|
||||
IF(CMAKE_SYSTEM MATCHES IRIX)
|
||||
CHECK_INCLUDE_FILES("sys/types.h;sys/prctl.h" CMAKE_HAVE_SPROC_H)
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_HAVE_SPROC_H)
|
||||
# We have sproc
|
||||
SET(CMAKE_USE_SPROC_INIT 1)
|
||||
|
||||
ELSEIF(_Threads_ptwin32)
|
||||
|
||||
IF(NOT DEFINED THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME)
|
||||
# Assign the default scheme
|
||||
SET(THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME "C")
|
||||
ELSE()
|
||||
# Validate the scheme specified by the user
|
||||
IF(NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "C" AND
|
||||
NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "CE" AND
|
||||
NOT THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
|
||||
MESSAGE(FATAL_ERROR "See documentation for FindPthreads.cmake, only C, CE, and SE modes are allowed")
|
||||
ENDIF()
|
||||
IF(NOT MSVC AND THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
|
||||
MESSAGE(FATAL_ERROR "Structured Exception Handling is only allowed for MSVC")
|
||||
ENDIF(NOT MSVC AND THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME STREQUAL "SE")
|
||||
ENDIF()
|
||||
|
||||
FIND_PATH(THREADS_PTHREADS_INCLUDE_DIR pthread.h)
|
||||
|
||||
# Determine the library filename
|
||||
IF(MSVC)
|
||||
SET(_Threads_pthreads_libname
|
||||
pthreadV${THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME}2)
|
||||
ELSEIF(MINGW)
|
||||
SET(_Threads_pthreads_libname
|
||||
pthreadG${THREADS_PTHREADS_WIN32_EXCEPTION_SCHEME}2)
|
||||
ELSE()
|
||||
MESSAGE(FATAL_ERROR "This should never happen")
|
||||
ENDIF()
|
||||
|
||||
# Use the include path to help find the library if possible
|
||||
SET(_Threads_lib_paths "")
|
||||
IF(THREADS_PTHREADS_INCLUDE_DIR)
|
||||
GET_FILENAME_COMPONENT(_Threads_root_dir
|
||||
${THREADS_PTHREADS_INCLUDE_DIR} PATH)
|
||||
SET(_Threads_lib_paths ${_Threads_root_dir}/lib)
|
||||
ENDIF()
|
||||
FIND_LIBRARY(THREADS_PTHREADS_WIN32_LIBRARY
|
||||
NAMES ${_Threads_pthreads_libname}
|
||||
PATHS ${_Threads_lib_paths}
|
||||
DOC "The Portable Threads Library for Win32"
|
||||
NO_SYSTEM_PATH
|
||||
)
|
||||
|
||||
IF(THREADS_PTHREADS_INCLUDE_DIR AND THREADS_PTHREADS_WIN32_LIBRARY)
|
||||
MARK_AS_ADVANCED(THREADS_PTHREADS_INCLUDE_DIR)
|
||||
SET(CMAKE_THREAD_LIBS_INIT ${THREADS_PTHREADS_WIN32_LIBRARY})
|
||||
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
ENDIF()
|
||||
|
||||
MARK_AS_ADVANCED(THREADS_PTHREADS_WIN32_LIBRARY)
|
||||
|
||||
ELSE()
|
||||
# Do we have pthreads?
|
||||
CHECK_INCLUDE_FILES("pthread.h" CMAKE_HAVE_PTHREAD_H)
|
||||
IF(CMAKE_HAVE_PTHREAD_H)
|
||||
|
||||
#
|
||||
# We have pthread.h
|
||||
# Let's check for the library now.
|
||||
#
|
||||
SET(CMAKE_HAVE_THREADS_LIBRARY)
|
||||
IF(NOT THREADS_HAVE_PTHREAD_ARG)
|
||||
|
||||
# Do we have -lpthreads
|
||||
CHECK_LIBRARY_EXISTS(pthreads pthread_create "" CMAKE_HAVE_PTHREADS_CREATE)
|
||||
IF(CMAKE_HAVE_PTHREADS_CREATE)
|
||||
SET(CMAKE_THREAD_LIBS_INIT "-lpthreads")
|
||||
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
ENDIF()
|
||||
|
||||
# Ok, how about -lpthread
|
||||
CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
|
||||
IF(CMAKE_HAVE_PTHREAD_CREATE)
|
||||
SET(CMAKE_THREAD_LIBS_INIT "-lpthread")
|
||||
SET(Threads_FOUND TRUE)
|
||||
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_SYSTEM MATCHES "SunOS.*")
|
||||
# On sun also check for -lthread
|
||||
CHECK_LIBRARY_EXISTS(thread thr_create "" CMAKE_HAVE_THR_CREATE)
|
||||
IF(CMAKE_HAVE_THR_CREATE)
|
||||
SET(CMAKE_THREAD_LIBS_INIT "-lthread")
|
||||
SET(CMAKE_HAVE_THREADS_LIBRARY 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
ENDIF()
|
||||
ENDIF(CMAKE_SYSTEM MATCHES "SunOS.*")
|
||||
|
||||
ENDIF(NOT THREADS_HAVE_PTHREAD_ARG)
|
||||
|
||||
IF(NOT CMAKE_HAVE_THREADS_LIBRARY)
|
||||
# If we did not found -lpthread, -lpthread, or -lthread, look for -pthread
|
||||
IF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
|
||||
MESSAGE(STATUS "Check if compiler accepts -pthread")
|
||||
TRY_RUN(THREADS_PTHREAD_ARG THREADS_HAVE_PTHREAD_ARG
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_ROOT}/Modules/CheckForPthreads.c
|
||||
CMAKE_FLAGS -DLINK_LIBRARIES:STRING=-pthread
|
||||
COMPILE_OUTPUT_VARIABLE OUTPUT)
|
||||
|
||||
IF(THREADS_HAVE_PTHREAD_ARG)
|
||||
IF(THREADS_PTHREAD_ARG MATCHES "^2$")
|
||||
SET(Threads_FOUND TRUE)
|
||||
MESSAGE(STATUS "Check if compiler accepts -pthread - yes")
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Check if compiler accepts -pthread - no")
|
||||
FILE(APPEND
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Determining if compiler accepts -pthread returned ${THREADS_PTHREAD_ARG} instead of 2. The compiler had the following output:\n${OUTPUT}\n\n")
|
||||
ENDIF()
|
||||
ELSE()
|
||||
MESSAGE(STATUS "Check if compiler accepts -pthread - no")
|
||||
FILE(APPEND
|
||||
${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Determining if compiler accepts -pthread failed with the following output:\n${OUTPUT}\n\n")
|
||||
ENDIF()
|
||||
|
||||
ENDIF("THREADS_HAVE_PTHREAD_ARG" MATCHES "^THREADS_HAVE_PTHREAD_ARG")
|
||||
|
||||
IF(THREADS_HAVE_PTHREAD_ARG)
|
||||
SET(Threads_FOUND TRUE)
|
||||
SET(CMAKE_THREAD_LIBS_INIT "-pthread")
|
||||
ENDIF()
|
||||
|
||||
ENDIF(NOT CMAKE_HAVE_THREADS_LIBRARY)
|
||||
ENDIF(CMAKE_HAVE_PTHREAD_H)
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_THREAD_LIBS_INIT)
|
||||
SET(CMAKE_USE_PTHREADS_INIT 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_SYSTEM MATCHES "Windows"
|
||||
AND NOT THREADS_USE_PTHREADS_WIN32)
|
||||
SET(CMAKE_USE_WIN32_THREADS_INIT 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_USE_PTHREADS_INIT)
|
||||
IF(CMAKE_SYSTEM MATCHES "HP-UX-*")
|
||||
# Use libcma if it exists and can be used. It provides more
|
||||
# symbols than the plain pthread library. CMA threads
|
||||
# have actually been deprecated:
|
||||
# http://docs.hp.com/en/B3920-90091/ch12s03.html#d0e11395
|
||||
# http://docs.hp.com/en/947/d8.html
|
||||
# but we need to maintain compatibility here.
|
||||
# The CMAKE_HP_PTHREADS setting actually indicates whether CMA threads
|
||||
# are available.
|
||||
CHECK_LIBRARY_EXISTS(cma pthread_attr_create "" CMAKE_HAVE_HP_CMA)
|
||||
IF(CMAKE_HAVE_HP_CMA)
|
||||
SET(CMAKE_THREAD_LIBS_INIT "-lcma")
|
||||
SET(CMAKE_HP_PTHREADS_INIT 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
ENDIF(CMAKE_HAVE_HP_CMA)
|
||||
SET(CMAKE_USE_PTHREADS_INIT 1)
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_SYSTEM MATCHES "OSF1-V*")
|
||||
SET(CMAKE_USE_PTHREADS_INIT 0)
|
||||
SET(CMAKE_THREAD_LIBS_INIT )
|
||||
ENDIF()
|
||||
|
||||
IF(CMAKE_SYSTEM MATCHES "CYGWIN_NT*")
|
||||
SET(CMAKE_USE_PTHREADS_INIT 1)
|
||||
SET(Threads_FOUND TRUE)
|
||||
SET(CMAKE_THREAD_LIBS_INIT )
|
||||
SET(CMAKE_USE_WIN32_THREADS_INIT 0)
|
||||
ENDIF()
|
||||
ENDIF(CMAKE_USE_PTHREADS_INIT)
|
||||
|
||||
INCLUDE(FindPackageHandleStandardArgs)
|
||||
IF(_Threads_ptwin32)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG
|
||||
THREADS_PTHREADS_WIN32_LIBRARY THREADS_PTHREADS_INCLUDE_DIR)
|
||||
ELSE()
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Threads DEFAULT_MSG Threads_FOUND)
|
||||
ENDIF()
|
||||
@ -0,0 +1,43 @@
|
||||
# - Try to find the freetype library
|
||||
# Once done this defines
|
||||
#
|
||||
# LIBUSB_FOUND - system has libusb
|
||||
# LIBUSB_INCLUDE_DIR - the libusb include directory
|
||||
# LIBUSB_LIBRARIES - Link these to use libusb
|
||||
|
||||
# Copyright (c) 2006, 2008 Laurent Montel, <montel@kde.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
|
||||
if (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
|
||||
|
||||
# in cache already
|
||||
set(LIBUSB_FOUND TRUE)
|
||||
|
||||
else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
|
||||
IF (NOT WIN32)
|
||||
# use pkg-config to get the directories and then use these values
|
||||
# in the FIND_PATH() and FIND_LIBRARY() calls
|
||||
find_package(PkgConfig)
|
||||
pkg_check_modules(PC_LIBUSB libusb-1.0)
|
||||
ENDIF(NOT WIN32)
|
||||
|
||||
set(LIBUSB_LIBRARY_NAME usb-1.0)
|
||||
IF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
set(LIBUSB_LIBRARY_NAME usb)
|
||||
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
|
||||
|
||||
FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
|
||||
PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})
|
||||
|
||||
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES ${LIBUSB_LIBRARY_NAME}
|
||||
PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS})
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)
|
||||
|
||||
MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)
|
||||
|
||||
endif (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES)
|
||||
@ -0,0 +1,64 @@
|
||||
# Copyright 2012 Jared Boone
|
||||
# Copyright 2013 Benjamin Vernoux
|
||||
#
|
||||
# This file is part of HackRF.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
# Based heavily upon the libftdi cmake setup.
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(hackrf-tools C)
|
||||
set(MAJOR_VERSION 0)
|
||||
set(MINOR_VERSION 4)
|
||||
set(PACKAGE hackrf-tools)
|
||||
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
|
||||
set(VERSION ${VERSION_STRING})
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules)
|
||||
|
||||
if(MSVC)
|
||||
include_directories(getopt)
|
||||
add_definitions(/D _CRT_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
add_definitions(-Wall)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90")
|
||||
endif()
|
||||
|
||||
if(NOT libhackrf_SOURCE_DIR)
|
||||
find_package(LIBHACKRF REQUIRED)
|
||||
include_directories(${LIBHACKRF_INCLUDE_DIR})
|
||||
else()
|
||||
include_directories(${libhackrf_SOURCE_DIR}/src)
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
########################################################################
|
||||
# Create uninstall target
|
||||
########################################################################
|
||||
|
||||
if(NOT hackrf_all_SOURCE_DIR)
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/../cmake/cmake_uninstall.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||
@ONLY)
|
||||
|
||||
|
||||
add_custom_target(uninstall
|
||||
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||
)
|
||||
endif()
|
||||
@ -0,0 +1,34 @@
|
||||
This repository contains hardware designs and software for HackRF, a project to
|
||||
produce a low cost, open source software radio platform.
|
||||
|
||||

|
||||
|
||||
How to build host software on Windows:
|
||||
prerequisite for cygwin or mingw:
|
||||
* cmake-2.8.10.2 or more see http://www.cmake.org/cmake/resources/software.html
|
||||
* libusbx-1.0.14 or more see http://sourceforge.net/projects/libusbx/files/latest/download?source=files
|
||||
* Install Windows driver for HackRF hardware or use Zadig see http://sourceforge.net/projects/libwdi/files/zadig
|
||||
- If you want to use Zadig select HackRF USB device and just install/replace it with WinUSB driver.
|
||||
* Build libhackrf before to build this library, see host/libhackrf/Readme.md.
|
||||
|
||||
For Cygwin:
|
||||
cmake -G "Unix Makefiles" -DCMAKE_LEGACY_CYGWIN_WIN32=1 -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
|
||||
make
|
||||
make install
|
||||
|
||||
For Mingw:
|
||||
#normal version
|
||||
cmake -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
|
||||
#debug version
|
||||
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
|
||||
make
|
||||
make install
|
||||
|
||||
How to build host software on Linux:
|
||||
cmake ./
|
||||
make
|
||||
make install
|
||||
|
||||
principal author: Michael Ossmann <mike@ossmann.com>
|
||||
|
||||
http://greatscottgadgets.com/hackrf/
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,180 @@
|
||||
/* Declarations for getopt.
|
||||
Copyright (C) 1989-1994, 1996-1999, 2001 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, write to the Free
|
||||
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
||||
02111-1307 USA. */
|
||||
|
||||
#ifndef _GETOPT_H
|
||||
|
||||
#ifndef __need_getopt
|
||||
# define _GETOPT_H 1
|
||||
#endif
|
||||
|
||||
/* If __GNU_LIBRARY__ is not already defined, either we are being used
|
||||
standalone, or this is the first header included in the source file.
|
||||
If we are being used with glibc, we need to include <features.h>, but
|
||||
that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
|
||||
not defined, include <ctype.h>, which will pull in <features.h> for us
|
||||
if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
|
||||
doesn't flood the namespace with stuff the way some other headers do.) */
|
||||
#if !defined __GNU_LIBRARY__
|
||||
# include <ctype.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* For communication from `getopt' to the caller.
|
||||
When `getopt' finds an option that takes an argument,
|
||||
the argument value is returned here.
|
||||
Also, when `ordering' is RETURN_IN_ORDER,
|
||||
each non-option ARGV-element is returned here. */
|
||||
|
||||
extern char *optarg;
|
||||
|
||||
/* Index in ARGV of the next element to be scanned.
|
||||
This is used for communication to and from the caller
|
||||
and for communication between successive calls to `getopt'.
|
||||
|
||||
On entry to `getopt', zero means this is the first call; initialize.
|
||||
|
||||
When `getopt' returns -1, this is the index of the first of the
|
||||
non-option elements that the caller should itself scan.
|
||||
|
||||
Otherwise, `optind' communicates from one call to the next
|
||||
how much of ARGV has been scanned so far. */
|
||||
|
||||
extern int optind;
|
||||
|
||||
/* Callers store zero here to inhibit the error message `getopt' prints
|
||||
for unrecognized options. */
|
||||
|
||||
extern int opterr;
|
||||
|
||||
/* Set to an option character which was unrecognized. */
|
||||
|
||||
extern int optopt;
|
||||
|
||||
#ifndef __need_getopt
|
||||
/* Describe the long-named options requested by the application.
|
||||
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
|
||||
of `struct option' terminated by an element containing a name which is
|
||||
zero.
|
||||
|
||||
The field `has_arg' is:
|
||||
no_argument (or 0) if the option does not take an argument,
|
||||
required_argument (or 1) if the option requires an argument,
|
||||
optional_argument (or 2) if the option takes an optional argument.
|
||||
|
||||
If the field `flag' is not NULL, it points to a variable that is set
|
||||
to the value given in the field `val' when the option is found, but
|
||||
left unchanged if the option is not found.
|
||||
|
||||
To have a long-named option do something other than set an `int' to
|
||||
a compiled-in constant, such as set a value from `optarg', set the
|
||||
option's `flag' field to zero and its `val' field to a nonzero
|
||||
value (the equivalent single-letter option character, if there is
|
||||
one). For long options that have a zero `flag' field, `getopt'
|
||||
returns the contents of the `val' field. */
|
||||
|
||||
struct option
|
||||
{
|
||||
# if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
const char *name;
|
||||
# else
|
||||
char *name;
|
||||
# endif
|
||||
/* has_arg can't be an enum because some compilers complain about
|
||||
type mismatches in all the code that assumes it is an int. */
|
||||
int has_arg;
|
||||
int *flag;
|
||||
int val;
|
||||
};
|
||||
|
||||
/* Names for the values of the `has_arg' field of `struct option'. */
|
||||
|
||||
# define no_argument 0
|
||||
# define required_argument 1
|
||||
# define optional_argument 2
|
||||
#endif /* need getopt */
|
||||
|
||||
|
||||
/* Get definitions and prototypes for functions to process the
|
||||
arguments in ARGV (ARGC of them, minus the program name) for
|
||||
options given in OPTS.
|
||||
|
||||
Return the option character from OPTS just read. Return -1 when
|
||||
there are no more options. For unrecognized options, or options
|
||||
missing arguments, `optopt' is set to the option letter, and '?' is
|
||||
returned.
|
||||
|
||||
The OPTS string is a list of characters which are recognized option
|
||||
letters, optionally followed by colons, specifying that that letter
|
||||
takes an argument, to be placed in `optarg'.
|
||||
|
||||
If a letter in OPTS is followed by two colons, its argument is
|
||||
optional. This behavior is specific to the GNU `getopt'.
|
||||
|
||||
The argument `--' causes premature termination of argument
|
||||
scanning, explicitly telling `getopt' that there are no more
|
||||
options.
|
||||
|
||||
If OPTS begins with `--', then non-option arguments are treated as
|
||||
arguments to the option '\0'. This behavior is specific to the GNU
|
||||
`getopt'. */
|
||||
|
||||
#if (defined __STDC__ && __STDC__) || defined __cplusplus
|
||||
# ifdef __GNU_LIBRARY__
|
||||
/* Many other libraries have conflicting prototypes for getopt, with
|
||||
differences in the consts, in stdlib.h. To avoid compilation
|
||||
errors, only prototype getopt for the GNU C library. */
|
||||
extern int getopt (int __argc, char *const *__argv, const char *__shortopts);
|
||||
# else /* not __GNU_LIBRARY__ */
|
||||
extern int getopt ();
|
||||
# endif /* __GNU_LIBRARY__ */
|
||||
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind);
|
||||
extern int getopt_long_only (int __argc, char *const *__argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind);
|
||||
|
||||
/* Internal only. Users should not call this directly. */
|
||||
extern int _getopt_internal (int __argc, char *const *__argv,
|
||||
const char *__shortopts,
|
||||
const struct option *__longopts, int *__longind,
|
||||
int __long_only);
|
||||
# endif
|
||||
#else /* not __STDC__ */
|
||||
extern int getopt ();
|
||||
# ifndef __need_getopt
|
||||
extern int getopt_long ();
|
||||
extern int getopt_long_only ();
|
||||
|
||||
extern int _getopt_internal ();
|
||||
# endif
|
||||
#endif /* __STDC__ */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Make sure we later can get all the definitions and declarations. */
|
||||
#undef __need_getopt
|
||||
|
||||
#endif /* getopt.h */
|
||||
@ -0,0 +1,71 @@
|
||||
# Copyright 2012 Jared Boone
|
||||
# Copyright 2013 Benjamin Vernoux
|
||||
#
|
||||
# This file is part of HackRF.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
# Based heavily upon the libftdi cmake setup.
|
||||
|
||||
set(INSTALL_DEFAULT_BINDIR "bin" CACHE STRING "Appended to CMAKE_INSTALL_PREFIX")
|
||||
|
||||
if(MSVC)
|
||||
add_library(libgetopt_static STATIC
|
||||
../getopt/getopt.c
|
||||
)
|
||||
endif()
|
||||
|
||||
add_executable(hackrf_max2837 hackrf_max2837.c)
|
||||
install(TARGETS hackrf_max2837 RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
add_executable(hackrf_si5351c hackrf_si5351c.c)
|
||||
install(TARGETS hackrf_si5351c RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
add_executable(hackrf_transfer hackrf_transfer.c)
|
||||
install(TARGETS hackrf_transfer RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
add_executable(hackrf_rffc5071 hackrf_rffc5071.c)
|
||||
install(TARGETS hackrf_rffc5071 RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
add_executable(hackrf_spiflash hackrf_spiflash.c)
|
||||
install(TARGETS hackrf_spiflash RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
add_executable(hackrf_cpldjtag hackrf_cpldjtag.c)
|
||||
install(TARGETS hackrf_cpldjtag RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
add_executable(hackrf_info hackrf_info.c)
|
||||
install(TARGETS hackrf_info RUNTIME DESTINATION ${INSTALL_DEFAULT_BINDIR})
|
||||
|
||||
if(NOT libhackrf_SOURCE_DIR)
|
||||
include_directories(${LIBHACKRF_INCLUDE_DIR})
|
||||
LIST(APPEND TOOLS_LINK_LIBS ${LIBHACKRF_LIBRARIES})
|
||||
else()
|
||||
LIST(APPEND TOOLS_LINK_LIBS hackrf)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
LIST(APPEND TOOLS_LINK_LIBS libgetopt_static)
|
||||
endif()
|
||||
|
||||
|
||||
target_link_libraries(hackrf_max2837 ${TOOLS_LINK_LIBS})
|
||||
target_link_libraries(hackrf_si5351c ${TOOLS_LINK_LIBS})
|
||||
target_link_libraries(hackrf_transfer ${TOOLS_LINK_LIBS})
|
||||
target_link_libraries(hackrf_rffc5071 ${TOOLS_LINK_LIBS})
|
||||
target_link_libraries(hackrf_spiflash ${TOOLS_LINK_LIBS})
|
||||
target_link_libraries(hackrf_cpldjtag ${TOOLS_LINK_LIBS})
|
||||
target_link_libraries(hackrf_info ${TOOLS_LINK_LIBS})
|
||||
@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||
* Copyright 2013 Benjamin Vernoux <titanmkd@gmail.com>
|
||||
* Copyright 2013 Michael Ossmann <mike@ossmann.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
typedef int64_t ssize_t;
|
||||
#else
|
||||
typedef int32_t ssize_t;
|
||||
#endif
|
||||
#endif
|
||||
/* input file shouldn't be any longer than this */
|
||||
#define MAX_XSVF_LENGTH 0x10000
|
||||
#define PACKET_LEN 4096
|
||||
|
||||
uint8_t data[MAX_XSVF_LENGTH];
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "xsvf", required_argument, 0, 'x' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
int parse_int(char* s, uint32_t* const value)
|
||||
{
|
||||
uint_fast8_t base = 10;
|
||||
char* s_end;
|
||||
long long_value;
|
||||
|
||||
if (strlen(s) > 2) {
|
||||
if (s[0] == '0') {
|
||||
if ((s[1] == 'x') || (s[1] == 'X')) {
|
||||
base = 16;
|
||||
s += 2;
|
||||
} else if ((s[1] == 'b') || (s[1] == 'B')) {
|
||||
base = 2;
|
||||
s += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_end = s;
|
||||
long_value = strtol(s, &s_end, base);
|
||||
if ((s != s_end) && (*s_end == 0)) {
|
||||
*value = long_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
static void usage()
|
||||
{
|
||||
printf("Usage:\n");
|
||||
printf("\t-x <filename>: XSVF file to be written to CPLD.\n");
|
||||
printf("\t-d <serialnumber>: Serial number of device, if multiple devices\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int opt;
|
||||
uint32_t length = 0;
|
||||
uint32_t total_length = 0;
|
||||
const char* path = NULL;
|
||||
const char* serial_number = NULL;
|
||||
hackrf_device* device = NULL;
|
||||
int result = HACKRF_SUCCESS;
|
||||
int option_index = 0;
|
||||
FILE* fd = NULL;
|
||||
ssize_t bytes_read;
|
||||
uint8_t* pdata = &data[0];
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "x:d:", long_options,
|
||||
&option_index)) != EOF) {
|
||||
switch (opt) {
|
||||
case 'x':
|
||||
path = optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
serial_number = optarg;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "argument error: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (path == NULL) {
|
||||
fprintf(stderr, "Specify a path to a file.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
fd = fopen(path, "rb");
|
||||
if (fd == NULL)
|
||||
{
|
||||
fprintf(stderr, "Failed to open file: %s\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* Get size of the file */
|
||||
fseek(fd, 0, SEEK_END); /* Not really portable but work on major OS Linux/Win32 */
|
||||
length = ftell(fd);
|
||||
/* Move to start */
|
||||
rewind(fd);
|
||||
printf("File size %d bytes.\n", length);
|
||||
|
||||
if (length > MAX_XSVF_LENGTH) {
|
||||
fprintf(stderr, "XSVF file too large.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
total_length = length;
|
||||
bytes_read = fread(data, 1, total_length, fd);
|
||||
if (bytes_read != total_length)
|
||||
{
|
||||
fprintf(stderr, "Failed to read all bytes (read %d bytes instead of %d bytes).\n",
|
||||
(int)bytes_read, total_length);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_init();
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_init() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open_by_serial(serial_number, &device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_open() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("LED1/2/3 blinking means CPLD program success.\nLED3/RED steady means error.\n");
|
||||
printf("Wait message 'Write finished' or in case of LED3/RED steady, Power OFF/Disconnect the HackRF.\n");
|
||||
result = hackrf_cpld_write(device, pdata, total_length);
|
||||
if (result != HACKRF_SUCCESS)
|
||||
{
|
||||
fprintf(stderr, "hackrf_cpld_write() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
printf("Write finished.\n");
|
||||
printf("Please Power OFF/Disconnect the HackRF.\n");
|
||||
fflush(stdout);
|
||||
|
||||
result = hackrf_close(device);
|
||||
if( result != HACKRF_SUCCESS )
|
||||
{
|
||||
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
hackrf_exit();
|
||||
|
||||
if (fd != NULL) {
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||
* Copyright 2013 Benjamin Vernoux <titanmkd@gmail.com>
|
||||
* Copyright 2013 Michael Ossmann <mike@ossmann.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int result = HACKRF_SUCCESS;
|
||||
uint8_t board_id = BOARD_ID_INVALID;
|
||||
char version[255 + 1];
|
||||
read_partid_serialno_t read_partid_serialno;
|
||||
hackrf_device_list_t *list;
|
||||
int i;
|
||||
|
||||
result = hackrf_init();
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_init() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
list = hackrf_device_list();
|
||||
|
||||
if (list->devicecount < 1 ) {
|
||||
printf("No HackRF boards found.\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
for (i = 0; i < list->devicecount; i++) {
|
||||
if (i > 0)
|
||||
printf("\n");
|
||||
|
||||
printf("Found HackRF board %d:\n", i);
|
||||
|
||||
if (list->serial_numbers[i])
|
||||
printf("USB descriptor string: %s\n", list->serial_numbers[i]);
|
||||
|
||||
hackrf_device* device = NULL;
|
||||
result = hackrf_device_list_open(list, i, &device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_open() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_board_id_read(device, &board_id);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_board_id_read() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Board ID Number: %d (%s)\n", board_id,
|
||||
hackrf_board_id_name(board_id));
|
||||
|
||||
result = hackrf_version_string_read(device, &version[0], 255);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_version_string_read() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Firmware Version: %s\n", version);
|
||||
|
||||
result = hackrf_board_partid_serialno_read(device, &read_partid_serialno);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_board_partid_serialno_read() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Part ID Number: 0x%08x 0x%08x\n",
|
||||
read_partid_serialno.part_id[0],
|
||||
read_partid_serialno.part_id[1]);
|
||||
printf("Serial Number: 0x%08x 0x%08x 0x%08x 0x%08x\n",
|
||||
read_partid_serialno.serial_no[0],
|
||||
read_partid_serialno.serial_no[1],
|
||||
read_partid_serialno.serial_no[2],
|
||||
read_partid_serialno.serial_no[3]);
|
||||
|
||||
result = hackrf_close(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
}
|
||||
}
|
||||
|
||||
hackrf_device_list_free(list);
|
||||
hackrf_exit();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-n, --register <n>: set register number for subsequent read/write operations\n");
|
||||
printf("\t-r, --read: read register specified by last -n argument, or all registers\n");
|
||||
printf("\t-w, --write <v>: write register specified by last -n argument with value <v>\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\t<command> -n 12 -r # reads from register 12\n");
|
||||
printf("\t<command> -r # reads all registers\n");
|
||||
printf("\t<command> -n 10 -w 22 # writes register 10 with 22 decimal\n");
|
||||
}
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "register", required_argument, 0, 'n' },
|
||||
{ "write", required_argument, 0, 'w' },
|
||||
{ "read", no_argument, 0, 'r' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
int parse_int(char* s, uint16_t* const value) {
|
||||
uint_fast8_t base = 10;
|
||||
char* s_end;
|
||||
long long_value;
|
||||
|
||||
if( strlen(s) > 2 ) {
|
||||
if( s[0] == '0' ) {
|
||||
if( (s[1] == 'x') || (s[1] == 'X') ) {
|
||||
base = 16;
|
||||
s += 2;
|
||||
} else if( (s[1] == 'b') || (s[1] == 'B') ) {
|
||||
base = 2;
|
||||
s += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_end = s;
|
||||
long_value = strtol(s, &s_end, base);
|
||||
if( (s != s_end) && (*s_end == 0) ) {
|
||||
*value = (uint16_t)long_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
int dump_register(hackrf_device* device, const uint16_t register_number) {
|
||||
uint16_t register_value;
|
||||
int result = hackrf_max2837_read(device, (uint8_t)register_number, ®ister_value);
|
||||
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
printf("[%2d] -> 0x%03x\n", register_number, register_value);
|
||||
} else {
|
||||
printf("hackrf_max2837_read() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int dump_registers(hackrf_device* device) {
|
||||
uint16_t register_number;
|
||||
int result = HACKRF_SUCCESS;
|
||||
|
||||
for(register_number=0; register_number<32; register_number++) {
|
||||
result = dump_register(device, register_number);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int write_register(
|
||||
hackrf_device* device,
|
||||
const uint16_t register_number,
|
||||
const uint16_t register_value
|
||||
) {
|
||||
int result = HACKRF_SUCCESS;
|
||||
result = hackrf_max2837_write(device, (uint8_t)register_number, register_value);
|
||||
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
printf("0x%03x -> [%2d]\n", register_value, register_number);
|
||||
} else {
|
||||
printf("hackrf_max2837_write() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define REGISTER_INVALID 32767
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int opt;
|
||||
uint16_t register_number = REGISTER_INVALID;
|
||||
uint16_t register_value;
|
||||
hackrf_device* device = NULL;
|
||||
int option_index = 0;
|
||||
|
||||
int result = hackrf_init();
|
||||
if( result ) {
|
||||
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "n:rw:", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'n':
|
||||
result = parse_int(optarg, ®ister_number);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
result = parse_int(optarg, ®ister_value);
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if( register_number == REGISTER_INVALID ) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: %s (%d)\n", hackrf_error_name(result), result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if( result ) {
|
||||
printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hackrf_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,181 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||
* Copyright 2013 Benjamin Vernoux <titanmkd@gmail.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-n, --register <n>: set register number for subsequent read/write operations\n");
|
||||
printf("\t-r, --read: read register specified by last -n argument, or all registers\n");
|
||||
printf("\t-w, --write <v>: write register specified by last -n argument with value <v>\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\t<command> -n 12 -r # reads from register 12\n");
|
||||
printf("\t<command> -r # reads all registers\n");
|
||||
printf("\t<command> -n 10 -w 514 # writes register 10 with 514 decimal\n");
|
||||
}
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "register", required_argument, 0, 'n' },
|
||||
{ "write", required_argument, 0, 'w' },
|
||||
{ "read", no_argument, 0, 'r' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
int parse_int(char* s, uint16_t* const value) {
|
||||
uint_fast8_t base = 10;
|
||||
char* s_end;
|
||||
long long_value;
|
||||
|
||||
if( strlen(s) > 2 ) {
|
||||
if( s[0] == '0' ) {
|
||||
if( (s[1] == 'x') || (s[1] == 'X') ) {
|
||||
base = 16;
|
||||
s += 2;
|
||||
} else if( (s[1] == 'b') || (s[1] == 'B') ) {
|
||||
base = 2;
|
||||
s += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_end = s;
|
||||
long_value = strtol(s, &s_end, base);
|
||||
if( (s != s_end) && (*s_end == 0) ) {
|
||||
*value = (uint16_t)long_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
int dump_register(hackrf_device* device, const uint16_t register_number) {
|
||||
uint16_t register_value;
|
||||
int result = hackrf_rffc5071_read(device, (uint8_t)register_number, ®ister_value);
|
||||
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
printf("[%2d] -> 0x%03x\n", register_number, register_value);
|
||||
} else {
|
||||
printf("hackrf_rffc5071_read() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int dump_registers(hackrf_device* device) {
|
||||
uint16_t register_number;
|
||||
int result = HACKRF_SUCCESS;
|
||||
|
||||
for(register_number=0; register_number<31; register_number++) {
|
||||
result = dump_register(device, register_number);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int write_register(
|
||||
hackrf_device* device,
|
||||
const uint16_t register_number,
|
||||
const uint16_t register_value
|
||||
) {
|
||||
int result = HACKRF_SUCCESS;
|
||||
result = hackrf_rffc5071_write(device, (uint8_t)register_number, register_value);
|
||||
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
printf("0x%03x -> [%2d]\n", register_value, register_number);
|
||||
} else {
|
||||
printf("hackrf_rffc5071_write() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define REGISTER_INVALID 32767
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int opt;
|
||||
uint16_t register_number = REGISTER_INVALID;
|
||||
uint16_t register_value;
|
||||
hackrf_device* device = NULL;
|
||||
int option_index = 0;
|
||||
|
||||
int result = hackrf_init();
|
||||
if( result ) {
|
||||
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "n:rw:", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'n':
|
||||
result = parse_int(optarg, ®ister_number);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
result = parse_int(optarg, ®ister_value);
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if( register_number == REGISTER_INVALID ) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: %s (%d)\n", hackrf_error_name(result), result);
|
||||
usage();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if( result ) {
|
||||
printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hackrf_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,248 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
|
||||
static void usage() {
|
||||
printf("\nUsage:\n");
|
||||
printf("\t-c, --config: print textual configuration information\n");
|
||||
printf("\t-n, --register <n>: set register number for subsequent read/write operations\n");
|
||||
printf("\t-r, --read: read register specified by last -n argument, or all registers\n");
|
||||
printf("\t-w, --write <v>: write register specified by last -n argument with value <v>\n");
|
||||
printf("\nExamples:\n");
|
||||
printf("\t<command> -n 12 -r # reads from register 12\n");
|
||||
printf("\t<command> -r # reads all registers\n");
|
||||
printf("\t<command> -n 10 -w 22 # writes register 10 with 22 decimal\n");
|
||||
}
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "config", no_argument, 0, 'c' },
|
||||
{ "register", required_argument, 0, 'n' },
|
||||
{ "write", required_argument, 0, 'w' },
|
||||
{ "read", no_argument, 0, 'r' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
int parse_int(char* const s, uint16_t* const value) {
|
||||
char* s_end = s;
|
||||
const long long_value = strtol(s, &s_end, 10);
|
||||
if( (s != s_end) && (*s_end == 0) ) {
|
||||
*value = (uint16_t)long_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
int dump_register(hackrf_device* device, const uint16_t register_number) {
|
||||
uint16_t register_value;
|
||||
int result = hackrf_si5351c_read(device, register_number, ®ister_value);
|
||||
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
printf("[%3d] -> 0x%02x\n", register_number, register_value);
|
||||
} else {
|
||||
printf("hackrf_max2837_read() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int dump_registers(hackrf_device* device) {
|
||||
uint16_t register_number;
|
||||
int result = HACKRF_SUCCESS;
|
||||
|
||||
for(register_number=0; register_number<256; register_number++) {
|
||||
result = dump_register(device, register_number);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int write_register(
|
||||
hackrf_device* device,
|
||||
const uint16_t register_number,
|
||||
const uint16_t register_value
|
||||
) {
|
||||
int result = HACKRF_SUCCESS;
|
||||
result = hackrf_si5351c_write(device, register_number, register_value);
|
||||
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
printf("0x%2x -> [%3d]\n", register_value, register_number);
|
||||
} else {
|
||||
printf("hackrf_max2837_write() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#define REGISTER_INVALID 32767
|
||||
|
||||
int dump_multisynth_config(hackrf_device* device, const uint_fast8_t ms_number) {
|
||||
uint_fast8_t i;
|
||||
uint_fast8_t reg_base;
|
||||
uint16_t parameters[8];
|
||||
uint32_t p1,p2,p3,r_div;
|
||||
uint_fast8_t div_lut[] = {1,2,4,8,16,32,64,128};
|
||||
|
||||
printf("MS%d:", ms_number);
|
||||
if(ms_number <6){
|
||||
reg_base = 42 + (ms_number * 8);
|
||||
for(i=0; i<8; i++) {
|
||||
uint_fast8_t reg_number = reg_base + i;
|
||||
int result = hackrf_si5351c_read(device, reg_number, ¶meters[i]);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
p1 =
|
||||
((parameters[2] & 0x03) << 16)
|
||||
| (parameters[3] << 8)
|
||||
| parameters[4]
|
||||
;
|
||||
p2 =
|
||||
((parameters[5] & 0x0F) << 16)
|
||||
| (parameters[6] << 8)
|
||||
| parameters[7]
|
||||
;
|
||||
p3 =
|
||||
((parameters[5] & 0xF0) << 12)
|
||||
| (parameters[0] << 8)
|
||||
| parameters[1]
|
||||
;
|
||||
r_div =
|
||||
(parameters[2] >> 4) & 0x7
|
||||
;
|
||||
|
||||
printf("\tp1 = %u\n", p1);
|
||||
printf("\tp2 = %u\n", p2);
|
||||
printf("\tp3 = %u\n", p3);
|
||||
if(p3)
|
||||
printf("\tOutput (800Mhz PLL): %#.10f Mhz\n", ((double)800 / (double)(((double)p1*p3 + p2 + 512*p3)/(double)(128*p3))) / div_lut[r_div] );
|
||||
} else {
|
||||
// MS6 and 7 are integer only
|
||||
unsigned int parms;
|
||||
reg_base = 90;
|
||||
|
||||
for(i=0; i<3; i++) {
|
||||
uint_fast8_t reg_number = reg_base + i;
|
||||
int result = hackrf_si5351c_read(device, reg_number, ¶meters[i]);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
r_div = (ms_number == 6) ? parameters[2] & 0x7 : (parameters[2] & 0x70) >> 4 ;
|
||||
parms = (ms_number == 6) ? parameters[0] : parameters[1];
|
||||
printf("\tp1_int = %u\n", parms);
|
||||
if(parms)
|
||||
printf("\tOutput (800Mhz PLL): %#.10f Mhz\n", (800.0f / parms) / div_lut[r_div] );
|
||||
}
|
||||
printf("\toutput divider = %u\n", div_lut[r_div]);
|
||||
|
||||
return HACKRF_SUCCESS;
|
||||
}
|
||||
|
||||
int dump_configuration(hackrf_device* device) {
|
||||
uint_fast8_t ms_number;
|
||||
int result;
|
||||
|
||||
for(ms_number=0; ms_number<8; ms_number++) {
|
||||
result = dump_multisynth_config(device, ms_number);
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return HACKRF_SUCCESS;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
int opt;
|
||||
uint16_t register_number = REGISTER_INVALID;
|
||||
uint16_t register_value;
|
||||
hackrf_device* device = NULL;
|
||||
int option_index = 0;
|
||||
|
||||
int result = hackrf_init();
|
||||
if( result ) {
|
||||
printf("hackrf_init() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
result = hackrf_open(&device);
|
||||
if( result ) {
|
||||
printf("hackrf_open() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
while( (opt = getopt_long(argc, argv, "cn:rw:", long_options, &option_index)) != EOF ) {
|
||||
switch( opt ) {
|
||||
case 'n':
|
||||
result = parse_int(optarg, ®ister_number);
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
result = parse_int(optarg, ®ister_value);
|
||||
if( result == HACKRF_SUCCESS ) {
|
||||
result = write_register(device, register_number, register_value);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if( register_number == REGISTER_INVALID ) {
|
||||
result = dump_registers(device);
|
||||
} else {
|
||||
result = dump_register(device, register_number);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
dump_configuration(device);
|
||||
break;
|
||||
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
|
||||
if( result != HACKRF_SUCCESS ) {
|
||||
printf("argument error: %s (%d)\n", hackrf_error_name(result), result);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if( result ) {
|
||||
printf("hackrf_close() failed: %s (%d)\n", hackrf_error_name(result), result);
|
||||
return -1;
|
||||
}
|
||||
|
||||
hackrf_exit();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright 2012 Jared Boone <jared@sharebrained.com>
|
||||
* Copyright 2013 Benjamin Vernoux <titanmkd@gmail.com>
|
||||
* Copyright 2013 Michael Ossmann <mike@ossmann.com>
|
||||
*
|
||||
* This file is part of HackRF.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <hackrf.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef bool
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
typedef int64_t ssize_t;
|
||||
#else
|
||||
typedef int32_t ssize_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* 8 Mbit flash */
|
||||
#define MAX_LENGTH 0x100000
|
||||
|
||||
static struct option long_options[] = {
|
||||
{ "address", required_argument, 0, 'a' },
|
||||
{ "length", required_argument, 0, 'l' },
|
||||
{ "read", required_argument, 0, 'r' },
|
||||
{ "write", required_argument, 0, 'w' },
|
||||
{ "verbose", no_argument, 0, 'v' },
|
||||
{ 0, 0, 0, 0 },
|
||||
};
|
||||
|
||||
int parse_u32(char* s, uint32_t* const value)
|
||||
{
|
||||
char* s_end;
|
||||
uint_fast8_t base = 10;
|
||||
uint32_t u32_value;
|
||||
|
||||
if (strlen(s) > 2) {
|
||||
if (s[0] == '0') {
|
||||
if ((s[1] == 'x') || (s[1] == 'X')) {
|
||||
base = 16;
|
||||
s += 2;
|
||||
} else if ((s[1] == 'b') || (s[1] == 'B')) {
|
||||
base = 2;
|
||||
s += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
s_end = s;
|
||||
u32_value = strtoul(s, &s_end, base);
|
||||
if ((s != s_end) && (*s_end == 0)) {
|
||||
*value = u32_value;
|
||||
return HACKRF_SUCCESS;
|
||||
} else {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
static void usage()
|
||||
{
|
||||
printf("Usage:\n");
|
||||
printf("\t-a, --address <n>: starting address (default: 0)\n");
|
||||
printf("\t-l, --length <n>: number of bytes to read (default: 0)\n");
|
||||
printf("\t-r <filename>: Read data into file.\n");
|
||||
printf("\t-w <filename>: Write data from file.\n");
|
||||
printf("\t-d <serialnumber>: Serial number of device, if multiple devices\n");
|
||||
printf("\t-v: Verbose output.\n");
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
int opt;
|
||||
uint32_t address = 0;
|
||||
uint32_t length = 0;
|
||||
uint32_t tmp_length;
|
||||
uint16_t xfer_len = 0;
|
||||
const char* path = NULL;
|
||||
const char* serial_number = NULL;
|
||||
hackrf_device* device = NULL;
|
||||
int result = HACKRF_SUCCESS;
|
||||
int option_index = 0;
|
||||
static uint8_t data[MAX_LENGTH];
|
||||
uint8_t* pdata = &data[0];
|
||||
FILE* fd = NULL;
|
||||
bool read = false;
|
||||
bool write = false;
|
||||
bool verbose = false;
|
||||
|
||||
while ((opt = getopt_long(argc, argv, "a:l:r:w:d:v", long_options,
|
||||
&option_index)) != EOF) {
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
result = parse_u32(optarg, &address);
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
result = parse_u32(optarg, &length);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
read = true;
|
||||
path = optarg;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
write = true;
|
||||
path = optarg;
|
||||
break;
|
||||
|
||||
case 'd':
|
||||
serial_number = optarg;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
verbose = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "opt error: %d\n", opt);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "argument error: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (write == read) {
|
||||
if (write == true) {
|
||||
fprintf(stderr, "Read and write options are mutually exclusive.\n");
|
||||
} else {
|
||||
fprintf(stderr, "Specify either read or write option.\n");
|
||||
}
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (path == NULL) {
|
||||
fprintf(stderr, "Specify a path to a file.\n");
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if( write )
|
||||
{
|
||||
fd = fopen(path, "rb");
|
||||
if(fd == NULL)
|
||||
{
|
||||
printf("Error to open file %s\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
/* Get size of the file */
|
||||
fseek(fd, 0, SEEK_END); /* Not really portable but work on major OS Linux/Win32 */
|
||||
length = ftell(fd);
|
||||
/* Move to start */
|
||||
rewind(fd);
|
||||
printf("File size %d bytes.\n", length);
|
||||
}
|
||||
|
||||
if (length == 0) {
|
||||
fprintf(stderr, "Requested transfer of zero bytes.\n");
|
||||
if(fd != NULL)
|
||||
fclose(fd);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if ((length > MAX_LENGTH) || (address > MAX_LENGTH)
|
||||
|| ((address + length) > MAX_LENGTH)) {
|
||||
fprintf(stderr, "Request exceeds size of flash memory.\n");
|
||||
if(fd != NULL)
|
||||
fclose(fd);
|
||||
usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (read) {
|
||||
fd = fopen(path, "wb");
|
||||
if(fd == NULL)
|
||||
{
|
||||
printf("Error to open file %s\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
if (fd == NULL) {
|
||||
fprintf(stderr, "Failed to open file: %s\n", path);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_init();
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_init() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
result = hackrf_open_by_serial(serial_number, &device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_open() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (read)
|
||||
{
|
||||
ssize_t bytes_written;
|
||||
tmp_length = length;
|
||||
while (tmp_length)
|
||||
{
|
||||
xfer_len = (tmp_length > 256) ? 256 : tmp_length;
|
||||
if( verbose ) printf("Reading %d bytes from 0x%06x.\n", xfer_len, address);
|
||||
result = hackrf_spiflash_read(device, address, xfer_len, pdata);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_spiflash_read() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
address += xfer_len;
|
||||
pdata += xfer_len;
|
||||
tmp_length -= xfer_len;
|
||||
}
|
||||
bytes_written = fwrite(data, 1, length, fd);
|
||||
if (bytes_written != length) {
|
||||
fprintf(stderr, "Failed write to file (wrote %d bytes).\n",
|
||||
(int)bytes_written);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
} else {
|
||||
ssize_t bytes_read = fread(data, 1, length, fd);
|
||||
if (bytes_read != length) {
|
||||
fprintf(stderr, "Failed read file (read %d bytes).\n",
|
||||
(int)bytes_read);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
printf("Erasing SPI flash.\n");
|
||||
result = hackrf_spiflash_erase(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_spiflash_erase() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
if( !verbose ) printf("Writing %d bytes at 0x%06x.\n", length, address);
|
||||
while (length) {
|
||||
xfer_len = (length > 256) ? 256 : length;
|
||||
if( verbose ) printf("Writing %d bytes at 0x%06x.\n", xfer_len, address);
|
||||
result = hackrf_spiflash_write(device, address, xfer_len, pdata);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_spiflash_write() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
address += xfer_len;
|
||||
pdata += xfer_len;
|
||||
length -= xfer_len;
|
||||
}
|
||||
}
|
||||
|
||||
result = hackrf_close(device);
|
||||
if (result != HACKRF_SUCCESS) {
|
||||
fprintf(stderr, "hackrf_close() failed: %s (%d)\n",
|
||||
hackrf_error_name(result), result);
|
||||
fclose(fd);
|
||||
fd = NULL;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
hackrf_exit();
|
||||
|
||||
if (fd != NULL) {
|
||||
fclose(fd);
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,4 @@
|
||||
ATTR{idVendor}=="1d50", ATTR{idProduct}=="604b", SYMLINK+="hackrf-jawbreaker-%k", MODE="660", GROUP="plugdev"
|
||||
ATTR{idVendor}=="1d50", ATTR{idProduct}=="6089", SYMLINK+="hackrf-one-%k", MODE="660", GROUP="plugdev"
|
||||
ATTR{idVendor}=="1d50", ATTR{idProduct}=="cc15", SYMLINK+="rad1o-%k", MODE="660", GROUP="plugdev"
|
||||
ATTR{idVendor}=="1fc9", ATTR{idProduct}=="000c", SYMLINK+="nxp-dfu-%k", MODE="660", GROUP="plugdev"
|
||||
@ -0,0 +1,8 @@
|
||||
# HackRF Jawbreaker
|
||||
ATTR{idVendor}=="1d50", ATTR{idProduct}=="604b", SYMLINK+="hackrf-jawbreaker-%k", MODE="660", GROUP="@HACKRF_GROUP@"
|
||||
# HackRF One
|
||||
ATTR{idVendor}=="1d50", ATTR{idProduct}=="6089", SYMLINK+="hackrf-one-%k", MODE="660", GROUP="@HACKRF_GROUP@"
|
||||
# HackRF One
|
||||
ATTR{idVendor}=="1d50", ATTR{idProduct}=="CC15", SYMLINK+="rad1o-%k", MODE="660", GROUP="@HACKRF_GROUP@"
|
||||
# HackRF DFU
|
||||
ATTR{idVendor}=="1fc9", ATTR{idProduct}=="000c", SYMLINK+="nxp-dfu-%k", MODE="660", GROUP="@HACKRF_GROUP@"
|
||||
@ -0,0 +1,165 @@
|
||||
# Copyright 2012 Jared Boone
|
||||
# Copyright 2013 Benjamin Vernoux
|
||||
#
|
||||
# This file is part of HackRF.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
# Based heavily upon the libftdi cmake setup.
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
project(libhackrf C)
|
||||
set(MAJOR_VERSION 0)
|
||||
set(MINOR_VERSION 4)
|
||||
set(PACKAGE libhackrf)
|
||||
set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION})
|
||||
set(VERSION ${VERSION_STRING})
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../cmake/modules)
|
||||
|
||||
if(MSVC)
|
||||
set(THREADS_USE_PTHREADS_WIN32 true)
|
||||
else()
|
||||
add_definitions(-Wall)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu90")
|
||||
|
||||
INCLUDE(TestBigEndian)
|
||||
TEST_BIG_ENDIAN(BIGENDIAN)
|
||||
if(${BIGENDIAN})
|
||||
add_definitions(-DHACKRF_BIG_ENDIAN)
|
||||
endif(${BIGENDIAN})
|
||||
endif()
|
||||
find_package(USB1 REQUIRED)
|
||||
find_package(Threads REQUIRED)
|
||||
|
||||
include_directories(${LIBUSB_INCLUDE_DIR} ${THREADS_PTHREADS_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(src)
|
||||
|
||||
########################################################################
|
||||
# Create Pkg Config File
|
||||
########################################################################
|
||||
FOREACH(inc ${LIBUSB_INCLUDE_DIR})
|
||||
LIST(APPEND HACKRF_PC_CFLAGS "-I${inc}")
|
||||
ENDFOREACH(inc)
|
||||
|
||||
# use space-separation format for the pc file
|
||||
STRING(REPLACE ";" " " HACKRF_PC_CFLAGS "${HACKRF_PC_CFLAGS}")
|
||||
STRING(REPLACE ";" " " HACKRF_PC_LIBS "${HACKRF_PC_LIBS}")
|
||||
|
||||
# unset these vars to avoid hard-coded paths to cross environment
|
||||
IF(CMAKE_CROSSCOMPILING)
|
||||
UNSET(HACKRF_PC_CFLAGS)
|
||||
UNSET(HACKRF_PC_LIBS)
|
||||
ENDIF(CMAKE_CROSSCOMPILING)
|
||||
|
||||
set(prefix ${CMAKE_INSTALL_PREFIX})
|
||||
set(exec_prefix \${prefix})
|
||||
set(libdir \${exec_prefix}/lib${LIB_SUFFIX})
|
||||
set(includedir \${prefix}/include)
|
||||
set(libpkgdata lib${LIB_SUFFIX})
|
||||
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
set(libpkgdata "libdata")
|
||||
endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
|
||||
|
||||
CONFIGURE_FILE(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/libhackrf.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libhackrf.pc
|
||||
@ONLY)
|
||||
|
||||
INSTALL(
|
||||
FILES ${CMAKE_CURRENT_BINARY_DIR}/libhackrf.pc
|
||||
DESTINATION ${libpkgdata}/pkgconfig
|
||||
)
|
||||
|
||||
########################################################################
|
||||
# Create Pkg Config File
|
||||
########################################################################
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
SET(SYSTEM_IS_LINUX TRUE)
|
||||
SET(UDEV_OPTION_DEFAULT ON)
|
||||
else()
|
||||
SET(SYSTEM_IS_LINUX FALSE)
|
||||
SET(UDEV_OPTION_DEFAULT OFF)
|
||||
endif()
|
||||
|
||||
option(INSTALL_UDEV_RULES
|
||||
"Install udev rules for the HackRF"
|
||||
${UDEV_OPTION_DEFAULT}
|
||||
)
|
||||
|
||||
set(UDEV_RULES_PATH
|
||||
"/etc/udev/rules.d"
|
||||
CACHE STRING
|
||||
"Target directory for udev rule installation. Ensure you have permissions to write to this directory."
|
||||
)
|
||||
|
||||
if(SYSTEM_IS_LINUX)
|
||||
if(INSTALL_UDEV_RULES)
|
||||
if(NOT DEFINED UDEV_RULES_GROUP)
|
||||
foreach(group usb plugdev)
|
||||
execute_process(COMMAND "getent" group "${group}"
|
||||
RESULT_VARIABLE _GETENT_RESULT
|
||||
OUTPUT_QUIET
|
||||
ERROR_QUIET)
|
||||
if(NOT _GETENT_RESULT)
|
||||
message(STATUS "Setting udev rule group to - ${group}")
|
||||
set(UDEV_RULES_GROUP ${group})
|
||||
break()
|
||||
endif(NOT _GETENT_RESULT)
|
||||
endforeach(group)
|
||||
endif(NOT DEFINED UDEV_RULES_GROUP)
|
||||
if(DEFINED UDEV_RULES_GROUP)
|
||||
set(HACKRF_GROUP "${UDEV_RULES_GROUP}"
|
||||
CACHE STRING "Group to associate HackRF devices with in udev rules")
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/53-hackrf.rules.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules
|
||||
@ONLY
|
||||
)
|
||||
message(STATUS "HackRF udev rules will be installed to '${UDEV_RULES_PATH}' upon running 'make install'")
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/53-hackrf.rules
|
||||
DESTINATION ${UDEV_RULES_PATH}
|
||||
COMPONENT "udev_rules")
|
||||
else(UDEV_RULES_GROUP)
|
||||
message(STATUS "HackRF udev rules will not be installed because no suitable group was found")
|
||||
message(STATUS "A group can be specified with -DUDEV_RULES_GROUP=<group>")
|
||||
endif(DEFINED UDEV_RULES_GROUP)
|
||||
else(INSTALL_UDEV_RULES)
|
||||
message(STATUS
|
||||
"HackRF udev rules will not be installed because INSTALL_UDEV_RULES=OFF"
|
||||
)
|
||||
endif(INSTALL_UDEV_RULES)
|
||||
else(SYSTEM_IS_LINUX)
|
||||
if(INSTALL_UDEV_RULES)
|
||||
message(STATUS "udev rules not supported on this platform. Hide this message via -DINSTALL_UDEV_RULES=Off")
|
||||
endif(INSTALL_UDEV_RULES)
|
||||
endif(SYSTEM_IS_LINUX)
|
||||
|
||||
########################################################################
|
||||
# Create uninstall target
|
||||
########################################################################
|
||||
if(NOT hackrf_all_SOURCE_DIR)
|
||||
configure_file(
|
||||
${PROJECT_SOURCE_DIR}/../cmake/cmake_uninstall.cmake.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||
@ONLY)
|
||||
|
||||
add_custom_target(uninstall
|
||||
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
|
||||
)
|
||||
endif()
|
||||
@ -0,0 +1,33 @@
|
||||
This repository contains hardware designs and software for HackRF, a project to
|
||||
produce a low cost, open source software radio platform.
|
||||
|
||||

|
||||
|
||||
How to build host software on Windows:
|
||||
prerequisite for cygwin or mingw:
|
||||
* cmake-2.8.10.2 or more see http://www.cmake.org/cmake/resources/software.html
|
||||
* libusbx-1.0.14 or more see http://sourceforge.net/projects/libusbx/files/latest/download?source=files
|
||||
* Install Windows driver for HackRF hardware or use Zadig see http://sourceforge.net/projects/libwdi/files/zadig
|
||||
- If you want to use Zadig select HackRF USB device and just install/replace it with WinUSB driver.
|
||||
|
||||
For Cygwin:
|
||||
cmake -G "Unix Makefiles" -DCMAKE_LEGACY_CYGWIN_WIN32=1 -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
|
||||
make
|
||||
make install
|
||||
|
||||
For Mingw:
|
||||
#normal version
|
||||
cmake -G "MSYS Makefiles" -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
|
||||
#debug version
|
||||
cmake -G "MSYS Makefiles" -DCMAKE_BUILD_TYPE=Debug -DLIBUSB_INCLUDE_DIR=/usr/local/include/libusb-1.0/
|
||||
make
|
||||
make install
|
||||
|
||||
How to build host software on Linux:
|
||||
cmake ./
|
||||
make
|
||||
make install
|
||||
|
||||
principal author: Michael Ossmann <mike@ossmann.com>
|
||||
|
||||
http://greatscottgadgets.com/hackrf/
|
||||
@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: HackRF Library
|
||||
Description: C Utility Library
|
||||
Version: @VERSION@
|
||||
Cflags: -I${includedir}/ @HACKRF_PC_CFLAGS@
|
||||
Libs: -L${libdir} -lhackrf
|
||||
Libs.private: @HACKRF_PC_LIBS@
|
||||
@ -0,0 +1,81 @@
|
||||
#
|
||||
# Copyright (c) 2012, Jared Boone <jared@sharebrained.com>
|
||||
# Copyright (c) 2013, Benjamin Vernoux <titanmkd@gmail.com>
|
||||
# Copyright (c) 2013, Michael Ossmann <mike@ossmann.com>
|
||||
#
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
#
|
||||
# Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
# Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
# documentation and/or other materials provided with the distribution.
|
||||
# Neither the name of Great Scott Gadgets nor the names of its contributors may be used to endorse or promote products derived from this software
|
||||
# without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Based heavily upon the libftdi cmake setup.
|
||||
|
||||
# Targets
|
||||
set(c_sources ${CMAKE_CURRENT_SOURCE_DIR}/hackrf.c CACHE INTERNAL "List of C sources")
|
||||
set(c_headers ${CMAKE_CURRENT_SOURCE_DIR}/hackrf.h CACHE INTERNAL "List of C headers")
|
||||
|
||||
# Dynamic library
|
||||
add_library(hackrf SHARED ${c_sources})
|
||||
set_target_properties(hackrf PROPERTIES VERSION ${MAJOR_VERSION}.${MINOR_VERSION}.0 SOVERSION 0)
|
||||
|
||||
# Static library
|
||||
add_library(hackrf-static STATIC ${c_sources})
|
||||
if(MSVC)
|
||||
set_target_properties(hackrf-static PROPERTIES OUTPUT_NAME "hackrf_static")
|
||||
else()
|
||||
set_target_properties(hackrf-static PROPERTIES OUTPUT_NAME "hackrf")
|
||||
endif()
|
||||
|
||||
set_target_properties(hackrf PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
set_target_properties(hackrf-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
|
||||
|
||||
# Dependencies
|
||||
target_link_libraries(hackrf ${LIBUSB_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
# For cygwin just force UNIX OFF and WIN32 ON
|
||||
if( ${CYGWIN} )
|
||||
SET(UNIX OFF)
|
||||
SET(WIN32 ON)
|
||||
endif( ${CYGWIN} )
|
||||
|
||||
if( ${UNIX} )
|
||||
install(TARGETS hackrf
|
||||
LIBRARY DESTINATION lib${LIB_SUFFIX}
|
||||
COMPONENT sharedlibs
|
||||
)
|
||||
install(TARGETS hackrf-static
|
||||
ARCHIVE DESTINATION lib${LIB_SUFFIX}
|
||||
COMPONENT staticlibs
|
||||
)
|
||||
install(FILES ${c_headers}
|
||||
DESTINATION include/${PROJECT_NAME}
|
||||
COMPONENT headers
|
||||
)
|
||||
endif( ${UNIX} )
|
||||
|
||||
if( ${WIN32} )
|
||||
install(TARGETS hackrf
|
||||
DESTINATION bin
|
||||
COMPONENT sharedlibs
|
||||
)
|
||||
install(TARGETS hackrf-static
|
||||
DESTINATION bin
|
||||
COMPONENT staticlibs
|
||||
)
|
||||
install(FILES ${c_headers}
|
||||
DESTINATION include/${PROJECT_NAME}
|
||||
COMPONENT headers
|
||||
)
|
||||
endif( ${WIN32} )
|
||||
1687
SoftwareDefined/HackRF/hackrf-2015.07.2/host/libhackrf/src/hackrf.c
Normal file
1687
SoftwareDefined/HackRF/hackrf-2015.07.2/host/libhackrf/src/hackrf.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,211 @@
|
||||
/*
|
||||
Copyright (c) 2012, Jared Boone <jared@sharebrained.com>
|
||||
Copyright (c) 2013, Benjamin Vernoux <titanmkd@gmail.com>
|
||||
Copyright (c) 2013, Michael Ossmann <mike@ossmann.com>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
Neither the name of Great Scott Gadgets nor the names of its contributors may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef __HACKRF_H__
|
||||
#define __HACKRF_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#define ADD_EXPORTS
|
||||
|
||||
/* You should define ADD_EXPORTS *only* when building the DLL. */
|
||||
#ifdef ADD_EXPORTS
|
||||
#define ADDAPI __declspec(dllexport)
|
||||
#else
|
||||
#define ADDAPI __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
/* Define calling convention in one place, for convenience. */
|
||||
#define ADDCALL __cdecl
|
||||
|
||||
#else /* _WIN32 not defined. */
|
||||
|
||||
/* Define with no value on non-Windows OSes. */
|
||||
#define ADDAPI
|
||||
#define ADDCALL
|
||||
|
||||
#endif
|
||||
|
||||
enum hackrf_error {
|
||||
HACKRF_SUCCESS = 0,
|
||||
HACKRF_TRUE = 1,
|
||||
HACKRF_ERROR_INVALID_PARAM = -2,
|
||||
HACKRF_ERROR_NOT_FOUND = -5,
|
||||
HACKRF_ERROR_BUSY = -6,
|
||||
HACKRF_ERROR_NO_MEM = -11,
|
||||
HACKRF_ERROR_LIBUSB = -1000,
|
||||
HACKRF_ERROR_THREAD = -1001,
|
||||
HACKRF_ERROR_STREAMING_THREAD_ERR = -1002,
|
||||
HACKRF_ERROR_STREAMING_STOPPED = -1003,
|
||||
HACKRF_ERROR_STREAMING_EXIT_CALLED = -1004,
|
||||
HACKRF_ERROR_OTHER = -9999,
|
||||
};
|
||||
|
||||
enum hackrf_board_id {
|
||||
BOARD_ID_JELLYBEAN = 0,
|
||||
BOARD_ID_JAWBREAKER = 1,
|
||||
BOARD_ID_HACKRF_ONE = 2,
|
||||
BOARD_ID_INVALID = 0xFF,
|
||||
};
|
||||
|
||||
enum hackrf_usb_board_id {
|
||||
USB_BOARD_ID_JAWBREAKER = 0x604B,
|
||||
USB_BOARD_ID_HACKRF_ONE = 0x6089,
|
||||
USB_BOARD_ID_RAD1O = 0xCC15,
|
||||
USB_BOARD_ID_INVALID = 0xFFFF,
|
||||
};
|
||||
|
||||
enum rf_path_filter {
|
||||
RF_PATH_FILTER_BYPASS = 0,
|
||||
RF_PATH_FILTER_LOW_PASS = 1,
|
||||
RF_PATH_FILTER_HIGH_PASS = 2,
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
TRANSCEIVER_MODE_OFF = 0,
|
||||
TRANSCEIVER_MODE_RX = 1,
|
||||
TRANSCEIVER_MODE_TX = 2,
|
||||
TRANSCEIVER_MODE_SS = 3,
|
||||
TRANSCEIVER_MODE_CPLD_UPDATE = 4
|
||||
} transceiver_mode_t;
|
||||
|
||||
typedef struct hackrf_device hackrf_device;
|
||||
|
||||
typedef struct {
|
||||
hackrf_device* device;
|
||||
uint8_t* buffer;
|
||||
int buffer_length;
|
||||
int valid_length;
|
||||
void* rx_ctx;
|
||||
void* tx_ctx;
|
||||
} hackrf_transfer;
|
||||
|
||||
typedef struct {
|
||||
uint32_t part_id[2];
|
||||
uint32_t serial_no[4];
|
||||
} read_partid_serialno_t;
|
||||
|
||||
|
||||
struct hackrf_device_list {
|
||||
char **serial_numbers;
|
||||
enum hackrf_usb_board_id *usb_board_ids;
|
||||
int *usb_device_index;
|
||||
int devicecount;
|
||||
|
||||
void **usb_devices;
|
||||
int usb_devicecount;
|
||||
};
|
||||
typedef struct hackrf_device_list hackrf_device_list_t;
|
||||
|
||||
typedef int (*hackrf_sample_block_cb_fn)(hackrf_transfer* transfer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_init();
|
||||
extern ADDAPI int ADDCALL hackrf_exit();
|
||||
|
||||
extern ADDAPI hackrf_device_list_t* ADDCALL hackrf_device_list();
|
||||
extern ADDAPI int ADDCALL hackrf_device_list_open(hackrf_device_list_t *list, int idx, hackrf_device** device);
|
||||
extern ADDAPI void ADDCALL hackrf_device_list_free(hackrf_device_list_t *list);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_open(hackrf_device** device);
|
||||
extern ADDAPI int ADDCALL hackrf_open_by_serial(const char* const desired_serial_number, hackrf_device** device);
|
||||
extern ADDAPI int ADDCALL hackrf_close(hackrf_device* device);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_start_rx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* rx_ctx);
|
||||
extern ADDAPI int ADDCALL hackrf_stop_rx(hackrf_device* device);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_start_tx(hackrf_device* device, hackrf_sample_block_cb_fn callback, void* tx_ctx);
|
||||
extern ADDAPI int ADDCALL hackrf_stop_tx(hackrf_device* device);
|
||||
|
||||
/* return HACKRF_TRUE if success */
|
||||
extern ADDAPI int ADDCALL hackrf_is_streaming(hackrf_device* device);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_max2837_read(hackrf_device* device, uint8_t register_number, uint16_t* value);
|
||||
extern ADDAPI int ADDCALL hackrf_max2837_write(hackrf_device* device, uint8_t register_number, uint16_t value);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_si5351c_read(hackrf_device* device, uint16_t register_number, uint16_t* value);
|
||||
extern ADDAPI int ADDCALL hackrf_si5351c_write(hackrf_device* device, uint16_t register_number, uint16_t value);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_set_baseband_filter_bandwidth(hackrf_device* device, const uint32_t bandwidth_hz);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_rffc5071_read(hackrf_device* device, uint8_t register_number, uint16_t* value);
|
||||
extern ADDAPI int ADDCALL hackrf_rffc5071_write(hackrf_device* device, uint8_t register_number, uint16_t value);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_erase(hackrf_device* device);
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_write(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* const data);
|
||||
extern ADDAPI int ADDCALL hackrf_spiflash_read(hackrf_device* device, const uint32_t address, const uint16_t length, unsigned char* data);
|
||||
|
||||
/* device will need to be reset after hackrf_cpld_write */
|
||||
extern ADDAPI int ADDCALL hackrf_cpld_write(hackrf_device* device,
|
||||
unsigned char* const data, const unsigned int total_length);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_board_id_read(hackrf_device* device, uint8_t* value);
|
||||
extern ADDAPI int ADDCALL hackrf_version_string_read(hackrf_device* device, char* version, uint8_t length);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_set_freq(hackrf_device* device, const uint64_t freq_hz);
|
||||
extern ADDAPI int ADDCALL hackrf_set_freq_explicit(hackrf_device* device,
|
||||
const uint64_t if_freq_hz, const uint64_t lo_freq_hz,
|
||||
const enum rf_path_filter path);
|
||||
|
||||
/* currently 8-20Mhz - either as a fraction, i.e. freq 20000000hz divider 2 -> 10Mhz or as plain old 10000000hz (double)
|
||||
preferred rates are 8, 10, 12.5, 16, 20Mhz due to less jitter */
|
||||
extern ADDAPI int ADDCALL hackrf_set_sample_rate_manual(hackrf_device* device, const uint32_t freq_hz, const uint32_t divider);
|
||||
extern ADDAPI int ADDCALL hackrf_set_sample_rate(hackrf_device* device, const double freq_hz);
|
||||
|
||||
/* external amp, bool on/off */
|
||||
extern ADDAPI int ADDCALL hackrf_set_amp_enable(hackrf_device* device, const uint8_t value);
|
||||
|
||||
extern ADDAPI int ADDCALL hackrf_board_partid_serialno_read(hackrf_device* device, read_partid_serialno_t* read_partid_serialno);
|
||||
|
||||
/* range 0-40 step 8d, IF gain in osmosdr */
|
||||
extern ADDAPI int ADDCALL hackrf_set_lna_gain(hackrf_device* device, uint32_t value);
|
||||
|
||||
/* range 0-62 step 2db, BB gain in osmosdr */
|
||||
extern ADDAPI int ADDCALL hackrf_set_vga_gain(hackrf_device* device, uint32_t value);
|
||||
|
||||
/* range 0-47 step 1db */
|
||||
extern ADDAPI int ADDCALL hackrf_set_txvga_gain(hackrf_device* device, uint32_t value);
|
||||
|
||||
/* antenna port power control */
|
||||
extern ADDAPI int ADDCALL hackrf_set_antenna_enable(hackrf_device* device, const uint8_t value);
|
||||
|
||||
extern ADDAPI const char* ADDCALL hackrf_error_name(enum hackrf_error errcode);
|
||||
extern ADDAPI const char* ADDCALL hackrf_board_id_name(enum hackrf_board_id board_id);
|
||||
extern ADDAPI const char* ADDCALL hackrf_usb_board_id_name(enum hackrf_usb_board_id usb_board_id);
|
||||
extern ADDAPI const char* ADDCALL hackrf_filter_path_name(const enum rf_path_filter path);
|
||||
|
||||
/* Compute nearest freq for bw filter (manual filter) */
|
||||
extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw_round_down_lt(const uint32_t bandwidth_hz);
|
||||
/* Compute best default value depending on sample rate (auto filter) */
|
||||
extern ADDAPI uint32_t ADDCALL hackrf_compute_baseband_filter_bw(const uint32_t bandwidth_hz);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // __cplusplus defined.
|
||||
#endif
|
||||
|
||||
#endif//__HACKRF_H__
|
||||
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2012 Jared Boone
|
||||
#
|
||||
# This file is part of HackRF.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
import usb
|
||||
import struct
|
||||
import sys
|
||||
|
||||
device = usb.core.find(idVendor=0x1d50, idProduct=0x604b)
|
||||
if device:
|
||||
print 'Find: HackRF Jawbreaker'
|
||||
else:
|
||||
device = usb.core.find(idVendor=0x1d50, idProduct=0x6089)
|
||||
if device:
|
||||
print 'Find: HackRF One'
|
||||
else:
|
||||
device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15)
|
||||
if device:
|
||||
print 'Find: Rad1o'
|
||||
else:
|
||||
print 'Not find any HackRF device.'
|
||||
sys.exit()
|
||||
device.set_configuration()
|
||||
|
||||
def read_max2837_register(register_number):
|
||||
return struct.unpack('<H', device.ctrl_transfer(0xC0, 3, 0, register_number, 2))[0]
|
||||
|
||||
def write_max2837_register(register_number, value):
|
||||
device.ctrl_transfer(0x40, 2, value, register_number)
|
||||
|
||||
def dump_max2837():
|
||||
for i in range(32):
|
||||
print('%2d: %03x' % (i, read_max2837_register(i)))
|
||||
|
||||
dump_max2837()
|
||||
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2012 Jared Boone
|
||||
#
|
||||
# This file is part of HackRF.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
import sys
|
||||
import usb
|
||||
|
||||
device = usb.core.find(idVendor=0x1d50, idProduct=0x604b)
|
||||
if device:
|
||||
print 'Find: HackRF Jawbreaker'
|
||||
else:
|
||||
device = usb.core.find(idVendor=0x1d50, idProduct=0x6089)
|
||||
if device:
|
||||
print 'Find: HackRF One'
|
||||
else:
|
||||
device = usb.core.find(idVendor=0x1d50, idProduct=0xCC15)
|
||||
if device:
|
||||
print 'Find: Rad1o'
|
||||
else:
|
||||
print 'Not find any HackRF device.'
|
||||
sys.exit()
|
||||
device.set_configuration()
|
||||
|
||||
def set_rx():
|
||||
device.ctrl_transfer(0x40, 1, 1, 0)
|
||||
|
||||
def set_tx():
|
||||
device.ctrl_transfer(0x40, 1, 2, 0)
|
||||
|
||||
if len(sys.argv) == 2:
|
||||
if sys.argv[1] == 'tx':
|
||||
set_tx()
|
||||
elif sys.argv[1] == 'rx':
|
||||
set_rx()
|
||||
else:
|
||||
print 'Usage: %s [rx|tx]' % sys.argv[0]
|
||||
Reference in New Issue
Block a user