Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Ettus Research's Universal Serial Radio Peripheral (USRP) #72

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,15 @@ Bundled dependencies:
* libcorrect (currently a fork with CMake related fixes)
* libaec

Ettus Research USRP dependencies (required when building USRP support)

* libuhd
* libboost

## Build

``` shell
git clone https://github.com/pietern/goestools
git clone --recursive https://github.com/codient/goestools
cd goestools
mkdir -p build
cd build
Expand Down
30 changes: 30 additions & 0 deletions etc/goesrecv-uhd.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[demodulator]
mode = "hrit"
source = "uhd"

[rtlsdr]
frequency = 1694100000
sample_rate = 2400000
gain = 5
bias_tee = false

[uhd]
type = "b200"
frequency = 1694100000
sample_rate = 4000000
gain = 32

[costas]
max_deviation = 200e3

[nanomsg]
sample_rate = 2400000
connect = "tcp://0.0.0.0:5005"
receive_buffer = 2097152

[decoder.packet_publisher]
bind = "tcp://0.0.0.0:5004"
send_buffer = 1048576

[monitor]
statsd_address = "udp4://localhost:8125"
1 change: 1 addition & 0 deletions src/goesproc/handler_goesr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -600,3 +600,4 @@ void GOESRImageHandler::overlayMaps(const GOESRProduct& product, cv::Mat& mat) {
mat = drawer.draw(mat);
#endif
}

12 changes: 12 additions & 0 deletions src/goesrecv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ add_library(publisher
)
target_link_libraries(publisher nanomsg)

pkg_check_modules(UHD uhd)
if(NOT UHD_FOUND)
message(WARNING "Unable to find libuhd")
else()
add_library(uhd_source uhd_source.cc)
target_link_libraries(uhd_source ${UHD_LIBRARIES} publisher stdc++)
endif()

pkg_check_modules(AIRSPY libairspy)
if(NOT AIRSPY_FOUND)
message(WARNING "Unable to find libairspy")
Expand Down Expand Up @@ -60,6 +68,10 @@ target_link_libraries(goesrecv clock_recovery)
target_link_libraries(goesrecv quantize)
target_link_libraries(goesrecv nanomsg_source)
target_link_libraries(goesrecv version)
if(UHD_FOUND)
target_compile_definitions(goesrecv PUBLIC -DBUILD_UHD)
target_link_libraries(goesrecv uhd_source)
endif()
if(AIRSPY_FOUND)
target_compile_definitions(goesrecv PUBLIC -DBUILD_AIRSPY)
target_link_libraries(goesrecv airspy_source)
Expand Down
42 changes: 42 additions & 0 deletions src/goesrecv/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,43 @@ void loadDemodulator(Config::Demodulator& out, const toml::Value& v) {
}
}

//
void loadUHDSource(Config::UHD& out, const toml::Value& v) {
const auto& table = v.as<toml::Table>();

for (const auto& it : table) {
const auto& key = it.first;
const auto& value = it.second;

if (key == "type") {
out.type = value.as<std::string>();
continue;
}

if (key == "frequency") {
out.frequency = value.as<int>();
continue;
}

if (key == "sample_rate") {
out.sampleRate = value.as<int>();
continue;
}

if (key == "gain") {
out.gain = value.as<int>();
continue;
}

if (key == "sample_publisher") {
out.samplePublisher = createSamplePublisher(value);
continue;
}

throwInvalidKey(key);
}
}

void loadAirspySource(Config::Airspy& out, const toml::Value& v) {
const auto& table = v.as<toml::Table>();
for (const auto& it : table) {
Expand Down Expand Up @@ -382,6 +419,11 @@ Config Config::load(const std::string& file) {
continue;
}

if (key == "uhd") {
loadUHDSource(out.uhd, value);
continue;
}

if (key == "airspy") {
loadAirspySource(out.airspy, value);
continue;
Expand Down
14 changes: 13 additions & 1 deletion src/goesrecv/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct Config {
// LRIT or HRIT
std::string downlinkType;

// String "airspy" or "rtlsdr"
// String "uhd", "airspy" or "rtlsdr"
std::string source;

// Demodulator statistics (gain, frequency correction, etc.)
Expand All @@ -33,6 +33,18 @@ struct Config {

Demodulator demodulator;

struct UHD {

std::string type; // device type filter
uint32_t frequency = 0;
uint32_t sampleRate = 0;
uint8_t gain = 8;

std::unique_ptr<SamplePublisher> samplePublisher;
};

UHD uhd;

struct Airspy {
uint32_t frequency = 0;
uint32_t sampleRate = 0;
Expand Down
33 changes: 33 additions & 0 deletions src/goesrecv/source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <algorithm>

#ifdef BUILD_UHD
#include "uhd_source.h"
#endif

#ifdef BUILD_AIRSPY
#include "airspy_source.h"
#endif
Expand All @@ -15,6 +19,35 @@
std::unique_ptr<Source> Source::build(
const std::string& type,
Config& config) {
if (type == "uhd") {
#ifdef BUILD_UHD
auto uhd = UHD::open( config.uhd.type );

// Use sample rate if set, otherwise default to lowest possible rate.
// auto rates = uhd->getSampleRates();

// Use sample rate if set, otherwise default to 2.4MSPS.
if (config.uhd.sampleRate != 0) {
uhd->setSampleRate(config.uhd.sampleRate);
} else {
uhd->setSampleRate(2400000);
}

uhd->setFrequency(config.uhd.frequency);
uhd->setGain(config.uhd.gain);
uhd->setSamplePublisher(std::move(config.uhd.samplePublisher));

return std::unique_ptr<Source>(uhd.release());
#else
throw std::runtime_error(
"You configured goesrecv to use the \"uhd\" source, "
"but goesrecv was not compiled with UHD support. "
"Make sure to install the UHD library before compiling goestools, "
"and look for a message saying 'Found uhd' when running cmake."
);
#endif
}

if (type == "airspy") {
#ifdef BUILD_AIRSPY
auto airspy = Airspy::open();
Expand Down
Loading