forked from mvaenskae/gr-osmosdr
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This patch adds support for both receiving and transmitting using the FreeSRP. More information on the FreeSRP can be found at: http://freesrp.org The gr-osmosdr blocks added make use of libfreesrp, the library required for interfacing with this device. The libfreesrp source code is freely available at https://github.com/freesrp/libfreesrp Usage example: osmocom_fft -a "freesrp"
- Loading branch information
Lukas Lao Beyer
authored and
Dimitri Stolnikov
committed
Apr 18, 2017
1 parent
e9dde9a
commit 5ecfa25
Showing
21 changed files
with
2,716 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ Josh Blum | |
SDRplay Ltd. | ||
Pavel Demin | ||
Marcus Müller | ||
Lukas Lao Beyer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
if(NOT LIBFREESRP_FOUND) | ||
pkg_check_modules (LIBFREESRP_PKG libfreesrp) | ||
find_path(LIBFREESRP_INCLUDE_DIRS NAMES freesrp.hpp | ||
PATHS | ||
${LIBFREESRP_PKG_INCLUDE_DIRS} | ||
/usr/include | ||
/usr/local/include | ||
) | ||
|
||
find_library(LIBFREESRP_LIBRARIES NAMES freesrp | ||
PATHS | ||
${LIBFREESRP_PKG_LIBRARY_DIRS} | ||
/usr/lib | ||
/usr/local/lib | ||
) | ||
|
||
if(LIBFREESRP_INCLUDE_DIRS AND LIBFREESRP_LIBRARIES) | ||
set(LIBFREESRP_FOUND TRUE CACHE INTERNAL "libfreesrp found") | ||
message(STATUS "Found libfreesrp: ${LIBFREESRP_INCLUDE_DIRS}, ${LIBFREESRP_LIBRARIES}") | ||
else(LIBFREESRP_INCLUDE_DIRS AND LIBFREESRP_LIBRARIES) | ||
set(LIBFREESRP_FOUND FALSE CACHE INTERNAL "libfreesrp found") | ||
message(STATUS "libfreesrp not found.") | ||
endif(LIBFREESRP_INCLUDE_DIRS AND LIBFREESRP_LIBRARIES) | ||
|
||
mark_as_advanced(LIBFREESRP_LIBRARIES LIBFREESRP_INCLUDE_DIRS) | ||
|
||
endif(NOT LIBFREESRP_FOUND) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2012 Free Software Foundation, Inc. | ||
# | ||
# This file is part of GNU Radio | ||
# | ||
# GNU Radio 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 3, or (at your option) | ||
# any later version. | ||
# | ||
# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to | ||
# the Free Software Foundation, Inc., 51 Franklin Street, | ||
# Boston, MA 02110-1301, USA. | ||
|
||
######################################################################## | ||
# This file included, use CMake directory variables | ||
######################################################################## | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${LIBFREESRP_INCLUDE_DIRS} | ||
) | ||
|
||
set(freesrp_srcs | ||
${CMAKE_CURRENT_SOURCE_DIR}/freesrp_common.cc | ||
${CMAKE_CURRENT_SOURCE_DIR}/freesrp_source_c.cc | ||
${CMAKE_CURRENT_SOURCE_DIR}/freesrp_sink_c.cc | ||
) | ||
|
||
######################################################################## | ||
# Append gnuradio-osmosdr library sources | ||
######################################################################## | ||
list(APPEND gr_osmosdr_srcs ${freesrp_srcs}) | ||
list(APPEND gr_osmosdr_libs ${LIBFREESRP_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
#include "freesrp_common.h" | ||
|
||
#include <cstdlib> | ||
|
||
#include <boost/make_shared.hpp> | ||
#include <boost/assign.hpp> | ||
|
||
#include <arg_helpers.h> | ||
|
||
using namespace FreeSRP; | ||
using namespace std; | ||
using namespace boost::assign; | ||
|
||
boost::shared_ptr<::FreeSRP::FreeSRP> freesrp_common::_srp; | ||
|
||
freesrp_common::freesrp_common(const string &args) | ||
{ | ||
dict_t dict = params_to_dict(args); | ||
|
||
if(!_srp) | ||
{ | ||
try | ||
{ | ||
string serial = ""; | ||
|
||
if(dict.count("freesrp")) | ||
{ | ||
serial = dict["freesrp"]; | ||
} | ||
|
||
if(dict.count("fx3")) | ||
{ | ||
if(Util::find_fx3()) | ||
{ | ||
// Upload firmware to FX3 | ||
string firmware_path = string(getenv("HOME")) + "/.freesrp/fx3.img"; | ||
if(dict["fx3"].length() > 0) | ||
{ | ||
firmware_path = dict["fx3"]; | ||
} | ||
Util::find_fx3(true, firmware_path); | ||
cout << "FX3 programmed with '" << firmware_path << "'" << endl; | ||
// Give FX3 time to re-enumerate | ||
this_thread::sleep_for(chrono::milliseconds(600)); | ||
} | ||
else | ||
{ | ||
cout << "No FX3 in bootloader mode found" << endl; | ||
} | ||
} | ||
|
||
_srp.reset(new ::FreeSRP::FreeSRP(serial)); | ||
|
||
if(dict.count("fpga") || !_srp->fpga_loaded()) | ||
{ | ||
string bitstream_path = string(getenv("HOME")) + "/.freesrp/fpga.bin"; | ||
if(dict["fpga"].length() > 0) | ||
{ | ||
bitstream_path = dict["fpga"]; | ||
} | ||
fpga_status stat = _srp->load_fpga(bitstream_path); | ||
switch(stat) | ||
{ | ||
case FPGA_CONFIG_ERROR: | ||
throw runtime_error("Could not load FPGA configuration!"); | ||
case FPGA_CONFIG_SKIPPED: | ||
cout << "FPGA already configured. Restart the FreeSRP to load a new bitstream." << endl; | ||
break; | ||
case FPGA_CONFIG_DONE: | ||
cout << "FPGA configured with '" << bitstream_path << "'" << endl; | ||
break; | ||
} | ||
} | ||
|
||
cout << "Connected to FreeSRP" << endl; | ||
|
||
if(dict.count("loopback")) | ||
{ | ||
response res = _srp->send_cmd({SET_LOOPBACK_EN, 1}); | ||
if(res.error == CMD_OK) | ||
{ | ||
cout << "AD9364 in loopback mode" << endl; | ||
} | ||
else | ||
{ | ||
throw runtime_error("Could not put AD9364 into loopback mode!"); | ||
} | ||
} | ||
else | ||
{ | ||
response res = _srp->send_cmd({SET_LOOPBACK_EN, 0}); | ||
if(res.error != CMD_OK) | ||
{ | ||
throw runtime_error("Error disabling AD9364 loopback mode!"); | ||
} | ||
} | ||
|
||
if(dict.count("ignore_overflow")) | ||
{ | ||
_ignore_overflow = true; | ||
} | ||
else | ||
{ | ||
_ignore_overflow = false; | ||
} | ||
} | ||
catch(const runtime_error& e) | ||
{ | ||
cerr << "FreeSRP Error: " << e.what() << endl; | ||
throw runtime_error(e.what()); | ||
} | ||
} | ||
} | ||
|
||
vector<string> freesrp_common::get_devices() | ||
{ | ||
vector<string> devices; | ||
|
||
try | ||
{ | ||
::FreeSRP::FreeSRP srp; | ||
|
||
string str; | ||
str = "freesrp=0,label='FreeSRP'"; | ||
|
||
devices.push_back(str); | ||
} | ||
catch(const ConnectionError &err) | ||
{ | ||
// No FreeSRP found. | ||
} | ||
|
||
return devices; | ||
} | ||
|
||
size_t freesrp_common::get_num_channels( void ) | ||
{ | ||
return 1; | ||
} | ||
|
||
osmosdr::meta_range_t freesrp_common::get_sample_rates( void ) | ||
{ | ||
osmosdr::meta_range_t range; | ||
|
||
// Any sample rate between 1e6 and 61.44e6 can be requested. | ||
// This list of some integer values is used instead of | ||
// range += osmosdr::range_t(1e6, 61.44e6); | ||
// because SoapyOsmo seems to handle the range object differently. | ||
range += osmosdr::range_t(1e6); | ||
range += osmosdr::range_t(8e6); | ||
range += osmosdr::range_t(16e6); | ||
range += osmosdr::range_t(20e6); | ||
range += osmosdr::range_t(40e6); | ||
range += osmosdr::range_t(50e6); | ||
range += osmosdr::range_t(61.44e6); | ||
|
||
return range; | ||
} | ||
|
||
osmosdr::freq_range_t freesrp_common::get_freq_range(size_t chan) | ||
{ | ||
osmosdr::meta_range_t freq_ranges; | ||
|
||
freq_ranges.push_back(osmosdr::range_t(7e7, 6e9, 2.4)); | ||
|
||
return freq_ranges; | ||
} | ||
|
||
|
||
osmosdr::freq_range_t freesrp_common::get_bandwidth_range(size_t chan) | ||
{ | ||
osmosdr::meta_range_t range; | ||
|
||
//range += osmosdr::range_t(2e5, 56e6); | ||
|
||
range += osmosdr::range_t(2e5); | ||
range += osmosdr::range_t(1e6); | ||
range += osmosdr::range_t(8e6); | ||
range += osmosdr::range_t(16e6); | ||
range += osmosdr::range_t(20e6); | ||
range += osmosdr::range_t(40e6); | ||
range += osmosdr::range_t(50e6); | ||
range += osmosdr::range_t(56e6); | ||
|
||
return range; | ||
} | ||
|
||
|
||
double freesrp_common::set_freq_corr( double ppm, size_t chan ) | ||
{ | ||
// TODO: Set DCXO tuning | ||
return 0; | ||
} | ||
|
||
double freesrp_common::get_freq_corr( size_t chan ) | ||
{ | ||
// TODO: Get DCXO tuning | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef INCLUDED_FREESRP_COMMON_H | ||
#define INCLUDED_FREESRP_COMMON_H | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include "osmosdr/ranges.h" | ||
|
||
#include <freesrp.hpp> | ||
|
||
class freesrp_common | ||
{ | ||
protected: | ||
freesrp_common(const std::string &args); | ||
public: | ||
static std::vector<std::string> get_devices(); | ||
|
||
size_t get_num_channels( void ); | ||
osmosdr::meta_range_t get_sample_rates( void ); | ||
osmosdr::freq_range_t get_freq_range( size_t chan = 0 ); | ||
osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ); | ||
double set_freq_corr( double ppm, size_t chan = 0 ); | ||
double get_freq_corr( size_t chan = 0 ); | ||
protected: | ||
static boost::shared_ptr<::FreeSRP::FreeSRP> _srp; | ||
bool _ignore_overflow = false; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.